test that empty factions are removed, but not monsters.

This commit is contained in:
Enno Rehling 2014-10-16 08:13:56 +02:00
parent 440aca34ea
commit ac65d83ba2
2 changed files with 51 additions and 5 deletions

View file

@ -1,12 +1,55 @@
#include <platform.h>
#include <kernel/faction.h>
#include <kernel/types.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/config.h>
#include <util/language.h>
#include "faction.h"
#include <CuTest.h>
#include <tests.h>
#include <assert.h>
#include <stdio.h>
static void test_remove_empty_factions(CuTest *tc) {
faction *f, *fm;
int fno;
test_cleanup();
fm = get_or_create_monsters();
assert(fm);
f = test_create_faction(0);
fno = f->no;
remove_empty_factions();
CuAssertPtrEquals(tc, 0, findfaction(fno));
CuAssertPtrEquals(tc, fm, get_monsters());
test_cleanup();
}
static void test_remove_dead_factions(CuTest *tc) {
faction *f, *fm;
region *r;
test_cleanup();
r = test_create_region(0, 0, 0);
fm = get_or_create_monsters();
f = test_create_faction(0);
assert(fm && r && f);
test_create_unit(f, r);
test_create_unit(fm, r);
remove_empty_factions();
CuAssertPtrEquals(tc, f, findfaction(f->no));
CuAssertPtrNotNull(tc, get_monsters());
fm->alive = 0;
f->alive = 0;
remove_empty_factions();
CuAssertPtrEquals(tc, 0, findfaction(f->no));
CuAssertPtrEquals(tc, fm, get_monsters());
test_cleanup();
}
static void test_addfaction(CuTest *tc) {
faction *f = 0;
const struct race *rc = rc_get_or_create("human");
@ -51,6 +94,8 @@ CuSuite *get_faction_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_addfaction);
SUITE_ADD_TEST(suite, test_remove_empty_factions);
SUITE_ADD_TEST(suite, test_remove_dead_factions);
SUITE_ADD_TEST(suite, test_get_monsters);
return suite;
}

View file

@ -34,25 +34,26 @@ struct race *test_create_race(const char *name)
struct region *test_create_region(int x, int y, const terrain_type *terrain)
{
region *r = new_region(x, y, NULL, 0);
terraform_region(r, terrain);
terraform_region(r, terrain ? terrain : get_or_create_terrain("plain"));
rsettrees(r, 0, 0);
rsettrees(r, 1, 0);
rsettrees(r, 2, 0);
rsethorses(r, 0);
rsetpeasants(r, terrain->size);
rsetpeasants(r, r->terrain->size);
return r;
}
struct faction *test_create_faction(const struct race *rc)
{
faction *f = addfaction("nobody@eressea.de", NULL, rc?rc:rc_find("human"), default_locale, 0);
faction *f = addfaction("nobody@eressea.de", NULL, rc?rc:rc_get_or_create("human"), default_locale, 0);
return f;
}
struct unit *test_create_unit(struct faction *f, struct region *r)
{
const struct race * rc = f ? f->race : 0;
assert(f || !r);
return create_unit(r, f, 1, f ? f->race : rc_find("human"), 0, 0, 0);
return create_unit(r, f, 1, rc ? rc : rc_get_or_create("human"), 0, 0, 0);
}
void test_cleanup(void)