- new test case (recruiting)

- logging and compilation fixes
This commit is contained in:
Enno Rehling 2008-12-31 11:30:44 +00:00
parent 5ea74d8bd8
commit 24182c4d06
6 changed files with 119 additions and 104 deletions

View File

@ -4,7 +4,7 @@
#include "eressea/server.cpp"
#ifndef BINDINGS_TOLUA
#ifdef BINDINGS_LUABIND
#include "eressea/lua/alliance.cpp"
#include "eressea/lua/building.cpp"
#include "eressea/lua/eressea.cpp"

View File

@ -837,7 +837,7 @@ demographics(void)
free(free_migrants);
free_migrants = m;
};
putchar('\n');
if (verbosity>=1) putchar('\n');
remove_empty_units();
@ -3930,7 +3930,7 @@ update_subscriptions(void)
strcat(strcpy(zText, basepath()), "/subscriptions");
F = fopen(zText, "r");
if (F==NULL) {
log_info((0, "could not open %s.\n", zText));
log_warning((0, "could not open %s.\n", zText));
return;
}
for (;;) {

View File

@ -357,10 +357,6 @@ extern void reorder_units(struct region * r);
extern const char *localenames[];
#ifdef _MSC_VER
#include <stdafx.h>
#endif
/** compatibility: **/
extern race_t old_race(const struct race *);
extern const struct race * new_race[];

View File

@ -258,31 +258,31 @@ _log_info(unsigned int level, const char * format, ...)
va_start(marker, format);
vfprintf(logfile, format, marker);
va_end(marker);
}
if (logfile!=stderr) {
if (stderr_level>=level) {
fprintf(stderr, "INFO[%u]: ", level);
va_start(marker, format);
if (stdio_codepage) {
char buffer[MAXLENGTH];
char converted[MAXLENGTH];
if (logfile!=stderr) {
if (stderr_level>=level) {
fprintf(stderr, "INFO[%u]: ", level);
va_start(marker, format);
if (stdio_codepage) {
char buffer[MAXLENGTH];
char converted[MAXLENGTH];
vsnprintf(buffer, sizeof(buffer), format, marker);
if (cp_convert(buffer, converted, MAXLENGTH, stdio_codepage)==0) {
fputs(converted, stderr);
} else {
/* fall back to non-converted output */
va_end(marker);
va_start(marker, format);
vfprintf(stderr, format, marker);
}
} else {
vfprintf(stderr, format, marker);
}
va_end(marker);
}
if (log_flags & LOG_FLUSH) {
log_flush();
vsnprintf(buffer, sizeof(buffer), format, marker);
if (cp_convert(buffer, converted, MAXLENGTH, stdio_codepage)==0) {
fputs(converted, stderr);
} else {
/* fall back to non-converted output */
va_end(marker);
va_start(marker, format);
vfprintf(stderr, format, marker);
}
} else {
vfprintf(stderr, format, marker);
}
va_end(marker);
}
if (log_flags & LOG_FLUSH) {
log_flush();
}
}
}
}

View File

@ -122,11 +122,11 @@
#ifdef _MSC_VER
#pragma warning (pop)
#endif // _MSC_VER
#endif // BINDINGS_LUABIND
#include "lua/script.h"
#include <boost/version.hpp>
#endif // BINDINGS_LUABIND
#include <libxml/encoding.h>
/* stdc++ includes */

View File

@ -100,48 +100,48 @@ local function test_unit()
end
local function test_region()
free_game()
local r = region.create(0, 0, "plain")
r:set_resource("horse", 42)
r:set_resource("money", 45)
r:set_resource("peasant", 200)
assert(r:get_resource("horse") == 42)
assert(r:get_resource("money") == 45)
assert(r:get_resource("peasant") == 200)
r.name = nil
r.info = nil
assert(r.name=="")
assert(r.info=="")
r.name = "Alabasterheim"
r.info = "Hier wohnen die siebzehn Zwerge"
assert(tostring(r) == "Alabasterheim (0,0)")
free_game()
local r = region.create(0, 0, "plain")
r:set_resource("horse", 42)
r:set_resource("money", 45)
r:set_resource("peasant", 200)
assert(r:get_resource("horse") == 42)
assert(r:get_resource("money") == 45)
assert(r:get_resource("peasant") == 200)
r.name = nil
r.info = nil
assert(r.name=="")
assert(r.info=="")
r.name = "Alabasterheim"
r.info = "Hier wohnen die siebzehn Zwerge"
assert(tostring(r) == "Alabasterheim (0,0)")
end
local function test_building()
free_game()
local u
local f = faction.create("enno@eressea.de", "human", "de")
local r = region.create(0, 0, "plain")
local b = building.create(r, "castle")
u = unit.create(f, r)
u.number = 1
u.building = b
u = unit.create(f, r)
u.number = 2
-- u.building = b
u = unit.create(f, r)
u.number = 3
u.building = b
local units = 0
for u in b.units do
units = units + 1
end
assert(units==2)
local r2 = region.create(0, 1, "plain")
assert(b.region==r)
b.region = r2
assert(b.region==r2)
assert(r2.buildings()==b)
free_game()
local u
local f = faction.create("enno@eressea.de", "human", "de")
local r = region.create(0, 0, "plain")
local b = building.create(r, "castle")
u = unit.create(f, r)
u.number = 1
u.building = b
u = unit.create(f, r)
u.number = 2
-- u.building = b
u = unit.create(f, r)
u.number = 3
u.building = b
local units = 0
for u in b.units do
units = units + 1
end
assert(units==2)
local r2 = region.create(0, 1, "plain")
assert(b.region==r)
b.region = r2
assert(b.region==r2)
assert(r2.buildings()==b)
end
local function loadscript(name)
@ -153,30 +153,30 @@ local function loadscript(name)
end
local function test_message()
free_game()
local r = region.create(0, 0, "plain")
local f = faction.create("enno@eressea.de", "human", "de")
local u = unit.create(f, r)
local msg = message.create("item_create_spell")
msg:set_unit("mage", u)
msg:set_int("number", 1)
msg:set_resource("item", "sword")
msg:send_region(r)
msg:send_faction(f)
return msg
free_game()
local r = region.create(0, 0, "plain")
local f = faction.create("enno@eressea.de", "human", "de")
local u = unit.create(f, r)
local msg = message.create("item_create_spell")
msg:set_unit("mage", u)
msg:set_int("number", 1)
msg:set_resource("item", "sword")
msg:send_region(r)
msg:send_faction(f)
return msg
end
local function test_hashtable()
free_game()
local f = faction.create("enno@eressea.de", "human", "de")
f.objects:set("enno", "smart guy")
f.objects:set("age", 10)
assert(f.objects:get("jesus") == nil)
assert(f.objects:get("enno") == "smart guy")
assert(f.objects:get("age") == 10)
f.objects:set("age", nil)
assert(f.objects:get("age") == nil)
free_game()
local f = faction.create("enno@eressea.de", "human", "de")
f.objects:set("enno", "smart guy")
f.objects:set("age", 10)
assert(f.objects:get("jesus") == nil)
assert(f.objects:get("enno") == "smart guy")
assert(f.objects:get("age") == 10)
f.objects:set("age", nil)
assert(f.objects:get("age") == nil)
end
function test_events()
@ -185,7 +185,7 @@ function test_events()
str = evt:get(0)
u2 = evt:get(1)
assert(u2~=nil)
print(str=="Du Elf stinken")
assert(str=="Du Elf stinken")
message_unit(u, u2, "thanks unit, i got your message: " .. str)
message_faction(u, u2.faction, "thanks faction, i got your message: " .. str)
message_region(u, "thanks region, i got your message: " .. str)
@ -218,18 +218,37 @@ function test_events()
assert(fail==0)
end
local function test_recruit()
free_game()
local r = region.create(0, 0, "plain")
local f = faction.create("enno@eressea.de", "human", "de")
local u = unit.create(f, r)
u.number = 1
local n = 3
r:set_resource("peasant", 200)
u:clear_orders()
u:add_item("money", 85*n+20)
u:add_order("REKRUTIERE " .. n)
process_orders()
assert(u.number == n+1)
local p = r:get_resource("peasant")
assert(p<200 and p>=200-n)
assert(u:get_item("money")==10)
end
loadscript("extensions.lua")
tests = {
["test_pure"] = test_pure,
["test_read_write"] = test_read_write,
["test_faction"] = test_faction,
["test_region"] = test_region,
["test_building"] = test_building,
["test_unit"] = test_unit,
["test_message"] = test_message,
["test_hashtable"] = test_hashtable,
["test_gmtool"] = test_gmtool,
["test_events"] = test_events
["pure"] = test_pure,
["read_write"] = test_read_write,
["faction"] = test_faction,
["region"] = test_region,
["building"] = test_building,
["unit"] = test_unit,
["message"] = test_message,
["hashtable"] = test_hashtable,
["gmtool"] = test_gmtool,
["events"] = test_events,
["recruit"] = test_recruit
}
fail = 0