gir_ffi 0.10.2 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +13 -0
  3. data/Gemfile +9 -4
  4. data/README.md +3 -2
  5. data/Rakefile +2 -1
  6. data/lib/ffi-glib/byte_array.rb +1 -1
  7. data/lib/ffi-glib/main_loop.rb +2 -1
  8. data/lib/ffi-glib/strv.rb +5 -2
  9. data/lib/ffi-glib/variant.rb +3 -5
  10. data/lib/ffi-glib.rb +4 -0
  11. data/lib/ffi-gobject/closure.rb +8 -10
  12. data/lib/ffi-gobject/object.rb +9 -6
  13. data/lib/ffi-gobject/param_spec.rb +4 -0
  14. data/lib/ffi-gobject/value.rb +13 -16
  15. data/lib/ffi-gobject_introspection/gobject_type_init.rb +18 -0
  16. data/lib/ffi-gobject_introspection/i_callable_info.rb +1 -5
  17. data/lib/ffi-gobject_introspection/i_constant_info.rb +3 -3
  18. data/lib/ffi-gobject_introspection/i_repository.rb +3 -47
  19. data/lib/ffi-gobject_introspection/i_vfunc_info.rb +3 -11
  20. data/lib/ffi-gobject_introspection/lib.rb +8 -31
  21. data/lib/{gir_ffi-base/glib → ffi-gobject_introspection}/strv.rb +9 -13
  22. data/lib/ffi-gobject_introspection.rb +47 -2
  23. data/lib/gir_ffi/allocation_helper.rb +1 -19
  24. data/lib/gir_ffi/arg_helper.rb +36 -26
  25. data/lib/{gir_ffi-base/glib → gir_ffi}/boolean.rb +7 -5
  26. data/lib/gir_ffi/boxed_base.rb +5 -23
  27. data/lib/gir_ffi/builder.rb +3 -3
  28. data/lib/gir_ffi/builders/argument_builder.rb +7 -8
  29. data/lib/gir_ffi/builders/base_argument_builder.rb +0 -1
  30. data/lib/gir_ffi/builders/callback_argument_builder.rb +2 -2
  31. data/lib/gir_ffi/builders/callback_return_value_builder.rb +21 -13
  32. data/lib/gir_ffi/builders/field_builder.rb +4 -10
  33. data/lib/gir_ffi/builders/module_builder.rb +6 -4
  34. data/lib/gir_ffi/builders/object_builder.rb +16 -16
  35. data/lib/gir_ffi/builders/struct_builder.rb +4 -6
  36. data/lib/gir_ffi/builders/struct_like.rb +1 -1
  37. data/lib/gir_ffi/builders/user_defined_builder.rb +83 -23
  38. data/lib/gir_ffi/builders/vfunc_argument_builder.rb +12 -17
  39. data/lib/gir_ffi/class_base.rb +0 -4
  40. data/lib/gir_ffi/core.rb +16 -13
  41. data/lib/gir_ffi/enum_base.rb +2 -41
  42. data/lib/gir_ffi/enum_like_base.rb +48 -0
  43. data/lib/gir_ffi/ffi_ext/pointer.rb +1 -1
  44. data/lib/gir_ffi/flags_base.rb +2 -41
  45. data/lib/gir_ffi/in_out_pointer.rb +1 -1
  46. data/lib/gir_ffi/in_pointer.rb +4 -4
  47. data/lib/gir_ffi/info_ext/i_type_info.rb +14 -5
  48. data/lib/gir_ffi/info_ext/i_vfunc_info.rb +8 -0
  49. data/lib/gir_ffi/module_base.rb +4 -0
  50. data/lib/gir_ffi/receiver_argument_info.rb +1 -1
  51. data/lib/gir_ffi/sized_array.rb +6 -6
  52. data/lib/gir_ffi/struct_base.rb +1 -6
  53. data/lib/gir_ffi/struct_like_base.rb +54 -45
  54. data/lib/gir_ffi/type_map.rb +6 -7
  55. data/lib/gir_ffi/union_base.rb +1 -1
  56. data/lib/gir_ffi/{user_defined_type_info.rb → user_defined_object_info.rb} +1 -2
  57. data/lib/gir_ffi/user_defined_property_info.rb +80 -2
  58. data/lib/gir_ffi/version.rb +1 -1
  59. data/lib/gir_ffi-base/gobject/lib.rb +0 -1
  60. data/lib/gir_ffi-base/gobject.rb +3 -5
  61. data/lib/gir_ffi-base.rb +3 -8
  62. data/tasks/test.rake +17 -3
  63. data/test/base_test_helper.rb +39 -23
  64. data/test/ffi-glib/closure_test.rb +37 -0
  65. data/test/ffi-glib/main_loop_test.rb +24 -0
  66. data/test/ffi-glib/ruby_closure_test.rb +0 -5
  67. data/test/ffi-gobject/object_test.rb +6 -10
  68. data/test/ffi-gobject/param_spec_test.rb +17 -5
  69. data/test/ffi-gobject/value_test.rb +15 -6
  70. data/test/ffi-gobject_introspection/gobject_type_init_test.rb +25 -0
  71. data/test/ffi-gobject_introspection/i_base_info_test.rb +1 -1
  72. data/test/ffi-gobject_introspection/i_repository_test.rb +18 -0
  73. data/test/ffi-gobject_introspection/i_vfunc_info_test.rb +40 -0
  74. data/test/{gir_ffi-base/glib → ffi-gobject_introspection}/strv_test.rb +8 -8
  75. data/test/gir_ffi/allocation_helper_test.rb +35 -0
  76. data/test/gir_ffi/arg_helper_test.rb +102 -7
  77. data/test/gir_ffi/boolean_test.rb +34 -0
  78. data/test/gir_ffi/boxed_base_test.rb +46 -6
  79. data/test/gir_ffi/builder_test.rb +88 -29
  80. data/test/gir_ffi/builders/argument_builder_test.rb +19 -0
  81. data/test/gir_ffi/builders/callback_argument_builder_test.rb +17 -0
  82. data/test/gir_ffi/builders/callback_return_value_builder_test.rb +1 -1
  83. data/test/gir_ffi/builders/field_builder_test.rb +2 -1
  84. data/test/gir_ffi/builders/struct_builder_test.rb +42 -25
  85. data/test/gir_ffi/builders/user_defined_builder_test.rb +365 -17
  86. data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +100 -0
  87. data/test/gir_ffi/builders/vfunc_builder_test.rb +5 -3
  88. data/test/{gir_ffi_test.rb → gir_ffi/core_test.rb} +8 -6
  89. data/test/gir_ffi/in_out_pointer_test.rb +1 -1
  90. data/test/gir_ffi/receiver_argument_info_test.rb +32 -0
  91. data/test/gir_ffi/sized_array_test.rb +34 -0
  92. data/test/gir_ffi/struct_base_test.rb +4 -32
  93. data/test/gir_ffi/struct_like_base_test.rb +164 -0
  94. data/test/gir_ffi/union_base_test.rb +4 -20
  95. data/test/gir_ffi/{user_defined_type_info_test.rb → user_defined_object_info_test.rb} +10 -10
  96. data/test/gir_ffi/user_defined_property_info_test.rb +22 -5
  97. data/test/gir_ffi/version_test.rb +1 -1
  98. data/test/integration/callback_exceptions_test.rb +2 -0
  99. data/test/integration/derived_classes_test.rb +2 -0
  100. data/test/integration/generated_everything_test.rb +22 -0
  101. data/test/integration/generated_gimarshallingtests_test.rb +23 -21
  102. data/test/integration/generated_gio_test.rb +2 -0
  103. data/test/integration/generated_glib_test.rb +2 -0
  104. data/test/integration/generated_gst_test.rb +2 -0
  105. data/test/integration/generated_gtop_test.rb +2 -0
  106. data/test/integration/generated_regress_test.rb +113 -29
  107. data/test/integration/generated_secret_test.rb +2 -0
  108. data/test/integration/generated_warnlib_test.rb +2 -0
  109. data/test/integration/method_lookup_test.rb +2 -0
  110. data/test/introspection_test_helper.rb +15 -0
  111. metadata +21 -27
  112. data/lib/gir_ffi-base/glib.rb +0 -8
  113. data/test/gir_ffi-base/glib/boolean_test.rb +0 -34
@@ -2,6 +2,7 @@
2
2
  require 'gir_ffi_test_helper'
3
3
 
4
4
  GirFFI.setup :GIMarshallingTests
5
+ GirFFI.setup :Regress
5
6
 
6
7
  describe GirFFI::Builders::UserDefinedBuilder do
7
8
  let(:klass) do
@@ -9,20 +10,20 @@ describe GirFFI::Builders::UserDefinedBuilder do
9
10
  Class.new(GIMarshallingTests::Object))
10
11
  end
11
12
  let(:builder) { GirFFI::Builders::UserDefinedBuilder.new info }
12
- let(:info) { GirFFI::UserDefinedTypeInfo.new klass }
13
+ let(:info) { GirFFI::UserDefinedObjectInfo.new klass }
13
14
 
14
15
  describe '#build_class' do
15
16
  before do
16
17
  builder.build_class
17
18
  end
18
19
 
19
- describe 'with type info containing one property' do
20
+ describe 'with type info containing one integer property' do
20
21
  let(:info) do
21
- GirFFI::UserDefinedTypeInfo.new klass do |it|
22
- it.install_property GObject.param_spec_int('foo', 'foo bar',
22
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
23
+ it.install_property GObject.param_spec_int('foo-bar', 'foo bar',
23
24
  'The Foo Bar Property',
24
25
  10, 20, 15,
25
- 3)
26
+ readwrite: true)
26
27
  end
27
28
  end
28
29
 
@@ -32,32 +33,379 @@ describe GirFFI::Builders::UserDefinedBuilder do
32
33
  q.instance_size.must_be :>, GIMarshallingTests::Object::Struct.size
33
34
  end
34
35
 
35
- it 'gives the types Struct the fields :parent and :foo' do
36
- klass::Struct.members.must_equal [:parent, :foo]
36
+ it "gives the type's Struct fields for the parent and the property" do
37
+ klass::Struct.members.must_equal [:parent, :foo_bar]
37
38
  end
38
39
 
39
40
  it 'creates accessor functions for the property' do
40
41
  obj = klass.new
41
- obj.foo = 13
42
- obj.foo.must_equal 13
42
+ obj.foo_bar = 13
43
+ obj.foo_bar.must_equal 13
43
44
  end
44
45
 
45
46
  it 'makes the property retrievable using #get_property' do
46
47
  obj = klass.new
47
- obj.foo = 13
48
- obj.get_property('foo').must_equal 13
48
+ obj.foo_bar = 13
49
+ obj.get_property('foo-bar').must_equal 13
49
50
  end
50
51
 
51
52
  it 'makes the property settable using #set_property' do
52
53
  obj = klass.new
53
- obj.set_property('foo', 20)
54
- obj.foo.must_equal 20
54
+ obj.set_property('foo-bar', 20)
55
+ obj.foo_bar.must_equal 20
56
+ end
57
+
58
+ it 'keeps parent properties accessible through their accessors' do
59
+ obj = klass.new
60
+ obj.int = 24
61
+ obj.int.must_equal 24
62
+ end
63
+
64
+ it 'keeps parent properties accessible through get_property and set_property' do
65
+ obj = klass.new
66
+ obj.set_property('int', 24)
67
+ obj.get_property('int').must_equal 24
68
+ end
69
+ end
70
+
71
+ describe 'with type info containing properties of several different types' do
72
+ let(:info) do
73
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
74
+ it.install_property GObject.param_spec_string('string-prop', 'string property',
75
+ 'The String Property',
76
+ 'this is the default value',
77
+ readwrite: true)
78
+ it.install_property GObject.param_spec_int('int-prop', 'integer property',
79
+ 'The Integer Property',
80
+ 10, 20, 15,
81
+ readwrite: true)
82
+ it.install_property GObject.param_spec_long('long-prop', 'long property',
83
+ 'The Long Property',
84
+ 10.0, 50.0, 42.0,
85
+ readwrite: true)
86
+ end
87
+ end
88
+
89
+ it 'registers a type of the proper size' do
90
+ expected_size = klass::Struct.size
91
+ gtype = klass.gtype
92
+ q = GObject.type_query gtype
93
+ q.instance_size.must_equal expected_size
94
+ end
95
+
96
+ it "gives the type's Struct fields for the parent and the properties with the correct offsets" do
97
+ offsets = klass::Struct.offsets
98
+ alignment = klass::Struct.alignment
99
+ alignment.must_equal 8 # TODO: Fix tests for platforms where this fails.
100
+ offsets.must_equal [[:parent, 0], [:string_prop, 32], [:int_prop, 40], [:long_prop, 48]]
101
+ end
102
+
103
+ it 'creates accessor functions for the string property' do
104
+ obj = klass.new
105
+ obj.string_prop = 'hello!'
106
+ obj.string_prop.must_equal 'hello!'
107
+ end
108
+
109
+ it 'creates accessor functions for the integer property' do
110
+ obj = klass.new
111
+ obj.int_prop = 13
112
+ obj.int_prop.must_equal 13
113
+ end
114
+ end
115
+
116
+ describe 'with a boxed property' do
117
+ let(:boxed_gtype) { GIMarshallingTests::BoxedStruct.gtype }
118
+ let(:info) do
119
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
120
+ it.install_property GObject.param_spec_boxed('boxed-prop', 'boxed property',
121
+ 'The Boxed Property',
122
+ boxed_gtype,
123
+ readwrite: true)
124
+ end
125
+ end
126
+
127
+ it 'registers a type of the proper size' do
128
+ expected_size = klass::Struct.size
129
+ gtype = klass.gtype
130
+ q = GObject.type_query gtype
131
+ q.instance_size.must_equal expected_size
132
+ end
133
+
134
+ it "gives the type's Struct fields for the parent and the property" do
135
+ klass::Struct.members.must_equal [:parent, :boxed_prop]
136
+ end
137
+
138
+ it 'creates accessor functions for the property' do
139
+ obj = klass.new
140
+ boxed = GIMarshallingTests::BoxedStruct.new
141
+ boxed.long_ = 423
142
+ obj.boxed_prop = boxed
143
+ obj.boxed_prop.long_.must_equal 423
144
+ end
145
+ end
146
+
147
+ describe 'with an object property' do
148
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
149
+ let(:info) do
150
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
151
+ it.install_property GObject.param_spec_object('object-prop', 'object property',
152
+ 'The Object Property',
153
+ object_gtype,
154
+ readwrite: true)
155
+ end
156
+ end
157
+
158
+ it 'registers a type of the proper size' do
159
+ expected_size = klass::Struct.size
160
+ gtype = klass.gtype
161
+ q = GObject.type_query gtype
162
+ q.instance_size.must_equal expected_size
163
+ end
164
+
165
+ it "gives the type's Struct fields for the parent and the property" do
166
+ klass::Struct.members.must_equal [:parent, :object_prop]
167
+ end
168
+
169
+ it 'creates accessor functions for the property' do
170
+ obj = klass.new
171
+ object = GIMarshallingTests::Object.new 42
172
+ object.int = 423
173
+ obj.object_prop = object
174
+ obj.object_prop.int.must_equal 423
175
+ end
176
+ end
177
+
178
+ describe 'with a boolean property' do
179
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
180
+ let(:info) do
181
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
182
+ it.install_property GObject.param_spec_boolean('the-prop', 'the property',
183
+ 'The Property',
184
+ true,
185
+ readwrite: true)
186
+ end
187
+ end
188
+
189
+ it 'creates accessor functions for the property' do
190
+ obj = klass.new
191
+ obj.the_prop = true
192
+ obj.the_prop.must_equal true
193
+ end
194
+ end
195
+
196
+ describe 'with a char property' do
197
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
198
+ let(:info) do
199
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
200
+ it.install_property GObject.param_spec_char('the-prop', 'the property',
201
+ 'The Property',
202
+ -20, 100, 15,
203
+ readwrite: true)
204
+ end
205
+ end
206
+
207
+ it 'creates accessor functions for the property' do
208
+ obj = klass.new
209
+ obj.the_prop = -13
210
+ obj.the_prop.must_equal(-13)
211
+ end
212
+ end
213
+
214
+ describe 'with a uchar property' do
215
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
216
+ let(:info) do
217
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
218
+ it.install_property GObject.param_spec_uchar('the-prop', 'the property',
219
+ 'The Property',
220
+ 10, 100, 15,
221
+ readwrite: true)
222
+ end
223
+ end
224
+
225
+ it 'creates accessor functions for the property' do
226
+ obj = klass.new
227
+ obj.the_prop = 13
228
+ obj.the_prop.must_equal 13
229
+ end
230
+ end
231
+
232
+ describe 'with a uint property' do
233
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
234
+ let(:info) do
235
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
236
+ it.install_property GObject.param_spec_uint('the-prop', 'the property',
237
+ 'The Property',
238
+ 10, 100, 15,
239
+ readwrite: true)
240
+ end
241
+ end
242
+
243
+ it 'creates accessor functions for the property' do
244
+ obj = klass.new
245
+ obj.the_prop = 423
246
+ obj.the_prop.must_equal 423
247
+ end
248
+ end
249
+
250
+ describe 'with a ulong property' do
251
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
252
+ let(:info) do
253
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
254
+ it.install_property GObject.param_spec_ulong('the-prop', 'the property',
255
+ 'The Property',
256
+ 10, 100, 15,
257
+ readwrite: true)
258
+ end
259
+ end
260
+
261
+ it 'creates accessor functions for the property' do
262
+ obj = klass.new
263
+ obj.the_prop = 423_432
264
+ obj.the_prop.must_equal 423_432
265
+ end
266
+ end
267
+
268
+ describe 'with a int64 property' do
269
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
270
+ let(:info) do
271
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
272
+ it.install_property GObject.param_spec_int64('the-prop', 'the property',
273
+ 'The Property',
274
+ 10, 100, 15,
275
+ readwrite: true)
276
+ end
277
+ end
278
+
279
+ it 'creates accessor functions for the property' do
280
+ obj = klass.new
281
+ obj.the_prop = -423_432
282
+ obj.the_prop.must_equal(-423_432)
283
+ end
284
+ end
285
+
286
+ describe 'with a uint64 property' do
287
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
288
+ let(:info) do
289
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
290
+ it.install_property GObject.param_spec_uint64('the-prop', 'the property',
291
+ 'The Property',
292
+ 10, 100, 15,
293
+ readwrite: true)
294
+ end
295
+ end
296
+
297
+ it 'creates accessor functions for the property' do
298
+ obj = klass.new
299
+ obj.the_prop = 423_432
300
+ obj.the_prop.must_equal 423_432
301
+ end
302
+ end
303
+
304
+ describe 'with a float property' do
305
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
306
+ let(:info) do
307
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
308
+ it.install_property GObject.param_spec_float('the-prop', 'the property',
309
+ 'The Property',
310
+ 10.0, 100.0, 15.0,
311
+ readwrite: true)
312
+ end
313
+ end
314
+
315
+ it 'creates accessor functions for the property' do
316
+ obj = klass.new
317
+ obj.the_prop = 42.23
318
+ obj.the_prop.must_be_within_epsilon 42.23
319
+ end
320
+ end
321
+
322
+ describe 'with a double property' do
323
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
324
+ let(:info) do
325
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
326
+ it.install_property GObject.param_spec_double('the-prop', 'the property',
327
+ 'The Property',
328
+ 10.0, 100.0, 15.0,
329
+ readwrite: true)
330
+ end
331
+ end
332
+
333
+ it 'creates accessor functions for the property' do
334
+ obj = klass.new
335
+ obj.the_prop = 42.23
336
+ obj.the_prop.must_equal 42.23
337
+ end
338
+ end
339
+
340
+ describe 'with an enum property' do
341
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
342
+ let(:info) do
343
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
344
+ prop = GObject.param_spec_enum('the-prop', 'the property',
345
+ 'The Property',
346
+ GIMarshallingTests::GEnum.gtype, 0,
347
+ readwrite: true)
348
+ it.install_property prop
349
+ end
350
+ end
351
+
352
+ it 'creates accessor functions for the property' do
353
+ obj = klass.new
354
+ obj.the_prop = :value2
355
+ obj.the_prop.must_equal :value2
356
+ end
357
+ end
358
+
359
+ describe 'with a flags property' do
360
+ let(:object_gtype) { GIMarshallingTests::Object.gtype }
361
+ let(:info) do
362
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
363
+ prop = GObject.param_spec_flags('the-prop', 'the property',
364
+ 'The Property',
365
+ GIMarshallingTests::Flags.gtype, 0,
366
+ readwrite: true)
367
+ it.install_property prop
368
+ end
369
+ end
370
+
371
+ it 'creates accessor functions for the property' do
372
+ obj = klass.new
373
+ obj.the_prop = { value2: true }
374
+ obj.the_prop.must_equal value2: true
375
+ end
376
+ end
377
+
378
+ describe 'when deriving from a class with hidden struct size' do
379
+ let(:parent_class) { Regress::TestInheritDrawable }
380
+ let(:parent_size) do
381
+ GObject.type_query(parent_class.gtype).instance_size
382
+ end
383
+ let(:klass) do
384
+ Object.const_set("DerivedClass#{Sequence.next}", Class.new(parent_class))
385
+ end
386
+ let(:info) do
387
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
388
+ it.install_property GObject.param_spec_int('int-prop', 'integer property',
389
+ 'Integer Property',
390
+ 10, 20, 15,
391
+ readwrite: true)
392
+ end
393
+ end
394
+
395
+ it 'registers a type that is bigger than the parent' do
396
+ klass_size = GObject.type_query(klass.gtype).instance_size
397
+ klass_size.must_be :>, parent_size
398
+ end
399
+
400
+ it 'leaves enough space in derived struct layout' do
401
+ struct_size = klass::Struct.size
402
+ struct_size.must_be :>, parent_size
55
403
  end
56
404
  end
57
405
 
58
406
  describe 'with type info containing an overridden g_name' do
59
407
  let(:info) do
60
- GirFFI::UserDefinedTypeInfo.new klass do |it|
408
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
61
409
  it.g_name = "OtherName#{Sequence.next}"
62
410
  end
63
411
  end
@@ -71,8 +419,8 @@ describe GirFFI::Builders::UserDefinedBuilder do
71
419
 
72
420
  describe 'with type info containing a vfunc' do
73
421
  let(:info) do
74
- GirFFI::UserDefinedTypeInfo.new klass do |it|
75
- it.install_vfunc_implementation :method_int8_in, proc {|instance, in_|
422
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
423
+ it.install_vfunc_implementation :method_int8_in, proc { |instance, in_|
76
424
  instance.int = in_
77
425
  }
78
426
  end
@@ -88,7 +436,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
88
436
  describe 'with type info containing a vfunc from an included Interface' do
89
437
  let(:info) do
90
438
  klass.class_eval { include GIMarshallingTests::Interface }
91
- GirFFI::UserDefinedTypeInfo.new klass do |it|
439
+ GirFFI::UserDefinedObjectInfo.new klass do |it|
92
440
  it.install_vfunc_implementation :test_int8_in,
93
441
  proc { |instance, in_| instance.int = in_ }
94
442
  end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+ require 'gir_ffi_test_helper'
3
+
4
+ describe GirFFI::Builders::VFuncArgumentBuilder do
5
+ let(:var_gen) { GirFFI::VariableNameGenerator.new }
6
+ let(:builder) { GirFFI::Builders::VFuncArgumentBuilder.new(var_gen, arg_info) }
7
+
8
+ describe 'for a plain in argument' do
9
+ let(:vfunc_info) do
10
+ get_vfunc_introspection_data 'GIMarshallingTests', 'Object', 'method_int8_in'
11
+ end
12
+ let(:arg_info) { vfunc_info.args[0] }
13
+
14
+ it 'has the correct value for #pre_conversion' do
15
+ builder.pre_conversion.must_equal ['_v1 = in_']
16
+ end
17
+
18
+ it 'has the correct value for #post_conversion' do
19
+ builder.post_conversion.must_equal []
20
+ end
21
+ end
22
+
23
+ describe 'for a transfer-none in argument' do
24
+ let(:vfunc_info) do
25
+ get_vfunc_introspection_data 'GIMarshallingTests', 'Object', 'vfunc_in_object_transfer_none'
26
+ end
27
+ let(:arg_info) { vfunc_info.args[0] }
28
+
29
+ it 'has the correct value for #pre_conversion' do
30
+ builder.pre_conversion.must_equal ['_v1 = GObject::Object.wrap(object)', '_v1.ref']
31
+ end
32
+
33
+ it 'has the correct value for #post_conversion' do
34
+ builder.post_conversion.must_equal []
35
+ end
36
+ end
37
+
38
+ describe 'for a transfer-none outgoing object argument' do
39
+ let(:vfunc_info) do
40
+ get_vfunc_introspection_data 'GIMarshallingTests', 'Object', 'vfunc_out_object_transfer_none'
41
+ end
42
+ let(:arg_info) { vfunc_info.args[0] }
43
+
44
+ it 'has the correct value for #pre_conversion' do
45
+ builder.pre_conversion.must_equal ['_v1 = object']
46
+ end
47
+
48
+ it 'has the correct value for #post_conversion' do
49
+ builder.post_conversion.must_equal ['_v1.put_pointer 0, GObject::Object.from(_v2)']
50
+ end
51
+ end
52
+
53
+ describe 'for a full-transfer outgoing object argument' do
54
+ let(:vfunc_info) do
55
+ get_vfunc_introspection_data 'GIMarshallingTests', 'Object', 'vfunc_out_object_transfer_full'
56
+ end
57
+ let(:arg_info) { vfunc_info.args[0] }
58
+
59
+ it 'has the correct value for #pre_conversion' do
60
+ builder.pre_conversion.must_equal ['_v1 = object']
61
+ end
62
+
63
+ it 'has the correct value for #post_conversion' do
64
+ builder.pre_conversion
65
+ builder.post_conversion.must_equal ['_v2.ref', '_v1.put_pointer 0, GObject::Object.from(_v2)']
66
+ end
67
+ end
68
+
69
+ describe 'for a full-transfer outgoing non-object argument' do
70
+ let(:vfunc_info) do
71
+ get_vfunc_introspection_data('GIMarshallingTests', 'Object',
72
+ 'method_int8_arg_and_out_callee')
73
+ end
74
+ let(:arg_info) { vfunc_info.args[1] }
75
+
76
+ it 'has the correct value for #pre_conversion' do
77
+ builder.pre_conversion.
78
+ must_equal ['_v1 = FFI::MemoryPointer.new(:int8).tap { |ptr| out.put_pointer 0, ptr }']
79
+ end
80
+
81
+ it 'has the correct value for #post_conversion' do
82
+ builder.post_conversion.must_equal ['_v1.put_int8 0, _v2']
83
+ end
84
+ end
85
+
86
+ describe 'for a receiver argument' do
87
+ let(:object_info) { get_introspection_data('GIMarshallingTests', 'Object') }
88
+ let(:type_info) { GirFFI::ReceiverTypeInfo.new(object_info) }
89
+ let(:arg_info) { GirFFI::ReceiverArgumentInfo.new(type_info) }
90
+
91
+ it 'has the correct value for #pre_conversion' do
92
+ builder.pre_conversion.
93
+ must_equal ['_v1 = GIMarshallingTests::Object.wrap(_instance)']
94
+ end
95
+
96
+ it 'has the correct value for #post_conversion' do
97
+ builder.post_conversion.must_equal []
98
+ end
99
+ end
100
+ end
@@ -99,7 +99,7 @@ describe GirFFI::Builders::VFuncBuilder do
99
99
  def self.call_with_argument_mapping(_proc, _instance, arg, out)
100
100
  _v1 = GIMarshallingTests::Object.wrap(_instance)
101
101
  _v2 = arg
102
- _v3 = GirFFI::AllocationHelper.allocate(:int8).tap { |ptr| out.put_pointer 0, ptr }
102
+ _v3 = FFI::MemoryPointer.new(:int8).tap { |ptr| out.put_pointer 0, ptr }
103
103
  _v4 = _proc.call(_v1, _v2)
104
104
  _v3.put_int8 0, _v4
105
105
  end
@@ -164,7 +164,8 @@ describe GirFFI::Builders::VFuncBuilder do
164
164
  def self.call_with_argument_mapping(_proc, _instance)
165
165
  _v1 = GIMarshallingTests::Object.wrap(_instance)
166
166
  _v2 = _proc.call(_v1)
167
- _v3 = GObject::Object.from(_v2.ref).to_ptr
167
+ _v2.ref
168
+ _v3 = GObject::Object.from(_v2).to_ptr
168
169
  return _v3
169
170
  end
170
171
  CODE
@@ -203,7 +204,8 @@ describe GirFFI::Builders::VFuncBuilder do
203
204
  _v1 = GIMarshallingTests::Object.wrap(_instance)
204
205
  _v2 = object
205
206
  _v3 = _proc.call(_v1)
206
- _v2.put_pointer 0, GObject::Object.from(_v3.ref)
207
+ _v3.ref
208
+ _v2.put_pointer 0, GObject::Object.from(_v3)
207
209
  end
208
210
  CODE
209
211
 
@@ -3,7 +3,7 @@ require 'gir_ffi_test_helper'
3
3
 
4
4
  GirFFI.setup :GIMarshallingTests
5
5
 
6
- describe GirFFI do
6
+ describe GirFFI::Core do
7
7
  it 'sets up cairo as Cairo' do
8
8
  GirFFI.setup :cairo
9
9
  assert Object.const_defined?(:Cairo)
@@ -25,6 +25,13 @@ describe GirFFI do
25
25
  restore_module :GObject
26
26
  end
27
27
 
28
+ describe '.setup' do
29
+ it 'passes the desired version down to the module builder' do
30
+ expect(GirFFI::Builder).to receive(:build_module).with('Regress', '0.1')
31
+ GirFFI.setup :Regress, '0.1'
32
+ end
33
+ end
34
+
28
35
  describe '::define_type' do
29
36
  describe 'without a block' do
30
37
  before do
@@ -57,11 +64,6 @@ describe GirFFI do
57
64
  type = GObject.type_from_instance obj
58
65
  type.must_equal @gtype
59
66
  end
60
-
61
- it 'makes GirFFI find the new class by GType' do
62
- klass = GirFFI::Builder.build_by_gtype @gtype
63
- klass.must_equal @klass
64
- end
65
67
  end
66
68
 
67
69
  describe 'with a block with a call to #install_property' do
@@ -4,7 +4,7 @@ require 'gir_ffi_test_helper'
4
4
  describe GirFFI::InOutPointer do
5
5
  describe '.new' do
6
6
  it 'wraps an existing pointer and a type' do
7
- ptr = GirFFI::AllocationHelper.safe_malloc(FFI.type_size(:int32))
7
+ ptr = FFI::MemoryPointer.new(:int32)
8
8
  ptr.put_int32 0, 42
9
9
  instance = GirFFI::InOutPointer.new :gint32, ptr
10
10
  instance.to_value.must_equal 42
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ require 'gir_ffi_test_helper'
3
+ require 'gir_ffi/receiver_argument_info'
4
+
5
+ describe GirFFI::ReceiverArgumentInfo do
6
+ let(:dummy_type) { 'foo' }
7
+ let(:instance) { GirFFI::ReceiverArgumentInfo.new dummy_type }
8
+
9
+ describe '#argument_type' do
10
+ it 'returns the argument type' do
11
+ instance.argument_type.must_equal dummy_type
12
+ end
13
+ end
14
+
15
+ describe '#direction' do
16
+ it 'returns the correct value' do
17
+ instance.direction.must_equal :in
18
+ end
19
+ end
20
+
21
+ describe '#ownership_transfer' do
22
+ it 'returns the correct value' do
23
+ instance.ownership_transfer.must_equal :everything
24
+ end
25
+ end
26
+
27
+ describe '#name' do
28
+ it 'returns the correct value' do
29
+ instance.name.must_equal '_instance'
30
+ end
31
+ end
32
+ end
@@ -173,6 +173,40 @@ describe GirFFI::SizedArray do
173
173
  end
174
174
  end
175
175
 
176
+ describe '#size_in_bytes' do
177
+ it 'returns the correct value' do
178
+ sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
179
+
180
+ sized.size_in_bytes.must_equal 12
181
+ end
182
+ end
183
+
184
+ describe '.get_value_from_pointer' do
185
+ it 'returns just a pointer' do
186
+ sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
187
+ ptr = sized.to_ptr
188
+ GirFFI::SizedArray.get_value_from_pointer(ptr, 0).must_equal ptr
189
+ end
190
+
191
+ it 'offsets correctly' do
192
+ sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
193
+ ptr = sized.to_ptr
194
+ next_ptr = GirFFI::SizedArray.get_value_from_pointer(ptr, 4)
195
+ tail = GirFFI::SizedArray.from(:int32, 2, next_ptr)
196
+ tail.must_be :==, [2, 3]
197
+ end
198
+ end
199
+
200
+ describe '.copy_value_to_pointer' do
201
+ it 'copies data correctly' do
202
+ sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
203
+ target = FFI::MemoryPointer.new sized.size_in_bytes
204
+ GirFFI::SizedArray.copy_value_to_pointer(sized, target)
205
+ result = GirFFI::SizedArray.from :int32, 3, target
206
+ result.must_be :==, [1, 2, 3]
207
+ end
208
+ end
209
+
176
210
  it 'includes Enumerable' do
177
211
  GirFFI::SizedArray.must_include Enumerable
178
212
  end