Slightly reduce amount of code required for a test.

This commit is contained in:
Enno Rehling 2017-10-07 20:25:07 +02:00
parent 703c6c0385
commit e87a26d961
1 changed files with 6 additions and 9 deletions

View File

@ -23,16 +23,13 @@ static void test_read_orders(CuTest *tc) {
} }
typedef struct order_list { typedef struct order_list {
const char *orders[8]; const char **orders;
int next; int next;
} order_list; } order_list;
static const char *getbuf_list(void *data) static const char *getbuf_list(void *data)
{ {
order_list * olist = (order_list *)data; order_list * olist = (order_list *)data;
if (olist->next >= 8) {
return NULL;
}
return olist->orders[olist->next++]; return olist->orders[olist->next++];
} }
@ -40,6 +37,7 @@ static void test_faction_password_okay(CuTest *tc) {
input in; input in;
faction *f; faction *f;
order_list olist; order_list olist;
const char *orders[] = { "ERESSEA 1 password", NULL };
test_setup(); test_setup();
f = test_create_faction(NULL); f = test_create_faction(NULL);
@ -47,8 +45,7 @@ static void test_faction_password_okay(CuTest *tc) {
CuAssertIntEquals(tc, 1, f->no); CuAssertIntEquals(tc, 1, f->no);
faction_setpassword(f, "password"); faction_setpassword(f, "password");
f->lastorders = turn - 1; f->lastorders = turn - 1;
olist.orders[0] = "ERESSEA 1 password"; olist.orders = orders;
olist.orders[1] = NULL;
olist.next = 0; olist.next = 0;
in.getbuf = getbuf_list; in.getbuf = getbuf_list;
in.data = &olist; in.data = &olist;
@ -62,15 +59,15 @@ static void test_faction_password_bad(CuTest *tc) {
input in; input in;
faction *f; faction *f;
order_list olist; order_list olist;
const char *orders[] = { "ERESSEA 1 password", NULL };
test_setup(); test_setup();
f = test_create_faction(NULL); f = test_create_faction(NULL);
renumber_faction(f, 1); renumber_faction(f, 1);
CuAssertIntEquals(tc, 1, f->no); CuAssertIntEquals(tc, 1, f->no);
faction_setpassword(f, "password"); faction_setpassword(f, "patzword");
f->lastorders = turn - 1; f->lastorders = turn - 1;
olist.orders[0] = "ERESSEA 1 patzword"; olist.orders = orders;
olist.orders[1] = NULL;
olist.next = 0; olist.next = 0;
in.getbuf = getbuf_list; in.getbuf = getbuf_list;
in.data = &olist; in.data = &olist;