From 2fbc7a44d59f6be5fb0d329fceb3881b1cdf63e0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 23 Oct 2016 13:02:53 +0200 Subject: [PATCH] add missing tests for recent failures. --- src/kernel/curse.test.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/kernel/unit.c | 2 +- src/kernel/unit.test.c | 17 ++++++++++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index d7c86b9b0..0ca4510d9 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -175,6 +176,43 @@ static void test_curse_cache(CuTest *tc) test_cleanup(); } +static void test_curse_ids(CuTest *tc) { + const curse_type ct_dummy = { "dummy", CURSETYP_NORM, 0, M_SUMEFFECT, NULL }; + curse *c1, *c2; + attrib *a1 = 0, *a2 = 0; + + test_setup(); + rng_init(0); + c1 = create_curse(NULL, &a1, &ct_dummy, 1, 1, 1, 1); + rng_init(0); + c2 = create_curse(NULL, &a2, &ct_dummy, 1, 1, 1, 1); + CuAssertTrue(tc, c1->no != c2->no); + a_remove(&a1, a1); + a_remove(&a2, a2); + test_cleanup(); +} + +static void test_curse_flags(CuTest *tc) { + const curse_type ct_dummy = { "dummy", CURSETYP_NORM, 0, M_SUMEFFECT, NULL }; + curse *c1, *c2; + unit *u; + + test_setup(); + u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + c1 = create_curse(u, &u->attribs, &ct_dummy, 1, 1, 1, 0); + CuAssertPtrEquals(tc, u, c1->magician); + CuAssertIntEquals(tc, 1, (int)c1->effect); + CuAssertIntEquals(tc, 1, (int)c1->vigour); + CuAssertIntEquals(tc, 1, c1->duration); + c2 = create_curse(u, &u->attribs, &ct_dummy, 1, 1, 1, 0); + CuAssertPtrEquals(tc, c1, c2); + CuAssertPtrEquals(tc, u, c1->magician); + CuAssertIntEquals(tc, 2, (int)c1->effect); + CuAssertIntEquals(tc, 1, (int)c1->vigour); + CuAssertIntEquals(tc, 1, c1->duration); + test_cleanup(); +} + CuSuite *get_curse_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -186,5 +224,7 @@ CuSuite *get_curse_suite(void) SUITE_ADD_TEST(suite, test_bad_dreams); SUITE_ADD_TEST(suite, test_memstream); SUITE_ADD_TEST(suite, test_write_flag); + SUITE_ADD_TEST(suite, test_curse_flags); + SUITE_ADD_TEST(suite, test_curse_ids); return suite; } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 201153663..ad8377254 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1717,7 +1717,7 @@ void renumber_unit(unit *u, int no) { uunhash(u); if (!ualias(u)) { attrib *a = a_add(&u->attribs, a_new(&at_alias)); - a->data.i = -u->no; + a->data.i = -u->no; // TODO: why is the alias negative? confusing! } u->no = no; uhash(u); diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 054a45652..c4b1f46ed 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -8,9 +8,10 @@ #include #include #include +#include #include #include -#include +#include #include #include #include @@ -454,6 +455,19 @@ static void test_remove_unit(CuTest *tc) { test_cleanup(); } +static void test_renumber_unit(CuTest *tc) { + unit *u1, *u2; + test_setup(); + u1 = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + u2 = test_create_unit(u1->faction, u1->region); + rng_init(0); + renumber_unit(u1, 0); + rng_init(0); + renumber_unit(u2, 0); + CuAssertTrue(tc, u1->no != u2->no); + test_cleanup(); +} + CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -476,5 +490,6 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_age_familiar); SUITE_ADD_TEST(suite, test_inside_building); SUITE_ADD_TEST(suite, test_limited_skills); + SUITE_ADD_TEST(suite, test_renumber_unit); return suite; }