tests/test_string.c

changeset 1646
85fd3ff8416e
parent 1582
32b82c424252
equal deleted inserted replaced
1644:bbe3199e37fc 1646:85fd3ff8416e
160 dup.ptr = NULL; 160 dup.ptr = NULL;
161 CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, str)); 161 CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, str));
162 CX_TEST_ASSERT(0 == cx_strcmp(dup, "test str")); 162 CX_TEST_ASSERT(0 == cx_strcmp(dup, "test str"));
163 ASSERT_ZERO_TERMINATED(dup); 163 ASSERT_ZERO_TERMINATED(dup);
164 cx_strfree_a(alloc, &dup); 164 cx_strfree_a(alloc, &dup);
165
166 // copy a plain C-string
167 CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, "a c-string test"));
168 CX_TEST_ASSERT(0 == cx_strcmp(dup, "a c-string test"));
169 ASSERT_ZERO_TERMINATED(dup);
170 cx_strfree_a(alloc, &dup);
165 } 171 }
166 cx_testing_allocator_destroy(&talloc); 172 cx_testing_allocator_destroy(&talloc);
167 } 173 }
168 174
169 CX_TEST(test_strlen) { 175 CX_TEST(test_strlen) {
291 cxmutstr longstr = cx_mutstrn(longstrc, longstrlen); 297 cxmutstr longstr = cx_mutstrn(longstrc, longstrlen);
292 cxstring longstrpattern = cx_strn(longstrpatternc, longstrpatternlen); 298 cxstring longstrpattern = cx_strn(longstrpatternc, longstrpatternlen);
293 cxmutstr longstrresult = cx_mutstrn(longstrc+256, longstrlen-256); 299 cxmutstr longstrresult = cx_mutstrn(longstrc+256, longstrlen-256);
294 300
295 CX_TEST_DO { 301 CX_TEST_DO {
296 cxstring notfound = cx_strstr(str, cx_str("no match")); 302 cxstring notfound = cx_strstr(str, "no match");
297 CX_TEST_ASSERT(notfound.length == 0); 303 CX_TEST_ASSERT(notfound.length == 0);
298 304
299 cxstring result = cx_strstr(str, cx_str("match")); 305 cxstring result = cx_strstr(str, "match");
300 CX_TEST_ASSERT(result.length == 20); 306 CX_TEST_ASSERT(result.length == 20);
301 CX_TEST_ASSERT(0 == strcmp(result.ptr, "match in this string")); 307 CX_TEST_ASSERT(0 == strcmp(result.ptr, "match in this string"));
302 308
303 result = cx_strstr(str, cx_str("")); 309 result = cx_strstr(str, "");
304 CX_TEST_ASSERT(result.length == str.length); 310 CX_TEST_ASSERT(result.length == str.length);
305 CX_TEST_ASSERT(0 == strcmp(result.ptr, str.ptr)); 311 CX_TEST_ASSERT(0 == strcmp(result.ptr, str.ptr));
306 312
307 cxmutstr resultm = cx_strstr_m(longstr, longstrpattern); 313 cxmutstr resultm = cx_strstr_m(longstr, longstrpattern);
308 CX_TEST_ASSERT(resultm.length == longstrresult.length); 314 CX_TEST_ASSERT(resultm.length == longstrresult.length);

mercurial