1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
samba-mirror/lib/ldb/tests/ldb_no_lmdb_test.c
Fabrice Fontaine f8799bf076 lib/ldb/tests: include stdint.h before cmocka.h
This fix the following build failures:

[2466/3864] Linking bin/default/lib/ldb/ldbmodify
In file included from /home/buildroot/autobuild/instance-0/output-1/host/opt/ext-toolchain/lib/gcc/mips64el-buildroot-linux-uclibc/5.5.0/include/stdint.h:9:0,
                 from ../../lib/tevent/tevent.h:31,
                 from ../../lib/ldb/include/ldb.h:51,
                 from ../../lib/ldb/tests/test_ldb_dn.c:25:
/home/buildroot/autobuild/instance-0/output-1/host/mips64el-buildroot-linux-uclibc/sysroot/usr/include/stdint.h:122:27: error: conflicting types for 'uintptr_t'
 typedef unsigned long int uintptr_t;
                           ^
In file included from ../../lib/ldb/tests/test_ldb_dn.c:23:0:
/home/buildroot/autobuild/instance-0/output-1/host/mips64el-buildroot-linux-uclibc/sysroot/usr/include/cmocka.h:132:28: note: previous declaration of 'uintptr_t' was here
       typedef unsigned int uintptr_t;
                            ^

In file included from /home/buildroot/autobuild/instance-0/output-1/host/opt/ext-toolchain/lib/gcc/mips64el-buildroot-linux-uclibc/5.5.0/include/stdint.h:9:0,
                 from ../../lib/tevent/tevent.h:31,
                 from ../../lib/ldb/tests/ldb_key_value_test.c:48:
/home/buildroot/autobuild/instance-0/output-1/host/mips64el-buildroot-linux-uclibc/sysroot/usr/include/stdint.h:122:27: error: conflicting types for 'uintptr_t'
 typedef unsigned long int uintptr_t;
                           ^
In file included from ../../lib/ldb/tests/ldb_key_value_test.c:43:0:
/home/buildroot/autobuild/instance-0/output-1/host/mips64el-buildroot-linux-uclibc/sysroot/usr/include/cmocka.h:132:28: note: previous declaration of 'uintptr_t' was here
       typedef unsigned int uintptr_t;
                            ^

Fixes:
 - http://autobuild.buildroot.org/results/9507739b3d5d51024ee9c60b74c2f85d5004e7e2

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14218

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Reviewed-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-12-18 15:32:40 +00:00

160 lines
3.5 KiB
C

/*
* Ensure lmdb backend is disabled
*
* Copyright (C) Mathieu Parent <math.parent@gmail.com> 2019
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Ensure lmdb backend is disabled
*
* Setup and tear down code copied from ldb_lmdb_test.c
*/
/*
* from cmocka.c:
* These headers or their equivalents should be included prior to
* including
* this header file.
*
* #include <stdarg.h>
* #include <stddef.h>
* #include <setjmp.h>
*
* This allows test applications to use custom definitions of C standard
* library functions and types.
*
*/
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>
#include <errno.h>
#include <unistd.h>
#include <talloc.h>
#include <tevent.h>
#include <ldb.h>
#define TEST_BE "mdb"
struct ldbtest_ctx {
struct tevent_context *ev;
struct ldb_context *ldb;
const char *dbfile;
const char *lockfile; /* lockfile is separate */
const char *dbpath;
};
static void unlink_old_db(struct ldbtest_ctx *test_ctx)
{
int ret;
errno = 0;
ret = unlink(test_ctx->lockfile);
if (ret == -1 && errno != ENOENT) {
fail();
}
errno = 0;
ret = unlink(test_ctx->dbfile);
if (ret == -1 && errno != ENOENT) {
fail();
}
}
static int ldbtest_noconn_setup(void **state)
{
struct ldbtest_ctx *test_ctx;
test_ctx = talloc_zero(NULL, struct ldbtest_ctx);
assert_non_null(test_ctx);
test_ctx->ev = tevent_context_init(test_ctx);
assert_non_null(test_ctx->ev);
test_ctx->ldb = ldb_init(test_ctx, test_ctx->ev);
assert_non_null(test_ctx->ldb);
test_ctx->dbfile = talloc_strdup(test_ctx, "apitest.ldb");
assert_non_null(test_ctx->dbfile);
test_ctx->lockfile = talloc_asprintf(test_ctx, "%s-lock",
test_ctx->dbfile);
assert_non_null(test_ctx->lockfile);
test_ctx->dbpath = talloc_asprintf(test_ctx,
TEST_BE"://%s", test_ctx->dbfile);
assert_non_null(test_ctx->dbpath);
unlink_old_db(test_ctx);
*state = test_ctx;
return 0;
}
static int ldbtest_noconn_teardown(void **state)
{
struct ldbtest_ctx *test_ctx = talloc_get_type_abort(*state,
struct ldbtest_ctx);
unlink_old_db(test_ctx);
talloc_free(test_ctx);
return 0;
}
static int ldbtest_setup(void **state)
{
struct ldbtest_ctx *test_ctx;
int ret;
ldbtest_noconn_setup((void **) &test_ctx);
ret = ldb_connect(test_ctx->ldb, test_ctx->dbpath, 0, NULL);
assert_int_equal(ret, LDB_ERR_OTHER);
*state = test_ctx;
return 0;
}
static int ldbtest_teardown(void **state)
{
struct ldbtest_ctx *test_ctx = talloc_get_type_abort(*state,
struct ldbtest_ctx);
ldbtest_noconn_teardown((void **) &test_ctx);
return 0;
}
static void test_ldb_lmdb_not_found(void **state)
{
// Actual test in ldbtest_setup
assert_int_equal(0, 0);
}
int main(int argc, const char **argv)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(
test_ldb_lmdb_not_found,
ldbtest_setup,
ldbtest_teardown),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}