test/buffer_tests.c

changeset 269
591473851c95
parent 259
2f5dea574a75
child 290
d5d6ab809ad3
equal deleted inserted replaced
268:00e88487a654 269:591473851c95
340 buffer[i] = 40+i; 340 buffer[i] = 40+i;
341 } 341 }
342 342
343 UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); 343 UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT);
344 b->size = b->capacity; 344 b->size = b->capacity;
345
346 unsigned char ubuffer[] = {127, 128, 129, 130};
347 UcxBuffer *ub = ucx_buffer_new(ubuffer, 4, UCX_BUFFER_DEFAULT);
348 ub->size = 4;
345 349
346 UCX_TEST_BEGIN 350 UCX_TEST_BEGIN
347 351
348 char rb[16]; 352 char rb[16];
349 for (size_t i = 0 ; i < 16 ; i++) { 353 for (size_t i = 0 ; i < 16 ; i++) {
358 UCX_TEST_ASSERT(b->pos == 16, "wrong position after EOF"); 362 UCX_TEST_ASSERT(b->pos == 16, "wrong position after EOF");
359 363
360 UCX_TEST_ASSERT(ucx_buffer_getc(b) == EOF, 364 UCX_TEST_ASSERT(ucx_buffer_getc(b) == EOF,
361 "out of bounds read does not return EOF"); 365 "out of bounds read does not return EOF");
362 UCX_TEST_ASSERT(b->pos == 16, "wrong position after out of bounds read"); 366 UCX_TEST_ASSERT(b->pos == 16, "wrong position after out of bounds read");
363 367
364 UCX_TEST_END 368 int uc[5];
365 369 for(int i=0;i<5;i++) {
366 ucx_buffer_free(b); 370 uc[i] = ucx_buffer_getc(ub);
371 }
372 UCX_TEST_ASSERT(uc[0] == 127, "wrong unsigned value(0)");
373 UCX_TEST_ASSERT(uc[1] == 128, "wrong unsigned value(0)");
374 UCX_TEST_ASSERT(uc[2] == 129, "wrong unsigned value(0)");
375 UCX_TEST_ASSERT(uc[3] == 130, "wrong unsigned value(0)");
376 UCX_TEST_ASSERT(uc[4] == EOF, "EOF not set after last ub read");
377
378 UCX_TEST_END
379
380 ucx_buffer_free(b);
381 ucx_buffer_free(ub);
367 free(buffer); 382 free(buffer);
368 } 383 }
369 384
370 UCX_TEST(test_ucx_buffer_write) { 385 UCX_TEST(test_ucx_buffer_write) {
371 char *buffer = (char*) malloc(32); 386 char *buffer = (char*) malloc(32);

mercurial