test all the edge cases.

This commit is contained in:
Enno Rehling 2017-09-30 19:44:39 +02:00
parent 5c63d20ff7
commit a067838fa0
4 changed files with 54 additions and 2 deletions

View File

@ -83,7 +83,7 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
variant var; variant var;
memset(args, 0, sizeof(args)); memset(args, 0, sizeof(args));
if (ord && (ord->command & CMD_QUIET)) { if (ord && is_silent(ord)) {
return NULL; return NULL;
} }

View File

@ -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) char *write_order(const order * ord, char *buffer, size_t size)
{ {
if (ord == 0) { if (ord == 0) {

View File

@ -61,6 +61,7 @@ extern "C" {
void set_order(order ** destp, order * src); void set_order(order ** destp, order * src);
char* get_command(const order *ord, char *buffer, size_t size); char* get_command(const order *ord, char *buffer, size_t size);
bool is_persistent(const order * ord); bool is_persistent(const order * ord);
bool is_silent(const order * ord);
bool is_exclusive(const order * ord); bool is_exclusive(const order * ord);
bool is_repeated(keyword_t kwd); bool is_repeated(keyword_t kwd);
bool is_long(keyword_t kwd); bool is_long(keyword_t kwd);

View File

@ -231,11 +231,57 @@ static void test_is_persistent(CuTest *tc) {
test_setup(); test_setup();
lang = test_create_locale(); 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); ord = parse_order("@move", lang);
CuAssertIntEquals(tc, K_MOVE | CMD_PERSIST, ord->command); CuAssertIntEquals(tc, K_MOVE | CMD_PERSIST, ord->command);
CuAssertTrue(tc, !is_persistent(ord)); CuAssertTrue(tc, !is_persistent(ord));
free_order(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); ord = parse_order("@invalid", lang);
CuAssertPtrEquals(tc, NULL, ord); CuAssertPtrEquals(tc, NULL, ord);
@ -246,7 +292,6 @@ static void test_is_persistent(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
CuSuite *get_order_suite(void) CuSuite *get_order_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
@ -261,5 +306,6 @@ CuSuite *get_order_suite(void)
SUITE_ADD_TEST(suite, test_getstrtoken); SUITE_ADD_TEST(suite, test_getstrtoken);
SUITE_ADD_TEST(suite, test_get_command); SUITE_ADD_TEST(suite, test_get_command);
SUITE_ADD_TEST(suite, test_is_persistent); SUITE_ADD_TEST(suite, test_is_persistent);
SUITE_ADD_TEST(suite, test_is_silent);
return suite; return suite;
} }