Mercurial > sdl-ios-xcode
annotate test/automated/rwops/TestSupportRWops_Cocoa.m @ 4841:740e833b2c00
Fixed overwriting of SDL_shape.c in merge.
author | Eli Gottlieb <eligottlieb@gmail.com> |
---|---|
date | Mon, 09 Aug 2010 20:27:45 -0400 |
parents | 033c455bbe99 |
children |
rev | line source |
---|---|
4451
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
1 #import "TestSupportRWops.h" |
4447
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2 #import <Foundation/Foundation.h> |
4451
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
3 #include "SDL.h" |
4447
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5 /* For proper OS X applications, the resources are contained inside the application bundle. |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6 So the strategy is to first check the application bundle for the file, then fallback to the current working directory. |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7 Note: One additional corner-case is if the resource is in a framework's resource bundle instead of the app. |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
8 We might want to use bundle identifiers, e.g. org.libsdl.sdl to get the bundle for the framework, |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
9 but we would somehow need to know what the bundle identifiers we need to search are. |
4451
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
10 Conversely, write directories are usually not in the bundles. This implementation uses NSTemporaryDirectory, |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
11 but consider Preferences, Application Support, Documents, etc. |
4447
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
12 Also, note the bundle layouts are different for iPhone and Mac. |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
13 */ |
4451
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
14 |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
15 const char* RWOPS_READ = "rwops/read"; |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
16 const char* RWOPS_WRITE = "write"; |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
17 |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
18 |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
19 FILE* TestSupportRWops_OpenFPFromReadDir(const char *file, const char *mode) |
4447
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
20 { |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
21 FILE* fp = NULL; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
22 |
4449
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
23 // If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only. |
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
24 if(strcmp("r", mode) && strcmp("rb", mode)) |
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
25 { |
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
26 return fopen(file, mode); |
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
27 } |
8f73f4a3c972
Exempted writable modes from bundle check on OS X since bundle areas are typically read-only.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4447
diff
changeset
|
28 |
4447
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
29 NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
30 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
31 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
32 NSFileManager* file_manager = [NSFileManager defaultManager]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
33 NSString* resource_path = [[NSBundle mainBundle] resourcePath]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
34 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
35 NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
36 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
37 NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
38 if([file_manager fileExistsAtPath:full_path_with_file_to_try]) |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
39 { |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
40 fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode); |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
41 } |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
42 else |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
43 { |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
44 fp = fopen(file, mode); |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
45 } |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
46 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
47 [autorelease_pool drain]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
48 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
49 return fp; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
50 } |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
51 |
4451
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
52 FILE* TestSupportRWops_OpenFPFromWriteDir(const char *file, const char *mode) |
4447
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
53 { |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
54 FILE* fp = NULL; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
55 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
56 NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
57 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
58 NSFileManager* file_manager = [NSFileManager defaultManager]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
59 NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
60 NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component]; |
4451
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
61 |
4447
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
62 fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode); |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
63 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
64 [autorelease_pool drain]; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
65 |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
66 return fp; |
947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
67 } |
4451
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
68 |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
69 SDL_RWops* TestSupportRWops_OpenRWopsFromReadDir(const char *file, const char *mode) |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
70 { |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
71 return SDL_RWFromFile(file, mode); |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
72 } |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
73 |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
74 SDL_RWops* TestSupportRWops_OpenRWopsFromWriteDir(const char *file, const char *mode) |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
75 { |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
76 SDL_RWops* rw = NULL; |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
77 |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
78 NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
79 |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
80 NSFileManager* file_manager = [NSFileManager defaultManager]; |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
81 NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)]; |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
82 NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component]; |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
83 |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
84 rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode ); |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
85 |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
86 [autorelease_pool drain]; |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
87 return rw; |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
88 } |
033c455bbe99
Refactored automated rwops tests so read and write directories can be more easily customized.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
4449
diff
changeset
|
89 |