From a7f8ad052db201971e851d820aac9b93bae427c9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 31 Dec 2016 19:56:55 +0100 Subject: [PATCH 1/4] failing test for name_unit. --- src/kernel/unit.test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index c4b1f46ed..752627144 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -468,6 +468,24 @@ static void test_renumber_unit(CuTest *tc) { test_cleanup(); } +static void gen_name(unit *u) +{ + unit_setname(u, "Hodor"); +} + +static void test_name_unit(CuTest *tc) { + race *rc; + unit * u; + + test_setup(); + rc = test_create_race("skeleton"); + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); + rc->generate_name = gen_name; + name_unit(u); + CuAssertStrEquals(tc, "Hodor", unit_getname(u)); + test_cleanup(); +} + CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -491,5 +509,6 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_inside_building); SUITE_ADD_TEST(suite, test_limited_skills); SUITE_ADD_TEST(suite, test_renumber_unit); + SUITE_ADD_TEST(suite, test_name_unit); return suite; } From 4a802be67c7677d00ee2c109a67289effdac6670 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 31 Dec 2016 20:03:50 +0100 Subject: [PATCH 2/4] fix undead name generation. --- src/kernel/race.c | 7 ------- src/kernel/race.h | 1 - src/kernel/unit.c | 12 +++--------- src/names.test.c | 2 +- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index f28c5ed2f..decc3b7bb 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -369,10 +369,3 @@ void register_race_description_function(race_desc_func func, const char *name) { void register_race_name_function(race_name_func func, const char *name) { register_function((pf_generic)func, name); } - -char * race_namegen(const struct race *rc, struct unit *u) { - if (rc->generate_name) { - rc->generate_name(u); - } - return NULL; -} diff --git a/src/kernel/race.h b/src/kernel/race.h index 022d09c86..6673676bd 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -252,7 +252,6 @@ extern "C" { const char *raceprefix(const struct unit *u); void register_race_name_function(race_name_func, const char *); void register_race_description_function(race_desc_func, const char *); - char * race_namegen(const struct race *rc, struct unit *u); #ifdef __cplusplus } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 4aff7d118..f06c4c252 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1480,15 +1480,9 @@ void default_name(const unit *u, char name[], int len) { void name_unit(unit * u) { - if (u_race(u)->generate_name) { - char *gen_name = race_namegen(u_race(u), u); - if (gen_name) { - free(u->_name); - u->_name = gen_name; - } - else { - unit_setname(u, racename(u->faction->locale, u, u_race(u))); - } + const race *rc = u_race(u); + if (rc->generate_name) { + rc->generate_name(u); } else { char name[32]; diff --git a/src/names.test.c b/src/names.test.c index f50937f17..1fc41f340 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -24,7 +24,7 @@ static void test_names(CuTest * tc) locale_setstring(default_locale, "undead_postfix_0", "Kobolde"); CuAssertPtrNotNull(tc, foo = (race_name_func)get_function("nameundead")); rc->generate_name = foo; - race_namegen(rc, u); + rc->generate_name(u); CuAssertStrEquals(tc, "Graue Kobolde", u->_name); CuAssertPtrNotNull(tc, get_function("nameskeleton")); CuAssertPtrNotNull(tc, get_function("namezombie")); From 065439e9676a010994f4e28bb25cb3dd006132ac Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 31 Dec 2016 20:12:13 +0100 Subject: [PATCH 3/4] test that monsters with "namegeneric" hook get a NULL name (WIP) --- src/names.test.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/names.test.c b/src/names.test.c index 1fc41f340..176a12a68 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -36,9 +36,25 @@ static void test_names(CuTest * tc) test_cleanup(); } +static void test_monster_names(CuTest *tc) { + unit *u; + race *rc; + + test_setup(); + register_names(); + rc = test_create_race("irongolem"); + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); + CuAssertPtrNotNull(tc, u->_name); + rc->generate_name = (race_name_func)get_function("namegeneric"); + rc->generate_name(u); + CuAssertPtrEquals(tc, 0, u->_name); + test_cleanup(); +} + CuSuite *get_names_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_names); + SUITE_ADD_TEST(suite, test_monster_names); return suite; } From 5b7cdc4d482f011719303e22a1499c0af1684066 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 31 Dec 2016 20:17:02 +0100 Subject: [PATCH 4/4] monster name pluralization changes with u->number. --- src/names.c | 6 +----- src/names.test.c | 6 ++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/names.c b/src/names.c index 99c21a05e..cf1cdb910 100644 --- a/src/names.c +++ b/src/names.c @@ -221,11 +221,7 @@ const char *silbe3[SIL3] = { static void generic_name(unit * u) { - const char * name = rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL); - name = LOC(u->faction->locale, name); - if (name) { - unit_setname(u, name); - } + unit_setname(u, NULL); } static void dragon_name(unit * u) diff --git a/src/names.test.c b/src/names.test.c index 176a12a68..8109fc2d4 100644 --- a/src/names.test.c +++ b/src/names.test.c @@ -42,12 +42,18 @@ static void test_monster_names(CuTest *tc) { test_setup(); register_names(); + default_locale = test_create_locale(); + locale_setstring(default_locale, "race::irongolem", "Eisengolem"); + locale_setstring(default_locale, "race::irongolem_p", "Eisengolems"); rc = test_create_race("irongolem"); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); CuAssertPtrNotNull(tc, u->_name); rc->generate_name = (race_name_func)get_function("namegeneric"); rc->generate_name(u); CuAssertPtrEquals(tc, 0, u->_name); + CuAssertStrEquals(tc, "Eisengolem", unit_getname(u)); + u->number = 2; + CuAssertStrEquals(tc, "Eisengolems", unit_getname(u)); test_cleanup(); }