Debian Codegraph @

t/crc.t

raw symbols SCIP
1 BEGIN {
2 $testsscip-perl cpan Digest-CRC 0.24 main/$tests. = 32;
3 if ($ENVscip-perl cpan Digest-CRC 0.24 main/`%ENV`.{'WITH_CRC64'}) {
4 $testsscip-perl cpan Digest-CRC 0.24 main/$tests.=$testsscip-perl cpan Digest-CRC 0.24 main/$tests.+2;
5 }
6 $|scip-perl cpan Digest-CRC 0.24 main/`$|`. = 1;
7
8 eval "use Test::More tests => $tests";
9
10 $@scip-perl cpan Digest-CRC 0.24 main/`$@`. and eval <<'ENDEV';
11 $ok = 1;
12
13 print "1..$tests\n";
14
15 sub ok {
16 my($res,$comment) = @_;
17 defined $comment and print "# $comment\n";
18 $res or print "not ";
19 print "ok ", $ok++, "\n";
20 }
21 ENDEV
22 }
23
24 use Digest::CRCscip-perl cpan Digest-CRC 0.24 Digest/CRC/ qw(crc64 crc32 crc16 crcccitt crc8 crcopenpgparmor
25 crc64_hex crc32_hex crc16_hex crcsaej1850 crcccitt_hex crc8_hex crcopenpgparmor_hex);
26 okscip-perl cpan Digest-CRC 0.24 main/ok().(1, 'use');
27
28 my $input = "123456789";
29 my ($crc32,$crc16,$crcsaej1850,$crcccitt,$crc8) = (crc32scip-perl cpan Digest-CRC 0.24 Digest/CRC/crc32().($input),crc16scip-perl cpan Digest-CRC 0.24 Digest/CRC/crc16().($input),crcsaej1850scip-perl cpan Digest-CRC 0.24 Digest/CRC/crcsaej1850().($input),crcccittscip-perl cpan Digest-CRC 0.24 Digest/CRC/crcccitt().($input),crc8scip-perl cpan Digest-CRC 0.24 Digest/CRC/crc8().($input));
30
31 if ($ENVscip-perl cpan Digest-CRC 0.24 main/`%ENV`.{'WITH_CRC64'}) {
32 my $crc64 = crc64scip-perl cpan Digest-CRC 0.24 Digest/CRC/crc64().($input);
33 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc64 == 5090661014116757502, 'crc64 '.$crc64);
34 $ctxscip-perl cpan Digest-CRC 0.24 main/$ctx. = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(type=>"crc64");
35 $ctxscip-perl cpan Digest-CRC 0.24 main/$ctx.->addscip-perl cpan Digest-CRC 0.24 main/add().($input);
36 $crc64 = $ctxscip-perl cpan Digest-CRC 0.24 main/$ctx.->digestscip-perl cpan Digest-CRC 0.24 main/digest().;
37 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc64 == 5090661014116757502, 'OO crc64 '.$crc64);
38 }
39
40 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc32 == 3421780262, 'crc32');
41 $crc32=$crc32^0xffffffff;
42 okscip-perl cpan Digest-CRC 0.24 main/ok().(crc32scip-perl cpan Digest-CRC 0.24 Digest/CRC/crc32().($input.joinscip-perl cpan Digest-CRC 0.24 main/join().('',
43 mapscip-perl cpan Digest-CRC 0.24 main/map(). {chrscip-perl cpan Digest-CRC 0.24 main/chr().(($crc32>>(8*$_scip-perl cpan Digest-CRC 0.24 main/$_.))&0xff)} (0,1,2,3))) == 0xffffffff,
44 'crc32 Nulltest');
45 okscip-perl cpan Digest-CRC 0.24 main/ok().($crcsaej1850 == 75, 'crcsaej1850');
46 okscip-perl cpan Digest-CRC 0.24 main/ok().($crcccitt == 10673, 'crcccitt');
47 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc16 == 47933, 'crc16');
48 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc8 == 244, 'crc8');
49 okscip-perl cpan Digest-CRC 0.24 main/ok().(($crc8=crc8scip-perl cpan Digest-CRC 0.24 Digest/CRC/crc8().($input.chrscip-perl cpan Digest-CRC 0.24 main/chr().($crc8))) == 0, 'crc8 Nulltest');
50 my $ctx; $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().();
51 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($input);
52 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->digestscip-perl cpan Digest-CRC 0.24 Digest/CRC/digest(). == 3421780262, 'OO crc32');
53
54 $crc32=$crc32^0xffffffff;
55
56
57 # addfile
58 openscip-perl cpan Digest-CRC 0.24 main/open().(F,"<README")||diescip-perl cpan Digest-CRC 0.24 main/die(). "Cannot open README";
59 $ctx->addfilescip-perl cpan Digest-CRC 0.24 Digest/CRC/addfile().(F);
60 closescip-perl cpan Digest-CRC 0.24 main/close().(F);
61 my $y = $ctx->digestscip-perl cpan Digest-CRC 0.24 Digest/CRC/digest().;
62 okscip-perl cpan Digest-CRC 0.24 main/ok().($y == 2527249122, 'OO crc32 with addfile '.$y);
63
64 # start at offset >0 with previous checksum result
65 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(type=>"crc32",cont=>1,init=>460478609);
66 openscip-perl cpan Digest-CRC 0.24 main/open().(F,"<README")||diescip-perl cpan Digest-CRC 0.24 main/die(). "Cannot open README";
67 use Fcntlscip-perl cpan Digest-CRC 0.24 Fcntl/ qw(:seek);
68 seekscip-perl cpan Digest-CRC 0.24 main/seek().(F,989,Fcntl::SEEK_SET);
69 $ctx->addfilescip-perl cpan Digest-CRC 0.24 Digest/CRC/addfile().(F);
70 closescip-perl cpan Digest-CRC 0.24 main/close().(F);
71 $y = $ctx->digestscip-perl cpan Digest-CRC 0.24 Digest/CRC/digest().;
72 okscip-perl cpan Digest-CRC 0.24 main/ok().($y == 2316035660, 'OO crc32 with init and addfile '.$y);
73
74 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(type=>"crcccitt");
75 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($input);
76 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->digestscip-perl cpan Digest-CRC 0.24 Digest/CRC/digest(). == 10673, 'OO crcccitt');
77
78 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(type=>"crc16");
79 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($input);
80 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->digestscip-perl cpan Digest-CRC 0.24 Digest/CRC/digest(). == 47933, 'OO crc16');
81
82 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(width=>16,init=>0,xorout=>0,refout=>1,poly=>0x3456,
83 refin=>1,cont=>0);
84 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($input);
85 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->digestscip-perl cpan Digest-CRC 0.24 Digest/CRC/digest(). == 12803, 'OO crc16 poly 3456');
86
87 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(type=>"crc8");
88 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($input);
89 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->digestscip-perl cpan Digest-CRC 0.24 Digest/CRC/digest(). == 244, 'OO crc8');
90
91 # crc8 test from Mathis Moder <[email protected]>
92 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(width=>8, init=>0xab, xorout=>0x00, refout=>0, poly=>0x07,
93 refin=>0, cont=>0);
94 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($input);
95 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->digestscip-perl cpan Digest-CRC 0.24 Digest/CRC/digest(). == 135, 'OO crc8 init=ab');
96
97 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(width=>8, init=>0xab, xorout=>0xff, refout=>1, poly=>0x07,
98 refin=>1, cont=>0);
99 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().("f1");
100 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->digestscip-perl cpan Digest-CRC 0.24 Digest/CRC/digest(). == 106, 'OO crc8 init=ab, refout');
101
102 $input = joinscip-perl cpan Digest-CRC 0.24 main/join(). '', 'aa'..'zz';
103 ($crc32,$crc16,$crcccitt,$crc8) = (crc32scip-perl cpan Digest-CRC 0.24 Digest/CRC/crc32().($input),crc16scip-perl cpan Digest-CRC 0.24 Digest/CRC/crc16().($input),crcccittscip-perl cpan Digest-CRC 0.24 Digest/CRC/crcccitt().($input),crc8scip-perl cpan Digest-CRC 0.24 Digest/CRC/crc8().($input));
104
105 # some more large messages
106 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc32 == 0xCDA63E54, 'crc32');
107 okscip-perl cpan Digest-CRC 0.24 main/ok().($crcccitt == 0x9702, 'crcccitt');
108 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc16 == 0x0220, 'crc16');
109 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc8 == 0x82, 'crc8');
110
111 # hex digest
112 my $hexinput = "ae";
113 ($crc32,$crc16,$crcccitt,$crc8,$crcopenpgparmorscip-perl cpan Digest-CRC 0.24 main/$crcopenpgparmor.) = (crc32_hexscip-perl cpan Digest-CRC 0.24 Digest/CRC/crc32_hex().($hexinput),crc16_hexscip-perl cpan Digest-CRC 0.24 Digest/CRC/crc16_hex().($hexinput),crcccitt_hexscip-perl cpan Digest-CRC 0.24 Digest/CRC/crcccitt_hex().($hexinput),crc8_hexscip-perl cpan Digest-CRC 0.24 Digest/CRC/crc8_hex().($hexinput),crcopenpgparmor_hexscip-perl cpan Digest-CRC 0.24 Digest/CRC/crcopenpgparmor_hex().($hexinput));
114 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc32 == "00e7ddce", 'crc32_hex'); # width padding to 4 bytes
115 okscip-perl cpan Digest-CRC 0.24 main/ok().($crcccitt == "1917", 'crcccitt_hex');
116 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc16 == "bbe9", 'crc16_hex');
117 okscip-perl cpan Digest-CRC 0.24 main/ok().($crc8 == "dc", 'crc8_hex');
118 okscip-perl cpan Digest-CRC 0.24 main/ok().($crcopenpgparmorscip-perl cpan Digest-CRC 0.24 main/$crcopenpgparmor. == "3e653a", 'crcopenpgparmor_hex');
119
120 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(type=>"crc8");
121 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($hexinput);
122 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->hexdigestscip-perl cpan Digest-CRC 0.24 Digest/CRC/hexdigest(). == "dc", 'OO crc8 hex');
123 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(type=>"crc16");
124 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($hexinput);
125 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->hexdigestscip-perl cpan Digest-CRC 0.24 Digest/CRC/hexdigest(). == "bbe9", 'OO crc16 hex');
126 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(type=>"crc32");
127 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($hexinput);
128 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->hexdigestscip-perl cpan Digest-CRC 0.24 Digest/CRC/hexdigest(). == "00e7ddce", 'OO crc32 hex');
129 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(type=>"crcccitt");
130 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($hexinput);
131 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->hexdigestscip-perl cpan Digest-CRC 0.24 Digest/CRC/hexdigest(). == "1917", 'OO crcccitt hex');
132 $ctx = Digest::CRC->newscip-perl cpan Digest-CRC 0.24 Digest/CRC/new().(type=>"crcopenpgparmor");
133 $ctx->addscip-perl cpan Digest-CRC 0.24 Digest/CRC/add().($hexinput);
134 okscip-perl cpan Digest-CRC 0.24 main/ok().($ctx->hexdigestscip-perl cpan Digest-CRC 0.24 Digest/CRC/hexdigest(). == "3e653a", 'OO crcopenpgparmor hex');
135
136 # openpgparmor
137 my $openpgparmor = crcopenpgparmorscip-perl cpan Digest-CRC 0.24 Digest/CRC/crcopenpgparmor().($input);
138 okscip-perl cpan Digest-CRC 0.24 main/ok().($openpgparmor == 4874579, 'openpgparmor '.$openpgparmor);