forked from github/server
test special treatment for spells in remove_empty_units.
This commit is contained in:
parent
559f1f905a
commit
440aca34ea
|
@ -232,9 +232,8 @@ int gift_items(unit * u, int flags)
|
||||||
int rule = rule_give();
|
int rule = rule_give();
|
||||||
|
|
||||||
assert(u->region);
|
assert(u->region);
|
||||||
assert(u->faction);
|
|
||||||
|
|
||||||
if ((u->faction->flags & FFL_QUIT) == 0 || (rule & GIVE_ONDEATH) == 0) {
|
if ((rule & GIVE_ONDEATH) == 0 || !u->faction || (u->faction->flags & FFL_QUIT) == 0) {
|
||||||
if ((rule & GIVE_ALLITEMS) == 0 && (flags & GIFT_FRIENDS))
|
if ((rule & GIVE_ALLITEMS) == 0 && (flags & GIFT_FRIENDS))
|
||||||
flags -= GIFT_FRIENDS;
|
flags -= GIFT_FRIENDS;
|
||||||
if ((rule & GIVE_PEASANTS) == 0 && (flags & GIFT_PEASANTS))
|
if ((rule & GIVE_PEASANTS) == 0 && (flags & GIFT_PEASANTS))
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
|
#include "faction.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
#include "race.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
|
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
|
@ -47,6 +49,58 @@ static void test_remove_empty_units_in_region(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_remove_units_without_faction(CuTest *tc) {
|
||||||
|
unit *u;
|
||||||
|
int uid;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
|
||||||
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
||||||
|
uid = u->no;
|
||||||
|
u_setfaction(u, 0);
|
||||||
|
remove_empty_units_in_region(u->region);
|
||||||
|
CuAssertPtrEquals(tc, 0, findunit(uid));
|
||||||
|
CuAssertIntEquals(tc, 0, u->number);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_remove_units_with_dead_faction(CuTest *tc) {
|
||||||
|
unit *u;
|
||||||
|
int uid;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
|
||||||
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
||||||
|
uid = u->no;
|
||||||
|
u->faction->alive = false;
|
||||||
|
remove_empty_units_in_region(u->region);
|
||||||
|
CuAssertPtrEquals(tc, 0, findunit(uid));
|
||||||
|
CuAssertIntEquals(tc, 0, u->number);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_remove_units_ignores_spells(CuTest *tc) {
|
||||||
|
unit *u;
|
||||||
|
int uid;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
|
||||||
|
u = create_unit(findregion(0, 0), test_create_faction(test_create_race("human")), 1, get_race(RC_SPELL), 0, 0, 0);
|
||||||
|
uid = u->no;
|
||||||
|
u->number = 0;
|
||||||
|
u->age = 1;
|
||||||
|
remove_empty_units_in_region(u->region);
|
||||||
|
CuAssertPtrNotNull(tc, findunit(uid));
|
||||||
|
CuAssertPtrNotNull(tc, u->region);
|
||||||
|
u->age = 0;
|
||||||
|
remove_empty_units_in_region(u->region);
|
||||||
|
CuAssertPtrEquals(tc, 0, findunit(uid));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_scale_number(CuTest *tc) {
|
static void test_scale_number(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
const struct potion_type *ptype;
|
const struct potion_type *ptype;
|
||||||
|
@ -74,6 +128,9 @@ CuSuite *get_unit_suite(void)
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_scale_number);
|
SUITE_ADD_TEST(suite, test_scale_number);
|
||||||
SUITE_ADD_TEST(suite, test_remove_empty_units);
|
SUITE_ADD_TEST(suite, test_remove_empty_units);
|
||||||
|
SUITE_ADD_TEST(suite, test_remove_units_ignores_spells);
|
||||||
|
SUITE_ADD_TEST(suite, test_remove_units_without_faction);
|
||||||
|
SUITE_ADD_TEST(suite, test_remove_units_with_dead_faction);
|
||||||
SUITE_ADD_TEST(suite, test_remove_empty_units_in_region);
|
SUITE_ADD_TEST(suite, test_remove_empty_units_in_region);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,8 @@ struct faction *test_create_faction(const struct race *rc)
|
||||||
|
|
||||||
struct unit *test_create_unit(struct faction *f, struct region *r)
|
struct unit *test_create_unit(struct faction *f, struct region *r)
|
||||||
{
|
{
|
||||||
unit *u = create_unit(r, f, 1, f?f->race:rc_find("human"), 0, 0, 0);
|
assert(f || !r);
|
||||||
return u;
|
return create_unit(r, f, 1, f ? f->race : rc_find("human"), 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_cleanup(void)
|
void test_cleanup(void)
|
||||||
|
|
Loading…
Reference in New Issue