2012-06-03 22:39:42 +02:00
|
|
|
#include <platform.h>
|
2014-07-06 08:06:51 +02:00
|
|
|
#include <kernel/config.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
#include "economy.h"
|
|
|
|
|
2014-07-06 05:14:11 +02:00
|
|
|
#include <util/message.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
#include <kernel/unit.h>
|
2014-07-06 05:14:11 +02:00
|
|
|
#include <kernel/race.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/building.h>
|
|
|
|
#include <kernel/ship.h>
|
2014-07-06 05:14:11 +02:00
|
|
|
#include <kernel/terrain.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
|
2012-05-31 04:17:08 +02:00
|
|
|
#include <CuTest.h>
|
2012-05-27 17:38:17 +02:00
|
|
|
#include <tests.h>
|
|
|
|
|
|
|
|
static void test_give_control_building(CuTest * tc)
|
|
|
|
{
|
2014-07-06 05:14:11 +02:00
|
|
|
unit *u1, *u2;
|
|
|
|
building *b;
|
|
|
|
struct faction *f;
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
f = test_create_faction(0);
|
|
|
|
r = findregion(0, 0);
|
|
|
|
b = test_create_building(r, 0);
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
u_set_building(u1, b);
|
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
u_set_building(u2, b);
|
|
|
|
CuAssertPtrEquals(tc, u1, building_owner(b));
|
|
|
|
give_control(u1, u2);
|
|
|
|
CuAssertPtrEquals(tc, u2, building_owner(b));
|
|
|
|
test_cleanup();
|
2012-05-27 17:38:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_give_control_ship(CuTest * tc)
|
|
|
|
{
|
2014-07-06 05:14:11 +02:00
|
|
|
unit *u1, *u2;
|
|
|
|
ship *sh;
|
|
|
|
struct faction *f;
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
test_create_world();
|
|
|
|
f = test_create_faction(0);
|
|
|
|
r = findregion(0, 0);
|
|
|
|
sh = test_create_ship(r, 0);
|
|
|
|
u1 = test_create_unit(f, r);
|
|
|
|
u_set_ship(u1, sh);
|
|
|
|
u2 = test_create_unit(f, r);
|
|
|
|
u_set_ship(u2, sh);
|
|
|
|
CuAssertPtrEquals(tc, u1, ship_owner(sh));
|
|
|
|
give_control(u1, u2);
|
|
|
|
CuAssertPtrEquals(tc, u2, ship_owner(sh));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-07-06 06:12:34 +02:00
|
|
|
struct steal {
|
2014-07-06 05:14:11 +02:00
|
|
|
struct unit *u;
|
|
|
|
struct region *r;
|
|
|
|
struct faction *f;
|
2014-07-06 06:12:34 +02:00
|
|
|
};
|
2014-07-06 05:14:11 +02:00
|
|
|
|
2014-07-06 06:12:34 +02:00
|
|
|
static void setup_steal(struct steal *env, terrain_type *ter, race *rc) {
|
|
|
|
env->r = test_create_region(0, 0, ter);
|
|
|
|
env->f = test_create_faction(rc);
|
|
|
|
env->u = test_create_unit(env->f, env->r);
|
2014-07-06 05:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_steal_okay(CuTest * tc) {
|
2014-07-06 06:12:34 +02:00
|
|
|
struct steal env;
|
2014-07-06 05:14:11 +02:00
|
|
|
race *rc;
|
|
|
|
terrain_type *ter;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
ter = test_create_terrain("plain", LAND_REGION);
|
|
|
|
rc = test_create_race("human");
|
|
|
|
rc->flags = 0;
|
2014-07-06 06:12:34 +02:00
|
|
|
setup_steal(&env, ter, rc);
|
|
|
|
CuAssertPtrEquals(tc, 0, check_steal(env.u, 0));
|
2014-07-06 05:14:11 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_steal_nosteal(CuTest * tc) {
|
2014-07-06 06:12:34 +02:00
|
|
|
struct steal env;
|
2014-07-06 05:14:11 +02:00
|
|
|
race *rc;
|
|
|
|
terrain_type *ter;
|
|
|
|
message *msg;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
ter = test_create_terrain("plain", LAND_REGION);
|
|
|
|
rc = test_create_race("human");
|
|
|
|
rc->flags = RCF_NOSTEAL;
|
2014-07-06 06:12:34 +02:00
|
|
|
setup_steal(&env, ter, rc);
|
|
|
|
CuAssertPtrNotNull(tc, msg = check_steal(env.u, 0));
|
2014-07-06 05:14:11 +02:00
|
|
|
msg_release(msg);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_steal_ocean(CuTest * tc) {
|
2014-07-06 06:12:34 +02:00
|
|
|
struct steal env;
|
2014-07-06 05:14:11 +02:00
|
|
|
race *rc;
|
|
|
|
terrain_type *ter;
|
|
|
|
message *msg;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
ter = test_create_terrain("ocean", SEA_REGION);
|
|
|
|
rc = test_create_race("human");
|
2014-07-06 06:12:34 +02:00
|
|
|
setup_steal(&env, ter, rc);
|
|
|
|
CuAssertPtrNotNull(tc, msg = check_steal(env.u, 0));
|
2014-07-06 05:14:11 +02:00
|
|
|
msg_release(msg);
|
|
|
|
test_cleanup();
|
2012-05-27 17:38:17 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 06:12:34 +02:00
|
|
|
struct give {
|
|
|
|
struct unit *src, *dst;
|
|
|
|
struct region *r;
|
2014-07-06 08:06:51 +02:00
|
|
|
struct faction *f1, *f2;
|
2014-07-06 06:12:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void setup_give(struct give *env) {
|
|
|
|
terrain_type *ter = test_create_terrain("plain", LAND_REGION);
|
|
|
|
env->r = test_create_region(0, 0, ter);
|
2014-07-06 08:06:51 +02:00
|
|
|
env->src = test_create_unit(env->f1, env->r);
|
|
|
|
env->dst = test_create_unit(env->f2, env->r);
|
2014-07-06 06:12:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_give_okay(CuTest * tc) {
|
|
|
|
struct give env;
|
2014-07-06 08:06:51 +02:00
|
|
|
struct race * rc;
|
|
|
|
|
2014-07-06 06:12:34 +02:00
|
|
|
test_cleanup();
|
2014-07-06 08:06:51 +02:00
|
|
|
rc = test_create_race("human");
|
|
|
|
env.f2 = env.f1 = test_create_faction(rc);
|
2014-07-06 06:12:34 +02:00
|
|
|
setup_give(&env);
|
|
|
|
|
2014-07-06 08:06:51 +02:00
|
|
|
set_param(&global.parameters, "rules.give", "0");
|
2014-07-06 06:12:34 +02:00
|
|
|
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, 0));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-07-06 08:06:51 +02:00
|
|
|
static void test_give_denied_by_rules(CuTest * tc) {
|
|
|
|
struct give env;
|
|
|
|
struct race * rc;
|
|
|
|
struct message *msg;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
rc = test_create_race("human");
|
|
|
|
env.f1 = test_create_faction(rc);
|
|
|
|
env.f2 = test_create_faction(rc);
|
|
|
|
setup_give(&env);
|
|
|
|
|
|
|
|
set_param(&global.parameters, "rules.give", "0");
|
|
|
|
CuAssertPtrNotNull(tc, msg=check_give(env.src, env.dst, 0));
|
|
|
|
msg_release(msg);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2012-05-27 17:38:17 +02:00
|
|
|
CuSuite *get_economy_suite(void)
|
|
|
|
{
|
2014-07-06 05:14:11 +02:00
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_give_control_building);
|
|
|
|
SUITE_ADD_TEST(suite, test_give_control_ship);
|
|
|
|
SUITE_ADD_TEST(suite, test_steal_okay);
|
|
|
|
SUITE_ADD_TEST(suite, test_steal_ocean);
|
|
|
|
SUITE_ADD_TEST(suite, test_steal_nosteal);
|
2014-07-06 06:12:34 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_give_okay);
|
2014-07-06 08:06:51 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_give_denied_by_rules);
|
2014-07-06 05:14:11 +02:00
|
|
|
return suite;
|
2012-05-27 17:38:17 +02:00
|
|
|
}
|