crash in quit faction

fix test modules that have no setup
add test for lazy trolls
This commit is contained in:
Enno Rehling 2020-01-26 12:32:31 +01:00
parent 2af7a1350b
commit 63f4853875
4 changed files with 68 additions and 13 deletions

View File

@ -2,16 +2,8 @@ require "lunit"
module("tests.e2.allies", package.seeall, lunit.testcase)
function skip_test_get_set_ally()
local f1 = faction.create("human")
local f2 = faction.create("human")
assert_equal(false, f1:get_ally(f2, "guard"))
f1:set_ally(f2, "guard", true)
assert_equal(true, f1:get_ally(f2, "guard"))
assert_equal(false, f1:get_ally(f2, "give"))
f1:set_ally(f2, "give", true)
assert_equal(true, f1:get_ally(f2, "give"))
function setup()
eressea.free_game()
end
function test_get_allies()
@ -28,3 +20,16 @@ function test_get_allies()
assert_equal(1, #allies[f2.id])
assert_equal("give", allies[f2.id][1])
end
function test_get_set_ally()
local f1 = faction.create("human")
local f2 = faction.create("human")
assert_equal(false, f1:get_ally(f2, "guard"))
f1:set_ally(f2, "guard", true)
assert_equal(true, f1:get_ally(f2, "guard"))
assert_equal(false, f1:get_ally(f2, "give"))
f1:set_ally(f2, "give", true)
assert_equal(true, f1:get_ally(f2, "give"))
end

View File

@ -1,7 +1,6 @@
require 'tests.e2.trolls'
require 'tests.e2.trees'
require 'tests.e2.buildings'
require 'tests.e2.allies'
require 'tests.e2.quit'
require 'tests.e2.movement'
require 'tests.e2.carts'
require 'tests.e2.quit'
@ -10,6 +9,7 @@ require 'tests.e2.spells'
require 'tests.e2.e2features'
require 'tests.e2.insects'
require 'tests.e2.production'
require 'tests.e2.allies'
require 'tests.e2.adamantium'
require 'tests.e2.undead'
require 'tests.e2.shiplanding'

View File

@ -0,0 +1,50 @@
require "lunit"
module("tests.e2.trolls", package.seeall, lunit.testcase )
function setup()
eressea.free_game()
end
function test_trolls_with_horses()
local r0 = region.create(0, 0, 'plain')
local r1 = region.create(1, 0, 'plain')
local r2 = region.create(2, 0, 'plain')
local r3 = region.create(3, 0, 'plain')
local r4 = region.create(4, 0, 'plain')
local r5 = region.create(5, 0, 'plain')
local f = faction.create('troll')
-- 1. 20 trolls can pull 5 loaded carts:
assert_not_nil(r0)
local u1 = unit.create(f, r0, 20)
u1:add_item('cart', 5)
-- trolls carry 10.8 GE, carts carry 100 GE:
u1:add_item('money', 100 * (5 * 100 + 2 * 108))
u1:add_order('NACH O O O')
process_orders()
assert_equal(r1, u1.region)
-- 20 trolls can also lead 20 horses
u1:add_item('horse', 20)
u1:add_item('money', 100 * 20 * 20)
process_orders()
assert_equal(r2, u1.region)
-- test if trolls are still "lazy". If yes they should still manage 10 full carts behind the 20 horses (5 more)
u1:add_item('cart', 5)
u1:add_item('money', 100 * 5 * 100)
process_orders()
assert_equal(r3, u1.region)
-- test if trolls are still "lazy". If not they should manage 15 full carts, 5 behind trolls and 10 behind 20 horses (again 5 more)
u1:add_item('cart', 5)
u1:add_item('money', 100 * 5 * 100)
process_orders()
assert_equal(r4, u1.region)
end

View File

@ -980,7 +980,7 @@ int quit_cmd(unit * u, struct order *ord)
if (p == P_FACTION) {
#ifdef QUIT_WITH_TRANSFER
faction *f2 = getfaction();
if (f2 == NULL) {
if (f2 == NULL || f2 == u->faction) {
cmistake(u, ord, 66, MSG_EVENT);
flags = 0;
}