test/utils_tests.c

changeset 223
e18884bbad48
parent 222
e0f850709a5c
child 225
a1a068c2c4ef
equal deleted inserted replaced
222:e0f850709a5c 223:e18884bbad48
89 89
90 free(teststr1); 90 free(teststr1);
91 free(teststr2); 91 free(teststr2);
92 } 92 }
93 93
94 UCX_TEST(test_ucx_sprintf) {
95 UCX_TEST_BEGIN
96
97 sstr_t s1 = ucx_sprintf("int: %d\nHello %s!", 123, "World");
98 UCX_TEST_ASSERT(s1.ptr, "s1.ptr is NULL");
99 UCX_TEST_ASSERT(s1.length == 21, "wrong length");
100 UCX_TEST_ASSERT(!sstrcmp(s1, S("int: 123\nHello World!")), "wrong content");
101 free(s1.ptr);
102
103 sstr_t s2 = ucx_sprintf("Nothing to format!");
104 UCX_TEST_ASSERT(s2.ptr, "s2.ptr is NULL");
105 UCX_TEST_ASSERT(s2.length == 18, "wrong length");
106 UCX_TEST_ASSERT(!memcmp(s2.ptr, "Nothing to format!", 18),
107 "wrong string without format arguments");
108 free(s2.ptr);
109
110 UCX_TEST_END
111 }
112
113 UCX_TEST(test_ucx_bprintf) {
114 UcxBuffer *b = ucx_buffer_new(NULL, 64, UCX_BUFFER_DEFAULT);
115
116 UCX_TEST_BEGIN
117
118 ucx_bprintf(b, "int: %d\nHello %s!", 123, "World");
119 UCX_TEST_ASSERT(b->size == 21, "wrong length");
120 UCX_TEST_ASSERT(!memcmp(b->space, "int: 123\nHello World!", 21),
121 "wrong content");
122
123 ucx_buffer_clear(b);
124
125 ucx_bprintf(b, "Nothing to format!");
126 UCX_TEST_ASSERT(b->size == 18, "wrong length");
127 UCX_TEST_ASSERT(!memcmp(b->space, "Nothing to format!", 18),
128 "wrong string without format arguments");
129
130 UCX_TEST_END
131
132 ucx_buffer_free(b);
133 }
134
94 UCX_TEST(test_ucx_stream_copy) { 135 UCX_TEST(test_ucx_stream_copy) {
95 UcxBuffer *b1 = ucx_buffer_new(NULL, 64, UCX_BUFFER_DEFAULT); 136 UcxBuffer *b1 = ucx_buffer_new(NULL, 64, UCX_BUFFER_DEFAULT);
96 UcxBuffer *b2 = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND); 137 UcxBuffer *b2 = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND);
97 138
98 UCX_TEST_BEGIN 139 UCX_TEST_BEGIN
141 UCX_TEST_END 182 UCX_TEST_END
142 183
143 ucx_buffer_free(b1); 184 ucx_buffer_free(b1);
144 ucx_buffer_free(b2); 185 ucx_buffer_free(b2);
145 } 186 }
187

mercurial