gir_ffi 0.6.7 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/{History.txt → Changelog.md} +93 -61
  3. data/{DESIGN.rdoc → DESIGN.md} +7 -7
  4. data/README.md +5 -7
  5. data/TODO.md +90 -0
  6. data/lib/ffi-glib.rb +0 -1
  7. data/lib/ffi-glib/array.rb +13 -29
  8. data/lib/ffi-glib/array_methods.rb +13 -0
  9. data/lib/ffi-glib/container_class_methods.rb +6 -1
  10. data/lib/ffi-glib/hash_table.rb +3 -2
  11. data/lib/ffi-glib/list.rb +3 -17
  12. data/lib/ffi-glib/list_methods.rb +22 -3
  13. data/lib/ffi-glib/ptr_array.rb +19 -19
  14. data/lib/ffi-glib/s_list.rb +3 -17
  15. data/lib/ffi-gobject.rb +10 -17
  16. data/lib/ffi-gobject/object.rb +19 -9
  17. data/lib/ffi-gobject/object_class.rb +14 -0
  18. data/lib/ffi-gobject/ruby_closure.rb +4 -5
  19. data/lib/ffi-gobject/value.rb +7 -5
  20. data/lib/ffi-gobject_introspection/i_vfunc_info.rb +1 -1
  21. data/lib/gir_ffi-base.rb +0 -2
  22. data/lib/gir_ffi-base/gobject.rb +1 -0
  23. data/lib/gir_ffi-base/gobject/lib.rb +1 -1
  24. data/lib/gir_ffi.rb +2 -0
  25. data/lib/gir_ffi/arg_helper.rb +18 -8
  26. data/lib/gir_ffi/builders/argument_builder.rb +62 -55
  27. data/lib/gir_ffi/builders/base_argument_builder.rb +52 -106
  28. data/lib/gir_ffi/builders/base_type_builder.rb +3 -3
  29. data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +34 -0
  30. data/lib/gir_ffi/builders/callback_argument_builder.rb +73 -0
  31. data/lib/gir_ffi/builders/callback_builder.rb +19 -9
  32. data/lib/gir_ffi/builders/callback_return_value_builder.rb +54 -0
  33. data/lib/gir_ffi/builders/closure_convertor.rb +9 -0
  34. data/lib/gir_ffi/builders/closure_to_pointer_convertor.rb +9 -0
  35. data/lib/gir_ffi/builders/constructor_result_convertor.rb +9 -0
  36. data/lib/gir_ffi/builders/enum_builder.rb +16 -16
  37. data/lib/gir_ffi/builders/field_builder.rb +36 -15
  38. data/lib/gir_ffi/builders/function_builder.rb +32 -27
  39. data/lib/gir_ffi/builders/interface_builder.rb +14 -4
  40. data/lib/gir_ffi/builders/mapping_method_builder.rb +95 -43
  41. data/lib/gir_ffi/builders/module_builder.rb +22 -35
  42. data/lib/gir_ffi/builders/null_convertor.rb +9 -0
  43. data/lib/gir_ffi/builders/object_builder.rb +11 -14
  44. data/lib/gir_ffi/builders/property_builder.rb +107 -9
  45. data/lib/gir_ffi/builders/registered_type_builder.rb +2 -2
  46. data/lib/gir_ffi/builders/return_value_builder.rb +42 -33
  47. data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +15 -0
  48. data/lib/gir_ffi/builders/signal_builder.rb +18 -58
  49. data/lib/gir_ffi/builders/struct_builder.rb +1 -2
  50. data/lib/gir_ffi/builders/type_builder.rb +1 -0
  51. data/lib/gir_ffi/builders/unintrospectable_builder.rb +4 -4
  52. data/lib/gir_ffi/builders/user_defined_builder.rb +151 -26
  53. data/lib/gir_ffi/builders/vfunc_builder.rb +57 -0
  54. data/lib/gir_ffi/builders/with_layout.rb +10 -8
  55. data/lib/gir_ffi/builders/with_methods.rb +1 -1
  56. data/lib/gir_ffi/callback_base.rb +42 -8
  57. data/lib/gir_ffi/class_base.rb +1 -2
  58. data/lib/gir_ffi/enum_base.rb +26 -4
  59. data/lib/gir_ffi/error_argument_info.rb +21 -0
  60. data/lib/gir_ffi/{setter_argument_info.rb → field_argument_info.rb} +2 -1
  61. data/lib/gir_ffi/g_type.rb +25 -0
  62. data/lib/gir_ffi/in_out_pointer.rb +3 -14
  63. data/lib/gir_ffi/in_pointer.rb +20 -21
  64. data/lib/gir_ffi/info_ext.rb +2 -0
  65. data/lib/gir_ffi/info_ext/i_callable_info.rb +0 -9
  66. data/lib/gir_ffi/info_ext/i_callback_info.rb +17 -0
  67. data/lib/gir_ffi/info_ext/i_function_info.rb +4 -0
  68. data/lib/gir_ffi/info_ext/i_property_info.rb +4 -0
  69. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +1 -0
  70. data/lib/gir_ffi/info_ext/i_signal_info.rb +14 -16
  71. data/lib/gir_ffi/info_ext/i_type_info.rb +72 -34
  72. data/lib/gir_ffi/info_ext/i_vfunc_info.rb +12 -0
  73. data/lib/gir_ffi/info_ext/safe_constant_name.rb +3 -2
  74. data/lib/gir_ffi/interface_base.rb +8 -3
  75. data/lib/gir_ffi/module_base.rb +3 -5
  76. data/lib/gir_ffi/object_base.rb +8 -0
  77. data/lib/gir_ffi/receiver_argument_info.rb +21 -0
  78. data/lib/gir_ffi/receiver_type_info.rb +27 -0
  79. data/lib/gir_ffi/return_value_info.rb +23 -0
  80. data/lib/gir_ffi/signal_base.rb +1 -1
  81. data/lib/{ffi-glib → gir_ffi}/sized_array.rb +10 -6
  82. data/lib/gir_ffi/struct_base.rb +10 -9
  83. data/lib/gir_ffi/type_base.rb +1 -0
  84. data/lib/gir_ffi/type_map.rb +3 -0
  85. data/lib/gir_ffi/unintrospectable_type_info.rb +4 -1
  86. data/lib/gir_ffi/union_base.rb +4 -21
  87. data/lib/gir_ffi/user_data_argument_info.rb +21 -0
  88. data/lib/gir_ffi/user_data_type_info.rb +17 -0
  89. data/lib/gir_ffi/user_defined_type_info.rb +18 -4
  90. data/lib/gir_ffi/version.rb +1 -1
  91. data/lib/gir_ffi/vfunc_base.rb +8 -0
  92. data/lib/gir_ffi/vfunc_implementation.rb +11 -0
  93. data/lib/gir_ffi/zero_terminated.rb +18 -24
  94. data/test/base_test_helper.rb +2 -3
  95. data/test/ffi-glib/array_test.rb +3 -3
  96. data/test/ffi-glib/ruby_closure_test.rb +3 -3
  97. data/test/ffi-gobject/value_test.rb +15 -1
  98. data/test/ffi-gobject_test.rb +2 -1
  99. data/test/gir_ffi/arg_helper_test.rb +21 -2
  100. data/test/gir_ffi/builders/argument_builder_test.rb +213 -287
  101. data/test/gir_ffi/builders/base_argument_builder_test.rb +1 -1
  102. data/test/gir_ffi/builders/callback_builder_test.rb +26 -8
  103. data/test/gir_ffi/builders/field_builder_test.rb +18 -3
  104. data/test/gir_ffi/builders/function_builder_test.rb +30 -12
  105. data/test/gir_ffi/builders/interface_builder_test.rb +9 -0
  106. data/test/gir_ffi/builders/module_builder_test.rb +0 -39
  107. data/test/gir_ffi/builders/object_builder_test.rb +27 -27
  108. data/test/gir_ffi/builders/property_builder_test.rb +110 -0
  109. data/test/gir_ffi/builders/return_value_builder_test.rb +168 -200
  110. data/test/gir_ffi/builders/signal_builder_test.rb +58 -14
  111. data/test/gir_ffi/builders/struct_builder_test.rb +2 -41
  112. data/test/gir_ffi/builders/user_defined_builder_test.rb +88 -20
  113. data/test/gir_ffi/builders/vfunc_builder_test.rb +44 -0
  114. data/test/gir_ffi/g_type_test.rb +29 -0
  115. data/test/gir_ffi/in_pointer_test.rb +28 -9
  116. data/test/gir_ffi/info_ext/i_callable_info_test.rb +0 -9
  117. data/test/gir_ffi/info_ext/i_callback_info_test.rb +19 -0
  118. data/test/gir_ffi/info_ext/i_function_info_test.rb +9 -0
  119. data/test/gir_ffi/info_ext/i_signal_info_test.rb +8 -11
  120. data/test/gir_ffi/info_ext/i_type_info_test.rb +140 -16
  121. data/test/gir_ffi/interface_base_test.rb +9 -3
  122. data/test/gir_ffi/object_base_test.rb +1 -2
  123. data/test/{ffi-glib → gir_ffi}/sized_array_test.rb +28 -28
  124. data/test/gir_ffi/type_map_test.rb +1 -1
  125. data/test/gir_ffi/user_defined_type_info_test.rb +36 -4
  126. data/test/gir_ffi_test.rb +5 -5
  127. data/test/gir_ffi_test_helper.rb +4 -0
  128. data/test/integration/generated_gimarshallingtests_test.rb +163 -59
  129. data/test/integration/generated_gobject_test.rb +21 -8
  130. data/test/integration/generated_pango_test.rb +2 -2
  131. data/test/integration/generated_regress_test.rb +361 -101
  132. data/test/lib/autogen.sh +5 -1
  133. metadata +51 -35
  134. data/TODO.rdoc +0 -63
  135. data/lib/gir_ffi-base/gir_ffi/library.rb +0 -17
  136. data/lib/gir_ffi-base/gir_ffi/struct.rb +0 -27
@@ -1,359 +1,331 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GirFFI::Builders::ReturnValueBuilder do
4
- let(:type_info) { Object.new }
5
4
  let(:var_gen) { GirFFI::VariableNameGenerator.new }
5
+ let(:return_type_info) { GirFFI::ReturnValueInfo.new(type_info) }
6
6
  let(:for_constructor) { false }
7
- let(:skip) { false }
8
7
  let(:builder) { GirFFI::Builders::ReturnValueBuilder.new(var_gen,
9
- type_info,
10
- for_constructor,
11
- skip) }
12
- let(:conversion_arguments) { [] }
13
- let(:argument_class_name) { flattened_tag }
14
- let(:flattened_tag) { nil }
15
-
16
- before do
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 }
20
- end
8
+ return_type_info,
9
+ for_constructor) }
21
10
 
22
11
  describe "for :gint32" do
23
- let(:flattened_tag) { :gint32 }
12
+ let(:type_info) { get_introspection_data("GIMarshallingTests",
13
+ "int_return_min").return_type }
24
14
 
25
- it "has no statements in #post" do
26
- builder.post.must_equal []
15
+ it "has no statements in #post_conversion" do
16
+ builder.post_conversion.must_equal []
27
17
  end
28
18
 
29
19
  it "returns the result of the c function directly" do
30
- builder.callarg.must_equal "_v1"
31
- builder.retval.must_equal "_v1"
20
+ builder.capture_variable_name.must_equal "_v1"
21
+ builder.return_value_name.must_equal "_v1"
32
22
  end
33
23
  end
34
24
 
35
25
  describe "for :struct" do
36
- let(:argument_class_name) { 'Bar::Foo' }
37
- let(:flattened_tag) { :struct }
26
+ let(:type_info) { get_method_introspection_data("GIMarshallingTests",
27
+ "BoxedStruct",
28
+ "returnv").return_type }
38
29
 
39
- it "wraps the result in #post" do
40
- builder.callarg.must_equal "_v1"
41
- builder.post.must_equal [ "_v2 = Bar::Foo.wrap(_v1)" ]
30
+ it "wraps the result in #post_conversion" do
31
+ builder.capture_variable_name.must_equal "_v1"
32
+ builder.post_conversion.must_equal [ "_v2 = GIMarshallingTests::BoxedStruct.wrap(_v1)" ]
42
33
  end
43
34
 
44
35
  it "returns the wrapped result" do
45
- builder.callarg.must_equal "_v1"
46
- builder.retval.must_equal "_v2"
36
+ builder.capture_variable_name.must_equal "_v1"
37
+ builder.return_value_name.must_equal "_v2"
47
38
  end
48
39
  end
49
40
 
50
41
  describe "for :union" do
51
- let(:argument_class_name) { 'Bar::Foo' }
52
- let(:flattened_tag) { :union }
42
+ let(:type_info) { get_method_introspection_data("GIMarshallingTests",
43
+ "Union",
44
+ "returnv").return_type }
53
45
 
54
- it "wraps the result in #post" do
55
- builder.callarg.must_equal "_v1"
56
- builder.post.must_equal [ "_v2 = Bar::Foo.wrap(_v1)" ]
46
+ it "wraps the result in #post_conversion" do
47
+ builder.capture_variable_name.must_equal "_v1"
48
+ builder.post_conversion.must_equal [ "_v2 = GIMarshallingTests::Union.wrap(_v1)" ]
57
49
  end
58
50
 
59
51
  it "returns the wrapped result" do
60
- builder.callarg.must_equal "_v1"
61
- builder.retval.must_equal "_v2"
52
+ builder.capture_variable_name.must_equal "_v1"
53
+ builder.return_value_name.must_equal "_v2"
62
54
  end
63
55
  end
64
56
 
65
57
  describe "for :interface" do
66
- let(:argument_class_name) { 'Bar::Foo' }
67
- let(:flattened_tag) { :interface }
68
-
69
- describe "when the method is not a constructor" do
70
- let(:for_constructor) { false }
58
+ let(:type_info) { get_method_introspection_data("Gio",
59
+ "File",
60
+ "new_for_commandline_arg").return_type }
71
61
 
72
- it "wraps the result in #post" do
73
- builder.callarg.must_equal "_v1"
74
- builder.post.must_equal [ "_v2 = Bar::Foo.wrap(_v1)" ]
75
- end
76
-
77
- it "returns the wrapped result" do
78
- builder.callarg.must_equal "_v1"
79
- builder.retval.must_equal "_v2"
80
- end
62
+ it "wraps the result in #post_conversion" do
63
+ builder.capture_variable_name.must_equal "_v1"
64
+ builder.post_conversion.must_equal [ "_v2 = Gio::File.wrap(_v1)" ]
81
65
  end
82
66
 
83
- describe "when the method is a constructor" do
84
- let(:for_constructor) { true }
85
-
86
- it "wraps the result in #post" do
87
- builder.callarg.must_equal "_v1"
88
- builder.post.must_equal [ "_v2 = self.constructor_wrap(_v1)" ]
89
- end
90
-
91
- it "returns the wrapped result" do
92
- builder.callarg.must_equal "_v1"
93
- builder.retval.must_equal "_v2"
94
- end
67
+ it "returns the wrapped result" do
68
+ builder.capture_variable_name.must_equal "_v1"
69
+ builder.return_value_name.must_equal "_v2"
95
70
  end
96
71
  end
97
72
 
98
73
  describe "for :object" do
99
- let(:argument_class_name) { 'Bar::Foo' }
100
- let(:flattened_tag) { :object }
101
-
102
74
  describe "when the method is not a constructor" do
75
+ let(:type_info) { get_method_introspection_data("GIMarshallingTests",
76
+ "Object",
77
+ "full_return").return_type }
103
78
  let(:for_constructor) { false }
104
79
 
105
- it "wraps the result in #post" do
106
- builder.callarg.must_equal "_v1"
107
- builder.post.must_equal [ "_v2 = Bar::Foo.wrap(_v1)" ]
80
+ it "wraps the result in #post_conversion" do
81
+ builder.capture_variable_name.must_equal "_v1"
82
+ builder.post_conversion.must_equal [ "_v2 = GIMarshallingTests::Object.wrap(_v1)" ]
108
83
  end
109
84
 
110
85
  it "returns the wrapped result" do
111
- builder.callarg.must_equal "_v1"
112
- builder.retval.must_equal "_v2"
86
+ builder.capture_variable_name.must_equal "_v1"
87
+ builder.return_value_name.must_equal "_v2"
113
88
  end
114
89
  end
115
90
 
116
91
  describe "when the method is a constructor" do
92
+ let(:type_info) { get_method_introspection_data("GIMarshallingTests",
93
+ "Object",
94
+ "new").return_type }
117
95
  let(:for_constructor) { true }
118
96
 
119
- it "wraps the result in #post" do
120
- builder.callarg.must_equal "_v1"
121
- builder.post.must_equal [ "_v2 = self.constructor_wrap(_v1)" ]
97
+ it "wraps the result in #post_conversion" do
98
+ builder.capture_variable_name.must_equal "_v1"
99
+ builder.post_conversion.must_equal [ "_v2 = self.constructor_wrap(_v1)" ]
122
100
  end
123
101
 
124
102
  it "returns the wrapped result" do
125
- builder.callarg.must_equal "_v1"
126
- builder.retval.must_equal "_v2"
103
+ builder.capture_variable_name.must_equal "_v1"
104
+ builder.return_value_name.must_equal "_v2"
127
105
  end
128
106
  end
129
107
  end
130
108
 
131
109
  describe "for :strv" do
132
- let(:argument_class_name) { 'GLib::Strv' }
133
- let(:flattened_tag) { :strv }
110
+ let(:type_info) { get_method_introspection_data("GLib",
111
+ "KeyFile",
112
+ "get_locale_string_list").return_type }
134
113
 
135
- it "wraps the result in #post" do
136
- builder.callarg.must_equal "_v1"
137
- builder.post.must_equal [ "_v2 = GLib::Strv.wrap(_v1)" ]
114
+ it "wraps the result in #post_conversion" do
115
+ builder.capture_variable_name.must_equal "_v1"
116
+ builder.post_conversion.must_equal [ "_v2 = GLib::Strv.wrap(_v1)" ]
138
117
  end
139
118
 
140
119
  it "returns the wrapped result" do
141
- builder.callarg.must_equal "_v1"
142
- builder.retval.must_equal "_v2"
120
+ builder.capture_variable_name.must_equal "_v1"
121
+ builder.return_value_name.must_equal "_v2"
143
122
  end
144
123
  end
145
124
 
146
125
  describe "for :zero_terminated" do
147
- let(:argument_class_name) { 'GirFFI::ZeroTerminated' }
148
- let(:conversion_arguments) { [:foo] }
149
- let(:flattened_tag) { :zero_terminated }
126
+ let(:type_info) { get_method_introspection_data("GLib",
127
+ "Variant",
128
+ "dup_bytestring").return_type }
129
+ before do
130
+ skip unless type_info.zero_terminated?
131
+ end
150
132
 
151
- it "wraps the result in #post" do
152
- builder.callarg.must_equal "_v1"
153
- builder.post.must_equal [ "_v2 = GirFFI::ZeroTerminated.wrap(:foo, _v1)" ]
133
+ it "wraps the result in #post_conversion" do
134
+ builder.capture_variable_name.must_equal "_v1"
135
+ builder.post_conversion.must_equal [ "_v2 = GirFFI::ZeroTerminated.wrap(:guint8, _v1)" ]
154
136
  end
155
137
 
156
138
  it "returns the wrapped result" do
157
- builder.callarg.must_equal "_v1"
158
- builder.retval.must_equal "_v2"
139
+ builder.capture_variable_name.must_equal "_v1"
140
+ builder.return_value_name.must_equal "_v2"
159
141
  end
160
142
  end
161
143
 
162
144
  describe "for :byte_array" do
163
- let(:argument_class_name) { 'GLib::ByteArray' }
164
- let(:flattened_tag) { :byte_array }
145
+ let(:type_info) { get_introspection_data("GIMarshallingTests",
146
+ "bytearray_full_return").return_type }
165
147
 
166
- it "wraps the result in #post" do
167
- builder.callarg.must_equal "_v1"
168
- builder.post.must_equal [ "_v2 = GLib::ByteArray.wrap(_v1)" ]
148
+ it "wraps the result in #post_conversion" do
149
+ builder.capture_variable_name.must_equal "_v1"
150
+ builder.post_conversion.must_equal [ "_v2 = GLib::ByteArray.wrap(_v1)" ]
169
151
  end
170
152
 
171
153
  it "returns the wrapped result" do
172
- builder.callarg.must_equal "_v1"
173
- builder.retval.must_equal "_v2"
154
+ builder.capture_variable_name.must_equal "_v1"
155
+ builder.return_value_name.must_equal "_v2"
174
156
  end
175
157
  end
176
158
 
177
159
  describe "for :ptr_array" do
178
- let(:argument_class_name) { 'GLib::PtrArray' }
179
- let(:conversion_arguments) { [:foo] }
180
- let(:flattened_tag) { :ptr_array }
160
+ let(:type_info) { get_introspection_data("GIMarshallingTests",
161
+ "gptrarray_utf8_none_return").return_type }
181
162
 
182
- it "wraps the result in #post" do
183
- builder.callarg.must_equal "_v1"
184
- builder.post.must_equal [ "_v2 = GLib::PtrArray.wrap(:foo, _v1)" ]
163
+ it "wraps the result in #post_conversion" do
164
+ builder.capture_variable_name.must_equal "_v1"
165
+ builder.post_conversion.must_equal [ "_v2 = GLib::PtrArray.wrap(:utf8, _v1)" ]
185
166
  end
186
167
 
187
168
  it "returns the wrapped result" do
188
- builder.callarg.must_equal "_v1"
189
- builder.retval.must_equal "_v2"
169
+ builder.capture_variable_name.must_equal "_v1"
170
+ builder.return_value_name.must_equal "_v2"
190
171
  end
191
172
  end
192
173
 
193
174
  describe "for :glist" do
194
- let(:argument_class_name) { 'GLib::List' }
195
- let(:conversion_arguments) { [:foo] }
196
- let(:flattened_tag) { :glist }
175
+ let(:type_info) { get_introspection_data("GIMarshallingTests",
176
+ "glist_int_none_return").return_type }
197
177
 
198
- it "wraps the result in #post" do
199
- builder.callarg.must_equal "_v1"
200
- builder.post.must_equal [ "_v2 = GLib::List.wrap(:foo, _v1)" ]
178
+ it "wraps the result in #post_conversion" do
179
+ builder.capture_variable_name.must_equal "_v1"
180
+ builder.post_conversion.must_equal [ "_v2 = GLib::List.wrap(:gint32, _v1)" ]
201
181
  end
202
182
 
203
183
  it "returns the wrapped result" do
204
- builder.callarg.must_equal "_v1"
205
- builder.retval.must_equal "_v2"
184
+ builder.capture_variable_name.must_equal "_v1"
185
+ builder.return_value_name.must_equal "_v2"
206
186
  end
207
187
  end
208
188
 
209
189
  describe "for :gslist" do
210
- let(:argument_class_name) { 'GLib::SList' }
211
- let(:conversion_arguments) { [:foo] }
212
- let(:flattened_tag) { :gslist }
190
+ let(:type_info) { get_introspection_data("GIMarshallingTests",
191
+ "gslist_int_none_return").return_type }
213
192
 
214
- it "wraps the result in #post" do
215
- builder.callarg.must_equal "_v1"
216
- builder.post.must_equal [ "_v2 = GLib::SList.wrap(:foo, _v1)" ]
193
+ it "wraps the result in #post_conversion" do
194
+ builder.capture_variable_name.must_equal "_v1"
195
+ builder.post_conversion.must_equal [ "_v2 = GLib::SList.wrap(:gint32, _v1)" ]
217
196
  end
218
197
 
219
198
  it "returns the wrapped result" do
220
- builder.callarg.must_equal "_v1"
221
- builder.retval.must_equal "_v2"
199
+ builder.capture_variable_name.must_equal "_v1"
200
+ builder.return_value_name.must_equal "_v2"
222
201
  end
223
202
  end
224
203
 
225
204
  describe "for :ghash" do
226
- let(:argument_class_name) { 'GLib::HashTable' }
227
- let(:conversion_arguments) { [[:foo, :bar]] }
228
- let(:flattened_tag) { :ghash }
205
+ let(:type_info) { get_introspection_data("GIMarshallingTests",
206
+ "ghashtable_int_none_return").return_type }
229
207
 
230
- it "wraps the result in #post" do
231
- builder.callarg.must_equal "_v1"
232
- builder.post.must_equal [ "_v2 = GLib::HashTable.wrap([:foo, :bar], _v1)" ]
208
+ it "wraps the result in #post_conversion" do
209
+ builder.capture_variable_name.must_equal "_v1"
210
+ builder.post_conversion.must_equal [ "_v2 = GLib::HashTable.wrap([:gint32, :gint32], _v1)" ]
233
211
  end
234
212
 
235
213
  it "returns the wrapped result" do
236
- builder.callarg.must_equal "_v1"
237
- builder.retval.must_equal "_v2"
214
+ builder.capture_variable_name.must_equal "_v1"
215
+ builder.return_value_name.must_equal "_v2"
238
216
  end
239
217
  end
240
218
 
241
219
  describe "for :array" do
242
- let(:argument_class_name) { 'GLib::Array' }
243
- let(:conversion_arguments) { [:foo] }
244
- let(:flattened_tag) { :array }
220
+ let(:type_info) { get_introspection_data("GIMarshallingTests",
221
+ "garray_int_none_return").return_type }
222
+
245
223
 
246
- it "wraps the result in #post" do
247
- builder.callarg.must_equal "_v1"
248
- builder.post.must_equal [ "_v2 = GLib::Array.wrap(:foo, _v1)" ]
224
+ it "wraps the result in #post_conversion" do
225
+ builder.capture_variable_name.must_equal "_v1"
226
+ builder.post_conversion.must_equal [ "_v2 = GLib::Array.wrap(:gint32, _v1)" ]
249
227
  end
250
228
 
251
229
  it "returns the wrapped result" do
252
- builder.callarg.must_equal "_v1"
253
- builder.retval.must_equal "_v2"
230
+ builder.capture_variable_name.must_equal "_v1"
231
+ builder.return_value_name.must_equal "_v2"
254
232
  end
255
233
  end
256
234
 
257
235
  describe "for :error" do
258
- let(:argument_class_name) { 'GLib::Error' }
259
- let(:flattened_tag) { :error }
236
+ let(:type_info) { get_introspection_data("GIMarshallingTests",
237
+ "gerror_return").return_type }
260
238
 
261
- it "wraps the result in #post" do
262
- builder.callarg.must_equal "_v1"
263
- builder.post.must_equal [ "_v2 = GLib::Error.wrap(_v1)" ]
239
+ it "wraps the result in #post_conversion" do
240
+ builder.capture_variable_name.must_equal "_v1"
241
+ builder.post_conversion.must_equal [ "_v2 = GLib::Error.wrap(_v1)" ]
264
242
  end
265
243
 
266
244
  it "returns the wrapped result" do
267
- builder.callarg.must_equal "_v1"
268
- builder.retval.must_equal "_v2"
245
+ builder.capture_variable_name.must_equal "_v1"
246
+ builder.return_value_name.must_equal "_v2"
269
247
  end
270
248
  end
271
249
 
272
250
  describe "for :c" do
273
- let(:argument_class_name) { 'GLib::SizedArray' }
274
-
275
251
  describe "with fixed size" do
276
- before do
277
- stub(type_info).flattened_tag { :c }
278
- stub(type_info).subtype_tag_or_class { :foo }
279
- stub(type_info).array_fixed_size { 3 }
280
- end
252
+ let(:type_info) { get_introspection_data("GIMarshallingTests",
253
+ "array_fixed_int_return").return_type }
281
254
 
282
- it "converts the result in #post" do
283
- builder.callarg.must_equal "_v1"
284
- builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:foo, 3, _v1)" ]
255
+ it "converts the result in #post_conversion" do
256
+ builder.capture_variable_name.must_equal "_v1"
257
+ builder.post_conversion.must_equal [ "_v2 = GirFFI::SizedArray.wrap(:gint32, 4, _v1)" ]
285
258
  end
286
259
 
287
260
  it "returns the wrapped result" do
288
- builder.callarg.must_equal "_v1"
289
- builder.retval.must_equal "_v2"
261
+ builder.capture_variable_name.must_equal "_v1"
262
+ builder.return_value_name.must_equal "_v2"
290
263
  end
291
264
  end
292
265
 
293
266
  describe "with separate size parameter" do
294
267
  let(:length_argument) { Object.new }
268
+ let(:type_info) { get_method_introspection_data("GIMarshallingTests",
269
+ "Object",
270
+ "method_array_return").return_type }
295
271
 
296
272
  before do
297
- stub(type_info).flattened_tag { :c }
298
- stub(type_info).subtype_tag_or_class { :foo }
299
- stub(type_info).array_fixed_size { -1 }
300
-
301
- stub(length_argument).retname { "bar" }
273
+ stub(length_argument).post_converted_name { "bar" }
302
274
  builder.length_arg = length_argument
303
275
  end
304
276
 
305
- it "converts the result in #post" do
306
- builder.callarg.must_equal "_v1"
307
- builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:foo, bar, _v1)" ]
277
+ it "converts the result in #post_conversion" do
278
+ builder.capture_variable_name.must_equal "_v1"
279
+ builder.post_conversion.must_equal [ "_v2 = GirFFI::SizedArray.wrap(:gint32, bar, _v1)" ]
308
280
  end
309
281
 
310
282
  it "returns the wrapped result" do
311
- builder.callarg.must_equal "_v1"
312
- builder.retval.must_equal "_v2"
283
+ builder.capture_variable_name.must_equal "_v1"
284
+ builder.return_value_name.must_equal "_v2"
313
285
  end
314
286
  end
315
287
  end
316
288
 
317
289
  describe "for :utf8" do
318
- before do
319
- stub(type_info).flattened_tag { :utf8 }
320
- end
290
+ let(:type_info) {
291
+ get_introspection_data("GIMarshallingTests", "utf8_full_return").return_type }
321
292
 
322
- it "converts the result in #post" do
323
- builder.callarg.must_equal "_v1"
324
- builder.post.must_equal [ "_v2 = _v1.to_utf8" ]
293
+ it "converts the result in #post_conversion" do
294
+ builder.capture_variable_name.must_equal "_v1"
295
+ builder.post_conversion.must_equal [ "_v2 = _v1.to_utf8" ]
325
296
  end
326
297
 
327
298
  it "returns the converted result" do
328
- builder.callarg.must_equal "_v1"
329
- builder.retval.must_equal "_v2"
299
+ builder.capture_variable_name.must_equal "_v1"
300
+ builder.return_value_name.must_equal "_v2"
330
301
  end
331
302
  end
332
303
 
333
304
  describe "for :void pointer" do
305
+ let(:callback_info) {
306
+ get_introspection_data("GIMarshallingTests", "CallbackIntInt") }
307
+ let(:type_info) { callback_info.args[1].argument_type }
308
+
334
309
  before do
335
- stub(type_info).flattened_tag { :void }
336
- stub(type_info).pointer? { true }
310
+ skip unless callback_info
337
311
  end
338
312
 
339
- it "has no statements in #post" do
340
- builder.post.must_equal []
313
+ it "has no statements in #post_conversion" do
314
+ builder.post_conversion.must_equal []
341
315
  end
342
316
 
343
317
  it "returns the result of the c function directly" do
344
- builder.callarg.must_equal "_v1"
345
- builder.retval.must_equal "_v1"
318
+ builder.capture_variable_name.must_equal "_v1"
319
+ builder.return_value_name.must_equal "_v1"
346
320
  end
347
321
  end
348
322
 
349
323
  describe "for :void" do
350
- before do
351
- stub(type_info).flattened_tag { :void }
352
- stub(type_info).pointer? { false }
353
- end
324
+ let(:type_info) {
325
+ get_method_introspection_data("Regress", "TestObj", "null_out").return_type }
354
326
 
355
- it "has no statements in #post" do
356
- builder.post.must_equal []
327
+ it "has no statements in #post_conversion" do
328
+ builder.post_conversion.must_equal []
357
329
  end
358
330
 
359
331
  it "marks itself as irrelevant" do
@@ -361,40 +333,36 @@ describe GirFFI::Builders::ReturnValueBuilder do
361
333
  end
362
334
 
363
335
  it "returns nothing" do
364
- builder.retval.must_be_nil
336
+ builder.return_value_name.must_be_nil
365
337
  end
366
338
  end
367
339
 
368
340
  describe "for a closure argument" do
369
- let(:tp_info) {
341
+ let(:type_info) {
370
342
  get_introspection_data("Regress", "TestCallbackUserData").args[0].argument_type }
371
- let(:builder) { GirFFI::Builders::ReturnValueBuilder.new(var_gen, tp_info) }
372
343
 
373
344
  before do
374
345
  builder.is_closure = true
375
346
  end
376
347
 
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]" ]
348
+ it "fetches the stored object in #post_conversion" do
349
+ builder.capture_variable_name.must_equal "_v1"
350
+ builder.post_conversion.must_equal [ "_v2 = GirFFI::ArgHelper::OBJECT_STORE[_v1.address]" ]
380
351
  end
381
352
 
382
353
  it "returns the stored object" do
383
- builder.callarg.must_equal "_v1"
384
- builder.retval.must_equal "_v2"
354
+ builder.capture_variable_name.must_equal "_v1"
355
+ builder.return_value_name.must_equal "_v2"
385
356
  end
386
357
  end
387
358
 
388
359
  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
360
+ let(:type_info) {
361
+ get_method_introspection_data("Regress", "TestObj", "skip_return_val").return_type }
362
+ let(:return_type_info) { GirFFI::ReturnValueInfo.new(type_info, true) }
395
363
 
396
- it "has no statements in #post" do
397
- builder.post.must_equal []
364
+ it "has no statements in #post_conversion" do
365
+ builder.post_conversion.must_equal []
398
366
  end
399
367
 
400
368
  it "marks itself as irrelevant" do
@@ -402,7 +370,7 @@ describe GirFFI::Builders::ReturnValueBuilder do
402
370
  end
403
371
 
404
372
  it "returns nothing" do
405
- builder.retval.must_be_nil
373
+ builder.return_value_name.must_be_nil
406
374
  end
407
375
  end
408
376
  end