From 18b113961675925d2c75a3320b969fe09e56a529 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 6 Jun 2021 16:31:07 +0200 Subject: [PATCH] test not sorting before building and ship owners. --- src/kernel/building.c | 2 +- src/sort.test.c | 67 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/kernel/building.c b/src/kernel/building.c index 2cb1a129c..c7e417d92 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -617,7 +617,7 @@ unit *building_owner(const building * bld) void building_update_owner(building * bld) { unit * owner = bld->_owner; - bld->_owner = building_owner_ex(bld, owner ? owner->faction : 0); + bld->_owner = building_owner_ex(bld, owner ? owner->faction : NULL); } const char *building_getname(const building * self) diff --git a/src/sort.test.c b/src/sort.test.c index 5e085ec2c..d8e0eadd3 100644 --- a/src/sort.test.c +++ b/src/sort.test.c @@ -1,9 +1,11 @@ #include "sort.h" +#include "kernel/building.h" #include "kernel/faction.h" #include "kernel/unit.h" #include "kernel/order.h" #include "kernel/region.h" +#include "kernel/ship.h" #include "util/base36.h" #include "util/keyword.h" @@ -57,10 +59,75 @@ static void test_sort_before(CuTest *tc) { test_teardown(); } +static void test_sort_before_owner(CuTest *tc) { + unit *u1, *u2; + faction *f; + region *r; + building *b; + ship *sh; + + test_setup(); + u1 = test_create_unit(f = test_create_faction(), r = test_create_plain(0, 0)); + b = test_create_building(r, NULL); + sh = test_create_ship(r, NULL); + + u2 = test_create_unit(f, r); + unit_addorder(u2, create_order(K_SORT, f->locale, "%s %s", + LOC(f->locale, parameters[P_BEFORE]), itoa36(u1->no))); + u1->building = b; + building_update_owner(b); + CuAssertPtrEquals(tc, u1, r->units); + CuAssertPtrEquals(tc, u2, u1->next); + CuAssertPtrEquals(tc, NULL, u2->next); + + /* nothing happens: */ + restack_units(); + CuAssertPtrEquals(tc, u1, r->units); + CuAssertPtrEquals(tc, u2, u1->next); + CuAssertPtrEquals(tc, NULL, u2->next); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error259")); + test_clear_messagelist(&f->msgs); + + /* u2 must be in the same building: */ + u2->building = b; + restack_units(); + CuAssertPtrEquals(tc, u1, r->units); + CuAssertPtrEquals(tc, u2, u1->next); + CuAssertPtrEquals(tc, NULL, u2->next); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error261")); + test_clear_messagelist(&f->msgs); + + u1->building = NULL; + u2->building = NULL; + building_update_owner(b); + u1->ship = sh; + ship_update_owner(sh); + + /* nothing happens: */ + restack_units(); + CuAssertPtrEquals(tc, u1, r->units); + CuAssertPtrEquals(tc, u2, u1->next); + CuAssertPtrEquals(tc, NULL, u2->next); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error259")); + test_clear_messagelist(&f->msgs); + + /* u2 must be in the same ship: */ + u2->ship = sh; + restack_units(); + CuAssertPtrEquals(tc, u1, r->units); + CuAssertPtrEquals(tc, u2, u1->next); + CuAssertPtrEquals(tc, NULL, u2->next); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error261")); + test_clear_messagelist(&f->msgs); + + test_teardown(); +} + CuSuite *get_sort_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_sort_before_owner); SUITE_ADD_TEST(suite, test_sort_after); SUITE_ADD_TEST(suite, test_sort_before); return suite;