LCOV - code coverage report
Current view: top level - lib/ldb/tests - lldb_ldap.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 35 35 100.0 %
Date: 2021-08-25 13:27:56 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  * from cmocka.c:
       3             :  * These headers or their equivalents should be included prior to
       4             :  * including
       5             :  * this header file.
       6             :  *
       7             :  * #include <stdarg.h>
       8             :  * #include <stddef.h>
       9             :  * #include <setjmp.h>
      10             :  *
      11             :  * This allows test applications to use custom definitions of C standard
      12             :  * library functions and types.
      13             :  */
      14             : #include <stdarg.h>
      15             : #include <stddef.h>
      16             : #include <stdint.h>
      17             : #include <setjmp.h>
      18             : #include <cmocka.h>
      19             : 
      20             : #include <errno.h>
      21             : #include <unistd.h>
      22             : #include <talloc.h>
      23             : 
      24             : #include <ldb.h>
      25             : #include <ldb_private.h>
      26             : #include <string.h>
      27             : #include <ctype.h>
      28             : 
      29             : int ldb_ldap_init(const char *version);
      30             : 
      31             : #include "ldb_ldap/ldb_ldap.c"
      32             : 
      33             : struct test_ctx {
      34             :         struct tevent_context *ev;
      35             :         struct ldb_context *ldb;
      36             :         struct ldb_message *msg;
      37             : };
      38             : 
      39           1 : static int lldb_msg_setup(void **state)
      40             : {
      41             :         struct test_ctx *test_ctx;
      42             : 
      43           1 :         test_ctx = talloc_zero(NULL, struct test_ctx);
      44           1 :         assert_non_null(test_ctx);
      45             : 
      46           1 :         test_ctx->ev = tevent_context_init(test_ctx);
      47           1 :         assert_non_null(test_ctx->ev);
      48             : 
      49           1 :         test_ctx->ldb = ldb_init(test_ctx, test_ctx->ev);
      50           1 :         assert_non_null(test_ctx->ldb);
      51             : 
      52           1 :         test_ctx->msg = ldb_msg_new(test_ctx);
      53           1 :         assert_non_null(test_ctx->msg);
      54             : 
      55           1 :         *state = test_ctx;
      56           1 :         return 0;
      57             : }
      58             : 
      59           1 : static int lldb_msg_teardown(void **state)
      60             : {
      61           1 :         struct test_ctx *test_ctx = talloc_get_type_abort(*state,
      62             :                                                           struct test_ctx);
      63             : 
      64           1 :         talloc_free(test_ctx);
      65           1 :         return 0;
      66             : }
      67             : 
      68           1 : static void test_lldb_add_msg_attr(void **state)
      69             : {
      70           1 :         struct test_ctx *test_ctx = talloc_get_type_abort(*state,
      71             :                                                           struct test_ctx);
      72           1 :         struct ldb_message *msg = test_ctx->msg;
      73             :         int ret;
      74           1 :         unsigned int num_elements = 0;
      75           1 :         struct berval **v = NULL;
      76             : 
      77           1 :         v = talloc_zero_array(test_ctx, struct berval *, 2);
      78           1 :         assert_non_null(v);
      79             : 
      80           1 :         v[0] = talloc_zero(v, struct berval);
      81           1 :         assert_non_null(v[0]);
      82             : 
      83           1 :         v[0]->bv_val = talloc_strdup(msg, "dc=example,dc=test");
      84           1 :         assert_non_null(v[0]->bv_val);
      85             : 
      86           1 :         v[0]->bv_len = strlen(v[0]->bv_val);
      87             : 
      88           1 :         num_elements = msg->num_elements;
      89             : 
      90           1 :         ret = lldb_add_msg_attr(test_ctx->ldb, msg, "defaultNamingContext", v);
      91           1 :         assert_int_equal(ret, LDB_SUCCESS);
      92           1 :         assert_int_equal(msg->num_elements, num_elements + 1);
      93           1 : }
      94             : 
      95             : 
      96           1 : int main(int argc, const char **argv)
      97             : {
      98           1 :         const struct CMUnitTest tests[] = {
      99             :                 cmocka_unit_test_setup_teardown(test_lldb_add_msg_attr,
     100             :                                                 lldb_msg_setup,
     101             :                                                 lldb_msg_teardown),
     102             :         };
     103             : 
     104           1 :         return cmocka_run_group_tests(tests, NULL, NULL);
     105             : }

Generated by: LCOV version 1.13