forked from github/server
add tests for snowglobe error messages
This commit is contained in:
parent
4952f212b8
commit
25966b3d7f
3 changed files with 64 additions and 14 deletions
|
@ -19,6 +19,22 @@ function test_snowglobe_fail()
|
|||
unit.create(f, r2, 1) -- unit in target region => fail
|
||||
process_orders()
|
||||
assert_equal('ocean', r2.terrain)
|
||||
assert_equal(1, u:get_item('snowglobe'))
|
||||
assert_equal(1, f:count_msg_type('target_region_not_empty'))
|
||||
end
|
||||
|
||||
function test_snowglobe_missing_direction()
|
||||
local r1 = region.create(0, 0, "glacier")
|
||||
local r2 = region.create(1, 0, "ocean")
|
||||
local f = faction.create("snowglobe1@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
u:add_item("snowglobe", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Schneekugel")
|
||||
process_orders()
|
||||
assert_equal('ocean', r2.terrain)
|
||||
assert_equal(1, u:get_item('snowglobe'))
|
||||
assert_equal(1, f:count_msg_type('missing_direction'))
|
||||
end
|
||||
|
||||
function test_snowglobe()
|
||||
|
@ -27,6 +43,7 @@ function test_snowglobe()
|
|||
local f = faction.create("snowglobe2@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
local have = 6
|
||||
local fail = 0
|
||||
u:add_item("snowglobe", have)
|
||||
local xform = { ocean = "glacier", glacier = "glacier", firewall = "volcano", volcano = "mountain", desert = "plain", plain = "plain" }
|
||||
u:clear_orders()
|
||||
|
@ -35,7 +52,12 @@ function test_snowglobe()
|
|||
r2.terrain = k
|
||||
process_orders()
|
||||
assert_equal(v, r2.terrain)
|
||||
if k~=v then have=have - 1 end
|
||||
if k~=v then
|
||||
have=have - 1
|
||||
else
|
||||
fail = fail + 1
|
||||
assert_equal(fail, f:count_msg_type('target_region_invalid'))
|
||||
end
|
||||
assert_equal(have, u:get_item("snowglobe"))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -224,6 +224,23 @@ static int tolua_faction_addnotice(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_count_msg_type(lua_State *L) {
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *str = tolua_tostring(L, 2, 0);
|
||||
int n = 0;
|
||||
if (self->msgs) {
|
||||
mlist * ml = self->msgs->begin;
|
||||
while (ml) {
|
||||
if (strcmp(str, ml->msg->type->name) == 0) {
|
||||
++n;
|
||||
}
|
||||
ml = ml->next;
|
||||
}
|
||||
}
|
||||
lua_pushinteger(L, n);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_objects(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
|
@ -528,12 +545,12 @@ void tolua_faction_open(lua_State * L)
|
|||
|
||||
tolua_variable(L, TOLUA_CAST "id", tolua_faction_get_id,
|
||||
tolua_faction_set_id);
|
||||
tolua_variable(L, TOLUA_CAST "uid", &tolua_faction_get_uid,
|
||||
&tolua_faction_set_uid);
|
||||
tolua_variable(L, TOLUA_CAST "name", &tolua_faction_get_name,
|
||||
&tolua_faction_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", &tolua_faction_get_info,
|
||||
&tolua_faction_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "uid", tolua_faction_get_uid,
|
||||
tolua_faction_set_uid);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_faction_get_name,
|
||||
tolua_faction_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", tolua_faction_get_info,
|
||||
tolua_faction_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_faction_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes,
|
||||
|
@ -549,7 +566,7 @@ void tolua_faction_open(lua_State * L)
|
|||
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance,
|
||||
tolua_faction_set_alliance);
|
||||
tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "magic", &tolua_faction_get_magic,
|
||||
tolua_variable(L, TOLUA_CAST "magic", tolua_faction_get_magic,
|
||||
tolua_faction_set_magic);
|
||||
tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age,
|
||||
tolua_faction_set_age);
|
||||
|
@ -559,11 +576,11 @@ void tolua_faction_open(lua_State * L)
|
|||
tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn,
|
||||
tolua_faction_set_lastturn);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "set_policy", &tolua_faction_set_policy);
|
||||
tolua_function(L, TOLUA_CAST "get_policy", &tolua_faction_get_policy);
|
||||
tolua_function(L, TOLUA_CAST "get_origin", &tolua_faction_get_origin);
|
||||
tolua_function(L, TOLUA_CAST "set_origin", &tolua_faction_set_origin);
|
||||
tolua_function(L, TOLUA_CAST "normalize", &tolua_faction_normalize);
|
||||
tolua_function(L, TOLUA_CAST "set_policy", tolua_faction_set_policy);
|
||||
tolua_function(L, TOLUA_CAST "get_policy", tolua_faction_get_policy);
|
||||
tolua_function(L, TOLUA_CAST "get_origin", tolua_faction_get_origin);
|
||||
tolua_function(L, TOLUA_CAST "set_origin", tolua_faction_set_origin);
|
||||
tolua_function(L, TOLUA_CAST "normalize", tolua_faction_normalize);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "add_item", tolua_faction_add_item);
|
||||
tolua_variable(L, TOLUA_CAST "items", tolua_faction_get_items, NULL);
|
||||
|
@ -572,7 +589,10 @@ void tolua_faction_open(lua_State * L)
|
|||
tolua_function(L, TOLUA_CAST "create", tolua_faction_create);
|
||||
tolua_function(L, TOLUA_CAST "get", tolua_faction_get);
|
||||
tolua_function(L, TOLUA_CAST "destroy", tolua_faction_destroy);
|
||||
tolua_function(L, TOLUA_CAST "add_notice", &tolua_faction_addnotice);
|
||||
tolua_function(L, TOLUA_CAST "add_notice", tolua_faction_addnotice);
|
||||
|
||||
/* tech debt hack, siehe https://paper.dropbox.com/doc/Weihnachten-2015-5tOx5r1xsgGDBpb0gILrv#:h=Probleme-mit-Tests-(Nachtrag-0 */
|
||||
tolua_function(L, TOLUA_CAST "count_msg_type", tolua_faction_count_msg_type);
|
||||
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_faction_get_objects,
|
||||
NULL);
|
||||
|
|
|
@ -321,6 +321,13 @@ static int tolua_msg_send_faction(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_msg_get_type(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, lmsg->msg->type->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_msg_render(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
|
@ -351,6 +358,7 @@ void tolua_message_open(lua_State * L)
|
|||
tolua_beginmodule(L, TOLUA_CAST "message");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "render", tolua_msg_render);
|
||||
tolua_variable(L, TOLUA_CAST "type", tolua_msg_get_type, 0);
|
||||
tolua_function(L, TOLUA_CAST "set", tolua_msg_set);
|
||||
tolua_function(L, TOLUA_CAST "set_unit", tolua_msg_set_unit);
|
||||
tolua_function(L, TOLUA_CAST "set_order", tolua_msg_set_order);
|
||||
|
|
Loading…
Reference in a new issue