re-enable intermittent test, supplement unit test.

Untote reservieren nichts von anderen Einheiten.
This commit is contained in:
Enno Rehling 2018-12-09 14:41:14 +01:00
parent c867120772
commit 1ca1c7cfea
3 changed files with 32 additions and 8 deletions

View File

@ -19,7 +19,7 @@ function test_undead_reserve_self()
assert_equal(1, u1:get_item("log")) assert_equal(1, u1:get_item("log"))
end end
function skip_undead_reserve_other() function test_undead_reserve_other()
local r1 = region.create(0, 0, "plain") local r1 = region.create(0, 0, "plain")
local f1 = faction.create("human") local f1 = faction.create("human")
local u1 = unit.create(f1, r1, 1) local u1 = unit.create(f1, r1, 1)
@ -28,9 +28,10 @@ function skip_undead_reserve_other()
u1.race = "undead" u1.race = "undead"
u1:clear_orders() u1:clear_orders()
u1:add_order("RESERVIERE 1 Holz") u1:add_order("RESERVIERE 1 Holz")
u1.name = 'Xolgrim'
process_orders() 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(0, u1:get_item("log"))
assert_equal(2, u2:get_item("log")) assert_equal(2, u2:get_item("log"))

View File

@ -6,6 +6,7 @@
#include "unit.h" #include "unit.h"
#include "item.h" #include "item.h"
#include "faction.h" #include "faction.h"
#include "race.h"
#include "region.h" #include "region.h"
#include "skill.h" #include "skill.h"
@ -42,6 +43,30 @@ void test_reservation(CuTest *tc) {
test_teardown(); 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) { void test_pool(CuTest *tc) {
unit *u1, *u2, *u3; unit *u1, *u2, *u3;
faction *f; faction *f;
@ -49,11 +74,11 @@ void test_pool(CuTest *tc) {
struct resource_type *rtype; struct resource_type *rtype;
test_setup(); test_setup();
test_create_world();
rtype = rt_get_or_create("money"); rtype = rt_get_or_create("money");
rtype->flags |= RTF_POOLED;
it_get_or_create(rtype); it_get_or_create(rtype);
f = test_create_faction(NULL); f = test_create_faction(NULL);
r = findregion(0, 0); r = test_create_plain(0, 0);
assert(r && f && rtype && rtype->itype); assert(r && f && rtype && rtype->itype);
u1 = test_create_unit(f, r); u1 = test_create_unit(f, r);
u2 = test_create_unit(f, r); u2 = test_create_unit(f, r);
@ -188,6 +213,7 @@ CuSuite *get_pool_suite(void)
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_reservation); SUITE_ADD_TEST(suite, test_reservation);
SUITE_ADD_TEST(suite, test_pool); 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_bug_2042);
SUITE_ADD_TEST(suite, test_pool_use); SUITE_ADD_TEST(suite, test_pool_use);
SUITE_ADD_TEST(suite, test_change_resource); SUITE_ADD_TEST(suite, test_change_resource);

View File

@ -3434,10 +3434,7 @@ static int reserve_i(unit * u, struct order *ord, int flags)
} }
int reserve_cmd(unit * u, struct order *ord) { int reserve_cmd(unit * u, struct order *ord) {
if ((u_race(u)->ec_flags & ECF_GETITEM)) { return reserve_i(u, ord, GET_DEFAULT);
return reserve_i(u, ord, GET_DEFAULT);
}
return 0;
} }
int reserve_self(unit * u, struct order *ord) { int reserve_self(unit * u, struct order *ord) {