2 Unix SMB/CIFS implementation.
6 Copyright (C) Jelmer Vernooij 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "../lib/util/parmlist.h"
26 static bool test_get_int(struct torture_context
*tctx
)
28 struct parmlist
*pctx
= talloc_zero(tctx
, struct parmlist
);
29 parmlist_set_string(pctx
, "bar", "3");
30 parmlist_set_string(pctx
, "notint", "bla");
31 torture_assert_int_equal(tctx
, 3, parmlist_get_int(pctx
, "bar", 42),
33 torture_assert_int_equal(tctx
, 42, parmlist_get_int(pctx
, "foo", 42),
35 torture_assert_int_equal(tctx
, 0, parmlist_get_int(pctx
, "notint", 42),
40 static bool test_get_string(struct torture_context
*tctx
)
42 struct parmlist
*pctx
= talloc_zero(tctx
, struct parmlist
);
43 parmlist_set_string(pctx
, "bar", "mystring");
44 torture_assert_str_equal(tctx
, "mystring",
45 parmlist_get_string(pctx
, "bar", "bla"), "existing");
46 torture_assert_str_equal(tctx
, "bla",
47 parmlist_get_string(pctx
, "foo", "bla"), "default");
51 static bool test_get(struct torture_context
*tctx
)
53 struct parmlist
*pctx
= talloc_zero(tctx
, struct parmlist
);
54 struct parmlist_entry
*e
;
55 parmlist_set_string(pctx
, "bar", "mystring");
57 e
= parmlist_get(pctx
, "bar");
58 torture_assert(tctx
, e
!= NULL
, "entry");
59 torture_assert_str_equal(tctx
, e
->key
, "bar", "key");
60 torture_assert_str_equal(tctx
, e
->value
, "mystring", "value");
62 e
= parmlist_get(pctx
, "nonexistant");
63 torture_assert(tctx
, e
== NULL
, "nonexistant");
67 static bool test_get_bool(struct torture_context
*tctx
)
69 struct parmlist
*pctx
= talloc_zero(tctx
, struct parmlist
);
70 parmlist_set_string(pctx
, "bar", "true");
71 parmlist_set_string(pctx
, "gasoline", "invalid");
73 torture_assert(tctx
, parmlist_get_bool(pctx
, "bar", false), "set");
74 torture_assert(tctx
, !parmlist_get_bool(pctx
, "foo", false), "default");
75 torture_assert(tctx
, !parmlist_get_bool(pctx
, "gasoline", false),
80 static bool test_get_string_list(struct torture_context
*tctx
)
82 struct parmlist
*pctx
= talloc_zero(tctx
, struct parmlist
);
84 parmlist_set_string(pctx
, "bar", "true, false");
86 ret
= parmlist_get_string_list(pctx
, "bar", NULL
);
87 torture_assert_int_equal(tctx
, str_list_length(ret
), 2, "length");
88 torture_assert_str_equal(tctx
, "true", ret
[0], "ret[0]");
89 torture_assert_str_equal(tctx
, "false", ret
[1], "ret[1]");
90 torture_assert(tctx
, NULL
== parmlist_get_string_list(pctx
, "nonexistant", NULL
), "nonexistant");
95 struct torture_suite
*torture_local_util_parmlist(TALLOC_CTX
*mem_ctx
)
97 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "PARMLIST");
99 torture_suite_add_simple_test(suite
, "get_int", test_get_int
);
100 torture_suite_add_simple_test(suite
, "get_string", test_get_string
);
101 torture_suite_add_simple_test(suite
, "get", test_get
);
102 torture_suite_add_simple_test(suite
, "get_bool", test_get_bool
);
103 torture_suite_add_simple_test(suite
, "get_string_list", test_get_string_list
);