3 * These headers or their equivalents should be included prior to
11 * This allows test applications to use custom definitions of C standard
12 * library functions and types.
25 #include <ldb_private.h>
29 int ldb_ldap_init(const char *version
);
31 #include "ldb_ldap/ldb_ldap.c"
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
);
59 static int lldb_msg_teardown(void **state
)
61 struct test_ctx
*test_ctx
= talloc_get_type_abort(*state
,
64 talloc_free(test_ctx
);
68 static void test_lldb_add_msg_attr(void **state
)
70 struct test_ctx
*test_ctx
= talloc_get_type_abort(*state
,
72 struct ldb_message
*msg
= test_ctx
->msg
;
74 unsigned int num_elements
= 0;
75 struct berval
**v
= NULL
;
77 v
= talloc_zero_array(test_ctx
, struct berval
*, 2);
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
,
104 cmocka_set_message_output(CM_OUTPUT_SUBUNIT
);
106 return cmocka_run_group_tests(tests
, NULL
, NULL
);