test/string_tests.c

Mon, 14 Jul 2014 16:54:10 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 14 Jul 2014 16:54:10 +0200
changeset 182
998bf7c643b4
parent 180
2185f19dcc45
child 184
5c0990c95f74
permissions
-rw-r--r--

merged sstrcat function

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 *
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
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
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
ee25d79a4187 removed old sstrncat
Mike Becker <universe@uap-core.de>
parents: 177
diff changeset
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
ee25d79a4187 removed old sstrncat
Mike Becker <universe@uap-core.de>
parents: 177
diff changeset
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
180
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
57
149
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
58 UCX_TEST(test_sstrchr_sstrrchr) {
148
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
59 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
60 UCX_TEST_BEGIN
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
61
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
62 sstr_t result = sstrchr(str, 'w');
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
63 UCX_TEST_ASSERT(result.length == 35, "sstrchr returned wrong length");
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
64 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
65 == 0, "sstrchr did not return the expected string");
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
66
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
67 result = sstrrchr(str, 'w');
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
68 UCX_TEST_ASSERT(result.length == 13, "sstrrchr returned wrong length");
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
69 UCX_TEST_ASSERT(strcmp("will kill you", result.ptr)
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
70 == 0, "sstrrchr did not return the expected string");
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
71
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
72 UCX_TEST_END
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
73 }
c27c2425c0b1 added sstrrchr
Mike Becker <universe@uap-core.de>
parents: 147
diff changeset
74
149
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
75 UCX_TEST(test_sstrcmp) {
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
76 sstr_t str = ST("compare this");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
77
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
78 UCX_TEST_BEGIN
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
79 UCX_TEST_ASSERT(sstrcmp(str, S("compare this")) == 0, "false negative");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
80 UCX_TEST_ASSERT(sstrcmp(str, S("Compare This")) != 0, "false positive");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
81 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
82 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
83 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
84 UCX_TEST_ASSERT(sstrcmp(str, S("compare")) > 0, "len > 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
85 UCX_TEST_END
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
86 }
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
87
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
88 UCX_TEST(test_sstrcasecmp) {
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
89
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
90 sstr_t str = ST("compare this");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
91
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
92 UCX_TEST_BEGIN
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
93 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this")) == 0, "false negative");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
94 UCX_TEST_ASSERT(sstrcasecmp(str, S("Compare This")) == 0,
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
95 "not ignoring case");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
96 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare tool")) < 0, "< 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
97 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare shit")) > 0, "> 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
98 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this not")) < 0,
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
99 "len < 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
100 UCX_TEST_ASSERT(sstrcasecmp(str, S("compare")) > 0, "len > 0 failed");
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
101 UCX_TEST_END
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
102 }
3bf87676d42d added sstrcasecmp
Mike Becker <universe@uap-core.de>
parents: 148
diff changeset
103
180
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
104
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
105 UCX_TEST(test_sstrcat) {
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
106 sstr_t s1 = S("12");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
107 sstr_t s2 = S("34");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
108 sstr_t s3 = S("56");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
109 sstr_t sn = { NULL, 0 };
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
110
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
111 UCX_TEST_BEGIN
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
112
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
113 sstr_t t1 = sstrcat(2, s1, s2);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
114 UCX_TEST_ASSERT(!sstrcmp(t1, S("1234")), "t1: wrong content");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
115 free(t1.ptr);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
116
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
117 sstr_t t2 = sstrcat(3, s1, s2, s3);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
118 UCX_TEST_ASSERT(!sstrcmp(t2, S("123456")), "t2: wrong content");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
119 free(t2.ptr);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
120
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
121 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
122 UCX_TEST_ASSERT(!sstrcmp(t3, S("123456")), "t3: wrong content");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
123 free(t3.ptr);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
124
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
125 sstr_t t4 = sstrcat(2, sn, sn);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
126 UCX_TEST_ASSERT(t4.ptr, "t4.ptr is NULL");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
127 UCX_TEST_ASSERT(t4.length == 0, "t4 has wrong length");
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
128 free(t4.ptr);
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
129
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
130
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
131 UCX_TEST_END
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
132
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
133 }
2185f19dcc45 added new sstrcat
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 179
diff changeset
134
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 123
diff changeset
135 UCX_TEST(test_sstrsplit) {
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 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
138 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
139 ssize_t n;
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 sstr_t *list;
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 UCX_TEST_BEGIN
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 /* Nullpointer check */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
146 UCX_TEST_ASSERT(sstrsplit(test, S(""), &n) == NULL,
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 "empty delimiter must return NULL");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 /* no delimiter occurence (ndo) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
151 list = sstrsplit(test, S("z"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 UCX_TEST_ASSERT(n == 1, "ndo, list length must be 1");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0, "ndo, "
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 "original string shall be returned as single list element");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 "ndo, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
157 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
158 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
159 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 /* partially matching delimiter (pmd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
164 list = sstrsplit(test, S("stringbuilder"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 UCX_TEST_ASSERT(n == 1, "pmd, list length must be 1");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0, "pmd, "
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 "original string shall be returned as single list element");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 "pmd, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
170 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
171 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
172 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 /* matching single-char delimiter (mscd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
177 list = sstrsplit(test, S(","), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 UCX_TEST_ASSERT(n == 5, "mscd, list length must be 5");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 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
180 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
181 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
182 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
183 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
184 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 "mscd, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
186 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
187 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
188 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
190
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
191 /* matching multi-char delimiter (mmcd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
193 list = sstrsplit(test, S("is"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194 UCX_TEST_ASSERT(n == 3, "mscd, list length must be 3");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195 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
196 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
197 UCX_TEST_ASSERT(strcmp(list[2].ptr, ",a,csv,string") == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 "mmcd, item 2 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 "mmcd, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
201 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
202 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
203 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
205
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206 /* bounded list using single-char delimiter (blsc) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 n = 3;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
208 list = sstrsplit(test, S(","), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209 UCX_TEST_ASSERT(n == 3, "blsc, list length must be 3");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210 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
211 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
212 UCX_TEST_ASSERT(strcmp(list[2].ptr, "a,csv,string") == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213 "blsc, item 2 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
214 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 "blsc, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
216 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
217 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
218 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221 /* bounded list using multi-char delimiter (blmc) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 n = 2;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
223 list = sstrsplit(test, S("is"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 UCX_TEST_ASSERT(n == 2, "blmc, list length must be 2");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 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
226 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
227 "blmc, item 1 mismatch");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 "blmc, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
230 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
231 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
232 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235 /* start with delimiter (swd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
236 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
237 list = sstrsplit(test, S("this"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238 UCX_TEST_ASSERT(n == 2, "swd, list length must be 2");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239 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
240 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
241 "swd, second item corrupt");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 "swd, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
244 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
245 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
246 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249 /* end with delimiter (ewd) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
251 list = sstrsplit(test, S("string"), &n);
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 UCX_TEST_ASSERT(n == 2, "ewd, list length must be 2");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 UCX_TEST_ASSERT(strcmp(list[0].ptr, "this,is,a,csv,") == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 "swd, first item corrupt");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 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
256 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 "ewd, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
258 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
259 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
260 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
261 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
262
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 /* exact match (exm) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
265 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
266 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
267 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
268 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
269 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
270 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
271 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 /* substring (subs) */
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274 n = 0;
116
234920008754 some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents: 104
diff changeset
275 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
276 UCX_TEST_ASSERT(n == 1, "subs, list length must be 1");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 UCX_TEST_ASSERT(strcmp(list[0].ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 "subs, single item must be the original string");
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0,
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 "subs, original has been modified");
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
281 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
282 free(list[i].ptr);
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 146
diff changeset
283 }
39
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 free(list);
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286 UCX_TEST_END
bf8ab7bb74ff added sstrsplit function
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287 }
97
499e1b465d77 fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents: 74
diff changeset
288
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 123
diff changeset
289 UCX_TEST(test_sstrtrim) {
104
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
290 sstr_t t1 = sstrtrim(sstr((char*)" ein test "));
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
291 sstr_t t2 = sstrtrim(sstr((char*)"abc"));
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
292 sstr_t t3 = sstrtrim(sstr((char*)" 123"));
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
293 sstr_t t4 = sstrtrim(sstr((char*)"xyz "));
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
294 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
295 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
296 UCX_TEST_BEGIN
104
9d3dea320d8e fixed sstrtrim and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
297 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
298 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
299 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
300 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
301 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
302 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
303 UCX_TEST_END
499e1b465d77 fixed execution order of tests + added test for sstrtrim
Mike Becker <universe@uap-core.de>
parents: 74
diff changeset
304 }
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
305
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
306 UCX_TEST(test_sstrprefixsuffix) {
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
307 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
308 sstr_t empty = ST("");
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
309
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
310 UCX_TEST_BEGIN
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
311
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
312 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
313 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
314
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
315 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
316 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
317
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
318 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
319 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
320
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
321 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
322 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
323
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
324 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
325 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
326
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
327
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
328 UCX_TEST_END
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 134
diff changeset
329 }

mercurial