From f0e255924f0d3d088d5337dca3a8e6f2cb9b440f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 12:41:04 +0200 Subject: [PATCH] add a unit test for add/free prefixes. fix bad free_prefixes call site. --- src/kernel/config.c | 1 - src/laws.c | 2 +- src/prefix.test.c | 20 ++++++++++++++++++++ src/tests.c | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 057c3efc0..f31083130 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1768,7 +1768,6 @@ void free_gamedata(void) free_units(); free_regions(); free_borders(); - free_prefixes(); for (i = 0; i != MAXLOCALES; ++i) { if (defaults[i]) { diff --git a/src/laws.c b/src/laws.c index 7cd77bc96..1ca192f1a 100755 --- a/src/laws.c +++ b/src/laws.c @@ -1469,7 +1469,7 @@ static void init_prefixnames(void) in->next = pnames; in->lang = lang; - if (!exist) { + if (!exist && race_prefixes) { int key; for (key = 0; race_prefixes[key]; ++key) { variant var; diff --git a/src/prefix.test.c b/src/prefix.test.c index 0ee02ec12..44c0d845d 100644 --- a/src/prefix.test.c +++ b/src/prefix.test.c @@ -1,9 +1,29 @@ #include "prefix.h" +#include + +#include #include +static void test_add_prefix(CuTest *tc) { + test_cleanup(); + CuAssertPtrEquals(tc, 0, race_prefixes); + add_raceprefix("sea"); + CuAssertPtrNotNull(tc, race_prefixes); + CuAssertStrEquals(tc, "sea", race_prefixes[0]); + CuAssertPtrEquals(tc, 0, race_prefixes[1]); + add_raceprefix("moon"); + CuAssertStrEquals(tc, "sea", race_prefixes[0]); + CuAssertStrEquals(tc, "moon", race_prefixes[1]); + CuAssertPtrEquals(tc, 0, race_prefixes[2]); + free_prefixes(); + CuAssertPtrEquals(tc, 0, race_prefixes); + test_cleanup(); +} + CuSuite *get_prefix_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_add_prefix); return suite; } \ No newline at end of file diff --git a/src/tests.c b/src/tests.c index cda710ef7..e336c192a 100644 --- a/src/tests.c +++ b/src/tests.c @@ -2,6 +2,7 @@ #include "tests.h" #include "keyword.h" #include "seen.h" +#include "prefix.h" #include #include @@ -84,6 +85,7 @@ void test_cleanup(void) free_spellbooks(); free_gamedata(); free_seen(); + free_prefixes(); mt_clear(); if (!mt_find("missing_message")) { mt_register(mt_new_va("missing_message", "name:string", 0));