test/string_tests.c

Thu, 28 Feb 2013 08:17:26 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 28 Feb 2013 08:17:26 +0100
changeset 102
7c8ebad4d973
parent 100
e0ec80179a5d
child 103
08018864fb91
permissions
-rw-r--r--

added headers that are missing under visual studio

39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 *
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 #include "string_tests.h"
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
7 UCX_TEST_IMPLEMENT(test_sstr) {
74
dc8bade7f2a3 made the code work with g++ and without warnings
Mike Becker <universe@uap-core.de>
parents: 71
diff changeset
8 sstr_t s1 = sstr((char*)"1234");
dc8bade7f2a3 made the code work with g++ and without warnings
Mike Becker <universe@uap-core.de>
parents: 71
diff changeset
9 sstr_t s2 = sstrn((char*)"ab", 2);
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
10
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
11 UCX_TEST_BEGIN
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
12
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
13 UCX_TEST_ASSERT(s1.length == 4, "s1 length must be 4");
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
14 UCX_TEST_ASSERT(s2.length == 2, "s2 length must be 2");
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
15
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
16 UCX_TEST_END
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
17 }
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
18
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
19 UCX_TEST_IMPLEMENT(test_sstr_len_cat) {
74
dc8bade7f2a3 made the code work with g++ and without warnings
Mike Becker <universe@uap-core.de>
parents: 71
diff changeset
20 sstr_t s1 = S("1234");
dc8bade7f2a3 made the code work with g++ and without warnings
Mike Becker <universe@uap-core.de>
parents: 71
diff changeset
21 sstr_t s2 = S(".:.:.");
dc8bade7f2a3 made the code work with g++ and without warnings
Mike Becker <universe@uap-core.de>
parents: 71
diff changeset
22 sstr_t s3 = S("X");
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
23
100
e0ec80179a5d happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
24 size_t len = sstrnlen(3, s1, s2, s3);
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
25 sstr_t cat;
100
e0ec80179a5d happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
26 cat.ptr = (char*) malloc(16);
e0ec80179a5d happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
27 cat.length = 16;
e0ec80179a5d happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
28 cat = sstrncat(3, cat, s1, s2, s3);
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
29
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
30 UCX_TEST_BEGIN
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
31
100
e0ec80179a5d happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
32 UCX_TEST_ASSERT(len == 10, "sstrnlen returned wrong size");
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
33
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
34 UCX_TEST_ASSERT(cat.ptr[0] == '1', "sstrncat, wrong content");
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
35 UCX_TEST_ASSERT(cat.ptr[1] == '2', "sstrncat, wrong content");
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
36 UCX_TEST_ASSERT(cat.ptr[2] == '3', "sstrncat, wrong content");
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
37 UCX_TEST_ASSERT(cat.ptr[3] == '4', "sstrncat, wrong content");
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
38 UCX_TEST_ASSERT(cat.ptr[4] == '.', "sstrncat, wrong content");
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
39 UCX_TEST_ASSERT(cat.ptr[8] == '.', "sstrncat, wrong content");
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
40 UCX_TEST_ASSERT(cat.ptr[9] == 'X', "sstrncat, wrong content");
100
e0ec80179a5d happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
41 UCX_TEST_ASSERT(cat.length == 10, "sstrncat, wrong length");
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
42
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
43 UCX_TEST_END
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
44
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
45 free(cat.ptr);
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
46 }
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
47
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 UCX_TEST_IMPLEMENT(test_sstrsplit) {
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 const char *original = "this,is,a,csv,string";
74
dc8bade7f2a3 made the code work with g++ and without warnings
Mike Becker <universe@uap-core.de>
parents: 71
diff changeset
51 sstr_t test = S("this,is,a,csv,string"); /* use copy of original here */
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 size_t n;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 sstr_t *list;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 UCX_TEST_BEGIN
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 /* Nullpointer check */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 n = 0;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 UCX_TEST_ASSERT(sstrsplit(test, ST(""), &n) == NULL,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 "empty delimiter must return NULL");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 /* no delimiter occurence (ndo) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 n = 0;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 list = sstrsplit(test, ST("z"), &n);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 UCX_TEST_ASSERT(n == 1, "ndo, list length must be 1");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0, "ndo, "
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 "original string shall be returned as single list element");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 "ndo, original has been modified");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 /* partially matching delimiter (pmd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 n = 0;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 list = sstrsplit(test, ST("stringbuilder"), &n);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 UCX_TEST_ASSERT(n == 1, "pmd, list length must be 1");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0, "pmd, "
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 "original string shall be returned as single list element");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 "pmd, original has been modified");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 /* matching single-char delimiter (mscd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 n = 0;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 list = sstrsplit(test, ST(","), &n);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 UCX_TEST_ASSERT(n == 5, "mscd, list length must be 5");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 UCX_TEST_ASSERT(strcmp(list[0].ptr, "this") == 0, "mscd, item 0 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 UCX_TEST_ASSERT(strcmp(list[1].ptr, "is") == 0, "mscd, item 1 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 UCX_TEST_ASSERT(strcmp(list[2].ptr, "a") == 0, "mscd, item 2 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 UCX_TEST_ASSERT(strcmp(list[3].ptr, "csv") == 0, "mscd, item 3 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 UCX_TEST_ASSERT(strcmp(list[4].ptr, "string")==0, "mscd, item 4 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 "mscd, original has been modified");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 /* matching multi-char delimiter (mmcd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 n = 0;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 list = sstrsplit(test, ST("is"), &n);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 UCX_TEST_ASSERT(n == 3, "mscd, list length must be 3");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 UCX_TEST_ASSERT(strcmp(list[0].ptr, "th") == 0, "mmcd, item 0 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 UCX_TEST_ASSERT(strcmp(list[1].ptr, ",") == 0, "mmcd, item 1 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 UCX_TEST_ASSERT(strcmp(list[2].ptr, ",a,csv,string") == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 "mmcd, item 2 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 "mmcd, original has been modified");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 /* bounded list using single-char delimiter (blsc) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 n = 3;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 list = sstrsplit(test, ST(","), &n);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 UCX_TEST_ASSERT(n == 3, "blsc, list length must be 3");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 UCX_TEST_ASSERT(strcmp(list[0].ptr, "this") == 0, "blsc, item 0 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 UCX_TEST_ASSERT(strcmp(list[1].ptr, "is") == 0, "blsc, item 1 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 UCX_TEST_ASSERT(strcmp(list[2].ptr, "a,csv,string") == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 "blsc, item 2 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 "blsc, original has been modified");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 /* bounded list using multi-char delimiter (blmc) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 n = 2;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 list = sstrsplit(test, ST("is"), &n);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 UCX_TEST_ASSERT(n == 2, "blmc, list length must be 2");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 UCX_TEST_ASSERT(strcmp(list[0].ptr, "th") == 0, "blmc, item 0 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 UCX_TEST_ASSERT(strcmp(list[1].ptr, ",is,a,csv,string") == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 "blmc, item 1 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 "blmc, original has been modified");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 /* start with delimiter (swd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 n = 0;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 list = sstrsplit(test, ST("this"), &n);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 UCX_TEST_ASSERT(n == 2, "swd, list length must be 2");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 UCX_TEST_ASSERT(list[0].length == 0, "swd, first item must be empty");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 UCX_TEST_ASSERT(strcmp(list[1].ptr, ",is,a,csv,string") == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 "swd, second item corrupt");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 "swd, original has been modified");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 /* end with delimiter (ewd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 n = 0;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 list = sstrsplit(test, ST("string"), &n);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 UCX_TEST_ASSERT(n == 2, "ewd, list length must be 2");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 UCX_TEST_ASSERT(strcmp(list[0].ptr, "this,is,a,csv,") == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 "swd, first item corrupt");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 UCX_TEST_ASSERT(list[1].length == 0, "ewd, second item must be empty");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 "ewd, original has been modified");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 /* exact match (exm) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 n = 0;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 list = sstrsplit(test, ST("this,is,a,csv,string"), &n);
71
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
155 UCX_TEST_ASSERT(n == 0, "exm, list length must be 0");
303dabadff1c made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
156 UCX_TEST_ASSERT(list == NULL, "exm, list must be NULL");
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 /* substring (subs) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 n = 0;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 list = sstrsplit(test, ST("this,is,a,csv,string,with,extension"), &n);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 UCX_TEST_ASSERT(n == 1, "subs, list length must be 1");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 "subs, single item must be the original string");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 "subs, original has been modified");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 UCX_TEST_END
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 }
97
499e1b465d77 fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents: 74
diff changeset
171
499e1b465d77 fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents: 74
diff changeset
172 UCX_TEST_IMPLEMENT(test_sstrtrim) {
100
e0ec80179a5d happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
173 sstr_t test = sstrtrim(sstr((char*)" ein test "));
e0ec80179a5d happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
174 sstr_t empty = sstrtrim(sstr((char*)""));
97
499e1b465d77 fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents: 74
diff changeset
175 UCX_TEST_BEGIN
499e1b465d77 fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents: 74
diff changeset
176 UCX_TEST_ASSERT(strncmp(test.ptr, "ein test", test.length) == 0, "failed");
98
0a752853f792 fixed sstrtrim for empty strings
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
177 UCX_TEST_ASSERT(empty.length == 0, "empty string failed");
97
499e1b465d77 fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents: 74
diff changeset
178 UCX_TEST_END
499e1b465d77 fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents: 74
diff changeset
179 }

mercurial