ldb: Add test for ldb_build_search_req()
authorAndrew Bartlett <abartlet@samba.org>
Tue, 30 May 2017 02:59:16 +0000 (14:59 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 31 May 2017 04:34:27 +0000 (06:34 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/tests/ldb_mod_op_test.c

index 7d8b074e8f26dc45a3c9a4f7a11f1ecf0f440d0f..9bcbb2fc76d2833dd1734938de4f92c971e27a3b 100644 (file)
@@ -418,6 +418,55 @@ static void test_ldb_handle(void **state)
        talloc_free(tmp_ctx);
 }
 
+static void test_ldb_build_search_req(void **state)
+{
+       int ret;
+       struct ldbtest_ctx *test_ctx = talloc_get_type_abort(*state,
+                                                       struct ldbtest_ctx);
+       TALLOC_CTX *tmp_ctx;
+       struct ldb_dn *basedn;
+       struct ldb_request *request = NULL;
+       struct ldb_request *request2 = NULL;
+       struct ldb_result *res = NULL;
+       const char *attrs[] = { "cn", NULL };
+
+       tmp_ctx = talloc_new(test_ctx);
+       assert_non_null(tmp_ctx);
+
+       basedn = ldb_dn_new_fmt(tmp_ctx, test_ctx->ldb, "dc=test");
+       assert_non_null(basedn);
+
+       res = talloc_zero(tmp_ctx, struct ldb_result);
+       assert_non_null(res);
+
+       ret = ldb_build_search_req(&request, test_ctx->ldb, tmp_ctx,
+                                  basedn, LDB_SCOPE_BASE,
+                                  NULL, attrs, NULL, res,
+                                  ldb_search_default_callback,
+                                  NULL);
+       assert_int_equal(ret, 0);
+
+       assert_int_equal(request->operation, LDB_SEARCH);
+       assert_ptr_equal(request->op.search.base, basedn);
+       assert_int_equal(request->op.search.scope, LDB_SCOPE_BASE);
+       assert_non_null(request->op.search.tree);
+       assert_ptr_equal(request->op.search.attrs, attrs);
+       assert_ptr_equal(request->context, res);
+       assert_ptr_equal(request->callback, ldb_search_default_callback);
+
+       ret = ldb_build_search_req(&request2, test_ctx->ldb, tmp_ctx,
+                                  basedn, LDB_SCOPE_BASE,
+                                  NULL, attrs, NULL, res,
+                                  ldb_search_default_callback,
+                                  request);
+       assert_int_equal(ret, 0);
+       assert_ptr_equal(request, request2->handle->parent);
+       assert_int_equal(request->starttime, request2->starttime);
+       assert_int_equal(request->timeout, request2->timeout);
+
+       talloc_free(tmp_ctx);
+}
+
 static void add_keyval(struct ldbtest_ctx *test_ctx,
                       const char *key,
                       const char *val)
@@ -1956,6 +2005,9 @@ int main(int argc, const char **argv)
                cmocka_unit_test_setup_teardown(test_ldb_handle,
                                                ldbtest_setup,
                                                ldbtest_teardown),
+               cmocka_unit_test_setup_teardown(test_ldb_build_search_req,
+                                               ldbtest_setup,
+                                               ldbtest_teardown),
                cmocka_unit_test_setup_teardown(test_transactions,
                                                ldbtest_setup,
                                                ldbtest_teardown),