From a067838fa0384f73a0d6f1241df679dc068e835c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 30 Sep 2017 19:44:39 +0200 Subject: [PATCH] test all the edge cases. --- src/kernel/messages.c | 2 +- src/kernel/order.c | 5 +++++ src/kernel/order.h | 1 + src/kernel/order.test.c | 48 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 114a80559..f2a175269 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -83,7 +83,7 @@ struct message *msg_feedback(const struct unit *u, struct order *ord, variant var; memset(args, 0, sizeof(args)); - if (ord && (ord->command & CMD_QUIET)) { + if (ord && is_silent(ord)) { return NULL; } diff --git a/src/kernel/order.c b/src/kernel/order.c index 5c760b188..f40646a33 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -564,6 +564,11 @@ bool is_persistent(const order * ord) } } +bool is_silent(const order * ord) +{ + return (ord->command & CMD_QUIET) != 0; +} + char *write_order(const order * ord, char *buffer, size_t size) { if (ord == 0) { diff --git a/src/kernel/order.h b/src/kernel/order.h index 4911983f9..b9d235c88 100644 --- a/src/kernel/order.h +++ b/src/kernel/order.h @@ -61,6 +61,7 @@ extern "C" { void set_order(order ** destp, order * src); char* get_command(const order *ord, char *buffer, size_t size); bool is_persistent(const order * ord); + bool is_silent(const order * ord); bool is_exclusive(const order * ord); bool is_repeated(keyword_t kwd); bool is_long(keyword_t kwd); diff --git a/src/kernel/order.test.c b/src/kernel/order.test.c index b42c7bf74..71938ca7e 100644 --- a/src/kernel/order.test.c +++ b/src/kernel/order.test.c @@ -231,11 +231,57 @@ static void test_is_persistent(CuTest *tc) { test_setup(); lang = test_create_locale(); + ord = parse_order("@invalid", lang); + CuAssertPtrEquals(tc, NULL, ord); + + 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); + ord = parse_order("@move", lang); CuAssertIntEquals(tc, K_MOVE | CMD_PERSIST, ord->command); CuAssertTrue(tc, !is_persistent(ord)); free_order(ord); + ord = parse_order("// comment", lang); + CuAssertTrue(tc, is_persistent(ord)); + CuAssertIntEquals(tc, K_KOMMENTAR, ord->command); + free_order(ord); + + test_cleanup(); +} + + +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); + ord = parse_order("@invalid", lang); CuAssertPtrEquals(tc, NULL, ord); @@ -246,7 +292,6 @@ static void test_is_persistent(CuTest *tc) { test_cleanup(); } - CuSuite *get_order_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -261,5 +306,6 @@ CuSuite *get_order_suite(void) SUITE_ADD_TEST(suite, test_getstrtoken); SUITE_ADD_TEST(suite, test_get_command); SUITE_ADD_TEST(suite, test_is_persistent); + SUITE_ADD_TEST(suite, test_is_silent); return suite; }