From f08640453ffde7680607c641f1131efc659f20e3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 10 Nov 2017 17:50:19 +0100 Subject: [PATCH 1/6] fix small typo --- scripts/run-turn.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index 83d4045ac..34c1ea4fb 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -29,7 +29,7 @@ local function dbupdate() update_scores() if config.dbname then dbname = config.basepath..'/'..config.dbname - edb = db.open(dbame) + edb = db.open(dbname) if edb~=nil then edb:update_factions() edb:update_scores() From 4a73db1f676b62a6cb01460ddc618a839be2c2c5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Nov 2017 14:59:44 +0100 Subject: [PATCH 2/6] add a test that proves bug 2384 exists. --- src/laws.test.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/laws.test.c b/src/laws.test.c index 787f69715..5e23eded1 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1009,6 +1009,34 @@ static void test_name_ship(CuTest *tc) { test_cleanup(); } +static void test_name_cmd_2384(CuTest *tc) { + unit *uo, *u, *ux; + faction *f; + + test_setup(); + uo = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + uo->ship = test_create_ship(uo->region, 0); + + f = test_create_faction(NULL); + ux = test_create_unit(f, test_create_region(0, 0, NULL)); + u_set_ship(ux, uo->ship); + u = test_create_unit(f, test_create_region(0, 0, NULL)); + u_set_ship(u, uo->ship); + u->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_SHIP])); + + ship_set_owner(uo); + name_cmd(u, u->thisorder); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error12")); + test_clear_messages(f); + + ship_set_owner(ux); + name_cmd(u, u->thisorder); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error12")); + CuAssertStrEquals(tc, "Hodor", u->ship->name); + + test_cleanup(); +} + static void test_long_order_normal(CuTest *tc) { /* TODO: write more tests */ unit *u; @@ -1748,6 +1776,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_nmr_warnings); SUITE_ADD_TEST(suite, test_ally_cmd); SUITE_ADD_TEST(suite, test_name_cmd); + SUITE_ADD_TEST(suite, test_name_cmd_2384); SUITE_ADD_TEST(suite, test_name_cmd_2274); SUITE_ADD_TEST(suite, test_ally_cmd_errors); SUITE_ADD_TEST(suite, test_long_order_normal); From 2703b01adefb6da96b66226b74bb830bf636e301 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Nov 2017 15:01:58 +0100 Subject: [PATCH 3/6] units can rename the ship they are on if their faction owns it. this fixes bug 2384. --- src/laws.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/laws.c b/src/laws.c index f2460122d..ef24cadaa 100644 --- a/src/laws.c +++ b/src/laws.c @@ -1817,11 +1817,13 @@ int name_cmd(struct unit *u, struct order *ord) s = &sh->name; } else { + unit *uo; if (!u->ship) { cmistake(u, ord, 144, MSG_PRODUCE); break; } - if (ship_owner(u->ship) != u) { + uo = ship_owner(u->ship); + if (uo->faction != u->faction) { cmistake(u, ord, 12, MSG_PRODUCE); break; } From db3feeedcce90bb877a30643ae532ebee230638b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Nov 2017 15:05:17 +0100 Subject: [PATCH 4/6] combine ship naming tests. --- src/laws.test.c | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 5e23eded1..188bbef9a 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -987,29 +987,6 @@ static void test_name_building(CuTest *tc) { } static void test_name_ship(CuTest *tc) { - unit *u; - faction *f; - order *ord; - - u = setup_name_cmd(); - f = u->faction; - u->ship = test_create_ship(u->region, 0); - - ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_SHIP])); - name_cmd(u, ord); - CuAssertStrEquals(tc, "Hodor", u->ship->name); - free_order(ord); - - ord = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_SHIP])); - name_cmd(u, ord); - CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error84")); - CuAssertStrEquals(tc, "Hodor", u->ship->name); - free_order(ord); - - test_cleanup(); -} - -static void test_name_cmd_2384(CuTest *tc) { unit *uo, *u, *ux; faction *f; @@ -1034,6 +1011,13 @@ static void test_name_cmd_2384(CuTest *tc) { CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error12")); CuAssertStrEquals(tc, "Hodor", u->ship->name); + test_clear_messages(f); + free_order(u->thisorder); + u->thisorder = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_SHIP])); + name_cmd(u, u->thisorder); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error84")); + CuAssertStrEquals(tc, "Hodor", u->ship->name); + test_cleanup(); } @@ -1776,8 +1760,11 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_nmr_warnings); SUITE_ADD_TEST(suite, test_ally_cmd); SUITE_ADD_TEST(suite, test_name_cmd); - SUITE_ADD_TEST(suite, test_name_cmd_2384); SUITE_ADD_TEST(suite, test_name_cmd_2274); + SUITE_ADD_TEST(suite, test_name_unit); + SUITE_ADD_TEST(suite, test_name_region); + SUITE_ADD_TEST(suite, test_name_building); + SUITE_ADD_TEST(suite, test_name_ship); SUITE_ADD_TEST(suite, test_ally_cmd_errors); SUITE_ADD_TEST(suite, test_long_order_normal); SUITE_ADD_TEST(suite, test_long_order_none); @@ -1827,10 +1814,6 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_mail_region_no_msg); SUITE_ADD_TEST(suite, test_mail_faction_no_target); SUITE_ADD_TEST(suite, test_luck_message); - SUITE_ADD_TEST(suite, test_name_unit); - SUITE_ADD_TEST(suite, test_name_region); - SUITE_ADD_TEST(suite, test_name_building); - SUITE_ADD_TEST(suite, test_name_ship); SUITE_ADD_TEST(suite, test_show_without_item); SUITE_ADD_TEST(suite, test_show_race); SUITE_ADD_TEST(suite, test_show_both); From ac8ca5f728d1560421c267152adfcaacdbc5b900 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Nov 2017 15:09:57 +0100 Subject: [PATCH 5/6] Also test that I can rename a ship that I myself own, of course. --- src/laws.test.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 188bbef9a..009985301 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -990,15 +990,14 @@ static void test_name_ship(CuTest *tc) { unit *uo, *u, *ux; faction *f; - test_setup(); + u = setup_name_cmd(); + u->ship = test_create_ship(u->region, 0); + f = u->faction; uo = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); - uo->ship = test_create_ship(uo->region, 0); - - f = test_create_faction(NULL); + u_set_ship(uo, u->ship); ux = test_create_unit(f, test_create_region(0, 0, NULL)); - u_set_ship(ux, uo->ship); - u = test_create_unit(f, test_create_region(0, 0, NULL)); - u_set_ship(u, uo->ship); + u_set_ship(ux, u->ship); + u->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_SHIP])); ship_set_owner(uo); @@ -1006,6 +1005,11 @@ static void test_name_ship(CuTest *tc) { CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error12")); test_clear_messages(f); + ship_set_owner(u); + name_cmd(u, u->thisorder); + CuAssertStrEquals(tc, "Hodor", u->ship->name); + + ship_setname(u->ship, "Titanic"); ship_set_owner(ux); name_cmd(u, u->thisorder); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error12")); From dae2ca2b5bf84d606c94a4ea05662c4eecdca83c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 12 Nov 2017 15:12:45 +0100 Subject: [PATCH 6/6] buildings should have all the same name-tests as ships. --- src/laws.test.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 009985301..90c29d93d 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -956,27 +956,40 @@ static void test_name_region(CuTest *tc) { } static void test_name_building(CuTest *tc) { - unit *u; + unit *uo, *u, *ux; faction *f; - order *ord; u = setup_name_cmd(); - f = u->faction; - - ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_BUILDING])); - name_cmd(u, ord); - CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error145")); - u->building = test_create_building(u->region, 0); - name_cmd(u, ord); - CuAssertStrEquals(tc, "Hodor", u->building->name); - free_order(ord); + f = u->faction; + uo = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + u_set_building(uo, u->building); + ux = test_create_unit(f, test_create_region(0, 0, NULL)); + u_set_building(ux, u->building); - ord = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_BUILDING])); - name_cmd(u, ord); + u->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_BUILDING])); + + building_set_owner(uo); + name_cmd(u, u->thisorder); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error148")); + test_clear_messages(f); + + building_set_owner(u); + name_cmd(u, u->thisorder); + CuAssertStrEquals(tc, "Hodor", u->building->name); + + building_setname(u->building, "Home"); + building_set_owner(ux); + name_cmd(u, u->thisorder); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error148")); + CuAssertStrEquals(tc, "Hodor", u->building->name); + + test_clear_messages(f); + free_order(u->thisorder); + u->thisorder = create_order(K_NAME, f->locale, LOC(f->locale, parameters[P_BUILDING])); + name_cmd(u, u->thisorder); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error84")); CuAssertStrEquals(tc, "Hodor", u->building->name); - free_order(ord); /* TODO: test BTF_NAMECHANGE: btype->flags |= BTF_NAMECHANGE;