2014-08-23 09:21:40 +02:00
|
|
|
|
#include <platform.h>
|
2014-08-17 14:24:19 +02:00
|
|
|
|
#include <kernel/config.h>
|
2014-08-16 23:23:37 +02:00
|
|
|
|
#include "order.h"
|
|
|
|
|
|
2017-10-09 20:33:47 +02:00
|
|
|
|
#include <kernel/skills.h>
|
2018-03-16 19:52:54 +01:00
|
|
|
|
#include <kernel/unit.h>
|
2017-10-09 20:33:47 +02:00
|
|
|
|
|
2018-09-29 19:32:39 +02:00
|
|
|
|
#include "util/param.h"
|
2014-08-16 23:23:37 +02:00
|
|
|
|
#include <util/parser.h>
|
|
|
|
|
#include <util/language.h>
|
|
|
|
|
|
2018-03-16 19:52:54 +01:00
|
|
|
|
#include <stream.h>
|
|
|
|
|
#include <memstream.h>
|
|
|
|
|
|
2014-12-12 11:13:25 +01:00
|
|
|
|
#include <tests.h>
|
2014-08-16 23:23:37 +02:00
|
|
|
|
#include <CuTest.h>
|
|
|
|
|
#include <stdlib.h>
|
2018-05-21 13:27:02 +02:00
|
|
|
|
#include <string.h>
|
2014-08-16 23:23:37 +02:00
|
|
|
|
|
|
|
|
|
static void test_create_order(CuTest *tc) {
|
|
|
|
|
char cmd[32];
|
|
|
|
|
order *ord;
|
2014-12-12 11:13:25 +01:00
|
|
|
|
struct locale * lang;
|
|
|
|
|
|
2017-03-25 10:37:13 +01:00
|
|
|
|
test_setup();
|
|
|
|
|
lang = test_create_locale();
|
2014-08-16 23:23:37 +02:00
|
|
|
|
|
|
|
|
|
ord = create_order(K_MOVE, lang, "NORTH");
|
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
2017-10-08 17:07:42 +02:00
|
|
|
|
CuAssertStrEquals(tc, "move NORTH", get_command(ord, lang, cmd, sizeof(cmd)));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
2017-10-09 20:33:47 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, init_order_depr(ord));
|
2014-08-16 23:23:37 +02:00
|
|
|
|
CuAssertStrEquals(tc, "NORTH", getstrtoken());
|
|
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2014-08-16 23:23:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_parse_order(CuTest *tc) {
|
|
|
|
|
char cmd[32];
|
|
|
|
|
order *ord;
|
2014-12-12 11:13:25 +01:00
|
|
|
|
struct locale * lang;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
2017-03-25 10:37:13 +01:00
|
|
|
|
test_setup();
|
|
|
|
|
lang = test_create_locale();
|
2014-08-16 23:23:37 +02:00
|
|
|
|
|
|
|
|
|
ord = parse_order("MOVE NORTH", lang);
|
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
2017-09-30 19:22:24 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, ord->command);
|
2014-08-16 23:23:37 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
2017-10-08 17:07:42 +02:00
|
|
|
|
CuAssertStrEquals(tc, "move NORTH", get_command(ord, lang, cmd, sizeof(cmd)));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
2017-10-09 20:33:47 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, init_order_depr(ord));
|
2014-08-16 23:23:37 +02:00
|
|
|
|
CuAssertStrEquals(tc, "NORTH", getstrtoken());
|
|
|
|
|
free_order(ord);
|
2017-03-25 10:37:13 +01:00
|
|
|
|
|
|
|
|
|
ord = parse_order("!MOVE NORTH", lang);
|
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
2017-10-08 12:39:41 +02:00
|
|
|
|
CuAssertTrue(tc, ord->id > 0);
|
2017-09-25 22:04:16 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
2017-09-30 19:22:24 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE | CMD_QUIET, ord->command);
|
2017-03-25 10:37:13 +01:00
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
|
|
ord = parse_order("@MOVE NORTH", lang);
|
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
2017-10-08 12:39:41 +02:00
|
|
|
|
CuAssertTrue(tc, ord->id > 0);
|
2017-09-25 22:04:16 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
2017-09-30 19:22:24 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE | CMD_PERSIST, ord->command);
|
2017-03-25 10:37:13 +01:00
|
|
|
|
free_order(ord);
|
|
|
|
|
|
2017-09-30 19:22:24 +02:00
|
|
|
|
ord = parse_order("!@MOVE NORTH", lang);
|
2017-03-25 10:37:13 +01:00
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
2017-10-08 12:39:41 +02:00
|
|
|
|
CuAssertTrue(tc, ord->id > 0);
|
2017-09-25 22:04:16 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
2017-09-30 19:22:24 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE | CMD_PERSIST | CMD_QUIET, ord->command);
|
2017-03-25 10:37:13 +01:00
|
|
|
|
free_order(ord);
|
|
|
|
|
|
2017-09-30 19:22:24 +02:00
|
|
|
|
ord = parse_order("@!MOVE NORTH", lang);
|
2017-03-25 10:37:13 +01:00
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
2017-10-08 12:39:41 +02:00
|
|
|
|
CuAssertTrue(tc, ord->id > 0);
|
2017-09-25 22:04:16 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
2017-09-30 19:22:24 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE | CMD_PERSIST | CMD_QUIET, ord->command);
|
2017-09-25 22:04:16 +02:00
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
|
|
ord = parse_order(" !@MOVE NORTH", lang);
|
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
2017-10-08 12:39:41 +02:00
|
|
|
|
CuAssertTrue(tc, ord->id > 0);
|
2017-09-25 22:04:16 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
2017-09-30 19:22:24 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MOVE | CMD_PERSIST | CMD_QUIET, ord->command);
|
2017-03-25 10:37:13 +01:00
|
|
|
|
free_order(ord);
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2014-08-16 23:23:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 14:24:19 +02:00
|
|
|
|
static void test_parse_make(CuTest *tc) {
|
|
|
|
|
char cmd[32];
|
|
|
|
|
order *ord;
|
2014-12-12 11:13:25 +01:00
|
|
|
|
struct locale * lang;
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2014-12-12 11:13:25 +01:00
|
|
|
|
lang = get_or_create_locale("en");
|
2014-08-17 14:24:19 +02:00
|
|
|
|
|
|
|
|
|
locale_setstring(lang, keyword(K_MAKE), "MAKE");
|
|
|
|
|
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
|
|
|
|
|
init_locale(lang);
|
|
|
|
|
ord = parse_order("M hurrdurr", lang);
|
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
|
|
|
|
CuAssertIntEquals(tc, K_MAKE, getkeyword(ord));
|
2017-10-08 17:07:42 +02:00
|
|
|
|
CuAssertStrEquals(tc, "MAKE hurrdurr", get_command(ord, lang, cmd, sizeof(cmd)));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
2017-10-09 20:33:47 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MAKE, init_order_depr(ord));
|
2014-08-17 14:24:19 +02:00
|
|
|
|
CuAssertStrEquals(tc, "hurrdurr", getstrtoken());
|
|
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2014-08-17 14:24:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-07 17:29:22 +02:00
|
|
|
|
static void test_parse_autostudy(CuTest *tc) {
|
|
|
|
|
char cmd[32];
|
|
|
|
|
order *ord;
|
|
|
|
|
struct locale * lang;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = get_or_create_locale("en");
|
|
|
|
|
locale_setstring(lang, mkname("skill", skillnames[SK_ENTERTAINMENT]), "Entertainment");
|
2018-09-09 15:13:20 +02:00
|
|
|
|
locale_setstring(lang, mkname("skill", skillnames[SK_MAGIC]), "Magic");
|
|
|
|
|
locale_setstring(lang, mkname("skill", skillnames[SK_TACTICS]), "Tactics");
|
2018-07-07 17:29:22 +02:00
|
|
|
|
locale_setstring(lang, keyword(K_STUDY), "STUDY");
|
|
|
|
|
locale_setstring(lang, keyword(K_AUTOSTUDY), "AUTOSTUDY");
|
|
|
|
|
locale_setstring(lang, parameters[P_AUTO], "AUTO");
|
|
|
|
|
init_locale(lang);
|
|
|
|
|
|
|
|
|
|
ord = parse_order("STUDY AUTO Entertainment", lang);
|
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
|
|
|
|
CuAssertIntEquals(tc, K_AUTOSTUDY, getkeyword(ord));
|
|
|
|
|
CuAssertStrEquals(tc, "AUTOSTUDY Entertainment", get_command(ord, lang, cmd, sizeof(cmd)));
|
|
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, K_AUTOSTUDY, init_order(ord, lang));
|
|
|
|
|
CuAssertStrEquals(tc, "Entertainment", getstrtoken());
|
|
|
|
|
free_order(ord);
|
2018-09-09 15:13:20 +02:00
|
|
|
|
|
|
|
|
|
ord = parse_order("STUDY AUTO Magic", lang);
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, getkeyword(ord));
|
|
|
|
|
CuAssertStrEquals(tc, "STUDY Magic", get_command(ord, lang, cmd, sizeof(cmd)));
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
|
|
ord = parse_order("STUDY AUTO Tactics", lang);
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, getkeyword(ord));
|
|
|
|
|
CuAssertStrEquals(tc, "STUDY Tactics", get_command(ord, lang, cmd, sizeof(cmd)));
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
2018-07-07 17:29:22 +02:00
|
|
|
|
test_teardown();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 14:24:19 +02:00
|
|
|
|
static void test_parse_make_temp(CuTest *tc) {
|
|
|
|
|
char cmd[32];
|
|
|
|
|
order *ord;
|
2014-12-12 11:13:25 +01:00
|
|
|
|
struct locale * lang;
|
2014-08-17 14:24:19 +02:00
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2014-12-12 11:13:25 +01:00
|
|
|
|
lang = get_or_create_locale("en");
|
2014-08-17 14:24:19 +02:00
|
|
|
|
locale_setstring(lang, keyword(K_MAKE), "MAKE");
|
|
|
|
|
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
|
2017-03-25 10:37:13 +01:00
|
|
|
|
locale_setstring(lang, parameters[P_TEMP], "TEMP");
|
2014-08-17 14:24:19 +02:00
|
|
|
|
init_locale(lang);
|
|
|
|
|
|
|
|
|
|
ord = parse_order("M T herp", lang);
|
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
|
|
|
|
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
|
2017-10-08 17:07:42 +02:00
|
|
|
|
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, lang, cmd, sizeof(cmd)));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
2018-07-07 17:29:22 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord, lang));
|
2014-08-17 14:24:19 +02:00
|
|
|
|
CuAssertStrEquals(tc, "herp", getstrtoken());
|
|
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2014-08-17 14:24:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_parse_maketemp(CuTest *tc) {
|
|
|
|
|
char cmd[32];
|
|
|
|
|
order *ord;
|
2015-10-14 20:48:01 +02:00
|
|
|
|
struct locale * lang;
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2014-08-17 14:24:19 +02:00
|
|
|
|
|
2015-10-14 20:48:01 +02:00
|
|
|
|
lang = get_or_create_locale("en");
|
2014-08-17 14:24:19 +02:00
|
|
|
|
locale_setstring(lang, keyword(K_MAKE), "MAKE");
|
|
|
|
|
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
|
|
|
|
|
locale_setstring(lang, "TEMP", "TEMP");
|
|
|
|
|
init_locale(lang);
|
|
|
|
|
|
|
|
|
|
ord = parse_order("MAKET herp", lang);
|
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
2017-10-08 17:07:42 +02:00
|
|
|
|
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, lang, cmd, sizeof(cmd)));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
|
2018-07-07 17:29:22 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord, lang));
|
2014-08-17 14:24:19 +02:00
|
|
|
|
CuAssertStrEquals(tc, "herp", getstrtoken());
|
|
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2014-08-17 14:24:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
static void test_init_order(CuTest *tc) {
|
2014-08-23 06:45:20 +02:00
|
|
|
|
order *ord;
|
2015-10-14 20:48:01 +02:00
|
|
|
|
struct locale * lang;
|
2014-08-23 06:45:20 +02:00
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2015-10-14 20:48:01 +02:00
|
|
|
|
|
|
|
|
|
lang = get_or_create_locale("en");
|
2014-08-23 06:45:20 +02:00
|
|
|
|
ord = create_order(K_MAKETEMP, lang, "hurr durr");
|
2018-07-07 17:29:22 +02:00
|
|
|
|
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord, lang));
|
2014-08-23 06:45:20 +02:00
|
|
|
|
CuAssertStrEquals(tc, "hurr", getstrtoken());
|
|
|
|
|
CuAssertStrEquals(tc, "durr", getstrtoken());
|
2015-10-13 15:45:38 +02:00
|
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2014-08-23 06:45:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
static void test_getstrtoken(CuTest *tc) {
|
2014-12-31 01:00:10 +01:00
|
|
|
|
init_tokens_str("hurr \"durr\" \"\" \'\'");
|
2014-08-23 06:45:20 +02:00
|
|
|
|
CuAssertStrEquals(tc, "hurr", getstrtoken());
|
|
|
|
|
CuAssertStrEquals(tc, "durr", getstrtoken());
|
2014-08-23 09:17:58 +02:00
|
|
|
|
CuAssertStrEquals(tc, "", getstrtoken());
|
|
|
|
|
CuAssertStrEquals(tc, "", getstrtoken());
|
|
|
|
|
CuAssertStrEquals(tc, 0, getstrtoken());
|
2014-12-22 14:21:24 +01:00
|
|
|
|
init_tokens_str(0);
|
2014-08-23 09:17:58 +02:00
|
|
|
|
CuAssertStrEquals(tc, 0, getstrtoken());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_skip_token(CuTest *tc) {
|
2014-12-31 01:00:10 +01:00
|
|
|
|
init_tokens_str("hurr \"durr\"");
|
2014-08-23 09:17:58 +02:00
|
|
|
|
skip_token();
|
|
|
|
|
CuAssertStrEquals(tc, "durr", getstrtoken());
|
|
|
|
|
CuAssertStrEquals(tc, 0, getstrtoken());
|
2014-08-23 06:45:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 11:52:31 +02:00
|
|
|
|
static void test_replace_order(CuTest *tc) {
|
|
|
|
|
order *orders = 0, *orig, *repl;
|
2015-10-14 20:49:30 +02:00
|
|
|
|
struct locale * lang;
|
2015-05-21 11:52:31 +02:00
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_setup();
|
2017-03-25 10:37:13 +01:00
|
|
|
|
lang = test_create_locale();
|
|
|
|
|
orig = create_order(K_MAKE, lang, NULL);
|
|
|
|
|
repl = create_order(K_ALLY, lang, NULL);
|
2015-05-21 11:52:31 +02:00
|
|
|
|
replace_order(&orders, orig, repl);
|
2018-10-14 11:48:21 +02:00
|
|
|
|
CuAssertPtrEquals(tc, NULL, orders);
|
2015-05-21 11:52:31 +02:00
|
|
|
|
orders = orig;
|
|
|
|
|
replace_order(&orders, orig, repl);
|
|
|
|
|
CuAssertPtrNotNull(tc, orders);
|
2018-10-14 11:48:21 +02:00
|
|
|
|
CuAssertPtrEquals(tc, NULL, orders->next);
|
2015-05-21 11:52:31 +02:00
|
|
|
|
CuAssertIntEquals(tc, getkeyword(repl), getkeyword(orders));
|
2015-10-14 20:56:09 +02:00
|
|
|
|
free_order(orders);
|
|
|
|
|
free_order(repl);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2015-05-21 11:52:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-25 10:37:13 +01:00
|
|
|
|
static void test_get_command(CuTest *tc) {
|
|
|
|
|
struct locale * lang;
|
|
|
|
|
order *ord;
|
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = test_create_locale();
|
|
|
|
|
ord = create_order(K_MAKE, lang, "iron");
|
2017-10-08 17:07:42 +02:00
|
|
|
|
CuAssertStrEquals(tc, "make iron", get_command(ord, lang, buf, sizeof(buf)));
|
2017-09-30 19:22:24 +02:00
|
|
|
|
ord->command |= CMD_QUIET;
|
2017-10-08 17:07:42 +02:00
|
|
|
|
CuAssertStrEquals(tc, "!make iron", get_command(ord, lang, buf, sizeof(buf)));
|
2017-09-30 19:22:24 +02:00
|
|
|
|
ord->command |= CMD_PERSIST;
|
2017-10-08 17:07:42 +02:00
|
|
|
|
CuAssertStrEquals(tc, "!@make iron", get_command(ord, lang, buf, sizeof(buf)));
|
2017-09-30 19:22:24 +02:00
|
|
|
|
ord->command = K_MAKE | CMD_PERSIST;
|
2017-10-08 17:07:42 +02:00
|
|
|
|
CuAssertStrEquals(tc, "@make iron", get_command(ord, lang, buf, sizeof(buf)));
|
2017-03-25 10:37:13 +01:00
|
|
|
|
free_order(ord);
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2017-03-25 10:37:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-30 19:35:40 +02:00
|
|
|
|
static void test_is_persistent(CuTest *tc) {
|
|
|
|
|
order *ord;
|
|
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = test_create_locale();
|
|
|
|
|
|
2017-09-30 19:44:39 +02:00
|
|
|
|
ord = parse_order("@invalid", lang);
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, ord);
|
2018-05-19 20:53:51 +02:00
|
|
|
|
free_order(ord);
|
2017-09-30 19:44:39 +02:00
|
|
|
|
|
|
|
|
|
ord = parse_order("give", lang);
|
|
|
|
|
CuAssertIntEquals(tc, K_GIVE, ord->command);
|
|
|
|
|
CuAssertTrue(tc, !is_persistent(ord));
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
|
|
ord = parse_order("@give", lang);
|
|
|
|
|
CuAssertTrue(tc, !is_repeated(K_GIVE));
|
|
|
|
|
CuAssertIntEquals(tc, K_GIVE | CMD_PERSIST, ord->command);
|
|
|
|
|
CuAssertTrue(tc, is_persistent(ord));
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
|
|
ord = parse_order("make", lang);
|
|
|
|
|
CuAssertTrue(tc, is_repeated(K_MAKE));
|
|
|
|
|
CuAssertIntEquals(tc, K_MAKE , ord->command);
|
|
|
|
|
CuAssertTrue(tc, is_persistent(ord));
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
2017-09-30 19:35:40 +02:00
|
|
|
|
ord = parse_order("@move", lang);
|
|
|
|
|
CuAssertIntEquals(tc, K_MOVE | CMD_PERSIST, ord->command);
|
|
|
|
|
CuAssertTrue(tc, !is_persistent(ord));
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
2017-09-30 19:44:39 +02:00
|
|
|
|
ord = parse_order("// comment", lang);
|
|
|
|
|
CuAssertTrue(tc, is_persistent(ord));
|
|
|
|
|
CuAssertIntEquals(tc, K_KOMMENTAR, ord->command);
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2017-09-30 19:44:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void test_is_silent(CuTest *tc) {
|
|
|
|
|
order *ord;
|
|
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = test_create_locale();
|
|
|
|
|
|
|
|
|
|
ord = parse_order("make", lang);
|
|
|
|
|
CuAssertIntEquals(tc, K_MAKE, ord->command);
|
|
|
|
|
CuAssertTrue(tc, !is_silent(ord));
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
|
|
ord = parse_order("!make", lang);
|
|
|
|
|
CuAssertIntEquals(tc, K_MAKE | CMD_QUIET, ord->command);
|
|
|
|
|
CuAssertTrue(tc, is_silent(ord));
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
2017-09-30 19:35:40 +02:00
|
|
|
|
ord = parse_order("@invalid", lang);
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, ord);
|
2018-05-19 20:53:51 +02:00
|
|
|
|
free_order(ord);
|
2017-09-30 19:35:40 +02:00
|
|
|
|
|
|
|
|
|
ord = parse_order("// comment", lang);
|
|
|
|
|
CuAssertTrue(tc, is_persistent(ord));
|
|
|
|
|
CuAssertIntEquals(tc, K_KOMMENTAR, ord->command);
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2017-09-30 19:35:40 +02:00
|
|
|
|
}
|
2017-10-09 20:33:47 +02:00
|
|
|
|
|
|
|
|
|
static void test_study_orders(CuTest *tc) {
|
|
|
|
|
order *ord;
|
|
|
|
|
struct locale *lang;
|
|
|
|
|
const char *s;
|
|
|
|
|
char token[16];
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = test_create_locale();
|
|
|
|
|
|
|
|
|
|
ord = create_order(K_STUDY, lang, skillname(SK_CROSSBOW, lang));
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, getkeyword(ord));
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, init_order(ord, lang));
|
|
|
|
|
s = gettoken(token, sizeof(token));
|
|
|
|
|
CuAssertStrEquals(tc, skillname(SK_CROSSBOW, lang), s);
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, (void *)getstrtoken());
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
|
|
ord = create_order(K_STUDY, lang, skillname(SK_MAGIC, lang));
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, getkeyword(ord));
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, init_order(ord, lang));
|
|
|
|
|
s = gettoken(token, sizeof(token));
|
|
|
|
|
CuAssertStrEquals(tc, skillname(SK_MAGIC, lang), s);
|
|
|
|
|
CuAssertPtrEquals(tc, NULL, (void *)getstrtoken());
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
|
|
|
|
ord = create_order(K_STUDY, lang, "%s 100", skillname(SK_MAGIC, lang));
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, getkeyword(ord));
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, init_order(ord, lang));
|
|
|
|
|
s = gettoken(token, sizeof(token));
|
|
|
|
|
CuAssertStrEquals(tc, skillname(SK_MAGIC, lang), s);
|
|
|
|
|
CuAssertIntEquals(tc, 100, getint());
|
|
|
|
|
free_order(ord);
|
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
|
test_teardown();
|
2017-10-09 20:33:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-16 21:49:24 +01:00
|
|
|
|
static void test_study_order(CuTest *tc) {
|
2018-03-16 19:52:54 +01:00
|
|
|
|
char token[32];
|
|
|
|
|
stream out;
|
|
|
|
|
unit *u;
|
|
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = get_or_create_locale("de");
|
|
|
|
|
locale_setstring(lang, mkname("skill", skillnames[SK_ALCHEMY]), "Alchemie");
|
|
|
|
|
locale_setstring(lang, "keyword::study", "LERNE");
|
|
|
|
|
init_keywords(lang);
|
|
|
|
|
init_skills(lang);
|
|
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
|
|
|
|
u->thisorder = create_order(K_STUDY, lang, "ALCH");
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, init_order(u->thisorder, lang));
|
|
|
|
|
CuAssertStrEquals(tc, skillname(SK_ALCHEMY, lang), gettoken(token, sizeof(token)));
|
|
|
|
|
|
2018-03-16 21:49:24 +01:00
|
|
|
|
CuAssertStrEquals(tc, "LERNE Alchemie", get_command(u->thisorder, lang, token, sizeof(token)));
|
|
|
|
|
|
2018-03-16 19:52:54 +01:00
|
|
|
|
mstream_init(&out);
|
|
|
|
|
stream_order(&out, u->thisorder, lang, true);
|
|
|
|
|
swrite("\n", 1, 1, &out);
|
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
|
out.api->readln(out.handle, token, sizeof(token));
|
|
|
|
|
CuAssertStrEquals(tc, "LERNE Alchemie", token);
|
|
|
|
|
mstream_done(&out);
|
|
|
|
|
|
|
|
|
|
test_teardown();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-17 12:55:26 +01:00
|
|
|
|
static void test_study_order_unknown(CuTest *tc) {
|
|
|
|
|
char token[32];
|
|
|
|
|
stream out;
|
|
|
|
|
unit *u;
|
|
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = get_or_create_locale("de");
|
|
|
|
|
locale_setstring(lang, "keyword::study", "LERNE");
|
|
|
|
|
init_keywords(lang);
|
|
|
|
|
init_skills(lang);
|
|
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
|
|
|
|
u->thisorder = create_order(K_STUDY, lang, "Schiffsbau");
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, init_order(u->thisorder, lang));
|
|
|
|
|
CuAssertStrEquals(tc, "Schiffsbau", gettoken(token, sizeof(token)));
|
|
|
|
|
|
|
|
|
|
CuAssertStrEquals(tc, "LERNE Schiffsbau", get_command(u->thisorder, lang, token, sizeof(token)));
|
|
|
|
|
|
|
|
|
|
mstream_init(&out);
|
|
|
|
|
stream_order(&out, u->thisorder, lang, true);
|
|
|
|
|
swrite("\n", 1, 1, &out);
|
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
|
out.api->readln(out.handle, token, sizeof(token));
|
|
|
|
|
CuAssertStrEquals(tc, "LERNE Schiffsbau", token);
|
|
|
|
|
mstream_done(&out);
|
|
|
|
|
|
|
|
|
|
test_teardown();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-16 21:49:24 +01:00
|
|
|
|
static void test_study_order_quoted(CuTest *tc) {
|
2018-03-16 19:52:54 +01:00
|
|
|
|
char token[32];
|
|
|
|
|
stream out;
|
|
|
|
|
unit *u;
|
|
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = get_or_create_locale("de");
|
|
|
|
|
locale_setstring(lang, mkname("skill", skillnames[SK_WEAPONLESS]), "Waffenloser Kampf");
|
|
|
|
|
locale_setstring(lang, "keyword::study", "LERNE");
|
|
|
|
|
init_keywords(lang);
|
|
|
|
|
init_skills(lang);
|
|
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
|
|
|
|
u->thisorder = create_order(K_STUDY, lang, "Waffenloser~Kampf");
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, init_order(u->thisorder, lang));
|
|
|
|
|
CuAssertStrEquals(tc, skillname(SK_WEAPONLESS, lang), gettoken(token, sizeof(token)));
|
|
|
|
|
|
2018-03-16 21:49:24 +01:00
|
|
|
|
CuAssertStrEquals(tc, "LERNE 'Waffenloser Kampf'", get_command(u->thisorder, lang, token, sizeof(token)));
|
|
|
|
|
|
2018-03-16 19:52:54 +01:00
|
|
|
|
mstream_init(&out);
|
|
|
|
|
stream_order(&out, u->thisorder, lang, true);
|
|
|
|
|
swrite("\n", 1, 1, &out);
|
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
|
out.api->readln(out.handle, token, sizeof(token));
|
|
|
|
|
CuAssertStrEquals(tc, "LERNE 'Waffenloser Kampf'", token);
|
|
|
|
|
mstream_done(&out);
|
|
|
|
|
|
|
|
|
|
test_teardown();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-17 12:55:26 +01:00
|
|
|
|
static void test_study_order_unknown_tilde(CuTest *tc) {
|
|
|
|
|
char token[32];
|
|
|
|
|
stream out;
|
|
|
|
|
unit *u;
|
|
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = get_or_create_locale("de");
|
|
|
|
|
locale_setstring(lang, "keyword::study", "LERNE");
|
|
|
|
|
init_keywords(lang);
|
|
|
|
|
init_skills(lang);
|
|
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
|
|
|
|
u->thisorder = create_order(K_STUDY, lang, "Waffenloser~Mampf");
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, init_order(u->thisorder, lang));
|
|
|
|
|
CuAssertStrEquals(tc, "Waffenloser Mampf", gettoken(token, sizeof(token)));
|
|
|
|
|
|
|
|
|
|
CuAssertStrEquals(tc, "LERNE Waffenloser~Mampf", get_command(u->thisorder, lang, token, sizeof(token)));
|
|
|
|
|
|
|
|
|
|
mstream_init(&out);
|
|
|
|
|
stream_order(&out, u->thisorder, lang, true);
|
|
|
|
|
swrite("\n", 1, 1, &out);
|
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
|
out.api->readln(out.handle, token, sizeof(token));
|
|
|
|
|
CuAssertStrEquals(tc, "LERNE Waffenloser~Mampf", token);
|
|
|
|
|
mstream_done(&out);
|
|
|
|
|
|
|
|
|
|
test_teardown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_study_order_unknown_quoted(CuTest *tc) {
|
|
|
|
|
char token[32];
|
|
|
|
|
stream out;
|
|
|
|
|
unit *u;
|
|
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = get_or_create_locale("de");
|
|
|
|
|
locale_setstring(lang, "keyword::study", "LERNE");
|
|
|
|
|
init_keywords(lang);
|
|
|
|
|
init_skills(lang);
|
|
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
|
|
|
|
u->thisorder = create_order(K_STUDY, lang, "'Waffenloser Dampf'");
|
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, init_order(u->thisorder, lang));
|
|
|
|
|
CuAssertStrEquals(tc, "Waffenloser Dampf", gettoken(token, sizeof(token)));
|
|
|
|
|
|
|
|
|
|
CuAssertStrEquals(tc, "LERNE 'Waffenloser Dampf'", get_command(u->thisorder, lang, token, sizeof(token)));
|
|
|
|
|
|
|
|
|
|
mstream_init(&out);
|
|
|
|
|
stream_order(&out, u->thisorder, lang, true);
|
|
|
|
|
swrite("\n", 1, 1, &out);
|
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
|
out.api->readln(out.handle, token, sizeof(token));
|
|
|
|
|
CuAssertStrEquals(tc, "LERNE 'Waffenloser Dampf'", token);
|
|
|
|
|
mstream_done(&out);
|
|
|
|
|
|
|
|
|
|
test_teardown();
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-21 13:27:02 +02:00
|
|
|
|
static void test_create_order_long(CuTest *tc) {
|
|
|
|
|
char buffer[2048];
|
|
|
|
|
order *ord;
|
|
|
|
|
struct locale *lang;
|
|
|
|
|
stream out;
|
|
|
|
|
const char * longstr = "// BESCHREIBEN EINHEIT \"In weià ƒ ƒ ƒ ƒ ƒ ƒ &#"
|
|
|
|
|
"131;ƒƒƒƒƒƒ?e GewÃ
"
|
|
|
|
|
"1;ƒƒƒƒƒƒƒƒƒÃƒƒƒ"
|
|
|
|
|
"ƒƒƒƒƒƒƒƒƒÃƒƒƒ&#"
|
|
|
|
|
"131;ƒƒƒƒƒƒ‚Ã
"
|
|
|
|
|
"1;ƒƒƒƒ‚Ã"
|
|
|
|
|
"ƒ‚ÂÃ&"
|
|
|
|
|
"#131;ƒƒƒ‚ÂÃ&#"
|
|
|
|
|
"131;ƒƒ‚ÂÂÃ&#"
|
|
|
|
|
"130;¢‚Ã&"
|
|
|
|
|
"#131;ƒ‚Ã"
|
|
|
|
|
"31;‚ÂÃ
"
|
|
|
|
|
"1;ƒƒƒƒƒƒƒ‚Ã"
|
|
|
|
|
"ƒƒƒ‚[...]hB��2�xa�Hv$P�xa��A���A��";
|
|
|
|
|
test_setup();
|
|
|
|
|
lang = test_create_locale();
|
|
|
|
|
ord = parse_order(longstr, lang);
|
|
|
|
|
CuAssertIntEquals(tc, 0, ord->command);
|
|
|
|
|
mstream_init(&out);
|
|
|
|
|
stream_order(&out, ord, lang, true);
|
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
|
out.api->readln(out.handle, buffer, sizeof(buffer));
|
2018-06-28 22:48:57 +02:00
|
|
|
|
CuAssertIntEquals(tc, 1026, strlen(buffer));
|
2018-05-21 13:27:02 +02:00
|
|
|
|
mstream_done(&out);
|
|
|
|
|
free_order(ord);
|
|
|
|
|
test_teardown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_crescape(CuTest *tc) {
|
|
|
|
|
char buffer[16];
|
|
|
|
|
const char *input = "12345678901234567890";
|
|
|
|
|
|
|
|
|
|
CuAssertStrEquals(tc, "1234", crescape("1234", buffer, 16));
|
|
|
|
|
CuAssertPtrEquals(tc, (void *)input, (void *)crescape(input, buffer, 16));
|
|
|
|
|
|
|
|
|
|
CuAssertStrEquals(tc, "\\\"1234\\\"", crescape("\"1234\"", buffer, 16));
|
|
|
|
|
CuAssertStrEquals(tc, "\\\"1234\\\"", buffer);
|
|
|
|
|
|
|
|
|
|
CuAssertStrEquals(tc, "\\\"1234", crescape("\"1234\"", buffer, 8));
|
|
|
|
|
|
|
|
|
|
/* unlike in C strings, only " and \ are escaped: */
|
|
|
|
|
CuAssertStrEquals(tc, "\\\"\\\\\n\r\'", crescape("\"\\\n\r\'", buffer, 16));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-16 23:23:37 +02:00
|
|
|
|
CuSuite *get_order_suite(void)
|
|
|
|
|
{
|
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
2018-05-21 13:27:02 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_crescape);
|
2014-08-16 23:23:37 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_create_order);
|
2018-05-21 13:27:02 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_create_order_long);
|
2017-10-09 20:33:47 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_study_orders);
|
2018-03-16 21:49:24 +01:00
|
|
|
|
SUITE_ADD_TEST(suite, test_study_order);
|
2018-03-17 12:55:26 +01:00
|
|
|
|
SUITE_ADD_TEST(suite, test_study_order_unknown);
|
|
|
|
|
SUITE_ADD_TEST(suite, test_study_order_unknown_tilde);
|
|
|
|
|
SUITE_ADD_TEST(suite, test_study_order_unknown_quoted);
|
2018-03-16 21:49:24 +01:00
|
|
|
|
SUITE_ADD_TEST(suite, test_study_order_quoted);
|
2014-08-16 23:23:37 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_parse_order);
|
2014-08-17 14:24:19 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_parse_make);
|
2018-07-07 17:29:22 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_parse_autostudy);
|
2014-08-17 14:24:19 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_parse_make_temp);
|
|
|
|
|
SUITE_ADD_TEST(suite, test_parse_maketemp);
|
2014-08-23 06:45:20 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_init_order);
|
2015-05-21 11:52:31 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_replace_order);
|
2014-08-23 09:17:58 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_skip_token);
|
|
|
|
|
SUITE_ADD_TEST(suite, test_getstrtoken);
|
2017-03-25 10:37:13 +01:00
|
|
|
|
SUITE_ADD_TEST(suite, test_get_command);
|
2017-09-30 19:35:40 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_is_persistent);
|
2017-09-30 19:44:39 +02:00
|
|
|
|
SUITE_ADD_TEST(suite, test_is_silent);
|
2014-08-16 23:23:37 +02:00
|
|
|
|
return suite;
|
|
|
|
|
}
|