ffi 1.2.1-x86-mingw32 → 1.3.0-x86-mingw32
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/README.md +10 -5
- data/ext/ffi_c/ArrayType.c +6 -2
- data/ext/ffi_c/Buffer.c +3 -1
- data/ext/ffi_c/Call.c +12 -21
- data/ext/ffi_c/FunctionInfo.c +27 -2
- data/ext/ffi_c/MappedType.c +1 -2
- data/ext/ffi_c/MemoryPointer.c +35 -4
- data/ext/ffi_c/Pointer.c +5 -4
- data/ext/ffi_c/Struct.c +125 -8
- data/ext/ffi_c/StructByReference.c +33 -0
- data/ext/ffi_c/StructByValue.c +2 -2
- data/ext/ffi_c/StructLayout.c +135 -1
- data/ext/ffi_c/Type.c +1 -0
- data/ext/ffi_c/extconf.rb +1 -1
- data/ffi.gemspec +1 -1
- data/lib/1.8/ffi_c.so +0 -0
- data/lib/1.9/ffi_c.so +0 -0
- data/lib/ffi.rb +2 -1
- data/lib/ffi/library.rb +2 -0
- data/lib/ffi/managedstruct.rb +37 -37
- data/lib/ffi/struct.rb +74 -1
- data/lib/ffi/struct_layout_builder.rb +50 -1
- data/lib/ffi/tools/generator.rb +2 -0
- data/lib/ffi/tools/generator_task.rb +1 -0
- data/lib/ffi/tools/types_generator.rb +2 -0
- data/libtest/Benchmark.c +1 -15
- data/libtest/BoolTest.c +2 -16
- data/libtest/BufferTest.c +3 -17
- data/libtest/ClosureTest.c +1 -15
- data/libtest/EnumTest.c +1 -15
- data/libtest/FunctionTest.c +2 -16
- data/libtest/GlobalVariable.c +2 -16
- data/libtest/LastErrorTest.c +2 -16
- data/libtest/NumberTest.c +1 -15
- data/libtest/PointerTest.c +1 -15
- data/libtest/ReferenceTest.c +1 -15
- data/libtest/StringTest.c +1 -15
- data/libtest/StructTest.c +1 -15
- data/libtest/UnionTest.c +1 -15
- data/libtest/VariadicTest.c +2 -16
- data/spec/ffi/async_callback_spec.rb +3 -14
- data/spec/ffi/bool_spec.rb +7 -18
- data/spec/ffi/buffer_spec.rb +26 -37
- data/spec/ffi/callback_spec.rb +96 -107
- data/spec/ffi/custom_param_type.rb +2 -13
- data/spec/ffi/custom_type_spec.rb +1 -12
- data/spec/ffi/dup_spec.rb +7 -18
- data/spec/ffi/enum_spec.rb +128 -139
- data/spec/ffi/errno_spec.rb +2 -13
- data/spec/ffi/ffi_spec.rb +4 -15
- data/spec/ffi/function_spec.rb +6 -17
- data/spec/ffi/library_spec.rb +26 -26
- data/spec/ffi/long_double.rb +1 -12
- data/spec/ffi/managed_struct_spec.rb +3 -18
- data/spec/ffi/number_spec.rb +32 -43
- data/spec/ffi/pointer_spec.rb +7 -22
- 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 +10 -12
- data/spec/ffi/string_spec.rb +9 -20
- data/spec/ffi/strptr_spec.rb +2 -13
- data/spec/ffi/struct_callback_spec.rb +3 -14
- data/spec/ffi/struct_initialize_spec.rb +3 -14
- data/spec/ffi/struct_packed_spec.rb +7 -18
- data/spec/ffi/struct_spec.rb +93 -104
- data/spec/ffi/typedef_spec.rb +5 -16
- data/spec/ffi/union_spec.rb +4 -15
- data/spec/ffi/variadic_spec.rb +7 -18
- metadata +4 -4
data/spec/ffi/ffi_spec.rb
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# This file is part of ruby-ffi.
|
3
|
-
#
|
4
|
-
# This code is free software: you can redistribute it and/or modify it under
|
5
|
-
# the terms of the GNU Lesser General Public License version 3 only, as
|
6
|
-
# published by the Free Software Foundation.
|
7
|
-
#
|
8
|
-
# This code is distributed in the hope that it will be useful, but WITHOUT
|
9
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
11
|
-
# version 3 for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
15
4
|
#
|
16
5
|
|
17
6
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
@@ -24,15 +13,15 @@ describe "FFI" do
|
|
24
13
|
let(:suffix) { FFI::Platform::LIBSUFFIX }
|
25
14
|
|
26
15
|
it "should add platform library extension if not present" do
|
27
|
-
FFI.map_library_name("#{prefix}dummy").should
|
16
|
+
FFI.map_library_name("#{prefix}dummy").should == "#{prefix}dummy.#{suffix}"
|
28
17
|
end
|
29
18
|
|
30
19
|
it "should add platform library extension even if lib suffix is present in name" do
|
31
|
-
FFI.map_library_name("#{prefix}dummy_with_#{suffix}").should
|
20
|
+
FFI.map_library_name("#{prefix}dummy_with_#{suffix}").should == "#{prefix}dummy_with_#{suffix}.#{suffix}"
|
32
21
|
end
|
33
22
|
|
34
23
|
it "should return Platform::LIBC when called with 'c'" do
|
35
|
-
FFI.map_library_name('c').should
|
24
|
+
FFI.map_library_name('c').should == FFI::Library::LIBC
|
36
25
|
end
|
37
26
|
|
38
27
|
end
|
data/spec/ffi/function_spec.rb
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# This file is part of ruby-ffi.
|
3
|
-
#
|
4
|
-
# This code is free software: you can redistribute it and/or modify it under
|
5
|
-
# the terms of the GNU Lesser General Public License version 3 only, as
|
6
|
-
# published by the Free Software Foundation.
|
7
|
-
#
|
8
|
-
# This code is distributed in the hope that it will be useful, but WITHOUT
|
9
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
11
|
-
# version 3 for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
15
4
|
#
|
16
5
|
|
17
6
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
@@ -37,20 +26,20 @@ describe FFI::Function do
|
|
37
26
|
end
|
38
27
|
it 'can be used as callback from C passing to it a block' do
|
39
28
|
function_add = FFI::Function.new(:int, [:int, :int]) { |a, b| a + b }
|
40
|
-
LibTest.testFunctionAdd(10, 10, function_add).should
|
29
|
+
LibTest.testFunctionAdd(10, 10, function_add).should == 20
|
41
30
|
end
|
42
31
|
it 'can be used as callback from C passing to it a Proc object' do
|
43
32
|
function_add = FFI::Function.new(:int, [:int, :int], Proc.new { |a, b| a + b })
|
44
|
-
LibTest.testFunctionAdd(10, 10, function_add).should
|
33
|
+
LibTest.testFunctionAdd(10, 10, function_add).should == 20
|
45
34
|
end
|
46
35
|
it 'can be used to wrap an existing function pointer' do
|
47
|
-
FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd')).call(10, 10).should
|
36
|
+
FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd')).call(10, 10).should == 20
|
48
37
|
end
|
49
38
|
it 'can be attached to a module' do
|
50
39
|
module Foo; end
|
51
40
|
fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd'))
|
52
41
|
fp.attach(Foo, 'add')
|
53
|
-
Foo.add(10, 10).should
|
42
|
+
Foo.add(10, 10).should == 20
|
54
43
|
end
|
55
44
|
it 'can be used to extend an object' do
|
56
45
|
fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd'))
|
@@ -61,7 +50,7 @@ describe FFI::Function do
|
|
61
50
|
end
|
62
51
|
end
|
63
52
|
fp.attach(foo.singleton_class, 'add')
|
64
|
-
foo.add(10, 10).should
|
53
|
+
foo.add(10, 10).should == 20
|
65
54
|
end
|
66
55
|
it 'can wrap a blocking function' do
|
67
56
|
fp = FFI::Function.new(:void, [ :int ], @libtest.find_function('testBlocking'), :blocking => true)
|
data/spec/ffi/library_spec.rb
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# This file is part of ruby-ffi.
|
3
|
-
#
|
4
|
-
# This code is free software: you can redistribute it and/or modify it under
|
5
|
-
# the terms of the GNU Lesser General Public License version 3 only, as
|
6
|
-
# published by the Free Software Foundation.
|
7
|
-
#
|
8
|
-
# This code is distributed in the hope that it will be useful, but WITHOUT
|
9
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
11
|
-
# version 3 for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
15
4
|
#
|
16
5
|
|
17
6
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
@@ -21,7 +10,7 @@ describe "Library" do
|
|
21
10
|
m = Module.new do
|
22
11
|
extend FFI::Library
|
23
12
|
end
|
24
|
-
m.ffi_convention.should
|
13
|
+
m.ffi_convention.should == :default
|
25
14
|
end
|
26
15
|
|
27
16
|
it "should be settable" do
|
@@ -29,12 +18,23 @@ describe "Library" do
|
|
29
18
|
extend FFI::Library
|
30
19
|
end
|
31
20
|
|
32
|
-
m.ffi_convention.should
|
21
|
+
m.ffi_convention.should == :default
|
33
22
|
m.ffi_convention :stdcall
|
34
|
-
m.ffi_convention.should
|
23
|
+
m.ffi_convention.should == :stdcall
|
35
24
|
end
|
36
25
|
end
|
37
26
|
|
27
|
+
describe "ffi_lib" do
|
28
|
+
it "empty name list should raise error" do
|
29
|
+
lambda {
|
30
|
+
Module.new do |m|
|
31
|
+
m.extend FFI::Library
|
32
|
+
ffi_lib
|
33
|
+
end
|
34
|
+
}.should raise_error(LoadError)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
38
|
unless RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
|
39
39
|
it "attach_function with no library specified" do
|
40
40
|
lambda {
|
@@ -50,7 +50,7 @@ describe "Library" do
|
|
50
50
|
m.extend FFI::Library
|
51
51
|
ffi_lib FFI::Library::CURRENT_PROCESS
|
52
52
|
attach_function :getpid, [ ], :uint
|
53
|
-
end.getpid.should
|
53
|
+
end.getpid.should == Process.pid
|
54
54
|
}.should_not raise_error
|
55
55
|
end
|
56
56
|
it "attach_function :getpid from [ 'c', 'libc.so.6'] " do
|
@@ -59,7 +59,7 @@ describe "Library" do
|
|
59
59
|
m.extend FFI::Library
|
60
60
|
ffi_lib [ 'c', 'libc.so.6' ]
|
61
61
|
attach_function :getpid, [ ], :uint
|
62
|
-
end.getpid.should
|
62
|
+
end.getpid.should == Process.pid
|
63
63
|
}.should_not raise_error
|
64
64
|
end
|
65
65
|
it "attach_function :getpid from [ 'libc.so.6', 'c' ] " do
|
@@ -68,7 +68,7 @@ describe "Library" do
|
|
68
68
|
m.extend FFI::Library
|
69
69
|
ffi_lib [ 'libc.so.6', 'c' ]
|
70
70
|
attach_function :getpid, [ ], :uint
|
71
|
-
end.getpid.should
|
71
|
+
end.getpid.should == Process.pid
|
72
72
|
}.should_not raise_error
|
73
73
|
end
|
74
74
|
it "attach_function :getpid from [ 'libfubar.so.0xdeadbeef', nil, 'c' ] " do
|
@@ -77,7 +77,7 @@ describe "Library" do
|
|
77
77
|
m.extend FFI::Library
|
78
78
|
ffi_lib [ 'libfubar.so.0xdeadbeef', nil, 'c' ]
|
79
79
|
attach_function :getpid, [ ], :uint
|
80
|
-
end.getpid.should
|
80
|
+
end.getpid.should == Process.pid
|
81
81
|
}.should_not raise_error
|
82
82
|
end
|
83
83
|
it "attach_function :getpid from [ 'libfubar.so.0xdeadbeef' ] " do
|
@@ -86,7 +86,7 @@ describe "Library" do
|
|
86
86
|
m.extend FFI::Library
|
87
87
|
ffi_lib 'libfubar.so.0xdeadbeef'
|
88
88
|
attach_function :getpid, [ ], :uint
|
89
|
-
end.getpid.should
|
89
|
+
end.getpid.should == Process.pid
|
90
90
|
}.should raise_error(LoadError)
|
91
91
|
end
|
92
92
|
end
|
@@ -103,10 +103,10 @@ describe "Library" do
|
|
103
103
|
def gvar_test(name, type, val)
|
104
104
|
lib = gvar_lib(name, type)
|
105
105
|
lib.set(val)
|
106
|
-
lib.gvar.should
|
106
|
+
lib.gvar.should == val
|
107
107
|
lib.set(0)
|
108
108
|
lib.gvar = val
|
109
|
-
lib.get.should
|
109
|
+
lib.get.should == val
|
110
110
|
end
|
111
111
|
[ 0, 127, -128, -1 ].each do |i|
|
112
112
|
it ":char variable" do
|
@@ -175,10 +175,10 @@ describe "Library" do
|
|
175
175
|
lib = gvar_lib("pointer", :pointer)
|
176
176
|
val = FFI::MemoryPointer.new :long
|
177
177
|
lib.set(val)
|
178
|
-
lib.gvar.should
|
178
|
+
lib.gvar.should == val
|
179
179
|
lib.set(nil)
|
180
180
|
lib.gvar = val
|
181
|
-
lib.get.should
|
181
|
+
lib.get.should == val
|
182
182
|
end
|
183
183
|
|
184
184
|
[ 0, 0x7fffffff, -0x80000000, -1 ].each do |i|
|
@@ -198,11 +198,11 @@ describe "Library" do
|
|
198
198
|
val = GlobalStruct.new
|
199
199
|
val[:data] = i
|
200
200
|
lib.set(val)
|
201
|
-
lib.gvar[:data].should
|
201
|
+
lib.gvar[:data].should == i
|
202
202
|
val[:data] = 0
|
203
203
|
lib.gvar[:data] = i
|
204
204
|
val = GlobalStruct.new(lib.get)
|
205
|
-
val[:data].should
|
205
|
+
val[:data].should == i
|
206
206
|
end
|
207
207
|
end
|
208
208
|
end
|
data/spec/ffi/long_double.rb
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# This file is part of ruby-ffi.
|
3
|
-
#
|
4
|
-
# This code is free software: you can redistribute it and/or modify it under
|
5
|
-
# the terms of the GNU Lesser General Public License version 3 only, as
|
6
|
-
# published by the Free Software Foundation.
|
7
|
-
#
|
8
|
-
# This code is distributed in the hope that it will be useful, but WITHOUT
|
9
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
11
|
-
# version 3 for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
15
4
|
#
|
16
5
|
|
17
6
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
@@ -1,17 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# This file is part of ruby-ffi.
|
3
|
-
#
|
4
|
-
# This code is free software: you can redistribute it and/or modify it under
|
5
|
-
# the terms of the GNU Lesser General Public License version 3 only, as
|
6
|
-
# published by the Free Software Foundation.
|
7
|
-
#
|
8
|
-
# This code is distributed in the hope that it will be useful, but WITHOUT
|
9
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
11
|
-
# version 3 for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
15
4
|
#
|
16
5
|
|
17
6
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
@@ -36,7 +25,7 @@ describe "Managed Struct" do
|
|
36
25
|
end
|
37
26
|
end
|
38
27
|
|
39
|
-
WhatClassAmI.new(ManagedStructTestLib.ptr_from_address(0x12345678)).class.should
|
28
|
+
WhatClassAmI.new(ManagedStructTestLib.ptr_from_address(0x12345678)).class.should == WhatClassAmI
|
40
29
|
end
|
41
30
|
|
42
31
|
it "should release memory properly" do
|
@@ -50,11 +39,7 @@ describe "Managed Struct" do
|
|
50
39
|
loop = 5
|
51
40
|
while loop > 0 && @@count < count
|
52
41
|
loop -= 1
|
53
|
-
|
54
|
-
java.lang.System.gc
|
55
|
-
else
|
56
|
-
GC.start
|
57
|
-
end
|
42
|
+
TestLibrary.force_gc
|
58
43
|
sleep 0.05 if @@count < count
|
59
44
|
end
|
60
45
|
end
|
data/spec/ffi/number_spec.rb
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# This file is part of ruby-ffi.
|
3
|
-
#
|
4
|
-
# This code is free software: you can redistribute it and/or modify it under
|
5
|
-
# the terms of the GNU Lesser General Public License version 3 only, as
|
6
|
-
# published by the Free Software Foundation.
|
7
|
-
#
|
8
|
-
# This code is distributed in the hope that it will be useful, but WITHOUT
|
9
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
11
|
-
# version 3 for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public License
|
14
|
-
# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
3
|
+
# For licensing, see LICENSE.SPECS
|
15
4
|
#
|
16
5
|
|
17
6
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
@@ -37,95 +26,95 @@ describe "Function with primitive integer arguments" do
|
|
37
26
|
attach_function :get_double, [ ], :double
|
38
27
|
end
|
39
28
|
it "int8.size" do
|
40
|
-
FFI::TYPE_INT8.size.should
|
29
|
+
FFI::TYPE_INT8.size.should == 1
|
41
30
|
end
|
42
31
|
it "uint8.size" do
|
43
|
-
FFI::TYPE_UINT8.size.should
|
32
|
+
FFI::TYPE_UINT8.size.should == 1
|
44
33
|
end
|
45
34
|
it "int16.size" do
|
46
|
-
FFI::TYPE_INT16.size.should
|
35
|
+
FFI::TYPE_INT16.size.should == 2
|
47
36
|
end
|
48
37
|
it "uint16.size" do
|
49
|
-
FFI::TYPE_UINT16.size.should
|
38
|
+
FFI::TYPE_UINT16.size.should == 2
|
50
39
|
end
|
51
40
|
it "int32.size" do
|
52
|
-
FFI::TYPE_INT32.size.should
|
41
|
+
FFI::TYPE_INT32.size.should == 4
|
53
42
|
end
|
54
43
|
it "uint32.size" do
|
55
|
-
FFI::TYPE_UINT32.size.should
|
44
|
+
FFI::TYPE_UINT32.size.should == 4
|
56
45
|
end
|
57
46
|
it "int64.size" do
|
58
|
-
FFI::TYPE_INT64.size.should
|
47
|
+
FFI::TYPE_INT64.size.should == 8
|
59
48
|
end
|
60
49
|
it "uint64.size" do
|
61
|
-
FFI::TYPE_UINT64.size.should
|
50
|
+
FFI::TYPE_UINT64.size.should == 8
|
62
51
|
end
|
63
52
|
it "float.size" do
|
64
|
-
FFI::TYPE_FLOAT32.size.should
|
53
|
+
FFI::TYPE_FLOAT32.size.should == 4
|
65
54
|
end
|
66
55
|
it "double.size" do
|
67
|
-
FFI::TYPE_FLOAT64.size.should
|
56
|
+
FFI::TYPE_FLOAT64.size.should == 8
|
68
57
|
end
|
69
58
|
[ 0, 127, -128, -1 ].each do |i|
|
70
59
|
it ":char call(:char (#{i}))" do
|
71
|
-
LibTest.ret_s8(i).should
|
60
|
+
LibTest.ret_s8(i).should == i
|
72
61
|
end
|
73
62
|
end
|
74
63
|
[ 0, 0x7f, 0x80, 0xff ].each do |i|
|
75
64
|
it ":uchar call(:uchar (#{i}))" do
|
76
|
-
LibTest.ret_u8(i).should
|
65
|
+
LibTest.ret_u8(i).should == i
|
77
66
|
end
|
78
67
|
end
|
79
68
|
[ 0, 0x7fff, -0x8000, -1 ].each do |i|
|
80
69
|
it ":short call(:short (#{i}))" do
|
81
|
-
LibTest.ret_s16(i).should
|
70
|
+
LibTest.ret_s16(i).should == i
|
82
71
|
end
|
83
72
|
end
|
84
73
|
[ 0, 0x7fff, 0x8000, 0xffff ].each do |i|
|
85
74
|
it ":ushort call(:ushort (#{i}))" do
|
86
|
-
LibTest.ret_u16(i).should
|
75
|
+
LibTest.ret_u16(i).should == i
|
87
76
|
end
|
88
77
|
end
|
89
78
|
[ 0, 0x7fffffff, -0x80000000, -1 ].each do |i|
|
90
79
|
it ":int call(:int (#{i}))" do
|
91
|
-
LibTest.ret_s32(i).should
|
80
|
+
LibTest.ret_s32(i).should == i
|
92
81
|
end
|
93
82
|
end
|
94
83
|
[ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i|
|
95
84
|
it ":uint call(:uint (#{i}))" do
|
96
|
-
LibTest.ret_u32(i).should
|
85
|
+
LibTest.ret_u32(i).should == i
|
97
86
|
end
|
98
87
|
end
|
99
88
|
[ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i|
|
100
89
|
it ":long_long call(:long_long (#{i}))" do
|
101
|
-
LibTest.ret_s64(i).should
|
90
|
+
LibTest.ret_s64(i).should == i
|
102
91
|
end
|
103
92
|
end
|
104
93
|
[ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i|
|
105
94
|
it ":ulong_long call(:ulong_long (#{i}))" do
|
106
|
-
LibTest.ret_u64(i).should
|
95
|
+
LibTest.ret_u64(i).should == i
|
107
96
|
end
|
108
97
|
end
|
109
98
|
if FFI::Platform::LONG_SIZE == 32
|
110
99
|
[ 0, 0x7fffffff, -0x80000000, -1 ].each do |i|
|
111
100
|
it ":long call(:long (#{i}))" do
|
112
|
-
LibTest.ret_long(i).should
|
101
|
+
LibTest.ret_long(i).should == i
|
113
102
|
end
|
114
103
|
end
|
115
104
|
[ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i|
|
116
105
|
it ":ulong call(:ulong (#{i}))" do
|
117
|
-
LibTest.ret_ulong(i).should
|
106
|
+
LibTest.ret_ulong(i).should == i
|
118
107
|
end
|
119
108
|
end
|
120
109
|
else
|
121
110
|
[ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i|
|
122
111
|
it ":long call(:long (#{i}))" do
|
123
|
-
LibTest.ret_long(i).should
|
112
|
+
LibTest.ret_long(i).should == i
|
124
113
|
end
|
125
114
|
end
|
126
115
|
[ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i|
|
127
116
|
it ":ulong call(:ulong (#{i}))" do
|
128
|
-
LibTest.ret_ulong(i).should
|
117
|
+
LibTest.ret_ulong(i).should == i
|
129
118
|
end
|
130
119
|
end
|
131
120
|
[ 0.0, 0.1, 1.1, 1.23 ].each do |f|
|
@@ -145,32 +134,32 @@ end
|
|
145
134
|
describe "Integer parameter range checking" do
|
146
135
|
[ 128, -129 ].each do |i|
|
147
136
|
it ":char call(:char (#{i}))" do
|
148
|
-
lambda { LibTest.ret_int8_t(i).should
|
137
|
+
lambda { LibTest.ret_int8_t(i).should == i }.should raise_error
|
149
138
|
end
|
150
139
|
end
|
151
140
|
[ -1, 256 ].each do |i|
|
152
141
|
it ":uchar call(:uchar (#{i}))" do
|
153
|
-
lambda { LibTest.ret_u_int8_t(i).should
|
142
|
+
lambda { LibTest.ret_u_int8_t(i).should == i }.should raise_error
|
154
143
|
end
|
155
144
|
end
|
156
145
|
[ 0x8000, -0x8001 ].each do |i|
|
157
146
|
it ":short call(:short (#{i}))" do
|
158
|
-
lambda { LibTest.ret_int16_t(i).should
|
147
|
+
lambda { LibTest.ret_int16_t(i).should == i }.should raise_error
|
159
148
|
end
|
160
149
|
end
|
161
150
|
[ -1, 0x10000 ].each do |i|
|
162
151
|
it ":ushort call(:ushort (#{i}))" do
|
163
|
-
lambda { LibTest.ret_u_int16_t(i).should
|
152
|
+
lambda { LibTest.ret_u_int16_t(i).should == i }.should raise_error
|
164
153
|
end
|
165
154
|
end
|
166
155
|
[ 0x80000000, -0x80000001 ].each do |i|
|
167
156
|
it ":int call(:int (#{i}))" do
|
168
|
-
lambda { LibTest.ret_int32_t(i).should
|
157
|
+
lambda { LibTest.ret_int32_t(i).should == i }.should raise_error
|
169
158
|
end
|
170
159
|
end
|
171
160
|
[ -1, 0x100000000 ].each do |i|
|
172
161
|
it ":ushort call(:ushort (#{i}))" do
|
173
|
-
lambda { LibTest.ret_u_int32_t(i).should
|
162
|
+
lambda { LibTest.ret_u_int32_t(i).should == i }.should raise_error
|
174
163
|
end
|
175
164
|
end
|
176
165
|
end
|
@@ -217,11 +206,11 @@ describe "Three different size Integer arguments" do
|
|
217
206
|
|
218
207
|
def verify(p, off, t, v)
|
219
208
|
if t == 'f32'
|
220
|
-
p.get_float32(off).should
|
209
|
+
p.get_float32(off).should == v
|
221
210
|
elsif t == 'f64'
|
222
|
-
p.get_float64(off).should
|
211
|
+
p.get_float64(off).should == v
|
223
212
|
else
|
224
|
-
p.get_int64(off).should
|
213
|
+
p.get_int64(off).should == v
|
225
214
|
end
|
226
215
|
end
|
227
216
|
|