2 * Ensure lmdb backend is disabled
4 * Copyright (C) Mathieu Parent <math.parent@gmail.com> 2019
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * Ensure lmdb backend is disabled
24 * Setup and tear down code copied from ldb_lmdb_test.c
29 * These headers or their equivalents should be included prior to
37 * This allows test applications to use custom definitions of C standard
38 * library functions and types.
56 struct tevent_context
*ev
;
57 struct ldb_context
*ldb
;
60 const char *lockfile
; /* lockfile is separate */
65 static void unlink_old_db(struct ldbtest_ctx
*test_ctx
)
70 ret
= unlink(test_ctx
->lockfile
);
71 if (ret
== -1 && errno
!= ENOENT
) {
76 ret
= unlink(test_ctx
->dbfile
);
77 if (ret
== -1 && errno
!= ENOENT
) {
82 static int ldbtest_noconn_setup(void **state
)
84 struct ldbtest_ctx
*test_ctx
;
86 test_ctx
= talloc_zero(NULL
, struct ldbtest_ctx
);
87 assert_non_null(test_ctx
);
89 test_ctx
->ev
= tevent_context_init(test_ctx
);
90 assert_non_null(test_ctx
->ev
);
92 test_ctx
->ldb
= ldb_init(test_ctx
, test_ctx
->ev
);
93 assert_non_null(test_ctx
->ldb
);
95 test_ctx
->dbfile
= talloc_strdup(test_ctx
, "apitest.ldb");
96 assert_non_null(test_ctx
->dbfile
);
98 test_ctx
->lockfile
= talloc_asprintf(test_ctx
, "%s-lock",
100 assert_non_null(test_ctx
->lockfile
);
102 test_ctx
->dbpath
= talloc_asprintf(test_ctx
,
103 TEST_BE
"://%s", test_ctx
->dbfile
);
104 assert_non_null(test_ctx
->dbpath
);
106 unlink_old_db(test_ctx
);
111 static int ldbtest_noconn_teardown(void **state
)
113 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
116 unlink_old_db(test_ctx
);
117 talloc_free(test_ctx
);
121 static int ldbtest_setup(void **state
)
123 struct ldbtest_ctx
*test_ctx
;
126 ldbtest_noconn_setup((void **) &test_ctx
);
128 ret
= ldb_connect(test_ctx
->ldb
, test_ctx
->dbpath
, 0, NULL
);
129 assert_int_equal(ret
, LDB_ERR_OTHER
);
135 static int ldbtest_teardown(void **state
)
137 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
139 ldbtest_noconn_teardown((void **) &test_ctx
);
143 static void test_ldb_lmdb_not_found(void **state
)
145 // Actual test in ldbtest_setup
146 assert_int_equal(0, 0);
149 int main(int argc
, const char **argv
)
151 const struct CMUnitTest tests
[] = {
152 cmocka_unit_test_setup_teardown(
153 test_ldb_lmdb_not_found
,
158 cmocka_set_message_output(CM_OUTPUT_SUBUNIT
);
160 return cmocka_run_group_tests(tests
, NULL
, NULL
);