From 043cb88d912acd3a9e87b9e205b73ab483cd5f51 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 7 Aug 2020 23:50:17 +0200 Subject: [PATCH] https://bugs.eressea.de/view.php?id=2629 make ship_ownernot test u->number, hope that wasn't important. --- src/kernel/ship.c | 6 +++--- src/kernel/ship.test.c | 16 +++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 55cddbba8..dd8752b12 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -514,9 +514,9 @@ unit *ship_owner(const ship * sh) { if (sh->number > 0) { unit *owner = sh->_owner; - if (!owner || (owner->ship != sh || owner->number <= 0)) { - unit * heir = ship_owner_ex(sh, owner ? owner->faction : 0); - return (heir && heir->number > 0) ? heir : 0; + if (!owner || owner->ship != sh) { + unit * heir = ship_owner_ex(sh, owner ? owner->faction : NULL); + return (heir && heir->number > 0) ? heir : NULL; } return owner; } diff --git a/src/kernel/ship.test.c b/src/kernel/ship.test.c index 174762182..1952e60a7 100644 --- a/src/kernel/ship.test.c +++ b/src/kernel/ship.test.c @@ -142,7 +142,7 @@ static void test_shipowner_goes_to_next_when_empty(CuTest * tc) u_set_ship(u, sh); u_set_ship(u2, sh); CuAssertPtrEquals(tc, u, ship_owner(sh)); - u->number = 0; + leave_ship(u); CuAssertPtrEquals(tc, u2, ship_owner(sh)); test_teardown(); } @@ -177,7 +177,7 @@ static void test_shipowner_goes_to_other_when_empty(CuTest * tc) u_set_ship(u, sh); u_set_ship(u2, sh); CuAssertPtrEquals(tc, u, ship_owner(sh)); - u->number = 0; + leave_ship(u); CuAssertPtrEquals(tc, u2, ship_owner(sh)); test_teardown(); } @@ -215,9 +215,9 @@ static void test_shipowner_goes_to_same_faction_when_empty(CuTest * tc) u_set_ship(u2, sh); u_set_ship(u3, sh); CuAssertPtrEquals(tc, u, ship_owner(sh)); - u->number = 0; + leave_ship(u); CuAssertPtrEquals(tc, u3, ship_owner(sh)); - u3->number = 0; + leave_ship(u3); CuAssertPtrEquals(tc, u2, ship_owner(sh)); test_teardown(); } @@ -362,10 +362,8 @@ static void test_shipowner_resets_when_empty(CuTest * tc) CuAssertPtrNotNull(tc, u); u_set_ship(u, sh); CuAssertPtrEquals(tc, u, ship_owner(sh)); - u->number = 0; + leave_ship(u); CuAssertPtrEquals(tc, NULL, ship_owner(sh)); - u->number = 1; - CuAssertPtrEquals(tc, u, ship_owner(sh)); test_teardown(); } @@ -401,12 +399,12 @@ void test_shipowner_goes_to_empty_unit_after_leave(CuTest * tc) u_set_ship(u3, sh); CuAssertPtrEquals(tc, u1, ship_owner(sh)); - u2->number = 0; + leave_ship(u2); leave_ship(u1); CuAssertPtrEquals(tc, u3, ship_owner(sh)); leave_ship(u3); CuAssertPtrEquals(tc, NULL, ship_owner(sh)); - u2->number = 1; + u2->ship = sh; CuAssertPtrEquals(tc, u2, ship_owner(sh)); test_teardown(); }