From c01e9b24ad93fcc017ee46578096bccc3c7f2c85 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 29 Apr 2018 15:09:07 +0200 Subject: [PATCH] unit tests for racial weapon permissions. --- src/battle.test.c | 49 ++++++++++++++++++++++++++++++++++++++++++ src/kernel/race.test.c | 13 +++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/battle.test.c b/src/battle.test.c index 7d968c091..865fc08c2 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -68,6 +68,54 @@ static void test_make_fighter(CuTest * tc) test_teardown(); } +static void test_select_weapon(CuTest *tc) { + item_type *itype; + weapon_type *wtype; + unit *au; + fighter *af; + battle *b; + race * rc; + + test_setup(); + au = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); + itype = test_create_itemtype("halberd"); + wtype = new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE); + i_change(&au->items, itype, 1); + rc = test_create_race("smurf"); + CuAssertIntEquals(tc, 0, rc->mask_item & au->_race->mask_item); + + b = make_battle(au->region); + af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false); + CuAssertPtrNotNull(tc, af->weapons); + CuAssertIntEquals(tc, 1, af->weapons[0].count); + free_battle(b); + + itype->mask_deny = rc_mask(au->_race); + b = make_battle(au->region); + af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false); + CuAssertPtrNotNull(tc, af->weapons); + CuAssertIntEquals(tc, 0, af->weapons[0].count); + free_battle(b); + + itype->mask_deny = 0; + itype->mask_allow = rc_mask(rc); + b = make_battle(au->region); + af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false); + CuAssertPtrNotNull(tc, af->weapons); + CuAssertIntEquals(tc, 0, af->weapons[0].count); + free_battle(b); + + itype->mask_deny = 0; + itype->mask_allow = rc_mask(au->_race); + b = make_battle(au->region); + af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false); + CuAssertPtrNotNull(tc, af->weapons); + CuAssertIntEquals(tc, 1, af->weapons[0].count); + free_battle(b); + + test_teardown(); +} + static building_type * setup_castle(void) { building_type * btype; construction *cons; @@ -583,6 +631,7 @@ CuSuite *get_battle_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_make_fighter); + SUITE_ADD_TEST(suite, test_select_weapon); SUITE_ADD_TEST(suite, test_battle_skilldiff); SUITE_ADD_TEST(suite, test_battle_skilldiff_building); SUITE_ADD_TEST(suite, test_defenders_get_building_bonus); diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index d695969b7..dcbe26e0e 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -26,6 +26,18 @@ static void test_rc_name(CuTest *tc) { test_teardown(); } +static void test_rc_item_mask(CuTest *tc) { + struct race *rc; + test_setup(); + rc = rc_get_or_create("hooman"); + CuAssertIntEquals(tc, 1, rc->mask_item); + rc = rc_get_or_create("aelf"); + CuAssertIntEquals(tc, 2, rc->mask_item); + rc = rc_get_or_create("dorf"); + CuAssertIntEquals(tc, 4, rc->mask_item); + test_teardown(); +} + static void test_rc_defaults(CuTest *tc) { struct race *rc; test_setup(); @@ -193,6 +205,7 @@ CuSuite *get_race_suite(void) SUITE_ADD_TEST(suite, test_old_race); SUITE_ADD_TEST(suite, test_rc_name); SUITE_ADD_TEST(suite, test_rc_defaults); + SUITE_ADD_TEST(suite, test_rc_item_mask); SUITE_ADD_TEST(suite, test_rc_find); SUITE_ADD_TEST(suite, test_rc_mask); SUITE_ADD_TEST(suite, test_rc_set_param);