diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index 3ee3cf056..2befe6733 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -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); diff --git a/src/kernel/order.c b/src/kernel/order.c index b72b8e6bd..20cce5853 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -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) { diff --git a/src/kernel/order.test.c b/src/kernel/order.test.c index 414dd87e7..6900da420 100644 --- a/src/kernel/order.test.c +++ b/src/kernel/order.test.c @@ -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;