From db5d9e069e55ebfb12565de069738945d99122a9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 16 Mar 2018 19:52:54 +0100 Subject: [PATCH] failing test for bug 2427: create_order(K_STUDY, ...) --- src/kernel/order.test.c | 62 +++++++++++++++++++++++++++++++++++++++++ storage | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/kernel/order.test.c b/src/kernel/order.test.c index 74679db6e..fe9c47b53 100644 --- a/src/kernel/order.test.c +++ b/src/kernel/order.test.c @@ -3,10 +3,14 @@ #include "order.h" #include +#include #include #include +#include +#include + #include #include #include @@ -331,11 +335,69 @@ static void test_study_orders(CuTest *tc) { test_teardown(); } +static void test_stream_order(CuTest *tc) { + 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))); + + 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(); +} + +static void test_stream_order_quoted(CuTest *tc) { + 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))); + + 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(); +} + CuSuite *get_order_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_create_order); SUITE_ADD_TEST(suite, test_study_orders); + SUITE_ADD_TEST(suite, test_stream_order); + SUITE_ADD_TEST(suite, test_stream_order_quoted); SUITE_ADD_TEST(suite, test_parse_order); SUITE_ADD_TEST(suite, test_parse_make); SUITE_ADD_TEST(suite, test_parse_make_temp); diff --git a/storage b/storage index d807ef5ce..5623ee652 160000 --- a/storage +++ b/storage @@ -1 +1 @@ -Subproject commit d807ef5ce64b3425b31fb440e0b93a4d233f517a +Subproject commit 5623ee6527e97af20c7d8efc03800b6fe1579744