2016-08-28 18:37:08 +02:00
|
|
|
#include <platform.h>
|
|
|
|
|
|
|
|
#include "names.h"
|
|
|
|
|
2016-08-28 19:15:00 +02:00
|
|
|
#include <kernel/race.h>
|
2016-08-28 21:27:40 +02:00
|
|
|
#include <kernel/unit.h>
|
2017-02-20 22:07:36 +01:00
|
|
|
#include <kernel/faction.h>
|
2016-08-28 19:08:52 +02:00
|
|
|
#include <util/language.h>
|
2016-08-28 18:37:08 +02:00
|
|
|
#include <util/functions.h>
|
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include "tests.h"
|
|
|
|
|
|
|
|
static void test_names(CuTest * tc)
|
|
|
|
{
|
2016-08-28 21:27:40 +02:00
|
|
|
unit *u;
|
|
|
|
race *rc;
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
2016-08-28 18:37:08 +02:00
|
|
|
register_names();
|
2017-02-20 22:07:36 +01:00
|
|
|
CuAssertPtrNotNull(tc, get_function("name_undead"));
|
|
|
|
CuAssertPtrNotNull(tc, get_function("name_skeleton"));
|
|
|
|
CuAssertPtrNotNull(tc, get_function("name_zombie"));
|
|
|
|
CuAssertPtrNotNull(tc, get_function("name_ghoul"));
|
|
|
|
CuAssertPtrNotNull(tc, get_function("name_dragon"));
|
|
|
|
CuAssertPtrNotNull(tc, get_function("name_youngdragon"));
|
|
|
|
CuAssertPtrNotNull(tc, get_function("name_wyrm"));
|
|
|
|
CuAssertPtrNotNull(tc, get_function("name_dracoid"));
|
2016-08-28 19:08:52 +02:00
|
|
|
default_locale = test_create_locale();
|
2016-08-28 21:27:40 +02:00
|
|
|
rc = test_create_race("undead");
|
2017-02-20 22:07:36 +01:00
|
|
|
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
|
2016-08-28 19:08:52 +02:00
|
|
|
locale_setstring(default_locale, "undead_name_0", "Graue");
|
|
|
|
locale_setstring(default_locale, "undead_postfix_0", "Kobolde");
|
2017-02-20 22:07:36 +01:00
|
|
|
CuAssertPtrNotNull(tc, rc->name_unit);
|
|
|
|
CuAssertTrue(tc, rc->name_unit == (race_func)get_function("name_undead"));
|
|
|
|
name_unit(u);
|
2016-08-28 21:27:40 +02:00
|
|
|
CuAssertStrEquals(tc, "Graue Kobolde", u->_name);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-08-28 18:37:08 +02:00
|
|
|
}
|
|
|
|
|
2016-12-31 20:12:13 +01:00
|
|
|
static void test_monster_names(CuTest *tc) {
|
|
|
|
unit *u;
|
2017-02-20 22:07:36 +01:00
|
|
|
faction *f;
|
2016-12-31 20:12:13 +01:00
|
|
|
race *rc;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
register_names();
|
2016-12-31 20:17:02 +01:00
|
|
|
default_locale = test_create_locale();
|
|
|
|
locale_setstring(default_locale, "race::irongolem", "Eisengolem");
|
|
|
|
locale_setstring(default_locale, "race::irongolem_p", "Eisengolems");
|
2016-12-31 20:12:13 +01:00
|
|
|
rc = test_create_race("irongolem");
|
2017-02-20 22:07:36 +01:00
|
|
|
f = test_create_faction(rc);
|
|
|
|
f->flags |= FFL_NPC;
|
|
|
|
u = test_create_unit(f, test_create_region(0, 0, 0));
|
|
|
|
unit_setname(u, "Hodor");
|
2016-12-31 20:12:13 +01:00
|
|
|
CuAssertPtrNotNull(tc, u->_name);
|
2017-02-20 22:07:36 +01:00
|
|
|
name_unit(u);
|
|
|
|
CuAssertPtrEquals(tc, NULL, u->_name);
|
2016-12-31 20:17:02 +01:00
|
|
|
CuAssertStrEquals(tc, "Eisengolem", unit_getname(u));
|
|
|
|
u->number = 2;
|
|
|
|
CuAssertStrEquals(tc, "Eisengolems", unit_getname(u));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-12-31 20:12:13 +01:00
|
|
|
}
|
|
|
|
|
2016-08-28 18:37:08 +02:00
|
|
|
CuSuite *get_names_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_names);
|
2016-12-31 20:12:13 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_monster_names);
|
2016-08-28 18:37:08 +02:00
|
|
|
return suite;
|
|
|
|
}
|