additional tests for spells.

also some support functionality for lua tests.
This commit is contained in:
Enno Rehling 2017-05-01 19:09:00 +02:00
parent c281a1e5c9
commit 8e9866f0ce
5 changed files with 112 additions and 1 deletions

View File

@ -20,3 +20,4 @@ require 'tests.magicbag'
require 'tests.process' require 'tests.process'
require 'tests.xmas' require 'tests.xmas'
require 'tests.production' require 'tests.production'
require 'tests.spells'

View File

@ -5,11 +5,12 @@ require 'tests.e3.rules'
require 'tests.e3.parser' require 'tests.e3.parser'
require 'tests.e3.morale' require 'tests.e3.morale'
require 'tests.e3.items' require 'tests.e3.items'
require 'tests.e3.production'
require 'tests.spells'
require 'tests.economy' require 'tests.economy'
require 'tests.orders' require 'tests.orders'
require 'tests.common' require 'tests.common'
require 'tests.items' require 'tests.items'
require 'tests.magicbag' require 'tests.magicbag'
require 'tests.process' require 'tests.process'
require 'tests.e3.production'
require 'tests.production' require 'tests.production'

83
scripts/tests/spells.lua Normal file
View File

@ -0,0 +1,83 @@
require 'lunit'
module("tests.spells", package.seeall, lunit.testcase)
function setup()
eressea.free_game()
eressea.settings.set("nmr.removenewbie", "0")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("NewbieImmunity", "0")
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.encounters", "0")
eressea.settings.set("magic.regeneration.enable", "0")
end
function test_create_bogus()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u.race = "elf"
u:set_skill("magic", 10)
u.magic = 'gwyrrd'
u:clear_orders()
u:add_order("ZAUBERE 'Erschaffe Katastrophe'")
process_orders()
assert_equal(f.messages[3], 'error173') -- HACKity HACK
end
function test_create_roi()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u.race = "elf"
u:set_skill("magic", 10)
u.magic = 'gwyrrd'
u.aura = 100
u:add_item("money", 3000)
u:add_spell("create_roi")
u:clear_orders()
u:add_order("ZAUBERE 'Erschaffe einen Ring der Unsichtbarkeit'")
local amax = u.aura_max
process_orders()
assert_equal(1, u:get_item("roi"))
assert_equal(50, u.aura)
assert_equal(amax - 1, u.aura_max)
end
function test_create_aots()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u.race = "elf"
u:set_skill("magic", 10)
u.magic = 'gwyrrd'
u.aura = 100
u:add_item("money", 3000)
u:add_spell("create_aots")
u:clear_orders()
u:add_order("ZAUBERE 'Erschaffe ein Amulett des wahren Sehens'")
local amax = u.aura_max
process_orders()
assert_equal(1, u:get_item("aots"))
assert_equal(50, u.aura)
assert_equal(amax - 1, u.aura_max)
end
function test_create_dreameye()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u.race = "elf"
u:set_skill("magic", 10)
u.magic = 'gwyrrd'
u.aura = 100
u:add_item("dragonhead", 1)
u:add_spell("create_dreameye")
u:clear_orders()
u:add_order("ZAUBERE 'Erschaffe ein Traumauge'")
local amax = u.aura_max
process_orders()
assert_equal(1, u:get_item("dreameye"))
assert_equal(100, u.aura)
assert_equal(amax - 5, u.aura_max)
end

View File

@ -268,6 +268,23 @@ static int tolua_faction_setkey(lua_State * L)
return 0; return 0;
} }
static int tolua_faction_get_messages(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
int i = 1;
mlist *ml;
if (!self->msgs) {
return 0;
}
lua_newtable(L);
for (ml = self->msgs->begin; ml; ml = ml->next, ++i) {
lua_pushnumber(L, i);
lua_pushstring(L, ml->msg->type->name);
lua_rawset(L, -3);
}
return 1;
}
static int tolua_faction_count_msg_type(lua_State *L) { static int tolua_faction_count_msg_type(lua_State *L) {
faction *self = (faction *)tolua_tousertype(L, 1, 0); faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *str = tolua_tostring(L, 2, 0); const char *str = tolua_tostring(L, 2, 0);
@ -637,6 +654,7 @@ void tolua_faction_open(lua_State * L)
/* tech debt hack, siehe https://paper.dropbox.com/doc/Weihnachten-2015-5tOx5r1xsgGDBpb0gILrv#:h=Probleme-mit-Tests-(Nachtrag-0 */ /* 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_function(L, TOLUA_CAST "count_msg_type", tolua_faction_count_msg_type);
tolua_variable(L, TOLUA_CAST "messages", tolua_faction_get_messages, NULL);
tolua_function(L, TOLUA_CAST "get_key", tolua_faction_getkey); tolua_function(L, TOLUA_CAST "get_key", tolua_faction_getkey);
tolua_function(L, TOLUA_CAST "set_key", tolua_faction_setkey); tolua_function(L, TOLUA_CAST "set_key", tolua_faction_setkey);

View File

@ -193,6 +193,13 @@ static int tolua_unit_set_id(lua_State * L)
return 0; return 0;
} }
static int tolua_unit_get_auramax(lua_State * L)
{
unit *self = (unit *)tolua_tousertype(L, 1, 0);
lua_pushinteger(L, max_spellpoints(self->region, self));
return 1;
}
static int tolua_unit_get_hpmax(lua_State * L) static int tolua_unit_get_hpmax(lua_State * L)
{ {
unit *self = (unit *)tolua_tousertype(L, 1, 0); unit *self = (unit *)tolua_tousertype(L, 1, 0);
@ -1033,6 +1040,7 @@ void tolua_unit_open(lua_State * L)
tolua_variable(L, TOLUA_CAST "race", &tolua_unit_get_race, tolua_variable(L, TOLUA_CAST "race", &tolua_unit_get_race,
tolua_unit_set_race); tolua_unit_set_race);
tolua_variable(L, TOLUA_CAST "hp_max", &tolua_unit_get_hpmax, 0); tolua_variable(L, TOLUA_CAST "hp_max", &tolua_unit_get_hpmax, 0);
tolua_variable(L, TOLUA_CAST "aura_max", &tolua_unit_get_auramax, 0);
tolua_function(L, TOLUA_CAST "show", &tolua_bufunit); tolua_function(L, TOLUA_CAST "show", &tolua_bufunit);
} }