gir_ffi 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/README.md +24 -6
- data/lib/ffi-glib/ptr_array.rb +17 -1
- data/lib/ffi-glib/variant.rb +15 -0
- data/lib/ffi-glib.rb +1 -0
- data/lib/ffi-gobject/object.rb +1 -1
- data/lib/ffi-gobject/ruby_closure.rb +1 -1
- data/lib/ffi-gobject/value.rb +13 -3
- data/lib/ffi-gobject.rb +1 -2
- data/lib/ffi-gobject_introspection/i_enum_info.rb +14 -0
- data/lib/ffi-gobject_introspection/lib.rb +2 -0
- data/lib/gir_ffi/arg_helper.rb +2 -0
- data/lib/gir_ffi/argument_builder.rb +22 -21
- data/lib/gir_ffi/base_argument_builder.rb +2 -1
- data/lib/gir_ffi/builder/module.rb +2 -3
- data/lib/gir_ffi/builder/type/enum.rb +18 -1
- data/lib/gir_ffi/builder/type/object.rb +20 -18
- data/lib/gir_ffi/class_base.rb +0 -1
- data/lib/gir_ffi/enum_base.rb +25 -0
- data/lib/gir_ffi/ffi_ext.rb +1 -0
- data/lib/gir_ffi/function_builder.rb +50 -33
- data/lib/gir_ffi/in_out_pointer.rb +0 -5
- data/lib/gir_ffi/in_pointer.rb +7 -5
- data/lib/gir_ffi/info_ext/i_callable_info.rb +4 -0
- data/lib/gir_ffi/info_ext/i_enum_info.rb +13 -0
- data/lib/gir_ffi/info_ext/i_field_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_object_info.rb +11 -0
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +11 -0
- data/lib/gir_ffi/info_ext/i_struct_info.rb +11 -0
- data/lib/gir_ffi/info_ext/i_type_info.rb +10 -19
- data/lib/gir_ffi/info_ext/i_union_info.rb +12 -0
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +0 -2
- data/lib/gir_ffi/info_ext.rb +4 -0
- data/lib/gir_ffi/interface_base.rb +0 -1
- data/lib/gir_ffi/return_value_builder.rb +3 -2
- data/lib/gir_ffi/type_map.rb +3 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi/zero_terminated.rb +36 -3
- data/lib/gir_ffi-base/gir_ffi/library.rb +17 -0
- data/lib/gir_ffi-base/gobject/lib.rb +2 -2
- data/lib/gir_ffi.rb +1 -0
- data/tasks/test.rake +1 -0
- data/test/base_test_helper.rb +22 -2
- data/test/ffi-glib/ruby_closure_test.rb +1 -1
- data/test/ffi-glib/variant_test.rb +10 -0
- data/test/ffi-gobject/value_test.rb +24 -8
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +17 -0
- data/test/gir_ffi/argument_builder_test.rb +66 -24
- data/test/gir_ffi/builder_test.rb +1 -1
- data/test/gir_ffi/function_builder_test.rb +1 -3
- data/test/gir_ffi/in_out_pointer_test.rb +5 -3
- data/test/gir_ffi/in_pointer_test.rb +32 -2
- data/test/gir_ffi/info_ext/i_arg_info_test.rb +2 -2
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +2 -2
- data/test/gir_ffi/info_ext/i_field_info_test.rb +14 -20
- data/test/gir_ffi/info_ext/i_function_info_test.rb +2 -2
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +2 -2
- data/test/gir_ffi/info_ext/i_type_info_test.rb +8 -8
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +2 -2
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +2 -2
- data/test/gir_ffi/return_value_builder_test.rb +18 -1
- data/test/gir_ffi/zero_terminated_test.rb +10 -0
- data/test/gir_ffi_test_helper.rb +0 -19
- data/test/integration/generated_gimarshallingtests_test.rb +291 -99
- data/test/integration/generated_regress_test.rb +138 -14
- data/test/lib/autogen.sh +6 -2
- metadata +14 -2
@@ -86,13 +86,27 @@ describe GirFFI::ArgumentBuilder do
|
|
86
86
|
stub(type_info).flattened_tag { :object }
|
87
87
|
end
|
88
88
|
|
89
|
+
it "has the correct value for #pre" do
|
90
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :object" ]
|
91
|
+
end
|
92
|
+
|
93
|
+
it "has the correct value for #post" do
|
94
|
+
builder.post.must_equal [ "_v2 = Bar::Foo.wrap(_v1.to_value)" ]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "for :struct" do
|
99
|
+
before do
|
100
|
+
stub(type_info).flattened_tag { :struct }
|
101
|
+
end
|
102
|
+
|
89
103
|
describe "when not allocated by the caller" do
|
90
104
|
before do
|
91
105
|
stub(argument_info).caller_allocates? { false }
|
92
106
|
end
|
93
107
|
|
94
108
|
it "has the correct value for #pre" do
|
95
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :
|
109
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :struct" ]
|
96
110
|
end
|
97
111
|
|
98
112
|
it "has the correct value for #post" do
|
@@ -106,7 +120,7 @@ describe GirFFI::ArgumentBuilder do
|
|
106
120
|
end
|
107
121
|
|
108
122
|
it "has the correct value for #pre" do
|
109
|
-
builder.pre.must_equal [ "_v1 = Bar::Foo.
|
123
|
+
builder.pre.must_equal [ "_v1 = Bar::Foo.new" ]
|
110
124
|
end
|
111
125
|
|
112
126
|
it "has the correct value for #post" do
|
@@ -115,32 +129,45 @@ describe GirFFI::ArgumentBuilder do
|
|
115
129
|
end
|
116
130
|
end
|
117
131
|
|
118
|
-
describe "for :
|
132
|
+
describe "for :strv" do
|
119
133
|
before do
|
120
|
-
stub(type_info).flattened_tag { :
|
134
|
+
stub(type_info).flattened_tag { :strv }
|
121
135
|
end
|
122
136
|
|
123
|
-
|
137
|
+
it "has the correct value for #pre" do
|
138
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :strv" ]
|
139
|
+
end
|
140
|
+
|
141
|
+
it "has the correct value for #post" do
|
142
|
+
builder.post.must_equal [ "_v2 = GLib::Strv.wrap(_v1.to_value)" ]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "for :array" do
|
147
|
+
before do
|
148
|
+
stub(type_info).flattened_tag { :array }
|
149
|
+
stub(type_info).element_type { :foo }
|
150
|
+
end
|
151
|
+
|
152
|
+
context "when allocated by the callee" do
|
124
153
|
before do
|
125
154
|
stub(argument_info).caller_allocates? { false }
|
126
155
|
end
|
127
|
-
|
128
156
|
it "has the correct value for #pre" do
|
129
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :
|
157
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :array" ]
|
130
158
|
end
|
131
159
|
|
132
160
|
it "has the correct value for #post" do
|
133
|
-
builder.post.must_equal [ "_v2 =
|
161
|
+
builder.post.must_equal [ "_v2 = GLib::Array.wrap(:foo, _v1.to_value)" ]
|
134
162
|
end
|
135
163
|
end
|
136
164
|
|
137
|
-
|
165
|
+
context "when allocated by the caller" do
|
138
166
|
before do
|
139
167
|
stub(argument_info).caller_allocates? { true }
|
140
168
|
end
|
141
|
-
|
142
169
|
it "has the correct value for #pre" do
|
143
|
-
builder.pre.must_equal [ "_v1 =
|
170
|
+
builder.pre.must_equal [ "_v1 = GLib::Array.new :foo" ]
|
144
171
|
end
|
145
172
|
|
146
173
|
it "has the correct value for #post" do
|
@@ -149,32 +176,32 @@ describe GirFFI::ArgumentBuilder do
|
|
149
176
|
end
|
150
177
|
end
|
151
178
|
|
152
|
-
describe "for :
|
179
|
+
describe "for :ptr_array" do
|
153
180
|
before do
|
154
|
-
stub(type_info).flattened_tag { :
|
181
|
+
stub(type_info).flattened_tag { :ptr_array }
|
182
|
+
stub(type_info).element_type { :foo }
|
155
183
|
end
|
156
184
|
|
157
185
|
it "has the correct value for #pre" do
|
158
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :
|
186
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :ptr_array" ]
|
159
187
|
end
|
160
188
|
|
161
189
|
it "has the correct value for #post" do
|
162
|
-
builder.post.must_equal [ "_v2 = GLib::
|
190
|
+
builder.post.must_equal [ "_v2 = GLib::PtrArray.wrap(:foo, _v1.to_value)" ]
|
163
191
|
end
|
164
192
|
end
|
165
193
|
|
166
|
-
describe "for :
|
194
|
+
describe "for :error" do
|
167
195
|
before do
|
168
|
-
stub(type_info).flattened_tag { :
|
169
|
-
stub(type_info).element_type { :foo }
|
196
|
+
stub(type_info).flattened_tag { :error }
|
170
197
|
end
|
171
198
|
|
172
199
|
it "has the correct value for #pre" do
|
173
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :
|
200
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :error" ]
|
174
201
|
end
|
175
202
|
|
176
203
|
it "has the correct value for #post" do
|
177
|
-
builder.post.must_equal [ "_v2 = GLib::
|
204
|
+
builder.post.must_equal [ "_v2 = GLib::Error.wrap(_v1.to_value)" ]
|
178
205
|
end
|
179
206
|
end
|
180
207
|
|
@@ -331,7 +358,7 @@ describe GirFFI::ArgumentBuilder do
|
|
331
358
|
end
|
332
359
|
|
333
360
|
it "has the correct value for #pre" do
|
334
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from :
|
361
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from :strv, GLib::Strv.from(foo)" ]
|
335
362
|
end
|
336
363
|
|
337
364
|
it "has the correct value for #post" do
|
@@ -339,13 +366,28 @@ describe GirFFI::ArgumentBuilder do
|
|
339
366
|
end
|
340
367
|
end
|
341
368
|
|
369
|
+
describe "for :ptr_array" do
|
370
|
+
before do
|
371
|
+
stub(type_info).flattened_tag { :ptr_array }
|
372
|
+
stub(type_info).element_type { :foo }
|
373
|
+
end
|
374
|
+
|
375
|
+
it "has the correct value for #pre" do
|
376
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from :ptr_array, GLib::PtrArray.from(:foo, foo)" ]
|
377
|
+
end
|
378
|
+
|
379
|
+
it "has the correct value for #post" do
|
380
|
+
builder.post.must_equal [ "_v2 = GLib::PtrArray.wrap(:foo, _v1.to_value)" ]
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
342
384
|
describe "for :utf8" do
|
343
385
|
before do
|
344
386
|
stub(type_info).flattened_tag { :utf8 }
|
345
387
|
end
|
346
388
|
|
347
389
|
it "has the correct value for #pre" do
|
348
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from :
|
390
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from :utf8, GirFFI::InPointer.from(:utf8, foo)" ]
|
349
391
|
end
|
350
392
|
|
351
393
|
it "has the correct value for #post" do
|
@@ -367,7 +409,7 @@ describe GirFFI::ArgumentBuilder do
|
|
367
409
|
it "has the correct value for #pre" do
|
368
410
|
builder.pre.must_equal [
|
369
411
|
"GirFFI::ArgHelper.check_fixed_array_size 3, foo, \"foo\"",
|
370
|
-
"_v1 = GirFFI::InOutPointer.from :
|
412
|
+
"_v1 = GirFFI::InOutPointer.from :c, GLib::SizedArray.from(:bar, 3, foo)"
|
371
413
|
]
|
372
414
|
end
|
373
415
|
|
@@ -387,7 +429,7 @@ describe GirFFI::ArgumentBuilder do
|
|
387
429
|
it "has the correct value for #pre" do
|
388
430
|
# TODO: Perhaps this should include a length check as well.
|
389
431
|
builder.pre.must_equal [
|
390
|
-
"_v1 = GirFFI::InOutPointer.from :
|
432
|
+
"_v1 = GirFFI::InOutPointer.from :c, GLib::SizedArray.from(:bar, -1, foo)"
|
391
433
|
]
|
392
434
|
end
|
393
435
|
|
@@ -77,7 +77,7 @@ describe GirFFI::Builder do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
should "set up struct members with the correct types" do
|
80
|
-
tags = [:int, :int8, :double, Regress::TestEnum]
|
80
|
+
tags = [:int, :int8, :double, Regress::TestEnum::Enum]
|
81
81
|
assert_equal tags.map {|t| FFI.find_type t},
|
82
82
|
Regress::TestStructA::Struct.layout.fields.map {|f| f.type}
|
83
83
|
end
|
@@ -83,7 +83,6 @@ describe GirFFI::FunctionBuilder do
|
|
83
83
|
def self.gvalue_in value
|
84
84
|
_v1 = ::GObject::Value.from(value)
|
85
85
|
DummyLib.gi_marshalling_tests_gvalue_in _v1
|
86
|
-
|
87
86
|
end
|
88
87
|
CODE
|
89
88
|
|
@@ -101,7 +100,6 @@ describe GirFFI::FunctionBuilder do
|
|
101
100
|
len = arr.nil? ? 0 : arr.length
|
102
101
|
_v2 = len
|
103
102
|
DummyLib.regress_test_array_int_null_in _v1, _v2
|
104
|
-
|
105
103
|
end
|
106
104
|
CODE
|
107
105
|
|
@@ -134,7 +132,7 @@ describe GirFFI::FunctionBuilder do
|
|
134
132
|
|
135
133
|
expected = <<-CODE
|
136
134
|
def method_array_inout ints
|
137
|
-
_v1 = GirFFI::InOutPointer.from :
|
135
|
+
_v1 = GirFFI::InOutPointer.from :c, GLib::SizedArray.from(:gint32, -1, ints)
|
138
136
|
length = ints.nil? ? 0 : ints.length
|
139
137
|
_v2 = GirFFI::InOutPointer.from :gint32, length
|
140
138
|
DummyLib.gi_marshalling_tests_object_method_array_inout self, _v1, _v2
|
@@ -22,8 +22,9 @@ describe GirFFI::InOutPointer do
|
|
22
22
|
GirFFI::InOutPointer.from :gboolean, false
|
23
23
|
end
|
24
24
|
|
25
|
-
it "handles :utf8" do
|
26
|
-
GirFFI::
|
25
|
+
it "handles :utf8 pointers" do
|
26
|
+
str_ptr = GirFFI::InPointer.from :utf8, "Hello"
|
27
|
+
GirFFI::InOutPointer.from :utf8, str_ptr
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
@@ -71,7 +72,8 @@ describe GirFFI::InOutPointer do
|
|
71
72
|
|
72
73
|
describe "for :utf8 values" do
|
73
74
|
it "returns a pointer to the held value" do
|
74
|
-
|
75
|
+
str_ptr = GirFFI::InPointer.from :utf8, "Some value"
|
76
|
+
ptr = GirFFI::InOutPointer.from :utf8, str_ptr
|
75
77
|
assert_equal "Some value", ptr.to_value.read_string
|
76
78
|
end
|
77
79
|
end
|
@@ -14,10 +14,21 @@ describe GirFFI::InPointer do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "handles enum types" do
|
17
|
-
e =
|
17
|
+
e = Module.new do
|
18
|
+
self::Enum = FFI::Enum.new [:foo, :bar, :baz]
|
19
|
+
end
|
18
20
|
ptr = GirFFI::InPointer.from_array e, [:bar, :foo, :baz]
|
19
21
|
ptr.read_array_of_int32(3).must_equal [1, 0, 2]
|
20
22
|
end
|
23
|
+
|
24
|
+
it "handles typed pointers" do
|
25
|
+
p1 = GirFFI::InPointer.from :gint32, 42
|
26
|
+
p2 = GirFFI::InPointer.from :gint32, 24
|
27
|
+
|
28
|
+
ptr = GirFFI::InPointer.from_array [:pointer, :uint32], [p1, p2]
|
29
|
+
|
30
|
+
ptr.read_array_of_pointer(2).must_equal [p1, p2]
|
31
|
+
end
|
21
32
|
end
|
22
33
|
|
23
34
|
describe "an instance created with .from_array :gint32" do
|
@@ -75,6 +86,20 @@ describe GirFFI::InPointer do
|
|
75
86
|
end
|
76
87
|
end
|
77
88
|
|
89
|
+
describe "an instance created with .from :guint32" do
|
90
|
+
before do
|
91
|
+
@result = GirFFI::InPointer.from :guint32, 12345
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns a pointer with an address equal to the given value" do
|
95
|
+
assert_equal 12345, @result.address
|
96
|
+
end
|
97
|
+
|
98
|
+
it "is an instance of GirFFI::InPointer" do
|
99
|
+
assert_instance_of GirFFI::InPointer, @result
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
78
103
|
describe "an instance created with .from :filename" do
|
79
104
|
before do
|
80
105
|
@result = GirFFI::InPointer.from :filename, "foo"
|
@@ -97,7 +122,12 @@ describe GirFFI::InPointer do
|
|
97
122
|
end
|
98
123
|
|
99
124
|
it "handles enum types" do
|
100
|
-
e =
|
125
|
+
e = Module.new do
|
126
|
+
self::Enum = FFI::Enum.new [:foo, :bar, :baz]
|
127
|
+
def self.[](val)
|
128
|
+
self::Enum[val]
|
129
|
+
end
|
130
|
+
end
|
101
131
|
ptr = GirFFI::InPointer.from e, :bar
|
102
132
|
ptr.address.must_equal 1
|
103
133
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::InfoExt::IArgInfo do
|
4
|
-
let(:
|
4
|
+
let(:klass) { Class.new do
|
5
5
|
include GirFFI::InfoExt::IArgInfo
|
6
6
|
end }
|
7
|
-
let(:arg_info) {
|
7
|
+
let(:arg_info) { klass.new }
|
8
8
|
|
9
9
|
describe "#cast_signal_argument" do
|
10
10
|
describe "with info for an enum" do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::InfoExt::ICallableInfo do
|
4
|
-
let(:
|
4
|
+
let(:klass) { Class.new do
|
5
5
|
include GirFFI::InfoExt::ICallableInfo
|
6
6
|
end }
|
7
|
-
let(:callable_info) {
|
7
|
+
let(:callable_info) { klass.new }
|
8
8
|
|
9
9
|
describe "#argument_ffi_types" do
|
10
10
|
describe "for a simple callable with several arguments" do
|
@@ -1,37 +1,31 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::InfoExt::IFieldInfo do
|
4
|
+
let(:klass) { Class.new do
|
5
|
+
include GirFFI::InfoExt::IFieldInfo
|
6
|
+
end }
|
7
|
+
let(:field_info) { klass.new }
|
4
8
|
describe "#layout_specification" do
|
5
9
|
it "returns an array of name, typespec and offset" do
|
6
|
-
|
7
|
-
include GirFFI::InfoExt::IFieldInfo
|
8
|
-
end
|
10
|
+
mock(type = Object.new).to_ffitype { :bar }
|
9
11
|
|
10
|
-
mock(
|
12
|
+
mock(field_info).name { "foo" }
|
13
|
+
mock(field_info).field_type { type }
|
14
|
+
mock(field_info).offset { 0 }
|
11
15
|
|
12
|
-
|
13
|
-
mock(field).name { "foo" }
|
14
|
-
mock(field).field_type { type }
|
15
|
-
mock(field).offset { 0 }
|
16
|
-
|
17
|
-
result = field.layout_specification
|
16
|
+
result = field_info.layout_specification
|
18
17
|
|
19
18
|
assert_equal [:foo, :bar, 0], result
|
20
19
|
end
|
21
20
|
|
22
21
|
it "keeps a complex typespec intact" do
|
23
|
-
|
24
|
-
include GirFFI::InfoExt::IFieldInfo
|
25
|
-
end
|
26
|
-
|
27
|
-
mock(type = Object.new).layout_specification_type { [:bar, 2] }
|
22
|
+
mock(type = Object.new).to_ffitype { [:bar, 2] }
|
28
23
|
|
29
|
-
|
30
|
-
mock(
|
31
|
-
mock(
|
32
|
-
mock(field).offset { 0 }
|
24
|
+
mock(field_info).name { "foo" }
|
25
|
+
mock(field_info).field_type { type }
|
26
|
+
mock(field_info).offset { 0 }
|
33
27
|
|
34
|
-
result =
|
28
|
+
result = field_info.layout_specification
|
35
29
|
|
36
30
|
assert_equal [:foo, [:bar, 2], 0], result
|
37
31
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::InfoExt::IFunctionInfo do
|
4
|
-
let(:
|
4
|
+
let(:klass) { Class.new do
|
5
5
|
include GirFFI::InfoExt::ICallableInfo
|
6
6
|
include GirFFI::InfoExt::IFunctionInfo
|
7
7
|
end }
|
8
|
-
let(:function_info) {
|
8
|
+
let(:function_info) { klass.new }
|
9
9
|
|
10
10
|
describe "#argument_ffi_types" do
|
11
11
|
before do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::InfoExt::ISignalInfo do
|
4
|
-
let(:
|
4
|
+
let(:klass) { Class.new do
|
5
5
|
include GirFFI::InfoExt::ISignalInfo
|
6
6
|
end }
|
7
|
-
let(:signal_info) {
|
7
|
+
let(:signal_info) { klass.new }
|
8
8
|
|
9
9
|
describe "#cast_back_signal_arguments" do
|
10
10
|
# TODO: Move to integration tests
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::InfoExt::ITypeInfo do
|
4
|
-
let(:
|
4
|
+
let(:klass) { Class.new do
|
5
5
|
include GirFFI::InfoExt::ITypeInfo
|
6
6
|
end }
|
7
|
-
let(:type_info) {
|
8
|
-
let(:elmtype_info) {
|
9
|
-
let(:keytype_info) {
|
10
|
-
let(:valtype_info) {
|
7
|
+
let(:type_info) { klass.new }
|
8
|
+
let(:elmtype_info) { klass.new }
|
9
|
+
let(:keytype_info) { klass.new }
|
10
|
+
let(:valtype_info) { klass.new }
|
11
11
|
|
12
|
-
describe "#
|
12
|
+
describe "#to_ffitype" do
|
13
13
|
it "returns an array with elements subtype and size for type :array" do
|
14
14
|
mock(type_info).pointer? { false }
|
15
15
|
stub(type_info).tag { :array }
|
16
16
|
mock(type_info).array_fixed_size { 2 }
|
17
17
|
|
18
|
-
mock(elmtype_info).
|
18
|
+
mock(elmtype_info).to_ffitype { :foo }
|
19
19
|
mock(type_info).param_type(0) { elmtype_info }
|
20
20
|
|
21
|
-
result = type_info.
|
21
|
+
result = type_info.to_ffitype
|
22
22
|
assert_equal [:foo, 2], result
|
23
23
|
end
|
24
24
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::InfoExt::SafeConstantName do
|
4
|
-
let(:
|
4
|
+
let(:klass) { Class.new do
|
5
5
|
include GirFFI::InfoExt::SafeConstantName
|
6
6
|
end }
|
7
|
-
let(:info) {
|
7
|
+
let(:info) { klass.new }
|
8
8
|
|
9
9
|
describe "#safe_name" do
|
10
10
|
it "makes names starting with an underscore safe" do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::InfoExt::SafeFunctionName do
|
4
|
-
let(:
|
4
|
+
let(:klass) { Class.new do
|
5
5
|
include GirFFI::InfoExt::SafeFunctionName
|
6
6
|
end }
|
7
|
-
let(:info) {
|
7
|
+
let(:info) { klass.new }
|
8
8
|
|
9
9
|
describe "#safe_name" do
|
10
10
|
it "keeps lower case names lower case" do
|
@@ -179,11 +179,12 @@ describe GirFFI::ReturnValueBuilder do
|
|
179
179
|
describe "for :ptr_array" do
|
180
180
|
before do
|
181
181
|
stub(type_info).flattened_tag { :ptr_array }
|
182
|
+
stub(type_info).element_type { :foo }
|
182
183
|
end
|
183
184
|
|
184
185
|
it "wraps the result in #post" do
|
185
186
|
builder.callarg.must_equal "_v1"
|
186
|
-
builder.post.must_equal [ "_v2 = GLib::PtrArray.wrap(_v1)" ]
|
187
|
+
builder.post.must_equal [ "_v2 = GLib::PtrArray.wrap(:foo, _v1)" ]
|
187
188
|
end
|
188
189
|
|
189
190
|
it "returns the wrapped result" do
|
@@ -260,6 +261,22 @@ describe GirFFI::ReturnValueBuilder do
|
|
260
261
|
end
|
261
262
|
end
|
262
263
|
|
264
|
+
describe "for :error" do
|
265
|
+
before do
|
266
|
+
stub(type_info).flattened_tag { :error }
|
267
|
+
end
|
268
|
+
|
269
|
+
it "wraps the result in #post" do
|
270
|
+
builder.callarg.must_equal "_v1"
|
271
|
+
builder.post.must_equal [ "_v2 = GLib::Error.wrap(_v1)" ]
|
272
|
+
end
|
273
|
+
|
274
|
+
it "returns the wrapped result" do
|
275
|
+
builder.callarg.must_equal "_v1"
|
276
|
+
builder.retval.must_equal "_v2"
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
263
280
|
describe "for :c" do
|
264
281
|
describe "with fixed size" do
|
265
282
|
before do
|
@@ -39,6 +39,16 @@ describe GirFFI::ZeroTerminated do
|
|
39
39
|
flunk
|
40
40
|
end
|
41
41
|
end
|
42
|
+
|
43
|
+
it "works for :int8" do
|
44
|
+
zt = GirFFI::ZeroTerminated.from :int8, [1, 2, 3]
|
45
|
+
arr = []
|
46
|
+
zt.each do |int|
|
47
|
+
arr << int
|
48
|
+
end
|
49
|
+
arr.must_equal [1, 2, 3]
|
50
|
+
end
|
51
|
+
|
42
52
|
end
|
43
53
|
|
44
54
|
it "includes Enumerable" do
|
data/test/gir_ffi_test_helper.rb
CHANGED
@@ -2,25 +2,6 @@ require 'introspection_test_helper'
|
|
2
2
|
|
3
3
|
require 'gir_ffi'
|
4
4
|
|
5
|
-
GObjectIntrospection::IRepository.prepend_search_path File.join(File.dirname(__FILE__), 'lib')
|
6
|
-
module GObjectIntrospection
|
7
|
-
class IRepository
|
8
|
-
def shared_library_with_regress namespace
|
9
|
-
case namespace
|
10
|
-
when "Regress"
|
11
|
-
return File.join(File.dirname(__FILE__), 'lib', 'libregress.so')
|
12
|
-
when "GIMarshallingTests"
|
13
|
-
return File.join(File.dirname(__FILE__), 'lib', 'libgimarshallingtests.so')
|
14
|
-
else
|
15
|
-
return shared_library_without_regress namespace
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
alias shared_library_without_regress shared_library
|
20
|
-
alias shared_library shared_library_with_regress
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
5
|
# Need a dummy module for some tests.
|
25
6
|
module DummyLib
|
26
7
|
end
|