7
7
8
8
#import < XCTest/XCTest.h>
9
9
#import " cocos2d.h"
10
-
10
+ # import " CCUnitTestAssertions.h "
11
11
12
12
13
13
@interface CCFileUtilTests : XCTestCase
@@ -20,10 +20,29 @@ +(void) resetSingleton;
20
20
21
21
@implementation CCFileUtilTests
22
22
23
+ - (void )setUp
24
+ {
25
+ [super setUp ];
26
+
27
+ [CCFileUtils resetSingleton ];
28
+
29
+ CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils ];
30
+
31
+ sharedFileUtils.directoriesDict =
32
+ [@{CCFileUtilsSuffixiPad : @" resources-tablet" ,
33
+ CCFileUtilsSuffixiPadHD : @" resources-tablethd" ,
34
+ CCFileUtilsSuffixiPhone : @" resources-phone" ,
35
+ CCFileUtilsSuffixiPhoneHD : @" resources-phonehd" ,
36
+ CCFileUtilsSuffixiPhone5 : @" resources-phone" ,
37
+ CCFileUtilsSuffixiPhone5HD : @" resources-phonehd" ,
38
+ CCFileUtilsSuffixDefault : @" " } mutableCopy];
39
+
40
+ sharedFileUtils.searchMode = CCFileUtilsSearchModeDirectory;
41
+ [sharedFileUtils buildSearchResolutionsOrder ];
42
+ }
23
43
24
44
-(void )testFullPathForFilenameMissingFile
25
45
{
26
- [CCFileUtils resetSingleton ];
27
46
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils ];
28
47
29
48
NSString *path = [sharedFileUtils fullPathForFilename: @" file that does not exist" ];
@@ -33,8 +52,6 @@ -(void)testFullPathForFilenameMissingFile
33
52
// File does not exist in this directory
34
53
path = [sharedFileUtils fullPathForFilename: @" powered.png" ];
35
54
XCTAssertTrue (path == nil , @" " );
36
-
37
-
38
55
}
39
56
40
57
// XCode Unit tests look inside the target's test application bundle - not the unit test app bundle, but the "cocos2d-tests-ios.app" bundle.
@@ -48,20 +65,64 @@ -(void)testFullPathForFilename
48
65
XCTAssertTrue (path != nil , @" " );
49
66
}
50
67
68
+ - (void )testFullPathsOfFileNameInAllSearchPaths
69
+ {
70
+ NSString *pathToUnzippedPackage = [[[NSBundle mainBundle ] bundlePath ] stringByAppendingPathComponent: @" Resources-shared/Packages/testpackage-iOS-phonehd_unzipped/testpackage-iOS-phonehd" ];
71
+ NSString *pathToUnzippedPackage2 = [[[NSBundle mainBundle ] bundlePath ] stringByAppendingPathComponent: @" Resources-shared/Packages/anotherpackage-iOS-phonehd_unzipped/anotherpackage-iOS-phonehd" ];
72
+
73
+ [CCFileUtils sharedFileUtils ].searchPath = @[pathToUnzippedPackage, pathToUnzippedPackage2];
74
+
75
+ NSArray *paths = [[CCFileUtils sharedFileUtils ] fullPathsOfFileNameInAllSearchPaths: @" fileLookup.plist" ];
76
+ XCTAssertEqual (paths.count , 2 );
77
+ }
78
+
79
+ - (void )testLoadFileNameLookupsInAllSearchPaths
80
+ {
81
+ NSString *pathToPackage = [NSTemporaryDirectory () stringByAppendingPathComponent: @" pack1" ];
82
+ NSString *pathToPackage2 = [NSTemporaryDirectory () stringByAppendingPathComponent: @" pack2" ];
83
+
84
+ [CCFileUtils sharedFileUtils ].searchPath = @[pathToPackage, pathToPackage2];
85
+
86
+ NSFileManager *fileManager = [NSFileManager defaultManager ];
87
+ [fileManager createDirectoryAtPath: pathToPackage withIntermediateDirectories: YES attributes: nil error: nil ];
88
+ [fileManager createDirectoryAtPath: pathToPackage2 withIntermediateDirectories: YES attributes: nil error: nil ];
89
+
90
+ NSDictionary *lookup1 = @{
91
+ @" filenames" : @{
92
+ @" foo.wav" : @" foo.mp4"
93
+ },
94
+ @" metadata" : @{
95
+ @" version" : @1
96
+ }
97
+ };
98
+ [lookup1 writeToFile: [pathToPackage stringByAppendingPathComponent: @" fileLookup.plist" ] atomically: YES ];
99
+
100
+ NSDictionary *lookup2 = @{
101
+ @" filenames" : @{
102
+ @" baa.psd" : @" baa.png"
103
+ },
104
+ @" metadata" : @{
105
+ @" version" : @1
106
+ }
107
+ };
108
+ [lookup2 writeToFile: [pathToPackage2 stringByAppendingPathComponent: @" fileLookup.plist" ] atomically: YES ];
109
+
110
+ [[CCFileUtils sharedFileUtils ] loadFileNameLookupsInAllSearchPathsWithName: @" fileLookup.plist" ];
111
+ NSDictionary *filenameLookup = [CCFileUtils sharedFileUtils ].filenameLookup ;
112
+ CCAssertEqualStrings (filenameLookup[@" baa.psd" ], @" baa.png" );
113
+ CCAssertEqualStrings (filenameLookup[@" foo.wav" ], @" foo.mp4" );
114
+ }
115
+
51
116
-(void )testCCFileUtilsSearchModeSuffix
52
117
{
53
- [CCFileUtils resetSingleton ];
54
118
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils ];
55
119
sharedFileUtils.searchMode = CCFileUtilsSearchModeSuffix;
56
120
57
121
XCTAssertTrue ([sharedFileUtils fullPathForFilename: @" Images/powered.png" ] != nil , @" " );
58
-
59
-
60
122
}
61
123
62
124
-(void )testCCFileUtilsSearchModeDirectory
63
125
{
64
- [CCFileUtils resetSingleton ];
65
126
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils ];
66
127
sharedFileUtils.searchMode = CCFileUtilsSearchModeDirectory;
67
128
@@ -80,20 +141,16 @@ -(void)testCCFileUtilsSearchModeDirectory
80
141
81
142
-(void )testCustomSearchPathsForExtensions
82
143
{
83
- [CCFileUtils resetSingleton ];
84
144
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils ];
85
145
[sharedFileUtils purgeCachedEntries ];
86
146
[sharedFileUtils setSearchPath: @[ @" Images" , kCCFileUtilsDefaultSearchPath ] ];
87
147
88
148
XCTAssertTrue ( [sharedFileUtils fullPathForFilename: @" Images/powered.png" contentScale: nil ] != nil , @" " );
89
149
XCTAssertTrue ( [sharedFileUtils fullPathForFilename: @" powered.png" contentScale: nil ] != nil , @" Search path 'Images' didn't work." );
90
-
91
150
}
92
151
93
-
94
152
-(void )testContentScaleLoading
95
153
{
96
- [CCFileUtils resetSingleton ];
97
154
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils ];
98
155
sharedFileUtils.searchMode = CCFileUtilsSearchModeSuffix;
99
156
@@ -103,15 +160,11 @@ -(void)testContentScaleLoading
103
160
[ (NSMutableArray *) [sharedFileUtils searchResolutionsOrder ] removeAllObjects ];
104
161
[ (NSMutableArray *) [sharedFileUtils searchResolutionsOrder ] addObject: CCFileUtilsSuffixiPhoneHD];
105
162
106
-
107
163
CGFloat scale = 0.0 ;
108
164
109
165
NSString *path1 = [sharedFileUtils fullPathForFilename: @" Images/blocks.png" contentScale: &scale];
110
166
XCTAssertTrue (scale == 2.0 , @" " );
111
167
XCTAssertTrue (path1 != nil , @" " );
112
-
113
168
}
114
169
115
-
116
-
117
170
@end
0 commit comments