Skip to content

Commit 405a8f2

Browse files
committed
CCPackage with install data now.
1 parent 87a59ec commit 405a8f2

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

UnitTests/CCPackageTests.m

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
#import <XCTest/XCTest.h>
1010
#import "CCPackage.h"
11+
#import "CCPackage_private.h"
1112
#import "CCUnitTestAssertions.h"
13+
#import "CCPackage+InstallData.h"
1214

1315
@interface CCPackageTests : XCTestCase
1416

@@ -53,6 +55,10 @@ - (void)testInitWithDictionary
5355
@"remoteURL" : @"http://foo.fake",
5456
@"installURL" : @"/Library/Caches/Packages",
5557
@"status" : @(CCPackageStatusInstalledDisabled),
58+
@"localDownloadURL" : @"/downloadfolder/baa.zip",
59+
@"localUnzipURL" : @"/unzupfolder/foo",
60+
@"folderName" : @"somename",
61+
@"enableOnDownload" : @(YES)
5662
};
5763

5864
CCPackage *package = [[CCPackage alloc] initWithDictionary:dictionary];
@@ -63,6 +69,10 @@ - (void)testInitWithDictionary
6369
XCTAssertEqualObjects(package.remoteURL, [NSURL URLWithString:@"http://foo.fake"]);
6470
XCTAssertEqualObjects(package.installURL, [NSURL fileURLWithPath:@"/Library/Caches/Packages"]);
6571
XCTAssertEqual(package.status, CCPackageStatusInstalledDisabled);
72+
XCTAssertEqualObjects(package.localDownloadURL, [NSURL fileURLWithPath:@"/downloadfolder/baa.zip"]);
73+
XCTAssertEqualObjects(package.unzipURL, [NSURL fileURLWithPath:@"/unzupfolder/foo"]);
74+
CCAssertEqualStrings(package.folderName, @"somename");
75+
XCTAssertTrue(package.enableOnDownload);
6676
}
6777

6878
- (void)testToDictionary
@@ -72,8 +82,12 @@ - (void)testToDictionary
7282
os:@"iOS"
7383
remoteURL:[NSURL URLWithString:@"http://foo.fake"]];
7484

75-
[package setValue:@(CCPackageStatusInstalledDisabled) forKey:@"status"];
76-
[package setValue:[NSURL fileURLWithPath:@"/Library/Caches/Packages"] forKey:@"installURL"];
85+
package.status = CCPackageStatusInstalledDisabled;
86+
package.installURL = [NSURL fileURLWithPath:@"/Library/Caches/Packages"];
87+
package.unzipURL = [NSURL fileURLWithPath:@"/unzupfolder/foo"];
88+
package.folderName = @"somename";
89+
package.localDownloadURL = [NSURL fileURLWithPath:@"/downloadfolder/baa.zip"];
90+
package.enableOnDownload = NO;
7791

7892
NSDictionary *dictionary = [package toDictionary];
7993

@@ -83,6 +97,10 @@ - (void)testToDictionary
8397
CCAssertEqualStrings(dictionary[@"remoteURL"], @"http://foo.fake");
8498
CCAssertEqualStrings(dictionary[@"installURL"], @"/Library/Caches/Packages");
8599
XCTAssertEqual([dictionary[@"status"] integerValue], CCPackageStatusInstalledDisabled);
100+
CCAssertEqualStrings(dictionary[@"localDownloadURL"], @"/downloadfolder/baa.zip");
101+
CCAssertEqualStrings(dictionary[@"localUnzipURL"], @"/unzupfolder/foo");
102+
CCAssertEqualStrings(dictionary[@"folderName"], @"somename");
103+
XCTAssertFalse([dictionary[@"enableOnDownload"] boolValue]);
86104
}
87105

88106
@end

cocos2d/CCPackage.m

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
6565
package.installURL = [NSURL fileURLWithPath:dictionary[PACKAGE_SERIALIZATION_KEY_INSTALL_URL]];
6666
package.status = (CCPackageStatus) [dictionary[PACKAGE_SERIALIZATION_KEY_STATUS] unsignedIntegerValue];
6767

68+
if (dictionary[PACKAGE_SERIALIZATION_KEY_LOCAL_DOWNLOAD_URL])
69+
{
70+
package.localDownloadURL = [NSURL fileURLWithPath:dictionary[PACKAGE_SERIALIZATION_KEY_LOCAL_DOWNLOAD_URL]];
71+
}
72+
73+
if (dictionary[PACKAGE_SERIALIZATION_KEY_LOCAL_UNZIP_URL])
74+
{
75+
package.unzipURL = [NSURL fileURLWithPath:dictionary[PACKAGE_SERIALIZATION_KEY_LOCAL_UNZIP_URL]];
76+
}
77+
78+
if (dictionary[PACKAGE_SERIALIZATION_KEY_FOLDER_NAME])
79+
{
80+
package.folderName = dictionary[PACKAGE_SERIALIZATION_KEY_FOLDER_NAME];
81+
}
82+
83+
if (dictionary[PACKAGE_SERIALIZATION_KEY_FOLDER_NAME])
84+
{
85+
package.enableOnDownload = [dictionary[PACKAGE_SERIALIZATION_KEY_ENABLE_ON_DOWNLOAD] boolValue];
86+
}
87+
6888
return package;
6989
}
7090

@@ -88,6 +108,23 @@ - (NSDictionary *)toDictionary
88108
dictionary[PACKAGE_SERIALIZATION_KEY_INSTALL_URL] = [_installURL path];
89109
}
90110

111+
if (_localDownloadURL)
112+
{
113+
dictionary[PACKAGE_SERIALIZATION_KEY_LOCAL_DOWNLOAD_URL] = [_localDownloadURL path];
114+
}
115+
116+
if (_unzipURL)
117+
{
118+
dictionary[PACKAGE_SERIALIZATION_KEY_LOCAL_UNZIP_URL] = [_unzipURL path];
119+
}
120+
121+
if (_folderName)
122+
{
123+
dictionary[PACKAGE_SERIALIZATION_KEY_FOLDER_NAME] = _folderName;
124+
}
125+
126+
dictionary[PACKAGE_SERIALIZATION_KEY_ENABLE_ON_DOWNLOAD] = @(_enableOnDownload);
127+
91128
return dictionary;
92129
}
93130

0 commit comments

Comments
 (0)