add the build number to saves.

this should make future debugging sessions easier, telling us what bugs were or were not fixed at the time of an incident.
added a test to make sure data file can be read/written, and at a minimum, sets global data-version.
also clean up test framework a bit, and introduce a helpful macro.
This commit is contained in:
Enno Rehling 2014-08-14 05:06:36 +02:00
parent 911992b04d
commit 38352ef3bf
5 changed files with 74 additions and 32 deletions

View File

@ -3,6 +3,7 @@ project(kernel C)
SET(_TEST_FILES
build.test.c
config.test.c
save.test.c
ship.test.c
spell.test.c
ally.test.c

View File

@ -20,6 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "save.h"
#include "../build.h"
#include "alchemy.h"
#include "alliance.h"
#include "ally.h"
@ -1285,7 +1287,7 @@ faction *readfaction(struct gamedata * data)
READ_STR(data->store, name, sizeof(name));
f->passw = _strdup(name);
if (data->version < NOOVERRIDE_VERSION && data->version >= OVERRIDE_VERSION) {
if (data->version < NOOVERRIDE_VERSION) {
READ_STR(data->store, 0, 0);
}
@ -1487,6 +1489,11 @@ int readgame(const char *filename, int backup)
gdata.store = &store;
global.data_version = gdata.version; /* HACK: attribute::read does not have access to gamedata, only storage */
if (gdata.version >= BUILDNO_VERSION) {
int build;
READ_INT(&store, &build);
log_debug("data in %s created with build %d.", filename, build);
}
if (gdata.version >= SAVEGAMEID_VERSION) {
int gameid;
@ -1824,6 +1831,7 @@ int writegame(const char *filename)
/* globale Variablen */
WRITE_INT(&store, VERSION_BUILD);
WRITE_INT(&store, game_id());
WRITE_SECTION(&store);

27
src/kernel/save.test.c Normal file
View File

@ -0,0 +1,27 @@
#include <platform.h>
#include <kernel/config.h>
#include "save.h"
#include "version.h"
#include <CuTest.h>
#include <tests.h>
#include <stdio.h>
static void test_readwrite_data(CuTest * tc)
{
const char *filename = "test.dat";
char path[MAX_PATH];
sprintf(path, "%s/%s", datapath(), filename);
CuAssertIntEquals(tc, 0, writegame(filename));
CuAssertIntEquals(tc, 0, readgame(filename, 0));
CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version);
CuAssertIntEquals(tc, 0, remove(path));
}
CuSuite *get_save_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_readwrite_data);
return suite;
}

View File

@ -36,8 +36,8 @@
#define INTERIM_VERSION 309
#define NEWSKILL_VERSION 309
#define WATCHERS_VERSION 310
*/
#define OVERRIDE_VERSION 311
*/
#define CURSETYPE_VERSION 312 /* turn 287 */
#define ALLIANCES_VERSION 313
#define DBLINK_VERSION 314
@ -72,8 +72,9 @@
#define NOOVERRIDE_VERSION 341 /* turn 775, full spellbooks are stored for factions */
#define INTFLAGS_VERSION 342 /* turn 876, FFL_NPC is now bit 25, flags is an int */
#define SAVEGAMEID_VERSION 343 /* instead of XMLNAME, save the game.id parameter from the config */
#define BUILDNO_VERSION 344 /* storing the build number in the save */
#define MIN_VERSION CURSETYPE_VERSION /* minimal datafile we support */
#define RELEASE_VERSION SAVEGAMEID_VERSION /* current datafile */
#define RELEASE_VERSION BUILDNO_VERSION /* current datafile */
#define STREAM_VERSION 2 /* internal encoding of binary files */

View File

@ -5,6 +5,10 @@
#include <util/log.h>
#define ADD_TESTS(suite, name) \
CuSuite *get_##name##_suite(void); \
CuSuiteAddSuite(suite, get_##name##_suite())
CuSuite *get_tests_suite(void);
CuSuite *get_callback_suite(void);
CuSuite *get_jsonconf_suite(void);
@ -45,38 +49,39 @@ int RunAllTests(void)
kernel_init();
/* self-test */
CuSuiteAddSuite(suite, get_tests_suite());
CuSuiteAddSuite(suite, get_callback_suite());
CuSuiteAddSuite(suite, get_json_suite());
CuSuiteAddSuite(suite, get_jsonconf_suite());
CuSuiteAddSuite(suite, get_direction_suite());
CuSuiteAddSuite(suite, get_skill_suite());
CuSuiteAddSuite(suite, get_keyword_suite());
ADD_TESTS(suite, tests);
ADD_TESTS(suite, callback);
ADD_TESTS(suite, json);
ADD_TESTS(suite, jsonconf);
ADD_TESTS(suite, direction);
ADD_TESTS(suite, skill);
ADD_TESTS(suite, keyword);
/* util */
CuSuiteAddSuite(suite, get_config_suite());
CuSuiteAddSuite(suite, get_base36_suite());
CuSuiteAddSuite(suite, get_bsdstring_suite());
CuSuiteAddSuite(suite, get_functions_suite());
CuSuiteAddSuite(suite, get_umlaut_suite());
ADD_TESTS(suite, config);
ADD_TESTS(suite, base36);
ADD_TESTS(suite, bsdstring);
ADD_TESTS(suite, functions);
ADD_TESTS(suite, umlaut);
/* kernel */
CuSuiteAddSuite(suite, get_build_suite());
CuSuiteAddSuite(suite, get_pool_suite());
CuSuiteAddSuite(suite, get_curse_suite());
CuSuiteAddSuite(suite, get_equipment_suite());
CuSuiteAddSuite(suite, get_item_suite());
CuSuiteAddSuite(suite, get_magic_suite());
CuSuiteAddSuite(suite, get_move_suite());
CuSuiteAddSuite(suite, get_reports_suite());
CuSuiteAddSuite(suite, get_ship_suite());
CuSuiteAddSuite(suite, get_spellbook_suite());
CuSuiteAddSuite(suite, get_building_suite());
CuSuiteAddSuite(suite, get_spell_suite());
CuSuiteAddSuite(suite, get_battle_suite());
CuSuiteAddSuite(suite, get_ally_suite());
ADD_TESTS(suite, build);
ADD_TESTS(suite, pool);
ADD_TESTS(suite, curse);
ADD_TESTS(suite, equipment);
ADD_TESTS(suite, item);
ADD_TESTS(suite, magic);
ADD_TESTS(suite, move);
ADD_TESTS(suite, reports);
ADD_TESTS(suite, save);
ADD_TESTS(suite, ship);
ADD_TESTS(suite, spellbook);
ADD_TESTS(suite, building);
ADD_TESTS(suite, spell);
ADD_TESTS(suite, battle);
ADD_TESTS(suite, ally);
/* gamecode */
CuSuiteAddSuite(suite, get_market_suite());
CuSuiteAddSuite(suite, get_laws_suite());
CuSuiteAddSuite(suite, get_economy_suite());
ADD_TESTS(suite, market);
ADD_TESTS(suite, laws);
ADD_TESTS(suite, economy);
CuSuiteRun(suite);
CuSuiteSummary(suite, output);