gir_ffi 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +14 -0
- data/TODO.rdoc +23 -5
- data/lib/ffi-glib/array.rb +14 -15
- data/lib/ffi-glib/container_class_methods.rb +0 -1
- data/lib/ffi-glib/hash_table.rb +3 -4
- data/lib/ffi-glib/ptr_array.rb +12 -4
- data/lib/ffi-glib/sized_array.rb +27 -7
- data/lib/ffi-gobject.rb +14 -15
- data/lib/ffi-gobject/closure.rb +1 -1
- data/lib/ffi-gobject/object.rb +40 -15
- data/lib/ffi-gobject/ruby_closure.rb +0 -1
- data/lib/ffi-gobject/value.rb +45 -21
- data/lib/ffi-gobject_introspection/i_arg_info.rb +4 -0
- data/lib/ffi-gobject_introspection/i_base_info.rb +42 -2
- data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
- data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -4
- data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_object_info.rb +2 -0
- data/lib/ffi-gobject_introspection/i_repository.rb +2 -3
- data/lib/ffi-gobject_introspection/i_struct_info.rb +3 -8
- data/lib/ffi-gobject_introspection/lib.rb +3 -0
- data/lib/gir_ffi-base.rb +3 -1
- data/lib/gir_ffi-base/gir_ffi/struct.rb +27 -0
- data/lib/gir_ffi-base/glib/boolean.rb +13 -1
- data/lib/gir_ffi-base/gobject.rb +7 -0
- data/lib/gir_ffi-base/gobject/lib.rb +0 -2
- data/lib/gir_ffi.rb +1 -3
- data/lib/gir_ffi/arg_helper.rb +4 -85
- data/lib/gir_ffi/builder.rb +5 -5
- data/lib/gir_ffi/builder_helper.rb +7 -0
- data/lib/gir_ffi/builders/argument_builder.rb +132 -0
- data/lib/gir_ffi/{base_argument_builder.rb → builders/base_argument_builder.rb} +32 -41
- data/lib/gir_ffi/builders/base_type_builder.rb +47 -0
- data/lib/gir_ffi/builders/callback_builder.rb +38 -0
- data/lib/gir_ffi/builders/constant_builder.rb +18 -0
- data/lib/gir_ffi/builders/enum_builder.rb +62 -0
- data/lib/gir_ffi/builders/error_argument_builder.rb +18 -0
- data/lib/gir_ffi/builders/field_builder.rb +94 -0
- data/lib/gir_ffi/builders/function_builder.rb +123 -0
- data/lib/gir_ffi/builders/interface_builder.rb +29 -0
- data/lib/gir_ffi/builders/mapping_method_builder.rb +88 -0
- data/lib/gir_ffi/builders/module_builder.rb +124 -0
- data/lib/gir_ffi/{null_argument_builder.rb → builders/null_argument_builder.rb} +0 -0
- data/lib/gir_ffi/builders/null_builder.rb +11 -0
- data/lib/gir_ffi/builders/object_builder.rb +123 -0
- data/lib/gir_ffi/{builder/property.rb → builders/property_builder.rb} +0 -0
- data/lib/gir_ffi/builders/registered_type_builder.rb +50 -0
- data/lib/gir_ffi/builders/return_value_builder.rb +68 -0
- data/lib/gir_ffi/builders/signal_builder.rb +91 -0
- data/lib/gir_ffi/builders/struct_builder.rb +35 -0
- data/lib/gir_ffi/builders/type_builder.rb +40 -0
- data/lib/gir_ffi/builders/unintrospectable_builder.rb +35 -0
- data/lib/gir_ffi/builders/union_builder.rb +34 -0
- data/lib/gir_ffi/builders/user_defined_builder.rb +103 -0
- data/lib/gir_ffi/builders/with_layout.rb +55 -0
- data/lib/gir_ffi/builders/with_methods.rb +44 -0
- data/lib/gir_ffi/callback_base.rb +31 -0
- data/lib/gir_ffi/class_base.rb +16 -10
- data/lib/gir_ffi/enum_base.rb +8 -4
- data/lib/gir_ffi/ffi_ext/pointer.rb +19 -2
- data/lib/gir_ffi/in_out_pointer.rb +38 -39
- data/lib/gir_ffi/in_pointer.rb +33 -18
- data/lib/gir_ffi/info_ext.rb +0 -4
- data/lib/gir_ffi/info_ext/i_arg_info.rb +0 -18
- data/lib/gir_ffi/info_ext/i_callable_info.rb +2 -1
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +6 -8
- data/lib/gir_ffi/info_ext/i_signal_info.rb +6 -21
- data/lib/gir_ffi/info_ext/i_type_info.rb +54 -29
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -1
- data/lib/gir_ffi/interface_base.rb +1 -1
- data/lib/gir_ffi/module_base.rb +5 -1
- data/lib/gir_ffi/object_base.rb +5 -1
- data/lib/gir_ffi/setter_argument_info.rb +4 -0
- data/lib/gir_ffi/signal_base.rb +21 -0
- data/lib/gir_ffi/struct_base.rb +24 -0
- data/lib/gir_ffi/type_base.rb +11 -0
- data/lib/gir_ffi/type_map.rb +4 -2
- data/lib/gir_ffi/union_base.rb +24 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/tasks/test.rake +73 -7
- data/test/base_test_helper.rb +3 -19
- data/test/ffi-glib/array_test.rb +6 -0
- data/test/ffi-glib/ptr_array_test.rb +13 -0
- data/test/ffi-glib/ruby_closure_test.rb +7 -7
- data/test/ffi-glib/sized_array_test.rb +2 -2
- data/test/ffi-gobject/gobject_test.rb +3 -12
- data/test/ffi-gobject/object_test.rb +33 -2
- data/test/ffi-gobject/value_test.rb +114 -1
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +2 -2
- data/test/ffi-gobject_introspection/i_object_info_test.rb +3 -3
- data/test/ffi-gobject_introspection/i_repository_test.rb +26 -21
- data/test/ffi-gobject_test.rb +14 -14
- data/test/gir_ffi-base/glib/boolean_test.rb +6 -0
- data/test/gir_ffi/arg_helper_test.rb +2 -122
- data/test/gir_ffi/builder_test.rb +67 -204
- data/test/gir_ffi/{argument_builder_test.rb → builders/argument_builder_test.rb} +230 -108
- data/test/gir_ffi/builders/base_argument_builder_test.rb +5 -0
- data/test/gir_ffi/builders/callback_builder_test.rb +50 -0
- data/test/gir_ffi/builders/constant_builder_test.rb +4 -0
- data/test/gir_ffi/{builder/type/enum_test.rb → builders/enum_builder_test.rb} +2 -3
- data/test/gir_ffi/builders/field_builder_test.rb +94 -0
- data/test/gir_ffi/{function_builder_test.rb → builders/function_builder_test.rb} +43 -24
- data/test/gir_ffi/{builder/type/interface_test.rb → builders/interface_builder_test.rb} +2 -2
- data/test/gir_ffi/{builder/module_test.rb → builders/module_builder_test.rb} +12 -13
- data/test/gir_ffi/{builder/type/object_test.rb → builders/object_builder_test.rb} +9 -9
- data/test/gir_ffi/{return_value_builder_test.rb → builders/return_value_builder_test.rb} +94 -58
- data/test/gir_ffi/builders/signal_builder_test.rb +62 -0
- data/test/gir_ffi/{builder/type/struct_test.rb → builders/struct_builder_test.rb} +36 -19
- data/test/gir_ffi/{builder/type/unintrospectable_test.rb → builders/unintrospectable_builder_test.rb} +3 -3
- data/test/gir_ffi/builders/union_builder_test.rb +29 -0
- data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb} +2 -2
- data/test/gir_ffi/callback_base_test.rb +11 -0
- data/test/gir_ffi/class_base_test.rb +22 -22
- data/test/gir_ffi/ffi_ext/pointer_test.rb +18 -0
- data/test/gir_ffi/in_out_pointer_test.rb +0 -7
- data/test/gir_ffi/in_pointer_test.rb +27 -3
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +16 -44
- data/test/gir_ffi/info_ext/i_type_info_test.rb +315 -74
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +6 -0
- data/test/gir_ffi/interface_base_test.rb +3 -5
- data/test/gir_ffi/object_base_test.rb +10 -6
- data/test/gir_ffi/type_map_test.rb +2 -2
- data/test/gir_ffi/unintrospectable_type_info_test.rb +2 -2
- data/test/gir_ffi_test_helper.rb +12 -4
- data/test/integration/generated_gimarshallingtests_test.rb +436 -76
- data/test/integration/generated_gio_test.rb +5 -11
- data/test/integration/generated_gobject_test.rb +8 -0
- data/test/integration/generated_regress_test.rb +755 -309
- data/test/integration/generated_secret_test.rb +2 -1
- metadata +73 -72
- data/lib/ffi-gobject/ruby_style.rb +0 -23
- data/lib/gir_ffi/argument_builder.rb +0 -154
- data/lib/gir_ffi/builder/field.rb +0 -60
- data/lib/gir_ffi/builder/module.rb +0 -127
- data/lib/gir_ffi/builder/type.rb +0 -39
- data/lib/gir_ffi/builder/type/base.rb +0 -48
- data/lib/gir_ffi/builder/type/callback.rb +0 -30
- data/lib/gir_ffi/builder/type/constant.rb +0 -22
- data/lib/gir_ffi/builder/type/enum.rb +0 -66
- data/lib/gir_ffi/builder/type/interface.rb +0 -33
- data/lib/gir_ffi/builder/type/object.rb +0 -134
- data/lib/gir_ffi/builder/type/registered_type.rb +0 -62
- data/lib/gir_ffi/builder/type/struct.rb +0 -34
- data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -39
- data/lib/gir_ffi/builder/type/union.rb +0 -34
- data/lib/gir_ffi/builder/type/user_defined.rb +0 -107
- data/lib/gir_ffi/builder/type/with_layout.rb +0 -62
- data/lib/gir_ffi/builder/type/with_methods.rb +0 -64
- data/lib/gir_ffi/callback.rb +0 -72
- data/lib/gir_ffi/callback_helper.rb +0 -11
- data/lib/gir_ffi/error_argument_builder.rb +0 -17
- data/lib/gir_ffi/function_builder.rb +0 -112
- data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_object_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_struct_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_union_info.rb +0 -12
- data/lib/gir_ffi/return_value_builder.rb +0 -81
- data/test/ffi-gobject/ruby_style_test.rb +0 -38
- data/test/gir_ffi/base_argument_builder_test.rb +0 -13
- data/test/gir_ffi/builder/type/callback_test.rb +0 -6
- data/test/gir_ffi/builder/type/constant_test.rb +0 -4
- data/test/gir_ffi/builder/type/union_test.rb +0 -12
- data/test/gir_ffi/callback_helper_test.rb +0 -10
- data/test/gir_ffi/callback_test.rb +0 -49
- data/test/gir_ffi/info_ext/i_arg_info_test.rb +0 -39
- data/test/gir_ffi/info_ext/i_object_info_test.rb +0 -14
@@ -1,21 +1,26 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
|
-
describe GirFFI::ReturnValueBuilder do
|
3
|
+
describe GirFFI::Builders::ReturnValueBuilder do
|
4
4
|
let(:type_info) { Object.new }
|
5
5
|
let(:var_gen) { GirFFI::VariableNameGenerator.new }
|
6
|
-
let(:for_constructor) {
|
7
|
-
let(:
|
6
|
+
let(:for_constructor) { false }
|
7
|
+
let(:skip) { false }
|
8
|
+
let(:builder) { GirFFI::Builders::ReturnValueBuilder.new(var_gen,
|
8
9
|
type_info,
|
9
|
-
for_constructor
|
10
|
+
for_constructor,
|
11
|
+
skip) }
|
12
|
+
let(:conversion_arguments) { [] }
|
13
|
+
let(:argument_class_name) { flattened_tag }
|
14
|
+
let(:flattened_tag) { nil }
|
10
15
|
|
11
16
|
before do
|
12
|
-
stub(type_info).
|
17
|
+
stub(type_info).argument_class_name { argument_class_name }
|
18
|
+
stub(type_info).extra_conversion_arguments { conversion_arguments }
|
19
|
+
stub(type_info).flattened_tag { flattened_tag }
|
13
20
|
end
|
14
21
|
|
15
22
|
describe "for :gint32" do
|
16
|
-
|
17
|
-
stub(type_info).flattened_tag { :gint32 }
|
18
|
-
end
|
23
|
+
let(:flattened_tag) { :gint32 }
|
19
24
|
|
20
25
|
it "has no statements in #post" do
|
21
26
|
builder.post.must_equal []
|
@@ -28,9 +33,8 @@ describe GirFFI::ReturnValueBuilder do
|
|
28
33
|
end
|
29
34
|
|
30
35
|
describe "for :struct" do
|
31
|
-
|
32
|
-
|
33
|
-
end
|
36
|
+
let(:argument_class_name) { 'Bar::Foo' }
|
37
|
+
let(:flattened_tag) { :struct }
|
34
38
|
|
35
39
|
it "wraps the result in #post" do
|
36
40
|
builder.callarg.must_equal "_v1"
|
@@ -44,9 +48,8 @@ describe GirFFI::ReturnValueBuilder do
|
|
44
48
|
end
|
45
49
|
|
46
50
|
describe "for :union" do
|
47
|
-
|
48
|
-
|
49
|
-
end
|
51
|
+
let(:argument_class_name) { 'Bar::Foo' }
|
52
|
+
let(:flattened_tag) { :union }
|
50
53
|
|
51
54
|
it "wraps the result in #post" do
|
52
55
|
builder.callarg.must_equal "_v1"
|
@@ -60,9 +63,8 @@ describe GirFFI::ReturnValueBuilder do
|
|
60
63
|
end
|
61
64
|
|
62
65
|
describe "for :interface" do
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
+
let(:argument_class_name) { 'Bar::Foo' }
|
67
|
+
let(:flattened_tag) { :interface }
|
66
68
|
|
67
69
|
describe "when the method is not a constructor" do
|
68
70
|
let(:for_constructor) { false }
|
@@ -94,9 +96,8 @@ describe GirFFI::ReturnValueBuilder do
|
|
94
96
|
end
|
95
97
|
|
96
98
|
describe "for :object" do
|
97
|
-
|
98
|
-
|
99
|
-
end
|
99
|
+
let(:argument_class_name) { 'Bar::Foo' }
|
100
|
+
let(:flattened_tag) { :object }
|
100
101
|
|
101
102
|
describe "when the method is not a constructor" do
|
102
103
|
let(:for_constructor) { false }
|
@@ -128,9 +129,8 @@ describe GirFFI::ReturnValueBuilder do
|
|
128
129
|
end
|
129
130
|
|
130
131
|
describe "for :strv" do
|
131
|
-
|
132
|
-
|
133
|
-
end
|
132
|
+
let(:argument_class_name) { 'GLib::Strv' }
|
133
|
+
let(:flattened_tag) { :strv }
|
134
134
|
|
135
135
|
it "wraps the result in #post" do
|
136
136
|
builder.callarg.must_equal "_v1"
|
@@ -144,10 +144,9 @@ describe GirFFI::ReturnValueBuilder do
|
|
144
144
|
end
|
145
145
|
|
146
146
|
describe "for :zero_terminated" do
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
end
|
147
|
+
let(:argument_class_name) { 'GirFFI::ZeroTerminated' }
|
148
|
+
let(:conversion_arguments) { [:foo] }
|
149
|
+
let(:flattened_tag) { :zero_terminated }
|
151
150
|
|
152
151
|
it "wraps the result in #post" do
|
153
152
|
builder.callarg.must_equal "_v1"
|
@@ -161,9 +160,8 @@ describe GirFFI::ReturnValueBuilder do
|
|
161
160
|
end
|
162
161
|
|
163
162
|
describe "for :byte_array" do
|
164
|
-
|
165
|
-
|
166
|
-
end
|
163
|
+
let(:argument_class_name) { 'GLib::ByteArray' }
|
164
|
+
let(:flattened_tag) { :byte_array }
|
167
165
|
|
168
166
|
it "wraps the result in #post" do
|
169
167
|
builder.callarg.must_equal "_v1"
|
@@ -177,10 +175,9 @@ describe GirFFI::ReturnValueBuilder do
|
|
177
175
|
end
|
178
176
|
|
179
177
|
describe "for :ptr_array" do
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
end
|
178
|
+
let(:argument_class_name) { 'GLib::PtrArray' }
|
179
|
+
let(:conversion_arguments) { [:foo] }
|
180
|
+
let(:flattened_tag) { :ptr_array }
|
184
181
|
|
185
182
|
it "wraps the result in #post" do
|
186
183
|
builder.callarg.must_equal "_v1"
|
@@ -194,10 +191,9 @@ describe GirFFI::ReturnValueBuilder do
|
|
194
191
|
end
|
195
192
|
|
196
193
|
describe "for :glist" do
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
end
|
194
|
+
let(:argument_class_name) { 'GLib::List' }
|
195
|
+
let(:conversion_arguments) { [:foo] }
|
196
|
+
let(:flattened_tag) { :glist }
|
201
197
|
|
202
198
|
it "wraps the result in #post" do
|
203
199
|
builder.callarg.must_equal "_v1"
|
@@ -211,10 +207,9 @@ describe GirFFI::ReturnValueBuilder do
|
|
211
207
|
end
|
212
208
|
|
213
209
|
describe "for :gslist" do
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
end
|
210
|
+
let(:argument_class_name) { 'GLib::SList' }
|
211
|
+
let(:conversion_arguments) { [:foo] }
|
212
|
+
let(:flattened_tag) { :gslist }
|
218
213
|
|
219
214
|
it "wraps the result in #post" do
|
220
215
|
builder.callarg.must_equal "_v1"
|
@@ -228,10 +223,9 @@ describe GirFFI::ReturnValueBuilder do
|
|
228
223
|
end
|
229
224
|
|
230
225
|
describe "for :ghash" do
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
end
|
226
|
+
let(:argument_class_name) { 'GLib::HashTable' }
|
227
|
+
let(:conversion_arguments) { [[:foo, :bar]] }
|
228
|
+
let(:flattened_tag) { :ghash }
|
235
229
|
|
236
230
|
it "wraps the result in #post" do
|
237
231
|
builder.callarg.must_equal "_v1"
|
@@ -245,10 +239,9 @@ describe GirFFI::ReturnValueBuilder do
|
|
245
239
|
end
|
246
240
|
|
247
241
|
describe "for :array" do
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
end
|
242
|
+
let(:argument_class_name) { 'GLib::Array' }
|
243
|
+
let(:conversion_arguments) { [:foo] }
|
244
|
+
let(:flattened_tag) { :array }
|
252
245
|
|
253
246
|
it "wraps the result in #post" do
|
254
247
|
builder.callarg.must_equal "_v1"
|
@@ -262,9 +255,8 @@ describe GirFFI::ReturnValueBuilder do
|
|
262
255
|
end
|
263
256
|
|
264
257
|
describe "for :error" do
|
265
|
-
|
266
|
-
|
267
|
-
end
|
258
|
+
let(:argument_class_name) { 'GLib::Error' }
|
259
|
+
let(:flattened_tag) { :error }
|
268
260
|
|
269
261
|
it "wraps the result in #post" do
|
270
262
|
builder.callarg.must_equal "_v1"
|
@@ -278,10 +270,12 @@ describe GirFFI::ReturnValueBuilder do
|
|
278
270
|
end
|
279
271
|
|
280
272
|
describe "for :c" do
|
273
|
+
let(:argument_class_name) { 'GLib::SizedArray' }
|
274
|
+
|
281
275
|
describe "with fixed size" do
|
282
276
|
before do
|
283
277
|
stub(type_info).flattened_tag { :c }
|
284
|
-
stub(type_info).
|
278
|
+
stub(type_info).subtype_tag_or_class { :foo }
|
285
279
|
stub(type_info).array_fixed_size { 3 }
|
286
280
|
end
|
287
281
|
|
@@ -298,9 +292,10 @@ describe GirFFI::ReturnValueBuilder do
|
|
298
292
|
|
299
293
|
describe "with separate size parameter" do
|
300
294
|
let(:length_argument) { Object.new }
|
295
|
+
|
301
296
|
before do
|
302
297
|
stub(type_info).flattened_tag { :c }
|
303
|
-
stub(type_info).
|
298
|
+
stub(type_info).subtype_tag_or_class { :foo }
|
304
299
|
stub(type_info).array_fixed_size { -1 }
|
305
300
|
|
306
301
|
stub(length_argument).retname { "bar" }
|
@@ -326,7 +321,7 @@ describe GirFFI::ReturnValueBuilder do
|
|
326
321
|
|
327
322
|
it "converts the result in #post" do
|
328
323
|
builder.callarg.must_equal "_v1"
|
329
|
-
builder.post.must_equal [ "_v2 =
|
324
|
+
builder.post.must_equal [ "_v2 = _v1.to_utf8" ]
|
330
325
|
end
|
331
326
|
|
332
327
|
it "returns the converted result" do
|
@@ -361,8 +356,49 @@ describe GirFFI::ReturnValueBuilder do
|
|
361
356
|
builder.post.must_equal []
|
362
357
|
end
|
363
358
|
|
364
|
-
it "
|
365
|
-
builder.
|
359
|
+
it "marks itself as irrelevant" do
|
360
|
+
builder.is_relevant?.must_equal false
|
361
|
+
end
|
362
|
+
|
363
|
+
it "returns nothing" do
|
364
|
+
builder.retval.must_be_nil
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
describe "for a closure argument" do
|
369
|
+
let(:tp_info) {
|
370
|
+
get_introspection_data("Regress", "TestCallbackUserData").args[0].argument_type }
|
371
|
+
let(:builder) { GirFFI::Builders::ReturnValueBuilder.new(var_gen, tp_info) }
|
372
|
+
|
373
|
+
before do
|
374
|
+
builder.is_closure = true
|
375
|
+
end
|
376
|
+
|
377
|
+
it "fetches the stored object in #post" do
|
378
|
+
builder.callarg.must_equal "_v1"
|
379
|
+
builder.post.must_equal [ "_v2 = GirFFI::ArgHelper::OBJECT_STORE[_v1.address]" ]
|
380
|
+
end
|
381
|
+
|
382
|
+
it "returns the stored object" do
|
383
|
+
builder.callarg.must_equal "_v1"
|
384
|
+
builder.retval.must_equal "_v2"
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
describe "for a skipped return value" do
|
389
|
+
let(:skip) { true }
|
390
|
+
|
391
|
+
before do
|
392
|
+
stub(type_info).flattened_tag { :uint32 }
|
393
|
+
stub(type_info).pointer? { false }
|
394
|
+
end
|
395
|
+
|
396
|
+
it "has no statements in #post" do
|
397
|
+
builder.post.must_equal []
|
398
|
+
end
|
399
|
+
|
400
|
+
it "marks itself as irrelevant" do
|
401
|
+
builder.is_relevant?.must_equal false
|
366
402
|
end
|
367
403
|
|
368
404
|
it "returns nothing" do
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'gir_ffi_test_helper'
|
2
|
+
|
3
|
+
describe GirFFI::Builders::SignalBuilder do
|
4
|
+
let(:builder) { GirFFI::Builders::SignalBuilder.new signal_info }
|
5
|
+
|
6
|
+
describe "#mapping_method_definition" do
|
7
|
+
describe "for a signal with no arguments or return value" do
|
8
|
+
let(:signal_info) {
|
9
|
+
get_signal_introspection_data "Regress", "TestObj", "test" }
|
10
|
+
|
11
|
+
it "returns a valid mapping method including receiver and user data" do
|
12
|
+
expected = <<-CODE.reset_indentation
|
13
|
+
def self.call_with_argument_mapping(_proc, _v1, _v2)
|
14
|
+
_v3 = ::Regress::TestObj.wrap(_v1)
|
15
|
+
_v4 = GirFFI::ArgHelper::OBJECT_STORE[_v2.address]
|
16
|
+
_proc.call(_v3, _v4)
|
17
|
+
end
|
18
|
+
CODE
|
19
|
+
|
20
|
+
builder.mapping_method_definition.must_equal expected
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "for a signal with an argument and a return value" do
|
25
|
+
let(:signal_info) {
|
26
|
+
get_signal_introspection_data "Regress", "TestObj", "sig-with-int64-prop" }
|
27
|
+
|
28
|
+
it "returns a valid mapping method" do
|
29
|
+
skip unless signal_info
|
30
|
+
|
31
|
+
expected = <<-CODE.reset_indentation
|
32
|
+
def self.call_with_argument_mapping(_proc, _v1, _v2, _v3)
|
33
|
+
_v4 = ::Regress::TestObj.wrap(_v1)
|
34
|
+
_v5 = GirFFI::ArgHelper::OBJECT_STORE[_v3.address]
|
35
|
+
_v6 = _proc.call(_v4, _v2, _v5)
|
36
|
+
return _v6
|
37
|
+
end
|
38
|
+
CODE
|
39
|
+
|
40
|
+
builder.mapping_method_definition.must_equal expected
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "for a signal with an enum argument" do
|
45
|
+
let(:signal_info) {
|
46
|
+
get_signal_introspection_data "Gio", "MountOperation", "reply" }
|
47
|
+
|
48
|
+
it "returns a valid mapping method" do
|
49
|
+
expected = <<-CODE.reset_indentation
|
50
|
+
def self.call_with_argument_mapping(_proc, _v1, _v2, _v3)
|
51
|
+
_v4 = ::Gio::MountOperation.wrap(_v1)
|
52
|
+
_v5 = ::Gio::MountOperationResult[_v2]
|
53
|
+
_v6 = GirFFI::ArgHelper::OBJECT_STORE[_v3.address]
|
54
|
+
_proc.call(_v4, _v5, _v6)
|
55
|
+
end
|
56
|
+
CODE
|
57
|
+
|
58
|
+
builder.mapping_method_definition.must_equal expected
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -1,17 +1,38 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
describe
|
3
|
+
describe GirFFI::Builders::StructBuilder do
|
4
|
+
describe "#layout_specification" do
|
5
|
+
it "returns the correct layout for Regress::TestStructA" do
|
6
|
+
info = get_introspection_data 'Regress', 'TestStructA'
|
7
|
+
builder = GirFFI::Builders::StructBuilder.new info
|
8
|
+
builder.layout_specification.must_equal [:some_int, :int32, 0,
|
9
|
+
:some_int8, :int8, 4,
|
10
|
+
:some_double, :double, 8,
|
11
|
+
:some_enum, Regress::TestEnum::Enum, 16]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
describe "for a struct with a simple layout" do
|
6
16
|
before do
|
17
|
+
module Foo
|
18
|
+
class Bar
|
19
|
+
class Struct
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
module Lib
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
7
27
|
@field = Object.new
|
8
28
|
|
9
29
|
@struct = Object.new
|
10
30
|
stub(@struct).safe_name { 'Bar' }
|
11
31
|
stub(@struct).namespace { 'Foo' }
|
32
|
+
stub(@struct).safe_namespace { 'Foo' }
|
12
33
|
stub(@struct).fields { [ @field ] }
|
13
34
|
|
14
|
-
@builder = GirFFI::
|
35
|
+
@builder = GirFFI::Builders::StructBuilder.new @struct
|
15
36
|
end
|
16
37
|
|
17
38
|
it "creates the correct layout specification" do
|
@@ -26,30 +47,26 @@ describe GirFFI::Builder::Type::Struct do
|
|
26
47
|
stub(type = Object.new).pointer? { false }
|
27
48
|
stub(type).tag { :gint32 }
|
28
49
|
stub(type).flattened_tag { :gint32 }
|
50
|
+
stub(type).tag_or_class { :gint32 }
|
51
|
+
stub(type).extra_conversion_arguments { [] }
|
29
52
|
|
30
53
|
stub(@field).field_type { type }
|
31
54
|
stub(@field).name { "bar" }
|
32
55
|
stub(@field).writable? { true }
|
56
|
+
stub(@field).offset { 4 }
|
57
|
+
stub(@field).container { @struct }
|
33
58
|
|
34
|
-
stub(@struct).
|
35
|
-
|
36
|
-
m = Module.new { module Lib; end }
|
37
|
-
stub(GirFFI::Builder).build_module('Foo') { m }
|
59
|
+
stub(@struct).find_instance_method { }
|
38
60
|
|
39
|
-
|
40
|
-
c::Struct = Class.new
|
61
|
+
stub(GirFFI::Builder).build_module('Foo') { Foo }
|
41
62
|
|
42
|
-
refute
|
43
|
-
refute
|
63
|
+
refute Foo::Bar.method_defined?(:bar)
|
64
|
+
refute Foo::Bar.method_defined?(:bar=)
|
44
65
|
|
45
|
-
@builder.instance_eval {
|
46
|
-
@klass = c
|
47
|
-
@structklass = c::Struct
|
48
|
-
}
|
49
66
|
@builder.send :setup_field_accessors
|
50
67
|
|
51
|
-
assert
|
52
|
-
assert
|
68
|
+
assert Foo::Bar.method_defined?(:bar)
|
69
|
+
assert Foo::Bar.method_defined?(:bar=)
|
53
70
|
end
|
54
71
|
end
|
55
72
|
|
@@ -62,7 +79,7 @@ describe GirFFI::Builder::Type::Struct do
|
|
62
79
|
stub(struct).safe_name { 'Bar' }
|
63
80
|
stub(struct).namespace { 'Foo' }
|
64
81
|
|
65
|
-
builder = GirFFI::
|
82
|
+
builder = GirFFI::Builders::StructBuilder.new struct
|
66
83
|
spec = builder.send :layout_specification
|
67
84
|
assert_equal [:bar, :foo, 0, :baz, [:qux, 2], 0], spec
|
68
85
|
end
|
@@ -79,7 +96,7 @@ describe GirFFI::Builder::Type::Struct do
|
|
79
96
|
stub(info).safe_name { 'Bar' }
|
80
97
|
stub(info).namespace { 'Foo' }
|
81
98
|
|
82
|
-
@classbuilder = GirFFI::
|
99
|
+
@classbuilder = GirFFI::Builders::ObjectBuilder.new info
|
83
100
|
|
84
101
|
spec = @classbuilder.send :layout_specification
|
85
102
|
assert_equal [:parent, GObject::Object::Struct, 0], spec
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
2
|
|
3
|
-
describe GirFFI::
|
3
|
+
describe GirFFI::Builders::UnintrospectableBuilder do
|
4
4
|
describe "building the GLocalFile type" do
|
5
5
|
before do
|
6
6
|
# Ensure existence of GLocalFile type
|
@@ -13,7 +13,7 @@ describe GirFFI::Builder::Type::Unintrospectable do
|
|
13
13
|
|
14
14
|
@gtype = GObject.type_from_name 'GLocalFile'
|
15
15
|
@info = GirFFI::UnintrospectableTypeInfo.new(@gtype)
|
16
|
-
@bldr = GirFFI::
|
16
|
+
@bldr = GirFFI::Builders::UnintrospectableBuilder.new(@info)
|
17
17
|
@klass = @bldr.build_class
|
18
18
|
end
|
19
19
|
|
@@ -30,7 +30,7 @@ describe GirFFI::Builder::Type::Unintrospectable do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "returns the same class when built again" do
|
33
|
-
other_bldr = GirFFI::
|
33
|
+
other_bldr = GirFFI::Builders::UnintrospectableBuilder.new(@info)
|
34
34
|
other_klass = other_bldr.build_class
|
35
35
|
|
36
36
|
assert_equal @klass, other_klass
|