Skip to content

Commit e0cefa8

Browse files
committed
Bugfix for CCFileUtils searchResolutionsOrder.
It was internally declared as NSMutableArray but accessible and writable(copy) as NSArray. This caused all kinds of weird crashes when assigning new values after setup and running the tests. Reenabled the tests depending on this.
1 parent 00884dc commit e0cefa8

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

UnitTests/CCPackageHelperTests.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,30 @@ @interface CCPackageHelperTests : XCTestCase
2020

2121
@implementation CCPackageHelperTests
2222

23-
/*
23+
2424
- (void)testDefaultResolution
2525
{
2626
// Standard test
27-
[CCFileUtils sharedFileUtils].searchResolutionsOrder = @[CCFileUtilsSuffixiPhoneHD, CCFileUtilsSuffixiPadHD];
27+
[CCFileUtils sharedFileUtils].searchResolutionsOrder = [@[CCFileUtilsSuffixiPhoneHD, CCFileUtilsSuffixiPadHD] mutableCopy];
2828
NSString *mappedResolution = [CCPackageHelper ccFileUtilsSuffixToResolution:CCFileUtilsSuffixiPhoneHD];
2929
NSString *defaultResolution = [CCPackageHelper defaultResolution];
3030
CCAssertEqualStrings(defaultResolution, mappedResolution);
3131

3232
// Ignore non mappable entriy and pick next
33-
[CCFileUtils sharedFileUtils].searchResolutionsOrder = @[@"weird_nonsense", CCFileUtilsSuffixiPadHD];
33+
[CCFileUtils sharedFileUtils].searchResolutionsOrder = [@[@"weird_nonsense", CCFileUtilsSuffixiPadHD] mutableCopy];
3434
NSString *mappedResolution2 = [CCPackageHelper ccFileUtilsSuffixToResolution:CCFileUtilsSuffixiPadHD];
3535
NSString *defaultResolution2 = [CCPackageHelper defaultResolution];
3636
CCAssertEqualStrings(defaultResolution2, mappedResolution2);
3737

3838
// Return default since nothing can be mapped
39-
[CCFileUtils sharedFileUtils].searchResolutionsOrder = @[@"nothing_to_be_mapped"];
39+
[CCFileUtils sharedFileUtils].searchResolutionsOrder = [@[@"nothing_to_be_mapped"] mutableCopy];
4040
NSString *defaultResolution3 = [CCPackageHelper defaultResolution];
4141
CCAssertEqualStrings(defaultResolution3, @"phonehd");
4242

4343
// Empty array
44-
[CCFileUtils sharedFileUtils].searchResolutionsOrder = @[];
44+
[CCFileUtils sharedFileUtils].searchResolutionsOrder = [@[] mutableCopy];
4545
NSString *defaultResolution4 = [CCPackageHelper defaultResolution];
4646
CCAssertEqualStrings(defaultResolution4, @"phonehd");
4747
}
48-
*/
4948

5049
@end

UnitTests/CCPackageManagerTests.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ - (void)setUp
2727

2828
- (void)testPackageWithName
2929
{
30-
// NOTE: This will kill many other tests due to a bug in CCFileUtils
31-
// So we assume until the bug's fixed that phonehd is the default resolution
32-
// [CCFileUtils sharedFileUtils].searchResolutionsOrder = @[CCFileUtilsSuffixiPadHD];
30+
[CCFileUtils sharedFileUtils].searchResolutionsOrder = [@[CCFileUtilsSuffixiPadHD] mutableCopy];
3331

3432
CCPackage *aPackage = [[CCPackage alloc] initWithName:@"foo"
35-
// resolution:@"tablethd" // See note above
36-
resolution:@"phonehd"
33+
resolution:@"tablethd" // See note above
3734
os:@"iOS"
3835
remoteURL:[NSURL URLWithString:@"http://foo.fake"]];
3936

cocos2d/Support/CCFileUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ typedef NS_ENUM(NSUInteger, CCFileUtilsSearchMode) {
133133
If the property "enableiPhoneResourcesOniPad" is enabled, it will also search for iPhone resources if you are in an iPad.
134134
135135
*/
136-
@property (nonatomic, copy) NSArray *searchResolutionsOrder;
136+
@property (nonatomic, strong) NSMutableArray *searchResolutionsOrder;
137137

138138
/** Array of search paths.
139139
You can use this array to modify the search path of the resources.

0 commit comments

Comments
 (0)