fix compilation, add tests for upkeep

This commit is contained in:
Enno Rehling 2021-05-20 22:04:50 +02:00
parent bed6cdff58
commit 0fcc1b8d29
3 changed files with 41 additions and 1 deletions

View File

@ -681,6 +681,24 @@ static void test_get_modifier_cursed(CuTest *tc) {
test_teardown(); test_teardown();
} }
static void test_maintenance_cost(CuTest *tc) {
unit *u;
race *rc;
test_setup();
CuAssertIntEquals(tc, 10, maintenance_cost(NULL));
u = test_create_unit(test_create_faction(), test_create_plain(0, 0));
CuAssertIntEquals(tc, 10, maintenance_cost(u));
u->number = 4;
CuAssertIntEquals(tc, 40, maintenance_cost(u));
rc = test_create_race("smurf");
rc->maintenance = 15;
u_setrace(u, rc);
CuAssertIntEquals(tc, 60, maintenance_cost(u));
u->faction->flags |= FFL_PAUSED;
CuAssertIntEquals(tc, 0, maintenance_cost(u));
test_teardown();
}
static void test_gift_items(CuTest *tc) { static void test_gift_items(CuTest *tc) {
unit *u, *u1, *u2; unit *u, *u1, *u2;
region *r; region *r;
@ -770,5 +788,6 @@ CuSuite *get_unit_suite(void)
SUITE_ADD_TEST(suite, test_get_modifier); SUITE_ADD_TEST(suite, test_get_modifier);
SUITE_ADD_TEST(suite, test_get_modifier_cursed); SUITE_ADD_TEST(suite, test_get_modifier_cursed);
SUITE_ADD_TEST(suite, test_gift_items); SUITE_ADD_TEST(suite, test_gift_items);
SUITE_ADD_TEST(suite, test_maintenance_cost);
return suite; return suite;
} }

View File

@ -66,7 +66,7 @@ static void handle_faction(void *userData, int no, const char *password) {
if (checkpasswd(f, password)) { if (checkpasswd(f, password)) {
state->f = f; state->f = f;
f->lastorders = turn; f->lastorders = turn;
freset(f, FFL_PAUSED); f->flags &= ~(FFL_PAUSED);
} }
else { else {
log_debug("invalid password for faction %s", itoa36(no)); log_debug("invalid password for faction %s", itoa36(no));

View File

@ -4,6 +4,7 @@
#include <kernel/ally.h> #include <kernel/ally.h>
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/race.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/item.h> #include <kernel/item.h>
@ -137,6 +138,25 @@ void test_upkeep_from_friend(CuTest * tc)
test_teardown(); test_teardown();
} }
void test_lifestyle(CuTest *tc)
{
unit *u;
race *rc;
test_setup();
u = test_create_unit(test_create_faction(), test_create_plain(0, 0));
CuAssertIntEquals(tc, 10, lifestyle(u));
u->number = 2;
CuAssertIntEquals(tc, 20, lifestyle(u));
rc = test_create_race("smurf");
rc->maintenance = 15;
u_setrace(u, rc);
CuAssertIntEquals(tc, 30, lifestyle(u));
u->faction->flags |= FFL_PAUSED;
CuAssertIntEquals(tc, 0, lifestyle(u));
test_teardown();
}
void test_upkeep_free(CuTest * tc) void test_upkeep_free(CuTest * tc)
{ {
region *r; region *r;
@ -168,5 +188,6 @@ CuSuite *get_upkeep_suite(void)
SUITE_ADD_TEST(suite, test_upkeep_from_friend); SUITE_ADD_TEST(suite, test_upkeep_from_friend);
SUITE_ADD_TEST(suite, test_upkeep_hunger_damage); SUITE_ADD_TEST(suite, test_upkeep_hunger_damage);
SUITE_ADD_TEST(suite, test_upkeep_free); SUITE_ADD_TEST(suite, test_upkeep_free);
SUITE_ADD_TEST(suite, test_lifestyle);
return suite; return suite;
} }