This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
TFBasicTypeMarshallingInCallbacksTest.class.st
172 lines (123 loc) · 4.35 KB
/
TFBasicTypeMarshallingInCallbacksTest.class.st
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Class {
#name : #TFBasicTypeMarshallingInCallbacksTest,
#superclass : #TFTestCase,
#category : #'ThreadedFFI-Tests'
}
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> assertCharType: aType named: name [
| callbackGotValue |
callbackGotValue := self call: name type: aType value: $A asInteger.
self assert: callbackGotValue equals: $A.
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> assertIntType: aType named: name value: aValue [
| callbackGotValue |
callbackGotValue := self call: name type: aType value: aValue.
self assert: callbackGotValue equals: aValue.
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> assertSignedIntType: aType named: name [
self assertIntType: aType named: name value: -65
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> assertUnsignedIntType: aType named: name [
self assertIntType: aType named: name value: 65
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> call: typeName type: type value: aValue [
| callback fun received |
callback := TFCallback
forCallback: [ :a | received := a. ]
parameters: { type }
returnType: TFBasicType void
runner: runner.
fun := TFExternalFunction
name: 'simple_callback_f_', typeName
moduleName: self libraryPath
definition: (TFFunctionDefinition
parameterTypes: { TFBasicType pointer. type }
returnType: TFBasicType void).
runner invokeFunction: fun withArguments: { callback getHandle . aValue}.
^ received
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testChar [
self assertCharType: TFBasicType schar named: 'char'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testDouble [
| received |
received := self call: 'double' type: TFBasicType double value: 2.7.
self assert: received equals: 2.7
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testFloat [
| received |
received := self call: 'float' type: TFBasicType float value: 2.7.
self assert: (received between: 2.6999 and: 2.7001)
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testPointer [
| bytes received |
[
bytes := ExternalAddress allocate: 2 "bytes".
received := self call: 'pointer' type: TFBasicType pointer value: bytes.
self assert: received getHandle equals: bytes getHandle
] ensure: [ bytes free ]
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testSignedInt [
self assertSignedIntType: TFBasicType sint named: 'int'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testSignedInt16 [
self assertSignedIntType: TFBasicType sint16 named: 'int16_t'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testSignedInt32 [
self assertSignedIntType: TFBasicType sint32 named: 'int32_t'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testSignedInt64 [
self assertSignedIntType: TFBasicType sint64 named: 'int64_t'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testSignedInt8 [
self assertSignedIntType: TFBasicType sint8 named: 'int8_t'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testSignedLong [
self assertSignedIntType: TFBasicType slong named: 'long'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testSignedShort [
self assertSignedIntType: TFBasicType sshort named: 'short'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testUnsignedInt [
self assertUnsignedIntType: TFBasicType uint named: 'uint'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testUnsignedInt16 [
self assertUnsignedIntType: TFBasicType uint16 named: 'uint16_t'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testUnsignedInt32 [
self assertUnsignedIntType: TFBasicType uint32 named: 'uint32_t'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testUnsignedInt64 [
self assertUnsignedIntType: TFBasicType uint64 named: 'uint64_t'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testUnsignedInt8 [
self assertUnsignedIntType: TFBasicType uint8 named: 'uint8_t'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testUnsignedLong [
self assertUnsignedIntType: TFBasicType ulong named: 'ulong'
]
{ #category : #tests }
TFBasicTypeMarshallingInCallbacksTest >> testUnsignedShort [
self assertUnsignedIntType: TFBasicType ushort named: 'ushort'
]