2014-11-03 08:33:07 +01:00
|
|
|
#include <platform.h>
|
|
|
|
|
|
|
|
#include "give.h"
|
|
|
|
#include "economy.h"
|
|
|
|
|
2015-06-08 08:56:14 +02:00
|
|
|
#include <kernel/ally.h>
|
2014-11-03 08:33:07 +01:00
|
|
|
#include <kernel/config.h>
|
2015-09-07 14:49:57 +02:00
|
|
|
#include <kernel/faction.h>
|
2014-11-03 08:33:07 +01:00
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/order.h>
|
2015-09-07 14:49:57 +02:00
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/terrain.h>
|
2014-11-03 08:33:07 +01:00
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
|
|
#include <util/base36.h>
|
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/message.h>
|
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
struct give {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct locale * lang;
|
2014-11-03 08:33:07 +01:00
|
|
|
struct unit *src, *dst;
|
|
|
|
struct region *r;
|
|
|
|
struct faction *f1, *f2;
|
|
|
|
struct item_type * itype;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void setup_give(struct give *env) {
|
|
|
|
struct terrain_type *ter = test_create_terrain("plain", LAND_REGION);
|
2015-09-07 14:49:57 +02:00
|
|
|
race *rc;
|
|
|
|
|
|
|
|
assert(env->f1);
|
|
|
|
rc = test_create_race(env->f1->race ? env->f1->race->_name : "humon");
|
2017-07-17 12:33:55 +02:00
|
|
|
rc->ec_flags |= ECF_GIVEPERSON;
|
2015-09-07 14:49:57 +02:00
|
|
|
|
2014-11-03 08:33:07 +01:00
|
|
|
env->r = test_create_region(0, 0, ter);
|
2015-09-07 14:49:57 +02:00
|
|
|
env->src = test_create_unit(env->f1, env->r);
|
2014-12-10 22:14:25 +01:00
|
|
|
env->dst = env->f2 ? test_create_unit(env->f2, env->r) : 0;
|
2014-11-03 08:33:07 +01:00
|
|
|
env->itype = it_get_or_create(rt_get_or_create("money"));
|
|
|
|
env->itype->flags |= ITF_HERB;
|
2015-06-08 08:56:14 +02:00
|
|
|
if (env->f1 && env->f2) {
|
|
|
|
ally * al = ally_add(&env->f2->allies, env->f1);
|
|
|
|
al->status = HELP_GIVE;
|
|
|
|
}
|
2016-11-14 20:01:44 +01:00
|
|
|
if (env->lang) {
|
|
|
|
locale_setstring(env->lang, env->itype->rtype->_name, "SILBER");
|
|
|
|
init_locale(env->lang);
|
|
|
|
env->f1->locale = env->lang;
|
|
|
|
}
|
2014-11-03 08:33:07 +01:00
|
|
|
}
|
|
|
|
|
2015-06-08 08:56:14 +02:00
|
|
|
static void test_give_unit(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2015-06-08 08:56:14 +02:00
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.give.max_men", "0");
|
2015-06-08 09:06:20 +02:00
|
|
|
give_unit(env.src, env.dst, NULL);
|
|
|
|
CuAssertPtrEquals(tc, env.f1, env.src->faction);
|
|
|
|
CuAssertIntEquals(tc, 0, env.f2->newbies);
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.give.max_men", "-1");
|
2015-06-08 08:56:14 +02:00
|
|
|
give_unit(env.src, env.dst, NULL);
|
|
|
|
CuAssertPtrEquals(tc, env.f2, env.src->faction);
|
2015-06-08 09:06:20 +02:00
|
|
|
CuAssertIntEquals(tc, 1, env.f2->newbies);
|
2015-06-08 08:56:14 +02:00
|
|
|
CuAssertPtrEquals(tc, 0, env.f1->units);
|
2017-03-05 11:25:17 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "give_person"));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(env.f2->msgs, "receive_person"));
|
2015-06-08 08:56:14 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2017-03-11 20:03:49 +01:00
|
|
|
static void test_give_unit_limits(CuTest * tc) {
|
|
|
|
struct give env = { 0 };
|
|
|
|
test_setup_ex(tc);
|
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
CuAssertIntEquals(tc, 1, env.f1->num_units);
|
|
|
|
CuAssertIntEquals(tc, 1, env.f2->num_units);
|
|
|
|
config_set("rules.limit.faction", "1");
|
|
|
|
give_unit(env.src, env.dst, NULL);
|
|
|
|
CuAssertPtrEquals(tc, env.f1, env.src->faction);
|
|
|
|
CuAssertIntEquals(tc, 0, env.f2->newbies);
|
|
|
|
CuAssertIntEquals(tc, 1, env.f1->num_units);
|
|
|
|
CuAssertIntEquals(tc, 1, env.f2->num_units);
|
2017-03-11 20:30:17 +01:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "too_many_units_in_faction"));
|
2017-03-11 20:03:49 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_give_unit_to_peasants(CuTest * tc) {
|
|
|
|
struct give env = { 0 };
|
|
|
|
test_setup_ex(tc);
|
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = 0;
|
|
|
|
setup_give(&env);
|
|
|
|
rsetpeasants(env.r, 0);
|
|
|
|
give_unit(env.src, NULL, NULL);
|
|
|
|
CuAssertIntEquals(tc, 0, env.src->number);
|
|
|
|
CuAssertIntEquals(tc, 1, rpeasants(env.r));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_give_unit_to_ocean(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-12-11 08:35:05 +01:00
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = 0;
|
|
|
|
setup_give(&env);
|
|
|
|
env.r->terrain = test_create_terrain("ocean", SEA_REGION);
|
|
|
|
give_unit(env.src, NULL, NULL);
|
|
|
|
CuAssertIntEquals(tc, 0, env.src->number);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-12-10 20:44:33 +01:00
|
|
|
static void test_give_men(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-12-10 20:44:33 +01:00
|
|
|
env.f2 = env.f1 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
2014-12-10 21:17:00 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, give_men(1, env.src, env.dst, NULL));
|
2014-12-10 20:44:33 +01:00
|
|
|
CuAssertIntEquals(tc, 2, env.dst->number);
|
|
|
|
CuAssertIntEquals(tc, 0, env.src->number);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2016-11-13 16:09:58 +01:00
|
|
|
static void test_give_men_magicians(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2016-11-13 16:09:58 +01:00
|
|
|
int p;
|
|
|
|
message * msg;
|
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2016-11-13 16:09:58 +01:00
|
|
|
env.f2 = env.f1 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
set_level(env.src, SK_MAGIC, 1);
|
|
|
|
CuAssertPtrNotNull(tc, msg = give_men(1, env.src, env.dst, NULL));
|
|
|
|
CuAssertStrEquals(tc, "error158", (const char *)msg->parameters[3].v);
|
|
|
|
CuAssertIntEquals(tc, 1, env.dst->number);
|
|
|
|
CuAssertIntEquals(tc, 1, env.src->number);
|
|
|
|
msg_release(msg);
|
|
|
|
|
|
|
|
p = rpeasants(env.r);
|
|
|
|
CuAssertPtrNotNull(tc, msg = disband_men(1, env.dst, NULL));
|
|
|
|
CuAssertStrEquals(tc, "give_person_peasants", (const char *)msg->parameters[0].v);
|
|
|
|
CuAssertIntEquals(tc, 0, env.dst->number);
|
|
|
|
CuAssertIntEquals(tc, p+1, rpeasants(env.r));
|
|
|
|
msg_release(msg);
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-03-13 21:10:39 +01:00
|
|
|
static void test_give_men_limit(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2015-03-13 21:10:39 +01:00
|
|
|
message *msg;
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2015-03-13 21:10:39 +01:00
|
|
|
env.f2 = test_create_faction(0);
|
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.give.max_men", "1");
|
2015-03-13 21:10:39 +01:00
|
|
|
|
|
|
|
/* below the limit, give men, increase newbies counter */
|
|
|
|
usetcontact(env.dst, env.src);
|
|
|
|
msg = give_men(1, env.src, env.dst, NULL);
|
|
|
|
CuAssertStrEquals(tc, "give_person", (const char *)msg->parameters[0].v);
|
|
|
|
CuAssertIntEquals(tc, 2, env.dst->number);
|
|
|
|
CuAssertIntEquals(tc, 0, env.src->number);
|
|
|
|
CuAssertIntEquals(tc, 1, env.f2->newbies);
|
|
|
|
msg_release(msg);
|
|
|
|
|
|
|
|
/* beyond the limit, do nothing */
|
|
|
|
usetcontact(env.src, env.dst);
|
|
|
|
msg = give_men(2, env.dst, env.src, NULL);
|
|
|
|
CuAssertStrEquals(tc, "error129", (const char *)msg->parameters[3].v);
|
|
|
|
CuAssertIntEquals(tc, 2, env.dst->number);
|
|
|
|
CuAssertIntEquals(tc, 0, env.src->number);
|
|
|
|
CuAssertIntEquals(tc, 0, env.f1->newbies);
|
|
|
|
msg_release(msg);
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-12-11 08:35:05 +01:00
|
|
|
static void test_give_men_in_ocean(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2014-12-11 08:35:05 +01:00
|
|
|
message * msg;
|
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-12-11 08:35:05 +01:00
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = 0;
|
|
|
|
setup_give(&env);
|
|
|
|
env.r->terrain = test_create_terrain("ocean", SEA_REGION);
|
|
|
|
msg = disband_men(1, env.src, NULL);
|
|
|
|
CuAssertStrEquals(tc, "give_person_ocean", (const char *)msg->parameters[0].v);
|
|
|
|
CuAssertIntEquals(tc, 0, env.src->number);
|
2015-10-13 22:37:45 +02:00
|
|
|
msg_release(msg);
|
2014-12-11 08:35:05 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-12-10 22:14:25 +01:00
|
|
|
static void test_give_men_too_many(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-12-10 22:14:25 +01:00
|
|
|
env.f2 = env.f1 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
CuAssertPtrEquals(tc, 0, give_men(2, env.src, env.dst, NULL));
|
|
|
|
CuAssertIntEquals(tc, 2, env.dst->number);
|
|
|
|
CuAssertIntEquals(tc, 0, env.src->number);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_give_men_none(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2014-12-10 22:14:25 +01:00
|
|
|
message * msg;
|
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-12-10 22:14:25 +01:00
|
|
|
env.f2 = env.f1 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
msg = give_men(0, env.src, env.dst, NULL);
|
2015-01-12 17:50:10 +01:00
|
|
|
CuAssertStrEquals(tc, "error96", test_get_messagetype(msg));
|
2014-12-10 22:14:25 +01:00
|
|
|
CuAssertIntEquals(tc, 1, env.dst->number);
|
|
|
|
CuAssertIntEquals(tc, 1, env.src->number);
|
2015-10-13 22:33:13 +02:00
|
|
|
msg_release(msg);
|
2014-12-10 22:14:25 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-12-10 21:17:00 +01:00
|
|
|
static void test_give_men_other_faction(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2014-12-10 21:17:00 +01:00
|
|
|
message * msg;
|
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-12-10 21:17:00 +01:00
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
usetcontact(env.dst, env.src);
|
|
|
|
msg = give_men(1, env.src, env.dst, NULL);
|
|
|
|
CuAssertStrEquals(tc, "give_person", (const char *)msg->parameters[0].v);
|
|
|
|
CuAssertIntEquals(tc, 2, env.dst->number);
|
|
|
|
CuAssertIntEquals(tc, 0, env.src->number);
|
2015-10-13 22:33:13 +02:00
|
|
|
msg_release(msg);
|
2014-12-10 21:17:00 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_give_men_requires_contact(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2014-12-10 21:17:00 +01:00
|
|
|
message * msg;
|
2015-09-07 14:49:57 +02:00
|
|
|
order *ord;
|
2014-12-10 21:17:00 +01:00
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-12-10 21:17:00 +01:00
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
msg = give_men(1, env.src, env.dst, NULL);
|
2015-01-12 17:50:10 +01:00
|
|
|
CuAssertStrEquals(tc, "feedback_no_contact", test_get_messagetype(msg));
|
2014-12-10 21:17:00 +01:00
|
|
|
CuAssertIntEquals(tc, 1, env.dst->number);
|
|
|
|
CuAssertIntEquals(tc, 1, env.src->number);
|
2015-09-07 14:49:57 +02:00
|
|
|
|
2017-01-07 21:19:58 +01:00
|
|
|
ord = create_order(K_GIVE, env.f1->locale, "%s ALLES PERSONEN", itoa36(env.dst->no));
|
2015-10-12 13:27:39 +02:00
|
|
|
test_clear_messages(env.f1);
|
2015-09-07 14:49:57 +02:00
|
|
|
give_cmd(env.src, ord);
|
|
|
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person"));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact"));
|
|
|
|
|
2015-10-13 22:33:13 +02:00
|
|
|
msg_release(msg);
|
|
|
|
free_order(ord);
|
2014-12-10 21:17:00 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_give_men_not_to_self(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2014-12-10 21:17:00 +01:00
|
|
|
message * msg;
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-12-10 21:17:00 +01:00
|
|
|
env.f2 = env.f1 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
2014-12-10 22:14:25 +01:00
|
|
|
msg = give_men(1, env.src, env.src, NULL);
|
2015-01-12 17:50:10 +01:00
|
|
|
CuAssertStrEquals(tc, "error10", test_get_messagetype(msg));
|
2014-12-10 21:17:00 +01:00
|
|
|
CuAssertIntEquals(tc, 1, env.src->number);
|
2015-10-13 22:33:13 +02:00
|
|
|
msg_release(msg);
|
2014-12-10 21:17:00 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-12-10 20:44:33 +01:00
|
|
|
static void test_give_peasants(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2014-12-10 21:17:00 +01:00
|
|
|
message * msg;
|
2014-12-11 08:35:05 +01:00
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-12-10 22:14:25 +01:00
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = 0;
|
2014-12-10 20:44:33 +01:00
|
|
|
setup_give(&env);
|
2014-12-11 08:35:05 +01:00
|
|
|
rsetpeasants(env.r, 0);
|
2014-12-10 22:14:25 +01:00
|
|
|
msg = disband_men(1, env.src, NULL);
|
2014-12-10 21:17:00 +01:00
|
|
|
CuAssertStrEquals(tc, "give_person_peasants", (const char*)msg->parameters[0].v);
|
2014-12-10 20:44:33 +01:00
|
|
|
CuAssertIntEquals(tc, 0, env.src->number);
|
2015-12-07 17:59:50 +01:00
|
|
|
CuAssertIntEquals(tc, 1, rpeasants(env.r));
|
2015-10-13 23:02:01 +02:00
|
|
|
msg_release(msg);
|
2014-12-10 20:44:33 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-11-03 08:33:07 +01:00
|
|
|
static void test_give(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2014-11-03 08:33:07 +01:00
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-11-03 08:33:07 +01:00
|
|
|
env.f2 = env.f1 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
|
|
|
|
i_change(&env.src->items, env.itype, 10);
|
|
|
|
CuAssertIntEquals(tc, 0, give_item(10, env.itype, env.src, env.dst, 0));
|
|
|
|
CuAssertIntEquals(tc, 0, i_get(env.src->items, env.itype));
|
|
|
|
CuAssertIntEquals(tc, 10, i_get(env.dst->items, env.itype));
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, -1, give_item(10, env.itype, env.src, env.dst, 0));
|
|
|
|
CuAssertIntEquals(tc, 0, i_get(env.src->items, env.itype));
|
|
|
|
CuAssertIntEquals(tc, 10, i_get(env.dst->items, env.itype));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2016-11-14 20:01:44 +01:00
|
|
|
static void test_give_cmd(CuTest * tc) {
|
|
|
|
struct give env = { 0 };
|
|
|
|
struct order *ord;
|
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2016-11-14 20:01:44 +01:00
|
|
|
env.lang = test_create_locale();
|
|
|
|
env.f2 = env.f1 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
|
|
|
|
i_change(&env.src->items, env.itype, 10);
|
|
|
|
|
2017-01-07 21:19:58 +01:00
|
|
|
ord = create_order(K_GIVE, env.f1->locale, "%s 5 %s", itoa36(env.dst->no), LOC(env.f1->locale, env.itype->rtype->_name));
|
2016-11-14 20:01:44 +01:00
|
|
|
assert(ord);
|
|
|
|
give_cmd(env.src, ord);
|
|
|
|
CuAssertIntEquals(tc, 5, i_get(env.src->items, env.itype));
|
|
|
|
CuAssertIntEquals(tc, 5, i_get(env.dst->items, env.itype));
|
|
|
|
|
|
|
|
free_order(ord);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-11-03 08:33:07 +01:00
|
|
|
static void test_give_herbs(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2014-11-03 08:33:07 +01:00
|
|
|
struct order *ord;
|
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2017-03-11 14:22:21 +01:00
|
|
|
env.f2 = env.f1 = test_create_faction(NULL);
|
2014-11-03 08:33:07 +01:00
|
|
|
setup_give(&env);
|
|
|
|
i_change(&env.src->items, env.itype, 10);
|
|
|
|
|
2017-01-07 21:19:58 +01:00
|
|
|
ord = create_order(K_GIVE, env.f1->locale, "%s %s", itoa36(env.dst->no), LOC(env.f1->locale, parameters[P_HERBS]));
|
2014-11-03 08:33:07 +01:00
|
|
|
assert(ord);
|
|
|
|
|
|
|
|
give_cmd(env.src, ord);
|
|
|
|
CuAssertIntEquals(tc, 0, i_get(env.src->items, env.itype));
|
|
|
|
CuAssertIntEquals(tc, 10, i_get(env.dst->items, env.itype));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2014-11-03 08:33:07 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_give_okay(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2014-11-03 08:33:07 +01:00
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-11-03 08:33:07 +01:00
|
|
|
env.f2 = env.f1 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.give.flags", "0");
|
2014-11-03 08:33:07 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, 0));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_give_denied_by_rules(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2014-11-03 08:33:07 +01:00
|
|
|
struct message *msg;
|
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2014-11-03 08:33:07 +01:00
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
config_set("rules.give.flags", "0");
|
2014-11-03 08:33:07 +01:00
|
|
|
CuAssertPtrNotNull(tc, msg = check_give(env.src, env.dst, 0));
|
|
|
|
msg_release(msg);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2016-08-21 11:46:54 +02:00
|
|
|
static void test_give_dead_unit(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2016-08-21 11:46:54 +02:00
|
|
|
struct message *msg;
|
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2016-08-21 11:46:54 +02:00
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
env.dst->number = 0;
|
|
|
|
freset(env.dst, UFL_ISNEW);
|
|
|
|
CuAssertPtrNotNull(tc, msg = check_give(env.src, env.dst, 0));
|
|
|
|
msg_release(msg);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_give_new_unit(CuTest * tc) {
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2016-08-21 11:46:54 +02:00
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2016-08-21 11:46:54 +02:00
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = test_create_faction(0);
|
|
|
|
setup_give(&env);
|
|
|
|
env.dst->number = 0;
|
|
|
|
fset(env.dst, UFL_ISNEW);
|
|
|
|
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, 0));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-09-05 18:14:28 +02:00
|
|
|
static void test_give_invalid_target(CuTest *tc) {
|
2017-02-18 21:15:14 +01:00
|
|
|
/* bug https://bugs.eressea.de/view.php?id=1685 */
|
2016-11-14 20:01:44 +01:00
|
|
|
struct give env = { 0 };
|
2015-09-05 18:14:28 +02:00
|
|
|
order *ord;
|
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
test_setup_ex(tc);
|
2015-09-05 18:14:28 +02:00
|
|
|
env.f1 = test_create_faction(0);
|
|
|
|
env.f2 = 0;
|
|
|
|
setup_give(&env);
|
|
|
|
|
|
|
|
i_change(&env.src->items, env.itype, 10);
|
2016-03-23 22:24:11 +01:00
|
|
|
ord = create_order(K_GIVE, env.f1->locale, "## KRAUT");
|
2015-09-05 18:14:28 +02:00
|
|
|
assert(ord);
|
|
|
|
|
|
|
|
give_cmd(env.src, ord);
|
|
|
|
CuAssertIntEquals(tc, 10, i_get(env.src->items, env.itype));
|
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_unit_not_found"));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2015-09-05 18:14:28 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-11-03 08:33:07 +01:00
|
|
|
CuSuite *get_give_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_give);
|
2016-11-14 20:01:44 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_cmd);
|
2014-12-10 20:44:33 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_men);
|
2016-11-13 16:09:58 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_men_magicians);
|
2015-03-13 21:10:39 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_men_limit);
|
2014-12-11 08:35:05 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_men_in_ocean);
|
2014-12-10 22:14:25 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_men_none);
|
|
|
|
SUITE_ADD_TEST(suite, test_give_men_too_many);
|
2014-12-10 21:17:00 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_men_other_faction);
|
|
|
|
SUITE_ADD_TEST(suite, test_give_men_requires_contact);
|
|
|
|
SUITE_ADD_TEST(suite, test_give_men_not_to_self);
|
2015-06-08 08:56:14 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_give_unit);
|
2017-03-11 20:03:49 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_unit_limits);
|
|
|
|
SUITE_ADD_TEST(suite, test_give_unit_to_ocean);
|
2014-12-11 08:35:05 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_unit_to_peasants);
|
2014-12-10 20:44:33 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_peasants);
|
2014-11-03 08:33:07 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_give_herbs);
|
|
|
|
SUITE_ADD_TEST(suite, test_give_okay);
|
|
|
|
SUITE_ADD_TEST(suite, test_give_denied_by_rules);
|
2015-09-05 18:14:28 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_give_invalid_target);
|
2016-08-21 11:46:54 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_give_new_unit);
|
|
|
|
SUITE_ADD_TEST(suite, test_give_dead_unit);
|
2014-11-03 08:33:07 +01:00
|
|
|
return suite;
|
|
|
|
}
|