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.
Files changed (166) hide show
  1. data/History.txt +14 -0
  2. data/TODO.rdoc +23 -5
  3. data/lib/ffi-glib/array.rb +14 -15
  4. data/lib/ffi-glib/container_class_methods.rb +0 -1
  5. data/lib/ffi-glib/hash_table.rb +3 -4
  6. data/lib/ffi-glib/ptr_array.rb +12 -4
  7. data/lib/ffi-glib/sized_array.rb +27 -7
  8. data/lib/ffi-gobject.rb +14 -15
  9. data/lib/ffi-gobject/closure.rb +1 -1
  10. data/lib/ffi-gobject/object.rb +40 -15
  11. data/lib/ffi-gobject/ruby_closure.rb +0 -1
  12. data/lib/ffi-gobject/value.rb +45 -21
  13. data/lib/ffi-gobject_introspection/i_arg_info.rb +4 -0
  14. data/lib/ffi-gobject_introspection/i_base_info.rb +42 -2
  15. data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
  16. data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -4
  17. data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
  18. data/lib/ffi-gobject_introspection/i_object_info.rb +2 -0
  19. data/lib/ffi-gobject_introspection/i_repository.rb +2 -3
  20. data/lib/ffi-gobject_introspection/i_struct_info.rb +3 -8
  21. data/lib/ffi-gobject_introspection/lib.rb +3 -0
  22. data/lib/gir_ffi-base.rb +3 -1
  23. data/lib/gir_ffi-base/gir_ffi/struct.rb +27 -0
  24. data/lib/gir_ffi-base/glib/boolean.rb +13 -1
  25. data/lib/gir_ffi-base/gobject.rb +7 -0
  26. data/lib/gir_ffi-base/gobject/lib.rb +0 -2
  27. data/lib/gir_ffi.rb +1 -3
  28. data/lib/gir_ffi/arg_helper.rb +4 -85
  29. data/lib/gir_ffi/builder.rb +5 -5
  30. data/lib/gir_ffi/builder_helper.rb +7 -0
  31. data/lib/gir_ffi/builders/argument_builder.rb +132 -0
  32. data/lib/gir_ffi/{base_argument_builder.rb → builders/base_argument_builder.rb} +32 -41
  33. data/lib/gir_ffi/builders/base_type_builder.rb +47 -0
  34. data/lib/gir_ffi/builders/callback_builder.rb +38 -0
  35. data/lib/gir_ffi/builders/constant_builder.rb +18 -0
  36. data/lib/gir_ffi/builders/enum_builder.rb +62 -0
  37. data/lib/gir_ffi/builders/error_argument_builder.rb +18 -0
  38. data/lib/gir_ffi/builders/field_builder.rb +94 -0
  39. data/lib/gir_ffi/builders/function_builder.rb +123 -0
  40. data/lib/gir_ffi/builders/interface_builder.rb +29 -0
  41. data/lib/gir_ffi/builders/mapping_method_builder.rb +88 -0
  42. data/lib/gir_ffi/builders/module_builder.rb +124 -0
  43. data/lib/gir_ffi/{null_argument_builder.rb → builders/null_argument_builder.rb} +0 -0
  44. data/lib/gir_ffi/builders/null_builder.rb +11 -0
  45. data/lib/gir_ffi/builders/object_builder.rb +123 -0
  46. data/lib/gir_ffi/{builder/property.rb → builders/property_builder.rb} +0 -0
  47. data/lib/gir_ffi/builders/registered_type_builder.rb +50 -0
  48. data/lib/gir_ffi/builders/return_value_builder.rb +68 -0
  49. data/lib/gir_ffi/builders/signal_builder.rb +91 -0
  50. data/lib/gir_ffi/builders/struct_builder.rb +35 -0
  51. data/lib/gir_ffi/builders/type_builder.rb +40 -0
  52. data/lib/gir_ffi/builders/unintrospectable_builder.rb +35 -0
  53. data/lib/gir_ffi/builders/union_builder.rb +34 -0
  54. data/lib/gir_ffi/builders/user_defined_builder.rb +103 -0
  55. data/lib/gir_ffi/builders/with_layout.rb +55 -0
  56. data/lib/gir_ffi/builders/with_methods.rb +44 -0
  57. data/lib/gir_ffi/callback_base.rb +31 -0
  58. data/lib/gir_ffi/class_base.rb +16 -10
  59. data/lib/gir_ffi/enum_base.rb +8 -4
  60. data/lib/gir_ffi/ffi_ext/pointer.rb +19 -2
  61. data/lib/gir_ffi/in_out_pointer.rb +38 -39
  62. data/lib/gir_ffi/in_pointer.rb +33 -18
  63. data/lib/gir_ffi/info_ext.rb +0 -4
  64. data/lib/gir_ffi/info_ext/i_arg_info.rb +0 -18
  65. data/lib/gir_ffi/info_ext/i_callable_info.rb +2 -1
  66. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +6 -8
  67. data/lib/gir_ffi/info_ext/i_signal_info.rb +6 -21
  68. data/lib/gir_ffi/info_ext/i_type_info.rb +54 -29
  69. data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -1
  70. data/lib/gir_ffi/interface_base.rb +1 -1
  71. data/lib/gir_ffi/module_base.rb +5 -1
  72. data/lib/gir_ffi/object_base.rb +5 -1
  73. data/lib/gir_ffi/setter_argument_info.rb +4 -0
  74. data/lib/gir_ffi/signal_base.rb +21 -0
  75. data/lib/gir_ffi/struct_base.rb +24 -0
  76. data/lib/gir_ffi/type_base.rb +11 -0
  77. data/lib/gir_ffi/type_map.rb +4 -2
  78. data/lib/gir_ffi/union_base.rb +24 -0
  79. data/lib/gir_ffi/version.rb +1 -1
  80. data/tasks/test.rake +73 -7
  81. data/test/base_test_helper.rb +3 -19
  82. data/test/ffi-glib/array_test.rb +6 -0
  83. data/test/ffi-glib/ptr_array_test.rb +13 -0
  84. data/test/ffi-glib/ruby_closure_test.rb +7 -7
  85. data/test/ffi-glib/sized_array_test.rb +2 -2
  86. data/test/ffi-gobject/gobject_test.rb +3 -12
  87. data/test/ffi-gobject/object_test.rb +33 -2
  88. data/test/ffi-gobject/value_test.rb +114 -1
  89. data/test/ffi-gobject_introspection/i_enum_info_test.rb +2 -2
  90. data/test/ffi-gobject_introspection/i_object_info_test.rb +3 -3
  91. data/test/ffi-gobject_introspection/i_repository_test.rb +26 -21
  92. data/test/ffi-gobject_test.rb +14 -14
  93. data/test/gir_ffi-base/glib/boolean_test.rb +6 -0
  94. data/test/gir_ffi/arg_helper_test.rb +2 -122
  95. data/test/gir_ffi/builder_test.rb +67 -204
  96. data/test/gir_ffi/{argument_builder_test.rb → builders/argument_builder_test.rb} +230 -108
  97. data/test/gir_ffi/builders/base_argument_builder_test.rb +5 -0
  98. data/test/gir_ffi/builders/callback_builder_test.rb +50 -0
  99. data/test/gir_ffi/builders/constant_builder_test.rb +4 -0
  100. data/test/gir_ffi/{builder/type/enum_test.rb → builders/enum_builder_test.rb} +2 -3
  101. data/test/gir_ffi/builders/field_builder_test.rb +94 -0
  102. data/test/gir_ffi/{function_builder_test.rb → builders/function_builder_test.rb} +43 -24
  103. data/test/gir_ffi/{builder/type/interface_test.rb → builders/interface_builder_test.rb} +2 -2
  104. data/test/gir_ffi/{builder/module_test.rb → builders/module_builder_test.rb} +12 -13
  105. data/test/gir_ffi/{builder/type/object_test.rb → builders/object_builder_test.rb} +9 -9
  106. data/test/gir_ffi/{return_value_builder_test.rb → builders/return_value_builder_test.rb} +94 -58
  107. data/test/gir_ffi/builders/signal_builder_test.rb +62 -0
  108. data/test/gir_ffi/{builder/type/struct_test.rb → builders/struct_builder_test.rb} +36 -19
  109. data/test/gir_ffi/{builder/type/unintrospectable_test.rb → builders/unintrospectable_builder_test.rb} +3 -3
  110. data/test/gir_ffi/builders/union_builder_test.rb +29 -0
  111. data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb} +2 -2
  112. data/test/gir_ffi/callback_base_test.rb +11 -0
  113. data/test/gir_ffi/class_base_test.rb +22 -22
  114. data/test/gir_ffi/ffi_ext/pointer_test.rb +18 -0
  115. data/test/gir_ffi/in_out_pointer_test.rb +0 -7
  116. data/test/gir_ffi/in_pointer_test.rb +27 -3
  117. data/test/gir_ffi/info_ext/i_signal_info_test.rb +16 -44
  118. data/test/gir_ffi/info_ext/i_type_info_test.rb +315 -74
  119. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +6 -0
  120. data/test/gir_ffi/interface_base_test.rb +3 -5
  121. data/test/gir_ffi/object_base_test.rb +10 -6
  122. data/test/gir_ffi/type_map_test.rb +2 -2
  123. data/test/gir_ffi/unintrospectable_type_info_test.rb +2 -2
  124. data/test/gir_ffi_test_helper.rb +12 -4
  125. data/test/integration/generated_gimarshallingtests_test.rb +436 -76
  126. data/test/integration/generated_gio_test.rb +5 -11
  127. data/test/integration/generated_gobject_test.rb +8 -0
  128. data/test/integration/generated_regress_test.rb +755 -309
  129. data/test/integration/generated_secret_test.rb +2 -1
  130. metadata +73 -72
  131. data/lib/ffi-gobject/ruby_style.rb +0 -23
  132. data/lib/gir_ffi/argument_builder.rb +0 -154
  133. data/lib/gir_ffi/builder/field.rb +0 -60
  134. data/lib/gir_ffi/builder/module.rb +0 -127
  135. data/lib/gir_ffi/builder/type.rb +0 -39
  136. data/lib/gir_ffi/builder/type/base.rb +0 -48
  137. data/lib/gir_ffi/builder/type/callback.rb +0 -30
  138. data/lib/gir_ffi/builder/type/constant.rb +0 -22
  139. data/lib/gir_ffi/builder/type/enum.rb +0 -66
  140. data/lib/gir_ffi/builder/type/interface.rb +0 -33
  141. data/lib/gir_ffi/builder/type/object.rb +0 -134
  142. data/lib/gir_ffi/builder/type/registered_type.rb +0 -62
  143. data/lib/gir_ffi/builder/type/struct.rb +0 -34
  144. data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -39
  145. data/lib/gir_ffi/builder/type/union.rb +0 -34
  146. data/lib/gir_ffi/builder/type/user_defined.rb +0 -107
  147. data/lib/gir_ffi/builder/type/with_layout.rb +0 -62
  148. data/lib/gir_ffi/builder/type/with_methods.rb +0 -64
  149. data/lib/gir_ffi/callback.rb +0 -72
  150. data/lib/gir_ffi/callback_helper.rb +0 -11
  151. data/lib/gir_ffi/error_argument_builder.rb +0 -17
  152. data/lib/gir_ffi/function_builder.rb +0 -112
  153. data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -11
  154. data/lib/gir_ffi/info_ext/i_object_info.rb +0 -11
  155. data/lib/gir_ffi/info_ext/i_struct_info.rb +0 -11
  156. data/lib/gir_ffi/info_ext/i_union_info.rb +0 -12
  157. data/lib/gir_ffi/return_value_builder.rb +0 -81
  158. data/test/ffi-gobject/ruby_style_test.rb +0 -38
  159. data/test/gir_ffi/base_argument_builder_test.rb +0 -13
  160. data/test/gir_ffi/builder/type/callback_test.rb +0 -6
  161. data/test/gir_ffi/builder/type/constant_test.rb +0 -4
  162. data/test/gir_ffi/builder/type/union_test.rb +0 -12
  163. data/test/gir_ffi/callback_helper_test.rb +0 -10
  164. data/test/gir_ffi/callback_test.rb +0 -49
  165. data/test/gir_ffi/info_ext/i_arg_info_test.rb +0 -39
  166. 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) { "irrelevant" }
7
- let(:builder) { GirFFI::ReturnValueBuilder.new(var_gen,
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).interface_type_name { 'Bar::Foo' }
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
- before do
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
- before do
32
- stub(type_info).flattened_tag { :struct }
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
- before do
48
- stub(type_info).flattened_tag { :union }
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
- before do
64
- stub(type_info).flattened_tag { :interface }
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
- before do
98
- stub(type_info).flattened_tag { :object }
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
- before do
132
- stub(type_info).flattened_tag { :strv }
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
- before do
148
- stub(type_info).flattened_tag { :zero_terminated }
149
- stub(type_info).element_type { :foo }
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
- before do
165
- stub(type_info).flattened_tag { :byte_array }
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
- before do
181
- stub(type_info).flattened_tag { :ptr_array }
182
- stub(type_info).element_type { :foo }
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
- before do
198
- stub(type_info).flattened_tag { :glist }
199
- stub(type_info).element_type { :foo }
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
- before do
215
- stub(type_info).flattened_tag { :gslist }
216
- stub(type_info).element_type { :foo }
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
- before do
232
- stub(type_info).flattened_tag { :ghash }
233
- stub(type_info).element_type { [:foo, :bar] }
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
- before do
249
- stub(type_info).flattened_tag { :array }
250
- stub(type_info).element_type { :foo }
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
- before do
266
- stub(type_info).flattened_tag { :error }
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).subtype_tag_or_class_name { ":foo" }
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).subtype_tag_or_class_name { ":foo" }
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 = GirFFI::ArgHelper.ptr_to_utf8(_v1)" ]
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 "does not capture the result of the c function" do
365
- builder.cvar.must_be_nil
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
- # FIXME: Test WithLayout directly, rather than through Struct.
4
- describe GirFFI::Builder::Type::Struct do
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::Builder::Type::Struct.new @struct
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).find_method { }
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
- c = Class.new
40
- c::Struct = Class.new
61
+ stub(GirFFI::Builder).build_module('Foo') { Foo }
41
62
 
42
- refute c.method_defined?(:bar)
43
- refute c.method_defined?(:bar=)
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 c.method_defined?(:bar)
52
- assert c.method_defined?(:bar=)
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::Builder::Type::Struct.new struct
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::Builder::Type::Object.new info
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::Builder::Type::Unintrospectable do
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::Builder::Type::Unintrospectable.new(@info)
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::Builder::Type::Unintrospectable.new(@info)
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