Fix the build after archiving rpg/ui/scene: drop their last live dependents
rpg/ui/scene moved to archive/ earlier left a handful of otherwise-generic systems with dead references into them: - asset/loader/chunk existed solely to load rpg overworld map chunks (tile_t, worldpos_t) - deleted outright, along with its ASSET_LOADER_TYPE_CHUNK entry in assetloader.c/h. - save/slot wrapped party_t/storyflagval_t/map-name/cutscene-path, which is 100% rpg save data - deleted outright (save.c/h, savedevice.c/h and the Linux save backend keep their generic settings/device-discovery logic, just lose the slot read/write pieces that only existed for it). - locale/localemanager.c and test/CMakeLists.txt/test/save/* had a few stray includes and test cases that only existed for the now-gone code. Also restores assets/locale/en_US.po (copied back from archive/assets/) - locale init still needs a real locale file to boot into, even with the asset-moving/archiving done separately. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
1 parent
f6b884bf7f
commit
fdfdfa3a66
31 files changed
+292
-1994
No files matched your search
@@ -7,8 +7,6 @@ include(dusktest)
|
||||
|
||||
# Tests
|
||||
dusktest(test_savesettings.c)
|
||||
dusktest(test_saveslot.c)
|
||||
target_sources(test_saveslot PRIVATE savetestfixture.c)
|
||||
|
||||
dusktest(test_savedevicelinux.c)
|
||||
target_sources(test_savedevicelinux PRIVATE savetestfixture.c)
|
||||
|
||||
@@ -10,9 +10,6 @@
|
||||
|
||||
#include "savetestfixture.h"
|
||||
#include "assert/assert.h"
|
||||
#include "asset/asset.h"
|
||||
#include "asset/loader/assetloader.h"
|
||||
#include "asset/loader/assetentry.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include <ftw.h>
|
||||
@@ -25,51 +22,6 @@ static char_t SAVE_TEST_FIXTURE_HOME[PATH_MAX];
|
||||
static char_t SAVE_TEST_FIXTURE_REAL_HOME[PATH_MAX];
|
||||
static bool_t SAVE_TEST_FIXTURE_HAD_REAL_HOME;
|
||||
|
||||
static const char_t *SAVE_TEST_FIXTURE_PARTY_JSON =
|
||||
"{\"members\":{\"hero\":{"
|
||||
"\"attack\":10,\"defense\":5,\"magic\":0,\"speed\":10,\"luck\":0,"
|
||||
"\"healthMax\":30,\"mpMax\":10"
|
||||
"}}}";
|
||||
|
||||
static yyjson_doc *SAVE_TEST_FIXTURE_PARTY_DOC = NULL;
|
||||
|
||||
errorret_t saveTestFixturePartyJsonLoadSyncStub(assetloading_t *loading) {
|
||||
loading->entry->data.json = SAVE_TEST_FIXTURE_PARTY_DOC;
|
||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t saveTestFixturePartyJsonDisposeStub(assetentry_t *entry) {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void saveTestFixtureStubPartyAsset(void) {
|
||||
memoryZero(&ASSET, sizeof(ASSET));
|
||||
for(size_t i = 0; i < ASSET_LOADING_COUNT_MAX; i++) {
|
||||
threadMutexInit(&ASSET.loading[i].mutex);
|
||||
}
|
||||
|
||||
if(SAVE_TEST_FIXTURE_PARTY_DOC == NULL) {
|
||||
SAVE_TEST_FIXTURE_PARTY_DOC = yyjson_read(
|
||||
SAVE_TEST_FIXTURE_PARTY_JSON, strlen(SAVE_TEST_FIXTURE_PARTY_JSON), 0
|
||||
);
|
||||
assertNotNull(
|
||||
SAVE_TEST_FIXTURE_PARTY_DOC, "Failed to parse party JSON fixture"
|
||||
);
|
||||
}
|
||||
|
||||
ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_JSON].loadSync =
|
||||
saveTestFixturePartyJsonLoadSyncStub;
|
||||
ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_JSON].dispose =
|
||||
saveTestFixturePartyJsonDisposeStub;
|
||||
}
|
||||
|
||||
void saveTestFixtureUnstubPartyAsset(void) {
|
||||
if(SAVE_TEST_FIXTURE_PARTY_DOC == NULL) return;
|
||||
yyjson_doc_free(SAVE_TEST_FIXTURE_PARTY_DOC);
|
||||
SAVE_TEST_FIXTURE_PARTY_DOC = NULL;
|
||||
}
|
||||
|
||||
static int_t saveTestFixtureRemoveEntry(
|
||||
const char *path,
|
||||
const struct stat *statBuffer,
|
||||
@@ -97,8 +49,6 @@ int saveTestFixtureSetup(void **state) {
|
||||
|
||||
assertTrue(setenv("HOME", SAVE_TEST_FIXTURE_HOME, 1) == 0, "setenv failed");
|
||||
|
||||
saveTestFixtureStubPartyAsset();
|
||||
|
||||
errorret_t ret = saveInit();
|
||||
assertTrue(errorIsOk(ret), "saveInit failed in test fixture");
|
||||
|
||||
@@ -106,8 +56,6 @@ int saveTestFixtureSetup(void **state) {
|
||||
}
|
||||
|
||||
int saveTestFixtureTeardown(void **state) {
|
||||
saveTestFixtureUnstubPartyAsset();
|
||||
|
||||
nftw(
|
||||
SAVE_TEST_FIXTURE_HOME, saveTestFixtureRemoveEntry, 16,
|
||||
FTW_DEPTH | FTW_PHYS
|
||||
|
||||
@@ -35,21 +35,3 @@ int saveTestFixtureTeardown(void **state);
|
||||
* filesystem permission tricks. Must be called after saveTestFixtureSetup.
|
||||
*/
|
||||
void saveTestFixtureBlockSaveDirectory(void);
|
||||
|
||||
/**
|
||||
* Stubs the JSON asset loader's sync callback to hand back a small
|
||||
* in-memory party.jsonc-shaped doc instead of doing a real file/zip read -
|
||||
* saveInit()/saveSlotInit() seed the party roster via partyInit(), which
|
||||
* loads party.jsonc through the real asset system, and there's no real
|
||||
* asset bundle available under the test harness. No thread, no real I/O.
|
||||
* Resets ASSET to a fresh, otherwise-empty state each call, so it's safe
|
||||
* to call once per test. Called automatically by saveTestFixtureSetup.
|
||||
*/
|
||||
void saveTestFixtureStubPartyAsset(void);
|
||||
|
||||
/**
|
||||
* Frees the in-memory doc created by saveTestFixtureStubPartyAsset. Safe
|
||||
* to call even if that function was never called. Called automatically
|
||||
* by saveTestFixtureTeardown.
|
||||
*/
|
||||
void saveTestFixtureUnstubPartyAsset(void);
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "dusktest.h"
|
||||
#include "savetestfixture.h"
|
||||
#include "save/save.h"
|
||||
#include "save/savedevicelinux.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include <stdio.h>
|
||||
@@ -54,16 +53,10 @@ static void test_saveInit_setsDefaults(void **state) {
|
||||
// saveTestFixtureSetup already called the real saveInit() - just assert
|
||||
// on the state it left behind.
|
||||
assert_int_equal(SAVE.deviceCurrent, 0xFF);
|
||||
assert_int_equal(SAVE.slotCurrent, 0xFF);
|
||||
assert_false(SAVE.findingAvailableDevice);
|
||||
assert_false(SAVE.noAvailableDeviceFound);
|
||||
assert_true(SAVE.settings.audioMasterVolume == 1.0f);
|
||||
assert_int_equal(SAVE.devices[0].state, SAVE_DEVICE_STATE_UNKNOWN);
|
||||
|
||||
for(uint8_t i = 0; i < SAVE_SLOT_COUNT; i++) {
|
||||
assert_int_equal(SAVE.caches[i].name[0], '\0');
|
||||
assert_int_equal(SAVE.caches[i].playerLevel, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
@@ -281,180 +274,6 @@ static void test_saveLoadSettings_readsAndClearsDirtyFlag(void **state) {
|
||||
assert_false(SAVE.settingsDirty);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// saveSaveSlot / saveLoadSlot
|
||||
// ============================================================
|
||||
|
||||
static void test_saveSaveSlot_noCurrentDeviceAsserts(void **state) {
|
||||
expect_assert_failure(saveSaveSlot());
|
||||
}
|
||||
|
||||
static void test_saveSaveSlot_invalidSlotIndexAsserts(void **state) {
|
||||
makeDeviceAvailable();
|
||||
// slotCurrent is still 0xFF (unset) from saveInit().
|
||||
expect_assert_failure(saveSaveSlot());
|
||||
}
|
||||
|
||||
static void test_saveSaveSlot_success(void **state) {
|
||||
makeDeviceAvailable();
|
||||
SAVE.slotCurrent = 1;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
stringCopy(
|
||||
SAVE.slot.cachedData.name, "Hero", sizeof(SAVE.slot.cachedData.name)
|
||||
);
|
||||
SAVE.slot.cachedData.playerLevel = 12;
|
||||
SAVE.slotDirty = true;
|
||||
|
||||
errorret_t ret = saveSaveSlot();
|
||||
assert_true(errorIsOk(ret));
|
||||
assert_false(SAVE.slotDirty);
|
||||
assert_true(stringEquals(SAVE.caches[1].name, "Hero"));
|
||||
assert_int_equal(SAVE.caches[1].playerLevel, 12);
|
||||
|
||||
// No pre-init needed - saveSlotReadJSON() (via saveDeviceSlotRead) fully
|
||||
// resets/overwrites its destination struct regardless of prior content.
|
||||
saveslot_t onDisk;
|
||||
errorret_t readRet = saveDeviceSlotRead(&SAVE.devices[0], &onDisk, 1);
|
||||
assert_true(errorIsOk(readRet));
|
||||
assert_true(stringEquals(onDisk.cachedData.name, "Hero"));
|
||||
assert_int_equal(onDisk.cachedData.playerLevel, 12);
|
||||
}
|
||||
|
||||
static void test_saveLoadSlot_noCurrentDeviceAsserts(void **state) {
|
||||
expect_assert_failure(saveLoadSlot());
|
||||
}
|
||||
|
||||
static void test_saveLoadSlot_invalidSlotIndexAsserts(void **state) {
|
||||
makeDeviceAvailable();
|
||||
expect_assert_failure(saveLoadSlot());
|
||||
}
|
||||
|
||||
static void test_saveLoadSlot_success(void **state) {
|
||||
makeDeviceAvailable();
|
||||
|
||||
// Write slot 2's on-disk file via SAVE.slot itself (saveSlotInit() only
|
||||
// ever operates on SAVE.slot now), then reset it again below - the
|
||||
// write and the load-under-test don't overlap in time.
|
||||
SAVE.slotCurrent = 2;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
stringCopy(
|
||||
SAVE.slot.cachedData.name, "Zelda", sizeof(SAVE.slot.cachedData.name)
|
||||
);
|
||||
SAVE.slot.cachedData.playerLevel = 30;
|
||||
errorret_t writeRet = saveDeviceSlotWrite(&SAVE.devices[0], &SAVE.slot, 2);
|
||||
assert_true(errorIsOk(writeRet));
|
||||
|
||||
SAVE.slotCurrent = 2;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
SAVE.slotDirty = true;
|
||||
|
||||
errorret_t ret = saveLoadSlot();
|
||||
assert_true(errorIsOk(ret));
|
||||
assert_false(SAVE.slotDirty);
|
||||
assert_true(stringEquals(SAVE.slot.cachedData.name, "Zelda"));
|
||||
assert_int_equal(SAVE.slot.cachedData.playerLevel, 30);
|
||||
assert_true(stringEquals(SAVE.caches[2].name, "Zelda"));
|
||||
assert_int_equal(SAVE.caches[2].playerLevel, 30);
|
||||
}
|
||||
|
||||
static void test_saveLoadSlot_deviceReadFails_cacheStaysStale(void **state) {
|
||||
makeDeviceAvailable();
|
||||
|
||||
char_t slotPath[512];
|
||||
errorret_t pathRet = saveDeviceLinuxGetSlotPath(
|
||||
slotPath, sizeof(slotPath), 0
|
||||
);
|
||||
assert_true(errorIsOk(pathRet));
|
||||
FILE *file = fopen(slotPath, "w");
|
||||
assert_non_null(file);
|
||||
fprintf(file, "not valid json {{{");
|
||||
fclose(file);
|
||||
|
||||
SAVE.slotCurrent = 0;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
SAVE.caches[0].playerLevel = 77;// sentinel
|
||||
|
||||
errorret_t ret = saveLoadSlot();
|
||||
assert_true(errorIsNotOk(ret));
|
||||
errorCatch(ret);
|
||||
|
||||
// The device read failed before the cache-sync line ever ran.
|
||||
assert_int_equal(SAVE.caches[0].playerLevel, 77);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// saveLoadAllSlots
|
||||
// ============================================================
|
||||
|
||||
static void test_saveLoadAllSlots_loadsAllAndEndsAtLastIndex(void **state) {
|
||||
makeDeviceAvailable();
|
||||
|
||||
for(uint8_t i = 0; i < SAVE_SLOT_COUNT; i++) {
|
||||
SAVE.slotCurrent = i;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
SAVE.slot.cachedData.playerLevel = (int32_t)(i + 1);
|
||||
errorret_t saveRet = saveSaveSlot();
|
||||
assert_true(errorIsOk(saveRet));
|
||||
}
|
||||
|
||||
errorret_t ret = saveLoadAllSlots();
|
||||
assert_true(errorIsOk(ret));
|
||||
assert_int_equal(SAVE.slotCurrent, SAVE_SLOT_COUNT - 1);
|
||||
|
||||
for(uint8_t i = 0; i < SAVE_SLOT_COUNT; i++) {
|
||||
assert_int_equal(SAVE.caches[i].playerLevel, (int32_t)(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_saveLoadAllSlots_missingFileLeavesInitDefaults(void **state) {
|
||||
makeDeviceAvailable();
|
||||
|
||||
SAVE.slotCurrent = 0;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
SAVE.slot.cachedData.playerLevel = 5;
|
||||
errorret_t saveRet = saveSaveSlot();
|
||||
assert_true(errorIsOk(saveRet));
|
||||
// Slots 1 and 2 are never written - no file exists for them.
|
||||
|
||||
errorret_t ret = saveLoadAllSlots();
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
assert_int_equal(SAVE.caches[0].playerLevel, 5);
|
||||
// Missing-file slots fall back to saveSlotInit()'s default (0), not the
|
||||
// JSON-missing-field default of 1 that a corrupt-but-present file with no
|
||||
// playerLevel key would produce - these are two different defaults.
|
||||
assert_int_equal(SAVE.caches[1].playerLevel, 0);
|
||||
assert_int_equal(SAVE.caches[2].playerLevel, 0);
|
||||
}
|
||||
|
||||
static void test_saveLoadAllSlots_middleSlotCorrupt_stopsAtFailingIndex(
|
||||
void **state
|
||||
) {
|
||||
makeDeviceAvailable();
|
||||
|
||||
SAVE.slotCurrent = 0;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
errorret_t saveRet = saveSaveSlot();
|
||||
assert_true(errorIsOk(saveRet));
|
||||
|
||||
char_t slotPath[512];
|
||||
errorret_t pathRet = saveDeviceLinuxGetSlotPath(
|
||||
slotPath, sizeof(slotPath), 1
|
||||
);
|
||||
assert_true(errorIsOk(pathRet));
|
||||
FILE *file = fopen(slotPath, "w");
|
||||
assert_non_null(file);
|
||||
fprintf(file, "not valid json {{{");
|
||||
fclose(file);
|
||||
|
||||
errorret_t ret = saveLoadAllSlots();
|
||||
assert_true(errorIsNotOk(ret));
|
||||
errorCatch(ret);
|
||||
|
||||
// The loop bails out as soon as slot 1 fails - it never reaches slot 2.
|
||||
assert_int_equal(SAVE.slotCurrent, 1);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// saveDispose
|
||||
// ============================================================
|
||||
@@ -566,46 +385,6 @@ int main(void) {
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveSaveSlot_noCurrentDeviceAsserts,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveSaveSlot_invalidSlotIndexAsserts,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveSaveSlot_success, saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveLoadSlot_noCurrentDeviceAsserts,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveLoadSlot_invalidSlotIndexAsserts,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveLoadSlot_success, saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveLoadSlot_deviceReadFails_cacheStaysStale,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveLoadAllSlots_loadsAllAndEndsAtLastIndex,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveLoadAllSlots_missingFileLeavesInitDefaults,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveLoadAllSlots_middleSlotCorrupt_stopsAtFailingIndex,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveDispose_succeeds, saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
#include "dusktest.h"
|
||||
#include "savetestfixture.h"
|
||||
#include "save/savedevice.h"
|
||||
#include "save/slot/saveslot.h"
|
||||
#include "save/settings/savesettings.h"
|
||||
#include "save/save.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
|
||||
@@ -150,28 +148,10 @@ static void test_saveDeviceCheckAvailability_resolvesSynchronouslyOnLinux(
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// saveDeviceSlotWrite / saveDeviceSlotRead / saveDeviceSettingsWrite /
|
||||
// saveDeviceSettingsRead - dispatch to the platform's four hooks.
|
||||
// saveDeviceSettingsWrite / saveDeviceSettingsRead - dispatch to the
|
||||
// platform's hooks.
|
||||
// ============================================================
|
||||
|
||||
static void test_saveDeviceSlotWrite_nullAsserts(void **state) {
|
||||
savedevice_t device;
|
||||
// Content is never touched - both calls assert on a NULL argument
|
||||
// before either device or slot would actually be read.
|
||||
saveslot_t slot;
|
||||
|
||||
expect_assert_failure(saveDeviceSlotWrite(NULL, &slot, 0));
|
||||
expect_assert_failure(saveDeviceSlotWrite(&device, NULL, 0));
|
||||
}
|
||||
|
||||
static void test_saveDeviceSlotRead_nullAsserts(void **state) {
|
||||
savedevice_t device;
|
||||
saveslot_t slot;
|
||||
|
||||
expect_assert_failure(saveDeviceSlotRead(NULL, &slot, 0));
|
||||
expect_assert_failure(saveDeviceSlotRead(&device, NULL, 0));
|
||||
}
|
||||
|
||||
static void test_saveDeviceSettingsWrite_nullAsserts(void **state) {
|
||||
savedevice_t device;
|
||||
savesettings_t settings;
|
||||
@@ -190,32 +170,6 @@ static void test_saveDeviceSettingsRead_nullAsserts(void **state) {
|
||||
expect_assert_failure(saveDeviceSettingsRead(&device, NULL));
|
||||
}
|
||||
|
||||
static void test_saveDeviceSlot_dispatchesToPlatform(void **state) {
|
||||
savedevice_t device;
|
||||
errorret_t initRet = saveDeviceInit(&device);
|
||||
assert_true(errorIsOk(initRet));
|
||||
// The save directory must exist before a write can succeed - normally
|
||||
// saveDeviceCheckAvailability does this via the platform's mkdirp.
|
||||
saveDeviceCheckAvailability(&device, updateCallback, NULL);
|
||||
saveDeviceUpdate(&device);
|
||||
|
||||
// saveSlotInit() only ever operates on SAVE.slot now, so that's the
|
||||
// write source here.
|
||||
saveSlotInit(&SAVE.slot);
|
||||
SAVE.slot.cachedData.playerLevel = 21;
|
||||
|
||||
errorret_t writeRet = saveDeviceSlotWrite(&device, &SAVE.slot, 0);
|
||||
assert_true(errorIsOk(writeRet));
|
||||
|
||||
// No pre-init needed - saveSlotReadJSON() (via saveDeviceSlotRead) fully
|
||||
// resets/overwrites its destination struct regardless of prior content.
|
||||
saveslot_t read;
|
||||
errorret_t readRet = saveDeviceSlotRead(&device, &read, 0);
|
||||
assert_true(errorIsOk(readRet));
|
||||
|
||||
assert_int_equal(read.cachedData.playerLevel, 21);
|
||||
}
|
||||
|
||||
static void test_saveDeviceSettings_dispatchesToPlatform(void **state) {
|
||||
savedevice_t device;
|
||||
errorret_t initRet = saveDeviceInit(&device);
|
||||
@@ -303,14 +257,6 @@ int main(void) {
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveDeviceSlotWrite_nullAsserts,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveDeviceSlotRead_nullAsserts,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveDeviceSettingsWrite_nullAsserts,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
@@ -319,10 +265,6 @@ int main(void) {
|
||||
test_saveDeviceSettingsRead_nullAsserts,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveDeviceSlot_dispatchesToPlatform,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_saveDeviceSettings_dispatchesToPlatform,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
#include "savetestfixture.h"
|
||||
#include "save/savedevice.h"
|
||||
#include "save/savedevicelinux.h"
|
||||
#include "save/slot/saveslot.h"
|
||||
#include "save/settings/savesettings.h"
|
||||
#include "save/save.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include <stdio.h>
|
||||
@@ -86,27 +84,6 @@ static void test_getSettingsPath_homeUnset_errors(void **state) {
|
||||
errorCatch(ret);
|
||||
}
|
||||
|
||||
static void test_getSlotPath_success(void **state) {
|
||||
char_t path[512];
|
||||
errorret_t ret = saveDeviceLinuxGetSlotPath(path, sizeof(path), 2);
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
char_t expected[512];
|
||||
stringFormat(
|
||||
expected, sizeof(expected), "%s/.dusk/saves/slot2.json", getenv("HOME")
|
||||
);
|
||||
assert_true(stringEquals(path, expected));
|
||||
}
|
||||
|
||||
static void test_getSlotPath_homeUnset_errors(void **state) {
|
||||
unsetenv("HOME");
|
||||
|
||||
char_t path[512];
|
||||
errorret_t ret = saveDeviceLinuxGetSlotPath(path, sizeof(path), 0);
|
||||
assert_true(errorIsNotOk(ret));
|
||||
errorCatch(ret);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// saveDeviceLinuxCheckAvailability
|
||||
// ============================================================
|
||||
@@ -175,105 +152,6 @@ static void test_checkAvailability_mkdirpFails(void **state) {
|
||||
assert_true(g_callbackFired);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// saveDeviceLinuxSlotWrite / saveDeviceLinuxSlotRead
|
||||
// ============================================================
|
||||
|
||||
static void test_slotWrite_nullAsserts(void **state) {
|
||||
savedevice_t device;
|
||||
// Content is never touched - both calls assert on a NULL argument
|
||||
// before either device or slot would actually be read.
|
||||
saveslot_t slot;
|
||||
|
||||
expect_assert_failure(saveDeviceLinuxSlotWrite(NULL, &slot, 0));
|
||||
expect_assert_failure(saveDeviceLinuxSlotWrite(&device, NULL, 0));
|
||||
}
|
||||
|
||||
static void test_slotRead_nullAsserts(void **state) {
|
||||
savedevice_t device;
|
||||
saveslot_t slot;
|
||||
|
||||
expect_assert_failure(saveDeviceLinuxSlotRead(NULL, &slot, 0));
|
||||
expect_assert_failure(saveDeviceLinuxSlotRead(&device, NULL, 0));
|
||||
}
|
||||
|
||||
static void test_slotWriteRead_roundTrip(void **state) {
|
||||
savedevice_t device;
|
||||
memoryZero(&device, sizeof(device));
|
||||
// The save directory must exist before a write can succeed - normally
|
||||
// saveDeviceLinuxCheckAvailability does this via mkdirp.
|
||||
checkAvailabilityAndDrain(&device);
|
||||
|
||||
// saveSlotInit() only ever operates on SAVE.slot now, so that's the
|
||||
// write source here.
|
||||
saveSlotInit(&SAVE.slot);
|
||||
stringCopy(
|
||||
SAVE.slot.cachedData.name, "Hero", sizeof(SAVE.slot.cachedData.name)
|
||||
);
|
||||
SAVE.slot.cachedData.playerLevel = 9;
|
||||
|
||||
errorret_t writeRet = saveDeviceLinuxSlotWrite(&device, &SAVE.slot, 1);
|
||||
assert_true(errorIsOk(writeRet));
|
||||
|
||||
// No pre-init needed - saveSlotReadJSON() (via saveDeviceLinuxSlotRead)
|
||||
// fully resets/overwrites its destination struct regardless of prior
|
||||
// content.
|
||||
saveslot_t read;
|
||||
errorret_t readRet = saveDeviceLinuxSlotRead(&device, &read, 1);
|
||||
assert_true(errorIsOk(readRet));
|
||||
|
||||
assert_true(stringEquals(read.cachedData.name, "Hero"));
|
||||
assert_int_equal(read.cachedData.playerLevel, 9);
|
||||
}
|
||||
|
||||
static void test_slotRead_noFileYet_leavesSlotUntouched(void **state) {
|
||||
savedevice_t device;
|
||||
memoryZero(&device, sizeof(device));
|
||||
|
||||
// Deliberately not saveSlotInit()'d - a missing slot file means
|
||||
// saveDeviceLinuxSlotRead never even calls saveSlotReadJSON, so slot
|
||||
// must come in exactly as the caller left it and go out unchanged.
|
||||
saveslot_t slot;
|
||||
memoryZero(&slot, sizeof(slot));
|
||||
stringCopy(slot.cachedData.name, "sentinel", sizeof(slot.cachedData.name));
|
||||
slot.cachedData.playerLevel = 555;
|
||||
|
||||
errorret_t ret = saveDeviceLinuxSlotRead(&device, &slot, 2);
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
assert_true(stringEquals(slot.cachedData.name, "sentinel"));
|
||||
assert_int_equal(slot.cachedData.playerLevel, 555);
|
||||
}
|
||||
|
||||
static void test_slotRead_corruptFile_errors(void **state) {
|
||||
savedevice_t device;
|
||||
memoryZero(&device, sizeof(device));
|
||||
|
||||
// The directory must exist before we can drop a file into it - normally
|
||||
// saveDeviceLinuxCheckAvailability does this via mkdirp.
|
||||
savedevice_t tmpDevice;
|
||||
memoryZero(&tmpDevice, sizeof(tmpDevice));
|
||||
tmpDevice.state = SAVE_DEVICE_STATE_CHECKING_AVAILABILITY;
|
||||
saveDeviceLinuxCheckAvailability(&tmpDevice);
|
||||
assert_int_equal(tmpDevice.state, SAVE_DEVICE_STATE_AVAILABLE);
|
||||
|
||||
char_t slotPath[512];
|
||||
errorret_t pathRet =
|
||||
saveDeviceLinuxGetSlotPath(slotPath, sizeof(slotPath), 0);
|
||||
assert_true(errorIsOk(pathRet));
|
||||
|
||||
FILE *file = fopen(slotPath, "w");
|
||||
assert_non_null(file);
|
||||
fprintf(file, "not valid json {{{");
|
||||
fclose(file);
|
||||
|
||||
saveslot_t slot;
|
||||
|
||||
errorret_t ret = saveDeviceLinuxSlotRead(&device, &slot, 0);
|
||||
assert_true(errorIsNotOk(ret));
|
||||
errorCatch(ret);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// saveDeviceLinuxSettingsWrite / saveDeviceLinuxSettingsRead
|
||||
// ============================================================
|
||||
@@ -381,14 +259,6 @@ int main(void) {
|
||||
test_getSettingsPath_homeUnset_errors,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_getSlotPath_success, saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_getSlotPath_homeUnset_errors,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_checkAvailability_wrongStateAsserts,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
@@ -410,25 +280,6 @@ int main(void) {
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_slotWrite_nullAsserts, saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_slotRead_nullAsserts, saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_slotWriteRead_roundTrip,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_slotRead_noFileYet_leavesSlotUntouched,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_slotRead_corruptFile_errors,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
),
|
||||
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_settingsWrite_nullAsserts,
|
||||
saveTestFixtureSetup, saveTestFixtureTeardown
|
||||
|
||||
Reference in new issue
Block a user