Files
dusk/test/save/savetestfixture.c
YourWishesandClaude Sonnet 5.5 31ee7989de Remove rpg, ui, editor and scene subfolders; split scripts by platform
Delete src/dusk/rpg, src/dusk/ui, the animation/keyframe modules, the
scene subfolders, the chunk asset loader and ./editor, and strip the
dependent save slot, scene type, engine and test code so the main
binary and tests build again. Add scene/node.c/.h skeleton and move
build scripts into scripts/<platform>/.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-03 07:29:25 -06:00

87 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);
}