test some simple facts about planes

This commit is contained in:
Enno Rehling 2016-04-09 14:26:10 +02:00
parent 45d16ef18f
commit c0acfddb71
6 changed files with 71 additions and 6 deletions

View File

@ -14,6 +14,7 @@ group.test.c
item.test.c
messages.test.c
order.test.c
plane.test.c
pool.test.c
race.test.c
save.test.c

View File

@ -28,6 +28,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <stdlib.h>
#include <assert.h>
#define MAXDEPTH 1024
bool allowed_swim(const region * src, const region * r)
{
if (fval(r->terrain, SWIM_INTO))

View File

@ -22,11 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
#define MAXDEPTH 1024
extern int search[MAXDEPTH][2];
extern int search_len;
extern struct region **path_find(struct region *start,
const struct region *target, int maxlen,
bool(*allowed) (const struct region *, const struct region *));

View File

@ -60,7 +60,6 @@ extern "C" {
struct plane *getplane(const struct region *r);
struct plane *findplane(int x, int y);
void init_planes(void);
int getplaneid(const struct region *r);
struct plane *getplanebyid(int id);
int plane_center_x(const struct plane *pl);

67
src/kernel/plane.test.c Normal file
View File

@ -0,0 +1,67 @@
#include <platform.h>
#include <kernel/config.h>
#include "plane.h"
#include "faction.h"
#include <tests.h>
#include <CuTest.h>
static void test_plane(CuTest *tc) {
struct region *r;
plane *pl;
test_cleanup();
r = test_create_region(0, 0, 0);
CuAssertPtrEquals(tc, 0, findplane(0, 0));
CuAssertPtrEquals(tc, 0, getplane(r));
CuAssertIntEquals(tc, 0, getplaneid(r));
CuAssertPtrEquals(tc, 0, getplanebyid(0));
CuAssertIntEquals(tc, 0, plane_center_x(0));
CuAssertIntEquals(tc, 0, plane_center_y(0));
CuAssertIntEquals(tc, 0, plane_width(0));
CuAssertIntEquals(tc, 0, plane_height(0));
CuAssertPtrEquals(tc, 0, get_homeplane());
pl = create_new_plane(1, "Hell", 4, 8, 40, 80, 15);
r = test_create_region(4, 40, 0);
CuAssertIntEquals(tc, 15, pl->flags);
CuAssertIntEquals(tc, 4, pl->minx);
CuAssertIntEquals(tc, 8, pl->maxx);
CuAssertIntEquals(tc, 40, pl->miny);
CuAssertIntEquals(tc, 80, pl->maxy);
CuAssertPtrEquals(tc, 0, pl->attribs);
CuAssertStrEquals(tc, "Hell", pl->name);
CuAssertPtrEquals(tc, pl, findplane(4, 40));
CuAssertPtrEquals(tc, pl, getplane(r));
CuAssertPtrEquals(tc, pl, getplanebyid(1));
CuAssertIntEquals(tc, 1, getplaneid(r));
CuAssertIntEquals(tc, 6, plane_center_x(pl));
CuAssertIntEquals(tc, 60, plane_center_y(pl));
CuAssertIntEquals(tc, 5, plane_width(pl));
CuAssertIntEquals(tc, 41, plane_height(pl));
}
static void test_origin(CuTest *tc) {
struct faction *f;
int x, y;
test_cleanup();
f = test_create_faction(0);
x = 0;
y = 0;
adjust_coordinates(f, &x, &y, 0);
CuAssertIntEquals(tc, 0, x);
CuAssertIntEquals(tc, 0, y);
faction_setorigin(f, 0, 10, 20);
adjust_coordinates(f, &x, &y, 0);
CuAssertIntEquals(tc, -10, x);
CuAssertIntEquals(tc, -20, y);
test_cleanup();
}
CuSuite *get_plane_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_plane);
SUITE_ADD_TEST(suite, test_origin);
return suite;
}

View File

@ -87,6 +87,7 @@ int RunAllTests(int argc, char *argv[])
/* kernel */
ADD_SUITE(alliance);
ADD_SUITE(command);
ADD_SUITE(plane);
ADD_SUITE(unit);
ADD_SUITE(faction);
ADD_SUITE(group);