forked from github/server
Merge pull request #168 from badgerman/hotfix-3-4-5
tests for volcanooutbreak and spyreport messages
This commit is contained in:
commit
a5da77c376
|
@ -794,3 +794,26 @@ function test_only_building_owner_can_set_not_paid()
|
|||
process_orders()
|
||||
assert_equal(0, u1:get_item("money"))
|
||||
end
|
||||
|
||||
function test_spyreport_message()
|
||||
local r1 = region.create(1, 2, "plain")
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r1, 1)
|
||||
local u2 = unit.create(f1, r1, 1)
|
||||
msg = message.create("spyreport")
|
||||
msg:set_unit("spy", u1)
|
||||
msg:set_unit("target", u2)
|
||||
msg:set_string("status", "hodor")
|
||||
assert_not_equal("", msg:render("de"))
|
||||
assert_not_equal("", msg:render("en"))
|
||||
end
|
||||
|
||||
function test_volcanooutbreak_message()
|
||||
local r1 = region.create(1, 0, "plain")
|
||||
local r2 = region.create(1, 1, "plain")
|
||||
msg = message.create("volcanooutbreak")
|
||||
msg:set_region("regionn", r1)
|
||||
msg:set_region("regionv", r2)
|
||||
assert_not_equal("", msg:render("de"))
|
||||
assert_not_equal("", msg:render("en"))
|
||||
end
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
#include <kernel/unit.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include <util/nrmessage.h>
|
||||
|
||||
/* lua includes */
|
||||
#include <tolua.h>
|
||||
|
@ -307,6 +309,21 @@ static int tolua_msg_send_faction(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_msg_render(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char * lname = tolua_tostring(L, 2, 0);
|
||||
const struct locale * lang = lname ? get_locale(lname) : default_locale;
|
||||
char name[64];
|
||||
|
||||
if (lmsg->msg == NULL) {
|
||||
lmsg->msg = msg_create(lmsg->mtype, lmsg->args);
|
||||
}
|
||||
nr_render(lmsg->msg, lang, name, sizeof(name), NULL);
|
||||
lua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void tolua_message_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
|
@ -321,6 +338,7 @@ void tolua_message_open(lua_State * L)
|
|||
NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "message");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "render", tolua_msg_render);
|
||||
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_region", tolua_msg_set_region);
|
||||
|
|
Loading…
Reference in New Issue