BUG 2367: add a test for set_familiar.

This commit is contained in:
Enno Rehling 2017-10-05 22:13:39 +02:00
parent 02cfde0a49
commit 4452f93009
4 changed files with 53 additions and 27 deletions

View File

@ -287,33 +287,11 @@ static void test_skill_familiar(CuTest *tc) {
test_cleanup();
}
static void test_age_familiar(CuTest *tc) {
unit *mag, *fam;
test_cleanup();
mag = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
fam = test_create_unit(mag->faction, test_create_region(0, 0, 0));
CuAssertPtrEquals(tc, 0, get_familiar(mag));
CuAssertPtrEquals(tc, 0, get_familiar_mage(fam));
CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam));
CuAssertPtrEquals(tc, fam, get_familiar(mag));
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
a_age(&fam->attribs, fam);
a_age(&mag->attribs, mag);
CuAssertPtrEquals(tc, fam, get_familiar(mag));
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
set_number(fam, 0);
a_age(&mag->attribs, mag);
CuAssertPtrEquals(tc, 0, get_familiar(mag));
test_cleanup();
}
static void test_inside_building(CuTest *tc) {
unit *u;
building *b;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
b = test_create_building(u->region, 0);
@ -631,7 +609,6 @@ CuSuite *get_unit_suite(void)
SUITE_ADD_TEST(suite, test_skillmod);
SUITE_ADD_TEST(suite, test_skill_hunger);
SUITE_ADD_TEST(suite, test_skill_familiar);
SUITE_ADD_TEST(suite, test_age_familiar);
SUITE_ADD_TEST(suite, test_inside_building);
SUITE_ADD_TEST(suite, test_skills);
SUITE_ADD_TEST(suite, test_limited_skills);

View File

@ -2192,18 +2192,20 @@ void set_familiar(unit * mage, unit * familiar)
a = a_add(&mage->attribs, a_new(&at_familiar));
a->data.v = familiar;
}
else
else {
assert(!a->data.v || a->data.v == familiar);
/* TODO: Diese Attribute beim Tod des Familiars entfernen: */
}
/* TODO: Diese Attribute beim Tod des Familiars entfernen: */
a = a_find(familiar->attribs, &at_familiarmage);
if (a == NULL) {
a = a_add(&familiar->attribs, a_new(&at_familiarmage));
a->data.v = mage;
}
else
else {
assert(!a->data.v || a->data.v == mage);
}
}
void remove_familiar(unit * mage)
{

View File

@ -477,6 +477,52 @@ static void test_illusioncastle(CuTest *tc)
test_cleanup();
}
static void test_familiar_set(CuTest *tc) {
unit *mag, *fam;
test_setup();
mag = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
fam = test_create_unit(mag->faction, test_create_region(0, 0, 0));
CuAssertPtrEquals(tc, NULL, get_familiar(mag));
CuAssertPtrEquals(tc, NULL, get_familiar_mage(fam));
CuAssertPtrEquals(tc, NULL, a_find(mag->attribs, &at_skillmod));
set_familiar(mag, fam);
CuAssertPtrEquals(tc, fam, get_familiar(mag));
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
CuAssertPtrNotNull(tc, a_find(mag->attribs, &at_skillmod));
test_cleanup();
}
static void test_familiar_age(CuTest *tc) {
unit *mag, *fam;
test_setup();
mag = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
fam = test_create_unit(mag->faction, test_create_region(0, 0, 0));
set_familiar(mag, fam);
CuAssertPtrEquals(tc, fam, get_familiar(mag));
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
a_age(&fam->attribs, fam);
a_age(&mag->attribs, mag);
CuAssertPtrEquals(tc, fam, get_familiar(mag));
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
set_number(fam, 0);
a_age(&mag->attribs, mag);
CuAssertPtrEquals(tc, NULL, get_familiar(mag));
test_cleanup();
}
CuSuite *get_familiar_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_familiar_set);
SUITE_ADD_TEST(suite, test_familiar_age);
return suite;
}
CuSuite *get_magic_suite(void)
{
CuSuite *suite = CuSuiteNew();

View File

@ -101,6 +101,7 @@ int RunAllTests(int argc, char *argv[])
ADD_SUITE(pool);
ADD_SUITE(curse);
ADD_SUITE(equipment);
ADD_SUITE(familiar);
ADD_SUITE(item);
ADD_SUITE(magic);
ADD_SUITE(alchemy);