Skip to content

Commit 4a28df3

Browse files
committed
Track retains/releases that occur during custom aggregation testing.
1 parent b1d3a40 commit 4a28df3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Tests/SQLiteTests/CustomAggregationTests.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,34 @@ class CustomAggregationTests : SQLiteTestCase {
122122
let _ = db.createAggregation("myReduceSUMX", initialValue: initial, reduce: reduce, result: { $0.value })
123123
// end this scope to ensure that the initial value is retained
124124
// by the createAggregation call.
125+
}();
126+
{
127+
XCTAssertEqual(TestObject.inits, 1)
128+
let result = try! db.prepare("SELECT myReduceSUMX(age) AS s FROM users")
129+
let i = result.columnNames.index(of: "s")!
130+
for row in result {
131+
let value = row[i] as? Int64
132+
XCTAssertEqual(1083, value)
133+
}
125134
}()
126-
let result = try! db.prepare("SELECT myReduceSUMX(age) AS s FROM users")
127-
let i = result.columnNames.index(of: "s")!
128-
for row in result {
129-
let value = row[i] as? Int64
130-
XCTAssertEqual(1083, value)
131-
}
135+
XCTAssertEqual(TestObject.inits, 4)
136+
XCTAssertEqual(TestObject.deinits, 3) // the initial value is still retained by the aggregate's state block, so deinits is one less than inits
132137
}
133138
}
134139

135140
/// This class is used to test that aggregation state variables
136141
/// can be reference types and are properly memory managed when
137142
/// crossing the Swift<->C boundary multiple times.
138143
class TestObject {
144+
static var inits = 0
145+
static var deinits = 0
146+
139147
var value: Int64
140148
init(value: Int64) {
141149
self.value = value
150+
TestObject.inits += 1
142151
}
143152
deinit {
153+
TestObject.deinits += 1
144154
}
145155
}

0 commit comments

Comments
 (0)