MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / test_reset

Function test_reset

src/test/test_databuffer_mm.cpp:123–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123int test_reset()
124{
125 std::cout << "\n*** Test reset ***\n";
126
127 const int size_buffer = 20;
128
129 DataBuffer::init(size_buffer);
130
131 const int size_write = 3;
132 const int size_read = size_write;
133
134 const int b = 1;
135 const int e = size_write + 1;
136 std::string data = create_range(b, e);
137
138 // test writing and reading data:
139 {
140 std::vector<uint8_t> bytes(size_read, to_char(99));
141
142 const uint32_t Nw = DataBuffer::write(data);
143
144#if 0
145 if ( Nw != DataBuffer::size() )
146 {
147 std::cout << "*** Test reset: expecting '" << Nw << "' items in buffer, got '" << DataBuffer::size() << "'\n";
148 return EXIT_FAILURE;
149 }
150#endif
151 const uint32_t Nr = DataBuffer::read(size_read, bytes.data());
152
153 if ( Nr != Nw || create_data(bytes) != data)
154 {
155 std::cout << "*** Test reset: expected to read '" << size_read << "', got '" << Nr << "'\n";
156 return EXIT_FAILURE;
157 }
158 }
159
160 // test reading data after reset:
161 {
162 std::vector<uint8_t> bytes(size_read, to_char(99));
163
164 const uint32_t Nw = DataBuffer::write(data);
165
166 // clear buffer, keep allocated memory:
167 std::cout << "*** Test reset: Reset buffer\n";
168 DataBuffer::reset();
169
170 const uint32_t Nr = DataBuffer::read(size_read, bytes.data());
171
172 if ( Nr != 0 || bytes[0] != to_char(99))
173 {
174 std::cout << "*** Test reset: Failed with Nr is '" << Nr << "', bytes[0] is '" << to_int(bytes[0]) << "', expected Nr of 0.\n";
175 print("*** ", data, "\n");
176 print("*** ", bytes, "\n");
177 return EXIT_FAILURE;
178 }
179 }
180

Callers 1

mainFunction · 0.85

Calls 8

initFunction · 0.85
create_rangeFunction · 0.85
to_charFunction · 0.85
sizeClass · 0.85
create_dataFunction · 0.85
to_intFunction · 0.85
dataMethod · 0.80
printFunction · 0.70

Tested by

no test coverage detected