test/string_tests.c

changeset 49
1771360b740d
parent 47
22fb97e9f58a
child 69
fb59270b1de3
equal deleted inserted replaced
48:621a4430c404 49:1771360b740d
1 /* 1 /*
2 * 2 *
3 */ 3 */
4 4
5 #include "string_tests.h" 5 #include "string_tests.h"
6
7 UCX_TEST_IMPLEMENT(test_sstr) {
8 sstr_t s1 = sstr("1234");
9 sstr_t s2 = sstrn("ab", 2);
10
11 UCX_TEST_BEGIN
12
13 UCX_TEST_ASSERT(s1.length == 4, "s1 length must be 4");
14 UCX_TEST_ASSERT(s2.length == 2, "s2 length must be 2");
15
16 UCX_TEST_END
17 }
18
19 UCX_TEST_IMPLEMENT(test_sstr_len_cat) {
20 sstr_t s1 = sstr("1234");
21 sstr_t s2 = sstr(".:.:.");
22 sstr_t s3 = sstr("X");
23
24 sstr_t cat;
25
26 size_t len = sstrnlen(3, s1, s2, s3);
27
28 UCX_TEST_BEGIN
29
30 UCX_TEST_ASSERT(len == s1.length + s2.length + s3.length,
31 "sstrnlen returned wrong size");
32
33 len = s1.length + s2.length + s3.length;
34
35 cat.ptr = malloc(len + 1);
36 cat.ptr[len] = 0;
37 cat.length = len;
38
39 sstrncat(3, cat, s1, s2, s3);
40
41 UCX_TEST_ASSERT(cat.ptr[0] == '1', "sstrncat, wrong content");
42 UCX_TEST_ASSERT(cat.ptr[1] == '2', "sstrncat, wrong content");
43 UCX_TEST_ASSERT(cat.ptr[2] == '3', "sstrncat, wrong content");
44 UCX_TEST_ASSERT(cat.ptr[3] == '4', "sstrncat, wrong content");
45 UCX_TEST_ASSERT(cat.ptr[4] == '.', "sstrncat, wrong content");
46 UCX_TEST_ASSERT(cat.ptr[8] == '.', "sstrncat, wrong content");
47 UCX_TEST_ASSERT(cat.ptr[9] == 'X', "sstrncat, wrong content");
48
49 UCX_TEST_END
50
51 free(cat.ptr);
52 }
6 53
7 UCX_TEST_IMPLEMENT(test_sstrsplit) { 54 UCX_TEST_IMPLEMENT(test_sstrsplit) {
8 55
9 const char *original = "this,is,a,csv,string"; 56 const char *original = "this,is,a,csv,string";
10 sstr_t test = sstr("this,is,a,csv,string"); /* use copy of original here */ 57 sstr_t test = sstr("this,is,a,csv,string"); /* use copy of original here */

mercurial