forked from github/server
fix allies with null faction (to be resolved later).
This commit is contained in:
parent
f27a77d288
commit
cf110d7788
2 changed files with 52 additions and 36 deletions
|
@ -12,11 +12,13 @@ ally * ally_find(ally *al, const struct faction *f) {
|
||||||
|
|
||||||
ally * ally_add(ally **al_p, struct faction *f) {
|
ally * ally_add(ally **al_p, struct faction *f) {
|
||||||
ally * al;
|
ally * al;
|
||||||
|
if (f) {
|
||||||
while (*al_p) {
|
while (*al_p) {
|
||||||
al = *al_p;
|
al = *al_p;
|
||||||
if (al->faction == f) return al;
|
if (al->faction == f) return al;
|
||||||
al_p = &al->next;
|
al_p = &al->next;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
al = (ally *)malloc(sizeof(ally));
|
al = (ally *)malloc(sizeof(ally));
|
||||||
al->faction = f;
|
al->faction = f;
|
||||||
al->status = 0;
|
al->status = 0;
|
||||||
|
|
|
@ -19,6 +19,20 @@ static void test_ally(CuTest * tc)
|
||||||
CuAssertPtrEquals(tc, 0, ally_find(al, f1));
|
CuAssertPtrEquals(tc, 0, ally_find(al, f1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_ally_null(CuTest * tc)
|
||||||
|
{
|
||||||
|
ally *a1 = 0, *a2 = 0;
|
||||||
|
|
||||||
|
a1 = ally_add(&a1, 0);
|
||||||
|
a2 = ally_add(&a1, 0);
|
||||||
|
CuAssertPtrNotNull(tc, a1);
|
||||||
|
CuAssertPtrNotNull(tc, a2);
|
||||||
|
CuAssertPtrEquals(tc, a2, a1->next);
|
||||||
|
CuAssertPtrEquals(tc, 0, a2->next);
|
||||||
|
free(a1);
|
||||||
|
free(a2);
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_ally_suite(void)
|
CuSuite *get_ally_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
|
Loading…
Reference in a new issue