Skip to content

Commit 447ba2d

Browse files
committed
CCPackageCocos2dEnabler unit tests added.
1 parent cf29603 commit 447ba2d

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

UnitTests/CCPackageCocos2dEnablerTests.m

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,82 @@
77
//
88

99
#import <XCTest/XCTest.h>
10+
#import "CCPackageCocos2dEnabler.h"
11+
#import "CCPackage.h"
12+
#import "CCFileUtils.h"
13+
#import "CCSprite.h"
1014

1115
@interface CCPackageCocos2dEnablerTests : XCTestCase
1216

17+
@property (nonatomic, strong) CCPackage *package;
18+
@property (nonatomic, copy) NSURL *installURL;
19+
1320
@end
1421

22+
1523
@implementation CCPackageCocos2dEnablerTests
1624

1725
- (void)setUp
1826
{
1927
[super setUp];
20-
// Put setup code here. This method is called before the invocation of each test method in the class.
28+
29+
self.package = [[CCPackage alloc] initWithName:@"Foo"
30+
resolution:@"phonehd"
31+
os:@"iOS"
32+
remoteURL:[NSURL URLWithString:@"http://foo.fake/Foo-iOS-phonehd.zip"]];
33+
34+
NSString *pathToPackage = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Resources-shared/Packages/testpackage-iOS-phonehd_unzipped"];
35+
self.installURL = [[NSURL fileURLWithPath:pathToPackage] URLByAppendingPathComponent:@"testpackage-iOS-phonehd"];
36+
[_package setValue:_installURL forKey:NSStringFromSelector(@selector(installURL))];
2137
}
2238

2339
- (void)tearDown
2440
{
25-
// Put teardown code here. This method is called after the invocation of each test method in the class.
41+
CCPackageCocos2dEnabler *packageEnabler = [[CCPackageCocos2dEnabler alloc] init];
42+
[packageEnabler disablePackages:@[_package]];
43+
2644
[super tearDown];
2745
}
2846

29-
- (void)testExample
47+
- (void)testEnablePackage
48+
{
49+
CCPackageCocos2dEnabler *packageEnabler = [[CCPackageCocos2dEnabler alloc] init];
50+
[packageEnabler enablePackages:@[_package]];
51+
52+
XCTAssertTrue([self isPackageInSearchPath]);
53+
XCTAssertEqual(_package.status, CCPackageStatusInstalledEnabled);
54+
55+
CCSprite *sprite = [CCSprite spriteWithImageNamed:@"boredSmiley.png"];
56+
XCTAssertNotNil(sprite);
57+
}
58+
59+
- (void)testDisablePackage
60+
{
61+
[self testEnablePackage];
62+
63+
CCPackageCocos2dEnabler *packageEnabler = [[CCPackageCocos2dEnabler alloc] init];
64+
[packageEnabler disablePackages:@[_package]];
65+
66+
XCTAssertEqual(_package.status, CCPackageStatusInstalledDisabled);
67+
68+
XCTAssertFalse([self isPackageInSearchPath]);
69+
70+
// Can't use [CCSprite spriteWithImageNamed:@"boredSmiley.png"], assertion exception is screwing up test result
71+
CGFloat *scale;
72+
NSString *path = [[CCFileUtils sharedFileUtils] fullPathForFilename:@"boredSmiley.png" contentScale:&scale];
73+
XCTAssertNil(path);
74+
}
75+
76+
- (BOOL)isPackageInSearchPath
3077
{
31-
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
78+
for (NSString *aSearchPath in [CCFileUtils sharedFileUtils].searchPath)
79+
{
80+
if ([aSearchPath isEqualToString:_package.installURL.path])
81+
{
82+
return YES;
83+
}
84+
}
85+
return NO;
3286
}
3387

3488
@end

0 commit comments

Comments
 (0)