summaryrefslogtreecommitdiff
path: root/lib/util/tests
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2009-09-27 17:37:53 +0200
committerJelmer Vernooij <jelmer@samba.org>2009-09-27 17:37:53 +0200
commitd9ada600cc81603300a0cfce75179c6aa1ac94cc (patch)
tree3d7dc80587be662a886aed0a643762c4574aac92 /lib/util/tests
parent43267812e17cc7749bb9275574af5eccc74129e5 (diff)
downloadsamba-d9ada600cc81603300a0cfce75179c6aa1ac94cc.tar.gz
samba-d9ada600cc81603300a0cfce75179c6aa1ac94cc.tar.bz2
samba-d9ada600cc81603300a0cfce75179c6aa1ac94cc.zip
parmlist: Add more tests.
Diffstat (limited to 'lib/util/tests')
-rw-r--r--lib/util/tests/parmlist.c66
1 files changed, 63 insertions, 3 deletions
diff --git a/lib/util/tests/parmlist.c b/lib/util/tests/parmlist.c
index 6323fdc599..4b1d875715 100644
--- a/lib/util/tests/parmlist.c
+++ b/lib/util/tests/parmlist.c
@@ -28,19 +28,79 @@ static bool test_get_int(struct torture_context *tctx)
struct parmlist *pctx = talloc_zero(tctx, struct parmlist);
parmlist_set_string(pctx, "bar", "3");
parmlist_set_string(pctx, "notint", "bla");
- torture_assert_int_equal(3, parmlist_get_int(pctx, "bar", 42));
- torture_assert_int_equal(42, parmlist_get_int(pctx, "foo", 42),
+ torture_assert_int_equal(tctx, 3, parmlist_get_int(pctx, "bar", 42),
+ "existing");
+ torture_assert_int_equal(tctx, 42, parmlist_get_int(pctx, "foo", 42),
"default");
- torture_assert_int_equal(0, parmlist_get_int(pctx, "notint", 42)
+ torture_assert_int_equal(tctx, 0, parmlist_get_int(pctx, "notint", 42),
"Not an integer");
return true;
}
+static bool test_get_string(struct torture_context *tctx)
+{
+ struct parmlist *pctx = talloc_zero(tctx, struct parmlist);
+ parmlist_set_string(pctx, "bar", "mystring");
+ torture_assert_str_equal(tctx, "mystring",
+ parmlist_get_string(pctx, "bar", "bla"), "existing");
+ torture_assert_str_equal(tctx, "bla",
+ parmlist_get_string(pctx, "foo", "bla"), "default");
+ return true;
+}
+
+static bool test_get(struct torture_context *tctx)
+{
+ struct parmlist *pctx = talloc_zero(tctx, struct parmlist);
+ struct parmlist_entry *e;
+ parmlist_set_string(pctx, "bar", "mystring");
+
+ e = parmlist_get(pctx, "bar");
+ torture_assert(tctx, e != NULL, "entry");
+ torture_assert_str_equal(tctx, e->key, "bar", "key");
+ torture_assert_str_equal(tctx, e->value, "mystring", "value");
+
+ e = parmlist_get(pctx, "nonexistant");
+ torture_assert(tctx, e == NULL, "nonexistant");
+ return true;
+}
+
+static bool test_get_bool(struct torture_context *tctx)
+{
+ struct parmlist *pctx = talloc_zero(tctx, struct parmlist);
+ parmlist_set_string(pctx, "bar", "true");
+ parmlist_set_string(pctx, "gasoline", "invalid");
+
+ torture_assert(tctx, parmlist_get_bool(pctx, "bar", false), "set");
+ torture_assert(tctx, !parmlist_get_bool(pctx, "foo", false), "default");
+ torture_assert(tctx, !parmlist_get_bool(pctx, "gasoline", false),
+ "invalid");
+ return true;
+}
+
+static bool test_get_string_list(struct torture_context *tctx)
+{
+ struct parmlist *pctx = talloc_zero(tctx, struct parmlist);
+ const char **ret;
+ parmlist_set_string(pctx, "bar", "true, false");
+
+ ret = parmlist_get_string_list(pctx, "bar", NULL);
+ torture_assert_int_equal(tctx, str_list_length(ret), 2, "length");
+ torture_assert_str_equal(tctx, "true", ret[0], "ret[0]");
+ torture_assert_str_equal(tctx, "false", ret[1], "ret[1]");
+ torture_assert(tctx, NULL == parmlist_get_string_list(pctx, "nonexistant", NULL), "nonexistant");
+
+ return true;
+}
+
struct torture_suite *torture_local_util_parmlist(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "PARMLIST");
torture_suite_add_simple_test(suite, "get_int", test_get_int);
+ torture_suite_add_simple_test(suite, "get_string", test_get_string);
+ torture_suite_add_simple_test(suite, "get", test_get);
+ torture_suite_add_simple_test(suite, "get_bool", test_get_bool);
+ torture_suite_add_simple_test(suite, "get_string_list", test_get_string_list);
return suite;
}