fix build_building tests, require an order argument.

test current replace_order behavior.
This commit is contained in:
Enno Rehling 2015-05-21 11:52:31 +02:00
parent b3214a1bf8
commit cf88280595
3 changed files with 25 additions and 3 deletions

View File

@ -204,7 +204,8 @@ static void test_build_building_no_materials(CuTest *tc) {
btype = bt_find("castle");
assert(btype);
set_level(u, SK_BUILDING, 1);
CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, 0));
u->orders = create_order(K_MAKE, u->faction->locale, 0);
CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, u->orders));
CuAssertPtrEquals(tc, 0, u->region->buildings);
CuAssertPtrEquals(tc, 0, u->building);
test_cleanup();
@ -222,7 +223,8 @@ static void test_build_building_with_golem(CuTest *tc) {
assert(btype->construction);
set_level(bf.u, SK_BUILDING, 1);
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 1, 0));
u->orders = create_order(K_MAKE, u->faction->locale, 0);
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 1, u->orders));
CuAssertPtrNotNull(tc, u->region->buildings);
CuAssertIntEquals(tc, 1, u->region->buildings->size);
CuAssertIntEquals(tc, 0, u->number);
@ -245,7 +247,8 @@ static void test_build_building_success(CuTest *tc) {
i_change(&bf.u->items, rtype->itype, 1);
set_level(u, SK_BUILDING, 1);
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, 0));
u->orders = create_order(K_MAKE, u->faction->locale, 0);
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, u->orders));
CuAssertPtrNotNull(tc, u->region->buildings);
CuAssertPtrEquals(tc, u->region->buildings, u->building);
CuAssertIntEquals(tc, 1, u->building->size);

View File

@ -65,6 +65,9 @@ static void release_data(order_data * data)
void replace_order(order ** dlist, order * orig, const order * src)
{
assert(src);
assert(orig);
assert(dlist);
while (*dlist != NULL) {
order *dst = *dlist;
if (dst->data == orig->data) {

View File

@ -143,6 +143,21 @@ static void test_skip_token(CuTest *tc) {
CuAssertStrEquals(tc, 0, getstrtoken());
}
static void test_replace_order(CuTest *tc) {
order *orders = 0, *orig, *repl;
struct locale * lang = get_or_create_locale("en");
orig = create_order(K_MAKE, lang, 0);
repl = create_order(K_ALLY, lang, 0);
replace_order(&orders, orig, repl);
CuAssertPtrEquals(tc, 0, orders);
orders = orig;
replace_order(&orders, orig, repl);
CuAssertPtrNotNull(tc, orders);
CuAssertPtrEquals(tc, 0, orders->next);
CuAssertIntEquals(tc, getkeyword(repl), getkeyword(orders));
}
CuSuite *get_order_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -152,6 +167,7 @@ CuSuite *get_order_suite(void)
SUITE_ADD_TEST(suite, test_parse_make_temp);
SUITE_ADD_TEST(suite, test_parse_maketemp);
SUITE_ADD_TEST(suite, test_init_order);
SUITE_ADD_TEST(suite, test_replace_order);
SUITE_ADD_TEST(suite, test_skip_token);
SUITE_ADD_TEST(suite, test_getstrtoken);
return suite;