test/string_tests.c

Wed, 10 Oct 2012 09:32:06 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 10 Oct 2012 09:32:06 +0200
changeset 58
733f22fca61a
parent 47
22fb97e9f58a
child 69
fb59270b1de3
permissions
-rw-r--r--

discarded memprintf / memscanf

Reason: memscanf has no chance to get the amount of bytes read

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

mercurial