forked from github/server
fix reading and writing curses from test (crash)
fix read_game/write_game incomaptibility.
This commit is contained in:
parent
ce867af34f
commit
3c272fd53f
|
@ -49,7 +49,7 @@ void game_done(void)
|
|||
calendar_cleanup();
|
||||
#endif
|
||||
free_functions();
|
||||
free_curses();
|
||||
curses_done();
|
||||
kernel_done();
|
||||
}
|
||||
|
||||
|
|
|
@ -74,17 +74,19 @@ void c_clearflag(curse * c, unsigned int flags)
|
|||
|
||||
void chash(curse * c)
|
||||
{
|
||||
curse *old = cursehash[c->no % MAXENTITYHASH];
|
||||
int i = c->no % MAXENTITYHASH;
|
||||
|
||||
cursehash[c->no % MAXENTITYHASH] = c;
|
||||
c->nexthash = old;
|
||||
c->nexthash = cursehash[i];
|
||||
cursehash[i] = c;
|
||||
assert(c->nexthash != c);
|
||||
}
|
||||
|
||||
static void cunhash(curse * c)
|
||||
{
|
||||
curse **show;
|
||||
int i = c->no % MAXENTITYHASH;
|
||||
|
||||
for (show = &cursehash[c->no % MAXENTITYHASH]; *show;
|
||||
for (show = &cursehash[i]; *show;
|
||||
show = &(*show)->nexthash) {
|
||||
if ((*show)->no == c->no)
|
||||
break;
|
||||
|
@ -195,6 +197,7 @@ int curse_read(attrib * a, void *owner, gamedata *data)
|
|||
int flags;
|
||||
float flt;
|
||||
|
||||
assert(!c->no);
|
||||
READ_INT(store, &c->no);
|
||||
chash(c);
|
||||
READ_TOK(store, cursename, sizeof(cursename));
|
||||
|
@ -824,7 +827,7 @@ double destr_curse(curse * c, int cast_level, double force)
|
|||
return force;
|
||||
}
|
||||
|
||||
void free_curses(void) {
|
||||
void curses_done(void) {
|
||||
int i;
|
||||
for (i = 0; i != MAXCTHASH; ++i) {
|
||||
ql_free(cursetypes[i]);
|
||||
|
|
|
@ -216,7 +216,7 @@ extern "C" {
|
|||
int duration; /* Dauer der Verzauberung. Wird jede Runde vermindert */
|
||||
} curse;
|
||||
|
||||
void free_curses(void); /* de-register all curse-types */
|
||||
void curses_done(void); /* de-register all curse-types */
|
||||
|
||||
void curse_write(const struct attrib *a, const void *owner,
|
||||
struct storage *store);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/save.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/version.h>
|
||||
#include <util/attrib.h>
|
||||
|
@ -53,6 +54,11 @@ static void setup_curse(curse_fixture *fix, const char *name) {
|
|||
fix->c = create_curse(fix->u, &fix->r->attribs, ct_find(name), 1.0, 1, 1.0, 0);
|
||||
}
|
||||
|
||||
static void cleanup_curse(curse_fixture *fix) {
|
||||
// destroy_curse(fix->c);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_magicstreet(CuTest *tc) {
|
||||
curse_fixture fix;
|
||||
message *msg;
|
||||
|
@ -61,7 +67,7 @@ static void test_magicstreet(CuTest *tc) {
|
|||
msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0);
|
||||
CuAssertStrEquals(tc, "curseinfo::magicstreet", test_get_messagetype(msg));
|
||||
msg_release(msg);
|
||||
test_cleanup();
|
||||
cleanup_curse(&fix);
|
||||
}
|
||||
|
||||
static void test_magicstreet_warning(CuTest *tc) {
|
||||
|
@ -72,7 +78,7 @@ static void test_magicstreet_warning(CuTest *tc) {
|
|||
msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0);
|
||||
CuAssertStrEquals(tc, "curseinfo::magicstreetwarn", test_get_messagetype(msg));
|
||||
msg_release(msg);
|
||||
test_cleanup();
|
||||
cleanup_curse(&fix);
|
||||
}
|
||||
|
||||
static void test_good_dreams(CuTest *tc) {
|
||||
|
@ -83,7 +89,7 @@ static void test_good_dreams(CuTest *tc) {
|
|||
msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0);
|
||||
CuAssertStrEquals(tc, "curseinfo::gooddream", test_get_messagetype(msg));
|
||||
msg_release(msg);
|
||||
test_cleanup();
|
||||
cleanup_curse(&fix);
|
||||
}
|
||||
|
||||
static void test_bad_dreams(CuTest *tc) {
|
||||
|
@ -94,7 +100,7 @@ static void test_bad_dreams(CuTest *tc) {
|
|||
msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0);
|
||||
CuAssertStrEquals(tc, "curseinfo::baddream", test_get_messagetype(msg));
|
||||
msg_release(msg);
|
||||
test_cleanup();
|
||||
cleanup_curse(&fix);
|
||||
}
|
||||
|
||||
static void test_memstream(CuTest *tc) {
|
||||
|
@ -125,20 +131,31 @@ static void test_write_flag(CuTest *tc) {
|
|||
curse_fixture fix;
|
||||
gamedata data;
|
||||
storage store;
|
||||
region * r;
|
||||
curse * c;
|
||||
int uid;
|
||||
|
||||
mstream_init(&data.strm);
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
|
||||
setup_curse(&fix, "gbdream");
|
||||
fix.c->flags = 42 | CURSE_ISNEW;
|
||||
curse_write(fix.r->attribs, fix.r, &store);
|
||||
c = fix.c;
|
||||
r = fix.r;
|
||||
uid = r->uid;
|
||||
c->flags = CURSE_ISNEW;
|
||||
write_game(&data);
|
||||
free_gamedata();
|
||||
data.strm.api->rewind(data.strm.handle);
|
||||
curse_read(fix.r->attribs, fix.r, &data);
|
||||
CuAssertIntEquals(tc, 42 | CURSE_ISNEW, ((curse *) fix.r->attribs->data.v)->flags);
|
||||
read_game(&data);
|
||||
r = findregionbyid(uid);
|
||||
CuAssertPtrNotNull(tc, r);
|
||||
CuAssertPtrNotNull(tc, r->attribs);
|
||||
c = (curse *)r->attribs->data.v;
|
||||
CuAssertIntEquals(tc, CURSE_ISNEW, c->flags);
|
||||
|
||||
mstream_done(&data.strm);
|
||||
gamedata_done(&data);
|
||||
test_cleanup();
|
||||
cleanup_curse(&fix);
|
||||
}
|
||||
|
||||
CuSuite *get_curse_suite(void)
|
||||
|
|
|
@ -1842,6 +1842,7 @@ int writegame(const char *filename)
|
|||
fstream_init(&strm, F);
|
||||
binstore_init(&store, &strm);
|
||||
|
||||
WRITE_INT(&store, VERSION_BUILD);
|
||||
n = write_game(&gdata);
|
||||
binstore_done(&store);
|
||||
fstream_done(&strm);
|
||||
|
@ -1875,7 +1876,6 @@ int write_game(gamedata *data) {
|
|||
/* globale Variablen */
|
||||
assert(data->version <= MAX_VERSION && data->version >= MIN_VERSION);
|
||||
|
||||
WRITE_INT(store, VERSION_BUILD);
|
||||
WRITE_INT(store, game_id());
|
||||
WRITE_SECTION(store);
|
||||
|
||||
|
|
|
@ -107,6 +107,11 @@ static void test_readwrite_dead_faction_group(CuTest *tc) {
|
|||
group *g;
|
||||
ally *al;
|
||||
int fno;
|
||||
gamedata data;
|
||||
storage store;
|
||||
|
||||
mstream_init(&data.strm);
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
|
||||
test_cleanup();
|
||||
f = test_create_faction(0);
|
||||
|
@ -126,10 +131,11 @@ static void test_readwrite_dead_faction_group(CuTest *tc) {
|
|||
destroyfaction(&factions);
|
||||
CuAssertTrue(tc, !f->_alive);
|
||||
CuAssertPtrEquals(tc, f2, factions);
|
||||
writegame("test.dat");
|
||||
write_game(&data);
|
||||
free_gamedata();
|
||||
f = f2 = NULL;
|
||||
readgame("test.dat", false);
|
||||
data.strm.api->rewind(data.strm.handle);
|
||||
read_game(&data);
|
||||
CuAssertPtrEquals(tc, 0, findfaction(fno));
|
||||
f2 = factions;
|
||||
CuAssertPtrNotNull(tc, f2);
|
||||
|
@ -138,6 +144,8 @@ static void test_readwrite_dead_faction_group(CuTest *tc) {
|
|||
g = get_group(u);
|
||||
CuAssertPtrNotNull(tc, g);
|
||||
CuAssertPtrEquals(tc, 0, g->allies);
|
||||
mstream_done(&data.strm);
|
||||
gamedata_done(&data);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue