| 24 | typename cs |
| 25 | > |
| 26 | void compress_stream_kernel_test ( |
| 27 | unsigned long seed |
| 28 | ) |
| 29 | /*! |
| 30 | requires |
| 31 | - cs is an implementation of compress_stream/compress_stream_kernel_abstract.h |
| 32 | the alphabet_size for cc is 256 |
| 33 | ensures |
| 34 | - runs tests on cs for compliance with the specs |
| 35 | !*/ |
| 36 | { |
| 37 | |
| 38 | |
| 39 | srand(seed); |
| 40 | |
| 41 | cs test; |
| 42 | |
| 43 | |
| 44 | dlog << LTRACE << 1; |
| 45 | |
| 46 | int count = 0; |
| 47 | while (count < 2) |
| 48 | { |
| 49 | print_spinner(); |
| 50 | istringstream sin; |
| 51 | ostringstream sout; |
| 52 | string buffer; |
| 53 | buffer.reserve(10000); |
| 54 | // fill sin with a bunch of random data in the range 0 to 63 |
| 55 | for (int i = 0; i < 10000; ++i) |
| 56 | { |
| 57 | char temp = static_cast<char>(::rand()&0x3f); |
| 58 | buffer.push_back(temp); |
| 59 | } |
| 60 | |
| 61 | print_spinner(); |
| 62 | sin.str(buffer); |
| 63 | string old_buffer = buffer; |
| 64 | |
| 65 | test.compress(sin,sout); |
| 66 | buffer = sout.str(); |
| 67 | |
| 68 | print_spinner(); |
| 69 | // corrput the data in buffer |
| 70 | buffer[buffer.size()/2]++; |
| 71 | |
| 72 | sin.str(buffer); |
| 73 | sout.str(""); |
| 74 | |
| 75 | bool detected_error = false; |
| 76 | try { |
| 77 | test.decompress(sin,sout); |
| 78 | } catch ( typename cs::decompression_error& ) |
| 79 | { |
| 80 | detected_error = true; |
| 81 | ++count; |
| 82 | } |
| 83 | |