gir_ffi 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/ffi-glib/array.rb +2 -3
- data/lib/ffi-glib/container_class_methods.rb +3 -4
- data/lib/ffi-glib/hash_table.rb +7 -3
- data/lib/ffi-glib/list_methods.rb +1 -1
- data/lib/ffi-glib/sized_array.rb +66 -0
- data/lib/ffi-glib/strv.rb +1 -1
- data/lib/ffi-glib.rb +5 -4
- data/lib/ffi-gobject/object.rb +2 -3
- data/lib/ffi-gobject/ruby_closure.rb +3 -2
- data/lib/ffi-gobject/value.rb +26 -14
- data/lib/ffi-gobject.rb +8 -5
- data/lib/ffi-gobject_introspection/g_error.rb +1 -0
- data/lib/ffi-gobject_introspection/i_base_info.rb +3 -2
- data/lib/ffi-gobject_introspection/i_union_info.rb +21 -8
- data/lib/ffi-gobject_introspection/lib.rb +1 -0
- data/lib/gir_ffi/argument_builder.rb +8 -20
- data/lib/gir_ffi/base_argument_builder.rb +13 -30
- data/lib/gir_ffi/builder/module.rb +3 -9
- data/lib/gir_ffi/builder/type/base.rb +2 -0
- data/lib/gir_ffi/builder/type/callback.rb +2 -2
- data/lib/gir_ffi/builder/type/enum.rb +1 -0
- data/lib/gir_ffi/builder/type/object.rb +13 -3
- data/lib/gir_ffi/builder/type/registered_type.rb +1 -1
- data/lib/gir_ffi/builder/type/struct.rb +18 -3
- data/lib/gir_ffi/builder/type/unintrospectable.rb +5 -45
- data/lib/gir_ffi/builder/type/user_defined.rb +3 -15
- data/lib/gir_ffi/builder/type.rb +5 -5
- data/lib/gir_ffi/builder.rb +5 -80
- data/lib/gir_ffi/callback.rb +65 -2
- data/lib/gir_ffi/callback_helper.rb +0 -56
- data/lib/gir_ffi/class_base.rb +2 -2
- data/lib/gir_ffi/in_out_pointer.rb +7 -28
- data/lib/gir_ffi/in_pointer.rb +12 -19
- data/lib/gir_ffi/info_ext/i_arg_info.rb +5 -0
- data/lib/gir_ffi/info_ext/i_callable_info.rb +16 -0
- data/lib/gir_ffi/info_ext/i_function_info.rb +15 -0
- data/lib/gir_ffi/info_ext/i_signal_info.rb +17 -10
- data/lib/gir_ffi/info_ext/i_type_info.rb +63 -39
- data/lib/gir_ffi/info_ext.rb +5 -3
- data/lib/gir_ffi/null_argument_builder.rb +1 -1
- data/lib/gir_ffi/return_value_builder.rb +24 -16
- data/lib/gir_ffi/unintrospectable_type_info.rb +41 -0
- data/lib/gir_ffi/user_defined_property_info.rb +15 -0
- data/lib/gir_ffi/user_defined_type_info.rb +25 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi-base.rb +3 -0
- data/lib/gir_ffi.rb +2 -1
- data/test/ffi-glib/sized_array_test.rb +87 -0
- data/test/ffi-gobject_introspection/i_base_info_test.rb +4 -5
- data/test/gir_ffi/argument_builder_test.rb +26 -55
- data/test/gir_ffi/builder/type/unintrospectable_test.rb +3 -19
- data/test/gir_ffi/builder/type/user_defined_test.rb +16 -21
- data/test/gir_ffi/builder_test.rb +31 -53
- data/test/gir_ffi/callback_helper_test.rb +0 -47
- data/test/gir_ffi/callback_test.rb +49 -0
- data/test/gir_ffi/function_builder_test.rb +8 -8
- data/test/gir_ffi/in_out_pointer_test.rb +2 -53
- data/test/gir_ffi/in_pointer_test.rb +0 -13
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +32 -0
- data/test/gir_ffi/info_ext/i_function_info_test.rb +61 -0
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +7 -0
- data/test/gir_ffi/info_ext/i_type_info_test.rb +158 -77
- data/test/gir_ffi/return_value_builder_test.rb +2 -2
- data/test/gir_ffi/unintrospectable_type_info_test.rb +95 -0
- data/test/gir_ffi/user_defined_property_info_test.rb +19 -0
- data/test/gir_ffi/user_defined_type_info_test.rb +34 -0
- data/test/integration/generated_gimarshallingtests_test.rb +10 -10
- data/test/integration/generated_regress_test.rb +10 -10
- metadata +24 -15
- data/lib/gir_ffi/builder/type/struct_based.rb +0 -31
- data/lib/gir_ffi/user_defined/i_base_info.rb +0 -7
- data/lib/gir_ffi/user_defined/i_object_info.rb +0 -13
- data/lib/gir_ffi/user_defined/i_property_info.rb +0 -9
- data/lib/gir_ffi/user_defined/i_registered_type_info.rb +0 -10
- data/test/gir_ffi/user_defined/i_object_info_test.rb +0 -18
- data/test/gir_ffi/user_defined/i_property_info_test.rb +0 -14
- data/test/gir_ffi/user_defined/i_registered_type_info_test.rb +0 -10
@@ -21,9 +21,7 @@ describe GirFFI::ArgumentBuilder do
|
|
21
21
|
stub(interface_type_info = Object.new).namespace { "Bar" }
|
22
22
|
stub(interface_type_info).name { "Foo" }
|
23
23
|
|
24
|
-
stub(type_info).tag { :interface }
|
25
24
|
stub(type_info).flattened_tag { :callback }
|
26
|
-
stub(type_info).type_specification { ":callback" }
|
27
25
|
stub(type_info).interface { interface_type_info }
|
28
26
|
end
|
29
27
|
|
@@ -38,7 +36,6 @@ describe GirFFI::ArgumentBuilder do
|
|
38
36
|
|
39
37
|
describe "for :zero_terminated" do
|
40
38
|
before do
|
41
|
-
stub(type_info).tag { :array }
|
42
39
|
stub(type_info).flattened_tag { :zero_terminated }
|
43
40
|
stub(type_info).element_type { :foo }
|
44
41
|
end
|
@@ -58,9 +55,7 @@ describe GirFFI::ArgumentBuilder do
|
|
58
55
|
|
59
56
|
describe "for :enum" do
|
60
57
|
before do
|
61
|
-
stub(type_info).tag { :interface }
|
62
58
|
stub(type_info).flattened_tag { :enum }
|
63
|
-
stub(type_info).type_specification { ":enum" }
|
64
59
|
end
|
65
60
|
|
66
61
|
it "has the correct value for #pre" do
|
@@ -74,9 +69,7 @@ describe GirFFI::ArgumentBuilder do
|
|
74
69
|
|
75
70
|
describe "for :flags" do
|
76
71
|
before do
|
77
|
-
stub(type_info).tag { :interface }
|
78
72
|
stub(type_info).flattened_tag { :flags }
|
79
|
-
stub(type_info).type_specification { ":flags" }
|
80
73
|
end
|
81
74
|
|
82
75
|
it "has the correct value for #pre" do
|
@@ -90,9 +83,7 @@ describe GirFFI::ArgumentBuilder do
|
|
90
83
|
|
91
84
|
describe "for :object" do
|
92
85
|
before do
|
93
|
-
stub(type_info).tag { :interface }
|
94
86
|
stub(type_info).flattened_tag { :object }
|
95
|
-
stub(type_info).type_specification { ":object" }
|
96
87
|
end
|
97
88
|
|
98
89
|
describe "when not allocated by the caller" do
|
@@ -115,7 +106,7 @@ describe GirFFI::ArgumentBuilder do
|
|
115
106
|
end
|
116
107
|
|
117
108
|
it "has the correct value for #pre" do
|
118
|
-
builder.pre.must_equal [ "_v1 = Bar::Foo.
|
109
|
+
builder.pre.must_equal [ "_v1 = Bar::Foo._allocate" ]
|
119
110
|
end
|
120
111
|
|
121
112
|
it "has the correct value for #post" do
|
@@ -126,9 +117,7 @@ describe GirFFI::ArgumentBuilder do
|
|
126
117
|
|
127
118
|
describe "for :struct" do
|
128
119
|
before do
|
129
|
-
stub(type_info).tag { :interface }
|
130
120
|
stub(type_info).flattened_tag { :struct }
|
131
|
-
stub(type_info).type_specification { ":struct" }
|
132
121
|
end
|
133
122
|
|
134
123
|
describe "when not allocated by the caller" do
|
@@ -151,7 +140,7 @@ describe GirFFI::ArgumentBuilder do
|
|
151
140
|
end
|
152
141
|
|
153
142
|
it "has the correct value for #pre" do
|
154
|
-
builder.pre.must_equal [ "_v1 = Bar::Foo.
|
143
|
+
builder.pre.must_equal [ "_v1 = Bar::Foo._allocate" ]
|
155
144
|
end
|
156
145
|
|
157
146
|
it "has the correct value for #post" do
|
@@ -162,13 +151,11 @@ describe GirFFI::ArgumentBuilder do
|
|
162
151
|
|
163
152
|
describe "for :strv" do
|
164
153
|
before do
|
165
|
-
stub(type_info).tag { :array }
|
166
154
|
stub(type_info).flattened_tag { :strv }
|
167
|
-
stub(type_info).type_specification { "[:strv, :utf8]" }
|
168
155
|
end
|
169
156
|
|
170
157
|
it "has the correct value for #pre" do
|
171
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for
|
158
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :strv" ]
|
172
159
|
end
|
173
160
|
|
174
161
|
it "has the correct value for #post" do
|
@@ -178,10 +165,8 @@ describe GirFFI::ArgumentBuilder do
|
|
178
165
|
|
179
166
|
describe "for :array" do
|
180
167
|
before do
|
181
|
-
stub(type_info).tag { :array }
|
182
168
|
stub(type_info).flattened_tag { :array }
|
183
169
|
stub(type_info).element_type { :foo }
|
184
|
-
stub(type_info).type_specification { ":array" }
|
185
170
|
end
|
186
171
|
|
187
172
|
it "has the correct value for #pre" do
|
@@ -194,50 +179,47 @@ describe GirFFI::ArgumentBuilder do
|
|
194
179
|
end
|
195
180
|
|
196
181
|
describe "for :c" do
|
182
|
+
before do
|
183
|
+
stub(type_info).flattened_tag { :c }
|
184
|
+
stub(type_info).subtype_tag_or_class_name { ":foo" }
|
185
|
+
end
|
186
|
+
|
197
187
|
describe "with fixed size" do
|
198
188
|
before do
|
199
|
-
stub(type_info).tag { :array }
|
200
|
-
stub(type_info).flattened_tag { :c }
|
201
|
-
stub(type_info).type_specification { "[:c, :foo]" }
|
202
189
|
stub(type_info).array_fixed_size { 3 }
|
203
190
|
end
|
204
191
|
|
205
192
|
it "has the correct value for #pre" do
|
206
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for
|
193
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :c" ]
|
207
194
|
end
|
208
195
|
|
209
196
|
it "has the correct value for #post" do
|
210
|
-
builder.post.must_equal [ "_v2 =
|
197
|
+
builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:foo, 3, _v1.to_value)" ]
|
211
198
|
end
|
212
199
|
end
|
213
200
|
|
214
201
|
describe "with separate size parameter" do
|
215
202
|
let(:length_argument) { Object.new }
|
216
203
|
before do
|
217
|
-
stub(type_info).tag { :array }
|
218
|
-
stub(type_info).flattened_tag { :c }
|
219
|
-
stub(type_info).type_specification { "[:c, :foo]" }
|
220
204
|
stub(type_info).array_fixed_size { -1 }
|
221
205
|
stub(length_argument).retname { "bar" }
|
222
206
|
builder.length_arg = length_argument
|
223
207
|
end
|
224
208
|
|
225
209
|
it "has the correct value for #pre" do
|
226
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for
|
210
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :c" ]
|
227
211
|
end
|
228
212
|
|
229
213
|
it "has the correct value for #post" do
|
230
|
-
builder.post.must_equal [ "_v2 =
|
214
|
+
builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:foo, bar, _v1.to_value)" ]
|
231
215
|
end
|
232
216
|
end
|
233
217
|
end
|
234
218
|
|
235
219
|
describe "for :glist" do
|
236
220
|
before do
|
237
|
-
stub(type_info).tag { :glist }
|
238
221
|
stub(type_info).flattened_tag { :glist }
|
239
222
|
stub(type_info).element_type { :foo }
|
240
|
-
stub(type_info).type_specification { ":glist" }
|
241
223
|
end
|
242
224
|
|
243
225
|
it "has the correct value for #pre" do
|
@@ -251,10 +233,8 @@ describe GirFFI::ArgumentBuilder do
|
|
251
233
|
|
252
234
|
describe "for :gslist" do
|
253
235
|
before do
|
254
|
-
stub(type_info).tag { :gslist }
|
255
236
|
stub(type_info).flattened_tag { :gslist }
|
256
237
|
stub(type_info).element_type { :foo }
|
257
|
-
stub(type_info).type_specification { ":gslist" }
|
258
238
|
end
|
259
239
|
|
260
240
|
it "has the correct value for #pre" do
|
@@ -268,10 +248,8 @@ describe GirFFI::ArgumentBuilder do
|
|
268
248
|
|
269
249
|
describe "for :ghash" do
|
270
250
|
before do
|
271
|
-
stub(type_info).tag { :ghash }
|
272
251
|
stub(type_info).flattened_tag { :ghash }
|
273
252
|
stub(type_info).element_type { [:foo, :bar] }
|
274
|
-
stub(type_info).type_specification { ":ghash" }
|
275
253
|
end
|
276
254
|
|
277
255
|
it "has the correct value for #pre" do
|
@@ -289,7 +267,6 @@ describe GirFFI::ArgumentBuilder do
|
|
289
267
|
|
290
268
|
describe "for :enum" do
|
291
269
|
before do
|
292
|
-
stub(type_info).tag { :interface }
|
293
270
|
stub(type_info).flattened_tag { :enum }
|
294
271
|
end
|
295
272
|
|
@@ -304,7 +281,6 @@ describe GirFFI::ArgumentBuilder do
|
|
304
281
|
|
305
282
|
describe "for :flags" do
|
306
283
|
before do
|
307
|
-
stub(type_info).tag { :interface }
|
308
284
|
stub(type_info).flattened_tag { :flags }
|
309
285
|
end
|
310
286
|
|
@@ -319,7 +295,6 @@ describe GirFFI::ArgumentBuilder do
|
|
319
295
|
|
320
296
|
describe "for :gint32" do
|
321
297
|
before do
|
322
|
-
stub(type_info).tag { :gint32 }
|
323
298
|
stub(type_info).flattened_tag { :gint32 }
|
324
299
|
end
|
325
300
|
|
@@ -335,7 +310,6 @@ describe GirFFI::ArgumentBuilder do
|
|
335
310
|
describe "for an array length" do
|
336
311
|
let(:array_argument) { Object.new }
|
337
312
|
before do
|
338
|
-
stub(type_info).tag { :gint32 }
|
339
313
|
stub(type_info).flattened_tag { :gint32 }
|
340
314
|
stub(array_argument).name { "foo_array" }
|
341
315
|
builder.array_arg = array_argument
|
@@ -353,13 +327,11 @@ describe GirFFI::ArgumentBuilder do
|
|
353
327
|
|
354
328
|
describe "for :strv" do
|
355
329
|
before do
|
356
|
-
stub(type_info).tag { :array }
|
357
330
|
stub(type_info).flattened_tag { :strv }
|
358
|
-
stub(type_info).type_specification { "[:strv, :utf8]" }
|
359
331
|
end
|
360
332
|
|
361
333
|
it "has the correct value for #pre" do
|
362
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from
|
334
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from :pointer, GLib::Strv.from(foo)" ]
|
363
335
|
end
|
364
336
|
|
365
337
|
it "has the correct value for #post" do
|
@@ -369,47 +341,44 @@ describe GirFFI::ArgumentBuilder do
|
|
369
341
|
|
370
342
|
describe "for :utf8" do
|
371
343
|
before do
|
372
|
-
stub(type_info).tag { :utf8 }
|
373
344
|
stub(type_info).flattened_tag { :utf8 }
|
374
|
-
stub(type_info).type_specification { ":utf8" }
|
375
345
|
end
|
376
346
|
|
377
347
|
it "has the correct value for #pre" do
|
378
|
-
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from :utf8, foo" ]
|
348
|
+
builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from :pointer, GirFFI::InPointer.from(:utf8, foo)" ]
|
379
349
|
end
|
380
350
|
|
381
351
|
it "has the correct value for #post" do
|
382
|
-
builder.post.must_equal [ "_v2 = _v1.to_value" ]
|
352
|
+
builder.post.must_equal [ "_v2 = ArgHelper.ptr_to_utf8 _v1.to_value" ]
|
383
353
|
end
|
384
354
|
end
|
385
355
|
|
386
356
|
describe "for :c" do
|
357
|
+
before do
|
358
|
+
stub(type_info).flattened_tag { :c }
|
359
|
+
stub(type_info).subtype_tag_or_class_name { ":bar" }
|
360
|
+
end
|
361
|
+
|
387
362
|
describe "with fixed size" do
|
388
363
|
before do
|
389
|
-
stub(type_info).tag { :array }
|
390
|
-
stub(type_info).flattened_tag { :c }
|
391
|
-
stub(type_info).type_specification { "[:c, :bar]" }
|
392
364
|
stub(type_info).array_fixed_size { 3 }
|
393
365
|
end
|
394
366
|
|
395
367
|
it "has the correct value for #pre" do
|
396
368
|
builder.pre.must_equal [
|
397
369
|
"GirFFI::ArgHelper.check_fixed_array_size 3, foo, \"foo\"",
|
398
|
-
"_v1 = GirFFI::InOutPointer.from
|
370
|
+
"_v1 = GirFFI::InOutPointer.from :pointer, GLib::SizedArray.from(:bar, 3, foo)"
|
399
371
|
]
|
400
372
|
end
|
401
373
|
|
402
374
|
it "has the correct value for #post" do
|
403
|
-
builder.post.must_equal [ "_v2 =
|
375
|
+
builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:bar, 3, _v1.to_value)" ]
|
404
376
|
end
|
405
377
|
end
|
406
378
|
|
407
379
|
describe "with separate size parameter" do
|
408
380
|
let(:length_argument) { Object.new }
|
409
381
|
before do
|
410
|
-
stub(type_info).tag { :array }
|
411
|
-
stub(type_info).flattened_tag { :c }
|
412
|
-
stub(type_info).type_specification { "[:c, :bar]" }
|
413
382
|
stub(type_info).array_fixed_size { -1 }
|
414
383
|
stub(length_argument).retname { "baz" }
|
415
384
|
builder.length_arg = length_argument
|
@@ -417,11 +386,13 @@ describe GirFFI::ArgumentBuilder do
|
|
417
386
|
|
418
387
|
it "has the correct value for #pre" do
|
419
388
|
# TODO: Perhaps this should include a length check as well.
|
420
|
-
builder.pre.must_equal [
|
389
|
+
builder.pre.must_equal [
|
390
|
+
"_v1 = GirFFI::InOutPointer.from :pointer, GLib::SizedArray.from(:bar, -1, foo)"
|
391
|
+
]
|
421
392
|
end
|
422
393
|
|
423
394
|
it "has the correct value for #post" do
|
424
|
-
builder.post.must_equal [ "_v2 =
|
395
|
+
builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:bar, baz, _v1.to_value)" ]
|
425
396
|
end
|
426
397
|
end
|
427
398
|
end
|
@@ -12,7 +12,8 @@ describe GirFFI::Builder::Type::Unintrospectable do
|
|
12
12
|
Gio::Lib.g_file_new_for_path(ptr)
|
13
13
|
|
14
14
|
@gtype = GObject.type_from_name 'GLocalFile'
|
15
|
-
@
|
15
|
+
@info = GirFFI::UnintrospectableTypeInfo.new(@gtype)
|
16
|
+
@bldr = GirFFI::Builder::Type::Unintrospectable.new(@info)
|
16
17
|
@klass = @bldr.build_class
|
17
18
|
end
|
18
19
|
|
@@ -29,7 +30,7 @@ describe GirFFI::Builder::Type::Unintrospectable do
|
|
29
30
|
end
|
30
31
|
|
31
32
|
it "returns the same class when built again" do
|
32
|
-
other_bldr = GirFFI::Builder::Type::Unintrospectable.new(@
|
33
|
+
other_bldr = GirFFI::Builder::Type::Unintrospectable.new(@info)
|
33
34
|
other_klass = other_bldr.build_class
|
34
35
|
|
35
36
|
assert_equal @klass, other_klass
|
@@ -47,21 +48,4 @@ describe GirFFI::Builder::Type::Unintrospectable do
|
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
50
|
-
|
51
|
-
# FIXME: Testing a private method, and with rather a lot of
|
52
|
-
# mocking, too.
|
53
|
-
describe "#interfaces" do
|
54
|
-
it "skips interfaces that have no introspection data" do
|
55
|
-
bldr = GirFFI::Builder::Type::Unintrospectable.new(:some_type)
|
56
|
-
|
57
|
-
mock(bldr).interface_gtypes { [:foo, :bar ] }
|
58
|
-
mock(gir = Object.new).find_by_gtype(:foo) { :foo_info }
|
59
|
-
mock(gir).find_by_gtype(:bar) { nil }
|
60
|
-
bldr.instance_eval { @gir = gir }
|
61
|
-
mock(GirFFI::Builder).build_class(:foo_info) { :foo_module }
|
62
|
-
|
63
|
-
result = bldr.send :interfaces
|
64
|
-
result.must_equal [:foo_module]
|
65
|
-
end
|
66
|
-
end
|
67
51
|
end
|
@@ -3,41 +3,36 @@ require 'gir_ffi_test_helper'
|
|
3
3
|
GirFFI.setup :GIMarshallingTests
|
4
4
|
|
5
5
|
describe GirFFI::Builder::Type::UserDefined do
|
6
|
-
describe "with
|
6
|
+
describe "with type info containing one property" do
|
7
7
|
before do
|
8
8
|
@klass = Class.new GIMarshallingTests::OverridesObject
|
9
9
|
Object.const_set "DerivedC#{Sequence.next}", @klass
|
10
|
-
|
10
|
+
|
11
|
+
@info = GirFFI::UserDefinedTypeInfo.new @klass do
|
11
12
|
install_property GObject.param_spec_int("foo", "foo bar",
|
12
13
|
"The Foo Bar Property",
|
13
14
|
10, 20, 15,
|
14
15
|
3)
|
15
16
|
end
|
17
|
+
|
18
|
+
@builder = GirFFI::Builder::Type::UserDefined.new @info
|
16
19
|
@builder.build_class
|
17
20
|
end
|
18
21
|
|
19
|
-
it "
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
it "registers a type that is bigger than the parent" do
|
23
|
+
gtype = @klass.get_gtype
|
24
|
+
q = GObject.type_query gtype
|
25
|
+
q.instance_size.must_be :>, GIMarshallingTests::OverridesObject::Struct.size
|
23
26
|
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
it "is an object of type GirFFI::UserDefined::IObjectInfo" do
|
31
|
-
@info.must_be_instance_of GirFFI::UserDefined::IObjectInfo
|
32
|
-
end
|
28
|
+
it "gives the types Struct the fields :parent and :foo" do
|
29
|
+
@klass::Struct.members.must_equal [:parent, :foo]
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
foo_property.must_be_instance_of GirFFI::UserDefined::IPropertyInfo
|
39
|
-
foo_property.name.must_equal "foo"
|
40
|
-
end
|
32
|
+
it "creates accessor functions for the property" do
|
33
|
+
obj = @klass.new
|
34
|
+
obj.foo = 13
|
35
|
+
obj.foo.must_equal 13
|
41
36
|
end
|
42
37
|
end
|
43
38
|
end
|
@@ -5,33 +5,6 @@ describe GirFFI::Builder do
|
|
5
5
|
@gir = GObjectIntrospection::IRepository.default
|
6
6
|
end
|
7
7
|
|
8
|
-
describe "::itypeinfo_to_callback_ffitype" do
|
9
|
-
describe "for an :interface argument" do
|
10
|
-
before do
|
11
|
-
@iface = Object.new
|
12
|
-
stub(@info = Object.new).interface { @iface }
|
13
|
-
stub(@info).tag { :interface }
|
14
|
-
stub(@info).pointer? { false }
|
15
|
-
end
|
16
|
-
|
17
|
-
it "correctly maps a :union argument to :pointer" do
|
18
|
-
stub(@iface).info_type { :union }
|
19
|
-
|
20
|
-
result = GirFFI::Builder.itypeinfo_to_callback_ffitype @info
|
21
|
-
|
22
|
-
assert_equal :pointer, result
|
23
|
-
end
|
24
|
-
|
25
|
-
it "correctly maps a :flags argument to :int32" do
|
26
|
-
stub(@iface).info_type { :flags }
|
27
|
-
|
28
|
-
result = GirFFI::Builder.itypeinfo_to_callback_ffitype @info
|
29
|
-
|
30
|
-
assert_equal :int32, result
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
8
|
describe "building GObject::Object" do
|
36
9
|
before do
|
37
10
|
save_module :GObject
|
@@ -63,12 +36,6 @@ describe GirFFI::Builder do
|
|
63
36
|
@go = get_introspection_data 'Regress', 'test_callback_destroy_notify'
|
64
37
|
end
|
65
38
|
|
66
|
-
should "have the correct types of the arguments for the attached function" do
|
67
|
-
argtypes = GirFFI::Builder.send(:ffi_function_argument_types, @go)
|
68
|
-
assert_equal [Regress::TestCallbackUserData, :pointer, GLib::DestroyNotify],
|
69
|
-
argtypes
|
70
|
-
end
|
71
|
-
|
72
39
|
should "define ffi callback types :Callback and :ClosureNotify" do
|
73
40
|
Regress.setup_method 'test_callback_destroy_notify'
|
74
41
|
tcud = Regress::Lib.find_type :TestCallbackUserData
|
@@ -80,6 +47,13 @@ describe GirFFI::Builder do
|
|
80
47
|
assert_equal [FFI.find_type(:pointer)], dn.param_types
|
81
48
|
end
|
82
49
|
|
50
|
+
it "calls attach_function with the correct types" do
|
51
|
+
argtypes = [ Regress::TestCallbackUserData, :pointer, GLib::DestroyNotify ]
|
52
|
+
mock(Regress::Lib).attach_function("regress_test_callback_destroy_notify",
|
53
|
+
argtypes, :int32) { true }
|
54
|
+
GirFFI::Builder.attach_ffi_function(Regress::Lib, @go)
|
55
|
+
end
|
56
|
+
|
83
57
|
after do
|
84
58
|
restore_module :Regress
|
85
59
|
restore_module :GObject
|
@@ -210,11 +184,26 @@ describe GirFFI::Builder do
|
|
210
184
|
end
|
211
185
|
|
212
186
|
describe "its #torture_signature_0 method" do
|
213
|
-
|
187
|
+
it "is attached with the correct ffi types" do
|
214
188
|
info = get_method_introspection_data 'Regress', 'TestObj',
|
215
189
|
'torture_signature_0'
|
216
|
-
|
217
|
-
|
190
|
+
|
191
|
+
argtypes = [:pointer, :int32, :pointer, :pointer, :pointer, :pointer, :uint32]
|
192
|
+
mock(Regress::Lib).attach_function("regress_test_obj_torture_signature_0",
|
193
|
+
argtypes, :void) { true }
|
194
|
+
GirFFI::Builder.attach_ffi_function(Regress::Lib, info)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "its #instance_method method" do
|
199
|
+
setup do
|
200
|
+
end
|
201
|
+
|
202
|
+
it "is attached with the correct ffi types" do
|
203
|
+
info = get_method_introspection_data 'Regress', 'TestObj', 'instance_method'
|
204
|
+
mock(Regress::Lib).attach_function("regress_test_obj_instance_method",
|
205
|
+
[:pointer], :int32) { true }
|
206
|
+
GirFFI::Builder.attach_ffi_function(Regress::Lib, info)
|
218
207
|
end
|
219
208
|
end
|
220
209
|
|
@@ -356,30 +345,19 @@ describe GirFFI::Builder do
|
|
356
345
|
end
|
357
346
|
|
358
347
|
it "attaches function to Regress::Lib" do
|
359
|
-
GirFFI::Builder.
|
348
|
+
GirFFI::Builder.attach_ffi_function Regress::Lib, @go
|
360
349
|
assert_defines_singleton_method Regress::Lib, :regress_test_array_gint32_in
|
361
350
|
end
|
362
351
|
|
363
|
-
it "
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
assert_equal :int32, GirFFI::Builder.send(:ffi_function_return_type, @go)
|
352
|
+
it "calls attach_function with the correct types" do
|
353
|
+
argtypes = [:int32, :pointer]
|
354
|
+
mock(Regress::Lib).attach_function("regress_test_array_gint32_in",
|
355
|
+
argtypes, :int32) { true }
|
356
|
+
GirFFI::Builder.attach_ffi_function(Regress::Lib, @go)
|
369
357
|
end
|
370
358
|
|
371
359
|
after do
|
372
360
|
restore_module :Regress
|
373
361
|
end
|
374
362
|
end
|
375
|
-
|
376
|
-
describe "looking at Regress::TestObj#instance_method" do
|
377
|
-
setup do
|
378
|
-
@go = get_method_introspection_data 'Regress', 'TestObj', 'instance_method'
|
379
|
-
end
|
380
|
-
|
381
|
-
it "has :pointer as types of the arguments for the attached function" do
|
382
|
-
assert_equal [:pointer], GirFFI::Builder.send(:ffi_function_argument_types, @go)
|
383
|
-
end
|
384
|
-
end
|
385
363
|
end
|
@@ -1,53 +1,6 @@
|
|
1
1
|
require 'gir_ffi_test_helper'
|
2
|
-
require "gir_ffi/callback_helper"
|
3
2
|
|
4
3
|
describe GirFFI::CallbackHelper do
|
5
|
-
describe "::map_single_callback_arg" do
|
6
|
-
it "maps a :struct type by building the type and wrapping the argument in it" do
|
7
|
-
cinfo = get_introspection_data 'GObject', 'ClosureMarshal'
|
8
|
-
ainfo = cinfo.args[0]
|
9
|
-
ifinfo = ainfo.argument_type.interface
|
10
|
-
|
11
|
-
assert_equal :struct, ifinfo.info_type
|
12
|
-
|
13
|
-
struct_class = Class.new
|
14
|
-
mock(GirFFI::Builder).build_class(ifinfo) { struct_class }
|
15
|
-
mock(struct_class).wrap("dummy") { "good-result" }
|
16
|
-
|
17
|
-
r = GirFFI::CallbackHelper.map_single_callback_arg "dummy", ainfo.argument_type
|
18
|
-
|
19
|
-
assert_equal "good-result", r
|
20
|
-
end
|
21
|
-
|
22
|
-
it "maps an :interface type by calling #to_object on the argument" do
|
23
|
-
cinfo = get_introspection_data 'Gtk', 'CellLayoutDataFunc'
|
24
|
-
ainfo = cinfo.args[0]
|
25
|
-
ifinfo = ainfo.argument_type.interface
|
26
|
-
|
27
|
-
assert_equal :interface, ifinfo.info_type
|
28
|
-
|
29
|
-
mock(ptr = Object.new).to_object { "good-result" }
|
30
|
-
|
31
|
-
r = GirFFI::CallbackHelper.map_single_callback_arg ptr, ainfo.argument_type
|
32
|
-
|
33
|
-
assert_equal "good-result", r
|
34
|
-
end
|
35
|
-
|
36
|
-
it "maps an :object type by calling #to_object on the argument" do
|
37
|
-
cinfo = get_introspection_data 'Gtk', 'CellLayoutDataFunc'
|
38
|
-
ainfo = cinfo.args[1]
|
39
|
-
ifinfo = ainfo.argument_type.interface
|
40
|
-
|
41
|
-
assert_equal :object, ifinfo.info_type
|
42
|
-
|
43
|
-
mock(ptr = Object.new).to_object { "good-result" }
|
44
|
-
|
45
|
-
r = GirFFI::CallbackHelper.map_single_callback_arg ptr, ainfo.argument_type
|
46
|
-
|
47
|
-
assert_equal "good-result", r
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
4
|
describe ".store_callback" do
|
52
5
|
it "stores the passed in proc in GirFFI::CallbackHelper::CALLBACKS" do
|
53
6
|
GirFFI::CallbackHelper.store_callback "some-callback"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'gir_ffi_test_helper'
|
2
|
+
|
3
|
+
describe GirFFI::Callback do
|
4
|
+
describe "::map_single_callback_arg" do
|
5
|
+
it "maps a :struct type by building the type and wrapping the argument in it" do
|
6
|
+
cinfo = get_introspection_data 'GObject', 'ClosureMarshal'
|
7
|
+
ainfo = cinfo.args[0]
|
8
|
+
ifinfo = ainfo.argument_type.interface
|
9
|
+
|
10
|
+
assert_equal :struct, ifinfo.info_type
|
11
|
+
|
12
|
+
struct_class = Class.new
|
13
|
+
mock(GirFFI::Builder).build_class(ifinfo) { struct_class }
|
14
|
+
mock(struct_class).wrap("dummy") { "good-result" }
|
15
|
+
|
16
|
+
r = GirFFI::Callback.map_single_callback_arg "dummy", ainfo.argument_type
|
17
|
+
|
18
|
+
assert_equal "good-result", r
|
19
|
+
end
|
20
|
+
|
21
|
+
it "maps an :interface type by calling #to_object on the argument" do
|
22
|
+
cinfo = get_introspection_data 'Gtk', 'CellLayoutDataFunc'
|
23
|
+
ainfo = cinfo.args[0]
|
24
|
+
ifinfo = ainfo.argument_type.interface
|
25
|
+
|
26
|
+
assert_equal :interface, ifinfo.info_type
|
27
|
+
|
28
|
+
mock(ptr = Object.new).to_object { "good-result" }
|
29
|
+
|
30
|
+
r = GirFFI::Callback.map_single_callback_arg ptr, ainfo.argument_type
|
31
|
+
|
32
|
+
assert_equal "good-result", r
|
33
|
+
end
|
34
|
+
|
35
|
+
it "maps an :object type by calling #to_object on the argument" do
|
36
|
+
cinfo = get_introspection_data 'Gtk', 'CellLayoutDataFunc'
|
37
|
+
ainfo = cinfo.args[1]
|
38
|
+
ifinfo = ainfo.argument_type.interface
|
39
|
+
|
40
|
+
assert_equal :object, ifinfo.info_type
|
41
|
+
|
42
|
+
mock(ptr = Object.new).to_object { "good-result" }
|
43
|
+
|
44
|
+
r = GirFFI::Callback.map_single_callback_arg ptr, ainfo.argument_type
|
45
|
+
|
46
|
+
assert_equal "good-result", r
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -9,9 +9,9 @@ describe GirFFI::FunctionBuilder do
|
|
9
9
|
|
10
10
|
expected = <<-CODE
|
11
11
|
def self.test_array_fixed_out_objects
|
12
|
-
_v1 = GirFFI::InOutPointer.for
|
12
|
+
_v1 = GirFFI::InOutPointer.for :c
|
13
13
|
DummyLib.regress_test_array_fixed_out_objects _v1
|
14
|
-
_v2 =
|
14
|
+
_v2 = GLib::SizedArray.wrap([:pointer, ::Regress::TestObj], 2, _v1.to_value)
|
15
15
|
return _v2
|
16
16
|
end
|
17
17
|
CODE
|
@@ -28,7 +28,7 @@ describe GirFFI::FunctionBuilder do
|
|
28
28
|
def self.test_array_gint16_in ints
|
29
29
|
n_ints = ints.nil? ? 0 : ints.length
|
30
30
|
_v1 = n_ints
|
31
|
-
_v2 =
|
31
|
+
_v2 = GLib::SizedArray.from(:gint16, -1, ints)
|
32
32
|
_v3 = DummyLib.regress_test_array_gint16_in _v1, _v2
|
33
33
|
return _v3
|
34
34
|
end
|
@@ -97,7 +97,7 @@ describe GirFFI::FunctionBuilder do
|
|
97
97
|
|
98
98
|
expected = <<-CODE
|
99
99
|
def self.test_array_int_null_in arr
|
100
|
-
_v1 =
|
100
|
+
_v1 = GLib::SizedArray.from(:gint32, -1, arr)
|
101
101
|
len = arr.nil? ? 0 : arr.length
|
102
102
|
_v2 = len
|
103
103
|
DummyLib.regress_test_array_int_null_in _v1, _v2
|
@@ -115,11 +115,11 @@ describe GirFFI::FunctionBuilder do
|
|
115
115
|
|
116
116
|
expected = <<-CODE
|
117
117
|
def self.test_array_int_null_out
|
118
|
-
_v1 = GirFFI::InOutPointer.for
|
118
|
+
_v1 = GirFFI::InOutPointer.for :c
|
119
119
|
_v2 = GirFFI::InOutPointer.for :gint32
|
120
120
|
DummyLib.regress_test_array_int_null_out _v1, _v2
|
121
121
|
_v3 = _v2.to_value
|
122
|
-
_v4 =
|
122
|
+
_v4 = GLib::SizedArray.wrap(:gint32, _v3, _v1.to_value)
|
123
123
|
return _v4
|
124
124
|
end
|
125
125
|
CODE
|
@@ -134,12 +134,12 @@ describe GirFFI::FunctionBuilder do
|
|
134
134
|
|
135
135
|
expected = <<-CODE
|
136
136
|
def method_array_inout ints
|
137
|
-
_v1 = GirFFI::InOutPointer.from
|
137
|
+
_v1 = GirFFI::InOutPointer.from :pointer, GLib::SizedArray.from(:gint32, -1, ints)
|
138
138
|
length = ints.nil? ? 0 : ints.length
|
139
139
|
_v2 = GirFFI::InOutPointer.from :gint32, length
|
140
140
|
DummyLib.gi_marshalling_tests_object_method_array_inout self, _v1, _v2
|
141
141
|
_v3 = _v2.to_value
|
142
|
-
_v4 =
|
142
|
+
_v4 = GLib::SizedArray.wrap(:gint32, _v3, _v1.to_value)
|
143
143
|
return _v4
|
144
144
|
end
|
145
145
|
CODE
|