Skip to content

Commit fcaceba

Browse files
committed
Add conditional cfg(test) to modules
Some modules were missing conditional test-only compilation
1 parent 8606c1f commit fcaceba

File tree

6 files changed

+180
-174
lines changed

6 files changed

+180
-174
lines changed

src/concat/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,10 @@ impl BroCatli {
575575
}
576576
}
577577

578+
#[cfg(test)]
578579
mod test {
579-
#[cfg(test)]
580580
use super::BroCatli;
581+
581582
#[test]
582583
fn test_deserialization() {
583584
let broccoli = BroCatli {

src/enc/backward_references/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#![cfg(feature = "std")]
21
#![cfg(test)]
2+
#![cfg(feature = "std")]
33

44
use alloc_stdlib::StandardAlloc;
55

src/enc/command.rs

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,79 @@ impl Command {
257257
}
258258
}
259259

260+
pub fn RecomputeDistancePrefixes(
261+
cmds: &mut [Command],
262+
num_commands: usize,
263+
num_direct_distance_codes: u32,
264+
distance_postfix_bits: u32,
265+
dist: &BrotliDistanceParams,
266+
) {
267+
if num_direct_distance_codes == 0u32 && (distance_postfix_bits == 0u32) {
268+
return;
269+
}
270+
for i in 0usize..num_commands {
271+
let cmd: &mut Command = &mut cmds[i];
272+
if cmd.copy_len() != 0 && cmd.cmd_prefix_ >= 128 {
273+
PrefixEncodeCopyDistance(
274+
cmd.restore_distance_code(dist) as usize,
275+
num_direct_distance_codes as usize,
276+
distance_postfix_bits as (u64),
277+
&mut cmd.dist_prefix_,
278+
&mut cmd.dist_extra_,
279+
);
280+
}
281+
}
282+
}
283+
284+
impl Command {
285+
pub fn init(
286+
&mut self,
287+
dist: &BrotliDistanceParams,
288+
insertlen: usize,
289+
copylen: usize,
290+
copylen_code: usize,
291+
distance_code: usize,
292+
) {
293+
self.insert_len_ = insertlen as u32;
294+
let copylen_code_delta = (copylen_code as i32 - copylen as i32) as i8;
295+
self.copy_len_ = (copylen as u32 | (u32::from(copylen_code_delta as u8) << 25));
296+
PrefixEncodeCopyDistance(
297+
distance_code,
298+
dist.num_direct_distance_codes as usize,
299+
u64::from(dist.distance_postfix_bits),
300+
&mut self.dist_prefix_,
301+
&mut self.dist_extra_,
302+
);
303+
get_length_code(
304+
insertlen,
305+
copylen_code,
306+
(self.dist_prefix_ & 0x3ff) == 0,
307+
&mut self.cmd_prefix_,
308+
);
309+
}
310+
311+
pub fn new(
312+
dist: &BrotliDistanceParams,
313+
insertlen: usize,
314+
copylen: usize,
315+
copylen_code: usize,
316+
distance_code: usize,
317+
) -> Self {
318+
let mut cmd = Command {
319+
insert_len_: insertlen as u32,
320+
copy_len_: (copylen | ((copylen_code ^ copylen) << 25)) as u32,
321+
dist_extra_: 0,
322+
cmd_prefix_: 0,
323+
dist_prefix_: 0,
324+
};
325+
cmd.init(dist, insertlen, copylen, copylen_code, distance_code);
326+
cmd
327+
}
328+
}
329+
330+
#[cfg(test)]
260331
mod test {
261332
// returns which distance code to use ( 0 means none, 1 means last, 2 means penultimate, 3 means the prior to penultimate
262-
#[cfg(test)]
263333
pub fn helperCommandDistanceIndexAndOffset(
264334
cmd: &super::Command,
265335
dist: &super::BrotliDistanceParams,
@@ -380,72 +450,3 @@ mod test {
380450
}
381451
}*/
382452
}
383-
pub fn RecomputeDistancePrefixes(
384-
cmds: &mut [Command],
385-
num_commands: usize,
386-
num_direct_distance_codes: u32,
387-
distance_postfix_bits: u32,
388-
dist: &BrotliDistanceParams,
389-
) {
390-
if num_direct_distance_codes == 0u32 && (distance_postfix_bits == 0u32) {
391-
return;
392-
}
393-
for i in 0usize..num_commands {
394-
let cmd: &mut Command = &mut cmds[i];
395-
if cmd.copy_len() != 0 && cmd.cmd_prefix_ >= 128 {
396-
PrefixEncodeCopyDistance(
397-
cmd.restore_distance_code(dist) as usize,
398-
num_direct_distance_codes as usize,
399-
distance_postfix_bits as (u64),
400-
&mut cmd.dist_prefix_,
401-
&mut cmd.dist_extra_,
402-
);
403-
}
404-
}
405-
}
406-
407-
impl Command {
408-
pub fn init(
409-
&mut self,
410-
dist: &BrotliDistanceParams,
411-
insertlen: usize,
412-
copylen: usize,
413-
copylen_code: usize,
414-
distance_code: usize,
415-
) {
416-
self.insert_len_ = insertlen as u32;
417-
let copylen_code_delta = (copylen_code as i32 - copylen as i32) as i8;
418-
self.copy_len_ = (copylen as u32 | (u32::from(copylen_code_delta as u8) << 25));
419-
PrefixEncodeCopyDistance(
420-
distance_code,
421-
dist.num_direct_distance_codes as usize,
422-
u64::from(dist.distance_postfix_bits),
423-
&mut self.dist_prefix_,
424-
&mut self.dist_extra_,
425-
);
426-
get_length_code(
427-
insertlen,
428-
copylen_code,
429-
(self.dist_prefix_ & 0x3ff) == 0,
430-
&mut self.cmd_prefix_,
431-
);
432-
}
433-
434-
pub fn new(
435-
dist: &BrotliDistanceParams,
436-
insertlen: usize,
437-
copylen: usize,
438-
copylen_code: usize,
439-
distance_code: usize,
440-
) -> Self {
441-
let mut cmd = Command {
442-
insert_len_: insertlen as u32,
443-
copy_len_: (copylen | ((copylen_code ^ copylen) << 25)) as u32,
444-
dist_extra_: 0,
445-
cmd_prefix_: 0,
446-
dist_prefix_: 0,
447-
};
448-
cmd.init(dist, insertlen, copylen, copylen_code, distance_code);
449-
cmd
450-
}
451-
}

src/enc/interface.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ pub fn u8_to_speed(data: u8) -> u16 {
761761
(1u16 << log_val) | (rem >> 3)
762762
}
763763
}
764+
764765
#[cfg(test)]
765766
mod test {
766767
use super::{speed_to_u8, u8_to_speed};

src/enc/static_dict.rs

Lines changed: 98 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -234,102 +234,6 @@ pub fn ComplexFindMatchLengthWithLimit(mut s1: &[u8], mut s2: &[u8], mut limit:
234234
matched + (limit & 7usize) // made it through the loop
235235
}
236236

237-
mod test {
238-
#[allow(unused)]
239-
fn construct_situation(seed: &[u8], mut output: &mut [u8], limit: usize, matchfor: usize) {
240-
output[..].clone_from_slice(seed);
241-
if matchfor >= limit {
242-
return;
243-
}
244-
output[matchfor] = output[matchfor].wrapping_add((matchfor as u8 % 253u8).wrapping_add(1));
245-
}
246-
#[test]
247-
fn test_find_match_length() {
248-
let mut a = [91u8; 600000];
249-
let mut b = [0u8; 600000];
250-
for i in 1..a.len() {
251-
a[i] = (a[i - 1] % 19u8).wrapping_add(17);
252-
}
253-
construct_situation(&a[..], &mut b[..], a.len(), 0);
254-
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 0);
255-
construct_situation(&a[..], &mut b[..], a.len(), 1);
256-
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 1);
257-
construct_situation(&a[..], &mut b[..], a.len(), 10);
258-
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 10);
259-
construct_situation(&a[..], &mut b[..], a.len(), 9);
260-
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 9);
261-
construct_situation(&a[..], &mut b[..], a.len(), 7);
262-
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 7);
263-
construct_situation(&a[..], &mut b[..], a.len(), 8);
264-
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 8);
265-
construct_situation(&a[..], &mut b[..], a.len(), 48);
266-
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 48);
267-
construct_situation(&a[..], &mut b[..], a.len(), 49);
268-
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 49);
269-
construct_situation(&a[..], &mut b[..], a.len(), 63);
270-
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 63);
271-
construct_situation(&a[..], &mut b[..], a.len(), 222);
272-
assert_eq!(
273-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
274-
222
275-
);
276-
construct_situation(&a[..], &mut b[..], a.len(), 1590);
277-
assert_eq!(
278-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
279-
1590
280-
);
281-
construct_situation(&a[..], &mut b[..], a.len(), 12590);
282-
assert_eq!(
283-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
284-
12590
285-
);
286-
construct_situation(&a[..], &mut b[..], a.len(), 52592);
287-
assert_eq!(
288-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
289-
52592
290-
);
291-
construct_situation(&a[..], &mut b[..], a.len(), 152592);
292-
assert_eq!(
293-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
294-
152592
295-
);
296-
construct_situation(&a[..], &mut b[..], a.len(), 252591);
297-
assert_eq!(
298-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
299-
252591
300-
);
301-
construct_situation(&a[..], &mut b[..], a.len(), 131072);
302-
assert_eq!(
303-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
304-
131072
305-
);
306-
construct_situation(&a[..], &mut b[..], a.len(), 131073);
307-
assert_eq!(
308-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
309-
131073
310-
);
311-
construct_situation(&a[..], &mut b[..], a.len(), 131072 + 64 + 32 + 16 + 8);
312-
assert_eq!(
313-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
314-
131072 + 64 + 32 + 16 + 8
315-
);
316-
construct_situation(&a[..], &mut b[..], a.len(), 272144 + 64 + 32 + 16 + 8 + 1);
317-
assert_eq!(
318-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
319-
272144 + 64 + 32 + 16 + 8 + 1
320-
);
321-
construct_situation(&a[..], &mut b[..], a.len(), 2 * 272144 + 64 + 32 + 16 + 8);
322-
assert_eq!(
323-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
324-
2 * 272144 + 64 + 32 + 16 + 8
325-
);
326-
construct_situation(&a[..], &mut b[..], a.len(), a.len());
327-
assert_eq!(
328-
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
329-
a.len()
330-
);
331-
}
332-
}
333237
#[allow(unused)]
334238
pub fn slowFindMatchLengthWithLimit(s1: &[u8], s2: &[u8], limit: usize) -> usize {
335239
for (index, it) in s1[..limit].iter().zip(s2[..limit].iter()).enumerate() {
@@ -1398,3 +1302,101 @@ pub fn BrotliFindAllStaticDictionaryMatches(
13981302
}
13991303
has_found_match
14001304
}
1305+
1306+
#[cfg(test)]
1307+
mod test {
1308+
#[allow(unused)]
1309+
fn construct_situation(seed: &[u8], mut output: &mut [u8], limit: usize, matchfor: usize) {
1310+
output[..].clone_from_slice(seed);
1311+
if matchfor >= limit {
1312+
return;
1313+
}
1314+
output[matchfor] = output[matchfor].wrapping_add((matchfor as u8 % 253u8).wrapping_add(1));
1315+
}
1316+
#[test]
1317+
fn test_find_match_length() {
1318+
let mut a = [91u8; 600000];
1319+
let mut b = [0u8; 600000];
1320+
for i in 1..a.len() {
1321+
a[i] = (a[i - 1] % 19u8).wrapping_add(17);
1322+
}
1323+
construct_situation(&a[..], &mut b[..], a.len(), 0);
1324+
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 0);
1325+
construct_situation(&a[..], &mut b[..], a.len(), 1);
1326+
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 1);
1327+
construct_situation(&a[..], &mut b[..], a.len(), 10);
1328+
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 10);
1329+
construct_situation(&a[..], &mut b[..], a.len(), 9);
1330+
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 9);
1331+
construct_situation(&a[..], &mut b[..], a.len(), 7);
1332+
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 7);
1333+
construct_situation(&a[..], &mut b[..], a.len(), 8);
1334+
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 8);
1335+
construct_situation(&a[..], &mut b[..], a.len(), 48);
1336+
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 48);
1337+
construct_situation(&a[..], &mut b[..], a.len(), 49);
1338+
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 49);
1339+
construct_situation(&a[..], &mut b[..], a.len(), 63);
1340+
assert_eq!(super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()), 63);
1341+
construct_situation(&a[..], &mut b[..], a.len(), 222);
1342+
assert_eq!(
1343+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1344+
222
1345+
);
1346+
construct_situation(&a[..], &mut b[..], a.len(), 1590);
1347+
assert_eq!(
1348+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1349+
1590
1350+
);
1351+
construct_situation(&a[..], &mut b[..], a.len(), 12590);
1352+
assert_eq!(
1353+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1354+
12590
1355+
);
1356+
construct_situation(&a[..], &mut b[..], a.len(), 52592);
1357+
assert_eq!(
1358+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1359+
52592
1360+
);
1361+
construct_situation(&a[..], &mut b[..], a.len(), 152592);
1362+
assert_eq!(
1363+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1364+
152592
1365+
);
1366+
construct_situation(&a[..], &mut b[..], a.len(), 252591);
1367+
assert_eq!(
1368+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1369+
252591
1370+
);
1371+
construct_situation(&a[..], &mut b[..], a.len(), 131072);
1372+
assert_eq!(
1373+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1374+
131072
1375+
);
1376+
construct_situation(&a[..], &mut b[..], a.len(), 131073);
1377+
assert_eq!(
1378+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1379+
131073
1380+
);
1381+
construct_situation(&a[..], &mut b[..], a.len(), 131072 + 64 + 32 + 16 + 8);
1382+
assert_eq!(
1383+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1384+
131072 + 64 + 32 + 16 + 8
1385+
);
1386+
construct_situation(&a[..], &mut b[..], a.len(), 272144 + 64 + 32 + 16 + 8 + 1);
1387+
assert_eq!(
1388+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1389+
272144 + 64 + 32 + 16 + 8 + 1
1390+
);
1391+
construct_situation(&a[..], &mut b[..], a.len(), 2 * 272144 + 64 + 32 + 16 + 8);
1392+
assert_eq!(
1393+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1394+
2 * 272144 + 64 + 32 + 16 + 8
1395+
);
1396+
construct_situation(&a[..], &mut b[..], a.len(), a.len());
1397+
assert_eq!(
1398+
super::FindMatchLengthWithLimit(&a[..], &b[..], a.len()),
1399+
a.len()
1400+
);
1401+
}
1402+
}

0 commit comments

Comments
 (0)