From 1ca1c7cfeaa2f312308aebdab654b57c5b199777 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 9 Dec 2018 14:41:14 +0100 Subject: [PATCH] re-enable intermittent test, supplement unit test. Untote reservieren nichts von anderen Einheiten. --- scripts/tests/e2/undead.lua | 5 +++-- src/kernel/pool.test.c | 30 ++++++++++++++++++++++++++++-- src/laws.c | 5 +---- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/scripts/tests/e2/undead.lua b/scripts/tests/e2/undead.lua index a27987756..e1b153f25 100644 --- a/scripts/tests/e2/undead.lua +++ b/scripts/tests/e2/undead.lua @@ -19,7 +19,7 @@ function test_undead_reserve_self() assert_equal(1, u1:get_item("log")) end -function skip_undead_reserve_other() +function test_undead_reserve_other() local r1 = region.create(0, 0, "plain") local f1 = faction.create("human") local u1 = unit.create(f1, r1, 1) @@ -28,9 +28,10 @@ function skip_undead_reserve_other() u1.race = "undead" u1:clear_orders() u1:add_order("RESERVIERE 1 Holz") + u1.name = 'Xolgrim' process_orders() - -- Intermittent Failure (clang): expected 0 but was 2 + -- Intermittent Failure: expected 0 but was 2 assert_equal(0, u1:get_item("log")) assert_equal(2, u2:get_item("log")) diff --git a/src/kernel/pool.test.c b/src/kernel/pool.test.c index 10c127f81..d5d190c26 100644 --- a/src/kernel/pool.test.c +++ b/src/kernel/pool.test.c @@ -6,6 +6,7 @@ #include "unit.h" #include "item.h" #include "faction.h" +#include "race.h" #include "region.h" #include "skill.h" @@ -42,6 +43,30 @@ void test_reservation(CuTest *tc) { test_teardown(); } +void test_pool_get_item(CuTest *tc) { + unit *u1, *u2; + faction *f; + region *r; + race *rc; + struct resource_type *rtype; + + test_setup(); + rtype = rt_get_or_create("money"); + rtype->flags |= RTF_POOLED; + it_get_or_create(rtype); + f = test_create_faction(NULL); + r = test_create_plain(0, 0); + u1 = test_create_unit(f, r); + u_setrace(u1, rc = test_create_race("undead")); + rc->ec_flags &= ~ECF_GETITEM; + u2 = test_create_unit(f, r); + i_change(&u2->items, rtype->itype, 2); + CuAssertIntEquals(tc, 0, get_pooled(u1, rtype, GET_DEFAULT, 1)); + CuAssertIntEquals(tc, 0, i_get(u1->items, rtype->itype)); + CuAssertIntEquals(tc, 2, i_get(u2->items, rtype->itype)); + test_teardown(); +} + void test_pool(CuTest *tc) { unit *u1, *u2, *u3; faction *f; @@ -49,11 +74,11 @@ void test_pool(CuTest *tc) { struct resource_type *rtype; test_setup(); - test_create_world(); rtype = rt_get_or_create("money"); + rtype->flags |= RTF_POOLED; it_get_or_create(rtype); f = test_create_faction(NULL); - r = findregion(0, 0); + r = test_create_plain(0, 0); assert(r && f && rtype && rtype->itype); u1 = test_create_unit(f, r); u2 = test_create_unit(f, r); @@ -188,6 +213,7 @@ CuSuite *get_pool_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_reservation); SUITE_ADD_TEST(suite, test_pool); + SUITE_ADD_TEST(suite, test_pool_get_item); SUITE_ADD_TEST(suite, test_pool_bug_2042); SUITE_ADD_TEST(suite, test_pool_use); SUITE_ADD_TEST(suite, test_change_resource); diff --git a/src/laws.c b/src/laws.c index b3c3eca92..9de897cb0 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3434,10 +3434,7 @@ static int reserve_i(unit * u, struct order *ord, int flags) } int reserve_cmd(unit * u, struct order *ord) { - if ((u_race(u)->ec_flags & ECF_GETITEM)) { - return reserve_i(u, ord, GET_DEFAULT); - } - return 0; + return reserve_i(u, ord, GET_DEFAULT); } int reserve_self(unit * u, struct order *ord) {