2014-08-23 09:21:40 +02:00
|
|
|
#include <platform.h>
|
2014-08-16 23:23:37 +02:00
|
|
|
#include <config.h>
|
2014-08-17 14:24:19 +02:00
|
|
|
#include <kernel/config.h>
|
2014-08-16 23:23:37 +02:00
|
|
|
#include "order.h"
|
|
|
|
|
|
|
|
#include <util/parser.h>
|
|
|
|
#include <util/language.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>
|
|
|
|
|
|
|
|
static void test_create_order(CuTest *tc) {
|
|
|
|
char cmd[32];
|
|
|
|
order *ord;
|
2014-12-12 11:13:25 +01:00
|
|
|
struct locale * lang;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
lang = get_or_create_locale("en");
|
2014-08-16 23:23:37 +02:00
|
|
|
|
|
|
|
locale_setstring(lang, "keyword::move", "MOVE");
|
|
|
|
ord = create_order(K_MOVE, lang, "NORTH");
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
|
|
|
CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd)));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, init_order(ord));
|
2014-08-16 23:23:37 +02:00
|
|
|
CuAssertStrEquals(tc, "NORTH", getstrtoken());
|
|
|
|
free_order(ord);
|
2014-12-12 11:13:25 +01:00
|
|
|
test_cleanup();
|
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
|
|
|
|
2014-12-12 11:13:25 +01:00
|
|
|
test_cleanup();
|
|
|
|
lang = get_or_create_locale("en");
|
2014-08-16 23:23:37 +02:00
|
|
|
|
|
|
|
locale_setstring(lang, "keyword::move", "MOVE");
|
2014-10-23 16:14:01 +02:00
|
|
|
init_keyword(lang, K_MOVE, "MOVE");
|
2014-08-16 23:23:37 +02:00
|
|
|
ord = parse_order("MOVE NORTH", lang);
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
|
|
|
CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd)));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, init_order(ord));
|
2014-08-16 23:23:37 +02:00
|
|
|
CuAssertStrEquals(tc, "NORTH", getstrtoken());
|
|
|
|
free_order(ord);
|
2014-12-12 11:13:25 +01:00
|
|
|
test_cleanup();
|
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;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
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));
|
|
|
|
CuAssertStrEquals(tc, "MAKE hurrdurr", get_command(ord, cmd, sizeof(cmd)));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
|
|
CuAssertIntEquals(tc, K_MAKE, init_order(ord));
|
2014-08-17 14:24:19 +02:00
|
|
|
CuAssertStrEquals(tc, "hurrdurr", getstrtoken());
|
|
|
|
free_order(ord);
|
2014-12-12 11:13:25 +01:00
|
|
|
test_cleanup();
|
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
|
|
|
|
2014-12-12 11:13:25 +01:00
|
|
|
test_cleanup();
|
|
|
|
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("M T herp", lang);
|
|
|
|
CuAssertPtrNotNull(tc, ord);
|
|
|
|
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
|
|
|
|
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, cmd, sizeof(cmd)));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
|
|
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
|
2014-08-17 14:24:19 +02:00
|
|
|
CuAssertStrEquals(tc, "herp", getstrtoken());
|
|
|
|
free_order(ord);
|
2014-12-12 11:13:25 +01:00
|
|
|
test_cleanup();
|
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;
|
|
|
|
|
|
|
|
test_cleanup();
|
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);
|
|
|
|
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, cmd, sizeof(cmd)));
|
2014-08-23 09:17:58 +02:00
|
|
|
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
|
|
|
|
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
|
2014-08-17 14:24:19 +02:00
|
|
|
CuAssertStrEquals(tc, "herp", getstrtoken());
|
|
|
|
free_order(ord);
|
2015-10-14 20:48:01 +02:00
|
|
|
test_cleanup();
|
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
|
|
|
|
2015-10-14 20:48:01 +02:00
|
|
|
test_cleanup();
|
|
|
|
|
|
|
|
lang = get_or_create_locale("en");
|
2014-08-23 06:45:20 +02:00
|
|
|
ord = create_order(K_MAKETEMP, lang, "hurr durr");
|
2014-08-23 09:17:58 +02:00
|
|
|
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
|
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);
|
2015-10-14 20:48:01 +02:00
|
|
|
test_cleanup();
|
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
|
|
|
|
2015-10-14 20:49:30 +02:00
|
|
|
test_cleanup();
|
|
|
|
lang = get_or_create_locale("en");
|
2015-05-21 11:52:31 +02:00
|
|
|
orig = create_order(K_MAKE, lang, 0);
|
|
|
|
repl = create_order(K_ALLY, lang, 0);
|
|
|
|
replace_order(&orders, orig, repl);
|
|
|
|
CuAssertPtrEquals(tc, 0, orders);
|
|
|
|
orders = orig;
|
|
|
|
replace_order(&orders, orig, repl);
|
|
|
|
CuAssertPtrNotNull(tc, orders);
|
|
|
|
CuAssertPtrEquals(tc, 0, orders->next);
|
|
|
|
CuAssertIntEquals(tc, getkeyword(repl), getkeyword(orders));
|
2015-10-14 20:56:09 +02:00
|
|
|
free_order(orders);
|
|
|
|
free_order(repl);
|
2015-10-14 20:49:30 +02:00
|
|
|
test_cleanup();
|
2015-05-21 11:52:31 +02:00
|
|
|
}
|
|
|
|
|
2014-08-16 23:23:37 +02:00
|
|
|
CuSuite *get_order_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_create_order);
|
|
|
|
SUITE_ADD_TEST(suite, test_parse_order);
|
2014-08-17 14:24:19 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_parse_make);
|
|
|
|
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);
|
2014-08-16 23:23:37 +02:00
|
|
|
return suite;
|
|
|
|
}
|