forked from github/server
retrofit tests for alliances.
This commit is contained in:
parent
9b56ccf53c
commit
188e003f7c
6 changed files with 82 additions and 11 deletions
|
@ -1,6 +1,7 @@
|
|||
project(kernel C)
|
||||
|
||||
SET(_TEST_FILES
|
||||
alliance.test.c
|
||||
build.test.c
|
||||
config.test.c
|
||||
group.test.c
|
||||
|
|
|
@ -43,13 +43,18 @@ without prior permission by the authors of Eressea.
|
|||
|
||||
alliance *alliances = NULL;
|
||||
|
||||
void free_alliance(alliance * al)
|
||||
void free_alliances(void)
|
||||
{
|
||||
while (alliances) {
|
||||
alliance *al = alliances;
|
||||
alliances = al->next;
|
||||
free(al->name);
|
||||
if (al->members)
|
||||
if (al->members) {
|
||||
ql_free(al->members);
|
||||
}
|
||||
free(al);
|
||||
}
|
||||
}
|
||||
|
||||
alliance *makealliance(int id, const char *name)
|
||||
{
|
||||
|
|
|
@ -57,7 +57,7 @@ extern "C" {
|
|||
extern alliance *makealliance(int id, const char *name);
|
||||
extern const char *alliancename(const struct alliance *al);
|
||||
extern void setalliance(struct faction *f, alliance * al);
|
||||
void free_alliance(struct alliance *al);
|
||||
void free_alliances(void);
|
||||
extern struct faction *alliance_get_leader(struct alliance *al);
|
||||
extern void alliance_cmd(void);
|
||||
bool is_allied(const struct faction *f1, const struct faction *f2);
|
||||
|
|
68
src/kernel/alliance.test.c
Normal file
68
src/kernel/alliance.test.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/faction.h>
|
||||
#include "alliance.h"
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct alliance_fixture {
|
||||
struct race * rc;
|
||||
struct faction *f1, *f2;
|
||||
} alliance_fixture;
|
||||
|
||||
static void setup_alliance(alliance_fixture *fix) {
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
fix->rc = test_create_race("human");
|
||||
fix->f1 = test_create_faction(fix->rc);
|
||||
fix->f2 = test_create_faction(fix->rc);
|
||||
assert(fix->rc && fix->f1 && fix->f2);
|
||||
}
|
||||
|
||||
static void test_alliance_make(CuTest *tc) {
|
||||
alliance * al;
|
||||
|
||||
test_cleanup();
|
||||
assert(!alliances);
|
||||
al = makealliance(1, "Hodor");
|
||||
CuAssertPtrNotNull(tc, al);
|
||||
CuAssertStrEquals(tc, "Hodor", al->name);
|
||||
CuAssertIntEquals(tc, 1, al->id);
|
||||
CuAssertIntEquals(tc, 0, al->flags);
|
||||
CuAssertPtrEquals(tc, 0, al->members);
|
||||
CuAssertPtrEquals(tc, 0, al->_leader);
|
||||
CuAssertPtrEquals(tc, 0, al->allies);
|
||||
CuAssertPtrEquals(tc, al, findalliance(1));
|
||||
CuAssertPtrEquals(tc, al, alliances);
|
||||
free_alliances();
|
||||
CuAssertPtrEquals(tc, 0, findalliance(1));
|
||||
CuAssertPtrEquals(tc, 0, alliances);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_alliance_join(CuTest *tc) {
|
||||
alliance_fixture fix;
|
||||
alliance * al;
|
||||
|
||||
setup_alliance(&fix);
|
||||
CuAssertPtrEquals(tc, 0, fix.f1->alliance);
|
||||
CuAssertPtrEquals(tc, 0, fix.f2->alliance);
|
||||
al = makealliance(1, "Hodor");
|
||||
setalliance(fix.f1, al);
|
||||
CuAssertPtrEquals(tc, fix.f1, alliance_get_leader(al));
|
||||
setalliance(fix.f2, al);
|
||||
CuAssertPtrEquals(tc, fix.f1, alliance_get_leader(al));
|
||||
CuAssertTrue(tc, is_allied(fix.f1, fix.f2));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_alliance_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_alliance_make);
|
||||
SUITE_ADD_TEST(suite, test_alliance_join);
|
||||
return suite;
|
||||
}
|
||||
|
|
@ -2290,11 +2290,7 @@ void free_gamedata(void)
|
|||
defaults[i] = 0;
|
||||
}
|
||||
}
|
||||
while (alliances) {
|
||||
alliance *al = alliances;
|
||||
alliances = al->next;
|
||||
free_alliance(al);
|
||||
}
|
||||
free_alliances();
|
||||
while (factions) {
|
||||
faction *f = factions;
|
||||
factions = f->next;
|
||||
|
|
|
@ -38,6 +38,7 @@ int RunAllTests(void)
|
|||
ADD_TESTS(suite, unicode);
|
||||
ADD_TESTS(suite, strings);
|
||||
/* kernel */
|
||||
ADD_TESTS(suite, alliance);
|
||||
ADD_TESTS(suite, unit);
|
||||
ADD_TESTS(suite, faction);
|
||||
ADD_TESTS(suite, group);
|
||||
|
|
Loading…
Reference in a new issue