2015-09-08 10:00:51 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include "seen.h"
|
2015-09-08 16:28:47 +02:00
|
|
|
#include "reports.h"
|
2015-09-09 09:04:59 +02:00
|
|
|
#include "travelthru.h"
|
2015-09-08 10:00:51 +02:00
|
|
|
|
|
|
|
#include <kernel/region.h>
|
2015-09-09 09:04:59 +02:00
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/faction.h>
|
2015-09-08 10:00:51 +02:00
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
|
2015-09-09 09:04:59 +02:00
|
|
|
static void setup_seen(int x, int y) {
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
for (dir = 0; dir != MAXDIRECTIONS; ++dir) {
|
|
|
|
test_create_region(x+delta_x[dir], y+delta_y[dir], 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-09 11:08:33 +02:00
|
|
|
static void test_add_seen(CuTest *tc) {
|
|
|
|
region *r;
|
|
|
|
seen_region **seen, *sr;
|
|
|
|
|
2016-09-04 21:15:22 +02:00
|
|
|
test_setup();
|
2015-09-09 11:08:33 +02:00
|
|
|
seen = seen_init();
|
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
sr = add_seen(seen, r, see_travel, false);
|
|
|
|
CuAssertPtrEquals(tc, r, sr->r);
|
|
|
|
CuAssertIntEquals(tc, see_travel, sr->mode);
|
|
|
|
CuAssertIntEquals(tc, false, sr->disbelieves);
|
|
|
|
CuAssertPtrEquals(tc, 0, sr->next);
|
|
|
|
CuAssertPtrEquals(tc, 0, sr->nextHash);
|
|
|
|
CuAssertPtrEquals(tc, sr, find_seen(seen, r));
|
|
|
|
sr = add_seen(seen, r, see_neighbour, true);
|
|
|
|
CuAssertIntEquals(tc, true, sr->disbelieves);
|
|
|
|
CuAssertIntEquals(tc, see_travel, sr->mode);
|
|
|
|
sr = add_seen(seen, r, see_unit, false);
|
|
|
|
CuAssertIntEquals(tc, true, sr->disbelieves);
|
|
|
|
CuAssertIntEquals(tc, see_unit, sr->mode);
|
|
|
|
seen_done(seen);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_faction_add_seen(CuTest *tc) {
|
|
|
|
faction *f;
|
|
|
|
seen_region *sr;
|
|
|
|
|
2016-09-04 21:15:22 +02:00
|
|
|
test_setup();
|
2015-09-09 11:08:33 +02:00
|
|
|
f = test_create_faction(0);
|
|
|
|
f->seen = seen_init();
|
2015-09-09 11:24:11 +02:00
|
|
|
test_create_region(0, 0, 0);
|
|
|
|
test_create_region(0, 1, 0);
|
2015-09-09 11:22:35 +02:00
|
|
|
sr = faction_add_seen(f, regions, see_unit);
|
2015-09-09 11:08:33 +02:00
|
|
|
CuAssertIntEquals(tc, false, sr->disbelieves);
|
|
|
|
CuAssertPtrEquals(tc, regions, f->first);
|
2015-09-09 11:22:35 +02:00
|
|
|
CuAssertPtrEquals(tc, regions, f->last);
|
2015-09-09 11:08:33 +02:00
|
|
|
seen_done(f->seen);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-09-09 09:04:59 +02:00
|
|
|
static void test_prepare_seen(CuTest *tc) {
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
unit *u;
|
|
|
|
|
2016-09-04 21:15:22 +02:00
|
|
|
test_setup();
|
2015-09-09 09:04:59 +02:00
|
|
|
f = test_create_faction(0);
|
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
u = test_create_unit(f, r);
|
|
|
|
f->seen = seen_init();
|
2015-09-09 11:08:33 +02:00
|
|
|
faction_add_seen(f, r, see_unit);
|
2015-09-09 09:04:59 +02:00
|
|
|
setup_seen(0, 0);
|
|
|
|
r = test_create_region(2, 2, 0);
|
|
|
|
setup_seen(2, 2);
|
|
|
|
travelthru_add(r, u);
|
|
|
|
|
|
|
|
init_reports();
|
|
|
|
prepare_seen(f);
|
|
|
|
CuAssertPtrEquals(tc, regions, f->first);
|
|
|
|
CuAssertPtrEquals(tc, 0, f->last);
|
|
|
|
seen_done(f->seen);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_seen_travelthru(CuTest *tc) {
|
|
|
|
seen_region *sr;
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
unit *u;
|
|
|
|
|
2016-09-04 21:15:22 +02:00
|
|
|
test_setup();
|
2015-09-09 09:04:59 +02:00
|
|
|
setup_seen(0, 0);
|
|
|
|
f = test_create_faction(0);
|
2016-09-08 09:06:02 +02:00
|
|
|
u = test_create_unit(f, test_create_region(0, 0, 0));
|
|
|
|
r = test_create_region(0, 1, 0);
|
2015-09-09 09:04:59 +02:00
|
|
|
travelthru_add(r, u);
|
|
|
|
init_reports();
|
|
|
|
view_default(f->seen, r, f);
|
|
|
|
get_seen_interval(f->seen, &f->first, &f->last);
|
|
|
|
link_seen(f->seen, f->first, f->last);
|
|
|
|
CuAssertPtrEquals(tc, regions, f->first);
|
|
|
|
CuAssertPtrEquals(tc, 0, f->last);
|
|
|
|
sr = find_seen(f->seen, regions);
|
|
|
|
CuAssertPtrEquals(tc, regions, sr->r);
|
|
|
|
CuAssertIntEquals(tc, see_neighbour, sr->mode);
|
|
|
|
sr = find_seen(f->seen, r);
|
|
|
|
CuAssertPtrEquals(tc, r, sr->r);
|
|
|
|
CuAssertIntEquals(tc, see_travel, sr->mode);
|
2015-10-13 16:05:32 +02:00
|
|
|
seen_done(f->seen);
|
2015-09-09 09:04:59 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-09-08 10:00:51 +02:00
|
|
|
static void test_seen_region(CuTest *tc) {
|
2015-09-08 16:28:47 +02:00
|
|
|
seen_region **seen, *sr;
|
|
|
|
region *r;
|
|
|
|
|
2016-09-04 21:15:22 +02:00
|
|
|
test_setup();
|
2015-09-09 09:04:59 +02:00
|
|
|
setup_seen(0, 0);
|
2015-09-08 16:28:47 +02:00
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
seen = seen_init();
|
2015-09-09 09:04:59 +02:00
|
|
|
add_seen(seen, r, see_unit, false);
|
2015-09-08 16:28:47 +02:00
|
|
|
sr = find_seen(seen, r);
|
|
|
|
CuAssertPtrEquals(tc, r, sr->r);
|
|
|
|
seen_done(seen);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_seen_interval_backward(CuTest *tc) {
|
2015-09-08 10:17:01 +02:00
|
|
|
region *r, *first, *last;
|
2015-09-09 09:04:59 +02:00
|
|
|
seen_region **seen;
|
2015-09-08 10:00:51 +02:00
|
|
|
|
2016-09-04 21:15:22 +02:00
|
|
|
test_setup();
|
2015-09-08 10:00:51 +02:00
|
|
|
r = test_create_region(0, 0, 0);
|
2015-09-09 09:04:59 +02:00
|
|
|
setup_seen(0, 0);
|
2015-09-08 10:00:51 +02:00
|
|
|
seen = seen_init();
|
2015-09-09 09:04:59 +02:00
|
|
|
add_seen(seen, r, see_unit, false);
|
2015-09-08 16:28:47 +02:00
|
|
|
view_default(seen, r, 0);
|
2015-09-08 10:17:01 +02:00
|
|
|
first = r;
|
|
|
|
last = 0;
|
|
|
|
get_seen_interval(seen, &first, &last);
|
2015-09-08 16:28:47 +02:00
|
|
|
CuAssertPtrEquals(tc, regions, first);
|
2015-09-08 10:17:01 +02:00
|
|
|
CuAssertPtrEquals(tc, 0, last);
|
2015-10-13 16:05:32 +02:00
|
|
|
seen_done(seen);
|
2015-09-08 16:28:47 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_seen_interval_forward(CuTest *tc) {
|
|
|
|
region *r, *first, *last;
|
2015-09-09 09:04:59 +02:00
|
|
|
seen_region **seen;
|
2015-09-08 16:28:47 +02:00
|
|
|
|
2016-09-04 21:15:22 +02:00
|
|
|
test_setup();
|
2015-09-09 09:04:59 +02:00
|
|
|
setup_seen(0, 0);
|
2015-09-08 16:28:47 +02:00
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
seen = seen_init();
|
|
|
|
add_seen(seen, r, see_unit, true);
|
|
|
|
view_default(seen, r, 0);
|
|
|
|
first = r;
|
|
|
|
last = 0;
|
|
|
|
get_seen_interval(seen, &first, &last);
|
|
|
|
CuAssertPtrEquals(tc, regions, first);
|
|
|
|
CuAssertPtrEquals(tc, 0, last);
|
2015-10-13 16:05:32 +02:00
|
|
|
seen_done(seen);
|
2015-09-08 16:28:47 +02:00
|
|
|
test_cleanup();
|
2015-09-08 10:00:51 +02:00
|
|
|
}
|
|
|
|
|
2015-09-09 09:38:57 +02:00
|
|
|
static void cb_testmap(seen_region *sr, void *cbdata) {
|
|
|
|
int *ip = (int *)cbdata;
|
|
|
|
*ip += sr->r->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_seenhash_map(CuTest *tc) {
|
|
|
|
region *r;
|
|
|
|
seen_region **seen;
|
|
|
|
int i = 0;
|
|
|
|
|
2016-09-04 21:15:22 +02:00
|
|
|
test_setup();
|
2015-09-09 09:38:57 +02:00
|
|
|
seen = seen_init();
|
|
|
|
r = test_create_region(1, 1, 0);
|
|
|
|
add_seen(seen, r, see_unit, false);
|
|
|
|
r = test_create_region(2, 2, 0);
|
|
|
|
add_seen(seen, r, see_unit, false);
|
|
|
|
seenhash_map(seen, cb_testmap, &i);
|
|
|
|
CuAssertIntEquals(tc, 3, i);
|
|
|
|
seen_done(seen);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-09-08 10:00:51 +02:00
|
|
|
CuSuite *get_seen_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
2015-09-09 09:04:59 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_prepare_seen);
|
|
|
|
SUITE_ADD_TEST(suite, test_seen_travelthru);
|
2016-09-08 09:06:02 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_add_seen);
|
|
|
|
SUITE_ADD_TEST(suite, test_faction_add_seen);
|
2015-09-08 10:00:51 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_seen_region);
|
2015-09-08 16:28:47 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_seen_interval_backward);
|
|
|
|
SUITE_ADD_TEST(suite, test_seen_interval_forward);
|
2015-09-09 09:38:57 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_seenhash_map);
|
2015-09-08 10:00:51 +02:00
|
|
|
return suite;
|
|
|
|
}
|