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

Function UNIT_TEST

libs/coding/coding_tests/files_container_tests.cpp:22–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20using namespace std;
21
22UNIT_TEST(FilesContainer_Smoke)
23{
24 string const fName = "files_container.tmp";
25 FileWriter::DeleteFileX(fName);
26 size_t const count = 10;
27
28 // fill container one by one
29 {
30 FilesContainerW writer(fName);
31
32 for (size_t i = 0; i < count; ++i)
33 {
34 auto w = writer.GetWriter(strings::to_string(i));
35
36 for (uint32_t j = 0; j < i; ++j)
37 WriteVarUint(w, j);
38 }
39 }
40
41 // read container one by one
42 {
43 FilesContainerR reader(fName);
44
45 for (size_t i = 0; i < count; ++i)
46 {
47 FilesContainerR::TReader r = reader.GetReader(strings::to_string(i));
48 ReaderSource<FilesContainerR::TReader> src(r);
49
50 for (uint32_t j = 0; j < i; ++j)
51 {
52 uint32_t const test = ReadVarUint<uint32_t>(src);
53 TEST_EQUAL(j, test, ());
54 }
55 }
56 }
57
58 // append to container
59 uint32_t const arrAppend[] = {888, 777, 666};
60 for (size_t i = 0; i < ARRAY_SIZE(arrAppend); ++i)
61 {
62 {
63 FilesContainerW writer(fName, FileWriter::OP_WRITE_EXISTING);
64
65 auto w = writer.GetWriter(strings::to_string(arrAppend[i]));
66 WriteVarUint(w, arrAppend[i]);
67 }
68
69 // read appended
70 {
71 FilesContainerR reader(fName);
72
73 FilesContainerR::TReader r = reader.GetReader(strings::to_string(arrAppend[i]));
74 ReaderSource<FilesContainerR::TReader> src(r);
75
76 uint32_t const test = ReadVarUint<uint32_t>(src);
77 TEST_EQUAL(arrAppend[i], test, ());
78 }
79 }

Callers

nothing calls this directly

Calls 15

DeleteFileXFunction · 0.85
to_stringFunction · 0.85
WriteVarUintFunction · 0.85
WriteToSinkFunction · 0.85
CheckInvariantFunction · 0.85
ReplaceInContainerFunction · 0.85
CheckContainerFunction · 0.85
TESTFunction · 0.85
GetWriterMethod · 0.80
GetReaderMethod · 0.45
FlushMethod · 0.45
SubReaderMethod · 0.45

Tested by

no test coverage detected