| 61 CX_TEST_ASSERT(0 == cx_strcmp(snull, "")); |
61 CX_TEST_ASSERT(0 == cx_strcmp(snull, "")); |
| 62 CX_TEST_ASSERT(0 == cx_strcmp(mnull, "")); |
62 CX_TEST_ASSERT(0 == cx_strcmp(mnull, "")); |
| 63 } |
63 } |
| 64 } |
64 } |
| 65 |
65 |
| 66 CX_TEST(test_string_cast) { |
66 CX_TEST(test_strcast) { |
| 67 char *c1 = (char*) "123"; |
67 char *c1 = (char*) "123"; |
| 68 const char *c2 = "abcde"; |
68 const char *c2 = "abcde"; |
| 69 unsigned char *c3 = (unsigned char*) "4711"; |
69 unsigned char *c3 = (unsigned char*) "4711"; |
| 70 unsigned const char *c4 = (unsigned const char*) "xyz0815"; |
70 unsigned const char *c4 = (unsigned const char*) "xyz0815"; |
| |
71 cxstring c5 = cx_str("foobar"); |
| |
72 cxmutstr c6 = cx_mutstr((char*)"hello world"); |
| 71 cxstring s1 = cx_strcast(c1); |
73 cxstring s1 = cx_strcast(c1); |
| 72 cxstring s2 = cx_strcast(c2); |
74 cxstring s2 = cx_strcast(c2); |
| 73 cxstring s3 = cx_strcast(c3); |
75 cxstring s3 = cx_strcast(c3); |
| 74 cxstring s4 = cx_strcast(c4); |
76 cxstring s4 = cx_strcast(c4); |
| |
77 cxstring s5 = cx_strcast(c5); |
| |
78 cxstring s6 = cx_strcast(c6); |
| 75 CX_TEST_DO { |
79 CX_TEST_DO { |
| 76 CX_TEST_ASSERT(s1.length == 3); |
80 CX_TEST_ASSERT(s1.length == 3); |
| 77 CX_TEST_ASSERT(strncmp(s1.ptr, "123", 3) == 0); |
81 CX_TEST_ASSERT(strncmp(s1.ptr, "123", 3) == 0); |
| 78 CX_TEST_ASSERT(s2.length == 5); |
82 CX_TEST_ASSERT(s2.length == 5); |
| 79 CX_TEST_ASSERT(strncmp(s2.ptr, "abcde", 5) == 0); |
83 CX_TEST_ASSERT(strncmp(s2.ptr, "abcde", 5) == 0); |
| 80 CX_TEST_ASSERT(s3.length == 4); |
84 CX_TEST_ASSERT(s3.length == 4); |
| 81 CX_TEST_ASSERT(strncmp(s3.ptr, "4711", 4) == 0); |
85 CX_TEST_ASSERT(strncmp(s3.ptr, "4711", 4) == 0); |
| 82 CX_TEST_ASSERT(s4.length == 7); |
86 CX_TEST_ASSERT(s4.length == 7); |
| 83 CX_TEST_ASSERT(strncmp(s4.ptr, "xyz0815", 7) == 0); |
87 CX_TEST_ASSERT(strncmp(s4.ptr, "xyz0815", 7) == 0); |
| |
88 CX_TEST_ASSERT(s5.length == 6); |
| |
89 CX_TEST_ASSERT(strncmp(s5.ptr, "foobar", 6) == 0); |
| |
90 CX_TEST_ASSERT(s6.length == 11); |
| |
91 CX_TEST_ASSERT(strncmp(s6.ptr, "hello world", 11) == 0); |
| |
92 } |
| |
93 } |
| |
94 |
| |
95 CX_TEST(test_strcast_m) { |
| |
96 char *c1 = (char*) "123"; |
| |
97 const char *c2 = "abcde"; |
| |
98 unsigned char *c3 = (unsigned char*) "4711"; |
| |
99 unsigned const char *c4 = (unsigned const char*) "xyz0815"; |
| |
100 cxstring c5 = cx_str("foobar"); |
| |
101 cxmutstr c6 = cx_mutstr((char*)"hello world"); |
| |
102 cxmutstr s1 = cx_strcast_m(c1); |
| |
103 cxstring s2 = cx_strcast_m(c2); |
| |
104 cxmutstr s3 = cx_strcast_m(c3); |
| |
105 cxstring s4 = cx_strcast_m(c4); |
| |
106 cxstring s5 = cx_strcast_m(c5); |
| |
107 cxmutstr s6 = cx_strcast_m(c6); |
| |
108 CX_TEST_DO { |
| |
109 CX_TEST_ASSERT(s1.length == 3); |
| |
110 CX_TEST_ASSERT(strncmp(s1.ptr, "123", 3) == 0); |
| |
111 CX_TEST_ASSERT(s2.length == 5); |
| |
112 CX_TEST_ASSERT(strncmp(s2.ptr, "abcde", 5) == 0); |
| |
113 CX_TEST_ASSERT(s3.length == 4); |
| |
114 CX_TEST_ASSERT(strncmp(s3.ptr, "4711", 4) == 0); |
| |
115 CX_TEST_ASSERT(s4.length == 7); |
| |
116 CX_TEST_ASSERT(strncmp(s4.ptr, "xyz0815", 7) == 0); |
| |
117 CX_TEST_ASSERT(s5.length == 6); |
| |
118 CX_TEST_ASSERT(strncmp(s5.ptr, "foobar", 6) == 0); |
| |
119 CX_TEST_ASSERT(s6.length == 11); |
| |
120 CX_TEST_ASSERT(strncmp(s6.ptr, "hello world", 11) == 0); |
| 84 } |
121 } |
| 85 } |
122 } |
| 86 |
123 |
| 87 CX_TEST(test_strfree) { |
124 CX_TEST(test_strfree) { |
| 88 CxTestingAllocator talloc; |
125 CxTestingAllocator talloc; |
| 1511 |
1548 |
| 1512 CX_TEST(test_strformat) { |
1549 CX_TEST(test_strformat) { |
| 1513 cxstring str = cx_str("Hello, World!"); |
1550 cxstring str = cx_str("Hello, World!"); |
| 1514 CX_TEST_DO { |
1551 CX_TEST_DO { |
| 1515 char actual[64]; |
1552 char actual[64]; |
| 1516 snprintf(actual, 64, "Test %"CX_PRIstr " Success.", CX_SFMT(str)); |
1553 snprintf(actual, 64, "Test %" CX_PRIstr " Success.", CX_SFMT(str)); |
| 1517 CX_TEST_ASSERT(0 == strncmp("Test Hello, World! Success.", actual, 64)); |
1554 CX_TEST_ASSERT(0 == strncmp("Test Hello, World! Success.", actual, 64)); |
| 1518 } |
1555 } |
| 1519 } |
1556 } |
| 1520 |
1557 |
| 1521 CxTestSuite *cx_test_suite_string(void) { |
1558 CxTestSuite *cx_test_suite_string(void) { |
| 1522 CxTestSuite *suite = cx_test_suite_new("string"); |
1559 CxTestSuite *suite = cx_test_suite_new("string"); |
| 1523 |
1560 |
| 1524 cx_test_register(suite, test_string_construct); |
1561 cx_test_register(suite, test_string_construct); |
| 1525 cx_test_register(suite, test_string_cast); |
1562 cx_test_register(suite, test_strcast); |
| |
1563 cx_test_register(suite, test_strcast_m); |
| 1526 cx_test_register(suite, test_strfree); |
1564 cx_test_register(suite, test_strfree); |
| 1527 cx_test_register(suite, test_strdup); |
1565 cx_test_register(suite, test_strdup); |
| 1528 cx_test_register(suite, test_strdup_shortened); |
1566 cx_test_register(suite, test_strdup_shortened); |
| 1529 cx_test_register(suite, test_strcpy); |
1567 cx_test_register(suite, test_strcpy); |
| 1530 cx_test_register(suite, test_strlen); |
1568 cx_test_register(suite, test_strlen); |