tests/test_string.c

changeset 1685
0344372c7115
parent 1680
1aa21afb8763
child 1693
c2d05cf1a062
equal deleted inserted replaced
1684:89a07d18f86c 1685:0344372c7115
589 errno = 0; 589 errno = 0;
590 cxmutstr z = cx_strcat(CX_NULLSTR, 3, a, b, c); 590 cxmutstr z = cx_strcat(CX_NULLSTR, 3, a, b, c);
591 CX_TEST_ASSERT(errno == EOVERFLOW); 591 CX_TEST_ASSERT(errno == EOVERFLOW);
592 CX_TEST_ASSERT(z.ptr == NULL); 592 CX_TEST_ASSERT(z.ptr == NULL);
593 CX_TEST_ASSERT(z.length == 0); 593 CX_TEST_ASSERT(z.length == 0);
594 }
595 cx_testing_allocator_destroy(&talloc);
596 }
597
598 CX_TEST(test_strcat_zero) {
599 CxTestingAllocator talloc;
600 cx_testing_allocator_init(&talloc);
601 CxAllocator *alloc = &talloc.base;
602
603 CX_TEST_DO {
604 cxmutstr t1 = cx_strcat_a(alloc, CX_NULLSTR, 0);
605 CX_TEST_ASSERT(0 == cx_strcmp(t1, ""));
606 ASSERT_ZERO_TERMINATED(t1);
607 cx_strfree_a(alloc, &t1);
608
609 cxmutstr s2 = cx_strdup_a(alloc, "testing");
610 s2.length = 4;
611 cxmutstr t2 = cx_strcat_a(alloc, s2, 0);
612 CX_TEST_ASSERT(0 == cx_strcmp(t2, "test"));
613 ASSERT_ZERO_TERMINATED(t2);
614 cx_strfree_a(alloc, &t2);
615
616 cxmutstr s3 = cx_strdup_a(alloc, "fake");
617 s3.length = 0;
618 cxmutstr t3 = cx_strcat_a(alloc, s3, 0);
619 CX_TEST_ASSERT(0 == cx_strcmp(t3, ""));
620 ASSERT_ZERO_TERMINATED(t3);
621 cx_strfree_a(alloc, &t3);
622
623 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
594 } 624 }
595 cx_testing_allocator_destroy(&talloc); 625 cx_testing_allocator_destroy(&talloc);
596 } 626 }
597 627
598 CX_TEST(test_strcat_more_than_eight) { 628 CX_TEST(test_strcat_more_than_eight) {
1682 cx_test_register(suite, test_strrchr_m); 1712 cx_test_register(suite, test_strrchr_m);
1683 cx_test_register(suite, test_strstr); 1713 cx_test_register(suite, test_strstr);
1684 cx_test_register(suite, test_strcmp); 1714 cx_test_register(suite, test_strcmp);
1685 cx_test_register(suite, test_strcasecmp); 1715 cx_test_register(suite, test_strcasecmp);
1686 cx_test_register(suite, test_strcat); 1716 cx_test_register(suite, test_strcat);
1717 cx_test_register(suite, test_strcat_zero);
1687 cx_test_register(suite, test_strcat_more_than_eight); 1718 cx_test_register(suite, test_strcat_more_than_eight);
1688 cx_test_register(suite, test_strsplit); 1719 cx_test_register(suite, test_strsplit);
1689 cx_test_register(suite, test_strsplit_a); 1720 cx_test_register(suite, test_strsplit_a);
1690 cx_test_register(suite, test_strtrim); 1721 cx_test_register(suite, test_strtrim);
1691 cx_test_register(suite, test_strprefix); 1722 cx_test_register(suite, test_strprefix);

mercurial