ffi 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ffi might be problematic. Click here for more details.
- data/Rakefile +13 -13
- data/ext/ffi_c/AbstractMemory.c +1 -1
- data/ext/ffi_c/compat.h +2 -2
- data/ext/ffi_c/extconf.rb +3 -3
- data/lib/ffi/library.rb +10 -8
- data/lib/ffi/platform.rb +0 -2
- data/lib/ffi/struct.rb +1 -5
- data/lib/ffi/tools/const_generator.rb +10 -13
- data/spec/ffi/async_callback_spec.rb +2 -2
- data/spec/ffi/bool_spec.rb +6 -6
- data/spec/ffi/buffer_spec.rb +23 -23
- data/spec/ffi/callback_spec.rb +101 -102
- data/spec/ffi/custom_type_spec.rb +20 -24
- data/spec/ffi/dup_spec.rb +7 -7
- data/spec/ffi/enum_spec.rb +127 -127
- data/spec/ffi/errno_spec.rb +2 -2
- data/spec/ffi/ffi_spec.rb +3 -3
- data/spec/ffi/function_spec.rb +10 -10
- data/spec/ffi/library_spec.rb +30 -12
- data/spec/ffi/managed_struct_spec.rb +4 -4
- data/spec/ffi/number_spec.rb +40 -40
- data/spec/ffi/pointer_spec.rb +21 -24
- data/spec/ffi/rbx/memory_pointer_spec.rb +17 -17
- data/spec/ffi/rbx/struct_spec.rb +2 -2
- data/spec/ffi/spec_helper.rb +1 -1
- data/spec/ffi/string_spec.rb +9 -9
- data/spec/ffi/strptr_spec.rb +3 -3
- data/spec/ffi/struct_callback_spec.rb +7 -7
- data/spec/ffi/struct_initialize_spec.rb +2 -2
- data/spec/ffi/struct_packed_spec.rb +6 -6
- data/spec/ffi/struct_spec.rb +85 -85
- data/spec/ffi/typedef_spec.rb +4 -4
- data/spec/ffi/union_spec.rb +3 -3
- data/spec/ffi/variadic_spec.rb +17 -14
- data/tasks/rdoc.rake +1 -1
- metadata +4 -4
data/spec/ffi/callback_spec.rb
CHANGED
@@ -29,7 +29,7 @@ describe "Callback" do
|
|
29
29
|
# cmp = proc do |p1, p2| args.push(p1.get_int(0)); args.push(p2.get_int(0)); 0; end
|
30
30
|
# # this is a bit dodgey, as it relies on qsort passing the args in order
|
31
31
|
# LibC.qsort(p, 2, 4, cmp)
|
32
|
-
# args.should
|
32
|
+
# args.should eq [ 1, 2 ]
|
33
33
|
# end
|
34
34
|
#
|
35
35
|
# it "Block can be substituted for Callback as last argument" do
|
@@ -42,7 +42,7 @@ describe "Callback" do
|
|
42
42
|
# args.push(p2.get_int(0))
|
43
43
|
# 0
|
44
44
|
# end
|
45
|
-
# args.should
|
45
|
+
# args.should eq [ 1, 2 ]
|
46
46
|
# end
|
47
47
|
module LibTest
|
48
48
|
extend FFI::Library
|
@@ -87,7 +87,6 @@ describe "Callback" do
|
|
87
87
|
attach_function :testCallbackVrU64, :testClosureVrLL, [ :cbVrU64 ], :ulong_long
|
88
88
|
attach_function :testCallbackVrP, :testClosureVrP, [ :cbVrP ], :pointer
|
89
89
|
attach_function :testCallbackVrY, :testClosureVrP, [ :cbVrY ], S8F32S32.ptr
|
90
|
-
attach_function :testCallbackCrV, :testClosureBrV, [ :cbCrV, :char ], :void
|
91
90
|
attach_function :testCallbackVrT, :testClosureVrT, [ :cbVrT ], S8F32S32.by_value
|
92
91
|
attach_function :testCallbackTrV, :testClosureTrV, [ :cbTrV, S8F32S32.ptr ], :void
|
93
92
|
attach_variable :cbVrS8, :gvar_pointer, :cbVrS8
|
@@ -96,142 +95,139 @@ describe "Callback" do
|
|
96
95
|
attach_function :testOptionalCallbackCrV, :testOptionalClosureBrV, [ :cbCrV, :char ], :void
|
97
96
|
|
98
97
|
end
|
99
|
-
it "function with Callback plus another arg should raise error if no arg given" do
|
100
|
-
lambda { LibTest.testCallbackCrV { |*a| }}.should raise_error
|
101
|
-
end
|
102
98
|
it "returning :char (0)" do
|
103
|
-
LibTest.testCallbackVrS8 { 0 }.should
|
99
|
+
LibTest.testCallbackVrS8 { 0 }.should eq 0
|
104
100
|
end
|
105
101
|
it "returning :char (127)" do
|
106
|
-
LibTest.testCallbackVrS8 { 127 }.should
|
102
|
+
LibTest.testCallbackVrS8 { 127 }.should eq 127
|
107
103
|
end
|
108
104
|
it "returning :char (-128)" do
|
109
|
-
LibTest.testCallbackVrS8 { -128 }.should
|
105
|
+
LibTest.testCallbackVrS8 { -128 }.should eq(-128)
|
110
106
|
end
|
111
107
|
# test wrap around
|
112
108
|
it "returning :char (128)" do
|
113
|
-
LibTest.testCallbackVrS8 { 128 }.should
|
109
|
+
LibTest.testCallbackVrS8 { 128 }.should eq(-128)
|
114
110
|
end
|
115
111
|
it "returning :char (255)" do
|
116
|
-
LibTest.testCallbackVrS8 { 0xff }.should
|
112
|
+
LibTest.testCallbackVrS8 { 0xff }.should eq(-1)
|
117
113
|
end
|
118
114
|
it "returning :uchar (0)" do
|
119
|
-
LibTest.testCallbackVrU8 { 0 }.should
|
115
|
+
LibTest.testCallbackVrU8 { 0 }.should eq 0
|
120
116
|
end
|
121
117
|
it "returning :uchar (0xff)" do
|
122
|
-
LibTest.testCallbackVrU8 { 0xff }.should
|
118
|
+
LibTest.testCallbackVrU8 { 0xff }.should eq 0xff
|
123
119
|
end
|
124
120
|
it "returning :uchar (-1)" do
|
125
|
-
LibTest.testCallbackVrU8 { -1 }.should
|
121
|
+
LibTest.testCallbackVrU8 { -1 }.should eq 0xff
|
126
122
|
end
|
127
123
|
it "returning :uchar (128)" do
|
128
|
-
LibTest.testCallbackVrU8 { 128 }.should
|
124
|
+
LibTest.testCallbackVrU8 { 128 }.should eq 128
|
129
125
|
end
|
130
126
|
it "returning :uchar (-128)" do
|
131
|
-
LibTest.testCallbackVrU8 { -128 }.should
|
127
|
+
LibTest.testCallbackVrU8 { -128 }.should eq 128
|
132
128
|
end
|
133
129
|
it "returning :short (0)" do
|
134
|
-
LibTest.testCallbackVrS16 { 0 }.should
|
130
|
+
LibTest.testCallbackVrS16 { 0 }.should eq 0
|
135
131
|
end
|
136
132
|
it "returning :short (0x7fff)" do
|
137
|
-
LibTest.testCallbackVrS16 { 0x7fff }.should
|
133
|
+
LibTest.testCallbackVrS16 { 0x7fff }.should eq 0x7fff
|
138
134
|
end
|
139
135
|
# test wrap around
|
140
136
|
it "returning :short (0x8000)" do
|
141
|
-
LibTest.testCallbackVrS16 { 0x8000 }.should
|
137
|
+
LibTest.testCallbackVrS16 { 0x8000 }.should eq(-0x8000)
|
142
138
|
end
|
143
139
|
it "returning :short (0xffff)" do
|
144
|
-
LibTest.testCallbackVrS16 { 0xffff }.should
|
140
|
+
LibTest.testCallbackVrS16 { 0xffff }.should eq(-1)
|
145
141
|
end
|
146
142
|
it "returning :ushort (0)" do
|
147
|
-
LibTest.testCallbackVrU16 { 0 }.should
|
143
|
+
LibTest.testCallbackVrU16 { 0 }.should eq 0
|
148
144
|
end
|
149
145
|
it "returning :ushort (0x7fff)" do
|
150
|
-
LibTest.testCallbackVrU16 { 0x7fff }.should
|
146
|
+
LibTest.testCallbackVrU16 { 0x7fff }.should eq 0x7fff
|
151
147
|
end
|
152
148
|
it "returning :ushort (0x8000)" do
|
153
|
-
LibTest.testCallbackVrU16 { 0x8000 }.should
|
149
|
+
LibTest.testCallbackVrU16 { 0x8000 }.should eq 0x8000
|
154
150
|
end
|
155
151
|
it "returning :ushort (0xffff)" do
|
156
|
-
LibTest.testCallbackVrU16 { 0xffff }.should
|
152
|
+
LibTest.testCallbackVrU16 { 0xffff }.should eq 0xffff
|
157
153
|
end
|
158
154
|
it "returning :ushort (-1)" do
|
159
|
-
LibTest.testCallbackVrU16 { -1 }.should
|
155
|
+
LibTest.testCallbackVrU16 { -1 }.should eq 0xffff
|
160
156
|
end
|
161
157
|
it "returning :int (0)" do
|
162
|
-
LibTest.testCallbackVrS32 { 0 }.should
|
158
|
+
LibTest.testCallbackVrS32 { 0 }.should eq 0
|
163
159
|
end
|
164
160
|
it "returning :int (0x7fffffff)" do
|
165
|
-
LibTest.testCallbackVrS32 { 0x7fffffff }.should
|
161
|
+
LibTest.testCallbackVrS32 { 0x7fffffff }.should eq 0x7fffffff
|
166
162
|
end
|
167
163
|
# test wrap around
|
168
164
|
it "returning :int (-0x80000000)" do
|
169
|
-
LibTest.testCallbackVrS32 { -0x80000000 }.should
|
165
|
+
LibTest.testCallbackVrS32 { -0x80000000 }.should eq(-0x80000000)
|
170
166
|
end
|
171
167
|
it "returning :int (-1)" do
|
172
|
-
LibTest.testCallbackVrS32 { -1 }.should
|
168
|
+
LibTest.testCallbackVrS32 { -1 }.should eq(-1)
|
173
169
|
end
|
174
170
|
it "returning :uint (0)" do
|
175
|
-
LibTest.testCallbackVrU32 { 0 }.should
|
171
|
+
LibTest.testCallbackVrU32 { 0 }.should eq 0
|
176
172
|
end
|
177
173
|
it "returning :uint (0x7fffffff)" do
|
178
|
-
LibTest.testCallbackVrU32 { 0x7fffffff }.should
|
174
|
+
LibTest.testCallbackVrU32 { 0x7fffffff }.should eq 0x7fffffff
|
179
175
|
end
|
180
176
|
# test wrap around
|
181
177
|
it "returning :uint (0x80000000)" do
|
182
|
-
LibTest.testCallbackVrU32 { 0x80000000 }.should
|
178
|
+
LibTest.testCallbackVrU32 { 0x80000000 }.should eq 0x80000000
|
183
179
|
end
|
184
180
|
it "returning :uint (0xffffffff)" do
|
185
|
-
LibTest.testCallbackVrU32 { 0xffffffff }.should
|
181
|
+
LibTest.testCallbackVrU32 { 0xffffffff }.should eq 0xffffffff
|
186
182
|
end
|
187
183
|
it "returning :uint (-1)" do
|
188
|
-
LibTest.testCallbackVrU32 { -1 }.should
|
184
|
+
LibTest.testCallbackVrU32 { -1 }.should eq 0xffffffff
|
189
185
|
end
|
190
186
|
it "returning :long (0)" do
|
191
|
-
LibTest.testCallbackVrL { 0 }.should
|
187
|
+
LibTest.testCallbackVrL { 0 }.should eq 0
|
192
188
|
end
|
193
189
|
it "returning :long (0x7fffffff)" do
|
194
|
-
LibTest.testCallbackVrL { 0x7fffffff }.should
|
190
|
+
LibTest.testCallbackVrL { 0x7fffffff }.should eq 0x7fffffff
|
195
191
|
end
|
196
192
|
# test wrap around
|
197
193
|
it "returning :long (-0x80000000)" do
|
198
|
-
LibTest.testCallbackVrL { -0x80000000 }.should
|
194
|
+
LibTest.testCallbackVrL { -0x80000000 }.should eq(-0x80000000)
|
199
195
|
end
|
200
196
|
it "returning :long (-1)" do
|
201
|
-
LibTest.testCallbackVrL { -1 }.should
|
197
|
+
LibTest.testCallbackVrL { -1 }.should eq(-1)
|
202
198
|
end
|
203
199
|
it "returning :ulong (0)" do
|
204
|
-
LibTest.testCallbackVrUL { 0 }.should
|
200
|
+
LibTest.testCallbackVrUL { 0 }.should eq 0
|
205
201
|
end
|
206
202
|
it "returning :ulong (0x7fffffff)" do
|
207
|
-
LibTest.testCallbackVrUL { 0x7fffffff }.should
|
203
|
+
LibTest.testCallbackVrUL { 0x7fffffff }.should eq 0x7fffffff
|
208
204
|
end
|
209
205
|
# test wrap around
|
210
206
|
it "returning :ulong (0x80000000)" do
|
211
|
-
LibTest.testCallbackVrUL { 0x80000000 }.should
|
207
|
+
LibTest.testCallbackVrUL { 0x80000000 }.should eq 0x80000000
|
212
208
|
end
|
213
209
|
it "returning :ulong (0xffffffff)" do
|
214
|
-
LibTest.testCallbackVrUL { 0xffffffff }.should
|
210
|
+
LibTest.testCallbackVrUL { 0xffffffff }.should eq 0xffffffff
|
215
211
|
end
|
216
212
|
it "Callback returning :ulong (-1)" do
|
217
213
|
if FFI::Platform::LONG_SIZE == 32
|
218
|
-
LibTest.testCallbackVrUL { -1 }.should
|
214
|
+
LibTest.testCallbackVrUL { -1 }.should eq 0xffffffff
|
219
215
|
else
|
220
|
-
LibTest.testCallbackVrUL { -1 }.should
|
216
|
+
LibTest.testCallbackVrUL { -1 }.should eq 0xffffffffffffffff
|
221
217
|
end
|
222
218
|
end
|
223
219
|
it "returning :long_long (0)" do
|
224
|
-
LibTest.testCallbackVrS64 { 0 }.should
|
220
|
+
LibTest.testCallbackVrS64 { 0 }.should eq 0
|
225
221
|
end
|
226
222
|
it "returning :long_long (0x7fffffffffffffff)" do
|
227
|
-
LibTest.testCallbackVrS64 { 0x7fffffffffffffff }.should
|
223
|
+
LibTest.testCallbackVrS64 { 0x7fffffffffffffff }.should eq 0x7fffffffffffffff
|
228
224
|
end
|
229
225
|
# test wrap around
|
230
226
|
it "returning :long_long (-0x8000000000000000)" do
|
231
|
-
LibTest.testCallbackVrS64 { -0x8000000000000000 }.should
|
227
|
+
LibTest.testCallbackVrS64 { -0x8000000000000000 }.should eq(-0x8000000000000000)
|
232
228
|
end
|
233
229
|
it "returning :long_long (-1)" do
|
234
|
-
LibTest.testCallbackVrS64 { -1 }.should
|
230
|
+
LibTest.testCallbackVrS64 { -1 }.should eq(-1)
|
235
231
|
end
|
236
232
|
it "returning bool" do
|
237
233
|
LibTest.testCallbackVrZ { true }.should be_true
|
@@ -241,7 +237,7 @@ describe "Callback" do
|
|
241
237
|
end
|
242
238
|
it "returning :pointer (MemoryPointer)" do
|
243
239
|
p = FFI::MemoryPointer.new :long
|
244
|
-
LibTest.testCallbackVrP { p }.should
|
240
|
+
LibTest.testCallbackVrP { p }.should eq p
|
245
241
|
end
|
246
242
|
|
247
243
|
|
@@ -251,9 +247,9 @@ describe "Callback" do
|
|
251
247
|
s[:s32] = 0x1eefbeef
|
252
248
|
s[:f32] = 1.234567
|
253
249
|
ret = LibTest.testCallbackVrT { s }
|
254
|
-
ret[:s8].should
|
255
|
-
ret[:f32].should
|
256
|
-
ret[:s32].should
|
250
|
+
ret[:s8].should eq s[:s8]
|
251
|
+
ret[:f32].should eq s[:f32]
|
252
|
+
ret[:s32].should eq s[:s32]
|
257
253
|
|
258
254
|
end
|
259
255
|
|
@@ -274,7 +270,7 @@ describe "Callback" do
|
|
274
270
|
it "global variable" do
|
275
271
|
proc = Proc.new { 0x1e }
|
276
272
|
LibTest.cbVrS8 = proc
|
277
|
-
LibTest.testGVarCallbackVrS8(LibTest.pVrS8).should
|
273
|
+
LibTest.testGVarCallbackVrS8(LibTest.pVrS8).should eq 0x1e
|
278
274
|
end
|
279
275
|
|
280
276
|
describe "When the callback is considered optional by the underlying library" do
|
@@ -288,9 +284,9 @@ describe "Callback" do
|
|
288
284
|
module LibTest
|
289
285
|
extend FFI::Library
|
290
286
|
ffi_lib TestLibrary::PATH
|
291
|
-
attach_function :
|
287
|
+
attach_function :testAnonymousCallbackVrS8, :testClosureVrB, [ callback([ ], :char) ], :char
|
292
288
|
end
|
293
|
-
LibTest.
|
289
|
+
LibTest.testAnonymousCallbackVrS8 { 0 }.should eq 0
|
294
290
|
end
|
295
291
|
end
|
296
292
|
|
@@ -328,7 +324,7 @@ describe "Callback" do
|
|
328
324
|
end
|
329
325
|
|
330
326
|
val = LibTest.testReturnsCallback(lookup_proc, 0x1234)
|
331
|
-
val.should
|
327
|
+
val.should eq 0x1234 * 2
|
332
328
|
lookup_proc_called.should be_true
|
333
329
|
return_proc_called.should be_true
|
334
330
|
end
|
@@ -339,7 +335,7 @@ describe "Callback" do
|
|
339
335
|
ffi_lib TestLibrary::PATH
|
340
336
|
callback :cb_return_type, [ :int ], :int
|
341
337
|
callback :cb_lookup, [ ], :cb_return_type
|
342
|
-
attach_function :
|
338
|
+
attach_function :testReturnsCallback_2, :testReturnsClosure, [ :cb_lookup, :int ], :int
|
343
339
|
end
|
344
340
|
module MethodCallback
|
345
341
|
def self.lookup
|
@@ -350,7 +346,7 @@ describe "Callback" do
|
|
350
346
|
end
|
351
347
|
end
|
352
348
|
|
353
|
-
LibTest.
|
349
|
+
LibTest.testReturnsCallback_2(MethodCallback.method(:lookup), 0x1234).should eq 0x2468
|
354
350
|
end
|
355
351
|
|
356
352
|
it 'should not blow up when a callback takes a callback as argument' do
|
@@ -359,7 +355,7 @@ describe "Callback" do
|
|
359
355
|
ffi_lib TestLibrary::PATH
|
360
356
|
callback :cb_argument, [ :int ], :int
|
361
357
|
callback :cb_with_cb_argument, [ :cb_argument, :int ], :int
|
362
|
-
attach_function :
|
358
|
+
attach_function :testCallbackAsArgument_2, :testArgumentClosure, [ :cb_with_cb_argument, :int ], :int
|
363
359
|
end
|
364
360
|
end
|
365
361
|
it 'should be able to use the callback argument' do
|
@@ -381,7 +377,7 @@ describe "Callback" do
|
|
381
377
|
cb.call(val)
|
382
378
|
end
|
383
379
|
val = LibTest.testCallbackAsArgument(callback_with_callback_arg, callback_arg, 0xff1)
|
384
|
-
val.should
|
380
|
+
val.should eq 0xff1 * 2
|
385
381
|
callback_arg_called.should be_true
|
386
382
|
callback_with_callback_arg_called.should be_true
|
387
383
|
end
|
@@ -393,7 +389,7 @@ describe "Callback" do
|
|
393
389
|
attach_function :testReturnsFunctionPointer, [ ], :funcptr
|
394
390
|
end
|
395
391
|
f = LibTest.testReturnsFunctionPointer
|
396
|
-
f.call(3).should
|
392
|
+
f.call(3).should eq 6
|
397
393
|
end
|
398
394
|
end
|
399
395
|
|
@@ -444,86 +440,89 @@ describe "Callback with " do
|
|
444
440
|
attach_function :testCallbackPrV, :testClosurePrV, [ :cbPrV, :pointer], :void
|
445
441
|
attach_function :testCallbackYrV, :testClosurePrV, [ :cbYrV, S8F32S32.in ], :void
|
446
442
|
end
|
443
|
+
it "function with Callback plus another arg should raise error if no arg given" do
|
444
|
+
lambda { LibTest.testCallbackCrV { |*a| }}.should raise_error
|
445
|
+
end
|
447
446
|
it ":char (0) argument" do
|
448
447
|
v = 0xdeadbeef
|
449
448
|
LibTest.testCallbackCrV(0) { |i| v = i }
|
450
|
-
v.should
|
449
|
+
v.should eq 0
|
451
450
|
end
|
452
451
|
it ":char (127) argument" do
|
453
452
|
v = 0xdeadbeef
|
454
453
|
LibTest.testCallbackCrV(127) { |i| v = i }
|
455
|
-
v.should
|
454
|
+
v.should eq 127
|
456
455
|
end
|
457
456
|
it ":char (-128) argument" do
|
458
457
|
v = 0xdeadbeef
|
459
458
|
LibTest.testCallbackCrV(-128) { |i| v = i }
|
460
|
-
v.should
|
459
|
+
v.should eq(-128)
|
461
460
|
end
|
462
461
|
it ":char (-1) argument" do
|
463
462
|
v = 0xdeadbeef
|
464
463
|
LibTest.testCallbackCrV(-1) { |i| v = i }
|
465
|
-
v.should
|
464
|
+
v.should eq(-1)
|
466
465
|
end
|
467
466
|
it ":uchar (0) argument" do
|
468
467
|
v = 0xdeadbeef
|
469
468
|
LibTest.testCallbackU8rV(0) { |i| v = i }
|
470
|
-
v.should
|
469
|
+
v.should eq 0
|
471
470
|
end
|
472
471
|
it ":uchar (127) argument" do
|
473
472
|
v = 0xdeadbeef
|
474
473
|
LibTest.testCallbackU8rV(127) { |i| v = i }
|
475
|
-
v.should
|
474
|
+
v.should eq 127
|
476
475
|
end
|
477
476
|
it ":uchar (128) argument" do
|
478
477
|
v = 0xdeadbeef
|
479
478
|
LibTest.testCallbackU8rV(128) { |i| v = i }
|
480
|
-
v.should
|
479
|
+
v.should eq 128
|
481
480
|
end
|
482
481
|
it ":uchar (255) argument" do
|
483
482
|
v = 0xdeadbeef
|
484
483
|
LibTest.testCallbackU8rV(255) { |i| v = i }
|
485
|
-
v.should
|
484
|
+
v.should eq 255
|
486
485
|
end
|
487
486
|
|
488
487
|
it ":short (0) argument" do
|
489
488
|
v = 0xdeadbeef
|
490
489
|
LibTest.testCallbackSrV(0) { |i| v = i }
|
491
|
-
v.should
|
490
|
+
v.should eq 0
|
492
491
|
end
|
493
492
|
it ":short (0x7fff) argument" do
|
494
493
|
v = 0xdeadbeef
|
495
494
|
LibTest.testCallbackSrV(0x7fff) { |i| v = i }
|
496
|
-
v.should
|
495
|
+
v.should eq 0x7fff
|
497
496
|
end
|
498
497
|
it ":short (-0x8000) argument" do
|
499
498
|
v = 0xdeadbeef
|
500
499
|
LibTest.testCallbackSrV(-0x8000) { |i| v = i }
|
501
|
-
v.should
|
500
|
+
v.should eq(-0x8000)
|
502
501
|
end
|
503
502
|
it ":short (-1) argument" do
|
504
503
|
v = 0xdeadbeef
|
505
504
|
LibTest.testCallbackSrV(-1) { |i| v = i }
|
506
|
-
v.should
|
505
|
+
v.should eq(-1)
|
507
506
|
end
|
508
507
|
it ":ushort (0) argument" do
|
509
508
|
v = 0xdeadbeef
|
510
509
|
LibTest.testCallbackU16rV(0) { |i| v = i }
|
511
|
-
v.should
|
510
|
+
v.should eq 0
|
512
511
|
end
|
513
512
|
it ":ushort (0x7fff) argument" do
|
514
513
|
v = 0xdeadbeef
|
515
514
|
LibTest.testCallbackU16rV(0x7fff) { |i| v = i }
|
516
|
-
v.should
|
515
|
+
v.should eq 0x7fff
|
517
516
|
end
|
518
517
|
it ":ushort (0x8000) argument" do
|
519
518
|
v = 0xdeadbeef
|
520
519
|
LibTest.testCallbackU16rV(0x8000) { |i| v = i }
|
521
|
-
v.should
|
520
|
+
v.should eq 0x8000
|
522
521
|
end
|
523
522
|
it ":ushort (0xffff) argument" do
|
524
523
|
v = 0xdeadbeef
|
525
524
|
LibTest.testCallbackU16rV(0xffff) { |i| v = i }
|
526
|
-
v.should
|
525
|
+
v.should eq 0xffff
|
527
526
|
end
|
528
527
|
it ":bool (true) argument" do
|
529
528
|
v = false
|
@@ -533,107 +532,107 @@ describe "Callback with " do
|
|
533
532
|
it ":int (0) argument" do
|
534
533
|
v = 0xdeadbeef
|
535
534
|
LibTest.testCallbackIrV(0) { |i| v = i }
|
536
|
-
v.should
|
535
|
+
v.should eq 0
|
537
536
|
end
|
538
537
|
it ":int (0x7fffffff) argument" do
|
539
538
|
v = 0xdeadbeef
|
540
539
|
LibTest.testCallbackIrV(0x7fffffff) { |i| v = i }
|
541
|
-
v.should
|
540
|
+
v.should eq 0x7fffffff
|
542
541
|
end
|
543
542
|
it ":int (-0x80000000) argument" do
|
544
543
|
v = 0xdeadbeef
|
545
544
|
LibTest.testCallbackIrV(-0x80000000) { |i| v = i }
|
546
|
-
v.should
|
545
|
+
v.should eq(-0x80000000)
|
547
546
|
end
|
548
547
|
it ":int (-1) argument" do
|
549
548
|
v = 0xdeadbeef
|
550
549
|
LibTest.testCallbackIrV(-1) { |i| v = i }
|
551
|
-
v.should
|
550
|
+
v.should eq(-1)
|
552
551
|
end
|
553
552
|
it ":uint (0) argument" do
|
554
553
|
v = 0xdeadbeef
|
555
554
|
LibTest.testCallbackU32rV(0) { |i| v = i }
|
556
|
-
v.should
|
555
|
+
v.should eq 0
|
557
556
|
end
|
558
557
|
it ":uint (0x7fffffff) argument" do
|
559
558
|
v = 0xdeadbeef
|
560
559
|
LibTest.testCallbackU32rV(0x7fffffff) { |i| v = i }
|
561
|
-
v.should
|
560
|
+
v.should eq 0x7fffffff
|
562
561
|
end
|
563
562
|
it ":uint (0x80000000) argument" do
|
564
563
|
v = 0xdeadbeef
|
565
564
|
LibTest.testCallbackU32rV(0x80000000) { |i| v = i }
|
566
|
-
v.should
|
565
|
+
v.should eq 0x80000000
|
567
566
|
end
|
568
567
|
it ":uint (0xffffffff) argument" do
|
569
568
|
v = 0xdeadbeef
|
570
569
|
LibTest.testCallbackU32rV(0xffffffff) { |i| v = i }
|
571
|
-
v.should
|
570
|
+
v.should eq 0xffffffff
|
572
571
|
end
|
573
572
|
it ":long (0) argument" do
|
574
573
|
v = 0xdeadbeef
|
575
574
|
LibTest.testCallbackLrV(0) { |i| v = i }
|
576
|
-
v.should
|
575
|
+
v.should eq 0
|
577
576
|
end
|
578
577
|
it ":long (0x7fffffff) argument" do
|
579
578
|
v = 0xdeadbeef
|
580
579
|
LibTest.testCallbackLrV(0x7fffffff) { |i| v = i }
|
581
|
-
v.should
|
580
|
+
v.should eq 0x7fffffff
|
582
581
|
end
|
583
582
|
it ":long (-0x80000000) argument" do
|
584
583
|
v = 0xdeadbeef
|
585
584
|
LibTest.testCallbackLrV(-0x80000000) { |i| v = i }
|
586
|
-
v.should
|
585
|
+
v.should eq(-0x80000000)
|
587
586
|
end
|
588
587
|
it ":long (-1) argument" do
|
589
588
|
v = 0xdeadbeef
|
590
589
|
LibTest.testCallbackLrV(-1) { |i| v = i }
|
591
|
-
v.should
|
590
|
+
v.should eq(-1)
|
592
591
|
end
|
593
592
|
it ":ulong (0) argument" do
|
594
593
|
v = 0xdeadbeef
|
595
594
|
LibTest.testCallbackULrV(0) { |i| v = i }
|
596
|
-
v.should
|
595
|
+
v.should eq 0
|
597
596
|
end
|
598
597
|
it ":ulong (0x7fffffff) argument" do
|
599
598
|
v = 0xdeadbeef
|
600
599
|
LibTest.testCallbackULrV(0x7fffffff) { |i| v = i }
|
601
|
-
v.should
|
600
|
+
v.should eq 0x7fffffff
|
602
601
|
end
|
603
602
|
it ":ulong (0x80000000) argument" do
|
604
603
|
v = 0xdeadbeef
|
605
604
|
LibTest.testCallbackULrV(0x80000000) { |i| v = i }
|
606
|
-
v.should
|
605
|
+
v.should eq 0x80000000
|
607
606
|
end
|
608
607
|
it ":ulong (0xffffffff) argument" do
|
609
608
|
v = 0xdeadbeef
|
610
609
|
LibTest.testCallbackULrV(0xffffffff) { |i| v = i }
|
611
|
-
v.should
|
610
|
+
v.should eq 0xffffffff
|
612
611
|
end
|
613
612
|
it ":long_long (0) argument" do
|
614
613
|
v = 0xdeadbeef
|
615
614
|
LibTest.testCallbackLLrV(0) { |i| v = i }
|
616
|
-
v.should
|
615
|
+
v.should eq 0
|
617
616
|
end
|
618
617
|
it ":long_long (0x7fffffffffffffff) argument" do
|
619
618
|
v = 0xdeadbeef
|
620
619
|
LibTest.testCallbackLLrV(0x7fffffffffffffff) { |i| v = i }
|
621
|
-
v.should
|
620
|
+
v.should eq 0x7fffffffffffffff
|
622
621
|
end
|
623
622
|
it ":long_long (-0x8000000000000000) argument" do
|
624
623
|
v = 0xdeadbeef
|
625
624
|
LibTest.testCallbackLLrV(-0x8000000000000000) { |i| v = i }
|
626
|
-
v.should
|
625
|
+
v.should eq(-0x8000000000000000)
|
627
626
|
end
|
628
627
|
it ":long_long (-1) argument" do
|
629
628
|
v = 0xdeadbeef
|
630
629
|
LibTest.testCallbackLLrV(-1) { |i| v = i }
|
631
|
-
v.should
|
630
|
+
v.should eq(-1)
|
632
631
|
end
|
633
632
|
it ":string argument" do
|
634
633
|
v = nil
|
635
634
|
LibTest.testCallbackArV("Hello, World") { |i| v = i }
|
636
|
-
v.should
|
635
|
+
v.should eq "Hello, World"
|
637
636
|
end
|
638
637
|
it ":string (nil) argument" do
|
639
638
|
v = "Hello, World"
|
@@ -644,18 +643,18 @@ describe "Callback with " do
|
|
644
643
|
v = nil
|
645
644
|
magic = FFI::Pointer.new(0xdeadbeef)
|
646
645
|
LibTest.testCallbackPrV(magic) { |i| v = i }
|
647
|
-
v.should
|
646
|
+
v.should eq magic
|
648
647
|
end
|
649
648
|
it ":pointer (nil) argument" do
|
650
649
|
v = "Hello, World"
|
651
650
|
LibTest.testCallbackPrV(nil) { |i| v = i }
|
652
|
-
v.should
|
651
|
+
v.should eq FFI::Pointer::NULL
|
653
652
|
end
|
654
653
|
it "struct by reference argument" do
|
655
654
|
v = nil
|
656
655
|
magic = LibTest::S8F32S32.new
|
657
656
|
LibTest.testCallbackYrV(magic) { |i| v = i }
|
658
|
-
v.class.should
|
657
|
+
v.class.should eq magic.class
|
659
658
|
v.pointer == magic.pointer
|
660
659
|
end
|
661
660
|
|
@@ -663,7 +662,7 @@ describe "Callback with " do
|
|
663
662
|
v = LibTest::S8F32S32.new
|
664
663
|
LibTest.testCallbackYrV(nil) { |i| v = i }
|
665
664
|
v.is_a?(FFI::Struct).should be_true
|
666
|
-
v.pointer.should
|
665
|
+
v.pointer.should eq FFI::Pointer::NULL
|
667
666
|
end
|
668
667
|
|
669
668
|
end # unless true
|