2014-10-31 19:15:26 +01:00
|
|
|
#include <platform.h>
|
|
|
|
#include "types.h"
|
2014-11-03 18:10:05 +01:00
|
|
|
#include "ally.h"
|
2014-10-31 19:15:26 +01:00
|
|
|
#include "group.h"
|
|
|
|
#include "faction.h"
|
|
|
|
#include "unit.h"
|
|
|
|
#include "region.h"
|
2016-02-13 13:42:02 +01:00
|
|
|
#include "save.h"
|
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
#include <util/gamedata.h>
|
2016-02-16 07:30:26 +01:00
|
|
|
#include <util/attrib.h>
|
|
|
|
#include <attributes/key.h>
|
2016-02-13 13:42:02 +01:00
|
|
|
|
2014-11-03 22:29:04 +01:00
|
|
|
#include <stream.h>
|
|
|
|
#include <filestream.h>
|
2014-11-03 18:10:05 +01:00
|
|
|
#include <storage.h>
|
|
|
|
#include <binarystore.h>
|
2014-10-31 19:15:26 +01:00
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2014-11-03 18:10:05 +01:00
|
|
|
static void test_group_readwrite(CuTest * tc)
|
|
|
|
{
|
|
|
|
faction * f;
|
|
|
|
group *g;
|
|
|
|
ally *al;
|
2016-02-16 07:30:26 +01:00
|
|
|
int i;
|
2016-02-13 13:42:02 +01:00
|
|
|
gamedata *data;
|
2014-11-03 18:10:05 +01:00
|
|
|
|
|
|
|
test_cleanup();
|
2016-02-13 13:42:02 +01:00
|
|
|
data = gamedata_open("test.dat", "wb", RELEASE_VERSION);
|
2016-02-25 10:16:50 +01:00
|
|
|
CuAssertPtrNotNull(tc, data);
|
2014-11-03 18:10:05 +01:00
|
|
|
f = test_create_faction(0);
|
2016-02-16 07:30:26 +01:00
|
|
|
g = new_group(f, "NW", 42);
|
|
|
|
g = new_group(f, "Egoisten", 43);
|
2016-02-23 10:47:33 +01:00
|
|
|
key_set(&g->attribs, 44);
|
2014-11-03 18:10:05 +01:00
|
|
|
al = ally_add(&g->allies, f);
|
2014-11-03 18:44:49 +01:00
|
|
|
al->status = HELP_GIVE;
|
2016-02-13 13:42:02 +01:00
|
|
|
write_groups(data->store, f);
|
|
|
|
WRITE_INT(data->store, 47);
|
|
|
|
binstore_done(data->store);
|
|
|
|
gamedata_close(data);
|
2014-11-03 18:10:05 +01:00
|
|
|
|
|
|
|
f->groups = 0;
|
2016-02-13 13:42:02 +01:00
|
|
|
free_group(g);
|
|
|
|
data = gamedata_open("test.dat", "rb", RELEASE_VERSION);
|
|
|
|
read_groups(data, f);
|
|
|
|
READ_INT(data->store, &i);
|
|
|
|
gamedata_close(data);
|
2014-11-03 18:10:05 +01:00
|
|
|
|
2016-02-16 07:30:26 +01:00
|
|
|
CuAssertIntEquals(tc, 47, i);
|
2014-11-03 18:10:05 +01:00
|
|
|
CuAssertPtrNotNull(tc, f->groups);
|
2016-02-16 07:30:26 +01:00
|
|
|
CuAssertIntEquals(tc, 42, f->groups->gid);
|
|
|
|
CuAssertStrEquals(tc, "NW", f->groups->name);
|
|
|
|
CuAssertPtrNotNull(tc, f->groups->next);
|
|
|
|
CuAssertIntEquals(tc, 43, f->groups->next->gid);
|
|
|
|
CuAssertStrEquals(tc, "Egoisten", f->groups->next->name);
|
|
|
|
CuAssertPtrEquals(tc, 0, f->groups->allies);
|
|
|
|
g = f->groups->next;
|
2016-02-23 10:47:33 +01:00
|
|
|
CuAssertTrue(tc, key_get(g->attribs, 44));
|
2016-02-16 07:30:26 +01:00
|
|
|
CuAssertPtrNotNull(tc, g->allies);
|
|
|
|
CuAssertPtrEquals(tc, 0, g->allies->next);
|
|
|
|
CuAssertPtrEquals(tc, f, g->allies->faction);
|
|
|
|
CuAssertIntEquals(tc, HELP_GIVE, g->allies->status);
|
2014-11-04 08:06:46 +01:00
|
|
|
remove("test.dat");
|
2014-11-03 18:10:05 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-10-31 19:15:26 +01:00
|
|
|
static void test_group(CuTest * tc)
|
|
|
|
{
|
|
|
|
unit *u;
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
group *g;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
r = findregion(0, 0);
|
|
|
|
f = test_create_faction(0);
|
|
|
|
assert(r && f);
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
assert(u);
|
2016-02-16 07:30:26 +01:00
|
|
|
CuAssertPtrNotNull(tc, (g = join_group(u, "hodor")));
|
|
|
|
CuAssertPtrEquals(tc, g, get_group(u));
|
2014-10-31 19:15:26 +01:00
|
|
|
CuAssertStrEquals(tc, "hodor", g->name);
|
|
|
|
CuAssertIntEquals(tc, 1, g->members);
|
|
|
|
set_group(u, 0);
|
|
|
|
CuAssertIntEquals(tc, 0, g->members);
|
|
|
|
CuAssertPtrEquals(tc, 0, get_group(u));
|
|
|
|
set_group(u, g);
|
|
|
|
CuAssertIntEquals(tc, 1, g->members);
|
|
|
|
CuAssertPtrEquals(tc, g, get_group(u));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_group_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_group);
|
2014-11-03 18:10:05 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_group_readwrite);
|
2014-10-31 19:15:26 +01:00
|
|
|
return suite;
|
|
|
|
}
|
|
|
|
|