2 * Tests exercising the ldb parse operations.
4 * Copyright (C) Catalyst.NET Ltd 2017
5 * Copyright (C) Michael Hanselmann 2019
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "../include/ldb.h"
34 static int setup(void **state)
38 ctx = talloc_zero(NULL, struct test_ctx);
46 static int teardown(void **state)
48 struct test_ctx *ctx =
49 talloc_get_type_abort(*state, struct test_ctx);
56 static void test_roundtrip(TALLOC_CTX *mem_ctx, const char *filter, const char *expected)
58 struct ldb_parse_tree *tree;
61 assert_non_null(filter);
62 assert_non_null(expected);
64 tree = ldb_parse_tree(mem_ctx, filter);
65 assert_non_null(tree);
67 serialized = ldb_filter_from_tree(mem_ctx, tree);
68 assert_non_null(serialized);
70 assert_string_equal(serialized, expected);
73 static void test_parse_filtertype(void **state)
75 struct test_ctx *ctx =
76 talloc_get_type_abort(*state, struct test_ctx);
78 test_roundtrip(ctx, "", "(|(objectClass=*)(distinguishedName=*))");
79 test_roundtrip(ctx, "a=value", "(a=value)");
80 test_roundtrip(ctx, "(|(foo=bar)(baz=hello))", "(|(foo=bar)(baz=hello))");
81 test_roundtrip(ctx, " ", "(|(objectClass=*)(distinguishedName=*))");
84 int main(int argc, const char **argv)
86 const struct CMUnitTest tests[] = {
87 cmocka_unit_test_setup_teardown(test_parse_filtertype, setup, teardown),
90 cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
92 return cmocka_run_group_tests(tests, NULL, NULL);