Files
dusk/test/save/savetestfixture.c
T
YourWishesandClaude Sonnet 5 fdfdfa3a66 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]>
2026-10-15 09:08:02 -05:00

86 lines
2.0 KiB
C

/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
// nftw()/FTW_DEPTH/FTW_PHYS are glibc extensions gated behind this.
#define _XOPEN_SOURCE 700
#include "savetestfixture.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "util/string.h"
#include <ftw.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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 int_t saveTestFixtureRemoveEntry(
const char *path,
const struct stat *statBuffer,
int typeFlag,
struct FTW *ftwBuffer
) {
return remove(path);
}
int saveTestFixtureSetup(void **state) {
const char_t *realHome = getenv("HOME");
SAVE_TEST_FIXTURE_HAD_REAL_HOME = realHome != NULL;
if(realHome != NULL) {
stringCopy(
SAVE_TEST_FIXTURE_REAL_HOME, realHome,
sizeof(SAVE_TEST_FIXTURE_REAL_HOME) - 1
);
}
stringCopy(
SAVE_TEST_FIXTURE_HOME, "/tmp/dusk-save-test-XXXXXX",
sizeof(SAVE_TEST_FIXTURE_HOME) - 1
);
assertNotNull(mkdtemp(SAVE_TEST_FIXTURE_HOME), "Failed to create temp $HOME");
assertTrue(setenv("HOME", SAVE_TEST_FIXTURE_HOME, 1) == 0, "setenv failed");
errorret_t ret = saveInit();
assertTrue(errorIsOk(ret), "saveInit failed in test fixture");
return 0;
}
int saveTestFixtureTeardown(void **state) {
nftw(
SAVE_TEST_FIXTURE_HOME, saveTestFixtureRemoveEntry, 16,
FTW_DEPTH | FTW_PHYS
);
if(SAVE_TEST_FIXTURE_HAD_REAL_HOME) {
setenv("HOME", SAVE_TEST_FIXTURE_REAL_HOME, 1);
} else {
unsetenv("HOME");
}
memoryZero(&SAVE, sizeof(SAVE));
return 0;
}
void saveTestFixtureBlockSaveDirectory(void) {
const char_t *home = getenv("HOME");
assertNotNull(home, "Fixture $HOME must be set before blocking it");
char_t path[PATH_MAX];
stringFormat(path, sizeof(path), "%s/.dusk", home);
FILE *file = fopen(path, "w");
assertNotNull(file, "Failed to create blocking file");
fclose(file);
}