diff --git a/src/contact.c b/src/contact.c index 635bdbd3d..2cc320709 100644 --- a/src/contact.c +++ b/src/contact.c @@ -115,13 +115,13 @@ int contact_cmd(unit * u, order * ord) } else { /* old-style syntax, KONTAKTIERE foo */ - unit *u2; + unit *u2 = NULL; int n = 0; if (p == P_TEMP) { n = getid(); u2 = findnewunit(u->region, u->faction, n); } - else { + else if (str) { n = atoi36((const char *)str); u2 = findunit(n); } diff --git a/src/contact.test.c b/src/contact.test.c index 3a9cc355e..8c76ec7c7 100644 --- a/src/contact.test.c +++ b/src/contact.test.c @@ -74,11 +74,73 @@ static void test_contact_cmd(CuTest *tc) { test_teardown(); } +static void test_contact_cmd_invalid(CuTest *tc) { + struct unit *u; + struct region *r; + const struct locale *lang; + struct order *ord; + + test_setup(); + r = test_create_plain(0, 0); + u = test_create_unit(test_create_faction(NULL), r); + lang = u->faction->locale; + + /* KONTAKTIERE EINHEIT */ + ord = create_order(K_CONTACT, u->faction->locale, "%s %i", + LOC(lang, parameters[P_UNIT]), u->no + 1); + contact_cmd(u, ord); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "feedback_unit_not_found")); + free_order(ord); + test_clear_messages(u->faction); + + /* KONTAKTIERE EINHEIT TEMP */ + ord = create_order(K_CONTACT, u->faction->locale, "%s %s %i", + LOC(lang, parameters[P_UNIT]), LOC(lang, parameters[P_TEMP]), u->no + 1); + contact_cmd(u, ord); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "feedback_unit_not_found")); + free_order(ord); + test_clear_messages(u->faction); + + /* KONTAKTIERE EINHEIT TEMP */ + ord = create_order(K_CONTACT, u->faction->locale, "%s %s", + LOC(lang, parameters[P_UNIT]), LOC(lang, parameters[P_TEMP])); + contact_cmd(u, ord); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "feedback_unit_not_found")); + free_order(ord); + test_clear_messages(u->faction); + + /* KONTAKTIERE EINHEIT */ + ord = create_order(K_CONTACT, u->faction->locale, + LOC(lang, parameters[P_UNIT])); + contact_cmd(u, ord); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "feedback_unit_not_found")); + free_order(ord); + test_clear_messages(u->faction); + + /* KONTAKTIERE TEMP */ + ord = create_order(K_CONTACT, u->faction->locale, + LOC(lang, parameters[P_TEMP])); + contact_cmd(u, ord); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "feedback_unit_not_found")); + free_order(ord); + test_clear_messages(u->faction); + + /* KONTAKTIERE */ + ord = create_order(K_CONTACT, u->faction->locale, NULL); + contact_cmd(u, ord); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "feedback_unit_not_found")); + free_order(ord); + test_clear_messages(u->faction); + + test_teardown(); +} + CuSuite *get_contact_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_contact); SUITE_ADD_TEST(suite, test_contact_cmd); + SUITE_ADD_TEST(suite, test_contact_cmd_invalid); return suite; }