From 3e943e4707c7caa6ae9cb7d32bdab7f4aec78ab9 Mon Sep 17 00:00:00 2001 From: Eric Wing Date: Sun, 9 May 2010 06:58:30 -0700 Subject: [PATCH] Refactored automated rwops tests so read and write directories can be more easily customized. The refactored tests were written in recognition that Mac and iPhone current working directories are usually not going to work. Resource directories are in bundles and write directories are restricted to certain areas. In theory, other platforms may have this problem too, hence the refactoring. Also updated the Xcode iPhone project to use 3.2 as the Base SDK, but 3.1 as the Deployment SDK (for iPhone/iPad compatibility.) --- .../SDL/SDLiPhoneOS.xcodeproj/project.pbxproj | 27 ++++++------ test/automated/Makefile | 1 + test/automated/rwops/TestSupportRWops.h | 14 +++++++ ...ndlesupport.m => TestSupportRWops_Cocoa.m} | 41 +++++++++++++++---- .../rwops/TestSupportRWops_Generic.c | 28 +++++++++++++ .../automated/rwops/Test_rwopsbundlesupport.h | 11 ----- test/automated/rwops/rwops.c | 38 ++++++----------- 7 files changed, 102 insertions(+), 58 deletions(-) create mode 100644 test/automated/rwops/TestSupportRWops.h rename test/automated/rwops/{Test_rwopsbundlesupport.m => TestSupportRWops_Cocoa.m} (62%) create mode 100644 test/automated/rwops/TestSupportRWops_Generic.c delete mode 100644 test/automated/rwops/Test_rwopsbundlesupport.h diff --git a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj index 55fc6e41d..3b3276d7a 100755 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj +++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj @@ -34,6 +34,7 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ + 001E39A71196EE6F00A3F5B8 /* TestSupportRWops_Cocoa.m in Sources */ = {isa = PBXBuildFile; fileRef = 001E39A51196EE6F00A3F5B8 /* TestSupportRWops_Cocoa.m */; }; 006E9852119550FB001DE610 /* audio.c in Sources */ = {isa = PBXBuildFile; fileRef = 006E9831119550FB001DE610 /* audio.c */; }; 006E9853119550FB001DE610 /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = 006E9834119550FB001DE610 /* common.c */; }; 006E9859119550FB001DE610 /* platform.c in Sources */ = {isa = PBXBuildFile; fileRef = 006E983D119550FB001DE610 /* platform.c */; }; @@ -42,7 +43,6 @@ 006E985C119550FB001DE610 /* render.c in Sources */ = {isa = PBXBuildFile; fileRef = 006E9844119550FB001DE610 /* render.c */; }; 006E985D119550FB001DE610 /* read in Copy rwops */ = {isa = PBXBuildFile; fileRef = 006E9847119550FB001DE610 /* read */; }; 006E985E119550FB001DE610 /* rwops.c in Sources */ = {isa = PBXBuildFile; fileRef = 006E9848119550FB001DE610 /* rwops.c */; }; - 006E985F119550FB001DE610 /* Test_rwopsbundlesupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 006E984B119550FB001DE610 /* Test_rwopsbundlesupport.m */; }; 006E9860119550FB001DE610 /* SDL_at.c in Sources */ = {isa = PBXBuildFile; fileRef = 006E984C119550FB001DE610 /* SDL_at.c */; }; 006E9861119550FB001DE610 /* surface.c in Sources */ = {isa = PBXBuildFile; fileRef = 006E984F119550FB001DE610 /* surface.c */; }; 006E9862119550FB001DE610 /* testsdl.c in Sources */ = {isa = PBXBuildFile; fileRef = 006E9851119550FB001DE610 /* testsdl.c */; }; @@ -264,6 +264,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 001E39A51196EE6F00A3F5B8 /* TestSupportRWops_Cocoa.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestSupportRWops_Cocoa.m; sourceTree = ""; }; + 001E39A61196EE6F00A3F5B8 /* TestSupportRWops.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestSupportRWops.h; sourceTree = ""; }; 006E982211955059001DE610 /* testsdl.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testsdl.app; sourceTree = BUILT_PRODUCTS_DIR; }; 006E982411955059001DE610 /* testsdl-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "testsdl-Info.plist"; sourceTree = ""; }; 006E9831119550FB001DE610 /* audio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = audio.c; sourceTree = ""; }; @@ -286,8 +288,6 @@ 006E9847119550FB001DE610 /* read */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = read; sourceTree = ""; }; 006E9848119550FB001DE610 /* rwops.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rwops.c; sourceTree = ""; }; 006E9849119550FB001DE610 /* rwops.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rwops.h; sourceTree = ""; }; - 006E984A119550FB001DE610 /* Test_rwopsbundlesupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Test_rwopsbundlesupport.h; sourceTree = ""; }; - 006E984B119550FB001DE610 /* Test_rwopsbundlesupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Test_rwopsbundlesupport.m; sourceTree = ""; }; 006E984C119550FB001DE610 /* SDL_at.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_at.c; path = ../../test/automated/SDL_at.c; sourceTree = SOURCE_ROOT; }; 006E984D119550FB001DE610 /* SDL_at.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_at.h; path = ../../test/automated/SDL_at.h; sourceTree = SOURCE_ROOT; }; 006E984F119550FB001DE610 /* surface.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = surface.c; sourceTree = ""; }; @@ -609,11 +609,11 @@ 006E9846119550FB001DE610 /* rwops */ = { isa = PBXGroup; children = ( + 001E39A51196EE6F00A3F5B8 /* TestSupportRWops_Cocoa.m */, + 001E39A61196EE6F00A3F5B8 /* TestSupportRWops.h */, 006E9847119550FB001DE610 /* read */, 006E9848119550FB001DE610 /* rwops.c */, 006E9849119550FB001DE610 /* rwops.h */, - 006E984A119550FB001DE610 /* Test_rwopsbundlesupport.h */, - 006E984B119550FB001DE610 /* Test_rwopsbundlesupport.m */, ); name = rwops; path = ../../test/automated/rwops; @@ -694,10 +694,10 @@ 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { isa = PBXGroup; children = ( - 006E982F119550E4001DE610 /* TestResources */, - 006E982E119550D8001DE610 /* AutomatedTests */, FD99B8BC0DD52E5C00FB1D6B /* Public Headers */, FD99B8BD0DD52E6D00FB1D6B /* Library Source */, + 006E982E119550D8001DE610 /* AutomatedTests */, + 006E982F119550E4001DE610 /* TestResources */, 29B97323FDCFA39411CA2CEA /* Frameworks */, 19C28FACFE9D520D11CA2CBB /* Products */, 006E982411955059001DE610 /* testsdl-Info.plist */, @@ -1313,10 +1313,10 @@ 006E985B119550FB001DE610 /* rect.c in Sources */, 006E985C119550FB001DE610 /* render.c in Sources */, 006E985E119550FB001DE610 /* rwops.c in Sources */, - 006E985F119550FB001DE610 /* Test_rwopsbundlesupport.m in Sources */, 006E9860119550FB001DE610 /* SDL_at.c in Sources */, 006E9861119550FB001DE610 /* surface.c in Sources */, 006E9862119550FB001DE610 /* testsdl.c in Sources */, + 001E39A71196EE6F00A3F5B8 /* TestSupportRWops_Cocoa.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1505,15 +1505,15 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = c99; GCC_DEBUGGING_SYMBOLS = full; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = NO; + IPHONEOS_DEPLOYMENT_TARGET = 3.1; ONLY_ACTIVE_ARCH = NO; PREBINDING = NO; - SDKROOT = iphoneos3.1.2; + SDKROOT = iphoneos3.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1522,13 +1522,14 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = c99; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = NO; + IPHONEOS_DEPLOYMENT_TARGET = 3.1; PREBINDING = NO; - SDKROOT = iphoneos3.1.2; + SDKROOT = iphoneos3.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -1537,7 +1538,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = NO; DEPLOYMENT_LOCATION = NO; @@ -1553,7 +1553,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; diff --git a/test/automated/Makefile b/test/automated/Makefile index dea509afa..fe181c792 100644 --- a/test/automated/Makefile +++ b/test/automated/Makefile @@ -10,6 +10,7 @@ LDFLAGS := `sdl-config --libs` SRC := testsdl.c \ platform/platform.c \ rwops/rwops.c \ + rwops/TestSupportRWops.c \ rect/rect.c \ surface/surface.c \ render/render.c \ diff --git a/test/automated/rwops/TestSupportRWops.h b/test/automated/rwops/TestSupportRWops.h new file mode 100644 index 000000000..95f155020 --- /dev/null +++ b/test/automated/rwops/TestSupportRWops.h @@ -0,0 +1,14 @@ + +#include +#include "SDL.h" + +#ifndef TestSupportRWops_h +#define TestSupportRWops_h + +FILE* TestSupportRWops_OpenFPFromReadDir(const char *file, const char *mode); +FILE* TestSupportRWops_OpenFPFromWriteDir(const char *file, const char *mode); +SDL_RWops* TestSupportRWops_OpenRWopsFromReadDir(const char *file, const char *mode); +SDL_RWops* TestSupportRWops_OpenRWopsFromWriteDir(const char *file, const char *mode); + + +#endif diff --git a/test/automated/rwops/Test_rwopsbundlesupport.m b/test/automated/rwops/TestSupportRWops_Cocoa.m similarity index 62% rename from test/automated/rwops/Test_rwopsbundlesupport.m rename to test/automated/rwops/TestSupportRWops_Cocoa.m index ebed430b9..5f0dc07d3 100644 --- a/test/automated/rwops/Test_rwopsbundlesupport.m +++ b/test/automated/rwops/TestSupportRWops_Cocoa.m @@ -1,14 +1,22 @@ -#ifdef __APPLE__ +#import "TestSupportRWops.h" #import +#include "SDL.h" /* For proper OS X applications, the resources are contained inside the application bundle. So the strategy is to first check the application bundle for the file, then fallback to the current working directory. Note: One additional corner-case is if the resource is in a framework's resource bundle instead of the app. We might want to use bundle identifiers, e.g. org.libsdl.sdl to get the bundle for the framework, but we would somehow need to know what the bundle identifiers we need to search are. + Conversely, write directories are usually not in the bundles. This implementation uses NSTemporaryDirectory, + but consider Preferences, Application Support, Documents, etc. Also, note the bundle layouts are different for iPhone and Mac. */ -FILE* Test_OpenFPFromBundleOrFallback(const char *file, const char *mode) + +const char* RWOPS_READ = "rwops/read"; +const char* RWOPS_WRITE = "write"; + + +FILE* TestSupportRWops_OpenFPFromReadDir(const char *file, const char *mode) { FILE* fp = NULL; @@ -41,22 +49,41 @@ return fp; } -FILE* Test_OpenFPFromTemporaryDir(const char *file, const char *mode) +FILE* TestSupportRWops_OpenFPFromWriteDir(const char *file, const char *mode) { FILE* fp = NULL; NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; - NSFileManager* file_manager = [NSFileManager defaultManager]; - NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; - NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component]; + fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode); [autorelease_pool drain]; return fp; } -#endif + +SDL_RWops* TestSupportRWops_OpenRWopsFromReadDir(const char *file, const char *mode) +{ + return SDL_RWFromFile(file, mode); +} + +SDL_RWops* TestSupportRWops_OpenRWopsFromWriteDir(const char *file, const char *mode) +{ + SDL_RWops* rw = NULL; + + NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; + + NSFileManager* file_manager = [NSFileManager defaultManager]; + NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; + NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component]; + + rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode ); + + [autorelease_pool drain]; + return rw; +} + diff --git a/test/automated/rwops/TestSupportRWops_Generic.c b/test/automated/rwops/TestSupportRWops_Generic.c new file mode 100644 index 000000000..32d76470d --- /dev/null +++ b/test/automated/rwops/TestSupportRWops_Generic.c @@ -0,0 +1,28 @@ +/* Generic implementation for file opening routines. +* Customizations for specific platforms should go in alternative files. +*/ +#include +#include "SDL.h" + +const char* RWOPS_READ = "rwops/read"; +const char* RWOPS_WRITE = "rwops/write"; + +FILE* TestSupportRWops_OpenFPFromReadDir(const char *file, const char *mode) +{ + return fopen(file, mode); +} + +FILE* TestSupportRWops_OpenFPFromWriteDir(const char *file, const char *mode) +{ + return fopen(file, mode); +} + +SDL_RWops* TestSupportRWops_OpenRWopsFromReadDir(const char *file, const char *mode) +{ + return SDL_RWFromFile(file, mode); +} + +SDL_RWops* TestSupportRWops_OpenRWopsFromWriteDir(const char *file, const char *mode) +{ + return SDL_RWFromFile(file, mode); +} diff --git a/test/automated/rwops/Test_rwopsbundlesupport.h b/test/automated/rwops/Test_rwopsbundlesupport.h deleted file mode 100644 index f3b72d54b..000000000 --- a/test/automated/rwops/Test_rwopsbundlesupport.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifdef __APPLE__ - -#include - -#ifndef SDL_rwopsbundlesupport_h -#define SDL_rwopsbundlesupport_h -FILE* Test_OpenFPFromBundleOrFallback(const char *file, const char *mode); -FILE* Test_OpenFPFromTemporaryDir(const char *file, const char *mode); - -#endif -#endif diff --git a/test/automated/rwops/rwops.c b/test/automated/rwops/rwops.c index b65268766..99ec1f46b 100644 --- a/test/automated/rwops/rwops.c +++ b/test/automated/rwops/rwops.c @@ -9,17 +9,11 @@ #include "SDL.h" #include "../SDL_at.h" -#if __APPLE__ -#include "Test_rwopsbundlesupport.h" -#endif +#include "TestSupportRWops.h" -#define RWOPS_READ "rwops/read" - -#if __APPLE__ -#define RWOPS_WRITE "write" -#else -#define RWOPS_WRITE "rwops/write" -#endif +/* Defined in TestSupportRWops implementation to allow flexibility. */ +extern const char* RWOPS_READ; +extern const char* RWOPS_WRITE; static const char hello_world[] = "Hello World!"; @@ -193,16 +187,16 @@ static void rwops_testFile (void) SDL_ATbegin( "SDL_RWFromFile" ); /* Read test. */ - rw = SDL_RWFromFile( RWOPS_READ, "r" ); - if (SDL_ATassert( "Opening memory with SDL_RWFromFile '"RWOPS_READ"'", rw != NULL )) + rw = TestSupportRWops_OpenRWopsFromReadDir( RWOPS_READ, "r" ); + if (SDL_ATassert( "Opening memory with SDL_RWFromFile RWOPS_READ", rw != NULL )) return; if (rwops_testGeneric( rw, 0 )) return; SDL_FreeRW( rw ); /* Write test. */ - rw = SDL_RWFromFile( RWOPS_WRITE, "w+" ); - if (SDL_ATassert( "Opening memory with SDL_RWFromFile '"RWOPS_WRITE"'", rw != NULL )) + rw = TestSupportRWops_OpenRWopsFromWriteDir( RWOPS_WRITE, "w+" ); + if (SDL_ATassert( "Opening memory with SDL_RWFromFile RWOPS_WRITE", rw != NULL )) return; if (rwops_testGeneric( rw, 1 )) return; @@ -226,12 +220,8 @@ static void rwops_testFP (void) SDL_ATbegin( "SDL_RWFromFP" ); /* Run read tests. */ -#if __APPLE__ - fp = Test_OpenFPFromBundleOrFallback( RWOPS_READ, "r" ); -#else - fp = fopen( RWOPS_READ, "r" ); -#endif - if (SDL_ATassert( "Failed to open file '"RWOPS_READ"'", fp != NULL)) + fp = TestSupportRWops_OpenFPFromReadDir( RWOPS_READ, "r" ); + if (SDL_ATassert( "Failed to open file 'WOPS_READ", fp != NULL)) return; rw = SDL_RWFromFP( fp, 1 ); if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL )) @@ -241,12 +231,8 @@ static void rwops_testFP (void) SDL_FreeRW( rw ); /* Run write tests. */ -#if __APPLE__ - fp = Test_OpenFPFromTemporaryDir( RWOPS_WRITE, "w+" ); -#else - fp = fopen( RWOPS_WRITE, "w+" ); -#endif - if (SDL_ATassert( "Failed to open file '"RWOPS_WRITE"'", fp != NULL)) + fp = TestSupportRWops_OpenFPFromWriteDir( RWOPS_WRITE, "w+" ); + if (SDL_ATassert( "Failed to open file RWOPS_WRITE", fp != NULL)) return; rw = SDL_RWFromFP( fp, 1 ); if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL ))