2017-10-07 20:17:04 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/config.h>
|
|
|
|
|
|
|
|
#include "orderfile.h"
|
|
|
|
|
2018-12-02 15:51:35 +01:00
|
|
|
#include "direction.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-12-02 15:51:35 +01:00
|
|
|
#include <kernel/order.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
|
|
#include <util/base36.h>
|
|
|
|
#include <util/keyword.h>
|
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/lists.h>
|
2018-01-13 08:51:40 +01:00
|
|
|
#include <util/message.h>
|
2018-12-02 15:51:35 +01:00
|
|
|
#include <util/param.h>
|
|
|
|
#include <util/password.h>
|
2017-10-07 20:17:04 +02:00
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
|
2018-12-02 15:51:35 +01:00
|
|
|
static void test_unit_orders(CuTest *tc) {
|
|
|
|
unit *u;
|
|
|
|
faction *f;
|
2020-03-02 21:05:49 +01:00
|
|
|
FILE *F = tmpfile();
|
2018-12-02 15:51:35 +01:00
|
|
|
|
|
|
|
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));
|
2020-03-02 21:05:49 +01:00
|
|
|
fprintf(F, "%s %s %s\n",
|
2018-12-02 15:51:35 +01:00
|
|
|
LOC(f->locale, parameters[P_FACTION]), itoa36(f->no), "password");
|
2020-03-02 21:05:49 +01:00
|
|
|
fprintf(F, "%s %s\n",
|
2018-12-02 15:51:35 +01:00
|
|
|
LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
|
2020-03-02 21:05:49 +01:00
|
|
|
fprintf(F, "%s %s\n", keyword_name(K_MOVE, f->locale),
|
2018-12-02 15:51:35 +01:00
|
|
|
LOC(f->locale, shortdirections[D_WEST]));
|
2020-03-02 21:05:49 +01:00
|
|
|
rewind(F);
|
|
|
|
CuAssertIntEquals(tc, 0, parseorders(F));
|
2018-12-02 15:51:35 +01:00
|
|
|
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);
|
2020-03-02 21:05:49 +01:00
|
|
|
fclose(F);
|
2018-12-02 15:51:35 +01:00
|
|
|
test_teardown();
|
|
|
|
}
|
|
|
|
|
2017-10-07 20:17:04 +02:00
|
|
|
static void test_faction_password_okay(CuTest *tc) {
|
|
|
|
faction *f;
|
2020-03-02 21:05:49 +01:00
|
|
|
FILE *F;
|
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;
|
2020-03-02 21:05:49 +01:00
|
|
|
F = tmpfile();
|
|
|
|
fprintf(F, "ERESSEA 1 password\n");
|
|
|
|
rewind(F);
|
|
|
|
CuAssertIntEquals(tc, 0, parseorders(F));
|
2017-10-07 20:17:04 +02:00
|
|
|
CuAssertIntEquals(tc, turn, f->lastorders);
|
2020-03-02 21:05:49 +01:00
|
|
|
fclose(F);
|
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) {
|
|
|
|
faction *f;
|
2020-03-02 21:05:49 +01:00
|
|
|
FILE *F;
|
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;
|
2020-03-02 21:05:49 +01:00
|
|
|
F = tmpfile();
|
|
|
|
fprintf(F, "ERESSEA 1 password\n");
|
|
|
|
rewind(F);
|
|
|
|
CuAssertIntEquals(tc, 0, parseorders(F));
|
2017-10-07 20:17:04 +02:00
|
|
|
CuAssertIntEquals(tc, turn - 1, f->lastorders);
|
2020-03-02 21:05:49 +01:00
|
|
|
fclose(F);
|
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();
|
2018-12-02 15:51:35 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_unit_orders);
|
2017-10-07 20:17:04 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_faction_password_okay);
|
|
|
|
SUITE_ADD_TEST(suite, test_faction_password_bad);
|
|
|
|
|
|
|
|
return suite;
|
|
|
|
}
|