| 1 |
#include "../lib/config.h" |
| 2 |
#include "../lib/heap.h" |
| 3 |
#include "../lib/logger.h" |
| 4 |
#include "../lib/registry.h" |
| 5 |
#include "../lib/runner.h" |
| 6 |
#include "../lib/sqlite.h" |
| 7 |
#include "../lib/vfs.h" |
| 8 |
|
| 9 |
TEST_MODULE(registry); |
| 10 |
|
| 11 |
#define FIXTURE \ |
| 12 |
FIXTURE_LOGGER; \ |
| 13 |
FIXTURE_VFS; \ |
| 14 |
FIXTURE_CONFIG; \ |
| 15 |
FIXTURE_REGISTRY; |
| 16 |
|
| 17 |
#define SETUP \ |
| 18 |
SETUP_HEAP; \ |
| 19 |
SETUP_SQLITE; \ |
| 20 |
SETUP_LOGGER; \ |
| 21 |
SETUP_VFS; \ |
| 22 |
SETUP_CONFIG; \ |
| 23 |
SETUP_REGISTRY; |
| 24 |
|
| 25 |
#define TEAR_DOWN \ |
| 26 |
TEAR_DOWN_REGISTRY; \ |
| 27 |
TEAR_DOWN_CONFIG; \ |
| 28 |
TEAR_DOWN_VFS; \ |
| 29 |
TEAR_DOWN_LOGGER; \ |
| 30 |
TEAR_DOWN_SQLITE; \ |
| 31 |
TEAR_DOWN_HEAP; |
| 32 |
|
| 33 |
/****************************************************************************** |
| 34 |
* |
| 35 |
* db-related APIs. |
| 36 |
* |
| 37 |
******************************************************************************/ |
| 38 |
|
| 39 |
struct db_fixture |
| 40 |
{ |
| 41 |
FIXTURE; |
| 42 |
}; |
| 43 |
|
| 44 |
TEST_SUITE(db); |
| 45 |
TEST_SETUP(db) |
| 46 |
{ |
| 47 |
struct db_fixture *f = munit_malloc(sizeof *f); |
| 48 |
SETUP; |
| 49 |
return f; |
| 50 |
} |
| 51 |
TEST_TEAR_DOWN(db) |
| 52 |
{ |
| 53 |
struct db_fixture *f = data; |
| 54 |
TEAR_DOWN; |
| 55 |
free(f); |
| 56 |
} |
| 57 |
|
| 58 |
/* Get a db that didn't exist before. */ |
| 59 |
TEST_CASE(db, get_new, NULL) |
| 60 |
{ |
| 61 |
struct db_fixture *f = data; |
| 62 |
struct db *db; |
| 63 |
(void)params; |
| 64 |
int rc; |
| 65 |
rc = registry__db_get(&f->registry, "test.db", &db); |
| 66 |
munit_assert_int(rc, ==, 0); |
| 67 |
munit_assert_string_equal(db->filename, "test.db"); |
| 68 |
return MUNIT_OK; |
| 69 |
} |
| 70 |
|
| 71 |
/* Get a previously registered db. */ |
| 72 |
TEST_CASE(db, get_existing, NULL) |
| 73 |
{ |
| 74 |
struct db_fixture *f = data; |
| 75 |
struct db *db1; |
| 76 |
struct db *db2; |
| 77 |
(void)params; |
| 78 |
int rc; |
| 79 |
rc = registry__db_get(&f->registry, "test.db", &db1); |
| 80 |
munit_assert_int(rc, ==, 0); |
| 81 |
rc = registry__db_get(&f->registry, "test.db", &db2); |
| 82 |
munit_assert_int(rc, ==, 0); |
| 83 |
munit_assert_ptr_equal(db1, db2); |
| 84 |
return MUNIT_OK; |
| 85 |
} |