|
| 1 | +// |
| 2 | +// CCSpriteFrameCacheTests.m |
| 3 | +// cocos2d-tests-ios |
| 4 | +// |
| 5 | +// Created by Nicky Weber on 02.10.14. |
| 6 | +// Copyright (c) 2014 Cocos2d. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import <XCTest/XCTest.h> |
| 10 | +#import "CCFileUtils.h" |
| 11 | +#import "CCSpriteFrameCache.h" |
| 12 | + |
| 13 | + |
| 14 | +@interface CCSpriteFrameCache() |
| 15 | + |
| 16 | +@end |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +@interface CCFileUtils() |
| 21 | ++(void) resetSingleton; |
| 22 | +@end |
| 23 | + |
| 24 | +@interface CCSpriteFrameCacheTests : XCTestCase |
| 25 | + |
| 26 | +@end |
| 27 | + |
| 28 | +@implementation CCSpriteFrameCacheTests |
| 29 | + |
| 30 | +- (void)setUp |
| 31 | +{ |
| 32 | + [super setUp]; |
| 33 | + |
| 34 | + [CCFileUtils resetSingleton]; |
| 35 | + |
| 36 | + CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils]; |
| 37 | + |
| 38 | + sharedFileUtils.directoriesDict = |
| 39 | + [@{CCFileUtilsSuffixiPad : @"resources-tablet", |
| 40 | + CCFileUtilsSuffixiPadHD : @"resources-tablethd", |
| 41 | + CCFileUtilsSuffixiPhone : @"resources-phone", |
| 42 | + CCFileUtilsSuffixiPhoneHD : @"resources-phonehd", |
| 43 | + CCFileUtilsSuffixiPhone5 : @"resources-phone", |
| 44 | + CCFileUtilsSuffixiPhone5HD : @"resources-phonehd", |
| 45 | + CCFileUtilsSuffixDefault : @""} mutableCopy]; |
| 46 | + |
| 47 | + sharedFileUtils.searchMode = CCFileUtilsSearchModeDirectory; |
| 48 | + [sharedFileUtils buildSearchResolutionsOrder]; |
| 49 | +} |
| 50 | + |
| 51 | +- (void)tearDown |
| 52 | +{ |
| 53 | + [CCFileUtils resetSingleton]; |
| 54 | + |
| 55 | + [super tearDown]; |
| 56 | +} |
| 57 | + |
| 58 | +- (void)testLoadSpriteFrameLookupsInAllSearchPathsWithName |
| 59 | +{ |
| 60 | + NSString *pathToUnzippedPackage = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Resources-shared/Packages/testpackage-iOS-phonehd_unzipped/testpackage-iOS-phonehd"]; |
| 61 | + NSString *pathToUnzippedPackage2 = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Resources-shared/Packages/testpackage-iOS-phonehd_unzipped/testpackage-iOS-phonehd"]; |
| 62 | + |
| 63 | + NSString *newSearchPathForPackage = [NSTemporaryDirectory() stringByAppendingPathComponent:@"testpackage-iOS-phonehd"]; |
| 64 | + NSString *newSearchPathForPackage2 = [NSTemporaryDirectory() stringByAppendingPathComponent:@"testpackage2-iOS-phonehd"]; |
| 65 | + |
| 66 | + NSFileManager *fileManager = [NSFileManager defaultManager]; |
| 67 | + [fileManager removeItemAtPath:newSearchPathForPackage error:nil]; |
| 68 | + [fileManager copyItemAtPath:pathToUnzippedPackage toPath:newSearchPathForPackage error:nil]; |
| 69 | + |
| 70 | + [fileManager removeItemAtPath:newSearchPathForPackage2 error:nil]; |
| 71 | + [fileManager copyItemAtPath:pathToUnzippedPackage2 toPath:newSearchPathForPackage2 error:nil]; |
| 72 | + |
| 73 | + [CCFileUtils sharedFileUtils].searchPath = @[newSearchPathForPackage,newSearchPathForPackage2]; |
| 74 | + |
| 75 | + [[CCSpriteFrameCache sharedSpriteFrameCache] loadSpriteFrameLookupsInAllSearchPathsWithName:@"spriteFrameFileList.plist"]; |
| 76 | + |
| 77 | + CCSpriteFrame *frame1 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"smileys/angrySmiley.png"]; |
| 78 | + CCSpriteFrame *frame2 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"moresmileys/confusedSmiley.png"]; |
| 79 | + |
| 80 | + XCTAssertNotNil(frame1, @"Error loading: smileys/angrySmiley.png"); |
| 81 | + XCTAssertNotNil(frame2, @"Error loading: smileys/moresmileys/confusedSmiley.png"); |
| 82 | +} |
| 83 | + |
| 84 | +@end |
0 commit comments