test/string_tests.c

Sun, 24 Nov 2019 17:57:25 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 24 Nov 2019 17:57:25 +0100
changeset 371
365b24f20f98
parent 364
5577d6c27a33
child 378
952c2df7e7ac
permissions
-rw-r--r--

adds set operations to UcxList

39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
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
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
259
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 250
diff changeset
4 * Copyright 2017 Mike Becker, 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
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "string_tests.h"
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30
283
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
31 UCX_TEST(test_sstr_macros) {
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
32 sstr_t hello = ST("Hello");
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
33 sstr_t world = S("World");
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
34
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
35 char buf[20];
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
36 snprintf(buf, sizeof(buf), "%" PRIsstr ", %" PRIsstr "!", SFMT(hello), SFMT(world));
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
37
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
38 UCX_TEST_BEGIN
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
39 const char* cmp = "Hello, World!";
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
40 UCX_TEST_ASSERT(!strcmp(cmp, buf), "Something weird happened.");
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
41 UCX_TEST_END
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
42 }
c3b6ff227481 adds more convenience macros for sstr
Mike Becker <universe@uap-core.de>
parents: 272
diff changeset
43
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 123
diff changeset
44 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
45 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
46 sstr_t s2 = sstrn((char*)"ab", 2);
198
b0f4fb043b47 added test for ucx_avl_put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
47
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
48 UCX_TEST_BEGIN
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_ASSERT(s1.length == 4, "s1 length must be 4");
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
51 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
52
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
53 UCX_TEST_END
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
54 }
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
55
179
ee25d79a4187 removed old sstrncat
Mike Becker <universe@uap-core.de>
parents: 177
diff changeset
56 UCX_TEST(test_sstr_len) {
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
57 sstr_t s1 = ST("1234");
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
58 sstr_t s2 = ST(".:.:.");
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
59 sstr_t s3 = ST("X");
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
60
184
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
61 size_t len1 = sstrnlen(1, s1);
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
62 size_t len2 = sstrnlen(2, s1, s2);
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
63 size_t len3 = sstrnlen(3, s1, s2, s3);
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
64
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
65 UCX_TEST_BEGIN
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
66
184
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
67 UCX_TEST_ASSERT(len1 == 4, "sstrnlen returned wrong size");
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
68 UCX_TEST_ASSERT(len2 == 9, "sstrnlen returned wrong size");
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
69 UCX_TEST_ASSERT(len3 == 10, "sstrnlen returned wrong size");
179
ee25d79a4187 removed old sstrncat
Mike Becker <universe@uap-core.de>
parents: 177
diff changeset
70
47
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
71 UCX_TEST_END
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
72 }
22fb97e9f58a sstrncat uses memcpy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
73
180
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
74
149
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
75 UCX_TEST(test_sstrchr_sstrrchr) {
148
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
76 sstr_t str = ST("I will find you - and I will kill you");
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
77 UCX_TEST_BEGIN
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
78
184
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
79 sstr_t notfound = sstrchr(str, 'x');
306
90b6d69bb499 merges constsstr branch
Mike Becker <universe@uap-core.de>
parents: 283
diff changeset
80 UCX_TEST_ASSERT(notfound.length == 0,
90b6d69bb499 merges constsstr branch
Mike Becker <universe@uap-core.de>
parents: 283
diff changeset
81 "string length not 0 after forward search w/o result");
90b6d69bb499 merges constsstr branch
Mike Becker <universe@uap-core.de>
parents: 283
diff changeset
82
90b6d69bb499 merges constsstr branch
Mike Becker <universe@uap-core.de>
parents: 283
diff changeset
83 notfound = sstrrchr(str, 'x');
90b6d69bb499 merges constsstr branch
Mike Becker <universe@uap-core.de>
parents: 283
diff changeset
84 UCX_TEST_ASSERT(notfound.length == 0,
90b6d69bb499 merges constsstr branch
Mike Becker <universe@uap-core.de>
parents: 283
diff changeset
85 "string length not 0 after reverse search w/o result");
184
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
86
148
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
87 sstr_t result = sstrchr(str, 'w');
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
88 UCX_TEST_ASSERT(result.length == 35, "sstrchr returned wrong length");
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
89 UCX_TEST_ASSERT(strcmp("will find you - and I will kill you", result.ptr)
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
90 == 0, "sstrchr did not return the expected string");
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
91
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
92 result = sstrrchr(str, 'w');
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
93 UCX_TEST_ASSERT(result.length == 13, "sstrrchr returned wrong length");
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
94 UCX_TEST_ASSERT(strcmp("will kill you", result.ptr)
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
95 == 0, "sstrrchr did not return the expected string");
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
96
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
97 UCX_TEST_END
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
98 }
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
99
214
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
100 UCX_TEST(test_sstrstr) {
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
101 sstr_t str = ST("find the match in this string");
236
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
102 sstr_t longstr = ST(
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
103 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
104 "mnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
105 "yzabcdeababababnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
106 "klmnopqrstuvwxyzaababababababababrstuvwxyzabcdefghijklmnopqrstuv"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
107 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
108 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
109 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
110 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
111 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
112 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
113 "wxyz1234567890");
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
114 sstr_t longstrpattern = ST(
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
115 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
116 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
117 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
118 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
119 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
120 );
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
121 sstr_t longstrresult = ST(
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
122 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
123 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
124 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
125 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
126 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
127 "abababababababababababababababababababababababababababababababab"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
128 "wxyz1234567890"
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
129 );
214
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
130 UCX_TEST_BEGIN
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
131
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
132 sstr_t notfound = sstrstr(str, S("no match"));
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
133 UCX_TEST_ASSERT(notfound.length == 0, "no match must return empty string");
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
134
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
135 sstr_t result = sstrstr(str, S("match"));
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
136 UCX_TEST_ASSERT(result.length == 20, "sstrstr returned wrong length");
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
137 UCX_TEST_ASSERT(!strcmp("match in this string", result.ptr),
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
138 "sstrstr did not return the expected string");
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
139
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
140 result = sstrstr(str, S(""));
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
141 UCX_TEST_ASSERT(result.length == str.length,
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
142 "sstrstr with empty match string returned wrong length");
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
143 UCX_TEST_ASSERT(!strcmp(str.ptr, result.ptr),
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
144 "sstrstr with empty match string did not return the original string");
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
145
236
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
146 result = sstrstr(longstr, longstrpattern);
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
147 UCX_TEST_ASSERT(result.length == longstrresult.length,
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
148 "long string result length incorrect");
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
149 UCX_TEST_ASSERT(!strcmp(result.ptr, longstrresult.ptr),
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
150 "long string result content incorrect");
ffc6d0910342 improves sstrstr function by using KMP string search algorithm
Mike Becker <universe@uap-core.de>
parents: 233
diff changeset
151
214
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
152 UCX_TEST_END
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
153 }
2bc19726c340 added sstrstr() function + improved sstrsplit variants by using sstrprefix()
Mike Becker <universe@uap-core.de>
parents: 213
diff changeset
154
149
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
155 UCX_TEST(test_sstrcmp) {
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
156 sstr_t str = ST("compare this");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
157
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
158 UCX_TEST_BEGIN
184
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
159 UCX_TEST_ASSERT(sstrcmp(str, S("")) == 1, "empty cmp failed");
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
160 UCX_TEST_ASSERT(sstrcmp(S(""), S("")) == 0, "empty cmp false negative");
149
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
161 UCX_TEST_ASSERT(sstrcmp(str, S("compare this")) == 0, "false negative");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
162 UCX_TEST_ASSERT(sstrcmp(str, S("Compare This")) != 0, "false positive");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
163 UCX_TEST_ASSERT(sstrcmp(str, S("compare tool")) < 0, "memcmp < 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
164 UCX_TEST_ASSERT(sstrcmp(str, S("compare shit")) > 0, "memcmp > 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
165 UCX_TEST_ASSERT(sstrcmp(str, S("compare this not")) < 0, "len < 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
166 UCX_TEST_ASSERT(sstrcmp(str, S("compare")) > 0, "len > 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
167 UCX_TEST_END
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
168 }
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
169
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
170 UCX_TEST(test_sstrcasecmp) {
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
171
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
172 sstr_t str = ST("compare this");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
173
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
174 UCX_TEST_BEGIN
184
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
175 UCX_TEST_ASSERT(sstrcasecmp(str, S("")) == 1, "empty cmp failed");
5c0990c95f74 added some string tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 180
diff changeset
176 UCX_TEST_ASSERT(sstrcasecmp(S(""), S("")) == 0, "empty cmp false negative");
149
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
177 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this")) == 0, "false negative");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
178 UCX_TEST_ASSERT(sstrcasecmp(str, S("Compare This")) == 0,
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
179 "not ignoring case");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
180 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare tool")) < 0, "< 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
181 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare shit")) > 0, "> 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
182 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this not")) < 0,
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
183 "len < 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
184 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare")) > 0, "len > 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
185 UCX_TEST_END
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
186 }
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
187
180
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
188
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
189 UCX_TEST(test_sstrcat) {
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
190 sstr_t s1 = S("12");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
191 sstr_t s2 = S("34");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
192 sstr_t s3 = S("56");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
193 sstr_t sn = { NULL, 0 };
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
194
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
195 UCX_TEST_BEGIN
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
196
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
197 sstr_t t1 = sstrcat(2, s1, s2);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
198 UCX_TEST_ASSERT(!sstrcmp(t1, S("1234")), "t1: wrong content");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
199 free(t1.ptr);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
200
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
201 sstr_t t2 = sstrcat(3, s1, s2, s3);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
202 UCX_TEST_ASSERT(!sstrcmp(t2, S("123456")), "t2: wrong content");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
203 free(t2.ptr);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
204
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
205 sstr_t t3 = sstrcat(6, s1, sn, s2, sn, s3, sn);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
206 UCX_TEST_ASSERT(!sstrcmp(t3, S("123456")), "t3: wrong content");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
207 free(t3.ptr);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
208
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
209 sstr_t t4 = sstrcat(2, sn, sn);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
210 UCX_TEST_ASSERT(t4.ptr, "t4.ptr is NULL");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
211 UCX_TEST_ASSERT(t4.length == 0, "t4 has wrong length");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
212 free(t4.ptr);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
213
272
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
214 // overflow test
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
215 sstr_t o0;
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
216 o0.ptr = "";
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
217 o0.length = ((size_t)-1) - 50;
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
218 sstr_t o1;
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
219 o1.ptr = "";
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
220 o1.length = 100;
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
221 sstr_t o2;
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
222 o2.ptr = "";
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
223 o2.length = 10;
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
224
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
225 sstr_t n = sstrcat(2, o0, o1);
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
226 UCX_TEST_ASSERT(n.ptr == NULL && n.length == 0, "overflow not detected");
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
227 sstr_t n2 = sstrcat(3, o0, o2, o1);
2def28b65328 adds integer overflow checks to sstrlen and sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 259
diff changeset
228 UCX_TEST_ASSERT(n2.ptr == NULL && n2.length == 0, "n2: overflow not detected");
180
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
229
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
230 UCX_TEST_END
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
231
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
232 }
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
233
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 123
diff changeset
234 UCX_TEST(test_sstrsplit) {
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
236 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
237 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
238 ssize_t n;
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239 sstr_t *list;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
240
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 UCX_TEST_BEGIN
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 /* Nullpointer check */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
245 UCX_TEST_ASSERT(sstrsplit(test, S(""), &n) == NULL,
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246 "empty delimiter must return NULL");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 /* no delimiter occurence (ndo) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
250 list = sstrsplit(test, S("z"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
251 UCX_TEST_ASSERT(n == 1, "ndo, list length must be 1");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0, "ndo, "
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 "original string shall be returned as single list element");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 "ndo, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
256 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
257 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
258 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
261 /* partially matching delimiter (pmd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
262 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
263 list = sstrsplit(test, S("stringbuilder"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 UCX_TEST_ASSERT(n == 1, "pmd, list length must be 1");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0, "pmd, "
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 "original string shall be returned as single list element");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268 "pmd, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
269 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
270 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
271 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274 /* matching single-char delimiter (mscd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
276 list = sstrsplit(test, S(","), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 UCX_TEST_ASSERT(n == 5, "mscd, list length must be 5");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 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
279 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
280 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
281 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
282 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
283 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 "mscd, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
285 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
286 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
287 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
288 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290 /* matching multi-char delimiter (mmcd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
291 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
292 list = sstrsplit(test, S("is"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293 UCX_TEST_ASSERT(n == 3, "mscd, list length must be 3");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
294 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
295 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
296 UCX_TEST_ASSERT(strcmp(list[2].ptr, ",a,csv,string") == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297 "mmcd, item 2 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
299 "mmcd, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
300 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
301 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
302 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
303 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
305 /* bounded list using single-char delimiter (blsc) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 n = 3;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
307 list = sstrsplit(test, S(","), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
308 UCX_TEST_ASSERT(n == 3, "blsc, list length must be 3");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
309 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
310 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
311 UCX_TEST_ASSERT(strcmp(list[2].ptr, "a,csv,string") == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312 "blsc, item 2 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
314 "blsc, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
315 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
316 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
317 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
318 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
319
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 /* bounded list using multi-char delimiter (blmc) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
321 n = 2;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
322 list = sstrsplit(test, S("is"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
323 UCX_TEST_ASSERT(n == 2, "blmc, list length must be 2");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
324 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
325 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
326 "blmc, item 1 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328 "blmc, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
329 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
330 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
331 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
332 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
333
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
334 /* start with delimiter (swd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
335 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
336 list = sstrsplit(test, S("this"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
337 UCX_TEST_ASSERT(n == 2, "swd, list length must be 2");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
338 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
339 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
340 "swd, second item corrupt");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
341 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
342 "swd, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
343 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
344 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
345 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
346 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
347
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
348 /* end with delimiter (ewd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
349 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
350 list = sstrsplit(test, S("string"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
351 UCX_TEST_ASSERT(n == 2, "ewd, list length must be 2");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
352 UCX_TEST_ASSERT(strcmp(list[0].ptr, "this,is,a,csv,") == 0,
232
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
353 "ewd, first item corrupt");
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
354 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
355 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
356 "ewd, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
357 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
358 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
359 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
360 free(list);
232
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
361
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
362 /* end with delimiter exceed bound (ewdeb) */
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
363 n = 3;
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
364 sstr_t ewdebtest = ST("a,b,c,");
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
365 list = sstrsplit(ewdebtest, S(","), &n);
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
366 UCX_TEST_ASSERT(n == 3, "ewdeb, list length must be 3");
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
367 UCX_TEST_ASSERT(strcmp(list[0].ptr, "a") == 0, "ewdeb, fst item corrupt");
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
368 UCX_TEST_ASSERT(strcmp(list[1].ptr, "b") == 0, "ewdeb, snd item corrupt");
233
bd58fdde142d reimplementation of sstrsplit
Mike Becker <universe@uap-core.de>
parents: 232
diff changeset
369 UCX_TEST_ASSERT(strcmp(list[2].ptr, "c,") == 0, "ewdeb, trd item corrupt");
232
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
370 for(int i=0;i<n;i++) {
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
371 free(list[i].ptr);
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
372 }
5f2d650eade7 adds new test case for sstrsplit: string ends with delimiter but empty string exceeds list bound
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
373 free(list);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
374
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
375 /* exact match (exm) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
376 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
377 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
378 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
379 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
380 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
381 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
382 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
383 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
384
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
385 /* substring (subs) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
386 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
387 list = sstrsplit(test, S("this,is,a,csv,string,with,extension"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
388 UCX_TEST_ASSERT(n == 1, "subs, list length must be 1");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
389 UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
390 "subs, single item must be the original string");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
391 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
392 "subs, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
393 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
394 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
395 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
396 free(list);
213
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
397
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
398 /* double encounter delimiter (ded) */
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
399 n = 0;
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
400 list = sstrsplit(test, S("is,"), &n);
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
401 UCX_TEST_ASSERT(n == 3, "ded, list length must be 3");
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
402 UCX_TEST_ASSERT(strcmp(list[0].ptr, "th") == 0, "ded, item 0 mismatch");
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
403 UCX_TEST_ASSERT(list[1].length == 0, "ded, item 1 not empty!");
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
404 UCX_TEST_ASSERT(strcmp(list[2].ptr, "a,csv,string") == 0,
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
405 "ded, item 2 mismatch");
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
406 for(int i=0;i<n;i++) {
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
407 free(list[i].ptr);
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
408 }
fa8b745be7b5 added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build
Mike Becker <universe@uap-core.de>
parents: 198
diff changeset
409 free(list);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
410
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
411 UCX_TEST_END
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
412 }
97
499e1b465d77 fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents: 74
diff changeset
413
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 123
diff changeset
414 UCX_TEST(test_sstrtrim) {
104
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
415 sstr_t t1 = sstrtrim(sstr((char*)" ein test "));
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
416 sstr_t t2 = sstrtrim(sstr((char*)"abc"));
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
417 sstr_t t3 = sstrtrim(sstr((char*)" 123"));
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
418 sstr_t t4 = sstrtrim(sstr((char*)"xyz "));
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
419 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
420 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
421 UCX_TEST_BEGIN
104
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
422 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
423 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
424 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
425 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
426 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
427 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
428 UCX_TEST_END
499e1b465d77 fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents: 74
diff changeset
429 }
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
430
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
431 UCX_TEST(test_sstrprefixsuffix) {
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
432 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
433 sstr_t empty = ST("");
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
434
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
435 UCX_TEST_BEGIN
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
436
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
437 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
438 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
439
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
440 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
441 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
442
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
443 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
444 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
445
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
446 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
447 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
448
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
449 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
450 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
451
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
452
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
453 UCX_TEST_END
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
454 }
364
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
455
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
456 UCX_TEST(test_sstrcaseprefixsuffix) {
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
457 sstr_t str = ST("test my prefix and my suffix");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
458 sstr_t empty = ST("");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
459
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
460 UCX_TEST_BEGIN
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
461
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
462 UCX_TEST_ASSERT(!sstrcaseprefix(empty, S("pREf")), "prefix empty string fails");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
463 UCX_TEST_ASSERT(!sstrcasesuffix(empty, S("sUf")), "suffix empty string fails");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
464
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
465 UCX_TEST_ASSERT(sstrcaseprefix(str, empty), "empty prefix fails");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
466 UCX_TEST_ASSERT(sstrcasesuffix(str, empty), "empty suffix fails");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
467
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
468 UCX_TEST_ASSERT(sstrcaseprefix(empty, empty), "string and prefix empty fails");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
469 UCX_TEST_ASSERT(sstrcasesuffix(empty, empty), "string and suffix empty fails");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
470
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
471 UCX_TEST_ASSERT(sstrcaseprefix(str, S("TEST ")), "prefix false negative");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
472 UCX_TEST_ASSERT(!sstrcaseprefix(str, S("8-) fsck ")), "prefix false positive");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
473
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
474 UCX_TEST_ASSERT(sstrcasesuffix(str, S("FIX")), "suffix false negative");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
475 UCX_TEST_ASSERT(!sstrcasesuffix(str, S("fox")), "suffix false positive");
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
476
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
477 UCX_TEST_END
5577d6c27a33 adds case independent versions of sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 306
diff changeset
478 }

mercurial