| 1 | # $Id: test.pl,v 1.1 2000/08/27 23:12:24 mikem Exp $ | ||||||||||
| 2 | # Before `make install' is performed this script should be runnable with | ||||||||||
| 3 | # `make test'. After `make install' it should work as `perl test.pl' | ||||||||||
| 4 | |||||||||||
| 5 | ######################### We start with some black magic to print on failure. | ||||||||||
| 6 | |||||||||||
| 7 | # Change 1..1 below to 1..last_test_to_print . | ||||||||||
| 8 | # (It may become useful if the test is moved to ./t subdirectory.) | ||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | BEGIN {print "1..16\n";} | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | END {print "not ok 1\n" unless $loaded;} | ||||||||
|
Subroutine
END: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||
| 12 | 1 | ▶ | use File::RsyncP::Digest; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | $loaded = 1; | |||||||||
| 14 | 1 | print "ok 1\n"; | |||||||||
| 15 | |||||||||||
| 16 | ######################### End of black magic. | ||||||||||
| 17 | |||||||||||
| 18 | # Insert your test code below (better if it prints "ok 13" | ||||||||||
| 19 | # (correspondingly "not ok 13") depending on the success of chunk 13 | ||||||||||
| 20 | # of the test code): | ||||||||||
| 21 | |||||||||||
| 22 | package MD4Test; | ||||||||||
| 23 | |||||||||||
| 24 | # 2: Constructor | ||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | print (($md4 = new File::RsyncP::Digest) ? "ok 2\n" : "not ok 2\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | # 3: Basic test data as defined in RFC 1320 (buggy version) | ||||||||||
| 29 | |||||||||||
| 30 | 1 | %data26 = ( | |||||||||
| 31 | "" => "0123456789abcdeffedcba9876543210", | ||||||||||
| 32 | "a" => "bde52cb31de33e46245e05fbdbd6fb24", | ||||||||||
| 33 | "abc" => "a448017aaf21d8525fc10ae87aa6729d", | ||||||||||
| 34 | "message digest" | ||||||||||
| 35 | => "d9130a8164549fe818874806e1c7014b", | ||||||||||
| 36 | "abcdefghijklmnopqrstuvwxyz" | ||||||||||
| 37 | => "d79e1c308aa5bbcdeea8ed63df412da9", | ||||||||||
| 38 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" | ||||||||||
| 39 | => "043f8582f241db351ce627e153e7f0e4", | ||||||||||
| 40 | "12345678901234567890123456789012345678901234567890123456789012345678901234567890" | ||||||||||
| 41 | => "e33b4ddc9c38f2199c3e7b164fcc0536", | ||||||||||
| 42 | # From draft-ietf-pppext-mschap-00.txt: | ||||||||||
| 43 | "\x4D\x00\x79\x00\x50\x00\x77\x00" => "fc156af7edcd6c0edde3337d427f4eac", | ||||||||||
| 44 | ); | ||||||||||
| 45 | |||||||||||
| 46 | 1 | $failed = 0; | |||||||||
| 47 | 1 | foreach (sort(keys(%data26))) | |||||||||
| 48 | { | ||||||||||
| 49 | 8 | $md4->reset; | |||||||||
| 50 | 8 | $md4->protocol(26); | |||||||||
| 51 | 8 | $md4->add($_); | |||||||||
| 52 | 8 | $digest = $md4->digest; | |||||||||
| 53 | 8 | $hex = unpack("H*", $digest); | |||||||||
| 54 | 8 | ▶ | if ($hex ne $data26{$_}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | { | ||||||||||
| 56 | 0 | $failed++; | |||||||||
| 57 | } | ||||||||||
| 58 | } | ||||||||||
| 59 | 1 | ▶ | print ($failed ? "not ok 3\n" : "ok 3\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | |||||||||||
| 61 | # 4: Various flavours of file-handle to addfile | ||||||||||
| 62 | |||||||||||
| 63 | 1 | open(F, "<$0"); | |||||||||
| 64 | |||||||||||
| 65 | 1 | $md4->reset; | |||||||||
| 66 | |||||||||||
| 67 | 1 | $md4->addfile(F); | |||||||||
| 68 | 1 | $hex = $md4->hexdigest; | |||||||||
| 69 | 1 | ▶ | print ($hex ne '' ? "ok 4\n" : "not ok 4\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | |||||||||||
| 71 | 1 | $orig = $hex; | |||||||||
| 72 | |||||||||||
| 73 | # 5: Fully qualified with ' operator | ||||||||||
| 74 | |||||||||||
| 75 | 1 | seek(F, 0, 0); | |||||||||
| 76 | 1 | $md4->reset; | |||||||||
| 77 | 1 | $md4->addfile(MD4Test'F); | |||||||||
| 78 | 1 | $hex = $md4->hexdigest; | |||||||||
| 79 | 1 | ▶ | print ($hex eq $orig ? "ok 5\n" : "not ok 5\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | |||||||||||
| 81 | # 6: Fully qualified with :: operator | ||||||||||
| 82 | |||||||||||
| 83 | 1 | seek(F, 0, 0); | |||||||||
| 84 | 1 | $md4->reset; | |||||||||
| 85 | 1 | $md4->addfile(MD4Test::F); | |||||||||
| 86 | 1 | $hex = $md4->hexdigest; | |||||||||
| 87 | 1 | ▶ | print ($hex eq $orig ? "ok 6\n" : "not ok 6\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | |||||||||||
| 89 | # 7: Type glob | ||||||||||
| 90 | |||||||||||
| 91 | 1 | seek(F, 0, 0); | |||||||||
| 92 | 1 | $md4->reset; | |||||||||
| 93 | 1 | $md4->addfile(*F); | |||||||||
| 94 | 1 | $hex = $md4->hexdigest; | |||||||||
| 95 | 1 | ▶ | print ($hex eq $orig ? "ok 7\n" : "not ok 7\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | |||||||||||
| 97 | # 8: Type glob reference (the prefered mechanism) | ||||||||||
| 98 | |||||||||||
| 99 | 1 | seek(F, 0, 0); | |||||||||
| 100 | 1 | $md4->reset; | |||||||||
| 101 | 1 | $md4->addfile(\*F); | |||||||||
| 102 | 1 | $hex = $md4->hexdigest; | |||||||||
| 103 | 1 | ▶ | print ($hex eq $orig ? "ok 8\n" : "not ok 8\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | |||||||||||
| 105 | # 9: File-handle passed by name (really the same as 6) | ||||||||||
| 106 | |||||||||||
| 107 | 1 | seek(F, 0, 0); | |||||||||
| 108 | 1 | $md4->reset; | |||||||||
| 109 | 1 | $md4->addfile("MD4Test::F"); | |||||||||
| 110 | 1 | $hex = $md4->hexdigest; | |||||||||
| 111 | 1 | ▶ | print ($hex eq $orig ? "ok 9\n" : "not ok 9\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | |||||||||||
| 113 | # 10: Other ways of reading the data -- line at a time | ||||||||||
| 114 | |||||||||||
| 115 | 1 | seek(F, 0, 0); | |||||||||
| 116 | 1 | $md4->reset; | |||||||||
| 117 | 1 | ▶ | while (<F>) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | { | ||||||||||
| 119 | 224 | $md4->add($_); | |||||||||
| 120 | } | ||||||||||
| 121 | 1 | $hex = $md4->hexdigest; | |||||||||
| 122 | 1 | ▶ | print ($hex eq $orig ? "ok 10\n" : "not ok 10\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | |||||||||||
| 124 | # 11: Input lines as a list to add() | ||||||||||
| 125 | |||||||||||
| 126 | 1 | seek(F, 0, 0); | |||||||||
| 127 | 1 | $md4->reset; | |||||||||
| 128 | 1 | $md4->add(<F>); | |||||||||
| 129 | 1 | $hex = $md4->hexdigest; | |||||||||
| 130 | 1 | ▶ | print ($hex eq $orig ? "ok 11\n" : "not ok 11\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | |||||||||||
| 132 | # 12: Random chunks up to 128 bytes | ||||||||||
| 133 | |||||||||||
| 134 | 1 | seek(F, 0, 0); | |||||||||
| 135 | 1 | $md4->reset; | |||||||||
| 136 | 1 | ▶ | while (read(F, $hexata, (rand % 128) + 1)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | { | ||||||||||
| 138 | 5608 | $md4->add($hexata); | |||||||||
| 139 | } | ||||||||||
| 140 | 1 | $hex = $md4->hexdigest; | |||||||||
| 141 | 1 | ▶ | print ($hex eq $orig ? "ok 12\n" : "not ok 12\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | |||||||||||
| 143 | # 13: All the data at once | ||||||||||
| 144 | |||||||||||
| 145 | 1 | seek(F, 0, 0); | |||||||||
| 146 | 1 | $md4->reset; | |||||||||
| 147 | 1 | undef $/; | |||||||||
| 148 | 1 | $data = <F>; | |||||||||
| 149 | 1 | $hex = $md4->hexhash($data); | |||||||||
| 150 | 1 | ▶ | print ($hex eq $orig ? "ok 13\n" : "not ok 13\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 151 | |||||||||||
| 152 | 1 | close(F); | |||||||||
| 153 | |||||||||||
| 154 | # 14: Using static member function | ||||||||||
| 155 | |||||||||||
| 156 | 1 | $hex = File::RsyncP::Digest->hexhash($data); | |||||||||
| 157 | 1 | ▶ | print ($hex eq $orig ? "ok 14\n" : "not ok 14\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | |||||||||||
| 159 | # 15: Basic test data as defined in RFC 1320 (non-buggy version) | ||||||||||
| 160 | |||||||||||
| 161 | 1 | %data27 = ( | |||||||||
| 162 | "" => "31d6cfe0d16ae931b73c59d7e0c089c0", | ||||||||||
| 163 | "a" => "bde52cb31de33e46245e05fbdbd6fb24", | ||||||||||
| 164 | "abc" => "a448017aaf21d8525fc10ae87aa6729d", | ||||||||||
| 165 | "message digest" | ||||||||||
| 166 | => "d9130a8164549fe818874806e1c7014b", | ||||||||||
| 167 | "abcdefghijklmnopqrstuvwxyz" | ||||||||||
| 168 | => "d79e1c308aa5bbcdeea8ed63df412da9", | ||||||||||
| 169 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" | ||||||||||
| 170 | => "043f8582f241db351ce627e153e7f0e4", | ||||||||||
| 171 | "12345678901234567890123456789012345678901234567890123456789012345678901234567890" | ||||||||||
| 172 | => "e33b4ddc9c38f2199c3e7b164fcc0536", | ||||||||||
| 173 | # From draft-ietf-pppext-mschap-00.txt: | ||||||||||
| 174 | "\x4D\x00\x79\x00\x50\x00\x77\x00" => "fc156af7edcd6c0edde3337d427f4eac", | ||||||||||
| 175 | ); | ||||||||||
| 176 | |||||||||||
| 177 | 1 | $failed = 0; | |||||||||
| 178 | 1 | foreach (sort(keys(%data27))) | |||||||||
| 179 | { | ||||||||||
| 180 | 8 | $md4->reset; | |||||||||
| 181 | 8 | $md4->protocol(27); | |||||||||
| 182 | 8 | $md4->add($_); | |||||||||
| 183 | 8 | $digest = $md4->digest; | |||||||||
| 184 | 8 | $hex = unpack("H*", $digest); | |||||||||
| 185 | 8 | ▶ | if ($hex ne $data27{$_}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 186 | { | ||||||||||
| 187 | 0 | $failed++; | |||||||||
| 188 | } | ||||||||||
| 189 | } | ||||||||||
| 190 | 1 | ▶ | print ($failed ? "not ok 15\n" : "ok 15\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 191 | |||||||||||
| 192 | # 16: test data using both buggy and non-buggy versions | ||||||||||
| 193 | |||||||||||
| 194 | 1 | %data27 = ( | |||||||||
| 195 | "" => "31d6cfe0d16ae931b73c59d7e0c089c0", | ||||||||||
| 196 | "a" => "bde52cb31de33e46245e05fbdbd6fb24", | ||||||||||
| 197 | "abc" => "a448017aaf21d8525fc10ae87aa6729d", | ||||||||||
| 198 | "message digest" | ||||||||||
| 199 | => "d9130a8164549fe818874806e1c7014b", | ||||||||||
| 200 | "abcdefghijklmnopqrstuvwxyz" | ||||||||||
| 201 | => "d79e1c308aa5bbcdeea8ed63df412da9", | ||||||||||
| 202 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" | ||||||||||
| 203 | => "043f8582f241db351ce627e153e7f0e4", | ||||||||||
| 204 | "12345678901234567890123456789012345678901234567890123456789012345678901234567890" | ||||||||||
| 205 | => "e33b4ddc9c38f2199c3e7b164fcc0536", | ||||||||||
| 206 | # From draft-ietf-pppext-mschap-00.txt: | ||||||||||
| 207 | "\x4D\x00\x79\x00\x50\x00\x77\x00" => "fc156af7edcd6c0edde3337d427f4eac", | ||||||||||
| 208 | ); | ||||||||||
| 209 | |||||||||||
| 210 | 1 | $failed = 0; | |||||||||
| 211 | 1 | foreach (sort(keys(%data27))) | |||||||||
| 212 | { | ||||||||||
| 213 | 8 | $md4->reset; | |||||||||
| 214 | 8 | $md4->protocol(27); | |||||||||
| 215 | 8 | $md4->add($_); | |||||||||
| 216 | 8 | $digest = $md4->digest2; | |||||||||
| 217 | 8 | $hex = unpack("H*", $digest); | |||||||||
| 218 | 8 | ▶ | if ($hex ne "$data26{$_}$data27{$_}" ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 219 | { | ||||||||||
| 220 | 0 | $failed++; | |||||||||
| 221 | } | ||||||||||
| 222 | } | ||||||||||
| 223 | 1 | ▶ | print ($failed ? "not ok 16\n" : "ok 16\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 224 | |||||||||||