enhance foolpotion test.

This commit is contained in:
Enno Rehling 2018-01-17 17:37:37 +01:00
parent 66ffca3ac4
commit e0a5ba60b4
3 changed files with 27 additions and 10 deletions

View File

@ -133,23 +133,26 @@ function test_foolpotion()
local f = faction.create("human", "noreply@eressea.de", "de")
local u = unit.create(f, r, 1)
turn_begin()
u:add_item("p7", 1)
u:add_item('p7', 2)
u:clear_orders()
u:add_order("BENUTZEN 1 Dumpfbackenbrot 4242")
turn_process()
assert_equal(1, u:get_item("p7"))
assert_equal(2, u:get_item('p7'))
assert_equal(1, f:count_msg_type('feedback_unit_not_found'))
local u2 = unit.create(f, r, 1)
u:clear_orders()
u:add_order("BENUTZEN 1 Dumpfbackenbrot " .. itoa36(u2.id))
u:add_order("BENUTZEN 2 Dumpfbackenbrot " .. itoa36(u2.id))
turn_process()
assert_equal(1, u:get_item("p7"))
assert_equal(2, u:get_item('p7'))
assert_equal(1, f:count_msg_type('error64'))
u:set_skill("stealth", 1);
u:set_skill("stealth", 1)
u2:set_skill('crossbow', 1)
turn_process()
assert_equal(0, u:get_item("p7"))
assert_equal(0, u:get_item('p7'))
assert_equal(0, u2:effect('p7'))
assert_equal(0, u2:get_skill('crossbow'))
assert_equal(1, f:count_msg_type('givedumb'))
turn_end()
end

View File

@ -499,15 +499,15 @@ static void test_battle_skilldiff_building(CuTest *tc)
test_teardown();
}
static void assert_skill(CuTest *tc, char *msg, unit *u, skill_t sk, int level, int week, int weekmax)
static void assert_skill(CuTest *tc, const char *msg, unit *u, skill_t sk, int level, int week, int weekmax)
{
skill *sv = unit_skill(u, sk);
char buf[256];
if (sv) {
sprintf(buf, "%s level %d != %d", msg, sv->level, level);
CuAssertIntEquals_Msg(tc, (const char *)&buf, level, sv->level);
CuAssertIntEquals_Msg(tc, buf, level, sv->level);
sprintf(buf, "%s week %d !<= %d !<= %d", msg, week, sv->weeks, weekmax);
CuAssert(tc, (const char *)&buf, sv->weeks >= week && sv->weeks <= weekmax);
CuAssert(tc, buf, sv->weeks >= week && sv->weeks <= weekmax);
}
else {
CuAssertIntEquals_Msg(tc, msg, level, 0);
@ -518,7 +518,7 @@ static void assert_skill(CuTest *tc, char *msg, unit *u, skill_t sk, int level,
static void test_drain_exp(CuTest *tc)
{
unit *u;
char *msg;
const char *msg;
int i;
double rand;

View File

@ -505,6 +505,19 @@ static int tolua_unit_addnotice(lua_State * L)
return 0;
}
static int bind_unit_effect(lua_State * L)
{
unit *u = (unit *)tolua_tousertype(L, 1, NULL);
const char *str = tolua_tostring(L, 2, NULL);
const item_type *itype = it_find(str);
if (itype) {
int effect = get_effect(u, itype);
lua_pushinteger(L, effect);
return 1;
}
return 0;
}
static void unit_castspell(unit * u, const char *name, int level)
{
spell *sp = find_spell(name);
@ -1030,6 +1043,7 @@ void tolua_unit_open(lua_State * L)
tolua_function(L, TOLUA_CAST "add_spell", tolua_unit_addspell);
tolua_variable(L, TOLUA_CAST "spells", tolua_unit_get_spells, 0);
tolua_function(L, TOLUA_CAST "cast_spell", tolua_unit_castspell);
tolua_function(L, TOLUA_CAST "effect", bind_unit_effect);
tolua_variable(L, TOLUA_CAST "magic", tolua_unit_get_magic,
tolua_unit_set_magic);