2017-01-10 18:20:47 +01:00
|
|
|
#include <platform.h>
|
2016-11-16 20:03:34 +01:00
|
|
|
#include "renumber.h"
|
|
|
|
|
|
|
|
#include <tests.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/faction.h>
|
2016-11-16 20:41:48 +01:00
|
|
|
#include <kernel/building.h>
|
|
|
|
#include <kernel/ship.h>
|
2016-11-16 20:03:34 +01:00
|
|
|
#include <kernel/order.h>
|
|
|
|
#include <util/base36.h>
|
|
|
|
#include <util/language.h>
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <CuTest.h>
|
|
|
|
|
|
|
|
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);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-16 20:03:34 +01:00
|
|
|
}
|
|
|
|
|
2016-11-17 21:08:35 +01:00
|
|
|
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);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-17 21:08:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-16 20:41:48 +01:00
|
|
|
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);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-16 20:41:48 +01:00
|
|
|
}
|
|
|
|
|
2016-11-17 21:08:35 +01:00
|
|
|
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);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-17 21:08:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-16 20:41:48 +01:00
|
|
|
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);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-16 20:41:48 +01:00
|
|
|
}
|
|
|
|
|
2016-11-18 22:31:06 +01:00
|
|
|
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);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-18 22:31:06 +01:00
|
|
|
}
|
|
|
|
|
2016-11-17 21:08:35 +01:00
|
|
|
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);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-17 21:08:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-16 20:03:34 +01:00
|
|
|
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);
|
2016-11-17 21:08:35 +01:00
|
|
|
CuAssertIntEquals(tc, -no, ualias(u));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-17 21:08:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-17 21:08:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-17 21:08:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-11-16 20:03:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_renumber_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_renumber_unit);
|
2016-11-17 21:08:35 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_renumber_unit_limit);
|
|
|
|
SUITE_ADD_TEST(suite, test_renumber_unit_duplicate);
|
|
|
|
SUITE_ADD_TEST(suite, test_renumber_unit_invalid);
|
2016-11-16 20:41:48 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_renumber_building);
|
2016-11-17 21:08:35 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_renumber_building_duplicate);
|
2016-11-16 20:41:48 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_renumber_ship);
|
2016-11-18 22:31:06 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_renumber_ship_twice);
|
2016-11-17 21:08:35 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_renumber_ship_duplicate);
|
2016-11-16 20:03:34 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_renumber_faction);
|
2016-11-17 21:08:35 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_renumber_faction_duplicate);
|
2016-11-16 20:03:34 +01:00
|
|
|
return suite;
|
|
|
|
}
|