static void test_write_flag(CuTest *tc) { curse_fixture fix; storage store; char buf[1024]; stream out = { 0 }; size_t len; mstream_init(&out); binstore_init(&store, &out); store.handle.data = &out; setup_curse(&fix, "gbdream"); fix.c->flags = 42 | CURSE_ISNEW; curse_write(fix.r->attribs, fix.r, &store); out.api->rewind(out.handle); len = out.api->read(out.handle, buf, sizeof(buf)); buf[len] = '\0'; out.api->rewind(out.handle); curse_read(fix.r->attribs, fix.r, &store); CuAssertIntEquals(tc, 42 | CURSE_ISNEW, ((curse *) fix.r->attribs->data.v)->flags); global.data_version = RELEASE_VERSION; CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version); mstream_done(&out); binstore_done(&store); test_cleanup(); }
static void test_group_readwrite(CuTest * tc) { faction * f; group *g; ally *al; storage store; FILE *F; stream strm; F = fopen("test.dat", "wb"); fstream_init(&strm, F); binstore_init(&store, &strm); test_cleanup(); test_create_world(); f = test_create_faction(0); g = new_group(f, "test", 42); al = ally_add(&g->allies, f); al->status = HELP_GIVE; write_groups(&store, f); binstore_done(&store); fstream_done(&strm); F = fopen("test.dat", "rb"); fstream_init(&strm, F); binstore_init(&store, &strm); f->groups = 0; free_group(g); read_groups(&store, f); binstore_done(&store); fstream_done(&strm); CuAssertPtrNotNull(tc, f->groups); CuAssertPtrNotNull(tc, f->groups->allies); CuAssertPtrEquals(tc, 0, f->groups->allies->next); CuAssertPtrEquals(tc, f, f->groups->allies->faction); CuAssertIntEquals(tc, HELP_GIVE, f->groups->allies->status); remove("test.dat"); test_cleanup(); }
static int tolua_storage_close(lua_State * L) { gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); binstore_done(data->store); return 0; }