From a4647be424c9350ab967eeacccd2761c71f9c6a9 Mon Sep 17 00:00:00 2001 From: Thomas Guyot-Sionnest Date: Mon, 19 Jan 2009 22:14:03 -0500 Subject: Move check_ntp's extract_value to utils_base.c. This function can also be used to parse performance data strings which could be useful in the future. --- lib/tests/test_utils.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) (limited to 'lib/tests/test_utils.c') 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) thresholds *thresholds = NULL; int rc; - plan_tests(81); + plan_tests(81+23); range = parse_range_string("6"); ok( range != NULL, "'6' is valid range"); @@ -172,5 +172,84 @@ main (int argc, char **argv) test = np_escaped_string("everything"); ok( strcmp(test, "everything") == 0, "everything okay"); + /* np_extract_value tests (23) */ + test=np_extract_value("foo=bar, bar=foo, foobar=barfoo\n", "foo"); + ok(test && !strcmp(test, "bar"), "1st test as expected"); + free(test); + + test=np_extract_value("foo=bar,bar=foo,foobar=barfoo\n", "bar"); + ok(test && !strcmp(test, "foo"), "2nd test as expected"); + free(test); + + test=np_extract_value("foo=bar, bar=foo, foobar=barfoo\n", "foobar"); + ok(test && !strcmp(test, "barfoo"), "3rd test as expected"); + free(test); + + test=np_extract_value("foo=bar\n", "foo"); + ok(test && !strcmp(test, "bar"), "Single test as expected"); + free(test); + + test=np_extract_value("foo=bar, bar=foo, foobar=barfooi\n", "abcd"); + ok(!test, "Key not found 1"); + + test=np_extract_value("foo=bar\n", "abcd"); + ok(!test, "Key not found 2"); + + test=np_extract_value("foo=bar=foobar", "foo"); + ok(test && !strcmp(test, "bar=foobar"), "Strange string 1"); + free(test); + + test=np_extract_value("foo", "foo"); + ok(!test, "Malformed string 1"); + + test=np_extract_value("foo,", "foo"); + ok(!test, "Malformed string 2"); + + test=np_extract_value("foo=", "foo"); + ok(!test, "Malformed string 3"); + + test=np_extract_value("foo=,bar=foo", "foo"); + ok(!test, "Malformed string 4"); + + test=np_extract_value(",foo", "foo"); + ok(!test, "Malformed string 5"); + + test=np_extract_value("=foo", "foo"); + ok(!test, "Malformed string 6"); + + test=np_extract_value("=foo,", "foo"); + ok(!test, "Malformed string 7"); + + test=np_extract_value(",,,", "foo"); + ok(!test, "Malformed string 8"); + + test=np_extract_value("===", "foo"); + ok(!test, "Malformed string 9"); + + test=np_extract_value(",=,=,", "foo"); + ok(!test, "Malformed string 10"); + + test=np_extract_value("=,=,=", "foo"); + ok(!test, "Malformed string 11"); + + test=np_extract_value(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foo"); + ok(test && !strcmp(test, "bar"), "Random spaces and newlines 1"); + free(test); + + test=np_extract_value(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "bar"); + ok(test && !strcmp(test, "foo"), "Random spaces and newlines 2"); + free(test); + + test=np_extract_value(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foobar"); + ok(test && !strcmp(test, "barfoo"), "Random spaces and newlines 3"); + free(test); + + test=np_extract_value(" foo=bar ,\n bar\n \n= \n foo\n , foobar=barfoo \n ", "bar"); + ok(test && !strcmp(test, "foo"), "Random spaces and newlines 4"); + free(test); + + test=np_extract_value("", "foo"); + ok(!test, "Empty string return NULL"); + return exit_status(); } -- cgit v1.2.3