Tests running and passing again on iOS devices

This commit is contained in:
Aaron Culliney 2016-07-17 19:27:32 -07:00
parent 59e6c4fabc
commit 4457e9e722
2 changed files with 72 additions and 48 deletions

View File

@ -97,7 +97,7 @@ unsupported_for_now
#elif __APPLE__
unsupported_for_now
#include "TargetConditionals.h"
#if TARGET_IPHONE_SIMULATOR
#if TARGET_OS_SIMULATOR
#elif TARGET_OS_IPHONE
#elif TARGET_OS_MAC
#else

View File

@ -70,56 +70,80 @@ void test_common_init(void) {
int test_setup_boot_disk(const char *fileName, int readonly) {
int err = 0;
char **path = NULL;
const unsigned int pathsCount = 3;
char *paths[pathsCount + 1] = {
NULL,
NULL,
NULL,
NULL,
};
const char *fmts[pathsCount + 1] = {
"%s%sdisks/%s",
"%s%sdisks/demo/%s",
"%s%sdisks/blanks/%s",
NULL,
};
#if defined(__APPLE__)
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFStringRef fileString = CFStringCreateWithCString(/*allocator*/NULL, fileName, CFStringGetSystemEncoding());
CFURLRef fileURL = CFBundleCopyResourceURL(mainBundle, fileString, NULL, NULL);
if (!fileURL) {
CFRELEASE(fileString);
char *fileName2 = NULL;
ASPRINTF(&fileName2, "disks/demo/%s", fileName);
fileString = CFStringCreateWithCString(/*allocator*/NULL, fileName2, CFStringGetSystemEncoding());
FREE(fileName2);
fileURL = CFBundleCopyResourceURL(mainBundle, fileString, NULL, NULL);
if (!fileURL) {
CFRELEASE(fileString);
ASPRINTF(&fileName2, "disks/blanks/%s", fileName);
fileString = CFStringCreateWithCString(/*allocator*/NULL, fileName2, CFStringGetSystemEncoding());
FREE(fileName2);
fileURL = CFBundleCopyResourceURL(mainBundle, fileString, NULL, NULL);
}
assert(fileURL);
}
CFStringRef filePath = CFURLCopyFileSystemPath(fileURL, kCFURLPOSIXPathStyle);
CFRELEASE(fileString);
CFRELEASE(fileURL);
CFIndex length = CFStringGetLength(filePath);
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
char *disk0 = (char *)MALLOC(maxSize);
if (!CFStringGetCString(filePath, disk0, maxSize, kCFStringEncodingUTF8)) {
FREE(disk0);
}
CFRELEASE(filePath);
# if TARGET_OS_SIMULATOR || !TARGET_OS_EMBEDDED
const char *prefixPath = "";
const char *sep = "";
# else // TARGET_OS_EMBEDDED
const char *prefixPath = data_dir;
const char *sep = "/";
# endif
char *paths[] = {
NULL,
NULL,
};
ASPRINTF(&paths[0], "%s", disk0);
FREE(disk0);
#else
char *paths[] = {
NULL,
NULL,
NULL,
NULL,
};
ASPRINTF(&paths[0], "%s/disks/%s", data_dir, fileName);
ASPRINTF(&paths[1], "%s/disks/demo/%s", data_dir, fileName);
ASPRINTF(&paths[2], "%s/disks/blanks/%s", data_dir, fileName);
do {
const char **fmtPtr = &fmts[0];
unsigned int idx = 0;
while (*fmtPtr) {
const char *fmt = *fmtPtr;
char *diskFile = NULL;
CFStringRef fileString = NULL;
CFURLRef fileURL = NULL;
ASPRINTF(&diskFile, fmt, prefixPath, sep, fileName);
assert(diskFile);
fileString = CFStringCreateWithCString(kCFAllocatorDefault, diskFile, kCFStringEncodingUTF8);
assert(fileString);
# if TARGET_OS_SIMULATOR || !TARGET_OS_EMBEDDED
// Use disks directly out of bundle ... is this OKAY?
fileURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), fileString, NULL, NULL);
# else
// AppDelegate should have copied disks to a R/W location
fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, fileString, kCFURLPOSIXPathStyle, /*isDirectory*/false);
# endif
if (fileURL) {
CFStringRef filePath = CFURLCopyFileSystemPath(fileURL, kCFURLPOSIXPathStyle);
assert(filePath);
CFIndex length = CFStringGetLength(filePath);
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
char *disk0 = (char *)MALLOC(maxSize);
if (CFStringGetCString(filePath, disk0, maxSize, kCFStringEncodingUTF8)) {
paths[idx++] = disk0;
}
CFRELEASE(filePath);
CFRELEASE(fileURL);
}
FREE(diskFile);
CFRELEASE(fileString);
++fmtPtr;
}
} while (0);
#else // !__APPLE__
do {
const char **fmtPtr = &fmts[0];
unsigned int idx = 0;
while (*fmtPtr) {
const char *fmt = *fmtPtr;
ASPRINTF(&paths[idx++], fmt, data_dir, "/", fileName);
}
} while (0);
#endif
path = &paths[0];