From 3e2c630c3fc12ba1de96400e7c357426b61c9341 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Sep 2016 19:39:35 +0200 Subject: [PATCH] testing that remove_unit takes unit out of the world properly. there is more to it than this, but I'd be happy with the dfindhash check for now. --- src/kernel/unit.test.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 1af197e15..df8496dce 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -401,6 +401,34 @@ static void test_unit_description(CuTest *tc) { test_cleanup(); } +static void test_remove_unit(CuTest *tc) { + region *r; + unit *u; + faction *f; + int uno; + const resource_type *rtype; + + test_setup(); + init_resources(); + rtype = get_resourcetype(R_SILVER); + r = test_create_region(0, 0, 0); + f = test_create_faction(0); + u = test_create_unit(f, r); + uno = u->no; + region_setresource(r, rtype, 0); + i_change(&u->items, rtype->itype, 100); + remove_unit(&r->units, u); + CuAssertIntEquals(tc, 100, region_getresource(r, rtype)); + CuAssertIntEquals(tc, 0, u->number); + CuAssertPtrEquals(tc, 0, u->region); + CuAssertPtrEquals(tc, 0, u->items); + CuAssertPtrEquals(tc, 0, u->faction); + CuAssertPtrEquals(tc, 0, r->units); + CuAssertPtrEquals(tc, 0, findunit(uno)); + CuAssertPtrEquals(tc, f, dfindhash(uno)); + test_cleanup(); +} + CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -409,6 +437,7 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_unit_name); SUITE_ADD_TEST(suite, test_unit_name_from_race); SUITE_ADD_TEST(suite, test_update_monster_name); + SUITE_ADD_TEST(suite, test_remove_unit); 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);