forked from github/server
Merge pull request #83 from badgerman/master
cleaning up in config.c and adding tests for pay_cmd
This commit is contained in:
commit
83f014047b
8 changed files with 105 additions and 35 deletions
|
@ -961,26 +961,6 @@ int getunit(const region * r, const faction * f, unit **uresult)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - String Listen --------------------------------------------- */
|
|
||||||
void addstrlist(strlist ** SP, const char *s)
|
|
||||||
{
|
|
||||||
strlist *slist = malloc(sizeof(strlist));
|
|
||||||
slist->next = NULL;
|
|
||||||
slist->s = _strdup(s);
|
|
||||||
addlist(SP, slist);
|
|
||||||
}
|
|
||||||
|
|
||||||
void freestrlist(strlist * s)
|
|
||||||
{
|
|
||||||
strlist *q, *p = s;
|
|
||||||
while (p) {
|
|
||||||
q = p->next;
|
|
||||||
free(p->s);
|
|
||||||
free(p);
|
|
||||||
p = q;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* - Namen der Strukturen -------------------------------------- */
|
/* - Namen der Strukturen -------------------------------------- */
|
||||||
char *untilde(char *ibuf)
|
char *untilde(char *ibuf)
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,14 +108,6 @@ extern "C" {
|
||||||
/* special units */
|
/* special units */
|
||||||
void make_undead_unit(struct unit *);
|
void make_undead_unit(struct unit *);
|
||||||
|
|
||||||
typedef struct strlist {
|
|
||||||
struct strlist *next;
|
|
||||||
char *s;
|
|
||||||
} strlist;
|
|
||||||
|
|
||||||
void addstrlist(strlist ** SP, const char *s);
|
|
||||||
void freestrlist(strlist * s);
|
|
||||||
|
|
||||||
unsigned int atoip(const char *s);
|
unsigned int atoip(const char *s);
|
||||||
unsigned int getuint(void);
|
unsigned int getuint(void);
|
||||||
int getint(void);
|
int getint(void);
|
||||||
|
|
|
@ -21,12 +21,10 @@ static void test_getunit(CuTest *tc) {
|
||||||
struct region *r;
|
struct region *r;
|
||||||
struct locale *lang;
|
struct locale *lang;
|
||||||
struct terrain_type *t_plain;
|
struct terrain_type *t_plain;
|
||||||
struct critbit_tree ** cb;
|
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
lang = get_or_create_locale("de");
|
lang = get_or_create_locale("de");
|
||||||
cb = (struct critbit_tree **)get_translations(lang, UT_PARAMS);
|
test_translate_param(lang, P_TEMP, "TEMP");
|
||||||
add_translation(cb, "TEMP", P_TEMP);
|
|
||||||
/* note that the english order is FIGHT, not COMBAT, so this is a poor example */
|
/* note that the english order is FIGHT, not COMBAT, so this is a poor example */
|
||||||
t_plain = test_create_terrain("plain", LAND_REGION);
|
t_plain = test_create_terrain("plain", LAND_REGION);
|
||||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, t_plain));
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, t_plain));
|
||||||
|
|
|
@ -329,7 +329,6 @@ static void test_reserve_cmd(CuTest *tc) {
|
||||||
region *r;
|
region *r;
|
||||||
order *ord;
|
order *ord;
|
||||||
const resource_type *rtype;
|
const resource_type *rtype;
|
||||||
const struct locale *loc;
|
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
|
@ -342,9 +341,7 @@ static void test_reserve_cmd(CuTest *tc) {
|
||||||
u1 = test_create_unit(f, r);
|
u1 = test_create_unit(f, r);
|
||||||
u2 = test_create_unit(f, r);
|
u2 = test_create_unit(f, r);
|
||||||
assert(u1 && u2);
|
assert(u1 && u2);
|
||||||
loc = get_locale("de");
|
ord = create_order(K_RESERVE, f->locale, "200 SILBER");
|
||||||
assert(loc);
|
|
||||||
ord = create_order(K_RESERVE, loc, "200 SILBER");
|
|
||||||
assert(ord);
|
assert(ord);
|
||||||
i_change(&u1->items, rtype->itype, 100);
|
i_change(&u1->items, rtype->itype, 100);
|
||||||
i_change(&u2->items, rtype->itype, 100);
|
i_change(&u2->items, rtype->itype, 100);
|
||||||
|
@ -354,6 +351,68 @@ static void test_reserve_cmd(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct pay_fixture {
|
||||||
|
unit *u1;
|
||||||
|
unit *u2;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void setup_pay_cmd(struct pay_fixture *fix) {
|
||||||
|
faction *f;
|
||||||
|
region *r;
|
||||||
|
building *b;
|
||||||
|
|
||||||
|
test_create_world();
|
||||||
|
f = test_create_faction(NULL);
|
||||||
|
r = findregion(0, 0);
|
||||||
|
assert(r && f);
|
||||||
|
b = test_create_building(r, bt_get_or_create("lighthouse"));
|
||||||
|
assert(b);
|
||||||
|
fix->u1 = test_create_unit(f, r);
|
||||||
|
fix->u2 = test_create_unit(f, r);
|
||||||
|
assert(fix->u1 && fix->u2);
|
||||||
|
u_set_building(fix->u1, b);
|
||||||
|
u_set_building(fix->u2, b);
|
||||||
|
assert(building_owner(b) == fix->u1);
|
||||||
|
test_translate_param(f->locale, P_NOT, "NOT");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_pay_cmd(CuTest *tc) {
|
||||||
|
struct pay_fixture fix;
|
||||||
|
order *ord;
|
||||||
|
faction *f;
|
||||||
|
building *b;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
setup_pay_cmd(&fix);
|
||||||
|
b = fix.u1->building;
|
||||||
|
f = fix.u1->faction;
|
||||||
|
|
||||||
|
ord = create_order(K_PAY, f->locale, "NOT");
|
||||||
|
assert(ord);
|
||||||
|
CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord));
|
||||||
|
CuAssertIntEquals(tc, BLD_DONTPAY, b->flags&BLD_DONTPAY);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_pay_cmd_must_be_owner(CuTest *tc) {
|
||||||
|
struct pay_fixture fix;
|
||||||
|
order *ord;
|
||||||
|
faction *f;
|
||||||
|
building *b;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
setup_pay_cmd(&fix);
|
||||||
|
b = fix.u1->building;
|
||||||
|
f = fix.u1->faction;
|
||||||
|
|
||||||
|
ord = create_order(K_PAY, f->locale, "NOT");
|
||||||
|
assert(ord);
|
||||||
|
CuAssertIntEquals(tc, 0, pay_cmd(fix.u2, ord));
|
||||||
|
CuAssertIntEquals(tc, 0, b->flags&BLD_DONTPAY);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void test_new_units(CuTest *tc) {
|
static void test_new_units(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
faction *f;
|
faction *f;
|
||||||
|
@ -521,6 +580,8 @@ CuSuite *get_laws_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_low_skill_cannot_guard);
|
SUITE_ADD_TEST(suite, test_low_skill_cannot_guard);
|
||||||
SUITE_ADD_TEST(suite, test_reserve_self);
|
SUITE_ADD_TEST(suite, test_reserve_self);
|
||||||
SUITE_ADD_TEST(suite, test_reserve_cmd);
|
SUITE_ADD_TEST(suite, test_reserve_cmd);
|
||||||
|
SUITE_ADD_TEST(suite, test_pay_cmd);
|
||||||
|
SUITE_ADD_TEST(suite, test_pay_cmd_must_be_owner);
|
||||||
SUITE_ADD_TEST(suite, test_new_units);
|
SUITE_ADD_TEST(suite, test_new_units);
|
||||||
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
|
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
|
||||||
SUITE_ADD_TEST(suite, test_contact);
|
SUITE_ADD_TEST(suite, test_contact);
|
||||||
|
|
|
@ -2406,6 +2406,26 @@ static void eval_int36(struct opstack **stack, const void *userdata)
|
||||||
|
|
||||||
/*** END MESSAGE RENDERING ***/
|
/*** END MESSAGE RENDERING ***/
|
||||||
|
|
||||||
|
/* - String Listen --------------------------------------------- */
|
||||||
|
void addstrlist(strlist ** SP, const char *s)
|
||||||
|
{
|
||||||
|
strlist *slist = malloc(sizeof(strlist));
|
||||||
|
slist->next = NULL;
|
||||||
|
slist->s = _strdup(s);
|
||||||
|
addlist(SP, slist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void freestrlist(strlist * s)
|
||||||
|
{
|
||||||
|
strlist *q, *p = s;
|
||||||
|
while (p) {
|
||||||
|
q = p->next;
|
||||||
|
free(p->s);
|
||||||
|
free(p);
|
||||||
|
p = q;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include <util/nrmessage.h>
|
#include <util/nrmessage.h>
|
||||||
|
|
||||||
static void log_orders(const struct message *msg)
|
static void log_orders(const struct message *msg)
|
||||||
|
|
|
@ -142,6 +142,15 @@ extern "C" {
|
||||||
size_t f_regionid(const struct region *r, const struct faction *f,
|
size_t f_regionid(const struct region *r, const struct faction *f,
|
||||||
char *buffer, size_t size);
|
char *buffer, size_t size);
|
||||||
|
|
||||||
|
typedef struct strlist {
|
||||||
|
struct strlist *next;
|
||||||
|
char *s;
|
||||||
|
} strlist;
|
||||||
|
|
||||||
|
void addstrlist(strlist ** SP, const char *s);
|
||||||
|
void freestrlist(strlist * s);
|
||||||
|
|
||||||
|
|
||||||
#define GR_PLURAL 0x01 /* grammar: plural */
|
#define GR_PLURAL 0x01 /* grammar: plural */
|
||||||
#define MAX_INVENTORY 128 /* maimum number of different items in an inventory */
|
#define MAX_INVENTORY 128 /* maimum number of different items in an inventory */
|
||||||
#define MAX_RAWMATERIALS 8 /* maximum kinds of raw materials in a regions */
|
#define MAX_RAWMATERIALS 8 /* maximum kinds of raw materials in a regions */
|
||||||
|
|
|
@ -132,6 +132,14 @@ item_type * test_create_itemtype(const char * name) {
|
||||||
return itype;
|
return itype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_translate_param(const struct locale *lang, param_t param, const char *text) {
|
||||||
|
struct critbit_tree **cb;
|
||||||
|
|
||||||
|
assert(lang && text);
|
||||||
|
cb = (struct critbit_tree **)get_translations(lang, UT_PARAMS);
|
||||||
|
add_translation(cb, text, param);
|
||||||
|
}
|
||||||
|
|
||||||
/** creates a small world and some stuff in it.
|
/** creates a small world and some stuff in it.
|
||||||
* two terrains: 'plain' and 'ocean'
|
* two terrains: 'plain' and 'ocean'
|
||||||
* one race: 'human'
|
* one race: 'human'
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef ERESSEA_TESTS_H
|
#ifndef ERESSEA_TESTS_H
|
||||||
#define ERESSEA_TESTS_H
|
#define ERESSEA_TESTS_H
|
||||||
|
|
||||||
|
#include <kernel/types.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -33,6 +34,7 @@ extern "C" {
|
||||||
struct building_type *test_create_buildingtype(const char *name);
|
struct building_type *test_create_buildingtype(const char *name);
|
||||||
|
|
||||||
int RunAllTests(void);
|
int RunAllTests(void);
|
||||||
|
void test_translate_param(const struct locale *lang, param_t param, const char *text);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue