reduce dependency on save.h

moving a_write* functions to attrib.h, which was most of the reason everyone and their mom include save.h
This commit is contained in:
Enno Rehling 2016-11-13 19:40:38 +01:00
parent 37bb9c7ae9
commit 11b122048b
33 changed files with 218 additions and 165 deletions

View File

@ -48,7 +48,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/faction.h>
#include <kernel/group.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/building.h>

View File

@ -24,7 +24,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/building.h>
#include <kernel/faction.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/unit.h>

View File

@ -20,7 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "iceberg.h"
#include <kernel/save.h>
#include <util/attrib.h>
attrib_type at_iceberg = {

View File

@ -20,7 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "key.h"
#include <kernel/save.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <storage.h>

View File

@ -20,7 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "movement.h"
#include <kernel/save.h>
#include <util/attrib.h>
#include <util/gamedata.h>

View File

@ -20,9 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "overrideroads.h"
#include <kernel/save.h>
#include <util/attrib.h>
attrib_type at_overrideroads = {
"roads_override", NULL, NULL, NULL, &a_writestring, &a_readstring
"roads_override", NULL, NULL, NULL, a_writestring, a_readstring
};

View File

@ -20,7 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "racename.h"
#include <kernel/save.h>
#include <util/attrib.h>
/* libc includes */

View File

@ -19,7 +19,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h>
#include <kernel/config.h>
#include "raceprefix.h"
#include <kernel/save.h>
#include <util/attrib.h>

View File

@ -19,7 +19,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h>
#include <kernel/config.h>
#include "reduceproduction.h"
#include <kernel/save.h>
#include <kernel/region.h>
#include <kernel/messages.h>
#include <util/message.h>

View File

@ -1,7 +1,6 @@
#include <platform.h>
#include <kernel/unit.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <util/attrib.h>
#include <attributes/stealth.h>

View File

@ -21,7 +21,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <util/attrib.h>
#include <util/gamedata.h>

View File

@ -28,7 +28,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/messages.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/terrain.h>
#include <kernel/terrainid.h>

View File

@ -57,7 +57,6 @@ without prior permission by the authors of Eressea.
#include <kernel/spellbook.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
#include <kernel/save.h>
/* util includes */
#include <util/attrib.h>
@ -70,6 +69,7 @@ without prior permission by the authors of Eressea.
#include <util/nrmessage.h>
#include <quicklist.h>
#include <filestream.h>
#include <stream.h>
/* libc includes */
#include <assert.h>
@ -177,7 +177,7 @@ static void print_items(FILE * F, item * items, const struct locale *lang)
}
static void
cr_output_curses(stream *out, const faction * viewer, const void *obj, objtype_t typ)
cr_output_curses(struct stream *out, const faction * viewer, const void *obj, objtype_t typ)
{
bool header = false;
attrib *a = NULL;

View File

@ -26,7 +26,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/region.h>
#include <kernel/faction.h>
#include <kernel/unit.h>
#include <kernel/save.h>
#include <kernel/curse.h>
#include <kernel/messages.h>
#include <kernel/ship.h>

View File

@ -3,7 +3,6 @@
#include "types.h"
#include "ally.h"
#include "save.h"
#include "unit.h"
#include "region.h"
#include "group.h"

View File

@ -28,7 +28,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "race.h"
#include "region.h"
#include "skill.h"
#include "save.h"
#include "lighthouse.h"
/* util includes */

View File

@ -29,7 +29,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "plane.h"
#include "race.h"
#include "region.h"
#include "save.h"
#include "spellbook.h"
#include "terrain.h"
#include "unit.h"

View File

@ -30,7 +30,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "pool.h"
#include "race.h"
#include "region.h"
#include "save.h"
#include "skill.h"
#include "terrain.h"
#include "unit.h"

View File

@ -32,7 +32,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "plane.h"
#include "region.h"
#include "resources.h"
#include "save.h"
#include "ship.h"
#include "terrain.h"
#include "terrainid.h"

View File

@ -93,6 +93,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* exported symbols symbols */
int firstx = 0, firsty = 0;
// TODO: is this still important?
int enc_gamedata = ENCODING_UTF8;
/* local symbols */
@ -2074,93 +2076,3 @@ int write_game(gamedata *data) {
return 0;
}
int a_readint(attrib * a, void *owner, struct gamedata *data)
{
int n;
READ_INT(data->store, &n);
if (a) a->data.i = n;
return AT_READ_OK;
}
void a_writeint(const attrib * a, const void *owner, struct storage *store)
{
WRITE_INT(store, a->data.i);
}
int a_readshorts(attrib * a, void *owner, struct gamedata *data)
{
int n;
READ_INT(data->store, &n);
a->data.sa[0] = (short)n;
READ_INT(data->store, &n);
a->data.sa[1] = (short)n;
return AT_READ_OK;
}
void a_writeshorts(const attrib * a, const void *owner, struct storage *store)
{
WRITE_INT(store, a->data.sa[0]);
WRITE_INT(store, a->data.sa[1]);
}
int a_readchars(attrib * a, void *owner, struct gamedata *data)
{
int i;
for (i = 0; i != 4; ++i) {
int n;
READ_INT(data->store, &n);
a->data.ca[i] = (char)n;
}
return AT_READ_OK;
}
void a_writechars(const attrib * a, const void *owner, struct storage *store)
{
int i;
for (i = 0; i != 4; ++i) {
WRITE_INT(store, a->data.ca[i]);
}
}
int a_readvoid(attrib * a, void *owner, struct gamedata *data)
{
return AT_READ_OK;
}
void a_writevoid(const attrib * a, const void *owner, struct storage *store)
{
}
int a_readstring(attrib * a, void *owner, struct gamedata *data)
{
char buf[DISPLAYSIZE];
char * result = 0;
int e;
size_t len = 0;
do {
e = READ_STR(data->store, buf, sizeof(buf));
if (result) {
result = realloc(result, len + DISPLAYSIZE - 1);
strcpy(result + len, buf);
len += DISPLAYSIZE - 1;
}
else {
result = _strdup(buf);
}
} while (e == ENOMEM);
a->data.v = result;
return AT_READ_OK;
}
void a_writestring(const attrib * a, const void *owner, struct storage *store)
{
assert(a->data.v);
WRITE_STR(store, (const char *)a->data.v);
}
void a_finalizestring(attrib * a)
{
free(a->data.v);
}

View File

@ -39,6 +39,8 @@ extern "C" {
* dass hier ein Fehler (fehlende ") vorliegt */
extern int data_version;
// TODO: is this *really* still in use?
extern int enc_gamedata;
int readorders(const char *filename);
@ -72,23 +74,6 @@ extern "C" {
void write_ship(struct gamedata *data, const struct ship *sh);
struct ship *read_ship(struct gamedata *data);
int a_readint(struct attrib *a, void *owner, struct gamedata *);
void a_writeint(const struct attrib *a, const void *owner,
struct storage *store);
int a_readshorts(struct attrib *a, void *owner, struct gamedata *);
void a_writeshorts(const struct attrib *a, const void *owner,
struct storage *store);
int a_readchars(struct attrib *a, void *owner, struct gamedata *);
void a_writechars(const struct attrib *a, const void *owner,
struct storage *store);
int a_readvoid(struct attrib *a, void *owner, struct gamedata *);
void a_writevoid(const struct attrib *a, const void *owner,
struct storage *);
int a_readstring(struct attrib *a, void *owner, struct gamedata *);
void a_writestring(const struct attrib *a, const void *owner,
struct storage *);
void a_finalizestring(struct attrib *a);
void create_backup(char *file);
int write_game(struct gamedata *data);

View File

@ -34,7 +34,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "region.h"
#include "spell.h"
#include "spellbook.h"
#include "save.h"
#include "ship.h"
#include "skill.h"
#include "terrain.h"

View File

@ -57,7 +57,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/resources.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/spell.h>
#include <kernel/spellbook.h>

View File

@ -38,7 +38,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/pool.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/terrain.h>
#include <kernel/terrainid.h>
#include <kernel/unit.h>

View File

@ -44,7 +44,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/render.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/terrain.h>
#include <kernel/terrainid.h>

View File

@ -63,7 +63,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/region.h>
#include <kernel/render.h>
#include <kernel/resources.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/spell.h>
#include <kernel/spellbook.h>
@ -85,6 +84,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <quicklist.h>
#include <util/rng.h>
#include <filestream.h>
#include <stream.h>
/* libc includes */
#include <assert.h>
@ -133,11 +133,11 @@ static char *gamedate_season(const struct locale *lang)
return buf;
}
void newline(stream *out) {
void newline(struct stream *out) {
sputs("", out);
}
void write_spaces(stream *out, size_t num) {
void write_spaces(struct stream *out, size_t num) {
static const char spaces[REPORTWIDTH] = " ";
while (num > 0) {
size_t bytes = (num > REPORTWIDTH) ? REPORTWIDTH : num;
@ -146,7 +146,7 @@ void write_spaces(stream *out, size_t num) {
}
}
static void centre(stream *out, const char *s, bool breaking)
static void centre(struct stream *out, const char *s, bool breaking)
{
/* Bei Namen die genau 80 Zeichen lang sind, kann es hier Probleme
* geben. Seltsamerweise wird i dann auf MAXINT oder aehnlich
@ -170,7 +170,7 @@ static void centre(stream *out, const char *s, bool breaking)
}
static void
paragraph(stream *out, const char *str, ptrdiff_t indent, int hanging_indent,
paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_indent,
char marker)
{
size_t length = REPORTWIDTH;
@ -248,7 +248,7 @@ static size_t write_spell_modifier(spell * sp, int flag, const char * str, bool
return 0;
}
void nr_spell_syntax(stream *out, spellbook_entry * sbe, const struct locale *lang)
void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct locale *lang)
{
int bytes;
char buf[4096];
@ -436,7 +436,7 @@ void nr_spell_syntax(stream *out, spellbook_entry * sbe, const struct locale *la
}
void nr_spell(stream *out, spellbook_entry * sbe, const struct locale *lang)
void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *lang)
{
int bytes, k, itemanz, costtyp;
char buf[4096];
@ -554,7 +554,7 @@ void nr_spell(stream *out, spellbook_entry * sbe, const struct locale *lang)
}
static void
nr_curses_i(stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj, attrib *a, int self)
nr_curses_i(struct stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj, attrib *a, int self)
{
for (; a; a = a->next) {
char buf[4096];
@ -582,7 +582,7 @@ nr_curses_i(stream *out, int indent, const faction *viewer, objtype_t typ, const
}
}
static void nr_curses(stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj)
static void nr_curses(struct stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj)
{
int self = 0;
attrib *a = NULL;
@ -652,7 +652,7 @@ static void nr_curses(stream *out, int indent, const faction *viewer, objtype_t
nr_curses_i(out, indent, viewer, typ, obj, a, self);
}
static void rps_nowrap(stream *out, const char *s)
static void rps_nowrap(struct stream *out, const char *s)
{
const char *x = s;
size_t indent = 0;
@ -675,7 +675,7 @@ static void rps_nowrap(stream *out, const char *s)
}
static void
nr_unit(stream *out, const faction * f, const unit * u, int indent, seen_mode mode)
nr_unit(struct stream *out, const faction * f, const unit * u, int indent, seen_mode mode)
{
attrib *a_otherfaction;
char marker;
@ -717,7 +717,7 @@ nr_unit(stream *out, const faction * f, const unit * u, int indent, seen_mode mo
}
static void
rp_messages(stream *out, message_list * msgs, faction * viewer, int indent,
rp_messages(struct stream *out, message_list * msgs, faction * viewer, int indent,
bool categorized)
{
nrsection *section;
@ -753,7 +753,7 @@ rp_messages(stream *out, message_list * msgs, faction * viewer, int indent,
}
}
static void rp_battles(stream *out, faction * f)
static void rp_battles(struct stream *out, faction * f)
{
if (f->battles != NULL) {
struct bmsg *bm = f->battles;
@ -773,7 +773,7 @@ static void rp_battles(stream *out, faction * f)
}
}
static void prices(stream *out, const region * r, const faction * f)
static void prices(struct stream *out, const region * r, const faction * f)
{
const luxury_type *sale = NULL;
struct demand *dmd;
@ -875,7 +875,7 @@ bool see_border(const connection * b, const faction * f, const region * r)
return cs;
}
static void describe(stream *out, const region * r, faction * f)
static void describe(struct stream *out, const region * r, faction * f)
{
int n;
bool dh;
@ -1268,7 +1268,7 @@ static void describe(stream *out, const region * r, faction * f)
}
}
static void statistics(stream *out, const region * r, const faction * f)
static void statistics(struct stream *out, const region * r, const faction * f)
{
const unit *u;
int number = 0, p = rpeasants(r);
@ -1620,7 +1620,7 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size)
*bufp = 0;
}
static void allies(stream *out, const faction * f)
static void allies(struct stream *out, const faction * f)
{
const group *g = f->groups;
char buf[16384];
@ -1649,7 +1649,7 @@ static void allies(stream *out, const faction * f)
}
}
static void guards(stream *out, const region * r, const faction * see)
static void guards(struct stream *out, const region * r, const faction * see)
{
/* die Partei see sieht dies; wegen
* "unbekannte Partei", wenn man es selbst ist... */
@ -1722,7 +1722,7 @@ static void guards(stream *out, const region * r, const faction * see)
}
}
static void rpline(stream *out)
static void rpline(struct stream *out)
{
static char line[REPORTWIDTH + 1];
if (line[0] != '-') {
@ -1732,7 +1732,7 @@ static void rpline(stream *out)
swrite(line, sizeof(char), sizeof(line), out);
}
static void list_address(stream *out, const faction * uf, quicklist * seenfactions)
static void list_address(struct stream *out, const faction * uf, quicklist * seenfactions)
{
int qi = 0;
quicklist *flist = seenfactions;
@ -1763,7 +1763,7 @@ static void list_address(stream *out, const faction * uf, quicklist * seenfactio
}
static void
nr_ship(stream *out, const region *r, const ship * sh, const faction * f,
nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f,
const unit * captain)
{
char buffer[8192], *bufp = buffer;
@ -1836,7 +1836,7 @@ nr_ship(stream *out, const region *r, const ship * sh, const faction * f,
}
static void
nr_building(stream *out, const region *r, const building *b, const faction *f)
nr_building(struct stream *out, const region *r, const building *b, const faction *f)
{
int i, bytes;
const char *name, *bname, *billusion = NULL;
@ -1908,7 +1908,7 @@ nr_building(stream *out, const region *r, const building *b, const faction *f)
}
}
static void nr_paragraph(stream *out, message * m, faction * f)
static void nr_paragraph(struct stream *out, message * m, faction * f)
{
int bytes;
char buf[4096], *bufp = buf;
@ -1924,14 +1924,14 @@ static void nr_paragraph(stream *out, message * m, faction * f)
}
typedef struct cb_data {
stream *out;
struct stream *out;
char *start, *writep;
size_t size;
const faction *f;
int maxtravel, counter;
} cb_data;
static void init_cb(cb_data *data, stream *out, char *buffer, size_t size, const faction *f) {
static void init_cb(cb_data *data, struct stream *out, char *buffer, size_t size, const faction *f) {
data->out = out;
data->writep = buffer;
data->start = buffer;
@ -1996,7 +1996,7 @@ static void cb_write_travelthru(region *r, unit *u, void *cbdata) {
}
}
void write_travelthru(stream *out, region *r, const faction *f)
void write_travelthru(struct stream *out, region *r, const faction *f)
{
int maxtravel;
char buf[8192];

View File

@ -47,7 +47,6 @@
#include <kernel/pool.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/spell.h>
#include <kernel/terrain.h>
@ -109,7 +108,7 @@
static double zero_effect = 0.0;
attrib_type at_wdwpyramid = {
"wdwpyramid", NULL, NULL, NULL, a_writevoid, a_readvoid
"wdwpyramid", NULL, NULL, NULL, NULL, NULL
};
/* ----------------------------------------------------------------------- */

View File

@ -8,7 +8,6 @@
#include <kernel/faction.h>
#include <kernel/messages.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>

View File

@ -22,7 +22,6 @@
#include <kernel/item.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/terrain.h>
#include <kernel/terrainid.h>
#include <kernel/unit.h>

View File

@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */
#include <kernel/unit.h>
#include <kernel/save.h>
#include <kernel/faction.h>
/* util includes */

View File

@ -29,6 +29,88 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
#include <stdlib.h>
int a_readint(attrib * a, void *owner, struct gamedata *data)
{
int n;
READ_INT(data->store, &n);
if (a) a->data.i = n;
return AT_READ_OK;
}
void a_writeint(const attrib * a, const void *owner, struct storage *store)
{
WRITE_INT(store, a->data.i);
}
int a_readshorts(attrib * a, void *owner, struct gamedata *data)
{
int n;
READ_INT(data->store, &n);
a->data.sa[0] = (short)n;
READ_INT(data->store, &n);
a->data.sa[1] = (short)n;
return AT_READ_OK;
}
void a_writeshorts(const attrib * a, const void *owner, struct storage *store)
{
WRITE_INT(store, a->data.sa[0]);
WRITE_INT(store, a->data.sa[1]);
}
int a_readchars(attrib * a, void *owner, struct gamedata *data)
{
int i;
for (i = 0; i != 4; ++i) {
int n;
READ_INT(data->store, &n);
a->data.ca[i] = (char)n;
}
return AT_READ_OK;
}
void a_writechars(const attrib * a, const void *owner, struct storage *store)
{
int i;
for (i = 0; i != 4; ++i) {
WRITE_INT(store, a->data.ca[i]);
}
}
#define DISPLAYSIZE 8192
int a_readstring(attrib * a, void *owner, struct gamedata *data)
{
char buf[DISPLAYSIZE];
char * result = 0;
int e;
size_t len = 0;
do {
e = READ_STR(data->store, buf, sizeof(buf));
if (result) {
result = realloc(result, len + DISPLAYSIZE - 1);
strcpy(result + len, buf);
len += DISPLAYSIZE - 1;
}
else {
result = _strdup(buf);
}
} while (e == ENOMEM);
a->data.v = result;
return AT_READ_OK;
}
void a_writestring(const attrib * a, const void *owner, struct storage *store)
{
assert(a->data.v);
WRITE_STR(store, (const char *)a->data.v);
}
void a_finalizestring(attrib * a)
{
free(a->data.v);
}
#define MAXATHASH 61
static attrib_type *at_hash[MAXATHASH];

View File

@ -81,6 +81,20 @@ extern "C" {
int a_read(struct gamedata *data, attrib ** attribs, void *owner);
void a_write(struct storage *store, const attrib * attribs, const void *owner);
int a_readint(struct attrib *a, void *owner, struct gamedata *);
void a_writeint(const struct attrib *a, const void *owner,
struct storage *store);
int a_readshorts(struct attrib *a, void *owner, struct gamedata *);
void a_writeshorts(const struct attrib *a, const void *owner,
struct storage *store);
int a_readchars(struct attrib *a, void *owner, struct gamedata *);
void a_writechars(const struct attrib *a, const void *owner,
struct storage *store);
int a_readstring(struct attrib *a, void *owner, struct gamedata *);
void a_writestring(const struct attrib *a, const void *owner,
struct storage *);
void a_finalizestring(struct attrib *a);
void attrib_done(void);
#define DEFAULT_AGE NULL

View File

@ -1,6 +1,10 @@
#include <platform.h>
#include "attrib.h"
#include <util/gamedata.h>
#include <storage.h>
#include <memstream.h>
#include <CuTest.h>
#include <tests.h>
@ -16,7 +20,6 @@ static void test_attrib_new(CuTest * tc)
CuAssertPtrEquals(tc, 0, a);
}
static void test_attrib_add(CuTest * tc)
{
attrib_type at_foo = { "foo" };
@ -52,7 +55,6 @@ static void test_attrib_remove_self(CuTest * tc) {
a_removeall(&alist, NULL);
}
static void test_attrib_removeall(CuTest * tc) {
const attrib_type at_foo = { "foo" };
const attrib_type at_bar = { "bar" };
@ -110,6 +112,86 @@ static void test_attrib_nexttype(CuTest * tc)
a_removeall(&alist, &at_bar);
}
static void test_attrib_rwstring(CuTest *tc) {
gamedata data;
storage store;
attrib a = { 0 };
test_setup();
a.data.v = _strdup("Hello World");
mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION);
a_writestring(&a, NULL, &store);
a_finalizestring(&a);
data.strm.api->rewind(data.strm.handle);
a_readstring(&a, NULL, &data);
CuAssertStrEquals(tc, "Hello World", (const char *)a.data.v);
mstream_done(&data.strm);
gamedata_done(&data);
test_cleanup();
}
static void test_attrib_rwint(CuTest *tc) {
gamedata data;
storage store;
attrib a = { 0 };
test_setup();
a.data.i = 42;
mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION);
a_writeint(&a, NULL, &store);
a.data.i = 0;
data.strm.api->rewind(data.strm.handle);
a_readint(&a, NULL, &data);
CuAssertIntEquals(tc, 42, a.data.i);
mstream_done(&data.strm);
gamedata_done(&data);
test_cleanup();
}
static void test_attrib_rwchars(CuTest *tc) {
gamedata data;
storage store;
attrib a = { 0 };
test_setup();
a.data.ca[0] = 1;
a.data.ca[3] = 42;
mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION);
a_writeint(&a, NULL, &store);
memset(a.data.ca, 42, 0);
data.strm.api->rewind(data.strm.handle);
a_readint(&a, NULL, &data);
CuAssertIntEquals(tc, 1, a.data.ca[0]);
CuAssertIntEquals(tc, 42, a.data.ca[3]);
mstream_done(&data.strm);
gamedata_done(&data);
test_cleanup();
}
static void test_attrib_rwshorts(CuTest *tc) {
gamedata data;
storage store;
attrib a = { 0 };
a.data.sa[0] = -4;
a.data.sa[1] = 42;
test_setup();
mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION);
a_writeint(&a, NULL, &store);
memset(a.data.ca, 42, 0);
data.strm.api->rewind(data.strm.handle);
a_readint(&a, NULL, &data);
CuAssertIntEquals(tc, -4, a.data.sa[0]);
CuAssertIntEquals(tc, 42, a.data.sa[1]);
mstream_done(&data.strm);
gamedata_done(&data);
test_cleanup();
}
CuSuite *get_attrib_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -119,5 +201,9 @@ CuSuite *get_attrib_suite(void)
SUITE_ADD_TEST(suite, test_attrib_removeall);
SUITE_ADD_TEST(suite, test_attrib_remove_self);
SUITE_ADD_TEST(suite, test_attrib_nexttype);
SUITE_ADD_TEST(suite, test_attrib_rwstring);
SUITE_ADD_TEST(suite, test_attrib_rwint);
SUITE_ADD_TEST(suite, test_attrib_rwchars);
SUITE_ADD_TEST(suite, test_attrib_rwshorts);
return suite;
}