From 455e742116541b4a3d000f5209ad29168865ca4d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 19 May 2015 23:27:57 +0200 Subject: [PATCH 1/3] add a test for writing reports --- scripts/tests/e2/init.lua | 1 + scripts/tests/e2/process.lua | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 scripts/tests/e2/process.lua diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index bec715853..eeb6a4ba0 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -2,3 +2,4 @@ require 'tests.e2.shiplanding' require 'tests.e2.e2features' require 'tests.e2.movement' require 'tests.e2.guard' +require 'tests.e2.process' diff --git a/scripts/tests/e2/process.lua b/scripts/tests/e2/process.lua new file mode 100644 index 000000000..b709d7b57 --- /dev/null +++ b/scripts/tests/e2/process.lua @@ -0,0 +1,43 @@ +require "lunit" + +module("tests.e2.process", package.seeall, lunit.testcase) + +local u, r, f,turn + +function setup() + eressea.free_game() + r = region.create(0, 0, "plain") + f = faction.create("bernd@eressea.de", "human", "de") + u = unit.create(f, r, 1) + u:add_item("money", 10) + turn = get_turn() +end + +local function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end +end + +local function assert_file(filename) + assert_equal(true, file_exists(filename)) + os.remove(filename) +end + +function test_process_turn() + u:add_order("NUMMER PARTEI 777") + process_orders() + assert_equal(0, init_reports()) + assert_equal(0, write_reports()) + assert_equal(0, eressea.write_game("test.dat")) + assert_file("data/test.dat") + assert_file("reports/" .. get_turn() .. "-ii.nr") + assert_file("reports/" .. get_turn() .. "-ii.cr") + assert_file("reports/" .. get_turn() .. "-ii.txt") + assert_file("reports/" .. get_turn() .. "-777.nr") + assert_file("reports/" .. get_turn() .. "-777.cr") + assert_file("reports/" .. get_turn() .. "-777.txt") + assert_file("reports/reports.txt") + os.remove("reports") + os.remove("data") + assert_equal(turn+1, get_turn()) +end From e8fa654a385277ff4d611f99cd47c85770c63f14 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 20 May 2015 12:42:30 +0200 Subject: [PATCH 2/3] test processing and reports for E2 and E3 both --- scripts/tests/e2/init.lua | 2 +- scripts/tests/e3/init.lua | 1 + scripts/tests/{e2 => }/process.lua | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) rename scripts/tests/{e2 => }/process.lua (95%) diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index eeb6a4ba0..92706b3e3 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -2,4 +2,4 @@ require 'tests.e2.shiplanding' require 'tests.e2.e2features' require 'tests.e2.movement' require 'tests.e2.guard' -require 'tests.e2.process' +require 'tests.process' diff --git a/scripts/tests/e3/init.lua b/scripts/tests/e3/init.lua index fe7d0c223..92efd69d7 100644 --- a/scripts/tests/e3/init.lua +++ b/scripts/tests/e3/init.lua @@ -3,3 +3,4 @@ require 'tests.e3.stealth' require 'tests.e3.spells' require 'tests.e3.rules' require 'tests.e3.parser' +require 'tests.process' diff --git a/scripts/tests/e2/process.lua b/scripts/tests/process.lua similarity index 95% rename from scripts/tests/e2/process.lua rename to scripts/tests/process.lua index b709d7b57..3256c73e6 100644 --- a/scripts/tests/e2/process.lua +++ b/scripts/tests/process.lua @@ -1,6 +1,6 @@ require "lunit" -module("tests.e2.process", package.seeall, lunit.testcase) +module("tests.process", package.seeall, lunit.testcase) local u, r, f,turn From af8a24e214f20084d9345dba13b29e042562dad8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 7 Aug 2015 00:09:18 +0200 Subject: [PATCH 3/3] I'm pretty sure this is already fixed in develop, but who knows. --- src/util/bsdstring.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index c43847da1..652608483 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -12,10 +12,6 @@ int wrptr(char **ptr, size_t * size, size_t bytes) if (bytes == 0) { return 0; } - if (bytes < 0) { - *size = 0; - return EINVAL; - } if (bytes <= *size) { *ptr += bytes; *size -= bytes;