MCPcopy Create free account
hub / github.com/comaps/comaps / UNIT_TEST

Function UNIT_TEST

libs/coding/coding_tests/var_record_reader_test.cpp:34–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32} // namespace
33
34UNIT_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}

Callers

nothing calls this directly

Calls 8

WriteVarUintFunction · 0.85
SaveForEachParamsClass · 0.85
ReadRecordMethod · 0.80
ForEachRecordMethod · 0.80
WriteMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected