forked from progrium/darwinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_test.go
44 lines (40 loc) · 847 Bytes
/
base_test.go
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
// Copyright 2021 Liu Dong. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package objc
import (
"testing"
"unsafe"
)
func TestSetAssociatedObject(t *testing.T) {
o1 := NewObject()
o2 := NewObject()
var i = 0
key := unsafe.Pointer(&i)
SetAssociatedObject(o1, key, o2, ASSOCIATION_RETAIN)
if o2.RetainCount() != 2 {
t.Fail()
}
o1.Release()
if o2.RetainCount() != 1 {
t.Fail()
}
o2.Release()
o1 = NewObject()
o2 = NewObject()
o3 := NewObject()
SetAssociatedObject(o1, key, o2, ASSOCIATION_RETAIN)
if o2.RetainCount() != 2 {
t.Fail()
}
SetAssociatedObject(o1, key, o3, ASSOCIATION_RETAIN)
if o2.RetainCount() != 1 {
t.Fail()
}
o1.Release()
if o2.RetainCount() != 1 || o3.RetainCount() != 1 {
t.Fail()
}
o2.Release()
o3.Release()
}