tests/test_buffer.c

changeset 1028
3e4905241838
parent 1026
ca20f9ffcb62
child 1030
06091e067bee
equal deleted inserted replaced
1027:b1373253e202 1028:3e4905241838
931 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptesting", 11)); 931 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptesting", 11));
932 } 932 }
933 cxBufferDestroy(&buf); 933 cxBufferDestroy(&buf);
934 } 934 }
935 935
936 CX_TEST(test_buffer_put_string_extend_copy_on_write) { 936 CX_TEST(test_buffer_put_string_copy_on_extend) {
937 CxTestingAllocator talloc;
938 cx_testing_allocator_init(&talloc);
939 const CxAllocator *alloc = &talloc.base;
940 CxBuffer buf;
941 char original[16] = "preparedXXXXXXX\0";
942 CX_TEST_DO {
943 cxBufferInit(&buf, original, 16, alloc, CX_BUFFER_COPY_ON_EXTEND);
944 buf.capacity = 8;
945 buf.size = buf.pos = 4;
946 size_t written = cxBufferPutString(&buf, "test");
947 CX_TEST_ASSERT(written == 4);
948 CX_TEST_ASSERT(buf.size == 8);
949 CX_TEST_ASSERT(buf.pos == 8);
950 CX_TEST_ASSERT(buf.capacity == 8);
951 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptest", 8));
952 CX_TEST_ASSERT(original == buf.space);
953 written = cxBufferPutString(&buf, "ing");
954 CX_TEST_ASSERT(written == 3);
955 CX_TEST_ASSERT(buf.size == 11);
956 CX_TEST_ASSERT(buf.pos == 11);
957 CX_TEST_ASSERT(buf.capacity >= 11);
958 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptesting", 11));
959 CX_TEST_ASSERT(original != buf.space);
960 CX_TEST_ASSERT(0 == memcmp(original, "preptestXXXXXXX\0", 16));
961 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc));
962 cxBufferDestroy(&buf);
963 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
964 cx_testing_allocator_destroy(&talloc);
965 }
966 }
967
968 CX_TEST(test_buffer_put_string_copy_on_write) {
937 CxBuffer buf; 969 CxBuffer buf;
938 char original[16] = "preparedXXXXXXX\0"; 970 char original[16] = "preparedXXXXXXX\0";
939 cxBufferInit(&buf, original, 16, cxDefaultAllocator, CX_BUFFER_COPY_ON_WRITE); 971 cxBufferInit(&buf, original, 16, cxDefaultAllocator, CX_BUFFER_COPY_ON_WRITE);
940 buf.capacity = 8; 972 buf.capacity = 8;
941 buf.size = 8; 973 buf.size = 8;
1287 cx_test_register(suite, test_buffer_put_extend); 1319 cx_test_register(suite, test_buffer_put_extend);
1288 cx_test_register(suite, test_buffer_put_copy_on_write); 1320 cx_test_register(suite, test_buffer_put_copy_on_write);
1289 cx_test_register(suite, test_buffer_put_string_fit); 1321 cx_test_register(suite, test_buffer_put_string_fit);
1290 cx_test_register(suite, test_buffer_put_string_discard); 1322 cx_test_register(suite, test_buffer_put_string_discard);
1291 cx_test_register(suite, test_buffer_put_string_extend); 1323 cx_test_register(suite, test_buffer_put_string_extend);
1292 cx_test_register(suite, test_buffer_put_string_extend_copy_on_write); 1324 cx_test_register(suite, test_buffer_put_string_copy_on_extend);
1325 cx_test_register(suite, test_buffer_put_string_copy_on_write);
1293 cx_test_register(suite, test_buffer_terminate); 1326 cx_test_register(suite, test_buffer_terminate);
1294 cx_test_register(suite, test_buffer_write_size_overflow); 1327 cx_test_register(suite, test_buffer_write_size_overflow);
1295 cx_test_register(suite, test_buffer_write_capacity_overflow); 1328 cx_test_register(suite, test_buffer_write_capacity_overflow);
1296 cx_test_register(suite, test_buffer_write_only_overwrite); 1329 cx_test_register(suite, test_buffer_write_only_overwrite);
1297 cx_test_register(suite, test_buffer_write_flush_at_capacity); 1330 cx_test_register(suite, test_buffer_write_flush_at_capacity);

mercurial