Commit fb4c6c150345c76c73de7cdfcb48caab34c5cab6
1 parent
6d1d2446
Increase coverage for RC4 testing
Showing
2 changed files
with
26 additions
and
1 deletions
libtests/qtest/rc4.test
| ... | ... | @@ -35,9 +35,14 @@ foreach my $key (@tests) |
| 35 | 35 | {$td->FILE => "test$n.in"}); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | +$td->runtest("other tests", | |
| 39 | + {$td->COMMAND => "rc4 other"}, | |
| 40 | + {$td->STRING => "passed\n", $td->EXIT_STATUS => 0}, | |
| 41 | + $td->NORMALIZE_NEWLINES); | |
| 42 | + | |
| 38 | 43 | cleanup(); |
| 39 | 44 | |
| 40 | -$td->report(4 * scalar(@tests)); | |
| 45 | +$td->report(1 + (4 * scalar(@tests))); | |
| 41 | 46 | |
| 42 | 47 | sub cleanup |
| 43 | 48 | { | ... | ... |
libtests/rc4.cc
| ... | ... | @@ -7,9 +7,29 @@ |
| 7 | 7 | #include <string.h> |
| 8 | 8 | #include <iostream> |
| 9 | 9 | #include <stdlib.h> |
| 10 | +#include <cassert> | |
| 11 | + | |
| 12 | +static void other_tests() | |
| 13 | +{ | |
| 14 | + // Test cases not covered by the pipeline: string as key, convert | |
| 15 | + // in place | |
| 16 | + RC4 r(reinterpret_cast<unsigned char const*>("quack")); | |
| 17 | + auto data = std::unique_ptr<unsigned char[]>( | |
| 18 | + new unsigned char[6], std::default_delete<unsigned char[]>()); | |
| 19 | + memcpy(data.get(), "potato", 6); | |
| 20 | + r.process(data.get(), 6); | |
| 21 | + assert(memcmp(data.get(), "\xa5\x6f\xe7\x27\x2b\x5c", 6) == 0); | |
| 22 | + std::cout << "passed" << std::endl; | |
| 23 | +} | |
| 10 | 24 | |
| 11 | 25 | int main(int argc, char* argv[]) |
| 12 | 26 | { |
| 27 | + if ((argc == 2) && (strcmp(argv[1], "other") == 0)) | |
| 28 | + { | |
| 29 | + other_tests(); | |
| 30 | + return 0; | |
| 31 | + } | |
| 32 | + | |
| 13 | 33 | if (argc != 4) |
| 14 | 34 | { |
| 15 | 35 | std::cerr << "Usage: rc4 hex-key infile outfile" << std::endl; | ... | ... |