Simple test for rules.give (there are many more, can_give deserves a test to itself).

The more tests I write, the more I hate the infrastructure for them.
This commit is contained in:
Enno Rehling 2014-07-05 23:06:51 -07:00
parent b9b627a171
commit b21cb8f5c7
4 changed files with 29 additions and 8 deletions

View File

@ -703,7 +703,6 @@ message *check_give(const unit *u, const unit *u2, order * ord) {
if (!can_give(u, u2, NULL, GIVE_ALLITEMS)) {
return msg_feedback(u, ord, "feedback_give_forbidden", "");
}
return 0;
}

View File

@ -1,4 +1,5 @@
#include <platform.h>
#include <kernel/config.h>
#include <kernel/types.h>
#include "economy.h"
@ -117,27 +118,47 @@ static void test_steal_ocean(CuTest * tc) {
struct give {
struct unit *src, *dst;
struct region *r;
struct faction *f;
struct faction *f1, *f2;
};
static void setup_give(struct give *env) {
terrain_type *ter = test_create_terrain("plain", LAND_REGION);
struct race * rc = test_create_race("human");
env->r = test_create_region(0, 0, ter);
env->f = test_create_faction(0);
env->src = test_create_unit(env->f, env->r);
env->dst = test_create_unit(env->f, env->r);
env->src = test_create_unit(env->f1, env->r);
env->dst = test_create_unit(env->f2, env->r);
}
static void test_give_okay(CuTest * tc) {
struct give env;
struct race * rc;
test_cleanup();
rc = test_create_race("human");
env.f2 = env.f1 = test_create_faction(rc);
setup_give(&env);
set_param(&global.parameters, "rules.give", "0");
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, 0));
test_cleanup();
}
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();
}
CuSuite *get_economy_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -147,5 +168,6 @@ CuSuite *get_economy_suite(void)
SUITE_ADD_TEST(suite, test_steal_ocean);
SUITE_ADD_TEST(suite, test_steal_nosteal);
SUITE_ADD_TEST(suite, test_give_okay);
SUITE_ADD_TEST(suite, test_give_denied_by_rules);
return suite;
}

View File

@ -2748,6 +2748,7 @@ void kernel_init(void)
register_reports();
if (!mt_find("missing_message")) {
mt_register(mt_new_va("missing_message", "name:string", 0));
mt_register(mt_new_va("missing_feedback", "unit:unit", "region:region", "command:order", "name:string", 0));
}
attrib_init();
translation_init();

View File

@ -189,8 +189,7 @@ void locale_setstring(locale * lang, const char *key, const char *value)
const char *locale_name(const locale * lang)
{
assert(lang);
return lang->name;
return lang ? lang->name : "(null)";
}
char *mkname_buf(const char *space, const char *name, char *buffer)