tests/test_string.c

changeset 1667
608cc0b25352
parent 1652
db8299984bfe
child 1668
3ffdfe1776b4
--- a/tests/test_string.c	Wed Dec 24 12:13:59 2025 +0100
+++ b/tests/test_string.c	Thu Dec 25 11:10:13 2025 +0100
@@ -376,22 +376,26 @@
     CxAllocator *alloc = &talloc.base;
 
     CX_TEST_DO {
-        cxmutstr t1 = cx_strcat_a(alloc, 2, s1, s2);
+        cxmutstr t1 = {0};
+        CX_TEST_ASSERT(0 == cx_strcat_a(alloc, &t1, 2, s1, s2));
         CX_TEST_ASSERT(0 == cx_strcmp(t1, "1234"));
         ASSERT_ZERO_TERMINATED(t1);
         cx_strfree_a(alloc, &t1);
 
-        cxmutstr t2 = cx_strcat_a(alloc, 3, s1, s2, s3);
+        cxmutstr t2 = {0};
+        CX_TEST_ASSERT(0 == cx_strcat_a(alloc, &t2, 3, s1, s2, s3));
         CX_TEST_ASSERT(0 == cx_strcmp(t2, "123456"));
         ASSERT_ZERO_TERMINATED(t2);
         cx_strfree_a(alloc, &t2);
 
-        cxmutstr t3 = cx_strcat_a(alloc, 6, s1, sn, s2, sn, s3, sn);
+        cxmutstr t3 = {0};
+        CX_TEST_ASSERT(0 == cx_strcat_a(alloc, &t3, 6, s1, sn, s2, sn, s3, sn));
         CX_TEST_ASSERT(0 == cx_strcmp(t3, "123456"));
         ASSERT_ZERO_TERMINATED(t3);
         cx_strfree_a(alloc, &t3);
 
-        cxmutstr t4 = cx_strcat_a(alloc, 2, sn, sn);
+        cxmutstr t4 = {0};
+        CX_TEST_ASSERT(0 == cx_strcat_a(alloc, &t4, 2, sn, sn));
         CX_TEST_ASSERT(0 == cx_strcmp(t4, ""));
         ASSERT_ZERO_TERMINATED(t4);
         cx_strfree_a(alloc, &t4);
@@ -399,14 +403,15 @@
         CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
 
         // use the macro
-        cxmutstr t5 = cx_strcat(3, s3, s1, s2);
+        cxmutstr t5 = {0};
+        CX_TEST_ASSERT(0 == cx_strcat(&t5, 3, s3, s1, s2));
         CX_TEST_ASSERT(0 == cx_strcmp(t5, "561234"));
         ASSERT_ZERO_TERMINATED(t5);
         cx_strfree(&t5);
 
         // use an initial string
         cxmutstr t6 = cx_strdup(cx_str("Hello"));
-        t6 = cx_strcat_m(t6, 2, cx_str(", "), cx_str("World!"));
+        CX_TEST_ASSERT(0 == cx_strcat(&t6, 2, cx_str(", "), cx_str("World!")));
         CX_TEST_ASSERT(0 == cx_strcmp(t6, "Hello, World!"));
         ASSERT_ZERO_TERMINATED(t6);
         cx_strfree(&t6);
@@ -417,7 +422,8 @@
         cxstring b = cx_strn(fakestr, SIZE_MAX / 3 - 5);
         cxstring c = cx_strn(fakestr, SIZE_MAX / 3 + 20);
         errno = 0;
-        cxmutstr z = cx_strcat(3, a, b, c);
+        cxmutstr z = {0};
+        CX_TEST_ASSERT(0 != cx_strcat(&z, 3, a, b, c));
         CX_TEST_ASSERT(errno == EOVERFLOW);
         CX_TEST_ASSERT(z.ptr == NULL);
         CX_TEST_ASSERT(z.length == 0);
@@ -437,7 +443,8 @@
     cxstring s9 = cx_str("xy");
 
     CX_TEST_DO {
-        cxmutstr r = cx_strcat(9, s1, s2, s3, s4, s5, s6, s7, s8, s9);
+        cxmutstr r = {0};
+        CX_TEST_ASSERT(0 == cx_strcat(&r, 9, s1, s2, s3, s4, s5, s6, s7, s8, s9));
         CX_TEST_ASSERT(0 == cx_strcmp(r, "123456789abcdef0xy"));
         ASSERT_ZERO_TERMINATED(r);
         cx_strfree(&r);

mercurial