forked from github/server
ship->owner not yet ready for primetime
better tests written
This commit is contained in:
parent
d12fe2dbed
commit
94ca9a1f98
2 changed files with 46 additions and 14 deletions
|
@ -289,7 +289,6 @@ void getshipweight(const ship * sh, int *sweight, int *scabins)
|
||||||
|
|
||||||
unit *shipowner(const ship * sh)
|
unit *shipowner(const ship * sh)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
|
||||||
unit *u;
|
unit *u;
|
||||||
unit *first = NULL;
|
unit *first = NULL;
|
||||||
|
|
||||||
|
@ -301,7 +300,7 @@ unit *shipowner(const ship * sh)
|
||||||
if (!first && u->number > 0)
|
if (!first && u->number > 0)
|
||||||
first = u;
|
first = u;
|
||||||
if (fval(u, UFL_OWNER) && u->number > 0)
|
if (fval(u, UFL_OWNER) && u->number > 0)
|
||||||
break;
|
return u;
|
||||||
if (u->number == 0)
|
if (u->number == 0)
|
||||||
freset(u, UFL_OWNER);
|
freset(u, UFL_OWNER);
|
||||||
}
|
}
|
||||||
|
@ -310,13 +309,9 @@ unit *shipowner(const ship * sh)
|
||||||
/* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit
|
/* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit
|
||||||
* nehmen. */
|
* nehmen. */
|
||||||
|
|
||||||
if (first && !u) {
|
if (first)
|
||||||
u = first;
|
fset(first, UFL_OWNER);
|
||||||
fset(u, UFL_OWNER);
|
return first;
|
||||||
}
|
|
||||||
assert(u==sh->owner);
|
|
||||||
#endif
|
|
||||||
return sh->owner;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_ship_reference(const struct ship *sh, struct storage *store)
|
void write_ship_reference(const struct ship *sh, struct storage *store)
|
||||||
|
|
|
@ -24,12 +24,46 @@ static void test_register_ship(CuTest * tc)
|
||||||
CuAssertPtrNotNull(tc, st_find("herp"));
|
CuAssertPtrNotNull(tc, st_find("herp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_shipowner(CuTest * tc)
|
static void test_shipowner_goes_to_next(CuTest * tc)
|
||||||
{
|
{
|
||||||
struct region *r;
|
struct region *r;
|
||||||
struct ship * sh;
|
struct ship *sh;
|
||||||
struct unit * u;
|
struct unit *u, *u2;
|
||||||
struct faction * f;
|
struct faction *f;
|
||||||
|
const struct ship_type *stype;
|
||||||
|
const struct race *human;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
|
||||||
|
human = rc_find("human");
|
||||||
|
CuAssertPtrNotNull(tc, human);
|
||||||
|
|
||||||
|
stype = st_find("boat");
|
||||||
|
CuAssertPtrNotNull(tc, stype);
|
||||||
|
|
||||||
|
f = test_create_faction(human);
|
||||||
|
r = findregion(0, 0);
|
||||||
|
|
||||||
|
sh = test_create_ship(r, stype);
|
||||||
|
CuAssertPtrNotNull(tc, sh);
|
||||||
|
|
||||||
|
u = test_create_unit(f, r);
|
||||||
|
u2 = test_create_unit(f, r);
|
||||||
|
CuAssertPtrNotNull(tc, u);
|
||||||
|
u_set_ship(u, sh);
|
||||||
|
u_set_ship(u2, sh);
|
||||||
|
CuAssertPtrEquals(tc, u, shipowner(sh));
|
||||||
|
u->number = 0;
|
||||||
|
CuAssertPtrEquals(tc, u2, shipowner(sh));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_shipowner_resets_when_dead(CuTest * tc)
|
||||||
|
{
|
||||||
|
struct region *r;
|
||||||
|
struct ship *sh;
|
||||||
|
struct unit *u;
|
||||||
|
struct faction *f;
|
||||||
const struct ship_type *stype;
|
const struct ship_type *stype;
|
||||||
const struct race *human;
|
const struct race *human;
|
||||||
|
|
||||||
|
@ -52,12 +86,15 @@ static void test_shipowner(CuTest * tc)
|
||||||
CuAssertPtrNotNull(tc, u);
|
CuAssertPtrNotNull(tc, u);
|
||||||
u_set_ship(u, sh);
|
u_set_ship(u, sh);
|
||||||
CuAssertPtrEquals(tc, u, shipowner(sh));
|
CuAssertPtrEquals(tc, u, shipowner(sh));
|
||||||
|
u->number = 0;
|
||||||
|
CuAssertPtrEquals(tc, 0, shipowner(sh));
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite *get_ship_suite(void)
|
CuSuite *get_ship_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_register_ship);
|
SUITE_ADD_TEST(suite, test_register_ship);
|
||||||
SUITE_ADD_TEST(suite, test_shipowner);
|
SUITE_ADD_TEST(suite, test_shipowner_resets_when_dead);
|
||||||
|
SUITE_ADD_TEST(suite, test_shipowner_goes_to_next);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue