forked from github/server
test all the edge cases.
This commit is contained in:
parent
5c63d20ff7
commit
a067838fa0
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue