From a60ff482a62517abca77990381d448d0d7a37c9f Mon Sep 17 00:00:00 2001 From: Eric Wing Date: Sat, 8 May 2010 00:54:22 -0700 Subject: [PATCH] Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware. The Mac OS X project has a new target called testsdl which builds the automated test. I looked at using Xcode's native unit test support, but the impedance mismatch between the existing automated test structure and Apple's was more than I could handle. As such, the testsdl application is a full blown proper OS X application, which means it is a self-contained .app bundle. This immediately revealed some problems from the automated test. The largest problem was the assumption about the current working directory and where to find resources. (I suspect Windows may have a similar problem depending on circumstance.) To open resources, the test was looking in directories relative to the SDL source directory, but this will not work well with self-contained .app bundles and Xcode which can place its built applications almost anywhere. And for real-world situations, this is pretty useless anyway. So I modified SDL_RWFromFile to do special things on OS X. First, it will look for a file in the .app bundle. If not found, it will fallback and just call fopen as it used to do. I also had to modify the automated test itself because it had a contrieved test which called fopen directly to do read from an existing FILE pointer. In addition, there was a write test. Since a .app bundle is likely going to be read-only, I added a special case for OS X to write to NSTemporaryDirectory. I expect these changes should work for both Mac and iPhone OS (which includes iPad). I will update the iPhone Xcode project next. Finally, FYI, the X11 automated test seems to be failing. Below is my output. Pending breakpoint 4 - "-[NSException raise]" resolved Platform : All tests successful (2) SDL_RWops : All tests successful (5) Rect : All tests successful (1) SDL_Surface : All tests successful (6) Rendering with cocoa driver : All tests successful (3) Assert Failed! Blit output not the same. Test Case 'Renderer x11' Test Suite 'Rendering with x11 driver' Last SDL error '' Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged. Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] : kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Rendering with x11 driver : Failed 1 out of 4 testcases! Rendering with dummy driver : All tests successful (3) SDL_Audio : All tests successful (1) Tests run with SDL 1.3.0 revision 1095906 System is running Mac OS X and is little endian --- Xcode/SDL/SDL.xcodeproj/project.pbxproj | 404 +++++++++++++++++- src/file/SDL_rwops.c | 13 +- src/file/cocoa/SDL_rwopsbundlesupport.h | 9 + src/file/cocoa/SDL_rwopsbundlesupport.m | 37 ++ .../automated/rwops/Test_rwopsbundlesupport.h | 11 + .../automated/rwops/Test_rwopsbundlesupport.m | 56 +++ test/automated/rwops/rwops.c | 19 +- test/automated/surface/surface.c | 7 +- 8 files changed, 550 insertions(+), 6 deletions(-) create mode 100644 src/file/cocoa/SDL_rwopsbundlesupport.h create mode 100644 src/file/cocoa/SDL_rwopsbundlesupport.m create mode 100644 test/automated/rwops/Test_rwopsbundlesupport.h create mode 100644 test/automated/rwops/Test_rwopsbundlesupport.m diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index 5e00827f0..5818e75a5 100755 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -104,6 +104,21 @@ 002F32E509CA0BF600EBEB88 /* SDL_dummyaudio.c in Sources */ = {isa = PBXBuildFile; fileRef = 002F32E209CA0BF600EBEB88 /* SDL_dummyaudio.c */; }; 002F32E709CA0BF600EBEB88 /* SDL_dummyaudio.c in Sources */ = {isa = PBXBuildFile; fileRef = 002F32E209CA0BF600EBEB88 /* SDL_dummyaudio.c */; }; 002F32E809CA0BF600EBEB88 /* SDL_dummyaudio.h in Headers */ = {isa = PBXBuildFile; fileRef = 002F32E309CA0BF600EBEB88 /* SDL_dummyaudio.h */; }; + 006E94A3119511A1001DE610 /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 006E949C119511A1001DE610 /* icon.bmp */; }; + 006E94A4119511A1001DE610 /* moose.dat in Resources */ = {isa = PBXBuildFile; fileRef = 006E949D119511A1001DE610 /* moose.dat */; }; + 006E94A5119511A1001DE610 /* picture.xbm in Resources */ = {isa = PBXBuildFile; fileRef = 006E949E119511A1001DE610 /* picture.xbm */; }; + 006E94A6119511A1001DE610 /* sail.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 006E949F119511A1001DE610 /* sail.bmp */; }; + 006E94A7119511A1001DE610 /* sample.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 006E94A0119511A1001DE610 /* sample.bmp */; }; + 006E94A8119511A1001DE610 /* sample.wav in Resources */ = {isa = PBXBuildFile; fileRef = 006E94A1119511A1001DE610 /* sample.wav */; }; + 006E94A9119511A1001DE610 /* utf8.txt in Resources */ = {isa = PBXBuildFile; fileRef = 006E94A2119511A1001DE610 /* utf8.txt */; }; + 006E94BC11951217001DE610 /* read in Copy rwops */ = {isa = PBXBuildFile; fileRef = 00D8DA121195093100638393 /* read */; }; + 006E94EF11951255001DE610 /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BECDF66C0761BA81005FE872 /* SDL.framework */; }; + 006E94F01195125B001DE610 /* SDL.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = BECDF66C0761BA81005FE872 /* SDL.framework */; }; + 006E95B011952992001DE610 /* SDL_rwopsbundlesupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 006E95AE11952992001DE610 /* SDL_rwopsbundlesupport.h */; }; + 006E95B111952992001DE610 /* SDL_rwopsbundlesupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 006E95AF11952992001DE610 /* SDL_rwopsbundlesupport.m */; }; + 006E95B211952992001DE610 /* SDL_rwopsbundlesupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 006E95AE11952992001DE610 /* SDL_rwopsbundlesupport.h */; }; + 006E95B311952992001DE610 /* SDL_rwopsbundlesupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 006E95AF11952992001DE610 /* SDL_rwopsbundlesupport.m */; }; + 006E95F711952D6E001DE610 /* Test_rwopsbundlesupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 006E95F611952D6E001DE610 /* Test_rwopsbundlesupport.m */; }; 007317A20858DECD00B2BC32 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0073179B0858DECD00B2BC32 /* AudioToolbox.framework */; }; 007317A30858DECD00B2BC32 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0073179C0858DECD00B2BC32 /* AudioUnit.framework */; }; 007317A40858DECD00B2BC32 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0073179D0858DECD00B2BC32 /* Cocoa.framework */; }; @@ -414,6 +429,15 @@ 00CFA89D106B4BA100758660 /* ForceFeedback.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00CFA89C106B4BA100758660 /* ForceFeedback.framework */; }; 00D0D08410675DD9004B05EF /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D0D08310675DD9004B05EF /* CoreFoundation.framework */; }; 00D0D0D810675E46004B05EF /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 007317C10858E15000B2BC32 /* Carbon.framework */; }; + 00D8DA1B1195093100638393 /* audio.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8D9FC1195093100638393 /* audio.c */; }; + 00D8DA1C1195093100638393 /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8D9FF1195093100638393 /* common.c */; }; + 00D8DA221195093100638393 /* platform.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA081195093100638393 /* platform.c */; }; + 00D8DA241195093100638393 /* rect.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA0C1195093100638393 /* rect.c */; }; + 00D8DA251195093100638393 /* render.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA0F1195093100638393 /* render.c */; }; + 00D8DA271195093100638393 /* rwops.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA131195093100638393 /* rwops.c */; }; + 00D8DA281195093100638393 /* SDL_at.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA151195093100638393 /* SDL_at.c */; }; + 00D8DA291195093100638393 /* surface.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA181195093100638393 /* surface.c */; }; + 00D8DA2A1195093100638393 /* testsdl.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA1A1195093100638393 /* testsdl.c */; }; 046B91EC0A11B53500FB151C /* SDL_sysloadso.c in Sources */ = {isa = PBXBuildFile; fileRef = 046B91E90A11B53500FB151C /* SDL_sysloadso.c */; }; 046B91ED0A11B53500FB151C /* SDL_sysloadso.c in Sources */ = {isa = PBXBuildFile; fileRef = 046B91E90A11B53500FB151C /* SDL_sysloadso.c */; }; 046B92130A11B8AD00FB151C /* SDL_dlcompat.c in Sources */ = {isa = PBXBuildFile; fileRef = 046B92100A11B8AD00FB151C /* SDL_dlcompat.c */; }; @@ -491,6 +515,13 @@ remoteGlobalIDString = 0083103F1072EA5700A531F1; remoteInfo = "Generate Doxygen DocSet"; }; + 00D8DA2E1195094500638393 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; + proxyType = 1; + remoteGlobalIDString = BECDF5FE0761BA81005FE872; + remoteInfo = Framework; + }; BECDF6C50761BA81005FE872 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; @@ -500,6 +531,31 @@ }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + 006E9491119510E1001DE610 /* Copy Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 006E94F01195125B001DE610 /* SDL.framework in Copy Frameworks */, + ); + name = "Copy Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; + 006E94B3119511CE001DE610 /* Copy rwops */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = rwops; + dstSubfolderSpec = 7; + files = ( + 006E94BC11951217001DE610 /* read in Copy rwops */, + ); + name = "Copy rwops"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 00162D3409BD1FA90037C8D0 /* SDL_config_macosx.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL_config_macosx.h; path = ../../include/SDL_config_macosx.h; sourceTree = SOURCE_ROOT; }; 00162D3709BD1FA90037C8D0 /* SDL_config.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL_config.h; path = ../../include/SDL_config.h; sourceTree = SOURCE_ROOT; }; @@ -524,6 +580,17 @@ 002F32D509CA0BE700EBEB88 /* SDL_diskaudio.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SDL_diskaudio.h; sourceTree = ""; }; 002F32E209CA0BF600EBEB88 /* SDL_dummyaudio.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = SDL_dummyaudio.c; sourceTree = ""; }; 002F32E309CA0BF600EBEB88 /* SDL_dummyaudio.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SDL_dummyaudio.h; sourceTree = ""; }; + 006E949C119511A1001DE610 /* icon.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; name = icon.bmp; path = ../../test/icon.bmp; sourceTree = SOURCE_ROOT; }; + 006E949D119511A1001DE610 /* moose.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = moose.dat; path = ../../test/moose.dat; sourceTree = SOURCE_ROOT; }; + 006E949E119511A1001DE610 /* picture.xbm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = picture.xbm; path = ../../test/picture.xbm; sourceTree = SOURCE_ROOT; }; + 006E949F119511A1001DE610 /* sail.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; name = sail.bmp; path = ../../test/sail.bmp; sourceTree = SOURCE_ROOT; }; + 006E94A0119511A1001DE610 /* sample.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; name = sample.bmp; path = ../../test/sample.bmp; sourceTree = SOURCE_ROOT; }; + 006E94A1119511A1001DE610 /* sample.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = sample.wav; path = ../../test/sample.wav; sourceTree = SOURCE_ROOT; }; + 006E94A2119511A1001DE610 /* utf8.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = utf8.txt; path = ../../test/utf8.txt; sourceTree = SOURCE_ROOT; }; + 006E95AE11952992001DE610 /* SDL_rwopsbundlesupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_rwopsbundlesupport.h; sourceTree = ""; }; + 006E95AF11952992001DE610 /* SDL_rwopsbundlesupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_rwopsbundlesupport.m; sourceTree = ""; }; + 006E95F511952D6E001DE610 /* Test_rwopsbundlesupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Test_rwopsbundlesupport.h; sourceTree = ""; }; + 006E95F611952D6E001DE610 /* Test_rwopsbundlesupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Test_rwopsbundlesupport.m; sourceTree = ""; }; 0073179B0858DECD00B2BC32 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = /System/Library/Frameworks/AudioToolbox.framework; sourceTree = ""; }; 0073179C0858DECD00B2BC32 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = /System/Library/Frameworks/AudioUnit.framework; sourceTree = ""; }; 0073179D0858DECD00B2BC32 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; @@ -685,6 +752,34 @@ 00CFA817106B49B600758660 /* SDL_yuv_sw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_yuv_sw.c; sourceTree = ""; }; 00CFA89C106B4BA100758660 /* ForceFeedback.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ForceFeedback.framework; path = /System/Library/Frameworks/ForceFeedback.framework; sourceTree = ""; }; 00D0D08310675DD9004B05EF /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = ""; }; + 00D8D92E1194EC8500638393 /* UnitTestBundle-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UnitTestBundle-Info.plist"; sourceTree = ""; }; + 00D8D9EF1195090700638393 /* testsdl.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testsdl.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 00D8D9F11195090700638393 /* testsdl-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "testsdl-Info.plist"; sourceTree = ""; }; + 00D8D9FC1195093100638393 /* audio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = audio.c; sourceTree = ""; }; + 00D8D9FD1195093100638393 /* audio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = audio.h; sourceTree = ""; }; + 00D8D9FF1195093100638393 /* common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = common.c; sourceTree = ""; }; + 00D8DA001195093100638393 /* common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = ""; }; + 00D8DA011195093100638393 /* images.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = images.h; sourceTree = ""; }; + 00D8DA021195093100638393 /* img_blit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = img_blit.c; sourceTree = ""; }; + 00D8DA031195093100638393 /* img_blitblend.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = img_blitblend.c; sourceTree = ""; }; + 00D8DA041195093100638393 /* img_face.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = img_face.c; sourceTree = ""; }; + 00D8DA051195093100638393 /* img_primitives.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = img_primitives.c; sourceTree = ""; }; + 00D8DA061195093100638393 /* img_primitivesblend.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = img_primitivesblend.c; sourceTree = ""; }; + 00D8DA081195093100638393 /* platform.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = platform.c; sourceTree = ""; }; + 00D8DA091195093100638393 /* platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = platform.h; sourceTree = ""; }; + 00D8DA0A1195093100638393 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README; path = ../../test/automated/README; sourceTree = SOURCE_ROOT; }; + 00D8DA0C1195093100638393 /* rect.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rect.c; sourceTree = ""; }; + 00D8DA0D1195093100638393 /* rect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rect.h; sourceTree = ""; }; + 00D8DA0F1195093100638393 /* render.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = render.c; sourceTree = ""; }; + 00D8DA101195093100638393 /* render.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = render.h; sourceTree = ""; }; + 00D8DA121195093100638393 /* read */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = read; sourceTree = ""; }; + 00D8DA131195093100638393 /* rwops.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rwops.c; sourceTree = ""; }; + 00D8DA141195093100638393 /* rwops.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rwops.h; sourceTree = ""; }; + 00D8DA151195093100638393 /* SDL_at.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_at.c; path = ../../test/automated/SDL_at.c; sourceTree = SOURCE_ROOT; }; + 00D8DA161195093100638393 /* SDL_at.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_at.h; path = ../../test/automated/SDL_at.h; sourceTree = SOURCE_ROOT; }; + 00D8DA181195093100638393 /* surface.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = surface.c; sourceTree = ""; }; + 00D8DA191195093100638393 /* surface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = surface.h; sourceTree = ""; }; + 00D8DA1A1195093100638393 /* testsdl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testsdl.c; path = ../../test/automated/testsdl.c; sourceTree = SOURCE_ROOT; }; 00F5D79E0990CA0D0051C449 /* UniversalBinaryNotes.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = UniversalBinaryNotes.rtf; sourceTree = ""; }; 01538330006D78D67F000001 /* SDL_audio.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = SDL_audio.c; sourceTree = ""; }; 01538331006D78D67F000001 /* SDL_audiocvt.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = SDL_audiocvt.c; sourceTree = ""; }; @@ -755,6 +850,14 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 00D8D9ED1195090700638393 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 006E94EF11951255001DE610 /* SDL.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; BECDF6680761BA81005FE872 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -869,6 +972,29 @@ path = dummy; sourceTree = ""; }; + 006E949B11951160001DE610 /* TestResources */ = { + isa = PBXGroup; + children = ( + 006E949C119511A1001DE610 /* icon.bmp */, + 006E949D119511A1001DE610 /* moose.dat */, + 006E949E119511A1001DE610 /* picture.xbm */, + 006E949F119511A1001DE610 /* sail.bmp */, + 006E94A0119511A1001DE610 /* sample.bmp */, + 006E94A1119511A1001DE610 /* sample.wav */, + 006E94A2119511A1001DE610 /* utf8.txt */, + ); + name = TestResources; + sourceTree = ""; + }; + 006E95AD11952992001DE610 /* cocoa */ = { + isa = PBXGroup; + children = ( + 006E95AE11952992001DE610 /* SDL_rwopsbundlesupport.h */, + 006E95AF11952992001DE610 /* SDL_rwopsbundlesupport.m */, + ); + path = cocoa; + sourceTree = ""; + }; 00CFA69B106B467B00758660 /* atomic */ = { isa = PBXGroup; children = ( @@ -1063,6 +1189,103 @@ path = macosx; sourceTree = ""; }; + 00D8D9FA1195091500638393 /* AutomatedTests */ = { + isa = PBXGroup; + children = ( + 00D8D9FB1195093100638393 /* audio */, + 00D8D9FE1195093100638393 /* common */, + 00D8DA071195093100638393 /* platform */, + 00D8DA0A1195093100638393 /* README */, + 00D8DA0B1195093100638393 /* rect */, + 00D8DA0E1195093100638393 /* render */, + 00D8DA111195093100638393 /* rwops */, + 00D8DA151195093100638393 /* SDL_at.c */, + 00D8DA161195093100638393 /* SDL_at.h */, + 00D8DA171195093100638393 /* surface */, + 00D8DA1A1195093100638393 /* testsdl.c */, + ); + name = AutomatedTests; + sourceTree = ""; + }; + 00D8D9FB1195093100638393 /* audio */ = { + isa = PBXGroup; + children = ( + 00D8D9FC1195093100638393 /* audio.c */, + 00D8D9FD1195093100638393 /* audio.h */, + ); + name = audio; + path = ../../test/automated/audio; + sourceTree = SOURCE_ROOT; + }; + 00D8D9FE1195093100638393 /* common */ = { + isa = PBXGroup; + children = ( + 00D8D9FF1195093100638393 /* common.c */, + 00D8DA001195093100638393 /* common.h */, + 00D8DA011195093100638393 /* images.h */, + 00D8DA021195093100638393 /* img_blit.c */, + 00D8DA031195093100638393 /* img_blitblend.c */, + 00D8DA041195093100638393 /* img_face.c */, + 00D8DA051195093100638393 /* img_primitives.c */, + 00D8DA061195093100638393 /* img_primitivesblend.c */, + ); + name = common; + path = ../../test/automated/common; + sourceTree = SOURCE_ROOT; + }; + 00D8DA071195093100638393 /* platform */ = { + isa = PBXGroup; + children = ( + 00D8DA081195093100638393 /* platform.c */, + 00D8DA091195093100638393 /* platform.h */, + ); + name = platform; + path = ../../test/automated/platform; + sourceTree = SOURCE_ROOT; + }; + 00D8DA0B1195093100638393 /* rect */ = { + isa = PBXGroup; + children = ( + 00D8DA0C1195093100638393 /* rect.c */, + 00D8DA0D1195093100638393 /* rect.h */, + ); + name = rect; + path = ../../test/automated/rect; + sourceTree = SOURCE_ROOT; + }; + 00D8DA0E1195093100638393 /* render */ = { + isa = PBXGroup; + children = ( + 00D8DA0F1195093100638393 /* render.c */, + 00D8DA101195093100638393 /* render.h */, + ); + name = render; + path = ../../test/automated/render; + sourceTree = SOURCE_ROOT; + }; + 00D8DA111195093100638393 /* rwops */ = { + isa = PBXGroup; + children = ( + 006E95F511952D6E001DE610 /* Test_rwopsbundlesupport.h */, + 006E95F611952D6E001DE610 /* Test_rwopsbundlesupport.m */, + 00D8DA121195093100638393 /* read */, + 00D8DA131195093100638393 /* rwops.c */, + 00D8DA141195093100638393 /* rwops.h */, + ); + name = rwops; + path = ../../test/automated/rwops; + sourceTree = SOURCE_ROOT; + }; + 00D8DA171195093100638393 /* surface */ = { + isa = PBXGroup; + children = ( + 00D8DA181195093100638393 /* surface.c */, + 00D8DA191195093100638393 /* surface.h */, + ); + name = surface; + path = ../../test/automated/surface; + sourceTree = SOURCE_ROOT; + }; 0153832C006D78D67F000001 /* audio */ = { isa = PBXGroup; children = ( @@ -1108,6 +1331,7 @@ 01538376006D79307F000001 /* file */ = { isa = PBXGroup; children = ( + 006E95AD11952992001DE610 /* cocoa */, 01538377006D79307F000001 /* SDL_rwops.c */, ); name = file; @@ -1249,6 +1473,7 @@ BECDF6B30761BA81005FE872 /* libSDL.a */, BECDF6BE0761BA81005FE872 /* Standard DMG */, BECDF6C30761BA81005FE872 /* Developer Extras Package */, + 00D8D9EF1195090700638393 /* testsdl.app */, ); name = Products; sourceTree = ""; @@ -1279,9 +1504,13 @@ F59C70FC00D5CB5801000001 /* pkg-support */, 0153844A006D81B07F000001 /* Public Headers */, 08FB77ACFE841707C02AAC07 /* Library Source */, + 00D8D9FA1195091500638393 /* AutomatedTests */, + 006E949B11951160001DE610 /* TestResources */, 034768DDFF38A45A11DB9C8B /* Products */, BECDF66B0761BA81005FE872 /* Info-Framework.plist */, BEC562FE0761C0E800A33029 /* Linked Frameworks */, + 00D8D92E1194EC8500638393 /* UnitTestBundle-Info.plist */, + 00D8D9F11195090700638393 /* testsdl-Info.plist */, ); comments = "To build Universal Binaries, we have experimented with a variety of different options.\nThe complication is that we must retain compatibility with at least 10.2. \nThe Universal Binary defaults only work for > 10.3.9\n\nSo far, we have found:\ngcc 4.0.0 with Xcode 2.1 always links against libgcc_s. gcc 4.0.1 from Xcode 2.2 fixes this problem.\n\nBut gcc 4.0 will not work with < 10.3.9 because we continue to get an undefined symbol to _fprintf$LDBL128.\nSo we must use gcc 3.3 on PPC to accomplish 10.2 support. (But 4.0 is required for i386.)\n\nSetting the deployment target to 10.4 will disable prebinding, so for PPC, we set it less than 10.4 to preserve prebinding for legacy support.\n\nSetting the PPC SDKROOT to /Developers/SDKs/MacOSX10.2.8.sdk will link to 63.0.0 libSystem.B.dylib. Leaving it at current or 10.4u links to 88.1.2. However, as long as we are using gcc 3.3, it doesn't seem to matter as testing has demonstrated both will run. We have decided not to invoke the 10.2.8 SDK because it is not a default installed component with Xcode which will probably cause most people problems. However, rather than deleting the SDKROOT_ppc entry entirely, we have mapped it to 10.4u in case we decide we need to change this setting.\n\nTo use Altivec or SSE, we needed architecture specific flags:\nOTHER_CFLAGS_ppc\nOTHER_CFLAGS_i386\nOTHER_CFLAGS=$(OTHER_CFLAGS_($CURRENT_ARCH))\n\nThe general OTHER_CFLAGS needed to be manually mapped to architecture specific options because Xcode didn't do this automatically for us.\n\n\n"; name = SDLFramework; @@ -1515,6 +1744,7 @@ 00CFA844106B49B600758660 /* SDL_yuv_sw_c.h in Headers */, 00A6EBDA1078D569001EEA06 /* SDL_revision.h in Headers */, 04F2AF691104AC4500D6DDF7 /* SDL_assert.h in Headers */, + 006E95B011952992001DE610 /* SDL_rwopsbundlesupport.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1614,12 +1844,33 @@ 00CFA872106B49B600758660 /* SDL_yuv_sw_c.h in Headers */, 00A6EBDB1078D569001EEA06 /* SDL_revision.h in Headers */, 04F2AF6A1104AC4500D6DDF7 /* SDL_assert.h in Headers */, + 006E95B211952992001DE610 /* SDL_rwopsbundlesupport.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + 00D8D9EE1195090700638393 /* testsdl */ = { + isa = PBXNativeTarget; + buildConfigurationList = 00D8D9F71195090900638393 /* Build configuration list for PBXNativeTarget "testsdl" */; + buildPhases = ( + 00D8D9EB1195090700638393 /* Resources */, + 00D8D9EC1195090700638393 /* Sources */, + 00D8D9ED1195090700638393 /* Frameworks */, + 006E9491119510E1001DE610 /* Copy Frameworks */, + 006E94B3119511CE001DE610 /* Copy rwops */, + ); + buildRules = ( + ); + dependencies = ( + 00D8DA2F1195094500638393 /* PBXTargetDependency */, + ); + name = testsdl; + productName = testsdl; + productReference = 00D8D9EF1195090700638393 /* testsdl.app */; + productType = "com.apple.product-type.application"; + }; BECDF5FE0761BA81005FE872 /* Framework */ = { isa = PBXNativeTarget; buildConfigurationList = 0073177A0858DB0500B2BC32 /* Build configuration list for PBXNativeTarget "Framework" */; @@ -1715,11 +1966,26 @@ BECDF6C00761BA81005FE872 /* Developer Extras Package */, 002D2A9E106C18E700BF972E /* Generate Header Files */, 0083103F1072EA5700A531F1 /* Generate Doxygen DocSet */, + 00D8D9EE1195090700638393 /* testsdl */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 00D8D9EB1195090700638393 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 006E94A3119511A1001DE610 /* icon.bmp in Resources */, + 006E94A4119511A1001DE610 /* moose.dat in Resources */, + 006E94A5119511A1001DE610 /* picture.xbm in Resources */, + 006E94A6119511A1001DE610 /* sail.bmp in Resources */, + 006E94A7119511A1001DE610 /* sample.bmp in Resources */, + 006E94A8119511A1001DE610 /* sample.wav in Resources */, + 006E94A9119511A1001DE610 /* utf8.txt in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; BECDF62A0761BA81005FE872 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -1771,7 +2037,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "sh ../../build-scripts/updaterev.sh"; + shellScript = "# The underlying scripts require calling hg to get revision info.\n# Since hg may not be in the standard Xcode path, I am sourcing .bashrc\n# But I don't know what to do if people are using other shells.\nsource ~/.bashrc\nsh ../../build-scripts/updaterev.sh\n"; }; 0083103E1072EA5700A531F1 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; @@ -1808,6 +2074,23 @@ /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 00D8D9EC1195090700638393 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 00D8DA1B1195093100638393 /* audio.c in Sources */, + 00D8DA1C1195093100638393 /* common.c in Sources */, + 00D8DA221195093100638393 /* platform.c in Sources */, + 00D8DA241195093100638393 /* rect.c in Sources */, + 00D8DA251195093100638393 /* render.c in Sources */, + 00D8DA271195093100638393 /* rwops.c in Sources */, + 00D8DA281195093100638393 /* SDL_at.c in Sources */, + 00D8DA291195093100638393 /* surface.c in Sources */, + 00D8DA2A1195093100638393 /* testsdl.c in Sources */, + 006E95F711952D6E001DE610 /* Test_rwopsbundlesupport.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; BECDF62C0761BA81005FE872 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -1920,6 +2203,7 @@ 04DB838C10FD8C81000519B5 /* SDL_blendfillrect.c in Sources */, 04DB838D10FD8C81000519B5 /* SDL_drawrect.c in Sources */, 04F2AF661104AC0800D6DDF7 /* SDL_assert.c in Sources */, + 006E95B111952992001DE610 /* SDL_rwopsbundlesupport.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2035,6 +2319,7 @@ 04DB838E10FD8C81000519B5 /* SDL_blendfillrect.c in Sources */, 04DB838F10FD8C81000519B5 /* SDL_drawrect.c in Sources */, 04F2AF671104AC0800D6DDF7 /* SDL_assert.c in Sources */, + 006E95B311952992001DE610 /* SDL_rwopsbundlesupport.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2056,6 +2341,11 @@ target = 0083103F1072EA5700A531F1 /* Generate Doxygen DocSet */; targetProxy = 008310451072EA9000A531F1 /* PBXContainerItemProxy */; }; + 00D8DA2F1195094500638393 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = BECDF5FE0761BA81005FE872 /* Framework */; + targetProxy = 00D8DA2E1195094500638393 /* PBXContainerItemProxy */; + }; BECDF6C60761BA81005FE872 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = BECDF5FE0761BA81005FE872 /* Framework */; @@ -2594,6 +2884,106 @@ }; name = Development_native_only; }; + 00D8D9F21195090800638393 /* Deployment_for_official_releases_using_10.4SDK_and_10.6SDK */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + INFOPLIST_FILE = "testsdl-Info.plist"; + INSTALL_PATH = "$(HOME)/Applications"; + OTHER_LDFLAGS = ( + "-framework", + Foundation, + "-framework", + AppKit, + ); + PREBINDING = NO; + PRODUCT_NAME = testsdl; + }; + name = Deployment_for_official_releases_using_10.4SDK_and_10.6SDK; + }; + 00D8D9F31195090800638393 /* Development_using_10.4SDK_and_10.6SDK */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + INFOPLIST_FILE = "testsdl-Info.plist"; + INSTALL_PATH = "$(HOME)/Applications"; + OTHER_LDFLAGS = ( + "-framework", + Foundation, + "-framework", + AppKit, + ); + PREBINDING = NO; + PRODUCT_NAME = testsdl; + }; + name = Development_using_10.4SDK_and_10.6SDK; + }; + 00D8D9F41195090800638393 /* Development_native_only */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + INFOPLIST_FILE = "testsdl-Info.plist"; + INSTALL_PATH = "$(HOME)/Applications"; + OTHER_LDFLAGS = ( + "-framework", + Foundation, + "-framework", + AppKit, + ); + PREBINDING = NO; + PRODUCT_NAME = testsdl; + }; + name = Development_native_only; + }; + 00D8D9F51195090800638393 /* Deployment_native_only */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + INFOPLIST_FILE = "testsdl-Info.plist"; + INSTALL_PATH = "$(HOME)/Applications"; + OTHER_LDFLAGS = ( + "-framework", + Foundation, + "-framework", + AppKit, + ); + PREBINDING = NO; + PRODUCT_NAME = testsdl; + }; + name = Deployment_native_only; + }; + 00D8D9F61195090800638393 /* Default */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + INFOPLIST_FILE = "testsdl-Info.plist"; + INSTALL_PATH = "$(HOME)/Applications"; + OTHER_LDFLAGS = ( + "-framework", + Foundation, + "-framework", + AppKit, + ); + PREBINDING = NO; + PRODUCT_NAME = testsdl; + }; + name = Default; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -2681,6 +3071,18 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Default; }; + 00D8D9F71195090900638393 /* Build configuration list for PBXNativeTarget "testsdl" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 00D8D9F21195090800638393 /* Deployment_for_official_releases_using_10.4SDK_and_10.6SDK */, + 00D8D9F31195090800638393 /* Development_using_10.4SDK_and_10.6SDK */, + 00D8D9F41195090800638393 /* Development_native_only */, + 00D8D9F51195090800638393 /* Deployment_native_only */, + 00D8D9F61195090800638393 /* Default */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Default; + }; /* End XCConfigurationList section */ }; rootObject = 0867D690FE84028FC02AAC07 /* Project object */; diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 945c60edc..b0ed77523 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -28,6 +28,10 @@ #include "SDL_endian.h" #include "SDL_rwops.h" +#ifdef __APPLE__ +#include "SDL_rwopsbundlesupport.h" +#endif /* __APPLE__ */ + #ifdef __NDS__ /* include libfat headers for fatInitDefault(). */ #include @@ -459,9 +463,12 @@ SDL_RWFromFile(const char *file, const char *mode) rwops->close = win32_file_close; #elif HAVE_STDIO_H - - fp = fopen(file, mode); - if (fp == NULL) { + #ifdef __APPLE__ + fp = SDL_OpenFPFromBundleOrFallback(file, mode); + #else + fp = fopen(file, mode); + #endif + if (fp == NULL) { SDL_SetError("Couldn't open %s", file); } else { rwops = SDL_RWFromFP(fp, 1); diff --git a/src/file/cocoa/SDL_rwopsbundlesupport.h b/src/file/cocoa/SDL_rwopsbundlesupport.h new file mode 100644 index 000000000..6929904c2 --- /dev/null +++ b/src/file/cocoa/SDL_rwopsbundlesupport.h @@ -0,0 +1,9 @@ +#ifdef __APPLE__ + +#include + +#ifndef SDL_rwopsbundlesupport_h +#define SDL_rwopsbundlesupport_h +FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode); +#endif +#endif diff --git a/src/file/cocoa/SDL_rwopsbundlesupport.m b/src/file/cocoa/SDL_rwopsbundlesupport.m new file mode 100644 index 000000000..c357e94c3 --- /dev/null +++ b/src/file/cocoa/SDL_rwopsbundlesupport.m @@ -0,0 +1,37 @@ +#ifdef __APPLE__ +#import + +/* 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. + Also, note the bundle layouts are different for iPhone and Mac. +*/ +FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode) +{ + FILE* fp = NULL; + + NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; + + + NSFileManager* file_manager = [NSFileManager defaultManager]; + NSString* resource_path = [[NSBundle mainBundle] resourcePath]; + + NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; + + NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component]; + if([file_manager fileExistsAtPath:full_path_with_file_to_try]) + { + fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode); + } + else + { + fp = fopen(file, mode); + } + + [autorelease_pool drain]; + + return fp; +} +#endif diff --git a/test/automated/rwops/Test_rwopsbundlesupport.h b/test/automated/rwops/Test_rwopsbundlesupport.h new file mode 100644 index 000000000..f3b72d54b --- /dev/null +++ b/test/automated/rwops/Test_rwopsbundlesupport.h @@ -0,0 +1,11 @@ +#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/Test_rwopsbundlesupport.m b/test/automated/rwops/Test_rwopsbundlesupport.m new file mode 100644 index 000000000..86c0fe52e --- /dev/null +++ b/test/automated/rwops/Test_rwopsbundlesupport.m @@ -0,0 +1,56 @@ +#ifdef __APPLE__ +#import + +/* 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. + Also, note the bundle layouts are different for iPhone and Mac. +*/ +FILE* Test_OpenFPFromBundleOrFallback(const char *file, const char *mode) +{ + FILE* fp = NULL; + + NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; + + + NSFileManager* file_manager = [NSFileManager defaultManager]; + NSString* resource_path = [[NSBundle mainBundle] resourcePath]; + + NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; + + NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component]; + if([file_manager fileExistsAtPath:full_path_with_file_to_try]) + { + fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode); + } + else + { + fp = fopen(file, mode); + } + + [autorelease_pool drain]; + + return fp; +} + +FILE* Test_OpenFPFromTemporaryDir(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 diff --git a/test/automated/rwops/rwops.c b/test/automated/rwops/rwops.c index 37a83c1e9..2dd7460ab 100644 --- a/test/automated/rwops/rwops.c +++ b/test/automated/rwops/rwops.c @@ -9,10 +9,17 @@ #include "SDL.h" #include "../SDL_at.h" - +#if __APPLE__ +#include "Test_rwopsbundlesupport.h" +#endif #define RWOPS_READ "rwops/read" + +#if __APPLE__ +#define RWOPS_WRITE "write" +#else #define RWOPS_WRITE "rwops/write" +#endif static const char hello_world[] = "Hello World!"; @@ -219,7 +226,12 @@ static void rwops_testFP (void) SDL_ATbegin( "SDL_RWFromFP" ); /* Run read tests. */ +#if __APPLE__ + /* Cheating: Using private API in SDL */ + fp = Test_OpenFPFromBundleOrFallback( RWOPS_READ, "r" ); +#else fp = fopen( RWOPS_READ, "r" ); +#endif if (SDL_ATassert( "Failed to open file '"RWOPS_READ"'", fp != NULL)) return; rw = SDL_RWFromFP( fp, 1 ); @@ -230,7 +242,12 @@ static void rwops_testFP (void) SDL_FreeRW( rw ); /* Run write tests. */ +#if __APPLE__ + /* Cheating: Using private API in SDL */ + fp = Test_OpenFPFromTemporaryDir( RWOPS_WRITE, "w+" ); +#else fp = fopen( RWOPS_WRITE, "w+" ); +#endif if (SDL_ATassert( "Failed to open file '"RWOPS_WRITE"'", fp != NULL)) return; rw = SDL_RWFromFP( fp, 1 ); diff --git a/test/automated/surface/surface.c b/test/automated/surface/surface.c index 3518053bf..826256039 100644 --- a/test/automated/surface/surface.c +++ b/test/automated/surface/surface.c @@ -50,7 +50,12 @@ static void surface_testLoad( SDL_Surface *testsur ) return; /* Create the blit surface. */ - face = SDL_LoadBMP("../icon.bmp"); +#ifdef __APPLE__ + face = SDL_LoadBMP("icon.bmp"); +#else + face = SDL_LoadBMP("../icon.bmp"); +#endif + if (SDL_ATassert( "SDL_CreateLoadBmp", face != NULL)) return;