| 22 | } |
| 23 | |
| 24 | static void test_stream_reader() |
| 25 | { |
| 26 | test_convert(Bytes{}, Bytes{}); |
| 27 | |
| 28 | /* Simple one-byte intervals */ |
| 29 | test_convert(Bytes{0x20, 0x20, 0x20, 0x20}, Bytes{0x8f, 0x8f, 0x8f, 0x8f}); |
| 30 | |
| 31 | /* One-and-a-half-byte intervals */ |
| 32 | test_convert(Bytes{0x20, 0x00, 0x10, 0x20, 0x01, 0x10, 0x20}, |
| 33 | Bytes{0x8f, 0x87, 0x8f, 0x3f, 0x3f, 0x89, 0x8f}); |
| 34 | |
| 35 | /* Two-byte intervals */ |
| 36 | test_convert(Bytes{0x20, 0x0c, 0x00, 0x10, 0x20, 0x0c, 0x01, 0x10, 0x20}, |
| 37 | Bytes{0x8f, 0x87, 0x8f, 0x3f, 0x3f, 0x89, 0x8f}); |
| 38 | |
| 39 | /* Overflow */ |
| 40 | test_convert(Bytes{0x20, 0x0b, 0x10, 0x20}, |
| 41 | Bytes{0x8f} + (Bytes{0x3f} * 0x207) + Bytes{0xa9, 0x8f}); |
| 42 | |
| 43 | /* Single-byte nop */ |
| 44 | test_convert(Bytes{0x20, 0x08, 0x20}, Bytes{0x8f, 0x8f}); |
| 45 | |
| 46 | /* Double-byte nop */ |
| 47 | test_convert(Bytes{0x20, 0x09, 0xde, 0x20}, Bytes{0x8f, 0x8f}); |
| 48 | |
| 49 | /* Triple-byte nop */ |
| 50 | test_convert(Bytes{0x20, 0x0a, 0xde, 0xad, 0x20}, Bytes{0x8f, 0x8f}); |
| 51 | |
| 52 | /* OOB block */ |
| 53 | test_convert( |
| 54 | Bytes{ |
| 55 | 0x20, /* data before */ |
| 56 | 0x0d, /* OOB */ |
| 57 | 0xaa, /* type byte */ |
| 58 | 0x01, |
| 59 | 0x00, /* size of payload, little-endian */ |
| 60 | 0x55, /* payload */ |
| 61 | 0x20 /* data continues */ |
| 62 | }, |
| 63 | Bytes{0x8f, 0x8f}); |
| 64 | } |
| 65 | |
| 66 | int main(int argc, const char* argv[]) |
| 67 | { |