From fa729ba9726872b06ec9aef337241262005a1cf4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 31 Aug 2016 09:26:48 +0200 Subject: [PATCH 1/7] fix mac build with clang 7.3 --- src/kernel/race.c | 2 +- src/kernel/race.test.c | 9 +++++++++ src/spells.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index be9f2ab68..2c22f6c09 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -155,7 +155,7 @@ static race *rc_find_i(const char *name) const char *rname = name; race *rc = races; - while (rc && !strcmp(rname, rc->_name) == 0) { + while (rc && strcmp(rname, rc->_name) != 0) { rc = rc->next; } if (!rc && strcmp(name, "uruk") == 0) { diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index aa37093d4..e8bbfcf29 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -41,11 +41,20 @@ static void test_rc_defaults(CuTest *tc) { test_cleanup(); } +static void test_rc_find(CuTest *tc) { + race *rc; + test_cleanup(); + rc = test_create_race("hungryhippos"); + CuAssertPtrEquals(tc, rc, (void *)rc_find("hungryhippos")); + test_cleanup(); +} + CuSuite *get_race_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_rc_name); SUITE_ADD_TEST(suite, test_rc_defaults); + SUITE_ADD_TEST(suite, test_rc_find); return suite; } diff --git a/src/spells.c b/src/spells.c index 1da440df2..e455f7395 100644 --- a/src/spells.c +++ b/src/spells.c @@ -5354,7 +5354,7 @@ int sp_leaveastral(castorder * co) u = pa->param[n]->data.u; if (!ucontact(u, mage)) { - if (power > 10 && !pa->param[n]->flag == TARGET_RESISTS + if (power > 10 && !(pa->param[n]->flag == TARGET_RESISTS) && can_survive(u, rt)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "feedback_no_contact_no_resist", "target", u)); From 8aec1c3e7f451f3cddf3f4c54c9d4985db77177f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 16 Oct 2015 12:03:32 +0200 Subject: [PATCH 2/7] narrowing down the memory leak in jsonconf.test.c, by adding a similar test to umlaut.test.c that exhibits the same behavior in a simpler setting. --- src/util/umlaut.test.c | 58 +++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/src/util/umlaut.test.c b/src/util/umlaut.test.c index f9f8f5d15..cc94359b8 100644 --- a/src/util/umlaut.test.c +++ b/src/util/umlaut.test.c @@ -26,9 +26,51 @@ static void test_transliterate(CuTest * tc) CuAssertStrEquals(tc, "h?", buffer); } +static void test_transliterations(CuTest *tc) { + const char * umlauts = "\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f"; /* auml ouml uuml szlig nul */ + void * tokens = 0; + variant id; + int result; + + id.i = 3; + addtoken(&tokens, umlauts, id); + /* transliteration is the real magic */ + result = findtoken(tokens, "AEoeUEss", &id); + CuAssertIntEquals(tc, E_TOK_SUCCESS, result); + CuAssertIntEquals(tc, 3, id.i); + + result = findtoken(tokens, umlauts, &id); + CuAssertIntEquals(tc, E_TOK_SUCCESS, result); + CuAssertIntEquals(tc, 3, id.i); + + freetokens(tokens); +} + +static void test_directions(CuTest * tc) +{ + void * tokens = 0; + variant id; + int result; + + id.i = 1; + addtoken(&tokens, "OSTEN", id); + addtoken(&tokens, "O", id); + + id.i = 2; + addtoken(&tokens, "nw", id); + addtoken(&tokens, "northwest", id); + + result = findtoken(tokens, "ost", &id); + CuAssertIntEquals(tc, E_TOK_SUCCESS, result); + CuAssertIntEquals(tc, 1, id.i); + result = findtoken(tokens, "northw", &id); + CuAssertIntEquals(tc, E_TOK_SUCCESS, result); + CuAssertIntEquals(tc, 2, id.i); + freetokens(tokens); +} + static void test_umlaut(CuTest * tc) { - const char * umlauts = "\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f"; /* auml ouml uuml szlig nul */ void * tokens = 0; variant id; int result; @@ -41,8 +83,7 @@ static void test_umlaut(CuTest * tc) addtoken(&tokens, "herpderp", id); id.i = 2; addtoken(&tokens, "derp", id); - id.i = 3; - addtoken(&tokens, umlauts, id); + addtoken(&tokens, "d", id); /* we can find substrings if they are significant */ result = findtoken(tokens, "herp", &id); @@ -57,15 +98,6 @@ static void test_umlaut(CuTest * tc) CuAssertIntEquals(tc, E_TOK_SUCCESS, findtoken(tokens, "DERP", &id)); CuAssertIntEquals(tc, 2, id.i); - result = findtoken(tokens, umlauts, &id); - CuAssertIntEquals(tc, E_TOK_SUCCESS, result); - CuAssertIntEquals(tc, 3, id.i); - - /* transliteration is the real magic */ - result = findtoken(tokens, "AEoeUEss", &id); - CuAssertIntEquals(tc, E_TOK_SUCCESS, result); - CuAssertIntEquals(tc, 3, id.i); - result = findtoken(tokens, "herp-a-derp", &id); CuAssertIntEquals(tc, E_TOK_NOMATCH, result); @@ -76,6 +108,8 @@ CuSuite *get_umlaut_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_umlaut); + SUITE_ADD_TEST(suite, test_directions); SUITE_ADD_TEST(suite, test_transliterate); + SUITE_ADD_TEST(suite, test_transliterations); return suite; } From 24c877d9742f6a93b67e38725379b2455b2fb476 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 17 Oct 2015 11:10:45 +0200 Subject: [PATCH 3/7] reduce failing test to less code --- src/util/umlaut.test.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/util/umlaut.test.c b/src/util/umlaut.test.c index cc94359b8..577b7059a 100644 --- a/src/util/umlaut.test.c +++ b/src/util/umlaut.test.c @@ -52,17 +52,10 @@ static void test_directions(CuTest * tc) variant id; int result; - id.i = 1; - addtoken(&tokens, "OSTEN", id); - addtoken(&tokens, "O", id); - id.i = 2; addtoken(&tokens, "nw", id); addtoken(&tokens, "northwest", id); - result = findtoken(tokens, "ost", &id); - CuAssertIntEquals(tc, E_TOK_SUCCESS, result); - CuAssertIntEquals(tc, 1, id.i); result = findtoken(tokens, "northw", &id); CuAssertIntEquals(tc, E_TOK_SUCCESS, result); CuAssertIntEquals(tc, 2, id.i); From b321918cd1881aca4f54c88ad5947c5f64fa2f82 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 31 Aug 2016 20:38:20 +0200 Subject: [PATCH 4/7] check and fix destroy_cmd syntax error handling --- src/kernel/build.c | 2 +- src/kernel/build.test.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/kernel/build.c b/src/kernel/build.c index a6e8ff3dc..6bea3e6b4 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -175,7 +175,7 @@ int destroy_cmd(unit * u, struct order *ord) } } - if (isparam(s, u->faction->locale, P_ROAD)) { + if (s && isparam(s, u->faction->locale, P_ROAD)) { destroy_road(u, n, ord); return 0; } diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index b59a09d73..65e651010 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -382,6 +382,18 @@ static void test_build_destroy_road_limit(CuTest *tc) test_cleanup(); } +static void test_build_destroy_cmd(CuTest *tc) { + unit *u; + faction *f; + + test_setup(); + u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0)); + u->thisorder = create_order(K_DESTROY, f->locale, NULL); + CuAssertIntEquals(tc, 138, destroy_cmd(u, u->thisorder)); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error138")); + test_cleanup(); +} + CuSuite *get_build_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -396,6 +408,7 @@ CuSuite *get_build_suite(void) SUITE_ADD_TEST(suite, test_build_building_success); SUITE_ADD_TEST(suite, test_build_building_with_golem); SUITE_ADD_TEST(suite, test_build_building_no_materials); + SUITE_ADD_TEST(suite, test_build_destroy_cmd); SUITE_ADD_TEST(suite, test_build_destroy_road); SUITE_ADD_TEST(suite, test_build_destroy_road_limit); SUITE_ADD_TEST(suite, test_build_destroy_road_guard); From 02374cd4927bfb8af74526c22589c4caca3babfe Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 2 Sep 2016 09:09:55 +0200 Subject: [PATCH 5/7] fix intermittent piracy test. https://bugs.eressea.de/view.php?id=2233 --- scripts/tests/e2/movement.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/tests/e2/movement.lua b/scripts/tests/e2/movement.lua index 706ed9ad2..390af2c48 100644 --- a/scripts/tests/e2/movement.lua +++ b/scripts/tests/e2/movement.lua @@ -4,6 +4,7 @@ module("tests.e2.movement", package.seeall, lunit.testcase) function setup() eressea.free_game() + eressea.settings.set("rules.food.flags", "4") eressea.settings.set("nmr.timeout", "0") eressea.settings.set("NewbieImmunity", "0") end @@ -29,7 +30,9 @@ end process_orders() --- write_reports() + if r2~=u1.region then + write_reports() + end assert_equal(r2, u1.region) -- should pass, but fails!!! end From b725e9676a260ea092d76c0b6800447258e10794 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 2 Sep 2016 09:29:52 +0200 Subject: [PATCH 6/7] simple test for basic unit descriptions --- src/kernel/unit.test.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index dc0484bf7..1af197e15 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -387,10 +387,25 @@ static void test_limited_skills(CuTest *tc) { test_cleanup(); } +static void test_unit_description(CuTest *tc) { + race *rc; + unit *u; + test_setup(); + rc = test_create_race("hodor"); + u = test_create_unit(test_create_faction(rc), test_create_region(0,0,0)); + CuAssertPtrEquals(tc, 0, u->display); + CuAssertStrEquals(tc, 0, u_description(u, u->faction->locale)); + u->display = _strdup("Hodor"); + CuAssertStrEquals(tc, "Hodor", u_description(u, NULL)); + CuAssertStrEquals(tc, "Hodor", u_description(u, u->faction->locale)); + test_cleanup(); +} + CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_scale_number); + SUITE_ADD_TEST(suite, test_unit_description); SUITE_ADD_TEST(suite, test_unit_name); SUITE_ADD_TEST(suite, test_unit_name_from_race); SUITE_ADD_TEST(suite, test_update_monster_name); From 4e323f8120b3a57a1d1e6de0a246a35c38b0a57f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 2 Sep 2016 16:18:45 +0200 Subject: [PATCH 7/7] bugfix #551: do not return a stack buffer that isn't static --- src/names.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/names.c b/src/names.c index e972c8d05..ca013649a 100644 --- a/src/names.c +++ b/src/names.c @@ -49,7 +49,7 @@ static const char *describe_race(const race * rc, const struct locale *lang) { char zText[32]; sprintf(zText, "describe_%s", rc->_name); - return LOC(lang, zText); + return locale_getstring(lang, zText); } static void count_particles(const char *monster, int *num_prefix, int *num_name, int *num_postfix)