fix symetric db_open and db_close calls.

This commit is contained in:
Enno Rehling 2017-11-09 20:17:06 +01:00
parent fee9b6d0a8
commit 9f778c0ae9
6 changed files with 12 additions and 9 deletions

View File

@ -32,7 +32,7 @@ static void test_command(CuTest * tc) {
struct locale * loc; struct locale * loc;
unit *u; unit *u;
test_cleanup(); test_setup();
loc = test_create_locale(); loc = test_create_locale();
st = stree_create(); st = stree_create();
CuAssertPtrNotNull(tc, st); CuAssertPtrNotNull(tc, st);

View File

@ -14,7 +14,7 @@ static void test_save_load_order(CuTest *tc) {
int id; int id;
const char * s = "GIB enno 1 Hodor"; const char * s = "GIB enno 1 Hodor";
db_open(); test_setup();
odata_create(&od, strlen(s) + 1, s); odata_create(&od, strlen(s) + 1, s);
CuAssertTrue(tc, od->_refcount >= 1); CuAssertTrue(tc, od->_refcount >= 1);
@ -28,7 +28,7 @@ static void test_save_load_order(CuTest *tc) {
CuAssertStrEquals(tc, s, od->_str); CuAssertStrEquals(tc, s, od->_str);
odata_release(od); odata_release(od);
db_close(); test_cleanup();
} }
CuSuite *get_db_suite(void) CuSuite *get_db_suite(void)

View File

@ -6,11 +6,12 @@
#include <critbit.h> #include <critbit.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
static critbit_tree cb_orders = { 0 }; static critbit_tree cb_orders = { 0 };
static int auto_id = 0; static int auto_id = -1;
struct cb_entry { struct cb_entry {
int id; int id;
@ -50,15 +51,13 @@ static int free_data_cb(const void *match, const void *key, size_t keylen,
{ {
struct cb_entry * ent = (struct cb_entry *)match; struct cb_entry * ent = (struct cb_entry *)match;
order_data *od = ent->data; order_data *od = ent->data;
if (od->_refcount > 1) {
log_error("refcount=%d for order %d, %s", od->_refcount, ent->id, od->_str);
}
odata_release(od); odata_release(od);
return 0; return 0;
} }
void db_open(void) void db_open(void)
{ {
assert(auto_id == -1);
auto_id = 0; auto_id = 0;
} }
@ -66,4 +65,5 @@ void db_close(void)
{ {
cb_foreach(&cb_orders, NULL, 0, free_data_cb, NULL); cb_foreach(&cb_orders, NULL, 0, free_data_cb, NULL);
cb_clear(&cb_orders); cb_clear(&cb_orders);
auto_id = -1;
} }

View File

@ -9,7 +9,7 @@ static void test_plane(CuTest *tc) {
struct region *r; struct region *r;
plane *pl; plane *pl;
test_cleanup(); test_setup();
r = test_create_region(0, 0, 0); r = test_create_region(0, 0, 0);
CuAssertPtrEquals(tc, 0, findplane(0, 0)); CuAssertPtrEquals(tc, 0, findplane(0, 0));
CuAssertPtrEquals(tc, 0, getplane(r)); CuAssertPtrEquals(tc, 0, getplane(r));
@ -38,13 +38,14 @@ static void test_plane(CuTest *tc) {
CuAssertIntEquals(tc, 60, plane_center_y(pl)); CuAssertIntEquals(tc, 60, plane_center_y(pl));
CuAssertIntEquals(tc, 5, plane_width(pl)); CuAssertIntEquals(tc, 5, plane_width(pl));
CuAssertIntEquals(tc, 41, plane_height(pl)); CuAssertIntEquals(tc, 41, plane_height(pl));
test_cleanup();
} }
static void test_origin(CuTest *tc) { static void test_origin(CuTest *tc) {
struct faction *f; struct faction *f;
int x, y; int x, y;
test_cleanup(); test_setup();
f = test_create_faction(0); f = test_create_faction(0);
x = 0; x = 0;
y = 0; y = 0;

View File

@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/log.h> #include <util/log.h>
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/db.h>
#include <kernel/version.h> #include <kernel/version.h>
#include <kernel/save.h> #include <kernel/save.h>
#include <util/filereader.h> #include <util/filereader.h>

View File

@ -1,6 +1,7 @@
#include <platform.h> #include <platform.h>
#include <eressea.h> #include <eressea.h>
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/db.h>
#include <CuTest.h> #include <CuTest.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>