forked from ObjectProfile/PythonBridge
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPBWeakFinalizerTest.class.st
More file actions
104 lines (92 loc) · 2.21 KB
/
PBWeakFinalizerTest.class.st
File metadata and controls
104 lines (92 loc) · 2.21 KB
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
Class {
#name : #PBWeakFinalizerTest,
#superclass : #TestCase,
#instVars : [
'weakRegistry',
'assertCounter'
],
#category : #'PythonBridge-Platform'
}
{ #category : #testing }
PBWeakFinalizerTest class >> isAbstract [
^ self == PBWeakFinalizerTest
]
{ #category : #running }
PBWeakFinalizerTest >> assertCount: anInteger [
self assert: assertCounter equals: anInteger
]
{ #category : #running }
PBWeakFinalizerTest >> countFinalizer [
^ LanguageLinkBlockFinalizer block: [ assertCounter := assertCounter + 1 ]
]
{ #category : #running }
PBWeakFinalizerTest >> setUp [
super setUp.
weakRegistry := self weakRegistryClass new.
assertCounter := 0
]
{ #category : #running }
PBWeakFinalizerTest >> tearDown [
weakRegistry destroy.
super tearDown
]
{ #category : #running }
PBWeakFinalizerTest >> testBlockFinalizer [
self assertCount: 0.
self countFinalizer finalize.
self assertCount: 1
]
{ #category : #running }
PBWeakFinalizerTest >> testDestroy [
| obj |
obj := Object new.
weakRegistry registerObject: obj finalizer: self countFinalizer.
weakRegistry destroy.
obj := nil.
self triggerGC.
self assertCount: 0
]
{ #category : #running }
PBWeakFinalizerTest >> testGcMultObjects [
| obj1 obj2 obj3 |
obj1 := Object new.
obj2 := Object new.
obj3 := Object new.
weakRegistry registerObject: obj1 finalizer: self countFinalizer.
weakRegistry registerObject: obj2 finalizer: self countFinalizer.
obj1 := nil.
self triggerGC.
self assertCount: 1.
weakRegistry registerObject: obj3 finalizer: self countFinalizer.
self triggerGC.
self assertCount: 1.
obj2 := nil.
obj3 := nil.
self triggerGC.
self assertCount: 3
]
{ #category : #running }
PBWeakFinalizerTest >> testGcObject [
| obj |
obj := Object new.
weakRegistry registerObject: obj finalizer: self countFinalizer.
obj := nil.
self triggerGC.
self assertCount: 1
]
{ #category : #running }
PBWeakFinalizerTest >> testNotGcObject [
| obj |
obj := Object new.
weakRegistry registerObject: obj finalizer: self countFinalizer.
self triggerGC.
self assertCount: 0
]
{ #category : #running }
PBWeakFinalizerTest >> triggerGC [
self subclassResponsibility
]
{ #category : #running }
PBWeakFinalizerTest >> weakRegistryClass [
self subclassResponsibility
]