Skip to content

Commit a2bf755

Browse files
author
Thayer J Andrews
committed
Merge remote-tracking branch 'upstream/develop' into develop
2 parents 0aedcac + 69910e4 commit a2bf755

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1299
-322
lines changed

UnitTests/CCFileUtilTests.m

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#import <XCTest/XCTest.h>
99
#import "cocos2d.h"
10-
10+
#import "CCUnitTestAssertions.h"
1111

1212

1313
@interface CCFileUtilTests : XCTestCase
@@ -20,10 +20,29 @@ +(void) resetSingleton;
2020

2121
@implementation CCFileUtilTests
2222

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+
}
2343

2444
-(void)testFullPathForFilenameMissingFile
2545
{
26-
[CCFileUtils resetSingleton];
2746
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
2847

2948
NSString *path = [sharedFileUtils fullPathForFilename:@"file that does not exist"];
@@ -33,8 +52,6 @@ -(void)testFullPathForFilenameMissingFile
3352
// File does not exist in this directory
3453
path = [sharedFileUtils fullPathForFilename:@"powered.png"];
3554
XCTAssertTrue(path == nil, @"");
36-
37-
3855
}
3956

4057
// 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
4865
XCTAssertTrue(path != nil, @"");
4966
}
5067

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+
51116
-(void)testCCFileUtilsSearchModeSuffix
52117
{
53-
[CCFileUtils resetSingleton];
54118
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
55119
sharedFileUtils.searchMode = CCFileUtilsSearchModeSuffix;
56120

57121
XCTAssertTrue([sharedFileUtils fullPathForFilename:@"Images/powered.png"] != nil, @"");
58-
59-
60122
}
61123

62124
-(void)testCCFileUtilsSearchModeDirectory
63125
{
64-
[CCFileUtils resetSingleton];
65126
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
66127
sharedFileUtils.searchMode = CCFileUtilsSearchModeDirectory;
67128

@@ -80,20 +141,16 @@ -(void)testCCFileUtilsSearchModeDirectory
80141

81142
-(void)testCustomSearchPathsForExtensions
82143
{
83-
[CCFileUtils resetSingleton];
84144
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
85145
[sharedFileUtils purgeCachedEntries];
86146
[sharedFileUtils setSearchPath: @[ @"Images", kCCFileUtilsDefaultSearchPath] ];
87147

88148
XCTAssertTrue( [sharedFileUtils fullPathForFilename:@"Images/powered.png" contentScale:nil] != nil, @"");
89149
XCTAssertTrue( [sharedFileUtils fullPathForFilename:@"powered.png" contentScale:nil] != nil, @"Search path 'Images' didn't work.");
90-
91150
}
92151

93-
94152
-(void)testContentScaleLoading
95153
{
96-
[CCFileUtils resetSingleton];
97154
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
98155
sharedFileUtils.searchMode = CCFileUtilsSearchModeSuffix;
99156

@@ -103,15 +160,11 @@ -(void)testContentScaleLoading
103160
[ (NSMutableArray*) [sharedFileUtils searchResolutionsOrder] removeAllObjects];
104161
[ (NSMutableArray*) [sharedFileUtils searchResolutionsOrder] addObject:CCFileUtilsSuffixiPhoneHD];
105162

106-
107163
CGFloat scale = 0.0;
108164

109165
NSString *path1 = [sharedFileUtils fullPathForFilename:@"Images/blocks.png" contentScale:&scale];
110166
XCTAssertTrue(scale == 2.0, @"");
111167
XCTAssertTrue(path1 != nil, @"");
112-
113168
}
114169

115-
116-
117170
@end

UnitTests/CCPackageDownloadManagerTests.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "CCDirector.h"
1414
#import "AppDelegate.h"
1515
#import "CCUnitTestAssertions.h"
16+
#import "CCPackage_private.h"
1617

1718
@interface CCPackageDownloadManagerTestURLProtocol : NSURLProtocol @end
1819

@@ -175,6 +176,22 @@ - (void)testEnqueuePausedPackage
175176
[self assertPackagesDownloadedAndContentsAreAsExpected:@[package1]];
176177
}
177178

179+
- (void)testResumeDownloadAfterLoadingPackages
180+
{
181+
// This test aims at the situation when coming back from persistency and
182+
// the package manager resume downloads.
183+
184+
CCPackage *package = [self completePackageWithName:@"package"];
185+
package.status = CCPackageStatusDownloadPaused;
186+
package.localDownloadURL = [NSURL fileURLWithPath:[_downloadManager.downloadPath stringByAppendingPathComponent:@"foo.zip"]];
187+
188+
[_downloadManager enqueuePackageForDownload:package];
189+
190+
[self waitUntilDelegateReturns];
191+
192+
[self assertPackagesDownloadedAndContentsAreAsExpected:@[package]];
193+
}
194+
178195
- (void)waitUntilDelegateReturns
179196
{
180197
while (!_allDownloadsReturned)

UnitTests/CCPackageDownloadTests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ - (void)testCancelDownload
298298

299299
NSFileManager *fileManager = [NSFileManager defaultManager];
300300
XCTAssertFalse([fileManager fileExistsAtPath:_download.localURL.path]);
301+
XCTAssertEqual(_package.status, CCPackageStatusInitial);
301302
}
302303

303304
- (void)testPauseDownload

UnitTests/CCPackageHelperTests.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ @interface CCPackageHelperTests : XCTestCase
2020

2121
@implementation CCPackageHelperTests
2222

23-
2423
- (void)testDefaultResolution
2524
{
2625
// Standard test

UnitTests/CCPackageInstallerTests.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,21 @@ - (void)testInstallFailingPackageAlreadyExists
122122

123123
- (void)setupInstallablePackage
124124
{
125+
_package.folderName = @"testpackage-iOS-phonehd";
126+
125127
NSString *pathToPackage = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Resources-shared/Packages/testpackage-iOS-phonehd_unzipped"];
128+
NSString *unzipPath = [NSTemporaryDirectory() stringByAppendingPathComponent:_package.folderName];
129+
130+
NSFileManager *fileManager = [NSFileManager defaultManager];
131+
NSError *error;
132+
[fileManager removeItemAtPath:unzipPath error:nil];
133+
if (![fileManager copyItemAtPath:pathToPackage toPath:unzipPath error:&error])
134+
{
135+
NSLog(@"%@", error);
136+
}
137+
138+
_package.unzipURL = [NSURL fileURLWithPath:unzipPath];
126139

127-
_package.unzipURL = [NSURL fileURLWithPath:pathToPackage];
128-
_package.folderName = @"testpackage-iOS-phonehd";
129140
_package.enableOnDownload = NO;
130141
}
131142

0 commit comments

Comments
 (0)