50 CX_TEST_ASSERT(strncmp(s2.ptr, "ab", 2) == 0); |
50 CX_TEST_ASSERT(strncmp(s2.ptr, "ab", 2) == 0); |
51 CX_TEST_ASSERT(s3.length == 4); |
51 CX_TEST_ASSERT(s3.length == 4); |
52 CX_TEST_ASSERT(strncmp(s3.ptr, "1234", 4) == 0); |
52 CX_TEST_ASSERT(strncmp(s3.ptr, "1234", 4) == 0); |
53 CX_TEST_ASSERT(s4.length == 2); |
53 CX_TEST_ASSERT(s4.length == 2); |
54 CX_TEST_ASSERT(strncmp(s4.ptr, "ab", 2) == 0); |
54 CX_TEST_ASSERT(strncmp(s4.ptr, "ab", 2) == 0); |
|
55 } |
|
56 } |
|
57 |
|
58 CX_TEST(test_string_cast) { |
|
59 char *c1 = (char*) "123"; |
|
60 const char *c2 = "abcde"; |
|
61 unsigned char *c3 = (unsigned char*) "4711"; |
|
62 unsigned const char *c4 = (unsigned const char*) "xyz0815"; |
|
63 cxstring s1 = cx_strcast(c1); |
|
64 cxstring s2 = cx_strcast(c2); |
|
65 cxstring s3 = cx_strcast(c3); |
|
66 cxstring s4 = cx_strcast(c4); |
|
67 CX_TEST_DO { |
|
68 CX_TEST_ASSERT(s1.length == 3); |
|
69 CX_TEST_ASSERT(strncmp(s1.ptr, "123", 3) == 0); |
|
70 CX_TEST_ASSERT(s2.length == 5); |
|
71 CX_TEST_ASSERT(strncmp(s2.ptr, "abcde", 5) == 0); |
|
72 CX_TEST_ASSERT(s3.length == 4); |
|
73 CX_TEST_ASSERT(strncmp(s3.ptr, "4711", 4) == 0); |
|
74 CX_TEST_ASSERT(s4.length == 7); |
|
75 CX_TEST_ASSERT(strncmp(s4.ptr, "xyz0815", 7) == 0); |
55 } |
76 } |
56 } |
77 } |
57 |
78 |
58 CX_TEST(test_strfree) { |
79 CX_TEST(test_strfree) { |
59 CxTestingAllocator talloc; |
80 CxTestingAllocator talloc; |
1312 |
1333 |
1313 CxTestSuite *cx_test_suite_string(void) { |
1334 CxTestSuite *cx_test_suite_string(void) { |
1314 CxTestSuite *suite = cx_test_suite_new("string"); |
1335 CxTestSuite *suite = cx_test_suite_new("string"); |
1315 |
1336 |
1316 cx_test_register(suite, test_string_construct); |
1337 cx_test_register(suite, test_string_construct); |
|
1338 cx_test_register(suite, test_string_cast); |
1317 cx_test_register(suite, test_strfree); |
1339 cx_test_register(suite, test_strfree); |
1318 cx_test_register(suite, test_strdup); |
1340 cx_test_register(suite, test_strdup); |
1319 cx_test_register(suite, test_strdup_shortened); |
1341 cx_test_register(suite, test_strdup_shortened); |
1320 cx_test_register(suite, test_strcpy); |
1342 cx_test_register(suite, test_strcpy); |
1321 cx_test_register(suite, test_strlen); |
1343 cx_test_register(suite, test_strlen); |