Fix a broken test on Android

This commit is contained in:
Aaron Culliney 2016-10-15 19:07:10 -07:00
parent a417249691
commit 5ab68b5503
3 changed files with 29 additions and 18 deletions

View File

@ -36,20 +36,12 @@ static pthread_mutex_t prefsLock = PTHREAD_MUTEX_INITIALIZER;
// ----------------------------------------------------------------------------
void prefs_load(void) {
static void _prefs_load(const char *filePath) {
pthread_mutex_lock(&prefsLock);
assert(filePath && "must specify a file path");
FREE(prefsFile);
const char *apple2JSON = getenv("APPLE2IX_JSON");
if (apple2JSON) {
ASPRINTF(&prefsFile, "%s", apple2JSON);
}
if (!prefsFile) {
ASPRINTF(&prefsFile, "%s/.apple2.json", HOMEDIR);
}
assert(prefsFile);
prefsFile = STRDUP(filePath);
json_destroy(&jsonPrefs);
int tokCount = json_createFromFile(prefsFile, &jsonPrefs);
@ -61,6 +53,27 @@ void prefs_load(void) {
pthread_mutex_unlock(&prefsLock);
}
void prefs_load(void) {
char *filePath = NULL;
const char *apple2JSON = getenv("APPLE2IX_JSON");
if (apple2JSON) {
filePath = STRDUP(apple2JSON);
} else {
ASPRINTF(&filePath, "%s/.apple2.json", HOMEDIR);
}
assert(filePath);
_prefs_load(filePath);
FREE(filePath);
}
#if TESTING
void prefs_load_file(const char *filePath) {
_prefs_load(filePath);
}
#endif
void prefs_loadString(const char *jsonString) {
pthread_mutex_lock(&prefsLock);
json_destroy(&jsonPrefs);

View File

@ -92,6 +92,10 @@ typedef void (*prefs_change_callback_f)(const char * _NONNULL domain);
// load preferences from persistent store
extern void prefs_load(void);
#if TESTING
extern void prefs_load_file(const char *filePath);
#endif
// load preferences from JSON string
extern void prefs_loadString(const char * _NONNULL jsonString);

View File

@ -1900,13 +1900,7 @@ TEST test_prefs_load_and_save() {
ASSERT(apple2JSON);
unlink(apple2JSON);
char *apple2JSONEnv = NULL;
ASPRINTF(&apple2JSONEnv, "APPLE2IX_JSON=%s/%s", HOMEDIR, TEST_JSON);
ASSERT(apple2JSONEnv);
putenv(apple2JSONEnv);
LEAK(apple2JSONEnv);
prefs_load();
prefs_load_file(apple2JSON);
prefs_sync(NULL);
prefs_save();