| 32 | } // namespace |
| 33 | |
| 34 | UNIT_TEST(VarRecordReader_Simple) |
| 35 | { |
| 36 | vector<uint8_t> data; |
| 37 | char const longString[] = |
| 38 | "0123456789012345678901234567890123456789012345678901234567890123456789" |
| 39 | "012345678901234567890123456789012345678901234567890123456789012345"; |
| 40 | size_t const longStringSize = sizeof(longString) - 1; |
| 41 | TEST_GREATER(longStringSize, 128, ()); |
| 42 | { |
| 43 | MemWriter<vector<uint8_t>> writer(data); |
| 44 | WriteVarUint(writer, 3U); // 0 |
| 45 | writer.Write("abc", 3); // 1 |
| 46 | WriteVarUint(writer, longStringSize); // 4 |
| 47 | writer.Write(longString, longStringSize); // 6 |
| 48 | WriteVarUint(writer, 4U); // 6 + longStringSize |
| 49 | writer.Write("defg", 4); // 7 + longStringSize |
| 50 | // 11 + longStringSize |
| 51 | } |
| 52 | |
| 53 | MemReader reader(&data[0], data.size()); |
| 54 | VarRecordReader<MemReader> recordReader(reader); |
| 55 | |
| 56 | auto r = recordReader.ReadRecord(0); |
| 57 | TEST_EQUAL(string(r.begin(), r.end()), "abc", ()); |
| 58 | |
| 59 | r = recordReader.ReadRecord(6 + longStringSize); |
| 60 | TEST_EQUAL(string(r.begin(), r.end()), "defg", ()); |
| 61 | |
| 62 | r = recordReader.ReadRecord(4); |
| 63 | TEST_EQUAL(string(r.begin(), r.end()), longString, ()); |
| 64 | |
| 65 | vector<pair<uint64_t, string>> forEachCalls; |
| 66 | recordReader.ForEachRecord(SaveForEachParams(forEachCalls)); |
| 67 | vector<pair<uint64_t, string>> expectedForEachCalls = {{0, "abc"}, {4, longString}, {6 + longStringSize, "defg"}}; |
| 68 | TEST_EQUAL(forEachCalls, expectedForEachCalls, ()); |
| 69 | } |
nothing calls this directly
no test coverage detected