From ff888401a15de39a791affaecadb91491d350eb9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 8 Sep 2015 07:40:08 +0200 Subject: [PATCH 01/17] disable valgrind --- tests/run-turn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-turn.sh b/tests/run-turn.sh index 4055613e5..e6b896618 100755 --- a/tests/run-turn.sh +++ b/tests/run-turn.sh @@ -30,7 +30,7 @@ set -e cd $ROOT/tests setup cleanup -VALGRIND=`which valgrind` +#VALGRIND=`which valgrind` SERVER=../Debug/eressea/eressea if [ -n "$VALGRIND" ]; then SUPP=../share/ubuntu-12_04.supp From 23a7ed59acf29f4f1bb7f421b06573d918a318aa Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 14 Sep 2015 17:17:29 +0200 Subject: [PATCH 02/17] backport familiar skill test from 3.7 development --- src/kernel/unit.test.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 7f281fc36..a76b5ea69 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -239,6 +239,33 @@ static void test_default_name(CuTest *tc) { test_cleanup(); } +static void test_skill_familiar(CuTest *tc) { + unit *mag, *fam; + region *r; + + test_cleanup(); + + // setup two units + mag = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + fam = test_create_unit(mag->faction, test_create_region(0, 0, 0)); + set_level(fam, SK_PERCEPTION, 6); + CuAssertIntEquals(tc, 6, effskill(fam, SK_PERCEPTION)); + set_level(mag, SK_PERCEPTION, 6); + CuAssertIntEquals(tc, 6, effskill(mag, SK_PERCEPTION)); + + // make them mage and familiar to each other + CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam)); + + // when they are in the same region, the mage gets half their skill as a bonus + CuAssertIntEquals(tc, 6, effskill(fam, SK_PERCEPTION)); + CuAssertIntEquals(tc, 9, effskill(mag, SK_PERCEPTION)); + + // when they are further apart, divide bonus by distance + r = test_create_region(3, 0, 0); + move_unit(fam, r, &r->units); + CuAssertIntEquals(tc, 7, effskill(mag, SK_PERCEPTION)); + test_cleanup(); +} CuSuite *get_unit_suite(void) { @@ -254,5 +281,6 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_remove_empty_units_in_region); SUITE_ADD_TEST(suite, test_names); SUITE_ADD_TEST(suite, test_default_name); + SUITE_ADD_TEST(suite, test_skill_familiar); return suite; } From 3a1444f37803021e6c30d1bb0270b10f7272e0f9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 14 Sep 2015 17:38:58 +0200 Subject: [PATCH 03/17] backport (failing) at_familiarmage test from 3.7 branch --- src/kernel/unit.test.c | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index a76b5ea69..d962fee51 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -239,6 +239,31 @@ static void test_default_name(CuTest *tc) { test_cleanup(); } +static void test_skill_hunger(CuTest *tc) { + unit *u; + + test_cleanup(); + u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + set_level(u, SK_ARMORER, 6); + set_level(u, SK_SAILING, 6); + fset(u, UFL_HUNGER); + + set_param(&global.parameters, "rules.hunger.reduces_skill", "0"); + CuAssertIntEquals(tc, 6, effskill(u, SK_ARMORER)); + CuAssertIntEquals(tc, 6, effskill(u, SK_SAILING)); + + set_param(&global.parameters, "rules.hunger.reduces_skill", "1"); + CuAssertIntEquals(tc, 3, effskill(u, SK_ARMORER)); + CuAssertIntEquals(tc, 3, effskill(u, SK_SAILING)); + + set_param(&global.parameters, "rules.hunger.reduces_skill", "2"); + CuAssertIntEquals(tc, 3, effskill(u, SK_ARMORER)); + CuAssertIntEquals(tc, 5, effskill(u, SK_SAILING)); + set_level(u, SK_SAILING, 2); + CuAssertIntEquals(tc, 1, effskill(u, SK_SAILING)); + test_cleanup(); +} + static void test_skill_familiar(CuTest *tc) { unit *mag, *fam; region *r; @@ -267,6 +292,29 @@ static void test_skill_familiar(CuTest *tc) { test_cleanup(); } +static void test_age_familiar(CuTest *tc) { + unit *mag, *fam; + + test_cleanup(); + + // setup two units + mag = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + fam = test_create_unit(mag->faction, test_create_region(0, 0, 0)); + CuAssertPtrEquals(tc, 0, get_familiar(mag)); + CuAssertPtrEquals(tc, 0, get_familiar_mage(fam)); + CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam)); + CuAssertPtrEquals(tc, fam, get_familiar(mag)); + CuAssertPtrEquals(tc, mag, get_familiar_mage(fam)); + a_age(&fam->attribs); + a_age(&mag->attribs); + CuAssertPtrEquals(tc, fam, get_familiar(mag)); + CuAssertPtrEquals(tc, mag, get_familiar_mage(fam)); + set_number(fam, 0); + a_age(&mag->attribs); + CuAssertPtrEquals(tc, 0, get_familiar(mag)); + test_cleanup(); +} + CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -281,6 +329,8 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_remove_empty_units_in_region); SUITE_ADD_TEST(suite, test_names); SUITE_ADD_TEST(suite, test_default_name); + SUITE_ADD_TEST(suite, test_skill_hunger); SUITE_ADD_TEST(suite, test_skill_familiar); + SUITE_ADD_TEST(suite, test_age_familiar); return suite; } From e217a4b55091bcf1dfcbcac090e850e66fe82bb3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 25 Aug 2015 22:50:58 +0200 Subject: [PATCH 04/17] age_unit accidentally returned AT_AGE_REMOVE (caused by a recent change to curse_age) --- src/kernel/curse.c | 2 +- src/util/attrib.c | 2 +- src/util/attrib.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kernel/curse.c b/src/kernel/curse.c index afa8ac2c3..828552a3a 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -131,7 +131,7 @@ int curse_age(attrib * a) else if (c->duration != INT_MAX) { c->duration = _max(0, c->duration - 1); } - return c->duration; + return (c->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } void destroy_curse(curse * c) diff --git a/src/util/attrib.c b/src/util/attrib.c index fb50d8dfc..26869cfee 100644 --- a/src/util/attrib.c +++ b/src/util/attrib.c @@ -256,7 +256,7 @@ int a_age(attrib ** p) if (a->type->age) { int result = a->type->age(a); assert(result >= 0 || !"age() returned a negative value"); - if (result == 0) { + if (result == AT_AGE_REMOVE) { a_remove(p, a); continue; } diff --git a/src/util/attrib.h b/src/util/attrib.h index cbba4ebf4..c235fd67a 100644 --- a/src/util/attrib.h +++ b/src/util/attrib.h @@ -90,8 +90,8 @@ extern "C" { #define AT_READ_OK 0 #define AT_READ_FAIL -1 -#define AT_AGE_KEEP 0 /* keep the attribute for another turn */ -#define AT_AGE_REMOVE 1 /* remove the attribute after calling age() */ +#define AT_AGE_REMOVE 0 /* remove the attribute after calling age() */ +#define AT_AGE_KEEP 1 /* keep the attribute for another turn */ #ifdef __cplusplus } From 1028539adb171c2c76779fe8e805a9b765156b52 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 23 Sep 2015 18:29:18 +0200 Subject: [PATCH 05/17] version number increase --- src/buildno.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/buildno.h b/src/buildno.h index c494bb5ee..11bf425d6 100644 --- a/src/buildno.h +++ b/src/buildno.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 3 #define VERSION_MINOR 6 -#define VERSION_BUILD 3 +#define VERSION_BUILD 4 From 6162d0f16cdc2504884ba12a0c3c8e7af10dbd9e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 25 Sep 2015 11:31:43 +0200 Subject: [PATCH 06/17] fixing bug 2141 --- res/core/weapons/mallorncrossbow.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/res/core/weapons/mallorncrossbow.xml b/res/core/weapons/mallorncrossbow.xml index 8d4a5027b..fb7be26c0 100644 --- a/res/core/weapons/mallorncrossbow.xml +++ b/res/core/weapons/mallorncrossbow.xml @@ -5,8 +5,8 @@ - - + + From 3eead446d0fba2db8d83e2b880ba927454abdd40 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 26 Sep 2015 22:42:22 +0200 Subject: [PATCH 07/17] reduce cron log spam --- src/battle.c | 4 ++-- src/kernel/save.c | 29 +++++++++++++---------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/battle.c b/src/battle.c index 44a594863..a47db8163 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1691,9 +1691,9 @@ void do_combatmagic(battle * b, combatmagic_t was) if (was == DO_PRECOMBATSPELL) { for (s = b->sides; s != b->sides + b->nsides; ++s) { fighter *fig = 0; - if (s->bf->attacker) { + if (fval(s->faction, FFL_CURSED) && s->bf->attacker) { spell *sp = find_spell("igjarjuk"); - if (sp && fval(s->faction, FFL_CURSED)) { + if (sp) { int si; for (si = 0; s->enemies[si]; ++si) { side *se = s->enemies[si]; diff --git a/src/kernel/save.c b/src/kernel/save.c index fc348acac..300555180 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1204,7 +1204,7 @@ faction *readfaction(struct gamedata * data) READ_STR(data->store, name, sizeof(name)); f->banner = _strdup(name); - log_printf(stdout, " - Lese Partei %s (%s)\n", f->name, factionid(f)); + log_debug(" - Lese Partei %s (%s)", f->name, factionid(f)); READ_STR(data->store, name, sizeof(name)); if (set_email(&f->email, name) != 0) { @@ -1385,7 +1385,7 @@ int readgame(const char *filename, bool backup) FILE *F; init_locales(); - log_printf(stdout, "- reading game data from %s\n", filename); + log_debug("- reading game data from %s\n", filename); sprintf(path, "%s/%s", datapath(), filename); if (backup) { @@ -1433,7 +1433,7 @@ int readgame(const char *filename, bool backup) a_read(&store, &global.attribs, NULL); READ_INT(&store, &turn); global.data_turn = turn; - log_printf(stdout, " - reading turn %d\n", turn); + log_debug(" - reading turn %d\n", turn); rng_init(turn); ++global.cookie; READ_INT(&store, &nread); /* max_unique_id = ignore */ @@ -1501,7 +1501,7 @@ int readgame(const char *filename, bool backup) /* Read factions */ read_alliances(&store); READ_INT(&store, &nread); - log_printf(stdout, " - Einzulesende Parteien: %d\n", nread); + log_debug(" - Einzulesende Parteien: %d\n", nread); fp = &factions; while (*fp) fp = &(*fp)->next; @@ -1522,7 +1522,7 @@ int readgame(const char *filename, bool backup) if (rmax < 0) { rmax = nread; } - log_printf(stdout, " - Einzulesende Regionen: %d/%d\r", rmax, nread); + log_debug(" - Einzulesende Regionen: %d/%d\r", rmax, nread); while (--nread >= 0) { unit **up; int x, y; @@ -1530,7 +1530,7 @@ int readgame(const char *filename, bool backup) READ_INT(&store, &y); if ((nread & 0x3FF) == 0) { /* das spart extrem Zeit */ - log_printf(stdout, " - Einzulesende Regionen: %d/%d * %d,%d \r", rmax, nread, x, y); + log_debug(" - Einzulesende Regionen: %d/%d * %d,%d \r", rmax, nread, x, y); } --rmax; @@ -1635,16 +1635,15 @@ int readgame(const char *filename, bool backup) update_interval(u->faction, u->region); } } - log_printf(stdout, "\n"); read_borders(&store); binstore_done(&store); fstream_done(&strm); /* Unaufgeloeste Zeiger initialisieren */ - log_printf(stdout, "fixing unresolved references.\n"); + log_debug("fixing unresolved references.\n"); resolve(); - log_printf(stdout, "updating area information for lighthouses.\n"); + log_debug("updating area information for lighthouses.\n"); for (r = regions; r; r = r->next) { if (r->flags & RF_LIGHTHOUSE) { building *b; @@ -1652,7 +1651,7 @@ int readgame(const char *filename, bool backup) update_lighthouse(b); } } - log_printf(stdout, "marking factions as alive.\n"); + log_debug("marking factions as alive.\n"); for (f = factions; f; f = f->next) { if (f->flags & FFL_NPC) { f->alive = 1; @@ -1699,7 +1698,7 @@ int readgame(const char *filename, bool backup) if (loadplane || maxregions >= 0) { remove_empty_factions(); } - log_printf(stdout, "Done loading turn %d.\n", turn); + log_debug("Done loading turn %d.\n", turn); return 0; } @@ -1805,7 +1804,7 @@ int writegame(const char *filename) WRITE_INT(&store, n); WRITE_SECTION(&store); - log_printf(stdout, " - Schreibe %d Parteien...\n", n); + log_debug(" - Schreibe %d Parteien...\n", n); for (f = factions; f; f = f->next) { if (fval(f, FFL_NPC)) { clear_npc_orders(f); @@ -1819,13 +1818,12 @@ int writegame(const char *filename) n = listlen(regions); WRITE_INT(&store, n); WRITE_SECTION(&store); - log_printf(stdout, " - Schreibe Regionen: %d \r", n); + log_debug(" - Schreibe Regionen: %d", n); for (r = regions; r; r = r->next, --n) { /* plus leerzeile */ if ((n % 1024) == 0) { /* das spart extrem Zeit */ - log_printf(stdout, " - Schreibe Regionen: %d \r", n); - fflush(stdout); + log_debug(" - Schreibe Regionen: %d", n); } WRITE_SECTION(&store); WRITE_INT(&store, r->x); @@ -1876,7 +1874,6 @@ int writegame(const char *filename) binstore_done(&store); fstream_done(&strm); - log_printf(stdout, "\nOk.\n"); return 0; } From 5e28cc9de39d348ada9cdcb585d5b8399f6537cb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 28 Sep 2015 11:31:58 +0200 Subject: [PATCH 08/17] re-enable valgrind --- tests/run-turn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-turn.sh b/tests/run-turn.sh index e6b896618..4055613e5 100755 --- a/tests/run-turn.sh +++ b/tests/run-turn.sh @@ -30,7 +30,7 @@ set -e cd $ROOT/tests setup cleanup -#VALGRIND=`which valgrind` +VALGRIND=`which valgrind` SERVER=../Debug/eressea/eressea if [ -n "$VALGRIND" ]; then SUPP=../share/ubuntu-12_04.supp From 37a8081c9bb9d1029365c8a89b0de93084cbeca9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 2 Oct 2015 11:30:14 +0200 Subject: [PATCH 09/17] handle express issues by filename --- process/compress.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/process/compress.py b/process/compress.py index 95b725fb0..204d580d7 100755 --- a/process/compress.py +++ b/process/compress.py @@ -24,7 +24,13 @@ try: except: print "%s: reports.txt file does not exist" % (argv[0], ) exit(0) - + +extras = [ '../wochenbericht.txt' ] +express='../express-%s.txt' % turn +if os.path.isfile(express): + os.symlink(express, 'express.txt') + extras.append('express.txt') + for line in infile.readlines(): settings = line[:-1].split(":") options = { "turn" : turn} @@ -38,7 +44,6 @@ for line in infile.readlines(): if not options.has_key("reports"): continue reports = options["reports"].split(",") -# reports = reports + [ "iso.cr" ] prefix = "%(turn)s-%(faction)s." % options if options["compression"]=="zip": output = prefix+"zip" @@ -61,7 +66,6 @@ for line in infile.readlines(): if os.path.isfile(output): continue os.system("bzip2 %s" % filename) - extras = [ '../wochenbericht.txt', '../express.txt' ] for extra in extras: if os.path.isfile(extra): files = files + [extra] From 61a95d8b526d48371056047cdcff6c7f5bd18dc9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 2 Oct 2015 11:30:14 +0200 Subject: [PATCH 10/17] handle express issues by filename --- process/compress.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/process/compress.py b/process/compress.py index 95b725fb0..204d580d7 100755 --- a/process/compress.py +++ b/process/compress.py @@ -24,7 +24,13 @@ try: except: print "%s: reports.txt file does not exist" % (argv[0], ) exit(0) - + +extras = [ '../wochenbericht.txt' ] +express='../express-%s.txt' % turn +if os.path.isfile(express): + os.symlink(express, 'express.txt') + extras.append('express.txt') + for line in infile.readlines(): settings = line[:-1].split(":") options = { "turn" : turn} @@ -38,7 +44,6 @@ for line in infile.readlines(): if not options.has_key("reports"): continue reports = options["reports"].split(",") -# reports = reports + [ "iso.cr" ] prefix = "%(turn)s-%(faction)s." % options if options["compression"]=="zip": output = prefix+"zip" @@ -61,7 +66,6 @@ for line in infile.readlines(): if os.path.isfile(output): continue os.system("bzip2 %s" % filename) - extras = [ '../wochenbericht.txt', '../express.txt' ] for extra in extras: if os.path.isfile(extra): files = files + [extra] From 99c385412ac391b4e3ddec777107689979d871d1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 10 Oct 2015 22:50:15 +0200 Subject: [PATCH 11/17] fix crash in mail_cmd when order is missing a message --- src/buildno.h | 2 +- src/laws.c | 8 ++++---- src/laws.test.c | 41 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/buildno.h b/src/buildno.h index 11bf425d6..7eabd81de 100644 --- a/src/buildno.h +++ b/src/buildno.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 3 #define VERSION_MINOR 6 -#define VERSION_BUILD 4 +#define VERSION_BUILD 5 diff --git a/src/laws.c b/src/laws.c index 488f6bbda..aedc34dc9 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2027,7 +2027,7 @@ int mail_cmd(unit * u, struct order *ord) } s = getstrtoken(); - if (!s[0]) { + if (!s || !s[0]) { cmistake(u, ord, 30, MSG_MESSAGE); break; } @@ -2050,7 +2050,7 @@ int mail_cmd(unit * u, struct order *ord) } s = getstrtoken(); - if (!s[0]) { + if (!s || !s[0]) { cmistake(u, ord, 30, MSG_MESSAGE); break; } @@ -2082,7 +2082,7 @@ int mail_cmd(unit * u, struct order *ord) s = getstrtoken(); - if (!s[0]) { + if (!s || !s[0]) { cmistake(u, ord, 30, MSG_MESSAGE); break; } @@ -2111,7 +2111,7 @@ int mail_cmd(unit * u, struct order *ord) s = getstrtoken(); - if (!s[0]) { + if (!s || !s[0]) { cmistake(u, ord, 30, MSG_MESSAGE); break; } diff --git a/src/laws.test.c b/src/laws.test.c index a824f4cab..431c03845 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -970,7 +970,7 @@ static void test_ally_cmd(CuTest *tc) { test_cleanup(); } -void test_nmr_warnings(CuTest *tc) { +static void test_nmr_warnings(CuTest *tc) { faction *f1, *f2; test_cleanup(); set_param(&global.parameters, "nmr.timeout", "3"); @@ -989,6 +989,43 @@ void test_nmr_warnings(CuTest *tc) { test_cleanup(); } +static void test_mail_cmd(CuTest *tc) { + unit *u; + order *ord; + faction *f; + struct locale *lang; + + test_cleanup(); + f = test_create_faction(0); + f->locale = lang = get_or_create_locale("de"); + locale_setstring(lang, parameters[P_UNIT], "EINHEIT"); + init_parameters(lang); + u = test_create_unit(f, test_create_region(0, 0, 0)); + ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s 'Hodor!'", itoa36(u->no)); + mail_cmd(u, ord); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "unitmessage")); + test_cleanup(); +} + +static void test_mail_cmd_no_msg(CuTest *tc) { + unit *u; + order *ord; + faction *f; + struct locale *lang; + + test_cleanup(); + f = test_create_faction(0); + f->locale = lang = get_or_create_locale("de"); + locale_setstring(lang, parameters[P_UNIT], "EINHEIT"); + init_parameters(lang); + u = test_create_unit(f, test_create_region(0, 0, 0)); + ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s", itoa36(u->no)); + mail_cmd(u, ord); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "unitmessage")); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30")); + test_cleanup(); +} + CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -1033,6 +1070,8 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_force_leave_ships); SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean); SUITE_ADD_TEST(suite, test_peasant_luck_effect); + SUITE_ADD_TEST(suite, test_mail_cmd); + SUITE_ADD_TEST(suite, test_mail_cmd_no_msg); (void)test_luck_message; /* disabled, breaks on travis */ return suite; From 070ed1a9416f546cf918edcbfb8f7e74745ece80 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Oct 2015 12:38:05 +0200 Subject: [PATCH 12/17] clean up hastily written tests, eliminate duplicate code --- src/laws.test.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 431c03845..c7f974de9 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -989,9 +989,7 @@ static void test_nmr_warnings(CuTest *tc) { test_cleanup(); } -static void test_mail_cmd(CuTest *tc) { - unit *u; - order *ord; +static unit * setup_mail_cmd(void) { faction *f; struct locale *lang; @@ -999,30 +997,32 @@ static void test_mail_cmd(CuTest *tc) { f = test_create_faction(0); f->locale = lang = get_or_create_locale("de"); locale_setstring(lang, parameters[P_UNIT], "EINHEIT"); + locale_setstring(lang, parameters[P_REGION], "REGION"); + locale_setstring(lang, parameters[P_FACTION], "PARTEI"); init_parameters(lang); - u = test_create_unit(f, test_create_region(0, 0, 0)); + return test_create_unit(f, test_create_region(0, 0, 0)); +} + +static void test_mail_cmd(CuTest *tc) { + order *ord; + unit *u; + + u = setup_mail_cmd(); ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s 'Hodor!'", itoa36(u->no)); mail_cmd(u, ord); - CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "unitmessage")); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "unitmessage")); test_cleanup(); } static void test_mail_cmd_no_msg(CuTest *tc) { unit *u; order *ord; - faction *f; - struct locale *lang; - test_cleanup(); - f = test_create_faction(0); - f->locale = lang = get_or_create_locale("de"); - locale_setstring(lang, parameters[P_UNIT], "EINHEIT"); - init_parameters(lang); - u = test_create_unit(f, test_create_region(0, 0, 0)); + u = setup_mail_cmd(); ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s", itoa36(u->no)); mail_cmd(u, ord); - CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "unitmessage")); - CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "unitmessage")); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30")); test_cleanup(); } From 403b8a2e7ea878243a8101b392b5f122c0e067fb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Oct 2015 12:44:22 +0200 Subject: [PATCH 13/17] add mail_cmd tests for REGION --- src/laws.test.c | 33 +++++++++++++++++++++++++++++---- src/tests.c | 2 +- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index c7f974de9..87b455330 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1003,7 +1003,7 @@ static unit * setup_mail_cmd(void) { return test_create_unit(f, test_create_region(0, 0, 0)); } -static void test_mail_cmd(CuTest *tc) { +static void test_mail_unit(CuTest *tc) { order *ord; unit *u; @@ -1014,7 +1014,18 @@ static void test_mail_cmd(CuTest *tc) { test_cleanup(); } -static void test_mail_cmd_no_msg(CuTest *tc) { +static void test_mail_region(CuTest *tc) { + order *ord; + unit *u; + + u = setup_mail_cmd(); + ord = create_order(K_MAIL, u->faction->locale, "REGION 'Hodor!'", itoa36(u->no)); + mail_cmd(u, ord); + CuAssertPtrNotNull(tc, test_find_messagetype(u->region->msgs, "mail_result")); + test_cleanup(); +} + +static void test_mail_unit_no_msg(CuTest *tc) { unit *u; order *ord; @@ -1026,6 +1037,18 @@ static void test_mail_cmd_no_msg(CuTest *tc) { test_cleanup(); } +static void test_mail_region_no_msg(CuTest *tc) { + unit *u; + order *ord; + + u = setup_mail_cmd(); + ord = create_order(K_MAIL, u->faction->locale, "REGION"); + mail_cmd(u, ord); + CuAssertPtrEquals(tc, 0, test_find_messagetype(u->region->msgs, "mail_result")); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30")); + test_cleanup(); +} + CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -1070,8 +1093,10 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_force_leave_ships); SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean); SUITE_ADD_TEST(suite, test_peasant_luck_effect); - SUITE_ADD_TEST(suite, test_mail_cmd); - SUITE_ADD_TEST(suite, test_mail_cmd_no_msg); + SUITE_ADD_TEST(suite, test_mail_unit); + SUITE_ADD_TEST(suite, test_mail_region); + SUITE_ADD_TEST(suite, test_mail_unit_no_msg); + SUITE_ADD_TEST(suite, test_mail_region_no_msg); (void)test_luck_message; /* disabled, breaks on travis */ return suite; diff --git a/src/tests.c b/src/tests.c index bcbd18c29..82417e9d2 100644 --- a/src/tests.c +++ b/src/tests.c @@ -257,7 +257,7 @@ const char * test_get_messagetype(const message *msg) { struct message * test_find_messagetype(struct message_list *msgs, const char *name) { struct mlist *ml; - assert(msgs); + if (!msgs) return 0; for (ml = msgs->begin; ml; ml = ml->next) { if (strcmp(name, test_get_messagetype(ml->msg)) == 0) { return ml->msg; From c47c9dbf6442645fdc46a1abaef11e1d3cbf360f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Oct 2015 12:52:13 +0200 Subject: [PATCH 14/17] add mail_cmd tests for FACTION --- src/laws.test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/laws.test.c b/src/laws.test.c index 87b455330..c7c3bf632 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1014,6 +1014,17 @@ static void test_mail_unit(CuTest *tc) { test_cleanup(); } +static void test_mail_faction(CuTest *tc) { + order *ord; + unit *u; + + u = setup_mail_cmd(); + ord = create_order(K_MAIL, u->faction->locale, "PARTEI %s 'Hodor!'", itoa36(u->faction->no)); + mail_cmd(u, ord); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "regionmessage")); + test_cleanup(); +} + static void test_mail_region(CuTest *tc) { order *ord; unit *u; @@ -1037,6 +1048,30 @@ static void test_mail_unit_no_msg(CuTest *tc) { test_cleanup(); } +static void test_mail_faction_no_msg(CuTest *tc) { + unit *u; + order *ord; + + u = setup_mail_cmd(); + ord = create_order(K_MAIL, u->faction->locale, "PARTEI %s", itoa36(u->faction->no)); + mail_cmd(u, ord); + CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "regionmessage")); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30")); + test_cleanup(); +} + +static void test_mail_faction_no_target(CuTest *tc) { + unit *u; + order *ord; + + u = setup_mail_cmd(); + ord = create_order(K_MAIL, u->faction->locale, "PARTEI %s", itoa36(u->faction->no+1)); + mail_cmd(u, ord); + CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "regionmessage")); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error66")); + test_cleanup(); +} + static void test_mail_region_no_msg(CuTest *tc) { unit *u; order *ord; @@ -1094,9 +1129,12 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean); SUITE_ADD_TEST(suite, test_peasant_luck_effect); SUITE_ADD_TEST(suite, test_mail_unit); + SUITE_ADD_TEST(suite, test_mail_faction); SUITE_ADD_TEST(suite, test_mail_region); SUITE_ADD_TEST(suite, test_mail_unit_no_msg); + SUITE_ADD_TEST(suite, test_mail_faction_no_msg); SUITE_ADD_TEST(suite, test_mail_region_no_msg); + SUITE_ADD_TEST(suite, test_mail_faction_no_target); (void)test_luck_message; /* disabled, breaks on travis */ return suite; From e8880db447bf9a92074a8a61601a5371b1dee598 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 26 Sep 2015 14:01:01 +0200 Subject: [PATCH 15/17] get the code to compile under vs2015 (disable warnings) --- src/creport.c | 2 +- src/magic.c | 6 +++--- src/platform.h | 8 ++++++++ src/report.c | 4 ++++ src/reports.c | 4 ++++ src/spells.c | 4 ++++ vs2015-build.bat | 11 +++++++++++ 7 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 vs2015-build.bat diff --git a/src/creport.c b/src/creport.c index aea88f03a..c8f4f9537 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1531,7 +1531,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) fprintf(F, "\"%s\";charset\n", charset); fprintf(F, "\"%s\";locale\n", locale_name(f->locale)); fprintf(F, "%d;noskillpoints\n", 1); - fprintf(F, "%ld;date\n", ctx->report_time); + fprintf(F, "%lld;date\n", (long long)ctx->report_time); fprintf(F, "\"%s\";Spiel\n", game_name()); fprintf(F, "\"%s\";Konfiguration\n", "Standard"); fprintf(F, "\"%s\";Koordinaten\n", "Hex"); diff --git a/src/magic.c b/src/magic.c index a02eff09f..a189e9495 100644 --- a/src/magic.c +++ b/src/magic.c @@ -870,9 +870,9 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range) /* Ein Spruch mit Fixkosten wird immer mit der Stufe des Spruchs und * nicht auf der Stufe des Magiers gezaubert */ if (costtyp == SPC_FIX) { - spellbook * spells = unit_get_spellbook(u); - if (spells) { - spellbook_entry * sbe = spellbook_get(spells, sp); + spellbook * sb = unit_get_spellbook(u); + if (sb) { + spellbook_entry * sbe = spellbook_get(sb, sp); if (sbe) { return _min(cast_level, sbe->level); } diff --git a/src/platform.h b/src/platform.h index 1da86fe5b..8e207fae2 100644 --- a/src/platform.h +++ b/src/platform.h @@ -34,6 +34,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # undef MOUSE_MOVED # define STDIO_CP 1252 /* log.c, convert to console character set */ # pragma warning (disable: 4201 4214 4514 4115 4711) +# pragma warning(disable: 4710) +/* warning C4710: function not inlined */ +# pragma warning(disable: 4456) +/* warning C4456 : declaration of hides previous local declaration */ +# pragma warning(disable: 4457) +/* warning C4457: declaration of hides function parameter */ +# pragma warning(disable: 4459) +/* warning C4459: declaration of hides global declaration */ # pragma warning(disable: 4056) /* warning C4056: overflow in floating point constant arithmetic */ # pragma warning(disable: 4201) diff --git a/src/report.c b/src/report.c index e77ff1d9e..254da710e 100644 --- a/src/report.c +++ b/src/report.c @@ -96,6 +96,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#ifdef _MSC_VER +# pragma warning(disable: 4774) // TODO: remove this +#endif + extern int *storms; extern int weeks_per_month; extern int months_per_year; diff --git a/src/reports.c b/src/reports.c index 21d51afa2..5f547b6ed 100644 --- a/src/reports.c +++ b/src/reports.c @@ -73,6 +73,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "move.h" +#ifdef _MSC_VER +# pragma warning(disable: 4774) // TODO: remove this +#endif + #define SCALEWEIGHT 100 /* Faktor, um den die Anzeige von Gewichten skaliert wird */ bool nocr = false; diff --git a/src/spells.c b/src/spells.c index 436a1bc43..033d74024 100644 --- a/src/spells.c +++ b/src/spells.c @@ -101,6 +101,10 @@ #include /* ----------------------------------------------------------------------- */ +#ifdef _MSC_VER +# pragma warning(disable: 4774) // TODO: remove this +#endif + static double zero_effect = 0.0; attrib_type at_wdwpyramid = { diff --git a/vs2015-build.bat b/vs2015-build.bat new file mode 100644 index 000000000..82f1f4cd6 --- /dev/null +++ b/vs2015-build.bat @@ -0,0 +1,11 @@ +@ECHO OFF +SET VSVERSION=14 +SET SRCDIR=%CD% +CD .. +SET ERESSEA=%CD% + +CD %SRCDIR% +mkdir build-vs%VSVERSION% +cd build-vs%VSVERSION% +"%ProgramFiles(x86)%\CMake\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%ProgramFiles(x86)%/Lua/5.1;%ERESSEA%/dependencies-win32" -DCMAKE_MODULE_PATH="%SRCDIR%/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE .. +PAUSE From 6a074fd29486383e285fa2811d46d8d7b793c882 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 27 Sep 2015 09:33:56 +0200 Subject: [PATCH 16/17] only disable MSVC2015 warnings in MSVC2015, do not break confuse compilers. --- src/platform.h | 2 ++ src/report.c | 2 +- src/reports.c | 2 +- src/spells.c | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/platform.h b/src/platform.h index 8e207fae2..77a767875 100644 --- a/src/platform.h +++ b/src/platform.h @@ -34,6 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # undef MOUSE_MOVED # define STDIO_CP 1252 /* log.c, convert to console character set */ # pragma warning (disable: 4201 4214 4514 4115 4711) +#if _MSC_VER >= 1900 # pragma warning(disable: 4710) /* warning C4710: function not inlined */ # pragma warning(disable: 4456) @@ -42,6 +43,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* warning C4457: declaration of hides function parameter */ # pragma warning(disable: 4459) /* warning C4459: declaration of hides global declaration */ +#endif # pragma warning(disable: 4056) /* warning C4056: overflow in floating point constant arithmetic */ # pragma warning(disable: 4201) diff --git a/src/report.c b/src/report.c index 254da710e..aa9b9addd 100644 --- a/src/report.c +++ b/src/report.c @@ -96,7 +96,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#ifdef _MSC_VER +#if defined(_MSC_VER) && _MSC_VER >= 1900 # pragma warning(disable: 4774) // TODO: remove this #endif diff --git a/src/reports.c b/src/reports.c index 5f547b6ed..bf365ab6c 100644 --- a/src/reports.c +++ b/src/reports.c @@ -73,7 +73,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "move.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) && _MSC_VER >= 1900 # pragma warning(disable: 4774) // TODO: remove this #endif diff --git a/src/spells.c b/src/spells.c index 033d74024..61c86956d 100644 --- a/src/spells.c +++ b/src/spells.c @@ -101,7 +101,7 @@ #include /* ----------------------------------------------------------------------- */ -#ifdef _MSC_VER +#if defined(_MSC_VER) && _MSC_VER >= 1900 # pragma warning(disable: 4774) // TODO: remove this #endif From a3c843f90d2668c15d685abc8fe86ce42d2c4e2b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Oct 2015 14:57:35 +0200 Subject: [PATCH 17/17] clean up after tests update runtests.bat script for windows development in VS2015 --- scripts/tests/common.lua | 2 +- scripts/tests/orders.lua | 2 +- scripts/tests/storage.lua | 1 + tests/runtests.bat | 5 ++++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index fb1a29965..69467dd11 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -45,7 +45,7 @@ function test_flags() eressea.write_game("test.dat") eressea.free_game() eressea.read_game("test.dat") - os.remove('test.dat') + os.remove('data/test.dat') f = get_faction(no) assert_equal(flags, f.flags) end diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua index d9443c9c4..21ecbe644 100644 --- a/scripts/tests/orders.lua +++ b/scripts/tests/orders.lua @@ -104,7 +104,7 @@ function test_process_quit() eressea.write_game('test.dat') eressea.free_game() eressea.read_game('test.dat') - os.remove('test.dat') + os.remove('data/test.dat') assert_equal(nil, _G.get_faction(fno)) end diff --git a/scripts/tests/storage.lua b/scripts/tests/storage.lua index cf496224c..a0e8e780e 100644 --- a/scripts/tests/storage.lua +++ b/scripts/tests/storage.lua @@ -28,4 +28,5 @@ function test_store_unit() store:close() assert_not_nil(u) assert_equal(u:get_item("money"), u.number * 100) + os.remove(filename) end diff --git a/tests/runtests.bat b/tests/runtests.bat index 3bb41c982..94bba0d68 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -1,5 +1,8 @@ @ECHO OFF -SET BUILD=..\build-vs12\eressea\Debug\ +IF EXIST ..\build-vs10 SET BUILD=..\build-vs10\eressea\Debug +IF EXIST ..\build-vs11 SET BUILD=..\build-vs11\eressea\Debug +IF EXIST ..\build-vs12 SET BUILD=..\build-vs12\eressea\Debug +IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\eressea\Debug SET SERVER=%BUILD%\eressea.exe %BUILD%\test_eressea.exe %SERVER% ..\scripts\run-tests.lua