forked from mkrautz/objc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall_test.go
215 lines (183 loc) · 5.7 KB
/
call_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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// Copyright (c) 2012 The 'objc' Package Authors. 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 (
"sync"
"testing"
)
type SomeObject struct {
Object `objc:"SomeObject : NSObject"`
t *testing.T
}
const (
float64val float64 = 42.0
float32val float32 = 54.0
uint64val uint64 = 0x432fea3effca34e3
uint32val uint32 = 0x3214324e
uint16val uint16 = 0x465f
uint8val uint8 = 0xe3
int64val int64 = -4214321421423
int32val int32 = -43414324
int16val int16 = -600
int8val int8 = -120
boolval bool = true
)
var once sync.Once
func registerTestClass() {
once.Do(func() {
c := NewClass(SomeObject{})
c.AddMethod("setTesting:", (*SomeObject).SetTesting)
c.AddMethod("callWithObject:selector:", (*SomeObject).CallWithObjectAndSelector)
c.AddMethod("callWithFloat64:", (*SomeObject).CallWithFloat64)
c.AddMethod("callWithFloat32:", (*SomeObject).CallWithFloat32)
c.AddMethod("callWithUint64:", (*SomeObject).CallWithUint64)
c.AddMethod("callWithUint32:", (*SomeObject).CallWithUint32)
c.AddMethod("callWithUint16:", (*SomeObject).CallWithUint16)
c.AddMethod("callWithUint8:", (*SomeObject).CallWithUint8)
c.AddMethod("callWithInt64:", (*SomeObject).CallWithInt64)
c.AddMethod("callWithInt32:", (*SomeObject).CallWithInt32)
c.AddMethod("callWithInt16:", (*SomeObject).CallWithInt16)
c.AddMethod("callWithInt8:", (*SomeObject).CallWithInt8)
c.AddMethod("callWithBool:", (*SomeObject).CallWithBool)
RegisterClass(c)
})
}
func (so *SomeObject) SetTesting(t *testing.T) {
so.t = t
}
func (so *SomeObject) CallWithObjectAndSelector(object Object, selector Selector) {
if selector.Selector() != "callWithObject:selector:" {
so.t.Errorf("unexpected selector")
}
if so.Pointer() != object.Pointer() {
so.t.Errorf("unexpected object")
}
}
func (so *SomeObject) CallWithFloat64(val float64) {
if val != float64val {
so.t.Errorf("float64: expected %v, got %v", float64val, val)
}
}
func (so *SomeObject) CallWithFloat32(val float32) {
if val != float32val {
so.t.Errorf("float32: expected %v, got %v", float32val, val)
}
}
func (so *SomeObject) CallWithUint64(val uint64) {
if val != uint64val {
so.t.Errorf("uint64: expected %v, got %v", uint64val, val)
}
}
func (so *SomeObject) CallWithUint32(val uint32) {
if val != uint32val {
so.t.Errorf("uint32: expected %v, got %v", uint32val, val)
}
}
func (so *SomeObject) CallWithUint16(val uint16) {
if val != uint16val {
so.t.Errorf("uint16: expected %v, got %v", uint16val, val)
}
}
func (so *SomeObject) CallWithUint8(val uint8) {
if val != uint8val {
so.t.Errorf("uint8: expected %v, got %v", uint8val, val)
}
}
func (so *SomeObject) CallWithInt64(val int64) {
if val != int64val {
so.t.Errorf("int64: expected %v, got %v", int64val, val)
}
}
func (so *SomeObject) CallWithInt32(val int32) {
if val != int32val {
so.t.Errorf("int32: expected %v, got %v", int32val, val)
}
}
func (so *SomeObject) CallWithInt16(val int16) {
if val != int16val {
so.t.Errorf("int8: expected %v, got %v", int16val, val)
}
}
func (so *SomeObject) CallWithInt8(val int8) {
if val != int8val {
so.t.Errorf("int8: expected %v, got %v", int8val, val)
}
}
func (so *SomeObject) CallWithBool(val bool) {
if val != boolval {
so.t.Errorf("bool: expected %v, got %v", boolval, val)
}
}
func TestSelectorObjectPassing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithObject:selector:", so, GetSelector("callWithObject:selector:"))
}
func TestFloat64Passing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithFloat64:", float64val)
}
func TestFloat32Passing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithFloat32:", float32val)
}
func TestUint64Passing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithUint64:", uint64val)
}
func TestUint32Passing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithUint32:", uint32val)
}
func TestUint16Passing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithUint16:", uint16val)
}
func TestUint8Passing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithUint8:", uint8val)
}
func TestInt64Passing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithInt64:", int64val)
}
func TestInt32Passing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithInt32:", int32val)
}
func TestInt16Passing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithInt16:", int16val)
}
func TestInt8Passing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithInt8:", int8val)
}
func TestBoolPassing(t *testing.T) {
registerTestClass()
so := GetClass("SomeObject").SendMsg("alloc").SendMsg("init")
so.SendMsg("setTesting:", t)
so.SendMsg("callWithBool:", boolval)
}