Skip to content

Commit 8ae1ade

Browse files
author
Thayer J Andrews
committed
CCEffects - First pass at some unit tests
So far these only test the node to node transforms that were just introduced to fix problems with CCRenderTexture.
1 parent 090bd54 commit 8ae1ade

File tree

2 files changed

+266
-0
lines changed

2 files changed

+266
-0
lines changed

UnitTests/CCEffectTests.m

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
//
2+
// CCEffectTests.m
3+
// cocos2d-tests-ios
4+
//
5+
// Created by Thayer J Andrews on 9/26/14.
6+
// Copyright (c) 2014 Cocos2d. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "cocos2d.h"
11+
#import "CCEffectUtils.h"
12+
13+
@interface CCEffectTests : XCTestCase
14+
@end
15+
16+
@implementation CCEffectTests
17+
18+
-(void)testNodeAncestry
19+
{
20+
CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];
21+
CCSprite *s2 = [CCSprite spriteWithImageNamed:@"f1.png"];
22+
23+
BOOL commonAncestor = NO;
24+
25+
CCEffectUtilsTransformFromNodeToNode(s1, s2, &commonAncestor);
26+
XCTAssertFalse(commonAncestor, @"Common ancestor found where there is none.");
27+
28+
CCEffectUtilsTransformFromNodeToNode(s2, s1, &commonAncestor);
29+
XCTAssertFalse(commonAncestor, @"Common ancestor found where there is none.");
30+
}
31+
32+
-(void)testSiblingTransforms
33+
{
34+
CCSprite *root = [CCSprite spriteWithImageNamed:@"f1.png"];
35+
root.name = @"root";
36+
root.positionType = CCPositionTypePoints;
37+
root.position = ccp(0.0f, 0.0f);
38+
root.anchorPoint = ccp(0.0f, 0.0f);
39+
40+
CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];
41+
s1.name = @"s1";
42+
s1.positionType = CCPositionTypePoints;
43+
s1.position = ccp(10.0f, 10.0f);
44+
s1.anchorPoint = ccp(0.0f, 0.0f);
45+
46+
CCSprite *s2 = [CCSprite spriteWithImageNamed:@"f1.png"];
47+
s2.name = @"s2";
48+
s2.positionType = CCPositionTypePoints;
49+
s2.position = ccp(100.0f, 100.0f);
50+
s2.anchorPoint = ccp(0.0f, 0.0f);
51+
52+
CCSprite *s3 = [CCSprite spriteWithImageNamed:@"f1.png"];
53+
s3.name = @"s3";
54+
s3.positionType = CCPositionTypePoints;
55+
s3.position = ccp(1000.0f, 1000.0f);
56+
s3.anchorPoint = ccp(0.0f, 0.0f);
57+
58+
BOOL commonAncestor = NO;
59+
GLKMatrix4 transform;
60+
61+
62+
63+
// Test this hierarchy:
64+
//
65+
// root
66+
// \
67+
// s1
68+
// / \
69+
// s2 s3
70+
//
71+
[root addChild:s1];
72+
[s1 addChild:s2];
73+
[s1 addChild:s3];
74+
transform = CCEffectUtilsTransformFromNodeToNode(s1, s2, &commonAncestor);
75+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
76+
XCTAssertEqual(transform.m30, -100.0f, @"");
77+
XCTAssertEqual(transform.m31, -100.0f, @"");
78+
79+
transform = CCEffectUtilsTransformFromNodeToNode(s2, s1, &commonAncestor);
80+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
81+
XCTAssertEqual(transform.m30, 100.0f, @"");
82+
XCTAssertEqual(transform.m31, 100.0f, @"");
83+
84+
transform = CCEffectUtilsTransformFromNodeToNode(s2, s3, &commonAncestor);
85+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
86+
XCTAssertEqual(transform.m30, -900.0f, @"");
87+
XCTAssertEqual(transform.m31, -900.0f, @"");
88+
89+
transform = CCEffectUtilsTransformFromNodeToNode(s3, s2, &commonAncestor);
90+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
91+
XCTAssertEqual(transform.m30, 900.0f, @"");
92+
XCTAssertEqual(transform.m31, 900.0f, @"");
93+
94+
transform = CCEffectUtilsTransformFromNodeToNode(s1, s3, &commonAncestor);
95+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
96+
XCTAssertEqual(transform.m30, -1000.0f, @"");
97+
XCTAssertEqual(transform.m31, -1000.0f, @"");
98+
99+
transform = CCEffectUtilsTransformFromNodeToNode(s3, s1, &commonAncestor);
100+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
101+
XCTAssertEqual(transform.m30, 1000.0f, @"");
102+
XCTAssertEqual(transform.m31, 1000.0f, @"");
103+
104+
105+
// Test this hierarchy:
106+
//
107+
// s1
108+
// / \
109+
// s2 s3
110+
//
111+
[root removeChild:s1];
112+
transform = CCEffectUtilsTransformFromNodeToNode(s1, s2, &commonAncestor);
113+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
114+
XCTAssertEqual(transform.m30, -100.0f, @"");
115+
XCTAssertEqual(transform.m31, -100.0f, @"");
116+
117+
transform = CCEffectUtilsTransformFromNodeToNode(s2, s1, &commonAncestor);
118+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
119+
XCTAssertEqual(transform.m30, 100.0f, @"");
120+
XCTAssertEqual(transform.m31, 100.0f, @"");
121+
122+
transform = CCEffectUtilsTransformFromNodeToNode(s2, s3, &commonAncestor);
123+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
124+
XCTAssertEqual(transform.m30, -900.0f, @"");
125+
XCTAssertEqual(transform.m31, -900.0f, @"");
126+
127+
transform = CCEffectUtilsTransformFromNodeToNode(s3, s2, &commonAncestor);
128+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
129+
XCTAssertEqual(transform.m30, 900.0f, @"");
130+
XCTAssertEqual(transform.m31, 900.0f, @"");
131+
132+
transform = CCEffectUtilsTransformFromNodeToNode(s1, s3, &commonAncestor);
133+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
134+
XCTAssertEqual(transform.m30, -1000.0f, @"");
135+
XCTAssertEqual(transform.m31, -1000.0f, @"");
136+
137+
transform = CCEffectUtilsTransformFromNodeToNode(s3, s1, &commonAncestor);
138+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
139+
XCTAssertEqual(transform.m30, 1000.0f, @"");
140+
XCTAssertEqual(transform.m31, 1000.0f, @"");
141+
142+
[s1 removeChild:s2];
143+
[s1 removeChild:s3];
144+
}
145+
146+
- (void)testAncestorTransforms
147+
{
148+
CCSprite *root = [CCSprite spriteWithImageNamed:@"f1.png"];
149+
root.name = @"root";
150+
root.positionType = CCPositionTypePoints;
151+
root.position = ccp(0.0f, 0.0f);
152+
root.anchorPoint = ccp(0.0f, 0.0f);
153+
154+
CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];
155+
s1.name = @"s1";
156+
s1.positionType = CCPositionTypePoints;
157+
s1.position = ccp(10.0f, 10.0f);
158+
s1.anchorPoint = ccp(0.0f, 0.0f);
159+
160+
CCSprite *s2 = [CCSprite spriteWithImageNamed:@"f1.png"];
161+
s2.name = @"s2";
162+
s2.positionType = CCPositionTypePoints;
163+
s2.position = ccp(100.0f, 100.0f);
164+
s2.anchorPoint = ccp(0.0f, 0.0f);
165+
166+
CCSprite *s3 = [CCSprite spriteWithImageNamed:@"f1.png"];
167+
s3.name = @"s3";
168+
s3.positionType = CCPositionTypePoints;
169+
s3.position = ccp(1000.0f, 1000.0f);
170+
s3.anchorPoint = ccp(0.0f, 0.0f);
171+
172+
BOOL commonAncestor = NO;
173+
GLKMatrix4 transform;
174+
175+
176+
// Test this hierarchy:
177+
//
178+
// root
179+
// \
180+
// s1
181+
// \
182+
// s2
183+
// \
184+
// s3
185+
//
186+
[root addChild:s1];
187+
[s1 addChild:s2];
188+
[s2 addChild:s3];
189+
transform = CCEffectUtilsTransformFromNodeToNode(s1, s2, &commonAncestor);
190+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
191+
XCTAssertEqual(transform.m30, -100.0f, @"");
192+
XCTAssertEqual(transform.m31, -100.0f, @"");
193+
194+
transform = CCEffectUtilsTransformFromNodeToNode(s2, s1, &commonAncestor);
195+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
196+
XCTAssertEqual(transform.m30, 100.0f, @"");
197+
XCTAssertEqual(transform.m31, 100.0f, @"");
198+
199+
transform = CCEffectUtilsTransformFromNodeToNode(s2, s3, &commonAncestor);
200+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
201+
XCTAssertEqual(transform.m30, -1000.0f, @"");
202+
XCTAssertEqual(transform.m31, -1000.0f, @"");
203+
204+
transform = CCEffectUtilsTransformFromNodeToNode(s3, s2, &commonAncestor);
205+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
206+
XCTAssertEqual(transform.m30, 1000.0f, @"");
207+
XCTAssertEqual(transform.m31, 1000.0f, @"");
208+
209+
transform = CCEffectUtilsTransformFromNodeToNode(s1, s3, &commonAncestor);
210+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
211+
XCTAssertEqual(transform.m30, -1100.0f, @"");
212+
XCTAssertEqual(transform.m31, -1100.0f, @"");
213+
214+
transform = CCEffectUtilsTransformFromNodeToNode(s3, s1, &commonAncestor);
215+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
216+
XCTAssertEqual(transform.m30, 1100.0f, @"");
217+
XCTAssertEqual(transform.m31, 1100.0f, @"");
218+
219+
220+
// Test this hierarchy:
221+
//
222+
// s1
223+
// \
224+
// s2
225+
// \
226+
// s3
227+
//
228+
[root removeChild:s1];
229+
transform = CCEffectUtilsTransformFromNodeToNode(s1, s2, &commonAncestor);
230+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
231+
XCTAssertEqual(transform.m30, -100.0f, @"");
232+
XCTAssertEqual(transform.m31, -100.0f, @"");
233+
234+
transform = CCEffectUtilsTransformFromNodeToNode(s2, s1, &commonAncestor);
235+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
236+
XCTAssertEqual(transform.m30, 100.0f, @"");
237+
XCTAssertEqual(transform.m31, 100.0f, @"");
238+
239+
transform = CCEffectUtilsTransformFromNodeToNode(s2, s3, &commonAncestor);
240+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
241+
XCTAssertEqual(transform.m30, -1000.0f, @"");
242+
XCTAssertEqual(transform.m31, -1000.0f, @"");
243+
244+
transform = CCEffectUtilsTransformFromNodeToNode(s3, s2, &commonAncestor);
245+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
246+
XCTAssertEqual(transform.m30, 1000.0f, @"");
247+
XCTAssertEqual(transform.m31, 1000.0f, @"");
248+
249+
transform = CCEffectUtilsTransformFromNodeToNode(s1, s3, &commonAncestor);
250+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
251+
XCTAssertEqual(transform.m30, -1100.0f, @"");
252+
XCTAssertEqual(transform.m31, -1100.0f, @"");
253+
254+
transform = CCEffectUtilsTransformFromNodeToNode(s3, s1, &commonAncestor);
255+
XCTAssertTrue(commonAncestor, @"No common ancestor found where there is one.");
256+
XCTAssertEqual(transform.m30, 1100.0f, @"");
257+
XCTAssertEqual(transform.m31, 1100.0f, @"");
258+
[s1 removeChild:s2];
259+
[s2 removeChild:s3];
260+
}
261+
262+
@end

cocos2d-tests-ios.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
92324E2A18EB635500D78D3F /* CCReaderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 92324E2918EB635500D78D3F /* CCReaderTest.m */; };
3030
9269312A1923D8A700CE6285 /* Resources-shared in Resources */ = {isa = PBXBuildFile; fileRef = B7C6237517EA695100928F91 /* Resources-shared */; };
3131
92FE241118F5F06F00647961 /* CCAnimationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 92FE241018F5F06F00647961 /* CCAnimationTest.m */; };
32+
9D96557319D6113500428E79 /* CCEffectTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D96557219D6113500428E79 /* CCEffectTests.m */; };
3233
A6167B93189A7D4D0044D391 /* VertexZTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A6167B92189A7D4D0044D391 /* VertexZTest.m */; };
3334
A664A4EF18A3D9B8006184B8 /* PositioningTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A664A4EE18A3D9B8006184B8 /* PositioningTest.m */; };
3435
B70AFC30180F2D7400516435 /* CCTransitionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B70AFC2F180F2D7400516435 /* CCTransitionTest.m */; };
@@ -225,6 +226,7 @@
225226
75F76496185A831B00E2FAFE /* Sounds */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Sounds; path = Resources/Sounds; sourceTree = SOURCE_ROOT; };
226227
92324E2918EB635500D78D3F /* CCReaderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCReaderTest.m; sourceTree = "<group>"; };
227228
92FE241018F5F06F00647961 /* CCAnimationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCAnimationTest.m; sourceTree = "<group>"; };
229+
9D96557219D6113500428E79 /* CCEffectTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCEffectTests.m; sourceTree = "<group>"; };
228230
A6167B92189A7D4D0044D391 /* VertexZTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VertexZTest.m; path = "cocos2d-ui-tests/tests/VertexZTest.m"; sourceTree = SOURCE_ROOT; };
229231
A664A4EE18A3D9B8006184B8 /* PositioningTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PositioningTest.m; path = "cocos2d-ui-tests/tests/PositioningTest.m"; sourceTree = SOURCE_ROOT; };
230232
B70AFC2F180F2D7400516435 /* CCTransitionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCTransitionTest.m; path = "cocos2d-ui-tests/tests/CCTransitionTest.m"; sourceTree = SOURCE_ROOT; };
@@ -398,6 +400,7 @@
398400
isa = PBXGroup;
399401
children = (
400402
92FE241018F5F06F00647961 /* CCAnimationTest.m */,
403+
9D96557219D6113500428E79 /* CCEffectTests.m */,
401404
755569E31856361100ED1B0F /* CCFileUtilTests.m */,
402405
755569E41856361100ED1B0F /* CCNodeTests.m */,
403406
755569E51856361100ED1B0F /* CCPhysicsTests.m */,
@@ -934,6 +937,7 @@
934937
files = (
935938
92324E2A18EB635500D78D3F /* CCReaderTest.m in Sources */,
936939
D32FDE8619B645CA0078CC16 /* CCTextureTests.m in Sources */,
940+
9D96557319D6113500428E79 /* CCEffectTests.m in Sources */,
937941
75556A161856370A00ED1B0F /* CCFileUtilTests.m in Sources */,
938942
92FE241118F5F06F00647961 /* CCAnimationTest.m in Sources */,
939943
75556A171856370A00ED1B0F /* CCNodeTests.m in Sources */,

0 commit comments

Comments
 (0)