add missing tests for recent failures.

This commit is contained in:
Enno Rehling 2016-10-23 13:02:53 +02:00
parent a921a6594a
commit 2fbc7a44d5
3 changed files with 57 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include <kernel/save.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <util/rng.h>
#include <util/gamedata.h>
#include <util/message.h>
#include <binarystore.h>
@ -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;
}

View File

@ -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);

View File

@ -8,9 +8,10 @@
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/spell.h>
#include <util/attrib.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/attrib.h>
#include <util/rng.h>
#include <spells/regioncurse.h>
#include <alchemy.h>
#include <laws.h>
@ -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;
}