summaryrefslogtreecommitdiffstats
path: root/lib/tests/test_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests/test_utils.c')
-rw-r--r--lib/tests/test_utils.c81
1 files changed, 80 insertions, 1 deletions
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index 86a17dc3..97343afa 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -29,7 +29,7 @@ main (int argc, char **argv)
29 thresholds *thresholds = NULL; 29 thresholds *thresholds = NULL;
30 int rc; 30 int rc;
31 31
32 plan_tests(81); 32 plan_tests(81+23);
33 33
34 range = parse_range_string("6"); 34 range = parse_range_string("6");
35 ok( range != NULL, "'6' is valid range"); 35 ok( range != NULL, "'6' is valid range");
@@ -172,5 +172,84 @@ main (int argc, char **argv)
172 test = np_escaped_string("everything"); 172 test = np_escaped_string("everything");
173 ok( strcmp(test, "everything") == 0, "everything okay"); 173 ok( strcmp(test, "everything") == 0, "everything okay");
174 174
175 /* np_extract_value tests (23) */
176 test=np_extract_value("foo=bar, bar=foo, foobar=barfoo\n", "foo");
177 ok(test && !strcmp(test, "bar"), "1st test as expected");
178 free(test);
179
180 test=np_extract_value("foo=bar,bar=foo,foobar=barfoo\n", "bar");
181 ok(test && !strcmp(test, "foo"), "2nd test as expected");
182 free(test);
183
184 test=np_extract_value("foo=bar, bar=foo, foobar=barfoo\n", "foobar");
185 ok(test && !strcmp(test, "barfoo"), "3rd test as expected");
186 free(test);
187
188 test=np_extract_value("foo=bar\n", "foo");
189 ok(test && !strcmp(test, "bar"), "Single test as expected");
190 free(test);
191
192 test=np_extract_value("foo=bar, bar=foo, foobar=barfooi\n", "abcd");
193 ok(!test, "Key not found 1");
194
195 test=np_extract_value("foo=bar\n", "abcd");
196 ok(!test, "Key not found 2");
197
198 test=np_extract_value("foo=bar=foobar", "foo");
199 ok(test && !strcmp(test, "bar=foobar"), "Strange string 1");
200 free(test);
201
202 test=np_extract_value("foo", "foo");
203 ok(!test, "Malformed string 1");
204
205 test=np_extract_value("foo,", "foo");
206 ok(!test, "Malformed string 2");
207
208 test=np_extract_value("foo=", "foo");
209 ok(!test, "Malformed string 3");
210
211 test=np_extract_value("foo=,bar=foo", "foo");
212 ok(!test, "Malformed string 4");
213
214 test=np_extract_value(",foo", "foo");
215 ok(!test, "Malformed string 5");
216
217 test=np_extract_value("=foo", "foo");
218 ok(!test, "Malformed string 6");
219
220 test=np_extract_value("=foo,", "foo");
221 ok(!test, "Malformed string 7");
222
223 test=np_extract_value(",,,", "foo");
224 ok(!test, "Malformed string 8");
225
226 test=np_extract_value("===", "foo");
227 ok(!test, "Malformed string 9");
228
229 test=np_extract_value(",=,=,", "foo");
230 ok(!test, "Malformed string 10");
231
232 test=np_extract_value("=,=,=", "foo");
233 ok(!test, "Malformed string 11");
234
235 test=np_extract_value(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foo");
236 ok(test && !strcmp(test, "bar"), "Random spaces and newlines 1");
237 free(test);
238
239 test=np_extract_value(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "bar");
240 ok(test && !strcmp(test, "foo"), "Random spaces and newlines 2");
241 free(test);
242
243 test=np_extract_value(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foobar");
244 ok(test && !strcmp(test, "barfoo"), "Random spaces and newlines 3");
245 free(test);
246
247 test=np_extract_value(" foo=bar ,\n bar\n \n= \n foo\n , foobar=barfoo \n ", "bar");
248 ok(test && !strcmp(test, "foo"), "Random spaces and newlines 4");
249 free(test);
250
251 test=np_extract_value("", "foo");
252 ok(!test, "Empty string return NULL");
253
175 return exit_status(); 254 return exit_status();
176} 255}