forked from github/server
orderdb backend choices and first tests.
This commit is contained in:
parent
e1afdd95bf
commit
6d79f85628
|
@ -219,6 +219,7 @@ set(TESTS_SRC
|
|||
monsters.test.c
|
||||
move.test.c
|
||||
names.test.c
|
||||
orderdb.test.c
|
||||
orderfile.test.c
|
||||
piracy.test.c
|
||||
prefix.test.c
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#include <util/message.h>
|
||||
#include <races/races.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void game_done(void)
|
||||
{
|
||||
#ifdef CLEANUP_CODE
|
||||
|
@ -63,7 +65,10 @@ void game_done(void)
|
|||
|
||||
void game_init(void)
|
||||
{
|
||||
orderdb_open();
|
||||
db_backend choices[] = { DB_MEMORY, DB_NONE };
|
||||
if (orderdb_open(choices) == DB_NONE) {
|
||||
log_fatal("no orderdb backend available");
|
||||
}
|
||||
kernel_init();
|
||||
register_triggers();
|
||||
register_xmas();
|
||||
|
|
|
@ -15,6 +15,8 @@ struct cb_entry {
|
|||
order_data *data;
|
||||
};
|
||||
|
||||
static db_backend odata_backend = DB_NONE;
|
||||
|
||||
order_data *odata_load(int id)
|
||||
{
|
||||
void * match;
|
||||
|
@ -67,9 +69,17 @@ void free_data(void) {
|
|||
cb_clear(&cb_orders);
|
||||
}
|
||||
|
||||
void orderdb_open(void)
|
||||
db_backend orderdb_open(db_backend choices[])
|
||||
{
|
||||
auto_id = 0;
|
||||
int i;
|
||||
for (i = 0; choices[i] != DB_NONE; ++i) {
|
||||
db_backend choice = choices[i];
|
||||
if (choice == DB_MEMORY) {
|
||||
auto_id = 0;
|
||||
return odata_backend = choice;
|
||||
}
|
||||
}
|
||||
return DB_NONE;
|
||||
}
|
||||
|
||||
void orderdb_close(void)
|
||||
|
|
|
@ -5,12 +5,20 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
DB_NONE,
|
||||
DB_MEMORY,
|
||||
DB_MMAP,
|
||||
DB_BDB,
|
||||
DB_SQLITE
|
||||
} db_backend;
|
||||
|
||||
typedef struct order_data {
|
||||
const char *_str;
|
||||
int _refcount;
|
||||
} order_data;
|
||||
|
||||
void orderdb_open(void);
|
||||
db_backend orderdb_open(db_backend choices[]);
|
||||
void orderdb_close(void);
|
||||
|
||||
order_data *odata_load(int id);
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
|
||||
#include "orderdb.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
static void test_orderdb_open_close(CuTest *tc) {
|
||||
db_backend choices[] = { DB_MEMORY, DB_NONE };
|
||||
db_backend nochoice[] = { DB_SQLITE, DB_NONE };
|
||||
|
||||
CuAssertIntEquals(tc, DB_MEMORY, orderdb_open(choices));
|
||||
orderdb_close();
|
||||
|
||||
CuAssertIntEquals(tc, DB_NONE, orderdb_open(nochoice));
|
||||
|
||||
orderdb_close();
|
||||
}
|
||||
|
||||
CuSuite *get_orderdb_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_orderdb_open_close);
|
||||
|
||||
return suite;
|
||||
}
|
|
@ -132,6 +132,7 @@ int RunAllTests(int argc, char *argv[])
|
|||
ADD_SUITE(monsters);
|
||||
ADD_SUITE(move);
|
||||
ADD_SUITE(names);
|
||||
ADD_SUITE(orderdb);
|
||||
ADD_SUITE(orderfile);
|
||||
ADD_SUITE(otherfaction);
|
||||
ADD_SUITE(piracy);
|
||||
|
|
|
@ -218,6 +218,7 @@ void log_fatal(const char *format, ...)
|
|||
va_start(args, format);
|
||||
log_write(LOG_CPERROR, NULL, format, args);
|
||||
va_end(args);
|
||||
abort();
|
||||
}
|
||||
|
||||
void log_error(const char *format, ...) /*-V524 */
|
||||
|
|
Loading…
Reference in New Issue