|
7 | 7 | //
|
8 | 8 |
|
9 | 9 | #import <XCTest/XCTest.h>
|
| 10 | +#import "CCPackageCocos2dEnabler.h" |
| 11 | +#import "CCPackage.h" |
| 12 | +#import "CCFileUtils.h" |
| 13 | +#import "CCSprite.h" |
10 | 14 |
|
11 | 15 | @interface CCPackageCocos2dEnablerTests : XCTestCase
|
12 | 16 |
|
| 17 | +@property (nonatomic, strong) CCPackage *package; |
| 18 | +@property (nonatomic, copy) NSURL *installURL; |
| 19 | + |
13 | 20 | @end
|
14 | 21 |
|
| 22 | + |
15 | 23 | @implementation CCPackageCocos2dEnablerTests
|
16 | 24 |
|
17 | 25 | - (void)setUp
|
18 | 26 | {
|
19 | 27 | [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))]; |
21 | 37 | }
|
22 | 38 |
|
23 | 39 | - (void)tearDown
|
24 | 40 | {
|
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 | + |
26 | 44 | [super tearDown];
|
27 | 45 | }
|
28 | 46 |
|
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 |
30 | 77 | {
|
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; |
32 | 86 | }
|
33 | 87 |
|
34 | 88 | @end
|
0 commit comments