From ace886a2d3de93b51843051029ef829751cba82f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 2 Mar 2014 10:55:35 -0800 Subject: [PATCH] added a test for saving/loading descriptions (bug 1984). added bindings for ship descriptions. fixed test framework, so make test will show failures in lua. --- core/scripts/init.lua | 2 +- core/scripts/tests/common.lua | 36 ++++++++++++++++++++++++++++++----- crypto | 2 +- src/bind_ship.c | 17 +++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/core/scripts/init.lua b/core/scripts/init.lua index bafa3da63..83bcc4f63 100755 --- a/core/scripts/init.lua +++ b/core/scripts/init.lua @@ -19,7 +19,7 @@ function run_tests() local argv = tests or {} local stats = lunit.main(argv) if stats.errors > 0 or stats.failed > 0 then - return 1 + assert(stats.errors == 0 and stats.failed == 0) end return 0 end diff --git a/core/scripts/tests/common.lua b/core/scripts/tests/common.lua index f20d48a10..f6aebd8db 100755 --- a/core/scripts/tests/common.lua +++ b/core/scripts/tests/common.lua @@ -39,7 +39,6 @@ module("tests.eressea.common", package.seeall, lunit.testcase) function setup() eressea.free_game() - eressea.write_game("free.dat") eressea.settings.set("nmr.removenewbie", "0") eressea.settings.set("nmr.timeout", "0") eressea.settings.set("NewbieImmunity", "0") @@ -152,7 +151,7 @@ function test_read_write() local uno = u.id local result = 0 assert_equal(r.terrain, "plain") - result = eressea.write_game("test_read_write.dat") + result = eressea.write_game("test.dat") assert_equal(result, 0) assert_not_equal(get_region(0, 0), nil) assert_not_equal(get_faction(fno), nil) @@ -164,13 +163,41 @@ function test_read_write() assert_equal(get_region(0, 0), nil) assert_equal(nil, get_faction(fno)) assert_equal(nil, get_unit(uno)) - result = eressea.read_game("test_read_write.dat") + result = eressea.read_game("test.dat") assert_equal(0, result) assert_not_equal(nil, get_region(0, 0)) assert_not_equal(nil, get_faction(fno)) assert_not_equal(nil, get_unit(uno)) end +function test_descriptions() + local info = "Descriptions can be very long. Bug 1984 behauptet, dass es Probleme gibt mit Beschreibungen die laenger als 120 Zeichen sind. This description is longer than 120 characters." + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + local s = _test_create_ship(r) + local b = building.create(r, "castle") + local uno = u.id + local fno = f.id + local sno = s.id + local bno = b.id + u.info = info + r.info = info + f.info = info + s.info = info + b.info = info + + filename = "test.dat" + eressea.write_game(filename) + eressea.free_game() + eressea.read_game(filename) + assert_equal(info, get_ship(sno).info) + assert_equal(info, get_unit(uno).info) + assert_equal(info, get_faction(fno).info) + assert_equal(info, get_building(bno).info) + assert_equal(info, get_region(0, 0).info) +end + function test_gmtool() local r1 = region.create(1, 0, "plain") local r2 = region.create(1, 1, "plain") @@ -577,7 +604,7 @@ function test_store_unit() local u = unit.create(f, r, 1) local fid = f.id u:add_item("money", u.number * 100) - local filename = config.basepath .. "/data/test.unit.dat" + local filename = config.basepath .. "/data/test.dat" store = storage.create(filename, "wb") assert_not_equal(store, nil) store:write_unit(u) @@ -1012,7 +1039,6 @@ module("tests.parser", package.seeall, lunit.testcase) function setup() eressea.free_game() - eressea.write_game("free.dat") eressea.settings.set("rules.economy.food", "4") -- FOOD_IS_FREE eressea.settings.set("rules.encounters", "0") eressea.settings.set("rules.move.owner_leave", "0") diff --git a/crypto b/crypto index dfa8a3225..166fdc8c1 160000 --- a/crypto +++ b/crypto @@ -1 +1 @@ -Subproject commit dfa8a32257786268cf3983b30916787430d6a846 +Subproject commit 166fdc8c146755055217070c58079ba9a7c03369 diff --git a/src/bind_ship.c b/src/bind_ship.c index ddfa883ad..7b9a61b67 100644 --- a/src/bind_ship.c +++ b/src/bind_ship.c @@ -50,6 +50,13 @@ static int tolua_ship_get_name(lua_State * L) return 1; } +static int tolua_ship_get_display(lua_State * L) +{ + ship *self = (ship *) tolua_tousertype(L, 1, 0); + tolua_pushstring(L, self->display); + return 1; +} + static int tolua_ship_get_region(lua_State * L) { ship *self = (ship *) tolua_tousertype(L, 1, 0); @@ -77,6 +84,14 @@ static int tolua_ship_set_name(lua_State * L) return 0; } +static int tolua_ship_set_display(lua_State * L) +{ + ship *self = (ship *) tolua_tousertype(L, 1, 0); + free(self->display); + self->display = _strdup(tolua_tostring(L, 2, 0)); + return 0; +} + static int tolua_ship_get_units(lua_State * L) { ship *self = (ship *) tolua_tousertype(L, 1, 0); @@ -175,6 +190,8 @@ void tolua_ship_open(lua_State * L) tolua_variable(L, TOLUA_CAST "id", tolua_ship_get_id, NULL); tolua_variable(L, TOLUA_CAST "name", tolua_ship_get_name, tolua_ship_set_name); + tolua_variable(L, TOLUA_CAST "info", tolua_ship_get_display, + tolua_ship_set_display); tolua_variable(L, TOLUA_CAST "units", tolua_ship_get_units, NULL); tolua_variable(L, TOLUA_CAST "flags", &tolua_ship_get_flags, tolua_ship_set_flags);