256 buf.pos = 3; |
256 buf.pos = 3; |
257 cxBufferClear(&buf); |
257 cxBufferClear(&buf); |
258 EXPECT_EQ(memcmp(space, "\0\0\0\0\0 test", 10), 0); |
258 EXPECT_EQ(memcmp(space, "\0\0\0\0\0 test", 10), 0); |
259 EXPECT_EQ(buf.size, 0); |
259 EXPECT_EQ(buf.size, 0); |
260 EXPECT_EQ(buf.pos, 0); |
260 EXPECT_EQ(buf.pos, 0); |
261 } |
261 cxBufferDestroy(&buf); |
|
262 } |
|
263 |
|
264 class BufferWrite : public ::testing::Test { |
|
265 protected: |
|
266 CxBuffer buf{}; |
|
267 |
|
268 void SetUp() override { |
|
269 cxBufferInit(&buf, nullptr, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); |
|
270 buf.capacity = 8; // artificially reduce capacity to check OOB writes |
|
271 memset(buf.space, 0, 16); |
|
272 memcpy(buf.space, "prep", 4); |
|
273 buf.size = buf.pos = 4; |
|
274 } |
|
275 |
|
276 void TearDown() override { |
|
277 cxBufferDestroy(&buf); |
|
278 } |
|
279 }; |
|
280 |
|
281 TEST_F(BufferWrite, SizeOneFit) { |
|
282 const char *data = "test"; |
|
283 ASSERT_EQ(buf.capacity, 8); |
|
284 ASSERT_EQ(buf.pos, 4); |
|
285 size_t written = cxBufferWrite(data, 1, 4, &buf); |
|
286 EXPECT_EQ(written, 4); |
|
287 EXPECT_EQ(buf.size, 8); |
|
288 EXPECT_EQ(buf.pos, 8); |
|
289 EXPECT_EQ(buf.capacity, 8); |
|
290 EXPECT_EQ(memcmp(buf.space, "preptest", 8), 0); |
|
291 } |
|
292 |
|
293 TEST_F(BufferWrite, SizeOneOverwrite) { |
|
294 |
|
295 } |
|
296 |
|
297 TEST_F(BufferWrite, SizeOnePartialOverwrite) { |
|
298 |
|
299 } |
|
300 |
|
301 TEST_F(BufferWrite, SizeOneDiscard) { |
|
302 const char *data = "testing"; |
|
303 ASSERT_EQ(buf.capacity, 8); |
|
304 ASSERT_EQ(buf.pos, 4); |
|
305 size_t written = cxBufferWrite(data, 1, 7, &buf); |
|
306 EXPECT_EQ(written, 4); |
|
307 EXPECT_EQ(buf.size, 8); |
|
308 EXPECT_EQ(buf.pos, 8); |
|
309 EXPECT_EQ(buf.capacity, 8); |
|
310 EXPECT_EQ(memcmp(buf.space, "preptest\0", 9), 0); |
|
311 } |
|
312 |
|
313 TEST_F(BufferWrite, SizeOneExtend) { |
|
314 buf.flags |= CX_BUFFER_AUTO_EXTEND; |
|
315 const char *data = "testing"; |
|
316 ASSERT_EQ(buf.capacity, 8); |
|
317 ASSERT_EQ(buf.pos, 4); |
|
318 size_t written = cxBufferWrite(data, 1, 7, &buf); |
|
319 EXPECT_EQ(written, 7); |
|
320 EXPECT_EQ(buf.size, 11); |
|
321 EXPECT_EQ(buf.pos, 11); |
|
322 EXPECT_GE(buf.capacity, 11); |
|
323 EXPECT_EQ(memcmp(buf.space, "preptesting", 11), 0); |
|
324 } |
|
325 |
|
326 TEST_F(BufferWrite, MultibyteOverwrite) { |
|
327 |
|
328 } |
|
329 |
|
330 TEST_F(BufferWrite, MultibytePartialOverwrite) { |
|
331 |
|
332 } |
|
333 |
|
334 TEST_F(BufferWrite, MultibyteFit) { |
|
335 |
|
336 } |
|
337 |
|
338 TEST_F(BufferWrite, MultibyteDiscard) { |
|
339 // remember: whole elements are discarded if they do not fit |
|
340 } |
|
341 |
|
342 TEST_F(BufferWrite, MultibyteExtend) { |
|
343 |
|
344 } |
|
345 |
|
346 TEST_F(BufferWrite, PutcWrapperFit) { |
|
347 |
|
348 } |
|
349 |
|
350 TEST_F(BufferWrite, PutcWrapperOverwrite) { |
|
351 |
|
352 } |
|
353 |
|
354 TEST_F(BufferWrite, PutcWrapperPartialOverwrite) { |
|
355 |
|
356 } |
|
357 |
|
358 TEST_F(BufferWrite, PutcWrapperDiscard) { |
|
359 |
|
360 } |
|
361 |
|
362 TEST_F(BufferWrite, PutcWrapperExtend) { |
|
363 |
|
364 } |
|
365 |
|
366 TEST_F(BufferWrite, PutStringWrapperFit) { |
|
367 |
|
368 } |
|
369 |
|
370 TEST_F(BufferWrite, PutStringWrapperOverwrite) { |
|
371 |
|
372 } |
|
373 |
|
374 TEST_F(BufferWrite, PutStringWrapperPartialOverwrite) { |
|
375 |
|
376 } |
|
377 |
|
378 TEST_F(BufferWrite, PutStringWrapperDiscard) { |
|
379 |
|
380 } |
|
381 |
|
382 TEST_F(BufferWrite, PutStringWrapperExtend) { |
|
383 |
|
384 } |