Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:cocos2d/cocos2d-iphone into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
slembcke committed Oct 1, 2014
2 parents 4bbcd4c + 7908afc commit c2cda65
Show file tree
Hide file tree
Showing 63 changed files with 5,364 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ url=https://github.com/slembcke/Chipmunk2D.git
path = external/ObjectAL
url = https://github.com/spritebuilder/ObjectAL-for-Cocos2D.git
branch = apportable
[submodule "external/SSZipArchive"]
path = external/SSZipArchive
url = https://github.com/spritebuilder/ssziparchive.git
293 changes: 293 additions & 0 deletions UnitTests/CCEffectTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
//
// CCEffectTests.m
// cocos2d-tests-ios
//
// Created by Thayer J Andrews on 9/26/14.
// Copyright (c) 2014 Cocos2d. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "cocos2d.h"
#import "CCEffectUtils.h"

@interface CCEffectTests : XCTestCase
@end

@implementation CCEffectTests

-(void)testNodeAncestry
{
CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];
CCSprite *s2 = [CCSprite spriteWithImageNamed:@"f1.png"];

BOOL commonAncestor = NO;

CCEffectUtilsTransformFromNodeToNode(s1, s2, &commonAncestor);
XCTAssertFalse(commonAncestor, @"Common ancestor found where there is none.");

CCEffectUtilsTransformFromNodeToNode(s2, s1, &commonAncestor);
XCTAssertFalse(commonAncestor, @"Common ancestor found where there is none.");
}

-(void)testSameNode
{
CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];

BOOL commonAncestor = NO;
GLKMatrix4 transform;

transform = CCEffectUtilsTransformFromNodeToNode(s1, s1, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");

XCTAssertEqual(transform.m00, 1.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m01, 0.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m02, 0.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m03, 0.0f, @"Unexpected transform value.");

XCTAssertEqual(transform.m10, 0.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m11, 1.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m12, 0.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m13, 0.0f, @"Unexpected transform value.");

XCTAssertEqual(transform.m20, 0.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m21, 0.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m22, 1.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m23, 0.0f, @"Unexpected transform value.");

XCTAssertEqual(transform.m30, 0.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m31, 0.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m32, 0.0f, @"Unexpected transform value.");
XCTAssertEqual(transform.m33, 1.0f, @"Unexpected transform value.");
}

-(void)testSiblingTransforms
{
CCSprite *root = [CCSprite spriteWithImageNamed:@"f1.png"];
root.name = @"root";
root.positionType = CCPositionTypePoints;
root.position = ccp(0.0f, 0.0f);
root.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];
s1.name = @"s1";
s1.positionType = CCPositionTypePoints;
s1.position = ccp(10.0f, 10.0f);
s1.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s2 = [CCSprite spriteWithImageNamed:@"f1.png"];
s2.name = @"s2";
s2.positionType = CCPositionTypePoints;
s2.position = ccp(100.0f, 100.0f);
s2.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s3 = [CCSprite spriteWithImageNamed:@"f1.png"];
s3.name = @"s3";
s3.positionType = CCPositionTypePoints;
s3.position = ccp(1000.0f, 1000.0f);
s3.anchorPoint = ccp(0.0f, 0.0f);

BOOL commonAncestor = NO;
GLKMatrix4 transform;



// Test this hierarchy:
//
// root
// \
// s1
// / \
// s2 s3
//
[root addChild:s1];
[s1 addChild:s2];
[s1 addChild:s3];
transform = CCEffectUtilsTransformFromNodeToNode(s1, s2, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -100.0f, @"");
XCTAssertEqual(transform.m31, -100.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s2, s1, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 100.0f, @"");
XCTAssertEqual(transform.m31, 100.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s2, s3, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -900.0f, @"");
XCTAssertEqual(transform.m31, -900.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s3, s2, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 900.0f, @"");
XCTAssertEqual(transform.m31, 900.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s1, s3, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -1000.0f, @"");
XCTAssertEqual(transform.m31, -1000.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s3, s1, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 1000.0f, @"");
XCTAssertEqual(transform.m31, 1000.0f, @"");


// Test this hierarchy:
//
// s1
// / \
// s2 s3
//
[root removeChild:s1];
transform = CCEffectUtilsTransformFromNodeToNode(s1, s2, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -100.0f, @"");
XCTAssertEqual(transform.m31, -100.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s2, s1, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 100.0f, @"");
XCTAssertEqual(transform.m31, 100.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s2, s3, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -900.0f, @"");
XCTAssertEqual(transform.m31, -900.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s3, s2, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 900.0f, @"");
XCTAssertEqual(transform.m31, 900.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s1, s3, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -1000.0f, @"");
XCTAssertEqual(transform.m31, -1000.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s3, s1, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 1000.0f, @"");
XCTAssertEqual(transform.m31, 1000.0f, @"");

[s1 removeChild:s2];
[s1 removeChild:s3];
}

- (void)testAncestorTransforms
{
CCSprite *root = [CCSprite spriteWithImageNamed:@"f1.png"];
root.name = @"root";
root.positionType = CCPositionTypePoints;
root.position = ccp(0.0f, 0.0f);
root.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];
s1.name = @"s1";
s1.positionType = CCPositionTypePoints;
s1.position = ccp(10.0f, 10.0f);
s1.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s2 = [CCSprite spriteWithImageNamed:@"f1.png"];
s2.name = @"s2";
s2.positionType = CCPositionTypePoints;
s2.position = ccp(100.0f, 100.0f);
s2.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s3 = [CCSprite spriteWithImageNamed:@"f1.png"];
s3.name = @"s3";
s3.positionType = CCPositionTypePoints;
s3.position = ccp(1000.0f, 1000.0f);
s3.anchorPoint = ccp(0.0f, 0.0f);

BOOL commonAncestor = NO;
GLKMatrix4 transform;


// Test this hierarchy:
//
// root
// \
// s1
// \
// s2
// \
// s3
//
[root addChild:s1];
[s1 addChild:s2];
[s2 addChild:s3];
transform = CCEffectUtilsTransformFromNodeToNode(s1, s2, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -100.0f, @"");
XCTAssertEqual(transform.m31, -100.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s2, s1, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 100.0f, @"");
XCTAssertEqual(transform.m31, 100.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s2, s3, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -1000.0f, @"");
XCTAssertEqual(transform.m31, -1000.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s3, s2, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 1000.0f, @"");
XCTAssertEqual(transform.m31, 1000.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s1, s3, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -1100.0f, @"");
XCTAssertEqual(transform.m31, -1100.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s3, s1, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 1100.0f, @"");
XCTAssertEqual(transform.m31, 1100.0f, @"");


// Test this hierarchy:
//
// s1
// \
// s2
// \
// s3
//
[root removeChild:s1];
transform = CCEffectUtilsTransformFromNodeToNode(s1, s2, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -100.0f, @"");
XCTAssertEqual(transform.m31, -100.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s2, s1, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 100.0f, @"");
XCTAssertEqual(transform.m31, 100.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s2, s3, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -1000.0f, @"");
XCTAssertEqual(transform.m31, -1000.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s3, s2, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 1000.0f, @"");
XCTAssertEqual(transform.m31, 1000.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s1, s3, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, -1100.0f, @"");
XCTAssertEqual(transform.m31, -1100.0f, @"");

transform = CCEffectUtilsTransformFromNodeToNode(s3, s1, &commonAncestor);
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
XCTAssertEqual(transform.m30, 1100.0f, @"");
XCTAssertEqual(transform.m31, 1100.0f, @"");
[s1 removeChild:s2];
[s2 removeChild:s3];
}

@end
90 changes: 90 additions & 0 deletions UnitTests/CCPackageCocos2dEnablerTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// CCPackageCocos2dEnablerTests.m
// cocos2d-tests-ios
//
// Created by Nicky Weber on 23.09.14.
// Copyright (c) 2014 Cocos2d. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "CCPackageCocos2dEnabler.h"
#import "CCPackage.h"
#import "CCFileUtils.h"
#import "CCSprite.h"
#import "CCBReader.h"
#import "AppDelegate.h"
#import "CCPackage_private.h"

@interface CCPackageCocos2dEnablerTests : XCTestCase

@property (nonatomic, strong) CCPackage *package;
@property (nonatomic, copy) NSURL *installURL;

@end


@implementation CCPackageCocos2dEnablerTests

- (void)setUp
{
[super setUp];
[(AppController *)[UIApplication sharedApplication].delegate configureCocos2d];

self.package = [[CCPackage alloc] initWithName:@"Foo"
resolution:@"phonehd"
os:@"iOS"
remoteURL:[NSURL URLWithString:@"http://foo.fake/Foo-iOS-phonehd.zip"]];

NSString *pathToPackage = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Resources-shared/Packages/testpackage-iOS-phonehd_unzipped"];
self.installURL = [[NSURL fileURLWithPath:pathToPackage] URLByAppendingPathComponent:@"testpackage-iOS-phonehd"];
_package.installURL = _installURL;
}


#pragma mark - Tests

- (void)testEnablePackage
{
CCPackageCocos2dEnabler *packageEnabler = [[CCPackageCocos2dEnabler alloc] init];
[packageEnabler enablePackages:@[_package]];

XCTAssertTrue([self isPackageInSearchPath]);
XCTAssertEqual(_package.status, CCPackageStatusInstalledEnabled);

CCSprite *sprite = [CCSprite spriteWithImageNamed:@"boredSmiley.png"];
XCTAssertNotNil(sprite);
}

- (void)testDisablePackage
{
[self testEnablePackage];

CCPackageCocos2dEnabler *packageEnabler = [[CCPackageCocos2dEnabler alloc] init];
[packageEnabler disablePackages:@[_package]];

XCTAssertEqual(_package.status, CCPackageStatusInstalledDisabled);

XCTAssertFalse([self isPackageInSearchPath]);

// Can't use [CCSprite spriteWithImageNamed:@"boredSmiley.png"], assertion exception is screwing up test result
CGFloat *scale;
NSString *path = [[CCFileUtils sharedFileUtils] fullPathForFilename:@"boredSmiley.png" contentScale:&scale];
XCTAssertNil(path);
}


#pragma mark - Helper

- (BOOL)isPackageInSearchPath
{
for (NSString *aSearchPath in [CCFileUtils sharedFileUtils].searchPath)
{
if ([aSearchPath isEqualToString:_package.installURL.path])
{
return YES;
}
}
return NO;
}

@end
Loading

0 comments on commit c2cda65

Please sign in to comment.