Mon, 14 Jul 2014 12:45:48 +0200
removed old sstrncat
39 | 1 | /* |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
39 | 3 | * |
177
11ad03783baf
go ahead, nothing to see here
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
4 | * Copyright 2014 Olaf Wintermann. All rights reserved. |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
5 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
8 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
11 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
15 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
39 | 27 | */ |
28 | ||
29 | #include "string_tests.h" | |
30 | ||
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
123
diff
changeset
|
31 | UCX_TEST(test_sstr) { |
74
dc8bade7f2a3
made the code work with g++ and without warnings
Mike Becker <universe@uap-core.de>
parents:
71
diff
changeset
|
32 | 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
|
33 | sstr_t s2 = sstrn((char*)"ab", 2); |
47
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 | UCX_TEST_BEGIN |
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
36 | |
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
37 | 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
|
38 | 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
|
39 | |
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
40 | UCX_TEST_END |
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
41 | } |
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
42 | |
179 | 43 | UCX_TEST(test_sstr_len) { |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
44 | sstr_t s1 = ST("1234"); |
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
45 | sstr_t s2 = ST(".:.:."); |
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
46 | sstr_t s3 = ST("X"); |
47
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
47 | |
100
e0ec80179a5d
happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents:
98
diff
changeset
|
48 | size_t len = sstrnlen(3, s1, s2, s3); |
47
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
49 | |
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
50 | UCX_TEST_BEGIN |
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
51 | |
100
e0ec80179a5d
happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents:
98
diff
changeset
|
52 | UCX_TEST_ASSERT(len == 10, "sstrnlen returned wrong size"); |
179 | 53 | |
47
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
54 | UCX_TEST_END |
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
55 | } |
22fb97e9f58a
sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
56 | |
149 | 57 | UCX_TEST(test_sstrchr_sstrrchr) { |
148 | 58 | sstr_t str = ST("I will find you - and I will kill you"); |
59 | UCX_TEST_BEGIN | |
60 | ||
61 | sstr_t result = sstrchr(str, 'w'); | |
62 | UCX_TEST_ASSERT(result.length == 35, "sstrchr returned wrong length"); | |
63 | UCX_TEST_ASSERT(strcmp("will find you - and I will kill you", result.ptr) | |
64 | == 0, "sstrchr did not return the expected string"); | |
65 | ||
66 | result = sstrrchr(str, 'w'); | |
67 | UCX_TEST_ASSERT(result.length == 13, "sstrrchr returned wrong length"); | |
68 | UCX_TEST_ASSERT(strcmp("will kill you", result.ptr) | |
69 | == 0, "sstrrchr did not return the expected string"); | |
70 | ||
71 | UCX_TEST_END | |
72 | } | |
73 | ||
149 | 74 | UCX_TEST(test_sstrcmp) { |
75 | sstr_t str = ST("compare this"); | |
76 | ||
77 | UCX_TEST_BEGIN | |
78 | UCX_TEST_ASSERT(sstrcmp(str, S("compare this")) == 0, "false negative"); | |
79 | UCX_TEST_ASSERT(sstrcmp(str, S("Compare This")) != 0, "false positive"); | |
80 | UCX_TEST_ASSERT(sstrcmp(str, S("compare tool")) < 0, "memcmp < 0 failed"); | |
81 | UCX_TEST_ASSERT(sstrcmp(str, S("compare shit")) > 0, "memcmp > 0 failed"); | |
82 | UCX_TEST_ASSERT(sstrcmp(str, S("compare this not")) < 0, "len < 0 failed"); | |
83 | UCX_TEST_ASSERT(sstrcmp(str, S("compare")) > 0, "len > 0 failed"); | |
84 | UCX_TEST_END | |
85 | } | |
86 | ||
87 | UCX_TEST(test_sstrcasecmp) { | |
88 | ||
89 | sstr_t str = ST("compare this"); | |
90 | ||
91 | UCX_TEST_BEGIN | |
92 | UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this")) == 0, "false negative"); | |
93 | UCX_TEST_ASSERT(sstrcasecmp(str, S("Compare This")) == 0, | |
94 | "not ignoring case"); | |
95 | UCX_TEST_ASSERT(sstrcasecmp(str, S("compare tool")) < 0, "< 0 failed"); | |
96 | UCX_TEST_ASSERT(sstrcasecmp(str, S("compare shit")) > 0, "> 0 failed"); | |
97 | UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this not")) < 0, | |
98 | "len < 0 failed"); | |
99 | UCX_TEST_ASSERT(sstrcasecmp(str, S("compare")) > 0, "len > 0 failed"); | |
100 | UCX_TEST_END | |
101 | } | |
102 | ||
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
123
diff
changeset
|
103 | UCX_TEST(test_sstrsplit) { |
39 | 104 | |
105 | const char *original = "this,is,a,csv,string"; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
106 | sstr_t test = ST("this,is,a,csv,string"); /* use copy of original here */ |
173
31a8682fffb7
fixed some sstring issues + added allocator macros
Mike Becker <universe@uap-core.de>
parents:
149
diff
changeset
|
107 | ssize_t n; |
39 | 108 | sstr_t *list; |
109 | ||
110 | UCX_TEST_BEGIN | |
111 | ||
112 | /* Nullpointer check */ | |
113 | n = 0; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
114 | UCX_TEST_ASSERT(sstrsplit(test, S(""), &n) == NULL, |
39 | 115 | "empty delimiter must return NULL"); |
116 | ||
117 | /* no delimiter occurence (ndo) */ | |
118 | n = 0; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
119 | list = sstrsplit(test, S("z"), &n); |
39 | 120 | UCX_TEST_ASSERT(n == 1, "ndo, list length must be 1"); |
121 | UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0, "ndo, " | |
122 | "original string shall be returned as single list element"); | |
123 | UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, | |
124 | "ndo, original has been modified"); | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
125 | for(int i=0;i<n;i++) { |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
126 | free(list[i].ptr); |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
127 | } |
39 | 128 | free(list); |
129 | ||
130 | /* partially matching delimiter (pmd) */ | |
131 | n = 0; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
132 | list = sstrsplit(test, S("stringbuilder"), &n); |
39 | 133 | UCX_TEST_ASSERT(n == 1, "pmd, list length must be 1"); |
134 | UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0, "pmd, " | |
135 | "original string shall be returned as single list element"); | |
136 | UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, | |
137 | "pmd, original has been modified"); | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
138 | for(int i=0;i<n;i++) { |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
139 | free(list[i].ptr); |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
140 | } |
39 | 141 | free(list); |
142 | ||
143 | /* matching single-char delimiter (mscd) */ | |
144 | n = 0; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
145 | list = sstrsplit(test, S(","), &n); |
39 | 146 | UCX_TEST_ASSERT(n == 5, "mscd, list length must be 5"); |
147 | UCX_TEST_ASSERT(strcmp(list[0].ptr, "this") == 0, "mscd, item 0 mismatch"); | |
148 | UCX_TEST_ASSERT(strcmp(list[1].ptr, "is") == 0, "mscd, item 1 mismatch"); | |
149 | UCX_TEST_ASSERT(strcmp(list[2].ptr, "a") == 0, "mscd, item 2 mismatch"); | |
150 | UCX_TEST_ASSERT(strcmp(list[3].ptr, "csv") == 0, "mscd, item 3 mismatch"); | |
151 | UCX_TEST_ASSERT(strcmp(list[4].ptr, "string")==0, "mscd, item 4 mismatch"); | |
152 | UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, | |
153 | "mscd, original has been modified"); | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
154 | for(int i=0;i<n;i++) { |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
155 | free(list[i].ptr); |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
156 | } |
39 | 157 | free(list); |
158 | ||
159 | /* matching multi-char delimiter (mmcd) */ | |
160 | n = 0; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
161 | list = sstrsplit(test, S("is"), &n); |
39 | 162 | UCX_TEST_ASSERT(n == 3, "mscd, list length must be 3"); |
163 | UCX_TEST_ASSERT(strcmp(list[0].ptr, "th") == 0, "mmcd, item 0 mismatch"); | |
164 | UCX_TEST_ASSERT(strcmp(list[1].ptr, ",") == 0, "mmcd, item 1 mismatch"); | |
165 | UCX_TEST_ASSERT(strcmp(list[2].ptr, ",a,csv,string") == 0, | |
166 | "mmcd, item 2 mismatch"); | |
167 | UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, | |
168 | "mmcd, original has been modified"); | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
169 | for(int i=0;i<n;i++) { |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
170 | free(list[i].ptr); |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
171 | } |
39 | 172 | free(list); |
173 | ||
174 | /* bounded list using single-char delimiter (blsc) */ | |
175 | n = 3; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
176 | list = sstrsplit(test, S(","), &n); |
39 | 177 | UCX_TEST_ASSERT(n == 3, "blsc, list length must be 3"); |
178 | UCX_TEST_ASSERT(strcmp(list[0].ptr, "this") == 0, "blsc, item 0 mismatch"); | |
179 | UCX_TEST_ASSERT(strcmp(list[1].ptr, "is") == 0, "blsc, item 1 mismatch"); | |
180 | UCX_TEST_ASSERT(strcmp(list[2].ptr, "a,csv,string") == 0, | |
181 | "blsc, item 2 mismatch"); | |
182 | UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, | |
183 | "blsc, original has been modified"); | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
184 | for(int i=0;i<n;i++) { |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
185 | free(list[i].ptr); |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
186 | } |
39 | 187 | free(list); |
188 | ||
189 | /* bounded list using multi-char delimiter (blmc) */ | |
190 | n = 2; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
191 | list = sstrsplit(test, S("is"), &n); |
39 | 192 | UCX_TEST_ASSERT(n == 2, "blmc, list length must be 2"); |
193 | UCX_TEST_ASSERT(strcmp(list[0].ptr, "th") == 0, "blmc, item 0 mismatch"); | |
194 | UCX_TEST_ASSERT(strcmp(list[1].ptr, ",is,a,csv,string") == 0, | |
195 | "blmc, item 1 mismatch"); | |
196 | UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, | |
197 | "blmc, original has been modified"); | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
198 | for(int i=0;i<n;i++) { |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
199 | free(list[i].ptr); |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
200 | } |
39 | 201 | free(list); |
202 | ||
203 | /* start with delimiter (swd) */ | |
204 | n = 0; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
205 | list = sstrsplit(test, S("this"), &n); |
39 | 206 | UCX_TEST_ASSERT(n == 2, "swd, list length must be 2"); |
207 | UCX_TEST_ASSERT(list[0].length == 0, "swd, first item must be empty"); | |
208 | UCX_TEST_ASSERT(strcmp(list[1].ptr, ",is,a,csv,string") == 0, | |
209 | "swd, second item corrupt"); | |
210 | UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, | |
211 | "swd, original has been modified"); | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
212 | for(int i=0;i<n;i++) { |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
213 | free(list[i].ptr); |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
214 | } |
39 | 215 | free(list); |
216 | ||
217 | /* end with delimiter (ewd) */ | |
218 | n = 0; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
219 | list = sstrsplit(test, S("string"), &n); |
39 | 220 | UCX_TEST_ASSERT(n == 2, "ewd, list length must be 2"); |
221 | UCX_TEST_ASSERT(strcmp(list[0].ptr, "this,is,a,csv,") == 0, | |
222 | "swd, first item corrupt"); | |
223 | UCX_TEST_ASSERT(list[1].length == 0, "ewd, second item must be empty"); | |
224 | UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, | |
225 | "ewd, original has been modified"); | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
226 | for(int i=0;i<n;i++) { |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
227 | free(list[i].ptr); |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
228 | } |
39 | 229 | free(list); |
230 | ||
231 | /* exact match (exm) */ | |
232 | n = 0; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
233 | list = sstrsplit(test, S("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
|
234 | 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
|
235 | UCX_TEST_ASSERT(list == NULL, "exm, list must be NULL"); |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
236 | for(int i=0;i<n;i++) { |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
237 | free(list[i].ptr); |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
238 | } |
39 | 239 | free(list); |
240 | ||
241 | /* substring (subs) */ | |
242 | n = 0; | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
104
diff
changeset
|
243 | list = sstrsplit(test, S("this,is,a,csv,string,with,extension"), &n); |
39 | 244 | UCX_TEST_ASSERT(n == 1, "subs, list length must be 1"); |
245 | UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0, | |
246 | "subs, single item must be the original string"); | |
247 | UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, | |
248 | "subs, original has been modified"); | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
249 | for(int i=0;i<n;i++) { |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
250 | free(list[i].ptr); |
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
146
diff
changeset
|
251 | } |
39 | 252 | free(list); |
253 | ||
254 | UCX_TEST_END | |
255 | } | |
97
499e1b465d77
fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents:
74
diff
changeset
|
256 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
123
diff
changeset
|
257 | UCX_TEST(test_sstrtrim) { |
104
9d3dea320d8e
fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
258 | sstr_t t1 = sstrtrim(sstr((char*)" ein test ")); |
9d3dea320d8e
fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
259 | sstr_t t2 = sstrtrim(sstr((char*)"abc")); |
9d3dea320d8e
fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
260 | sstr_t t3 = sstrtrim(sstr((char*)" 123")); |
9d3dea320d8e
fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
261 | sstr_t t4 = sstrtrim(sstr((char*)"xyz ")); |
9d3dea320d8e
fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
262 | sstr_t t5 = sstrtrim(sstr((char*)" ")); |
100
e0ec80179a5d
happy 100th commit + removed deprecated sstrcat + fixed sstrncat
Mike Becker <universe@uap-core.de>
parents:
98
diff
changeset
|
263 | 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
|
264 | UCX_TEST_BEGIN |
104
9d3dea320d8e
fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
265 | UCX_TEST_ASSERT(strncmp(t1.ptr, "ein test", t1.length) == 0, "failed"); |
9d3dea320d8e
fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
266 | UCX_TEST_ASSERT(strncmp(t2.ptr, "abc", t2.length) == 0, "failed"); |
9d3dea320d8e
fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
267 | UCX_TEST_ASSERT(strncmp(t3.ptr, "123", t3.length) == 0, "failed"); |
9d3dea320d8e
fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
268 | UCX_TEST_ASSERT(strncmp(t4.ptr, "xyz", t4.length) == 0, "failed"); |
9d3dea320d8e
fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
269 | UCX_TEST_ASSERT(t5.length == 0, "string t5 not empty"); |
98
0a752853f792
fixed sstrtrim for empty strings
Mike Becker <universe@uap-core.de>
parents:
97
diff
changeset
|
270 | 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
|
271 | UCX_TEST_END |
499e1b465d77
fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents:
74
diff
changeset
|
272 | } |
146
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
273 | |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
274 | UCX_TEST(test_sstrprefixsuffix) { |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
275 | sstr_t str = ST("test my prefix and my suffix"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
276 | sstr_t empty = ST(""); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
277 | |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
278 | UCX_TEST_BEGIN |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
279 | |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
280 | UCX_TEST_ASSERT(!sstrprefix(empty, S("pref")), "prefix empty string fails"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
281 | UCX_TEST_ASSERT(!sstrsuffix(empty, S("suf")), "suffix empty string fails"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
282 | |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
283 | UCX_TEST_ASSERT(sstrprefix(str, empty), "empty prefix fails"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
284 | UCX_TEST_ASSERT(sstrsuffix(str, empty), "empty suffix fails"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
285 | |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
286 | UCX_TEST_ASSERT(sstrprefix(empty, empty), "string and prefix empty fails"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
287 | UCX_TEST_ASSERT(sstrsuffix(empty, empty), "string and suffix empty fails"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
288 | |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
289 | UCX_TEST_ASSERT(sstrprefix(str, S("test ")), "prefix false negative"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
290 | UCX_TEST_ASSERT(!sstrprefix(str, S("8-) fsck ")), "prefix false positive"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
291 | |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
292 | UCX_TEST_ASSERT(sstrsuffix(str, S("fix")), "suffix false negative"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
293 | UCX_TEST_ASSERT(!sstrsuffix(str, S("fox")), "suffix false positive"); |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
294 | |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
295 | |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
296 | UCX_TEST_END |
aa376dba1ba8
fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
297 | } |