2017-10-07 20:17:04 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/config.h>
|
|
|
|
|
|
|
|
#include "orderfile.h"
|
|
|
|
|
2018-02-14 20:00:48 +01:00
|
|
|
#include <kernel/calendar.h>
|
2017-10-07 20:17:04 +02:00
|
|
|
#include <kernel/faction.h>
|
2018-01-13 08:51:40 +01:00
|
|
|
#include <util/message.h>
|
2017-10-07 20:17:04 +02:00
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
|
|
|
|
static const char *getbuf_null(void *data)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_read_orders(CuTest *tc) {
|
|
|
|
input in;
|
|
|
|
test_setup();
|
|
|
|
in.getbuf = getbuf_null;
|
|
|
|
in.data = NULL;
|
|
|
|
CuAssertIntEquals(tc, 0, read_orders(&in));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-10-07 20:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct order_list {
|
2017-10-07 20:25:07 +02:00
|
|
|
const char **orders;
|
2017-10-07 20:17:04 +02:00
|
|
|
int next;
|
|
|
|
} order_list;
|
|
|
|
|
|
|
|
static const char *getbuf_list(void *data)
|
|
|
|
{
|
|
|
|
order_list * olist = (order_list *)data;
|
|
|
|
return olist->orders[olist->next++];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_faction_password_okay(CuTest *tc) {
|
|
|
|
input in;
|
|
|
|
faction *f;
|
|
|
|
order_list olist;
|
2017-10-07 20:25:07 +02:00
|
|
|
const char *orders[] = { "ERESSEA 1 password", NULL };
|
2017-10-07 20:17:04 +02:00
|
|
|
|
|
|
|
test_setup();
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
renumber_faction(f, 1);
|
|
|
|
CuAssertIntEquals(tc, 1, f->no);
|
|
|
|
faction_setpassword(f, "password");
|
|
|
|
f->lastorders = turn - 1;
|
2017-10-07 20:25:07 +02:00
|
|
|
olist.orders = orders;
|
2017-10-07 20:17:04 +02:00
|
|
|
olist.next = 0;
|
|
|
|
in.getbuf = getbuf_list;
|
|
|
|
in.data = &olist;
|
|
|
|
CuAssertIntEquals(tc, 0, read_orders(&in));
|
|
|
|
CuAssertIntEquals(tc, 2, olist.next);
|
|
|
|
CuAssertIntEquals(tc, turn, f->lastorders);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-10-07 20:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_faction_password_bad(CuTest *tc) {
|
|
|
|
input in;
|
|
|
|
faction *f;
|
|
|
|
order_list olist;
|
2017-10-07 20:25:07 +02:00
|
|
|
const char *orders[] = { "ERESSEA 1 password", NULL };
|
2017-10-07 20:17:04 +02:00
|
|
|
|
|
|
|
test_setup();
|
2018-05-18 19:58:49 +02:00
|
|
|
mt_create_va(mt_new("wrongpasswd", NULL), "password:string", MT_NEW_END);
|
2018-01-13 08:51:40 +01:00
|
|
|
|
2017-10-07 20:17:04 +02:00
|
|
|
f = test_create_faction(NULL);
|
|
|
|
renumber_faction(f, 1);
|
|
|
|
CuAssertIntEquals(tc, 1, f->no);
|
2017-10-07 20:25:07 +02:00
|
|
|
faction_setpassword(f, "patzword");
|
2017-10-07 20:17:04 +02:00
|
|
|
f->lastorders = turn - 1;
|
2017-10-07 20:25:07 +02:00
|
|
|
olist.orders = orders;
|
2017-10-07 20:17:04 +02:00
|
|
|
olist.next = 0;
|
|
|
|
in.getbuf = getbuf_list;
|
|
|
|
in.data = &olist;
|
|
|
|
CuAssertIntEquals(tc, 0, read_orders(&in));
|
|
|
|
CuAssertIntEquals(tc, 2, olist.next);
|
|
|
|
CuAssertIntEquals(tc, turn - 1, f->lastorders);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-10-07 20:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_orderfile_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_read_orders);
|
|
|
|
SUITE_ADD_TEST(suite, test_faction_password_okay);
|
|
|
|
SUITE_ADD_TEST(suite, test_faction_password_bad);
|
|
|
|
|
|
|
|
return suite;
|
|
|
|
}
|