|
| 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 |
0 commit comments