-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMemoryManagementTests.swift
63 lines (56 loc) · 2.03 KB
/
MemoryManagementTests.swift
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
import XCTest
import test_component
class MemoryManagementTests : XCTestCase {
public func testAggregatedObject() throws {
weak var weakDerived: AppDerived? = nil
try {
let appDerived = AppDerived()
// invoke a method so that _inner object is QI'ed
try appDerived.doTheThing()
weakDerived = appDerived
}()
XCTAssertNil(weakDerived)
}
public func testReturningAggregatedObject() throws {
weak var weakDerived: AppDerived? = nil
try {
let classy = Class()
let appDerived = AppDerived()
weakDerived = appDerived
classy.baseProperty = appDerived
let base_returned = try XCTUnwrap(classy.baseProperty)
XCTAssertNotNil(base_returned)
}()
XCTAssertNil(weakDerived)
}
public func testNonAggregatedObject() throws {
weak var weakDerived: Derived? = nil
try {
let derived = Derived()
// invoke a method so that _inner object is QI'ed
try derived.doTheThing()
weakDerived = derived
}()
XCTAssertNil(weakDerived)
}
public func testReturningNonAggregatedObject() throws {
weak var weakDerived: Derived? = nil
try {
let classy = Class()
let derived = Derived()
weakDerived = derived
classy.baseProperty = derived
let base_returned = try XCTUnwrap(classy.baseProperty)
XCTAssertNotNil(base_returned)
}()
XCTAssertNil(weakDerived)
}
}
var memoryManagementTests: [XCTestCaseEntry] = [
testCase([
("testAggregatedObject", MemoryManagementTests.testAggregatedObject),
("testNonAggregatedObject", MemoryManagementTests.testNonAggregatedObject),
("testReturningAggregatedObject", MemoryManagementTests.testReturningAggregatedObject),
("testReturningNonAggregatedObject", MemoryManagementTests.testReturningNonAggregatedObject),
])
]