-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathCCMemoryTests.m
113 lines (89 loc) · 2.32 KB
/
CCMemoryTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// CCMemoryTests.m
// cocos2d-tests-ios
//
// Created by Scott Lembcke on 1/9/14.
// Copyright (c) 2014 Cocos2d. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "cocos2d.h"
@interface CCMemoryNode : CCNode
@end
@implementation CCMemoryNode
-(id)retain
{
//Help with debug.
//NSLog(@"CCMemoryNode : Retain %@",[NSThread callStackSymbols]);
return [super retain];
}
-(oneway void)release
{
//Help with debug.
//NSLog(@"CCMemoryNode : release %@",[NSThread callStackSymbols]);
[super release];
}
-(id)autorelease
{
//Help with debug.
//NSLog(@"CCMemoryNode : retain | autorelease %@",[NSThread callStackSymbols]);
return [super autorelease];
}
@end
@interface CCMemoryTests : XCTestCase
@end
@implementation CCMemoryTests
- (void)testPhysicsBodyRetainCycle1
{
CCNode *node = [[CCNode alloc] init];
XCTAssert(node.retainCount == 1, @"");
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
XCTAssert(node.retainCount == 1, @"");
node.physicsBody = nil;
XCTAssert(node.retainCount == 1, @"");
[node release];
}
- (void)testPhysicsBodyRetainCycle2
{
CCNode *node;
CCPhysicsNode *physics;
@autoreleasepool {
node = [[CCMemoryNode alloc] init];
XCTAssert(node.retainCount == 1, @"");
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
XCTAssert(node.retainCount == 1, @"");
physics = [CCPhysicsNode node];
[physics onEnter];
[physics addChild:node];
XCTAssert(node.retainCount > 1, @"");
[physics removeChild:node];
}
XCTAssert(node.retainCount == 1, @"");
XCTAssert(physics.retainCount == 1, @"");
[physics release];
[node release];
}
// There are terrible problems with the following test.
// I think it's due to singletons not getting cleaned up properly. -_-
//- (void)testPhysicsBodyRetainCycle3
//{
// CCNode *node = [[CCNode alloc] init];
// XCTAssert(node.retainCount == 1, @"");
//
// node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
// XCTAssert(node.retainCount == 1, @"");
//
// @autoreleasepool {
// CCPhysicsNode *physics = [CCPhysicsNode node];
// [physics onEnter];
//
// [physics addChild:node];
// XCTAssert(node.retainCount > 1, @"");
//
// [physics onExit];
// [physics cleanup];
// }
// XCTAssert(node.retainCount == 1, @"");
//
// [node release];
//}
@end