server/src/kernel/save.test.c

69 lines
1.6 KiB
C
Raw Normal View History

#include <platform.h>
#include <kernel/config.h>
#include "save.h"
#include "unit.h"
#include "faction.h"
#include "version.h"
#include <CuTest.h>
#include <tests.h>
#include <stdio.h>
static void test_readwrite_data(CuTest * tc)
{
const char *filename = "test.dat";
char path[MAX_PATH];
test_cleanup();
sprintf(path, "%s/%s", datapath(), filename);
CuAssertIntEquals(tc, 0, writegame(filename));
2015-05-13 02:18:51 +02:00
CuAssertIntEquals(tc, 0, readgame(filename, false));
CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version);
CuAssertIntEquals(tc, 0, remove(path));
test_cleanup();
}
static void test_readwrite_unit(CuTest * tc)
{
const char *filename = "test.dat";
char path[MAX_PATH];
gamedata *data;
struct unit *u;
struct region *r;
struct faction *f;
int fno;
test_cleanup();
r = test_create_region(0, 0, 0);
f = test_create_faction(0);
fno = f->no;
u = test_create_unit(f, r);
_mkdir(datapath());
sprintf(path, "%s/%s", datapath(), filename);
data = gamedata_open(path, "wb");
write_unit(data, u);
gamedata_close(data);
free_gamedata();
f = test_create_faction(0);
renumber_faction(f, fno);
data = gamedata_open(path, "rb");
u = read_unit(data);
gamedata_close(data);
CuAssertPtrNotNull(tc, u);
CuAssertPtrEquals(tc, f, u->faction);
CuAssertPtrEquals(tc, 0, u->region);
CuAssertIntEquals(tc, 0, remove(path));
test_cleanup();
}
CuSuite *get_save_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_readwrite_data);
SUITE_ADD_TEST(suite, test_readwrite_unit);
return suite;
}