forked from github/server
extract read_region and test that it fixes bad names.
This commit is contained in:
parent
ec787743f0
commit
663ad17b5a
|
@ -1125,6 +1125,17 @@ static region *readregion(struct gamedata *data, int x, int y)
|
|||
return r;
|
||||
}
|
||||
|
||||
region *read_region(gamedata *data)
|
||||
{
|
||||
storage *store = data->store;
|
||||
region *r;
|
||||
int x, y;
|
||||
READ_INT(store, &x);
|
||||
READ_INT(store, &y);
|
||||
r = readregion(data, x, y);
|
||||
return r;
|
||||
}
|
||||
|
||||
void writeregion(struct gamedata *data, const region * r)
|
||||
{
|
||||
assert(r);
|
||||
|
@ -1189,6 +1200,14 @@ void writeregion(struct gamedata *data, const region * r)
|
|||
WRITE_SECTION(data->store);
|
||||
}
|
||||
|
||||
void write_region(gamedata *data, const region *r)
|
||||
{
|
||||
storage *store = data->store;
|
||||
WRITE_INT(store, r->x);
|
||||
WRITE_INT(store, r->y);
|
||||
writeregion(data, r);
|
||||
}
|
||||
|
||||
static ally **addally(const faction * f, ally ** sfp, int aid, int state)
|
||||
{
|
||||
struct faction *af = findfaction(aid);
|
||||
|
@ -1344,10 +1363,6 @@ void _test_write_password(gamedata *data, const faction *f) {
|
|||
write_password(data, f);
|
||||
}
|
||||
|
||||
/** Reads a faction from a file.
|
||||
* This function requires no context, can be called in any state. The
|
||||
* faction may not already exist, however.
|
||||
*/
|
||||
faction *read_faction(struct gamedata * data)
|
||||
{
|
||||
ally **sfp;
|
||||
|
@ -1803,18 +1818,11 @@ int read_game(gamedata *data) {
|
|||
rmax = nread;
|
||||
}
|
||||
log_debug(" - Einzulesende Regionen: %d/%d\r", rmax, nread);
|
||||
|
||||
while (--nread >= 0) {
|
||||
unit **up;
|
||||
int x, y;
|
||||
READ_INT(store, &x);
|
||||
READ_INT(store, &y);
|
||||
|
||||
if ((nread & 0x3FF) == 0) { /* das spart extrem Zeit */
|
||||
log_debug(" - Einzulesende Regionen: %d/%d * %d,%d \r", rmax, nread, x, y);
|
||||
}
|
||||
--rmax;
|
||||
|
||||
r = readregion(data, x, y);
|
||||
r = read_region(data);
|
||||
|
||||
/* Burgen */
|
||||
READ_INT(store, &p);
|
||||
|
@ -1861,8 +1869,13 @@ int read_game(gamedata *data) {
|
|||
*up = u;
|
||||
up = &u->next;
|
||||
|
||||
update_interval(u->faction, u->region);
|
||||
update_interval(u->faction, r);
|
||||
}
|
||||
|
||||
if ((nread & 0x3FF) == 0) { /* das spart extrem Zeit */
|
||||
log_debug(" - Einzulesende Regionen: %d/%d * %d,%d \r", rmax, nread, r->x, r->y);
|
||||
}
|
||||
--rmax;
|
||||
}
|
||||
read_borders(data);
|
||||
|
||||
|
@ -2032,9 +2045,7 @@ int write_game(gamedata *data) {
|
|||
log_debug(" - Schreibe Regionen: %d", n);
|
||||
}
|
||||
WRITE_SECTION(store);
|
||||
WRITE_INT(store, r->x);
|
||||
WRITE_INT(store, r->y);
|
||||
writeregion(data, r);
|
||||
write_region(data, r);
|
||||
|
||||
WRITE_INT(store, listlen(r->buildings));
|
||||
WRITE_SECTION(store);
|
||||
|
|
|
@ -63,6 +63,9 @@ extern "C" {
|
|||
void write_faction(struct gamedata *data, const struct faction *f);
|
||||
struct faction *read_faction(struct gamedata *data);
|
||||
|
||||
void write_region(struct gamedata *data, const struct region *r);
|
||||
struct region *read_region(struct gamedata *data);
|
||||
|
||||
void write_building(struct gamedata *data, const struct building *b);
|
||||
struct building *read_building(struct gamedata *data);
|
||||
|
||||
|
|
|
@ -111,6 +111,34 @@ static void test_readwrite_faction(CuTest * tc)
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_readwrite_region(CuTest * tc)
|
||||
{
|
||||
gamedata data;
|
||||
storage store;
|
||||
region *r;
|
||||
|
||||
test_setup();
|
||||
r = test_create_region(0, 0, 0);
|
||||
free(r->land->name);
|
||||
r->land->name = _strdup(" Hodor ");
|
||||
CuAssertStrEquals(tc, " Hodor ", r->land->name);
|
||||
mstream_init(&data.strm);
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
write_region(&data, r);
|
||||
|
||||
data.strm.api->rewind(data.strm.handle);
|
||||
free_gamedata();
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
r = read_region(&data);
|
||||
CuAssertPtrNotNull(tc, r);
|
||||
CuAssertStrEquals(tc, "Hodor", r->land->name);
|
||||
regions = r;
|
||||
|
||||
mstream_done(&data.strm);
|
||||
gamedata_done(&data);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_readwrite_building(CuTest * tc)
|
||||
{
|
||||
gamedata data;
|
||||
|
@ -427,6 +455,7 @@ CuSuite *get_save_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_readwrite_data);
|
||||
SUITE_ADD_TEST(suite, test_readwrite_unit);
|
||||
SUITE_ADD_TEST(suite, test_readwrite_faction);
|
||||
SUITE_ADD_TEST(suite, test_readwrite_region);
|
||||
SUITE_ADD_TEST(suite, test_readwrite_building);
|
||||
SUITE_ADD_TEST(suite, test_readwrite_ship);
|
||||
SUITE_ADD_TEST(suite, test_readwrite_dead_faction_createunit);
|
||||
|
|
Loading…
Reference in New Issue