Bug 2525: failing test for default orders.

This commit is contained in:
Enno Rehling 2018-12-02 15:51:35 +01:00
parent b74e8c0ebd
commit a9f3592228
4 changed files with 65 additions and 8 deletions

View File

@ -47,13 +47,12 @@ static void begin_orders(unit *u) {
u->orders = NULL; u->orders = NULL;
} }
static unit *unitorders(input *in, faction *f) static void unitorders(input *in, faction *f)
{ {
int i; int i;
unit *u; unit *u;
if (!f) assert(f);
return NULL;
i = getid(); i = getid();
u = findunit(i); u = findunit(i);
@ -120,10 +119,6 @@ static unit *unitorders(input *in, faction *f)
} }
} }
else {
return NULL;
}
return u;
} }
static faction *factionorders(void) static faction *factionorders(void)
@ -189,7 +184,8 @@ int read_orders(input *in)
* vermerkt. */ * vermerkt. */
case P_UNIT: case P_UNIT:
if (!f || !unitorders(in, f)) { if (f) {
unitorders(in, f);
do { do {
b = in->getbuf(in->data); b = in->getbuf(in->data);
if (!b) { if (!b) {

View File

@ -3,9 +3,20 @@
#include "orderfile.h" #include "orderfile.h"
#include "direction.h"
#include <kernel/calendar.h> #include <kernel/calendar.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/order.h>
#include <kernel/unit.h>
#include <util/base36.h>
#include <util/keyword.h>
#include <util/language.h>
#include <util/lists.h>
#include <util/message.h> #include <util/message.h>
#include <util/param.h>
#include <util/password.h>
#include <CuTest.h> #include <CuTest.h>
#include <tests.h> #include <tests.h>
@ -24,6 +35,49 @@ static void test_read_orders(CuTest *tc) {
test_teardown(); test_teardown();
} }
static const char *getbuf_strings(void *data)
{
strlist **listp = (strlist **)data;
if (listp && *listp) {
strlist *list = *listp;
*listp = list->next;
return list->s;
}
return NULL;
}
static void test_unit_orders(CuTest *tc) {
input in;
unit *u;
faction *f;
strlist *orders = NULL;
char buf[64];
test_setup();
u = test_create_unit(f = test_create_faction(NULL), test_create_plain(0, 0));
f->locale = test_create_locale();
u->orders = create_order(K_ENTERTAIN, f->locale, NULL);
faction_setpassword(f, password_hash("password", PASSWORD_DEFAULT));
snprintf(buf, sizeof(buf), "%s %s %s",
LOC(f->locale, parameters[P_FACTION]), itoa36(f->no), "password");
addstrlist(&orders, buf);
snprintf(buf, sizeof(buf), "%s %s",
LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
addstrlist(&orders, buf);
snprintf(buf, sizeof(buf), "%s %s", keyword_name(K_MOVE, f->locale),
LOC(f->locale, shortdirections[D_WEST]));
addstrlist(&orders, buf);
in.data = &orders;
in.getbuf = getbuf_strings;
CuAssertIntEquals(tc, 0, read_orders(&in));
CuAssertPtrNotNull(tc, u->old_orders);
CuAssertPtrNotNull(tc, u->orders);
CuAssertIntEquals(tc, K_MOVE, getkeyword(u->orders));
CuAssertIntEquals(tc, K_ENTERTAIN, getkeyword(u->old_orders));
CuAssertIntEquals(tc, UFL_ORDERS, u->flags & UFL_ORDERS);
test_teardown();
}
typedef struct order_list { typedef struct order_list {
const char **orders; const char **orders;
int next; int next;
@ -85,6 +139,7 @@ CuSuite *get_orderfile_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_read_orders); SUITE_ADD_TEST(suite, test_read_orders);
SUITE_ADD_TEST(suite, test_unit_orders);
SUITE_ADD_TEST(suite, test_faction_password_okay); SUITE_ADD_TEST(suite, test_faction_password_okay);
SUITE_ADD_TEST(suite, test_faction_password_bad); SUITE_ADD_TEST(suite, test_faction_password_bad);

View File

@ -88,6 +88,11 @@ bool keyword_disabled(keyword_t kwd) {
return disabled_kwd[kwd]; return disabled_kwd[kwd];
} }
const char *keyword_name(keyword_t kwd, const struct locale *lang)
{
return LOC(lang, mkname("keyword", keywords[kwd]));
}
const char *keywords[MAXKEYWORDS] = { const char *keywords[MAXKEYWORDS] = {
"//", "//",
"banner", "banner",

View File

@ -83,6 +83,7 @@ extern "C"
void init_keywords(const struct locale *lang); void init_keywords(const struct locale *lang);
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str); void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
bool keyword_disabled(keyword_t kwd); bool keyword_disabled(keyword_t kwd);
const char *keyword_name(keyword_t kwd, const struct locale *lang);
void enable_keyword(keyword_t kwd, bool enabled); void enable_keyword(keyword_t kwd, bool enabled);
const char *keyword(keyword_t kwd); const char *keyword(keyword_t kwd);