Skip to content

Commit 33c3120

Browse files
committed
CCPackage unit tests added.
Fix for file urls serialization: Prevent prepending of file:// scheme of installURL for de/serialization cycles.
1 parent f0c3220 commit 33c3120

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

UnitTests/CCPackageTests.m

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,79 @@
77
//
88

99
#import <XCTest/XCTest.h>
10+
#import "CCPackage.h"
11+
#import "CCUnitTestAssertions.h"
1012

1113
@interface CCPackageTests : XCTestCase
1214

1315
@end
1416

17+
1518
@implementation CCPackageTests
1619

17-
- (void)setUp
20+
- (void)testInitializer
1821
{
19-
[super setUp];
20-
// Put setup code here. This method is called before the invocation of each test method in the class.
22+
CCPackage *package = [[CCPackage alloc] initWithName:@"DLC"
23+
resolution:@"tablethd"
24+
os:@"iOS"
25+
remoteURL:[NSURL URLWithString:@"http://foo.fake"]];
26+
27+
CCAssertEqualStrings(package.name, @"DLC");
28+
CCAssertEqualStrings(package.resolution, @"tablethd");
29+
CCAssertEqualStrings(package.os, @"iOS");
30+
XCTAssertEqualObjects(package.remoteURL, [NSURL URLWithString:@"http://foo.fake"]);
31+
XCTAssertEqual(package.status, CCPackageStatusInitial);
2132
}
2233

23-
- (void)tearDown
34+
- (void)testStandardIdentifier
2435
{
25-
// Put teardown code here. This method is called after the invocation of each test method in the class.
26-
[super tearDown];
36+
CCPackage *package = [[CCPackage alloc] initWithName:@"DLC"
37+
resolution:@"tablethd"
38+
os:@"iOS"
39+
remoteURL:[NSURL URLWithString:@"http://foo.fake"]];
40+
41+
CCAssertEqualStrings([package standardIdentifier], @"DLC-iOS-tablethd");
2742
}
2843

29-
- (void)testExample
44+
- (void)testInitWithDictionary
3045
{
31-
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
46+
NSDictionary *dictionary = @{
47+
@"name" : @"DLC",
48+
@"resolution" : @"tablethd",
49+
@"os" : @"iOS",
50+
@"remoteURL" : @"http://foo.fake",
51+
@"installURL" : @"/Library/Caches/Packages",
52+
@"status" : @(CCPackageStatusInstalledDisabled),
53+
};
54+
55+
CCPackage *package = [[CCPackage alloc] initWithDictionary:dictionary];
56+
57+
CCAssertEqualStrings(package.name, @"DLC");
58+
CCAssertEqualStrings(package.resolution, @"tablethd");
59+
CCAssertEqualStrings(package.os, @"iOS");
60+
XCTAssertEqualObjects(package.remoteURL, [NSURL URLWithString:@"http://foo.fake"]);
61+
XCTAssertEqualObjects(package.installURL, [NSURL fileURLWithPath:@"/Library/Caches/Packages"]);
62+
XCTAssertEqual(package.status, CCPackageStatusInstalledDisabled);
63+
}
64+
65+
- (void)testToDictionary
66+
{
67+
CCPackage *package = [[CCPackage alloc] initWithName:@"DLC"
68+
resolution:@"tablethd"
69+
os:@"iOS"
70+
remoteURL:[NSURL URLWithString:@"http://foo.fake"]];
71+
72+
[package setValue:@(CCPackageStatusInstalledDisabled) forKey:@"status"];
73+
[package setValue:[NSURL fileURLWithPath:@"/Library/Caches/Packages"] forKey:@"installURL"];
74+
75+
NSDictionary *dictionary = [package toDictionary];
76+
77+
CCAssertEqualStrings(dictionary[@"name"], @"DLC");
78+
CCAssertEqualStrings(dictionary[@"resolution"], @"tablethd");
79+
CCAssertEqualStrings(dictionary[@"os"], @"iOS");
80+
CCAssertEqualStrings(dictionary[@"remoteURL"], @"http://foo.fake");
81+
CCAssertEqualStrings(dictionary[@"installURL"], @"/Library/Caches/Packages");
82+
XCTAssertEqual([dictionary[@"status"] integerValue], CCPackageStatusInstalledDisabled);
3283
}
3384

3485
@end

cocos2d/CCPackage.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
6161
os:dictionary[PACKAGE_SERIALIZATION_KEY_OS]
6262
remoteURL:[NSURL URLWithString:dictionary[PACKAGE_SERIALIZATION_KEY_REMOTE_URL]]];
6363

64-
package.installURL = [NSURL URLWithString:dictionary[PACKAGE_SERIALIZATION_KEY_INSTALL_URL]];
64+
package.installURL = [NSURL fileURLWithPath:dictionary[PACKAGE_SERIALIZATION_KEY_INSTALL_URL]];
6565
package.status = (CCPackageStatus) [dictionary[PACKAGE_SERIALIZATION_KEY_STATUS] unsignedIntegerValue];
6666

6767
return package;
@@ -84,7 +84,7 @@ - (NSDictionary *)toDictionary
8484
dictionary[PACKAGE_SERIALIZATION_KEY_VERSION] = @(PACKAGE_SERIALIZATION_VERSION);
8585
if (_installURL)
8686
{
87-
dictionary[PACKAGE_SERIALIZATION_KEY_INSTALL_URL] = [_installURL absoluteString];
87+
dictionary[PACKAGE_SERIALIZATION_KEY_INSTALL_URL] = [_installURL path];
8888
}
8989

9090
return dictionary;

0 commit comments

Comments
 (0)