From 403b8a2e7ea878243a8101b392b5f122c0e067fb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Oct 2015 12:44:22 +0200 Subject: [PATCH] add mail_cmd tests for REGION --- src/laws.test.c | 33 +++++++++++++++++++++++++++++---- src/tests.c | 2 +- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index c7f974de9..87b455330 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1003,7 +1003,7 @@ static unit * setup_mail_cmd(void) { return test_create_unit(f, test_create_region(0, 0, 0)); } -static void test_mail_cmd(CuTest *tc) { +static void test_mail_unit(CuTest *tc) { order *ord; unit *u; @@ -1014,7 +1014,18 @@ static void test_mail_cmd(CuTest *tc) { test_cleanup(); } -static void test_mail_cmd_no_msg(CuTest *tc) { +static void test_mail_region(CuTest *tc) { + order *ord; + unit *u; + + u = setup_mail_cmd(); + ord = create_order(K_MAIL, u->faction->locale, "REGION 'Hodor!'", itoa36(u->no)); + mail_cmd(u, ord); + CuAssertPtrNotNull(tc, test_find_messagetype(u->region->msgs, "mail_result")); + test_cleanup(); +} + +static void test_mail_unit_no_msg(CuTest *tc) { unit *u; order *ord; @@ -1026,6 +1037,18 @@ static void test_mail_cmd_no_msg(CuTest *tc) { test_cleanup(); } +static void test_mail_region_no_msg(CuTest *tc) { + unit *u; + order *ord; + + u = setup_mail_cmd(); + ord = create_order(K_MAIL, u->faction->locale, "REGION"); + mail_cmd(u, ord); + CuAssertPtrEquals(tc, 0, test_find_messagetype(u->region->msgs, "mail_result")); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30")); + test_cleanup(); +} + CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -1070,8 +1093,10 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_force_leave_ships); SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean); SUITE_ADD_TEST(suite, test_peasant_luck_effect); - SUITE_ADD_TEST(suite, test_mail_cmd); - SUITE_ADD_TEST(suite, test_mail_cmd_no_msg); + SUITE_ADD_TEST(suite, test_mail_unit); + SUITE_ADD_TEST(suite, test_mail_region); + SUITE_ADD_TEST(suite, test_mail_unit_no_msg); + SUITE_ADD_TEST(suite, test_mail_region_no_msg); (void)test_luck_message; /* disabled, breaks on travis */ return suite; diff --git a/src/tests.c b/src/tests.c index bcbd18c29..82417e9d2 100644 --- a/src/tests.c +++ b/src/tests.c @@ -257,7 +257,7 @@ const char * test_get_messagetype(const message *msg) { struct message * test_find_messagetype(struct message_list *msgs, const char *name) { struct mlist *ml; - assert(msgs); + if (!msgs) return 0; for (ml = msgs->begin; ml; ml = ml->next) { if (strcmp(name, test_get_messagetype(ml->msg)) == 0) { return ml->msg;