ffi 1.2.1 → 1.3.0
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/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 +73 -58
@@ -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"))
|
@@ -44,4 +33,4 @@ describe "functions with custom parameter types" do
|
|
44
33
|
end
|
45
34
|
|
46
35
|
end
|
47
|
-
end
|
36
|
+
end
|
@@ -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"))
|
data/spec/ffi/dup_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
|
|
@@ -24,7 +13,7 @@ describe "Pointer#dup" do
|
|
24
13
|
p2 = p1.dup
|
25
14
|
p1.put_string(0, "deadbeef")
|
26
15
|
|
27
|
-
p2.get_string(0).should
|
16
|
+
p2.get_string(0).should == "test123"
|
28
17
|
end
|
29
18
|
|
30
19
|
it "sliced pointer can be cloned" do
|
@@ -33,8 +22,8 @@ describe "Pointer#dup" do
|
|
33
22
|
p2 = p1[1].dup
|
34
23
|
|
35
24
|
# first char will be excised
|
36
|
-
p2.get_string(0).should
|
37
|
-
p1.get_string(0).should
|
25
|
+
p2.get_string(0).should == "est123"
|
26
|
+
p1.get_string(0).should == "test123"
|
38
27
|
end
|
39
28
|
|
40
29
|
it "sliced pointer when cloned is independent" do
|
@@ -44,7 +33,7 @@ describe "Pointer#dup" do
|
|
44
33
|
|
45
34
|
p1.put_string(0, "deadbeef")
|
46
35
|
# first char will be excised
|
47
|
-
p2.get_string(0).should
|
36
|
+
p2.get_string(0).should == "est123"
|
48
37
|
end
|
49
38
|
end
|
50
39
|
|
@@ -58,8 +47,8 @@ describe "Struct#dup" do
|
|
58
47
|
s1[:i] = 0x12345
|
59
48
|
s2 = s1.dup
|
60
49
|
s1[:i] = 0x98765
|
61
|
-
s2[:i].should
|
62
|
-
s1[:i].should
|
50
|
+
s2[:i].should == 0x12345
|
51
|
+
s1[:i].should == 0x98765
|
63
52
|
end
|
64
53
|
|
65
54
|
end
|
data/spec/ffi/enum_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"))
|
@@ -49,180 +38,180 @@ end
|
|
49
38
|
|
50
39
|
describe "A library with no enum defined" do
|
51
40
|
it "returns nil when asked for an enum" do
|
52
|
-
TestEnum0.enum_type(:foo).should
|
41
|
+
TestEnum0.enum_type(:foo).should == nil
|
53
42
|
end
|
54
43
|
end
|
55
44
|
|
56
45
|
describe "An untagged enum" do
|
57
46
|
it "constants can be used as function parameters and return value" do
|
58
|
-
TestEnum1.test_untagged_enum(:c1).should
|
59
|
-
TestEnum1.test_untagged_enum(:c2).should
|
60
|
-
TestEnum1.test_untagged_enum(:c3).should
|
61
|
-
TestEnum1.test_untagged_enum(:c4).should
|
62
|
-
TestEnum1.test_untagged_enum(:c5).should
|
63
|
-
TestEnum1.test_untagged_enum(:c6).should
|
64
|
-
TestEnum1.test_untagged_enum(:c7).should
|
65
|
-
TestEnum1.test_untagged_enum(:c8).should
|
66
|
-
TestEnum1.test_untagged_enum(:c9).should
|
67
|
-
TestEnum1.test_untagged_enum(:c10).should
|
68
|
-
TestEnum1.test_untagged_enum(:c11).should
|
69
|
-
TestEnum1.test_untagged_enum(:c12).should
|
70
|
-
TestEnum1.test_untagged_enum(:c13).should
|
71
|
-
TestEnum1.test_untagged_enum(:c14).should
|
72
|
-
TestEnum1.test_untagged_enum(:c15).should
|
73
|
-
TestEnum1.test_untagged_enum(:c16).should
|
47
|
+
TestEnum1.test_untagged_enum(:c1).should == 0
|
48
|
+
TestEnum1.test_untagged_enum(:c2).should == 1
|
49
|
+
TestEnum1.test_untagged_enum(:c3).should == 2
|
50
|
+
TestEnum1.test_untagged_enum(:c4).should == 3
|
51
|
+
TestEnum1.test_untagged_enum(:c5).should == 42
|
52
|
+
TestEnum1.test_untagged_enum(:c6).should == 43
|
53
|
+
TestEnum1.test_untagged_enum(:c7).should == 44
|
54
|
+
TestEnum1.test_untagged_enum(:c8).should == 45
|
55
|
+
TestEnum1.test_untagged_enum(:c9).should == 42
|
56
|
+
TestEnum1.test_untagged_enum(:c10).should == 43
|
57
|
+
TestEnum1.test_untagged_enum(:c11).should == 4242
|
58
|
+
TestEnum1.test_untagged_enum(:c12).should == 4243
|
59
|
+
TestEnum1.test_untagged_enum(:c13).should == 42
|
60
|
+
TestEnum1.test_untagged_enum(:c14).should == 4242
|
61
|
+
TestEnum1.test_untagged_enum(:c15).should == 424242
|
62
|
+
TestEnum1.test_untagged_enum(:c16).should == 42424242
|
74
63
|
end
|
75
64
|
end
|
76
65
|
|
77
66
|
describe "A tagged typedef enum" do
|
78
67
|
it "is accessible through its tag" do
|
79
|
-
TestEnum3.enum_type(:enum_type1).should_not
|
80
|
-
TestEnum3.enum_type(:enum_type2).should_not
|
81
|
-
TestEnum3.enum_type(:enum_type3).should_not
|
82
|
-
TestEnum3.enum_type(:enum_type4).should_not
|
68
|
+
TestEnum3.enum_type(:enum_type1).should_not == nil
|
69
|
+
TestEnum3.enum_type(:enum_type2).should_not == nil
|
70
|
+
TestEnum3.enum_type(:enum_type3).should_not == nil
|
71
|
+
TestEnum3.enum_type(:enum_type4).should_not == nil
|
83
72
|
end
|
84
73
|
it "contains enum constants" do
|
85
|
-
TestEnum3.enum_type(:enum_type1).symbols.length.should
|
86
|
-
TestEnum3.enum_type(:enum_type2).symbols.length.should
|
87
|
-
TestEnum3.enum_type(:enum_type3).symbols.length.should
|
88
|
-
TestEnum3.enum_type(:enum_type4).symbols.length.should
|
74
|
+
TestEnum3.enum_type(:enum_type1).symbols.length.should == 4
|
75
|
+
TestEnum3.enum_type(:enum_type2).symbols.length.should == 4
|
76
|
+
TestEnum3.enum_type(:enum_type3).symbols.length.should == 4
|
77
|
+
TestEnum3.enum_type(:enum_type4).symbols.length.should == 4
|
89
78
|
end
|
90
79
|
it "constants can be used as function parameters and return value" do
|
91
|
-
TestEnum3.test_tagged_typedef_enum1(:c1).should
|
92
|
-
TestEnum3.test_tagged_typedef_enum1(:c2).should
|
93
|
-
TestEnum3.test_tagged_typedef_enum1(:c3).should
|
94
|
-
TestEnum3.test_tagged_typedef_enum1(:c4).should
|
95
|
-
TestEnum3.test_tagged_typedef_enum2(:c5).should
|
96
|
-
TestEnum3.test_tagged_typedef_enum2(:c6).should
|
97
|
-
TestEnum3.test_tagged_typedef_enum2(:c7).should
|
98
|
-
TestEnum3.test_tagged_typedef_enum2(:c8).should
|
99
|
-
TestEnum3.test_tagged_typedef_enum3(:c9).should
|
100
|
-
TestEnum3.test_tagged_typedef_enum3(:c10).should
|
101
|
-
TestEnum3.test_tagged_typedef_enum3(:c11).should
|
102
|
-
TestEnum3.test_tagged_typedef_enum3(:c12).should
|
103
|
-
TestEnum3.test_tagged_typedef_enum4(:c13).should
|
104
|
-
TestEnum3.test_tagged_typedef_enum4(:c14).should
|
105
|
-
TestEnum3.test_tagged_typedef_enum4(:c15).should
|
106
|
-
TestEnum3.test_tagged_typedef_enum4(:c16).should
|
80
|
+
TestEnum3.test_tagged_typedef_enum1(:c1).should == :c1
|
81
|
+
TestEnum3.test_tagged_typedef_enum1(:c2).should == :c2
|
82
|
+
TestEnum3.test_tagged_typedef_enum1(:c3).should == :c3
|
83
|
+
TestEnum3.test_tagged_typedef_enum1(:c4).should == :c4
|
84
|
+
TestEnum3.test_tagged_typedef_enum2(:c5).should == :c5
|
85
|
+
TestEnum3.test_tagged_typedef_enum2(:c6).should == :c6
|
86
|
+
TestEnum3.test_tagged_typedef_enum2(:c7).should == :c7
|
87
|
+
TestEnum3.test_tagged_typedef_enum2(:c8).should == :c8
|
88
|
+
TestEnum3.test_tagged_typedef_enum3(:c9).should == :c9
|
89
|
+
TestEnum3.test_tagged_typedef_enum3(:c10).should == :c10
|
90
|
+
TestEnum3.test_tagged_typedef_enum3(:c11).should == :c11
|
91
|
+
TestEnum3.test_tagged_typedef_enum3(:c12).should == :c12
|
92
|
+
TestEnum3.test_tagged_typedef_enum4(:c13).should == :c13
|
93
|
+
TestEnum3.test_tagged_typedef_enum4(:c14).should == :c14
|
94
|
+
TestEnum3.test_tagged_typedef_enum4(:c15).should == :c15
|
95
|
+
TestEnum3.test_tagged_typedef_enum4(:c16).should == :c16
|
107
96
|
end
|
108
97
|
|
109
98
|
it "integers can be used instead of constants" do
|
110
|
-
TestEnum3.test_tagged_typedef_enum1(0).should
|
111
|
-
TestEnum3.test_tagged_typedef_enum1(1).should
|
112
|
-
TestEnum3.test_tagged_typedef_enum1(2).should
|
113
|
-
TestEnum3.test_tagged_typedef_enum1(3).should
|
114
|
-
TestEnum3.test_tagged_typedef_enum2(42).should
|
115
|
-
TestEnum3.test_tagged_typedef_enum2(43).should
|
116
|
-
TestEnum3.test_tagged_typedef_enum2(44).should
|
117
|
-
TestEnum3.test_tagged_typedef_enum2(45).should
|
118
|
-
TestEnum3.test_tagged_typedef_enum3(42).should
|
119
|
-
TestEnum3.test_tagged_typedef_enum3(43).should
|
120
|
-
TestEnum3.test_tagged_typedef_enum3(4242).should
|
121
|
-
TestEnum3.test_tagged_typedef_enum3(4243).should
|
122
|
-
TestEnum3.test_tagged_typedef_enum4(42).should
|
123
|
-
TestEnum3.test_tagged_typedef_enum4(4242).should
|
124
|
-
TestEnum3.test_tagged_typedef_enum4(424242).should
|
125
|
-
TestEnum3.test_tagged_typedef_enum4(42424242).should
|
99
|
+
TestEnum3.test_tagged_typedef_enum1(0).should == :c1
|
100
|
+
TestEnum3.test_tagged_typedef_enum1(1).should == :c2
|
101
|
+
TestEnum3.test_tagged_typedef_enum1(2).should == :c3
|
102
|
+
TestEnum3.test_tagged_typedef_enum1(3).should == :c4
|
103
|
+
TestEnum3.test_tagged_typedef_enum2(42).should == :c5
|
104
|
+
TestEnum3.test_tagged_typedef_enum2(43).should == :c6
|
105
|
+
TestEnum3.test_tagged_typedef_enum2(44).should == :c7
|
106
|
+
TestEnum3.test_tagged_typedef_enum2(45).should == :c8
|
107
|
+
TestEnum3.test_tagged_typedef_enum3(42).should == :c9
|
108
|
+
TestEnum3.test_tagged_typedef_enum3(43).should == :c10
|
109
|
+
TestEnum3.test_tagged_typedef_enum3(4242).should == :c11
|
110
|
+
TestEnum3.test_tagged_typedef_enum3(4243).should == :c12
|
111
|
+
TestEnum3.test_tagged_typedef_enum4(42).should == :c13
|
112
|
+
TestEnum3.test_tagged_typedef_enum4(4242).should == :c14
|
113
|
+
TestEnum3.test_tagged_typedef_enum4(424242).should == :c15
|
114
|
+
TestEnum3.test_tagged_typedef_enum4(42424242).should == :c16
|
126
115
|
end
|
127
116
|
end
|
128
117
|
|
129
118
|
describe "All enums" do
|
130
119
|
it "have autonumbered constants when defined with names only" do
|
131
|
-
TestEnum1.enum_value(:c1).should
|
132
|
-
TestEnum1.enum_value(:c2).should
|
133
|
-
TestEnum1.enum_value(:c3).should
|
134
|
-
TestEnum1.enum_value(:c4).should
|
135
|
-
|
136
|
-
TestEnum3.enum_value(:c1).should
|
137
|
-
TestEnum3.enum_value(:c2).should
|
138
|
-
TestEnum3.enum_value(:c3).should
|
139
|
-
TestEnum3.enum_value(:c4).should
|
120
|
+
TestEnum1.enum_value(:c1).should == 0
|
121
|
+
TestEnum1.enum_value(:c2).should == 1
|
122
|
+
TestEnum1.enum_value(:c3).should == 2
|
123
|
+
TestEnum1.enum_value(:c4).should == 3
|
124
|
+
|
125
|
+
TestEnum3.enum_value(:c1).should == 0
|
126
|
+
TestEnum3.enum_value(:c2).should == 1
|
127
|
+
TestEnum3.enum_value(:c3).should == 2
|
128
|
+
TestEnum3.enum_value(:c4).should == 3
|
140
129
|
end
|
141
130
|
it "can have an explicit first constant and autonumbered subsequent constants" do
|
142
|
-
TestEnum1.enum_value(:c5).should
|
143
|
-
TestEnum1.enum_value(:c6).should
|
144
|
-
TestEnum1.enum_value(:c7).should
|
145
|
-
TestEnum1.enum_value(:c8).should
|
146
|
-
|
147
|
-
TestEnum3.enum_value(:c5).should
|
148
|
-
TestEnum3.enum_value(:c6).should
|
149
|
-
TestEnum3.enum_value(:c7).should
|
150
|
-
TestEnum3.enum_value(:c8).should
|
131
|
+
TestEnum1.enum_value(:c5).should == 42
|
132
|
+
TestEnum1.enum_value(:c6).should == 43
|
133
|
+
TestEnum1.enum_value(:c7).should == 44
|
134
|
+
TestEnum1.enum_value(:c8).should == 45
|
135
|
+
|
136
|
+
TestEnum3.enum_value(:c5).should == 42
|
137
|
+
TestEnum3.enum_value(:c6).should == 43
|
138
|
+
TestEnum3.enum_value(:c7).should == 44
|
139
|
+
TestEnum3.enum_value(:c8).should == 45
|
151
140
|
end
|
152
141
|
it "can have a mix of explicit and autonumbered constants" do
|
153
|
-
TestEnum1.enum_value(:c9).should
|
154
|
-
TestEnum1.enum_value(:c10).should
|
155
|
-
TestEnum1.enum_value(:c11).should
|
156
|
-
TestEnum1.enum_value(:c12).should
|
157
|
-
|
158
|
-
TestEnum3.enum_value(:c9).should
|
159
|
-
TestEnum3.enum_value(:c10).should
|
160
|
-
TestEnum3.enum_value(:c11).should
|
161
|
-
TestEnum3.enum_value(:c12).should
|
142
|
+
TestEnum1.enum_value(:c9).should == 42
|
143
|
+
TestEnum1.enum_value(:c10).should == 43
|
144
|
+
TestEnum1.enum_value(:c11).should == 4242
|
145
|
+
TestEnum1.enum_value(:c12).should == 4243
|
146
|
+
|
147
|
+
TestEnum3.enum_value(:c9).should == 42
|
148
|
+
TestEnum3.enum_value(:c10).should == 43
|
149
|
+
TestEnum3.enum_value(:c11).should == 4242
|
150
|
+
TestEnum3.enum_value(:c12).should == 4243
|
162
151
|
end
|
163
152
|
it "can have all its constants explicitely valued" do
|
164
|
-
TestEnum1.enum_value(:c13).should
|
165
|
-
TestEnum1.enum_value(:c14).should
|
166
|
-
TestEnum1.enum_value(:c15).should
|
167
|
-
TestEnum1.enum_value(:c16).should
|
153
|
+
TestEnum1.enum_value(:c13).should == 42
|
154
|
+
TestEnum1.enum_value(:c14).should == 4242
|
155
|
+
TestEnum1.enum_value(:c15).should == 424242
|
156
|
+
TestEnum1.enum_value(:c16).should == 42424242
|
168
157
|
|
169
|
-
TestEnum3.enum_value(:c13).should
|
170
|
-
TestEnum3.enum_value(:c14).should
|
171
|
-
TestEnum3.enum_value(:c15).should
|
172
|
-
TestEnum3.enum_value(:c16).should
|
158
|
+
TestEnum3.enum_value(:c13).should == 42
|
159
|
+
TestEnum3.enum_value(:c14).should == 4242
|
160
|
+
TestEnum3.enum_value(:c15).should == 424242
|
161
|
+
TestEnum3.enum_value(:c16).should == 42424242
|
173
162
|
end
|
174
163
|
it "return the constant corresponding to a specific value" do
|
175
164
|
enum = TestEnum3.enum_type(:enum_type1)
|
176
|
-
enum[0].should
|
177
|
-
enum[1].should
|
178
|
-
enum[2].should
|
179
|
-
enum[3].should
|
165
|
+
enum[0].should == :c1
|
166
|
+
enum[1].should == :c2
|
167
|
+
enum[2].should == :c3
|
168
|
+
enum[3].should == :c4
|
180
169
|
|
181
170
|
enum = TestEnum3.enum_type(:enum_type2)
|
182
|
-
enum[42].should
|
183
|
-
enum[43].should
|
184
|
-
enum[44].should
|
185
|
-
enum[45].should
|
171
|
+
enum[42].should == :c5
|
172
|
+
enum[43].should == :c6
|
173
|
+
enum[44].should == :c7
|
174
|
+
enum[45].should == :c8
|
186
175
|
|
187
176
|
enum = TestEnum3.enum_type(:enum_type3)
|
188
|
-
enum[42].should
|
189
|
-
enum[43].should
|
190
|
-
enum[4242].should
|
191
|
-
enum[4243].should
|
177
|
+
enum[42].should == :c9
|
178
|
+
enum[43].should == :c10
|
179
|
+
enum[4242].should == :c11
|
180
|
+
enum[4243].should == :c12
|
192
181
|
|
193
182
|
enum = TestEnum3.enum_type(:enum_type4)
|
194
|
-
enum[42].should
|
195
|
-
enum[4242].should
|
196
|
-
enum[424242].should
|
197
|
-
enum[42424242].should
|
183
|
+
enum[42].should == :c13
|
184
|
+
enum[4242].should == :c14
|
185
|
+
enum[424242].should == :c15
|
186
|
+
enum[42424242].should == :c16
|
198
187
|
end
|
199
188
|
it "return nil for values that don't have a symbol" do
|
200
189
|
enum = TestEnum3.enum_type(:enum_type1)
|
201
|
-
enum[-1].should
|
202
|
-
enum[4].should
|
190
|
+
enum[-1].should == nil
|
191
|
+
enum[4].should == nil
|
203
192
|
|
204
193
|
enum = TestEnum3.enum_type(:enum_type2)
|
205
|
-
enum[0].should
|
206
|
-
enum[41].should
|
207
|
-
enum[46].should
|
194
|
+
enum[0].should == nil
|
195
|
+
enum[41].should == nil
|
196
|
+
enum[46].should == nil
|
208
197
|
|
209
198
|
enum = TestEnum3.enum_type(:enum_type3)
|
210
|
-
enum[0].should
|
211
|
-
enum[41].should
|
212
|
-
enum[44].should
|
213
|
-
enum[4241].should
|
214
|
-
enum[4244].should
|
199
|
+
enum[0].should == nil
|
200
|
+
enum[41].should == nil
|
201
|
+
enum[44].should == nil
|
202
|
+
enum[4241].should == nil
|
203
|
+
enum[4244].should == nil
|
215
204
|
|
216
205
|
enum = TestEnum3.enum_type(:enum_type4)
|
217
|
-
enum[0].should
|
218
|
-
enum[41].should
|
219
|
-
enum[43].should
|
220
|
-
enum[4241].should
|
221
|
-
enum[4243].should
|
222
|
-
enum[424241].should
|
223
|
-
enum[424243].should
|
224
|
-
enum[42424241].should
|
225
|
-
enum[42424243].should
|
206
|
+
enum[0].should == nil
|
207
|
+
enum[41].should == nil
|
208
|
+
enum[43].should == nil
|
209
|
+
enum[4241].should == nil
|
210
|
+
enum[4243].should == nil
|
211
|
+
enum[424241].should == nil
|
212
|
+
enum[424243].should == nil
|
213
|
+
enum[42424241].should == nil
|
214
|
+
enum[42424243].should == nil
|
226
215
|
end
|
227
216
|
|
228
217
|
it "duplicate enum keys rejected" do
|
data/spec/ffi/errno_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,6 +13,6 @@ describe "FFI.errno" do
|
|
24
13
|
it "FFI.errno contains errno from last function" do
|
25
14
|
LibTest.setLastError(0)
|
26
15
|
LibTest.setLastError(0x12345678)
|
27
|
-
FFI.errno.should
|
16
|
+
FFI.errno.should == 0x12345678
|
28
17
|
end
|
29
18
|
end
|