ctdb-daemon: Use ctdb_parse_node_address() in ctdbd
[samba4-gss.git] / lib / ldb / tests / lldb_ldap.c
blobc5404f189b381ef6c7160de1c2a6c0b5bb35d88a
1 /*
2 * from cmocka.c:
3 * These headers or their equivalents should be included prior to
4 * including
5 * this header file.
7 * #include <stdarg.h>
8 * #include <stddef.h>
9 * #include <setjmp.h>
11 * This allows test applications to use custom definitions of C standard
12 * library functions and types.
14 #include <stdarg.h>
15 #include <stddef.h>
16 #include <stdint.h>
17 #include <setjmp.h>
18 #include <cmocka.h>
20 #include <errno.h>
21 #include <unistd.h>
22 #include <talloc.h>
24 #include <ldb.h>
25 #include <ldb_private.h>
26 #include <string.h>
27 #include <ctype.h>
29 int ldb_ldap_init(const char *version);
31 #include "ldb_ldap/ldb_ldap.c"
33 struct test_ctx {
34 struct tevent_context *ev;
35 struct ldb_context *ldb;
36 struct ldb_message *msg;
39 static int lldb_msg_setup(void **state)
41 struct test_ctx *test_ctx;
43 test_ctx = talloc_zero(NULL, struct test_ctx);
44 assert_non_null(test_ctx);
46 test_ctx->ev = tevent_context_init(test_ctx);
47 assert_non_null(test_ctx->ev);
49 test_ctx->ldb = ldb_init(test_ctx, test_ctx->ev);
50 assert_non_null(test_ctx->ldb);
52 test_ctx->msg = ldb_msg_new(test_ctx);
53 assert_non_null(test_ctx->msg);
55 *state = test_ctx;
56 return 0;
59 static int lldb_msg_teardown(void **state)
61 struct test_ctx *test_ctx = talloc_get_type_abort(*state,
62 struct test_ctx);
64 talloc_free(test_ctx);
65 return 0;
68 static void test_lldb_add_msg_attr(void **state)
70 struct test_ctx *test_ctx = talloc_get_type_abort(*state,
71 struct test_ctx);
72 struct ldb_message *msg = test_ctx->msg;
73 int ret;
74 unsigned int num_elements = 0;
75 struct berval **v = NULL;
77 v = talloc_zero_array(test_ctx, struct berval *, 2);
78 assert_non_null(v);
80 v[0] = talloc_zero(v, struct berval);
81 assert_non_null(v[0]);
83 v[0]->bv_val = talloc_strdup(msg, "dc=example,dc=test");
84 assert_non_null(v[0]->bv_val);
86 v[0]->bv_len = strlen(v[0]->bv_val);
88 num_elements = msg->num_elements;
90 ret = lldb_add_msg_attr(test_ctx->ldb, msg, "defaultNamingContext", v);
91 assert_int_equal(ret, LDB_SUCCESS);
92 assert_int_equal(msg->num_elements, num_elements + 1);
96 int main(int argc, const char **argv)
98 const struct CMUnitTest tests[] = {
99 cmocka_unit_test_setup_teardown(test_lldb_add_msg_attr,
100 lldb_msg_setup,
101 lldb_msg_teardown),
104 cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
106 return cmocka_run_group_tests(tests, NULL, NULL);