ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Compress-LZF/t/03_freeze_best.t
Revision: 1.1
Committed: Sun Aug 25 18:13:26 2013 UTC (10 years, 9 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-3_7, rel-3_8, HEAD
Log Message:
3.7

File Contents

# User Rev Content
1 root 1.1 BEGIN {
2     eval "use Storable; 1" or do {
3     print "1..0 # skip Storable module unavailable\n";
4     exit;
5     };
6     }
7    
8     BEGIN { $| = 1; print "1..1959\n"; }
9    
10     END {print "not ok 1\n" unless $loaded;}
11     use Compress::LZF ':freeze';
12     use Storable;
13     $loaded = 1;
14     print "ok 1\n";
15    
16     $tst = 0;
17    
18     sub ok {
19     print (($_[0] ? "ok " : "not ok "), 1+ ++$tst, "\n");
20     }
21    
22     sub chk {
23     my $s = shift;
24     my $n = sfreeze_best $s; ok(1);
25     my $nr = sfreeze_cr_best $s; ok(1);
26     my $nc = sfreeze_c_best $s; ok(1);
27     my $r = sfreeze_best \$s; ok(1);
28     my $rr = sfreeze_cr_best\$s; ok(1);
29     my $rc = sfreeze_c_best \$s; ok(1);
30    
31     ok (length ($n) >= length ($nc));
32     ok (length ($n) <= length ($r));
33     ok (length ($r) >= length ($rr));
34     ok ($rr eq $rc);
35     ok (length ($r) >= length ($rr));
36    
37     #print unpack("H*", $s), " => ", unpack("H*", $rc), "\n";
38    
39     ok ($s eq sthaw $n);
40     ok ($s eq sthaw $nr);
41     ok ($s eq sthaw $nc);
42     ok ($s eq ${sthaw $r});
43     ok ($s eq ${sthaw $rr});
44     ok ($s eq ${sthaw $rc});
45     }
46    
47     for my $pfx (0, 1, 4, 6, 7, 40, ord('x'), 240..255) {
48     chk $pfx;
49     $pfx =~ /(.*)/;
50     chk $1;
51     chk chr($pfx)."x";
52     chk chr($pfx)."xxxxxxxxxxxxx";
53     chk chr($pfx)."abcdefghijklm";
54     }
55    
56     ok (eval {sthaw undef; 1});
57     ok (!eval {sthaw "\x07"; 1});
58     ok (!defined sthaw sfreeze_best undef);
59