server/src/kernel/ally.test.c

71 lines
1.6 KiB
C
Raw Normal View History

#include <platform.h>
#include "types.h"
#include "ally.h"
#include <CuTest.h>
#include <tests.h>
static void test_ally(CuTest * tc)
{
struct ally * al = NULL;
struct faction * f;
test_setup();
f = test_create_faction(NULL);
ally_set(&al, f, HELP_GUARD);
CuAssertPtrNotNull(tc, al);
CuAssertIntEquals(tc, HELP_GUARD, ally_get(al, f));
ally_set(&al, f, 0);
2018-10-14 11:48:21 +02:00
CuAssertPtrEquals(tc, NULL, al);
CuAssertIntEquals(tc, 0, ally_get(al, f));
allies_free(al);
test_teardown();
}
2018-10-30 18:45:13 +01:00
static void test_ally_clone(CuTest * tc)
{
struct ally * al = NULL, *ac;
struct faction * f;
test_setup();
f = test_create_faction(NULL);
CuAssertPtrEquals(tc, NULL, ally_clone(NULL));
ally_set(&al, f, HELP_GUARD);
ac = ally_clone(al);
CuAssertPtrNotNull(tc, ac);
CuAssertTrue(tc, al != ac);
CuAssertIntEquals(tc, HELP_GUARD, ally_get(ac, f));
CuAssertIntEquals(tc, HELP_GUARD, ally_get(al, f));
allies_free(al);
allies_free(ac);
test_teardown();
}
static void test_allies(CuTest *tc) {
struct allies * al = NULL;
struct faction * f;
test_setup();
f = test_create_faction(NULL);
CuAssertIntEquals(tc, 0, allies_get(al, f));
allies_set(&al, f, 42);
CuAssertIntEquals(tc, 42, allies_get(al, f));
allies_set(&al, f, 0);
CuAssertIntEquals(tc, 0, allies_get(al, f));
CuAssertPtrEquals(tc, NULL, al);
test_teardown();
}
CuSuite *get_ally_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_ally);
2018-10-30 18:45:13 +01:00
SUITE_ADD_TEST(suite, test_ally_clone);
SUITE_ADD_TEST(suite, test_allies);
return suite;
}