clean up hastily written tests, eliminate duplicate code

This commit is contained in:
Enno Rehling 2015-10-11 12:38:05 +02:00
parent 99c385412a
commit 070ed1a941
1 changed files with 15 additions and 15 deletions

View File

@ -989,9 +989,7 @@ static void test_nmr_warnings(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_mail_cmd(CuTest *tc) { static unit * setup_mail_cmd(void) {
unit *u;
order *ord;
faction *f; faction *f;
struct locale *lang; struct locale *lang;
@ -999,30 +997,32 @@ static void test_mail_cmd(CuTest *tc) {
f = test_create_faction(0); f = test_create_faction(0);
f->locale = lang = get_or_create_locale("de"); f->locale = lang = get_or_create_locale("de");
locale_setstring(lang, parameters[P_UNIT], "EINHEIT"); locale_setstring(lang, parameters[P_UNIT], "EINHEIT");
locale_setstring(lang, parameters[P_REGION], "REGION");
locale_setstring(lang, parameters[P_FACTION], "PARTEI");
init_parameters(lang); init_parameters(lang);
u = test_create_unit(f, test_create_region(0, 0, 0)); return test_create_unit(f, test_create_region(0, 0, 0));
}
static void test_mail_cmd(CuTest *tc) {
order *ord;
unit *u;
u = setup_mail_cmd();
ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s 'Hodor!'", itoa36(u->no)); ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s 'Hodor!'", itoa36(u->no));
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "unitmessage")); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "unitmessage"));
test_cleanup(); test_cleanup();
} }
static void test_mail_cmd_no_msg(CuTest *tc) { static void test_mail_cmd_no_msg(CuTest *tc) {
unit *u; unit *u;
order *ord; order *ord;
faction *f;
struct locale *lang;
test_cleanup(); u = setup_mail_cmd();
f = test_create_faction(0);
f->locale = lang = get_or_create_locale("de");
locale_setstring(lang, parameters[P_UNIT], "EINHEIT");
init_parameters(lang);
u = test_create_unit(f, test_create_region(0, 0, 0));
ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s", itoa36(u->no)); ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s", itoa36(u->no));
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "unitmessage")); CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "unitmessage"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30")); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30"));
test_cleanup(); test_cleanup();
} }