#include #include "renumber.h" #include #include #include #include #include #include #include #include #include #include static void test_renumber_faction(CuTest *tc) { unit *u; int uno, no; const struct locale *lang; test_setup_ex(tc); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); no = u->faction->no; uno = (no > 1) ? no - 1 : no + 1; lang = u->faction->locale; u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_FACTION]), itoa36(uno)); renumber_cmd(u, u->thisorder); renumber_factions(); CuAssertIntEquals(tc, uno, u->faction->no); test_cleanup(); } static void test_renumber_faction_duplicate(CuTest *tc) { unit *u; faction *f, *f2; int no; const struct locale *lang; test_setup_ex(tc); f2 = test_create_faction(0); u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0)); no = f->no; lang = f->locale; u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_FACTION]), itoa36(f2->no)); renumber_cmd(u, u->thisorder); renumber_factions(); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "renumber_inuse")); CuAssertIntEquals(tc, no, u->faction->no); test_cleanup(); } static void test_renumber_building(CuTest *tc) { unit *u; int uno, no; const struct locale *lang; test_setup_ex(tc); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); u->building = test_create_building(u->region, 0); no = u->building->no; uno = (no > 1) ? no - 1 : no + 1; lang = u->faction->locale; u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_BUILDING]), itoa36(uno)); renumber_cmd(u, u->thisorder); CuAssertIntEquals(tc, uno, u->building->no); test_cleanup(); } static void test_renumber_building_duplicate(CuTest *tc) { unit *u; faction *f; int uno, no; const struct locale *lang; test_setup_ex(tc); u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0)); u->building = test_create_building(u->region, 0); uno = u->building->no; u->building = test_create_building(u->region, 0); no = u->building->no; lang = f->locale; u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_BUILDING]), itoa36(uno)); renumber_cmd(u, u->thisorder); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error115")); CuAssertIntEquals(tc, no, u->building->no); test_cleanup(); } static void test_renumber_ship(CuTest *tc) { unit *u; int uno, no; const struct locale *lang; test_setup_ex(tc); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); u->ship = test_create_ship(u->region, 0); no = u->ship->no; uno = (no > 1) ? no - 1 : no + 1; lang = u->faction->locale; u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_SHIP]), itoa36(uno)); renumber_cmd(u, u->thisorder); CuAssertIntEquals(tc, uno, u->ship->no); test_cleanup(); } static void test_renumber_ship_twice(CuTest *tc) { unit *u; int uno, no; const struct locale *lang; test_setup_ex(tc); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); u->ship = test_create_ship(u->region, 0); no = u->ship->no; uno = (no > 1) ? no - 1 : no + 1; lang = u->faction->locale; u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_SHIP]), itoa36(uno)); renumber_cmd(u, u->thisorder); CuAssertIntEquals(tc, uno, u->ship->no); free_order(u->thisorder); u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_SHIP]), itoa36(no)); renumber_cmd(u, u->thisorder); CuAssertIntEquals(tc, no, u->ship->no); test_cleanup(); } static void test_renumber_ship_duplicate(CuTest *tc) { unit *u; faction *f; int uno, no; const struct locale *lang; test_setup_ex(tc); u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0)); u->ship = test_create_ship(u->region, 0); uno = u->ship->no; u->ship = test_create_ship(u->region, 0); no = u->ship->no; lang = f->locale; u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_SHIP]), itoa36(uno)); renumber_cmd(u, u->thisorder); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error115")); CuAssertIntEquals(tc, no, u->ship->no); test_cleanup(); } static void test_renumber_unit(CuTest *tc) { unit *u; int uno, no; const struct locale *lang; test_setup_ex(tc); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); no = u->no; uno = (no > 1) ? no - 1 : no + 1; lang = u->faction->locale; u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_UNIT]), itoa36(uno)); renumber_cmd(u, u->thisorder); CuAssertIntEquals(tc, uno, u->no); CuAssertIntEquals(tc, -no, ualias(u)); test_cleanup(); } static void test_renumber_unit_duplicate(CuTest *tc) { unit *u, *u2; faction *f; int no; const struct locale *lang; test_setup_ex(tc); u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0)); no = u->no; u2 = test_create_unit(f, u->region); lang = f->locale; u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_UNIT]), itoa36(u2->no)); renumber_cmd(u, u->thisorder); CuAssertIntEquals(tc, no, u->no); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error115")); CuAssertIntEquals(tc, 0, ualias(u)); test_cleanup(); } static void test_renumber_unit_limit(CuTest *tc) { unit *u; faction *f; int no; const struct locale *lang; test_setup_ex(tc); u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0)); no = u->no; lang = f->locale; u->thisorder = create_order(K_NUMBER, lang, "%s 10000", LOC(lang, parameters[P_UNIT])); renumber_cmd(u, u->thisorder); CuAssertIntEquals(tc, no, u->no); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error114")); CuAssertIntEquals(tc, 0, ualias(u)); test_cleanup(); } static void test_renumber_unit_invalid(CuTest *tc) { unit *u; faction *f; int no; const struct locale *lang; test_setup_ex(tc); u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0)); no = u->no; lang = f->locale; u->thisorder = create_order(K_NUMBER, lang, "%s TEMP", LOC(lang, parameters[P_UNIT])); renumber_cmd(u, u->thisorder); CuAssertIntEquals(tc, no, u->no); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error116")); CuAssertIntEquals(tc, 0, ualias(u)); test_cleanup(); } CuSuite *get_renumber_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_renumber_unit); SUITE_ADD_TEST(suite, test_renumber_unit_limit); SUITE_ADD_TEST(suite, test_renumber_unit_duplicate); SUITE_ADD_TEST(suite, test_renumber_unit_invalid); SUITE_ADD_TEST(suite, test_renumber_building); SUITE_ADD_TEST(suite, test_renumber_building_duplicate); SUITE_ADD_TEST(suite, test_renumber_ship); SUITE_ADD_TEST(suite, test_renumber_ship_twice); SUITE_ADD_TEST(suite, test_renumber_ship_duplicate); SUITE_ADD_TEST(suite, test_renumber_faction); SUITE_ADD_TEST(suite, test_renumber_faction_duplicate); return suite; }