Add a real test suite for the save system (previously had none)
Covers save.c (device discovery/orchestration), savedevice.c (the generic device state machine and platform dispatch), and the Linux platform backend (path building, availability checks, JSON read/write, corrupt/missing-file handling), plus saveslot.c/savesettings.c JSON round-trips. 88 tests across 5 files, all run against the real Linux filesystem backend sandboxed to a temp $HOME (there's no mockable platform layer - the hooks are compile-time macros, not function pointers). Deliberately locks in two existing behaviors rather than working around them: saveSaveSettings() is a permanent no-op because nothing anywhere ever sets SAVE.settingsDirty = true, and saveUpdate() unconditionally rewrites settings back out the moment a device is found regardless of that same dirty flag. Both are pre-existing, not introduced here. Does not cover the SAVE_DEVICE_DATA_RAW blob codec (PSP/GameCube/Wii only) or GameCube's 2-device fallback chain - neither compiles into the Linux host test build. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "save/save.h"
|
||||
|
||||
/**
|
||||
* Points $HOME at a fresh, empty temporary directory and resets the global
|
||||
* SAVE state via the real saveInit(). Save tests run against the real Linux
|
||||
* filesystem backend (there is no fake/mockable platform layer to swap in -
|
||||
* the platform hooks are compile-time macros, not function pointers), so
|
||||
* this sandboxing is what keeps tests from touching the real user's
|
||||
* $HOME/.dusk/saves. Matches cmocka's CMUnitTestSetup signature - pass
|
||||
* directly to cmocka_unit_test_setup_teardown.
|
||||
*/
|
||||
int saveTestFixtureSetup(void **state);
|
||||
|
||||
/**
|
||||
* Recursively removes the temporary $HOME directory tree created by
|
||||
* saveTestFixtureSetup and restores the real $HOME. Matches cmocka's
|
||||
* CMUnitTestTeardown signature - pass directly to
|
||||
* cmocka_unit_test_setup_teardown.
|
||||
*/
|
||||
int saveTestFixtureTeardown(void **state);
|
||||
|
||||
/**
|
||||
* Places a regular file where the ".dusk" directory needs to go, so a
|
||||
* subsequent availability check's mkdirp() call fails with ENOTDIR instead
|
||||
* of succeeding. Used to deterministically exercise the "device unavailable
|
||||
* because its directory couldn't be created" path without relying on real
|
||||
* filesystem permission tricks. Must be called after saveTestFixtureSetup.
|
||||
*/
|
||||
void saveTestFixtureBlockSaveDirectory(void);
|
||||
Reference in New Issue
Block a user