forked from github/server
fix build_building tests, require an order argument.
test current replace_order behavior.
This commit is contained in:
parent
b3214a1bf8
commit
cf88280595
|
@ -204,7 +204,8 @@ static void test_build_building_no_materials(CuTest *tc) {
|
||||||
btype = bt_find("castle");
|
btype = bt_find("castle");
|
||||||
assert(btype);
|
assert(btype);
|
||||||
set_level(u, SK_BUILDING, 1);
|
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->region->buildings);
|
||||||
CuAssertPtrEquals(tc, 0, u->building);
|
CuAssertPtrEquals(tc, 0, u->building);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
@ -222,7 +223,8 @@ static void test_build_building_with_golem(CuTest *tc) {
|
||||||
assert(btype->construction);
|
assert(btype->construction);
|
||||||
|
|
||||||
set_level(bf.u, SK_BUILDING, 1);
|
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);
|
CuAssertPtrNotNull(tc, u->region->buildings);
|
||||||
CuAssertIntEquals(tc, 1, u->region->buildings->size);
|
CuAssertIntEquals(tc, 1, u->region->buildings->size);
|
||||||
CuAssertIntEquals(tc, 0, u->number);
|
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);
|
i_change(&bf.u->items, rtype->itype, 1);
|
||||||
set_level(u, SK_BUILDING, 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);
|
CuAssertPtrNotNull(tc, u->region->buildings);
|
||||||
CuAssertPtrEquals(tc, u->region->buildings, u->building);
|
CuAssertPtrEquals(tc, u->region->buildings, u->building);
|
||||||
CuAssertIntEquals(tc, 1, u->building->size);
|
CuAssertIntEquals(tc, 1, u->building->size);
|
||||||
|
|
|
@ -65,6 +65,9 @@ static void release_data(order_data * data)
|
||||||
|
|
||||||
void replace_order(order ** dlist, order * orig, const order * src)
|
void replace_order(order ** dlist, order * orig, const order * src)
|
||||||
{
|
{
|
||||||
|
assert(src);
|
||||||
|
assert(orig);
|
||||||
|
assert(dlist);
|
||||||
while (*dlist != NULL) {
|
while (*dlist != NULL) {
|
||||||
order *dst = *dlist;
|
order *dst = *dlist;
|
||||||
if (dst->data == orig->data) {
|
if (dst->data == orig->data) {
|
||||||
|
|
|
@ -143,6 +143,21 @@ static void test_skip_token(CuTest *tc) {
|
||||||
CuAssertStrEquals(tc, 0, getstrtoken());
|
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 *get_order_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
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_make_temp);
|
||||||
SUITE_ADD_TEST(suite, test_parse_maketemp);
|
SUITE_ADD_TEST(suite, test_parse_maketemp);
|
||||||
SUITE_ADD_TEST(suite, test_init_order);
|
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_skip_token);
|
||||||
SUITE_ADD_TEST(suite, test_getstrtoken);
|
SUITE_ADD_TEST(suite, test_getstrtoken);
|
||||||
return suite;
|
return suite;
|
||||||
|
|
Loading…
Reference in New Issue