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-08 10:00:51 +02:00
|
|
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
|
|
|
|
static void test_seen_region(CuTest *tc) {
|
2015-09-08 16:28:47 +02:00
|
|
|
seen_region **seen, *sr;
|
|
|
|
region *r;
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
|
|
|
region *rn = test_create_region(delta_x[dir], delta_y[dir], 0);
|
|
|
|
}
|
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
seen = seen_init();
|
|
|
|
add_seen(seen, r, see_unit, true);
|
|
|
|
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-08 16:28:47 +02:00
|
|
|
seen_region **seen, *sr;
|
2015-09-08 10:17:01 +02:00
|
|
|
int dir;
|
2015-09-08 10:00:51 +02:00
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
r = test_create_region(0, 0, 0);
|
2015-09-08 10:17:01 +02:00
|
|
|
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
|
|
|
region *rn = test_create_region(delta_x[dir], delta_y[dir], 0);
|
|
|
|
}
|
2015-09-08 10:00:51 +02:00
|
|
|
seen = seen_init();
|
2015-09-08 10:17:01 +02:00
|
|
|
add_seen(seen, r, see_unit, true);
|
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-09-08 16:28:47 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_seen_interval_forward(CuTest *tc) {
|
|
|
|
region *r, *first, *last;
|
|
|
|
seen_region **seen, *sr;
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
|
|
|
region *rn = test_create_region(delta_x[dir], delta_y[dir], 0);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
test_cleanup();
|
2015-09-08 10:00:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_seen_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
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-08 10:00:51 +02:00
|
|
|
return suite;
|
|
|
|
}
|