forked from github/server
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:
parent
911992b04d
commit
38352ef3bf
|
@ -3,6 +3,7 @@ project(kernel C)
|
||||||
SET(_TEST_FILES
|
SET(_TEST_FILES
|
||||||
build.test.c
|
build.test.c
|
||||||
config.test.c
|
config.test.c
|
||||||
|
save.test.c
|
||||||
ship.test.c
|
ship.test.c
|
||||||
spell.test.c
|
spell.test.c
|
||||||
ally.test.c
|
ally.test.c
|
||||||
|
|
|
@ -20,6 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "save.h"
|
#include "save.h"
|
||||||
|
|
||||||
|
#include "../build.h"
|
||||||
|
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
#include "alliance.h"
|
#include "alliance.h"
|
||||||
#include "ally.h"
|
#include "ally.h"
|
||||||
|
@ -1285,7 +1287,7 @@ faction *readfaction(struct gamedata * data)
|
||||||
|
|
||||||
READ_STR(data->store, name, sizeof(name));
|
READ_STR(data->store, name, sizeof(name));
|
||||||
f->passw = _strdup(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);
|
READ_STR(data->store, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1487,6 +1489,11 @@ int readgame(const char *filename, int backup)
|
||||||
gdata.store = &store;
|
gdata.store = &store;
|
||||||
global.data_version = gdata.version; /* HACK: attribute::read does not have access to gamedata, only storage */
|
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) {
|
if (gdata.version >= SAVEGAMEID_VERSION) {
|
||||||
int gameid;
|
int gameid;
|
||||||
|
|
||||||
|
@ -1824,6 +1831,7 @@ int writegame(const char *filename)
|
||||||
|
|
||||||
/* globale Variablen */
|
/* globale Variablen */
|
||||||
|
|
||||||
|
WRITE_INT(&store, VERSION_BUILD);
|
||||||
WRITE_INT(&store, game_id());
|
WRITE_INT(&store, game_id());
|
||||||
WRITE_SECTION(&store);
|
WRITE_SECTION(&store);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -36,8 +36,8 @@
|
||||||
#define INTERIM_VERSION 309
|
#define INTERIM_VERSION 309
|
||||||
#define NEWSKILL_VERSION 309
|
#define NEWSKILL_VERSION 309
|
||||||
#define WATCHERS_VERSION 310
|
#define WATCHERS_VERSION 310
|
||||||
*/
|
|
||||||
#define OVERRIDE_VERSION 311
|
#define OVERRIDE_VERSION 311
|
||||||
|
*/
|
||||||
#define CURSETYPE_VERSION 312 /* turn 287 */
|
#define CURSETYPE_VERSION 312 /* turn 287 */
|
||||||
#define ALLIANCES_VERSION 313
|
#define ALLIANCES_VERSION 313
|
||||||
#define DBLINK_VERSION 314
|
#define DBLINK_VERSION 314
|
||||||
|
@ -72,8 +72,9 @@
|
||||||
#define NOOVERRIDE_VERSION 341 /* turn 775, full spellbooks are stored for factions */
|
#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 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 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 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 */
|
#define STREAM_VERSION 2 /* internal encoding of binary files */
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
#include <util/log.h>
|
#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_tests_suite(void);
|
||||||
CuSuite *get_callback_suite(void);
|
CuSuite *get_callback_suite(void);
|
||||||
CuSuite *get_jsonconf_suite(void);
|
CuSuite *get_jsonconf_suite(void);
|
||||||
|
@ -45,38 +49,39 @@ int RunAllTests(void)
|
||||||
kernel_init();
|
kernel_init();
|
||||||
|
|
||||||
/* self-test */
|
/* self-test */
|
||||||
CuSuiteAddSuite(suite, get_tests_suite());
|
ADD_TESTS(suite, tests);
|
||||||
CuSuiteAddSuite(suite, get_callback_suite());
|
ADD_TESTS(suite, callback);
|
||||||
CuSuiteAddSuite(suite, get_json_suite());
|
ADD_TESTS(suite, json);
|
||||||
CuSuiteAddSuite(suite, get_jsonconf_suite());
|
ADD_TESTS(suite, jsonconf);
|
||||||
CuSuiteAddSuite(suite, get_direction_suite());
|
ADD_TESTS(suite, direction);
|
||||||
CuSuiteAddSuite(suite, get_skill_suite());
|
ADD_TESTS(suite, skill);
|
||||||
CuSuiteAddSuite(suite, get_keyword_suite());
|
ADD_TESTS(suite, keyword);
|
||||||
/* util */
|
/* util */
|
||||||
CuSuiteAddSuite(suite, get_config_suite());
|
ADD_TESTS(suite, config);
|
||||||
CuSuiteAddSuite(suite, get_base36_suite());
|
ADD_TESTS(suite, base36);
|
||||||
CuSuiteAddSuite(suite, get_bsdstring_suite());
|
ADD_TESTS(suite, bsdstring);
|
||||||
CuSuiteAddSuite(suite, get_functions_suite());
|
ADD_TESTS(suite, functions);
|
||||||
CuSuiteAddSuite(suite, get_umlaut_suite());
|
ADD_TESTS(suite, umlaut);
|
||||||
/* kernel */
|
/* kernel */
|
||||||
CuSuiteAddSuite(suite, get_build_suite());
|
ADD_TESTS(suite, build);
|
||||||
CuSuiteAddSuite(suite, get_pool_suite());
|
ADD_TESTS(suite, pool);
|
||||||
CuSuiteAddSuite(suite, get_curse_suite());
|
ADD_TESTS(suite, curse);
|
||||||
CuSuiteAddSuite(suite, get_equipment_suite());
|
ADD_TESTS(suite, equipment);
|
||||||
CuSuiteAddSuite(suite, get_item_suite());
|
ADD_TESTS(suite, item);
|
||||||
CuSuiteAddSuite(suite, get_magic_suite());
|
ADD_TESTS(suite, magic);
|
||||||
CuSuiteAddSuite(suite, get_move_suite());
|
ADD_TESTS(suite, move);
|
||||||
CuSuiteAddSuite(suite, get_reports_suite());
|
ADD_TESTS(suite, reports);
|
||||||
CuSuiteAddSuite(suite, get_ship_suite());
|
ADD_TESTS(suite, save);
|
||||||
CuSuiteAddSuite(suite, get_spellbook_suite());
|
ADD_TESTS(suite, ship);
|
||||||
CuSuiteAddSuite(suite, get_building_suite());
|
ADD_TESTS(suite, spellbook);
|
||||||
CuSuiteAddSuite(suite, get_spell_suite());
|
ADD_TESTS(suite, building);
|
||||||
CuSuiteAddSuite(suite, get_battle_suite());
|
ADD_TESTS(suite, spell);
|
||||||
CuSuiteAddSuite(suite, get_ally_suite());
|
ADD_TESTS(suite, battle);
|
||||||
|
ADD_TESTS(suite, ally);
|
||||||
/* gamecode */
|
/* gamecode */
|
||||||
CuSuiteAddSuite(suite, get_market_suite());
|
ADD_TESTS(suite, market);
|
||||||
CuSuiteAddSuite(suite, get_laws_suite());
|
ADD_TESTS(suite, laws);
|
||||||
CuSuiteAddSuite(suite, get_economy_suite());
|
ADD_TESTS(suite, economy);
|
||||||
|
|
||||||
CuSuiteRun(suite);
|
CuSuiteRun(suite);
|
||||||
CuSuiteSummary(suite, output);
|
CuSuiteSummary(suite, output);
|
||||||
|
|
Loading…
Reference in New Issue