File: test_registry.c

package info (click to toggle)
dqlite 1.18.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,372 kB
  • sloc: ansic: 57,583; makefile: 336; sh: 243
file content (85 lines) | stat: -rw-r--r-- 1,713 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "../lib/config.h"
#include "../lib/heap.h"
#include "../lib/logger.h"
#include "../lib/registry.h"
#include "../lib/runner.h"
#include "../lib/sqlite.h"
#include "../lib/vfs.h"

TEST_MODULE(registry);

#define FIXTURE         \
	FIXTURE_LOGGER; \
	FIXTURE_VFS;    \
	FIXTURE_CONFIG; \
	FIXTURE_REGISTRY;

#define SETUP         \
	SETUP_HEAP;   \
	SETUP_SQLITE; \
	SETUP_LOGGER; \
	SETUP_VFS;    \
	SETUP_CONFIG; \
	SETUP_REGISTRY;

#define TEAR_DOWN           \
	TEAR_DOWN_REGISTRY; \
	TEAR_DOWN_CONFIG;   \
	TEAR_DOWN_VFS;      \
	TEAR_DOWN_LOGGER;   \
	TEAR_DOWN_SQLITE;   \
	TEAR_DOWN_HEAP;

/******************************************************************************
 *
 * db-related APIs.
 *
 ******************************************************************************/

struct db_fixture
{
	FIXTURE;
};

TEST_SUITE(db);
TEST_SETUP(db)
{
	struct db_fixture *f = munit_malloc(sizeof *f);
	SETUP;
	return f;
}
TEST_TEAR_DOWN(db)
{
	struct db_fixture *f = data;
	TEAR_DOWN;
	free(f);
}

/* Get a db that didn't exist before. */
TEST_CASE(db, get_new, NULL)
{
	struct db_fixture *f = data;
	struct db *db;
	(void)params;
	int rc;
	rc = registry__get_or_create(&f->registry, "test.db", &db);
	munit_assert_int(rc, ==, 0);
	munit_assert_string_equal(db->filename, "test.db");
	return MUNIT_OK;
}

/* Get a previously registered db. */
TEST_CASE(db, get_existing, NULL)
{
	struct db_fixture *f = data;
	struct db *db1;
	struct db *db2;
	(void)params;
	int rc;
	rc = registry__get_or_create(&f->registry, "test.db", &db1);
	munit_assert_int(rc, ==, 0);
	rc = registry__get_or_create(&f->registry, "test.db", &db2);
	munit_assert_int(rc, ==, 0);
	munit_assert_ptr_equal(db1, db2);
	return MUNIT_OK;
}