| 53 | |
| 54 | template <typename IntType> |
| 55 | void testCompressedInt(IntType n, StringRef rep = StringRef()) { |
| 56 | BinaryWriter w(AssumeVersion(g_network->protocolVersion())); |
| 57 | CompressedInt<IntType> cn(n); |
| 58 | |
| 59 | w << cn; |
| 60 | if (rep.size() != 0 && w.toValue() != rep) { |
| 61 | printf("WRONG ENCODING:\n"); |
| 62 | printf(" test value (BigE): "); |
| 63 | printBitsLittle(sizeof(IntType), &n); |
| 64 | printf(" encoded: "); |
| 65 | printBitsBig(w.toValue().size(), w.toValue().begin()); |
| 66 | printf(" expected: "); |
| 67 | printBitsBig(rep.size(), rep.begin()); |
| 68 | puts(""); |
| 69 | } else |
| 70 | rep = w.toValue(); |
| 71 | |
| 72 | cn.value = 0; |
| 73 | BinaryReader r(rep, AssumeVersion(g_network->protocolVersion())); |
| 74 | r >> cn; |
| 75 | |
| 76 | if (cn.value != n) { |
| 77 | printf("FAILURE:\n"); |
| 78 | printf(" test value: (Big): "); |
| 79 | printBitsLittle(sizeof(IntType), &n); |
| 80 | printf(" encoded: "); |
| 81 | printBitsBig(rep.size(), rep.begin()); |
| 82 | printf(" decoded value: "); |
| 83 | printBitsLittle(sizeof(IntType), &cn.value); |
| 84 | puts(""); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | TEST_CASE("/flow/compressed_ints") { |
| 89 | testCompressedInt<int>(-2, LiteralStringRef("\x7e")); |
nothing calls this directly
no test coverage detected