From 400b8f1ffad1fd3d28d7586280b0a6ec9329e357 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 5 Sep 2015 19:25:55 +0200 Subject: [PATCH] add another failing test for bug 1685 add test for forbiddenid (cannot have a unit with id TEMP) --- src/kernel/config.c | 1 + src/kernel/config.test.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/kernel/config.c b/src/kernel/config.c index a63fb092d..b51cf40ee 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -842,6 +842,7 @@ building *largestbuilding(const region * r, cmp_building_cb cmp_gt, extern faction *dfindhash(int i); static const char *forbidden[] = { "t", "te", "tem", "temp", NULL }; +// PEASANT: "b", "ba", "bau", "baue", "p", "pe", "pea", "peas" int forbiddenid(int id) { diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index ef5792bd0..8ed225907 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -53,6 +53,13 @@ static void test_getunit(CuTest *tc) { CuAssertPtrEquals(tc, NULL, u2); free_order(ord); + // bug https://bugs.eressea.de/view.php?id=1685 + ord = create_order(K_GIVE, lang, "##"); + init_order(ord); + CuAssertIntEquals(tc, GET_NOTFOUND, getunit(u->region, u->faction, &u2)); + CuAssertPtrEquals(tc, NULL, u2); + free_order(ord); + ord = create_order(K_GIVE, lang, "TEMP 42"); init_order(ord); CuAssertIntEquals(tc, GET_UNIT, getunit(u->region, u->faction, &u2)); @@ -97,9 +104,20 @@ static void test_param_flt(CuTest * tc) CuAssertDblEquals(tc, 42.0, get_param_flt(par, "bar", 0.0), 0.01); } +static void test_forbiddenid(CuTest *tc) { + CuAssertIntEquals(tc, 0, forbiddenid(1)); + CuAssertIntEquals(tc, 1, forbiddenid(0)); + CuAssertIntEquals(tc, 1, forbiddenid(-1)); + CuAssertIntEquals(tc, 1, forbiddenid(atoi36("temp"))); + CuAssertIntEquals(tc, 1, forbiddenid(atoi36("tem"))); + CuAssertIntEquals(tc, 1, forbiddenid(atoi36("te"))); + CuAssertIntEquals(tc, 1, forbiddenid(atoi36("t"))); +} + CuSuite *get_config_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_forbiddenid); SUITE_ADD_TEST(suite, test_getunit); SUITE_ADD_TEST(suite, test_get_set_param); SUITE_ADD_TEST(suite, test_param_int);