2017-11-09 19:55:28 +01:00
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/config.h>
|
2018-09-24 20:18:21 +02:00
|
|
|
#include <kernel/faction.h>
|
2018-09-28 21:02:32 +02:00
|
|
|
#include <kernel/order.h>
|
2017-11-09 19:55:28 +01:00
|
|
|
|
2018-10-24 09:02:19 +02:00
|
|
|
#include "database.h"
|
2018-09-28 20:50:24 +02:00
|
|
|
#include "db/driver.h"
|
2017-11-09 19:55:28 +01:00
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
|
2018-09-24 20:18:21 +02:00
|
|
|
#include <stdio.h>
|
2017-11-09 19:55:28 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2018-10-24 09:02:19 +02:00
|
|
|
static void test_orderdb(CuTest *tc) {
|
|
|
|
order_data *od = NULL;
|
|
|
|
const char * s = "GIB enno 1 Hodor";
|
|
|
|
|
|
|
|
odata_create(&od, strlen(s) + 1, s);
|
|
|
|
CuAssertPtrNotNull(tc, od);
|
|
|
|
CuAssertStrEquals(tc, s, od->_str);
|
|
|
|
CuAssertTrue(tc, od->_refcount >= 1);
|
|
|
|
odata_release(od);
|
|
|
|
}
|
|
|
|
|
2017-11-09 19:55:28 +01:00
|
|
|
static void test_save_load_order(CuTest *tc) {
|
|
|
|
order_data *od;
|
|
|
|
int id;
|
|
|
|
const char * s = "GIB enno 1 Hodor";
|
|
|
|
|
2017-11-09 20:17:06 +01:00
|
|
|
test_setup();
|
2017-11-09 19:55:28 +01:00
|
|
|
|
|
|
|
odata_create(&od, strlen(s) + 1, s);
|
|
|
|
CuAssertTrue(tc, od->_refcount >= 1);
|
|
|
|
id = odata_save(od);
|
|
|
|
odata_release(od);
|
|
|
|
CuAssertTrue(tc, id != 0);
|
|
|
|
|
|
|
|
od = odata_load(id);
|
|
|
|
CuAssertPtrNotNull(tc, od);
|
|
|
|
CuAssertTrue(tc, od->_refcount >= 1);
|
|
|
|
CuAssertStrEquals(tc, s, od->_str);
|
|
|
|
odata_release(od);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-11-09 19:55:28 +01:00
|
|
|
}
|
|
|
|
|
2018-09-24 20:18:21 +02:00
|
|
|
static void test_update_faction(CuTest *tc) {
|
|
|
|
faction *f;
|
2019-04-23 13:18:51 +02:00
|
|
|
int err;
|
|
|
|
dbrow_id id;
|
2018-09-24 20:18:21 +02:00
|
|
|
|
|
|
|
test_setup();
|
2018-10-24 19:39:30 +02:00
|
|
|
db_driver_open(DB_GAME, NULL);
|
2018-09-24 20:18:21 +02:00
|
|
|
f = test_create_faction(NULL);
|
2019-04-23 13:18:51 +02:00
|
|
|
CuAssertIntEquals(tc, 0, f->uid);
|
|
|
|
id = 0;
|
|
|
|
err = db_driver_faction_save(&id, f->no,
|
2018-10-24 09:27:48 +02:00
|
|
|
faction_getemail(f),
|
|
|
|
faction_getpassword(f));
|
2019-04-24 15:13:27 +02:00
|
|
|
CuAssertIntEquals(tc, 0, err);
|
2019-04-23 13:18:51 +02:00
|
|
|
CuAssertTrue(tc, 0 != id);
|
|
|
|
f->uid = (int)id;
|
|
|
|
db_driver_close(DB_GAME);
|
|
|
|
|
|
|
|
db_driver_open(DB_GAME, NULL);
|
2019-04-24 15:13:27 +02:00
|
|
|
err = db_driver_faction_save(&id, f->no,
|
2018-10-24 09:27:48 +02:00
|
|
|
faction_getemail(f),
|
|
|
|
faction_getpassword(f));
|
2019-04-24 15:13:27 +02:00
|
|
|
CuAssertIntEquals(tc, 0, err);
|
2019-04-23 13:18:51 +02:00
|
|
|
CuAssertIntEquals(tc, f->uid, id);
|
2018-10-24 19:39:30 +02:00
|
|
|
db_driver_close(DB_GAME);
|
2018-09-24 20:18:21 +02:00
|
|
|
test_teardown();
|
|
|
|
}
|
|
|
|
|
2017-11-09 19:55:28 +01:00
|
|
|
CuSuite *get_db_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_save_load_order);
|
2018-09-24 20:18:21 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_update_faction);
|
2018-10-24 09:02:19 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_orderdb);
|
2017-11-09 19:55:28 +01:00
|
|
|
|
|
|
|
return suite;
|
|
|
|
}
|