Skip to content

Commit 9dfa2d7

Browse files
committed
First package test added to cocos2d-tests-ios.
Extracted some cocos2d config code in app delegate and made that public to rerun packages tests.
1 parent dfc0625 commit 9dfa2d7

File tree

4 files changed

+199
-13
lines changed

4 files changed

+199
-13
lines changed

cocos2d-tests-ios.xcodeproj/project.pbxproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
758A6C7B18440D5C00D1A8D2 /* ParticleTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 758A6C7A18440D5C00D1A8D2 /* ParticleTest.m */; };
2727
758A6C80184410EE00D1A8D2 /* Particles in Resources */ = {isa = PBXBuildFile; fileRef = 758A6C7F184410EE00D1A8D2 /* Particles */; };
2828
75F76497185A831B00E2FAFE /* Sounds in Resources */ = {isa = PBXBuildFile; fileRef = 75F76496185A831B00E2FAFE /* Sounds */; };
29+
839B149F19CC1E440000E5E2 /* CCPackageTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 839B149E19CC1E440000E5E2 /* CCPackageTest.m */; };
2930
92324E2A18EB635500D78D3F /* CCReaderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 92324E2918EB635500D78D3F /* CCReaderTest.m */; };
3031
9269312A1923D8A700CE6285 /* Resources-shared in Resources */ = {isa = PBXBuildFile; fileRef = B7C6237517EA695100928F91 /* Resources-shared */; };
3132
92FE241118F5F06F00647961 /* CCAnimationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 92FE241018F5F06F00647961 /* CCAnimationTest.m */; };
@@ -221,6 +222,7 @@
221222
75EA924B1860BFC800BF914A /* PerformanceTextureTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceTextureTest.h; sourceTree = "<group>"; };
222223
75EA924C1860BFC800BF914A /* PerformanceTextureTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PerformanceTextureTest.m; sourceTree = "<group>"; };
223224
75F76496185A831B00E2FAFE /* Sounds */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Sounds; path = Resources/Sounds; sourceTree = SOURCE_ROOT; };
225+
839B149E19CC1E440000E5E2 /* CCPackageTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCPackageTest.m; path = "cocos2d-ui-tests/tests/CCPackageTest.m"; sourceTree = SOURCE_ROOT; };
224226
92324E2918EB635500D78D3F /* CCReaderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCReaderTest.m; sourceTree = "<group>"; };
225227
92FE241018F5F06F00647961 /* CCAnimationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCAnimationTest.m; sourceTree = "<group>"; };
226228
A6167B92189A7D4D0044D391 /* VertexZTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VertexZTest.m; path = "cocos2d-ui-tests/tests/VertexZTest.m"; sourceTree = SOURCE_ROOT; };
@@ -520,6 +522,7 @@
520522
D3B2A7E4187DD60B00406C5A /* CCBMFontTest.m */,
521523
A6167B92189A7D4D0044D391 /* VertexZTest.m */,
522524
A664A4EE18A3D9B8006184B8 /* PositioningTest.m */,
525+
839B149E19CC1E440000E5E2 /* CCPackageTest.m */,
523526
);
524527
name = Tests;
525528
path = "cocos2d-ui-tests/tests";
@@ -532,6 +535,7 @@
532535
B7E2605F17E7D278007067F0 /* cocos2d-tests-ios */,
533536
B7E2604A17E7D278007067F0 /* Frameworks */,
534537
B7E2604917E7D278007067F0 /* Products */,
538+
E525F171C7FA9B056FA8C500,
535539
);
536540
sourceTree = "<group>";
537541
};
@@ -962,6 +966,7 @@
962966
7587BDB3185A0A6900EEEFDE /* TextureTest.m in Sources */,
963967
D3C9C867188078B900C58900 /* CCSchedulerTest.m in Sources */,
964968
7587BDB7185A64AD00EEEFDE /* ColorTest.m in Sources */,
969+
839B149F19CC1E440000E5E2 /* CCPackageTest.m in Sources */,
965970
D340E10F185660BE006E605C /* TilemapTest.m in Sources */,
966971
B7E2622117E7D3B2007067F0 /* MainMenu.m in Sources */,
967972
D3D6CF5F18BD5F0500A51531 /* CCRendererTest.m in Sources */,

cocos2d-ui-tests/ios/AppDelegate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@
2929
{
3030
}
3131

32+
- (void)configureFileUtilsSearchPathAndRegisterSpriteSheets;
33+
3234
@end

cocos2d-ui-tests/ios/AppDelegate.m

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,36 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3434
{
3535
// Configure the file utils to work with SpriteBuilder, but use a custom resource path (Resources-shared instead of Published-iOS)
3636
[CCBReader configureCCFileUtils];
37-
37+
38+
[self configureFileUtilsSearchPathAndRegisterSpriteSheets];
39+
40+
[self setupCocos2dWithOptions:@{
41+
CCSetupDepthFormat: @GL_DEPTH24_STENCIL8,
42+
// CCSetupScreenMode: CCScreenModeFixed,
43+
// CCSetupScreenOrientation: CCScreenOrientationPortrait,
44+
CCSetupTabletScale2X: @YES,
45+
// CCSetupShowDebugStats: @YES,
46+
}];
47+
48+
return YES;
49+
}
50+
51+
- (void)configureFileUtilsSearchPathAndRegisterSpriteSheets
52+
{
3853
CCFileUtils* sharedFileUtils = [CCFileUtils sharedFileUtils];
39-
54+
4055
sharedFileUtils.searchPath =
4156
[NSArray arrayWithObjects:
4257
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Images"],
4358
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Fonts"],
4459
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Resources-shared"],
4560
[[NSBundle mainBundle] resourcePath],
4661
nil];
47-
62+
4863
// Register spritesheets.
4964
[[CCSpriteFrameCache sharedSpriteFrameCache] registerSpriteFramesFile:@"Interface.plist"];
5065
[[CCSpriteFrameCache sharedSpriteFrameCache] registerSpriteFramesFile:@"Sprites.plist"];
5166
[[CCSpriteFrameCache sharedSpriteFrameCache] registerSpriteFramesFile:@"TilesAtlassed.plist"];
52-
53-
[self setupCocos2dWithOptions:@{
54-
CCSetupDepthFormat: @GL_DEPTH24_STENCIL8,
55-
// CCSetupScreenMode: CCScreenModeFixed,
56-
// CCSetupScreenOrientation: CCScreenOrientationPortrait,
57-
CCSetupTabletScale2X: @YES,
58-
// CCSetupShowDebugStats: @YES,
59-
}];
60-
61-
return YES;
6267
}
6368

6469
- (CCScene*) startScene
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
//
2+
// CCPackageTest.m
3+
// cocos2d-tests-ios
4+
//
5+
// Created by Nicky Weber on 19.09.14.
6+
// Copyright (c) 2014 Cocos2d. All rights reserved.
7+
//
8+
#import "CCPlatformTextField.h"
9+
#import "TestBase.h"
10+
#import "CCPackageManager.h"
11+
#import "CCPackageManagerDelegate.h"
12+
#import "CCPackage.h"
13+
#import "CCPackageConstants.h"
14+
#import "AppDelegate.h"
15+
16+
@interface CCPackageTest : TestBase <CCPackageManagerDelegate>
17+
18+
@property (nonatomic, strong) CCPackage *package;
19+
20+
@end
21+
22+
23+
@implementation CCPackageTest
24+
25+
- (void) setupPackageTest
26+
{
27+
[self.contentNode removeAllChildren];
28+
29+
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PACKAGE_STORAGE_USERDEFAULTS_KEY];
30+
[[NSUserDefaults standardUserDefaults] synchronize];
31+
32+
[self removeAllPackages];
33+
34+
[self resetCocos2d];
35+
36+
[self cleanDirectories];
37+
38+
[CCPackageManager sharedManager].delegate = self;
39+
40+
[self addLabels];
41+
42+
self.package = [[CCPackageManager sharedManager] downloadPackageWithName:@"testpackage"
43+
resolution:@"phonehd"
44+
remoteURL:[NSURL URLWithString:@"https://github.com/NickyWeber/cocos2d_test_resources/raw/master/testpackage-iOS-phonehd.zip?raw=true"]
45+
enableAfterDownload:YES];
46+
}
47+
48+
- (void)addLabels
49+
{
50+
CGSize winSize = [CCDirector sharedDirector].viewSize;
51+
52+
CCLabelTTF *labelSmiley1 = [CCLabelTTF labelWithString:@"Jolly Smiley? ->" fontName:@"HelveticaNeue-Light" fontSize:10 * [CCDirector sharedDirector].UIScaleFactor];
53+
CCLabelTTF *labelSmiley2 = [CCLabelTTF labelWithString:@"<- Angry Smiley?" fontName:@"HelveticaNeue-Light" fontSize:10 * [CCDirector sharedDirector].UIScaleFactor];
54+
55+
labelSmiley1.position = ccp((CGFloat) (winSize.width / 2.0 - 75.0), (CGFloat) (winSize.height / 2.0));
56+
labelSmiley2.position = ccp((CGFloat) (winSize.width / 2.0 + 75.0), (CGFloat) (winSize.height / 2.0));
57+
58+
[self.contentNode addChild:labelSmiley1];
59+
[self.contentNode addChild:labelSmiley2];
60+
}
61+
62+
- (void)removeAllPackages
63+
{
64+
for (CCPackage *aPackage in [[CCPackageManager sharedManager].allPackages mutableCopy])
65+
{
66+
[[CCPackageManager sharedManager] deletePackage:aPackage error:nil];
67+
}
68+
}
69+
70+
- (void)resetCocos2d
71+
{
72+
[(AppController *) [UIApplication sharedApplication].delegate configureFileUtilsSearchPathAndRegisterSpriteSheets];
73+
}
74+
75+
- (void)cleanDirectories
76+
{
77+
NSString *installFolder = [CCPackageManager sharedManager].installedPackagesPath;
78+
NSString *unzipFolder = [NSTemporaryDirectory() stringByAppendingPathComponent:PACKAGE_REL_UNZIP_FOLDER];
79+
NSString *downloadFolder = [NSTemporaryDirectory() stringByAppendingPathComponent:PACKAGE_REL_DOWNLOAD_FOLDER];
80+
81+
NSArray *foldersToClean = @[
82+
[NSURL fileURLWithPath:installFolder],
83+
[NSURL fileURLWithPath:unzipFolder],
84+
[NSURL fileURLWithPath:downloadFolder]];
85+
86+
87+
for (NSURL *folderURL in foldersToClean)
88+
{
89+
NSFileManager *fileManager = [NSFileManager defaultManager];
90+
NSDirectoryEnumerator *dirEnumerator = [fileManager enumeratorAtURL:folderURL
91+
includingPropertiesForKeys:@[NSURLNameKey]
92+
options:NSDirectoryEnumerationSkipsSubdirectoryDescendants
93+
errorHandler:^BOOL(NSURL *url, NSError *error) {
94+
return YES;
95+
}];
96+
97+
NSLog(@"%@", folderURL);
98+
for (NSURL *fileURL in dirEnumerator)
99+
{
100+
NSLog(@"\t%@", fileURL);
101+
102+
NSError *error;
103+
if (![fileManager removeItemAtURL:fileURL error:&error])
104+
{
105+
NSLog(@"Error removing file: %@", error);
106+
}
107+
}
108+
}
109+
}
110+
111+
112+
#pragma mark - CCPackageManagerDelegate
113+
114+
- (void)packageInstallationFinished:(CCPackage *)package
115+
{
116+
self.subTitle = [NSString stringWithFormat:@"Package installed"];
117+
118+
CGSize winSize = [CCDirector sharedDirector].viewSize;
119+
120+
CCSprite *smiley1 = [CCSprite spriteWithImageNamed:@"jollySmiley.png"];
121+
[self.contentNode addChild:smiley1];
122+
smiley1.position = ccp((CGFloat) (winSize.width / 2.0 - 20.0), (CGFloat) (winSize.height / 2.0));
123+
124+
CCSprite *smiley2 = [CCSprite spriteWithImageNamed:@"smileys/angrySmiley.png"];
125+
[self.contentNode addChild:smiley2];
126+
smiley2.position = ccp((CGFloat) (winSize.width / 2.0 + 20.0) , (CGFloat) (winSize.height / 2.0));
127+
128+
129+
/*
130+
NSError *error;
131+
if (![[CCPackageManager sharedManager] deletePackage:package error:&error])
132+
{
133+
NSLog(@"Error removing package: %@", error);
134+
}
135+
*/
136+
}
137+
138+
- (void)packageInstallationFailed:(CCPackage *)package error:(NSError *)error
139+
{
140+
self.subTitle = [NSString stringWithFormat:@"Test failed: installation failed."];
141+
}
142+
143+
- (void)packageDownloadFinished:(CCPackage *)package
144+
{
145+
self.subTitle = [NSString stringWithFormat:@"Download finished"];
146+
}
147+
148+
- (void)packageDownloadFailed:(CCPackage *)package error:(NSError *)error
149+
{
150+
self.subTitle = [NSString stringWithFormat:@"Test failed: download failed."];
151+
}
152+
153+
- (void)packageUnzippingFinished:(CCPackage *)package
154+
{
155+
self.subTitle = [NSString stringWithFormat:@"Unzip finished"];
156+
}
157+
158+
- (void)packageUnzippingFailed:(CCPackage *)package error:(NSError *)error
159+
{
160+
self.subTitle = [NSString stringWithFormat:@"Test failed: unzipping failed."];
161+
}
162+
163+
- (void)packageDownloadProgress:(CCPackage *)package downloadedBytes:(NSUInteger)downloadedBytes totalBytes:(NSUInteger)totalBytes
164+
{
165+
NSLog(@"downloading... %u / %u", downloadedBytes, totalBytes);
166+
}
167+
168+
- (void)packageUnzippingProgress:(CCPackage *)package unzippedBytes:(NSUInteger)unzippedBytes totalBytes:(NSUInteger)totalBytes
169+
{
170+
NSLog(@"unzipping... %u / %u", unzippedBytes, totalBytes);
171+
}
172+
173+
174+
@end

0 commit comments

Comments
 (0)