2016-11-01 17:25:52 +01:00
|
|
|
#include <platform.h>
|
2015-08-19 14:37:51 +02:00
|
|
|
#include <kernel/config.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/faction.h>
|
2018-09-29 11:37:17 +02:00
|
|
|
#include <kernel/attrib.h>
|
2017-12-29 06:13:28 +01:00
|
|
|
#include <util/macros.h>
|
2015-08-19 14:37:51 +02:00
|
|
|
|
|
|
|
#include "travelthru.h"
|
|
|
|
#include "reports.h"
|
|
|
|
#include "tests.h"
|
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
|
|
|
|
struct attrib;
|
|
|
|
|
2015-08-19 14:50:19 +02:00
|
|
|
static void count_travelers(region *r, unit *u, void *cbdata) {
|
2015-08-19 14:37:51 +02:00
|
|
|
int *n = (int *)cbdata;
|
2017-01-10 16:31:05 +01:00
|
|
|
UNUSED_ARG(r);
|
2015-08-19 14:37:51 +02:00
|
|
|
*n += u->number;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct travel_fixture {
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
} travel_fixture;
|
|
|
|
|
|
|
|
static void setup_travelthru(travel_fixture *fix, int nunits) {
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
|
2018-01-14 09:38:26 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2015-08-19 14:37:51 +02:00
|
|
|
while (r->attribs) {
|
|
|
|
a_remove(&r->attribs, r->attribs);
|
|
|
|
}
|
2020-11-14 17:12:36 +01:00
|
|
|
f = test_create_faction();
|
2015-08-19 14:37:51 +02:00
|
|
|
while (nunits--) {
|
2018-01-14 09:58:45 +01:00
|
|
|
unit *u = test_create_unit(f, test_create_region(1, 0, NULL));
|
2015-08-19 14:37:51 +02:00
|
|
|
travelthru_add(r, u);
|
|
|
|
}
|
|
|
|
fix->r = r;
|
|
|
|
fix->f = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_travelthru_count(CuTest *tc) {
|
|
|
|
travel_fixture fix;
|
2017-12-27 19:58:39 +01:00
|
|
|
|
|
|
|
test_setup();
|
2015-08-19 14:37:51 +02:00
|
|
|
setup_travelthru(&fix, 0);
|
|
|
|
CuAssertIntEquals(tc, 0, count_travelthru(fix.r, fix.f));
|
|
|
|
|
|
|
|
setup_travelthru(&fix, 1);
|
|
|
|
CuAssertIntEquals(tc, 1, count_travelthru(fix.r, fix.f));
|
|
|
|
|
|
|
|
setup_travelthru(&fix, 2);
|
|
|
|
CuAssertIntEquals(tc, 2, count_travelthru(fix.r, fix.f));
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-19 14:37:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_travelthru_map(CuTest *tc) {
|
|
|
|
int n = 0;
|
|
|
|
travel_fixture fix;
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
2015-08-19 14:37:51 +02:00
|
|
|
setup_travelthru(&fix, 0);
|
|
|
|
travelthru_map(fix.r, count_travelers, &n);
|
|
|
|
CuAssertIntEquals(tc, 0, n);
|
|
|
|
|
|
|
|
setup_travelthru(&fix, 1);
|
|
|
|
travelthru_map(fix.r, count_travelers, &n);
|
|
|
|
CuAssertIntEquals(tc, 1, n);
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2015-08-19 14:37:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_travelthru_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_travelthru_count);
|
|
|
|
SUITE_ADD_TEST(suite, test_travelthru_map);
|
|
|
|
return suite;
|
|
|
|
}
|