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
@@ -9,7 +9,8 @@ describe GObject do
9
9
  it "emits a signal" do
10
10
  a = 1
11
11
  o = Regress::TestSubObj.new
12
- callback = Proc.new { a = 2 }
12
+ prc = proc { a = 2 }
13
+ callback = GObject::Callback.from prc
13
14
  ::GObject::Lib.g_signal_connect_data o, "test", callback, nil, nil, 0
14
15
  GObject.signal_emit o, "test"
15
16
  assert_equal 2, a
@@ -1,7 +1,26 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GirFFI::ArgHelper do
4
- it "has no more tests" do
5
- pass
4
+ describe ".cast_from_pointer" do
5
+ it "handles class types" do
6
+ klass = Class.new
7
+ mock(klass).wrap(:pointer_value) { :wrapped_value }
8
+ GirFFI::ArgHelper.cast_from_pointer(klass, :pointer_value).must_equal :wrapped_value
9
+ end
10
+
11
+ it "handles negative :gint8" do
12
+ ptr = FFI::Pointer.new(-127)
13
+ GirFFI::ArgHelper.cast_from_pointer(:gint8, ptr).must_equal(-127)
14
+ end
15
+
16
+ it "handles positive :gint8" do
17
+ ptr = FFI::Pointer.new(128)
18
+ GirFFI::ArgHelper.cast_from_pointer(:gint8, ptr).must_equal(128)
19
+ end
20
+
21
+ it "handles :guint32" do
22
+ ptr = FFI::Pointer.new(0xffffffff)
23
+ GirFFI::ArgHelper.cast_from_pointer(:guint32, ptr).must_equal(0xffffffff)
24
+ end
6
25
  end
7
26
  end
@@ -1,244 +1,223 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
- # Dummy module
4
- module Bar
5
- module Foo
6
-
7
- end
8
- end
9
-
10
- # NOTE: All cooperating classes were originally stubbed, but this became
11
- # unweildy as functionality was moved between classes. Also, IArgInfo and
12
- # related classes are not really classes controlled by GirFFI, as part of their
13
- # interface is dictated by GIR's implementation. Therefore, these tests are
14
- # being converted to a situation where they test behavior agains real instances
15
- # of IArgInfo.
16
3
  describe GirFFI::Builders::ArgumentBuilder do
17
- let(:argument_info) { Object.new }
18
- let(:type_info) { Object.new }
19
4
  let(:var_gen) { GirFFI::VariableNameGenerator.new }
20
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, argument_info) }
21
- let(:conversion_arguments) { [] }
22
- let(:argument_class_name) { nil }
23
-
24
- before do
25
- stub(argument_info).name { 'foo' }
26
- stub(argument_info).argument_type { type_info }
27
- stub(argument_info).direction { direction }
28
- stub(argument_info).skip? { false }
29
- stub(type_info).argument_class_name { argument_class_name }
30
- stub(type_info).extra_conversion_arguments { conversion_arguments }
31
- end
5
+ let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
32
6
 
33
7
  describe "for an argument with direction :in" do
34
- let(:direction) { :in }
35
-
36
8
  describe "for :callback" do
37
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
38
9
  let(:arg_info) {
39
10
  get_introspection_data('Regress', 'test_callback_destroy_notify').args[0] }
40
11
 
41
- it "has the correct value for #pre" do
42
- builder.pre.must_equal [ "_v1 = ::Regress::TestCallbackUserData.from(callback)" ]
12
+ it "has the correct value for #pre_conversion" do
13
+ builder.pre_conversion.must_equal [ "_v1 = Regress::TestCallbackUserData.from(callback)" ]
43
14
  end
44
15
 
45
- it "has the correct value for #post" do
46
- builder.post.must_equal [ ]
16
+ it "has the correct value for #post_conversion" do
17
+ builder.post_conversion.must_equal [ ]
47
18
  end
48
19
  end
49
20
 
50
21
  describe "for :zero_terminated" do
51
- let(:argument_class_name) { 'GirFFI::ZeroTerminated' }
52
- let(:conversion_arguments) { [:foo] }
22
+ let(:arg_info) { get_introspection_data("GIMarshallingTests",
23
+ "array_in_len_zero_terminated").args[0] }
53
24
 
54
- before do
55
- stub(type_info).flattened_tag { :zero_terminated }
25
+ it "has the correct value for #pre_conversion" do
26
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::ZeroTerminated.from(:gint32, ints)" ]
27
+ end
28
+
29
+ it "has the correct value for #post_conversion" do
30
+ builder.post_conversion.must_equal [ ]
56
31
  end
32
+ end
33
+
34
+ describe "for :void" do
35
+ let(:arg_info) { get_introspection_data("Regress", "test_callback_user_data").args[1] }
36
+
37
+ describe "when it is a regular argument" do
38
+ before do
39
+ builder.is_closure = false
40
+ end
41
+
42
+ it "has the correct value for #pre_conversion" do
43
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InPointer.from(:void, user_data)" ]
44
+ end
57
45
 
58
- it "has the correct value for #pre" do
59
- builder.pre.must_equal [ "_v1 = GirFFI::ZeroTerminated.from(:foo, foo)" ]
46
+ it "has the correct value for #post_conversion" do
47
+ builder.post_conversion.must_equal [ ]
48
+ end
60
49
  end
61
50
 
62
- it "has the correct value for #post" do
63
- builder.post.must_equal [ ]
51
+ describe "when it is a closure" do
52
+ before do
53
+ builder.is_closure = true
54
+ end
55
+
56
+ it "has the correct value for #pre_conversion" do
57
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InPointer.from_closure_data(user_data)" ]
58
+ end
59
+
60
+ it "has the correct value for #post_conversion" do
61
+ builder.post_conversion.must_equal [ ]
62
+ end
64
63
  end
65
64
  end
66
65
  end
67
66
 
68
67
  describe "for an argument with direction :out" do
69
- let(:direction) { :out }
70
-
71
68
  describe "for :enum" do
72
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
73
69
  let(:arg_info) { get_introspection_data("GIMarshallingTests", "genum_out").args[0] }
74
70
 
75
- it "has the correct value for #pre" do
76
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for GIMarshallingTests::GEnum" ]
71
+ it "has the correct value for #pre_conversion" do
72
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for GIMarshallingTests::GEnum" ]
77
73
  end
78
74
 
79
- it "has the correct value for #post" do
80
- builder.post.must_equal [ "_v2 = _v1.to_value" ]
75
+ it "has the correct value for #post_conversion" do
76
+ builder.post_conversion.must_equal [ "_v2 = _v1.to_value" ]
81
77
  end
82
78
  end
83
79
 
84
80
  describe "for :flags" do
85
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
86
81
  let(:arg_info) {
87
82
  get_introspection_data("GIMarshallingTests", "flags_out").args[0] }
88
83
 
89
- it "has the correct value for #pre" do
90
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for GIMarshallingTests::Flags" ]
84
+ it "has the correct value for #pre_conversion" do
85
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for GIMarshallingTests::Flags" ]
91
86
  end
92
87
 
93
- it "has the correct value for #post" do
94
- builder.post.must_equal [ "_v2 = _v1.to_value" ]
88
+ it "has the correct value for #post_conversion" do
89
+ builder.post_conversion.must_equal [ "_v2 = _v1.to_value" ]
95
90
  end
96
91
  end
97
92
 
98
93
  describe "for :object" do
99
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
100
94
  let(:arg_info) {
101
- get_introspection_data("GIMarshallingTests", "param_spec_out").args[0] }
95
+ get_method_introspection_data("Regress", "TestObj", "null_out").args[0] }
102
96
 
103
- before do
104
- # FIXME: Find alternative info that doesn't need a guard.
105
- skip unless get_introspection_data("GIMarshallingTests", "param_spec_out")
106
- end
107
-
108
- it "has the correct value for #pre" do
109
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, GObject::ParamSpec]" ]
97
+ it "has the correct value for #pre_conversion" do
98
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, Regress::TestObj]" ]
110
99
  end
111
100
 
112
- it "has the correct value for #post" do
113
- builder.post.must_equal [ "_v2 = ::GObject::ParamSpec.wrap(_v1.to_value)" ]
101
+ it "has the correct value for #post_conversion" do
102
+ builder.post_conversion.must_equal [ "_v2 = Regress::TestObj.wrap(_v1.to_value)" ]
114
103
  end
115
104
  end
116
105
 
117
106
  describe "for :struct" do
118
- let(:argument_class_name) { 'Bar::Foo' }
119
- before do
120
- stub(type_info).flattened_tag { :struct }
121
- end
122
107
 
123
108
  describe "when not allocated by the caller" do
124
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
125
109
  let(:arg_info) {
126
110
  get_introspection_data("GIMarshallingTests", "boxed_struct_out").args[0] }
127
111
 
128
- it "has the correct value for #pre" do
129
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, GIMarshallingTests::BoxedStruct]" ]
112
+ it "has the correct value for #pre_conversion" do
113
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, GIMarshallingTests::BoxedStruct]" ]
130
114
  end
131
115
 
132
- it "has the correct value for #post" do
133
- builder.post.must_equal [ "_v2 = ::GIMarshallingTests::BoxedStruct.wrap(_v1.to_value)" ]
116
+ it "has the correct value for #post_conversion" do
117
+ builder.post_conversion.must_equal [ "_v2 = GIMarshallingTests::BoxedStruct.wrap(_v1.to_value)" ]
134
118
  end
135
119
  end
136
120
 
137
121
  describe "when allocated by the caller" do
138
- before do
139
- stub(argument_info).caller_allocates? { true }
140
- end
122
+ let(:arg_info) {
123
+ get_method_introspection_data("Regress", "TestStructA", "clone").args[0] }
141
124
 
142
- it "has the correct value for #pre" do
143
- builder.pre.must_equal [ "_v1 = Bar::Foo.new" ]
125
+ it "has the correct value for #pre_conversion" do
126
+ builder.pre_conversion.must_equal [ "_v1 = Regress::TestStructA.new" ]
144
127
  end
145
128
 
146
- it "has the correct value for #post" do
147
- builder.post.must_equal [ "_v2 = _v1" ]
129
+ it "has empty #post_conversion" do
130
+ builder.post_conversion.must_equal []
148
131
  end
149
132
  end
150
133
  end
151
134
 
152
135
  describe "for :strv" do
153
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
154
136
  let(:arg_info) {
155
137
  get_introspection_data("GIMarshallingTests", "gstrv_out").args[0] }
156
138
 
157
- it "has the correct value for #pre" do
158
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :strv]" ]
139
+ it "has the correct value for #pre_conversion" do
140
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :strv]" ]
159
141
  end
160
142
 
161
- it "has the correct value for #post" do
162
- builder.post.must_equal [ "_v2 = GLib::Strv.wrap(_v1.to_value)" ]
143
+ it "has the correct value for #post_conversion" do
144
+ builder.post_conversion.must_equal [ "_v2 = GLib::Strv.wrap(_v1.to_value)" ]
163
145
  end
164
146
  end
165
147
 
166
148
  describe "for :array" do
167
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
168
149
 
169
150
  describe "when allocated by the callee" do
170
151
  let(:arg_info) {
171
152
  get_introspection_data("GIMarshallingTests", "garray_utf8_none_out").args[0] }
172
153
 
173
- it "has the correct value for #pre" do
174
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :array]" ]
154
+ it "has the correct value for #pre_conversion" do
155
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :array]" ]
175
156
  end
176
157
 
177
- it "has the correct value for #post" do
178
- builder.post.must_equal [ "_v2 = GLib::Array.wrap(:utf8, _v1.to_value)" ]
158
+ it "has the correct value for #post_conversion" do
159
+ builder.post_conversion.must_equal [ "_v2 = GLib::Array.wrap(:utf8, _v1.to_value)" ]
179
160
  end
180
161
  end
181
162
 
182
163
  describe "when allocated by the caller" do
183
- let(:arg_info) {
184
- get_introspection_data("GIMarshallingTests", "garray_utf8_full_out_caller_allocated").args[0] }
164
+ let(:function_info) {
165
+ get_introspection_data("GIMarshallingTests", "garray_utf8_full_out_caller_allocated") }
185
166
 
186
- before do
187
- # FIXME: Find alternative info that doesn't need a guard.
188
- skip unless get_introspection_data("GIMarshallingTests", "garray_utf8_full_out_caller_allocated")
189
- end
167
+ let(:arg_info) { function_info.args[0] }
168
+
169
+ before do
170
+ skip unless function_info
171
+ end
190
172
 
191
- it "has the correct value for #pre" do
192
- builder.pre.must_equal [ "_v1 = GLib::Array.new :utf8" ]
173
+ it "has the correct value for #pre_conversion" do
174
+ builder.pre_conversion.must_equal [ "_v1 = GLib::Array.new :utf8" ]
193
175
  end
194
176
 
195
- it "has the correct value for #post" do
196
- builder.post.must_equal [ "_v2 = _v1" ]
177
+ it "has empty #post_conversion" do
178
+ builder.post_conversion.must_equal []
197
179
  end
198
180
  end
199
181
  end
200
182
 
201
183
  describe "for :ptr_array" do
202
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
203
184
  let(:arg_info) {
204
185
  get_introspection_data("GIMarshallingTests", "gptrarray_utf8_none_out").args[0] }
205
186
 
206
- it "has the correct value for #pre" do
207
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :ptr_array]" ]
187
+ it "has the correct value for #pre_conversion" do
188
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :ptr_array]" ]
208
189
  end
209
190
 
210
- it "has the correct value for #post" do
211
- builder.post.must_equal [ "_v2 = GLib::PtrArray.wrap(:utf8, _v1.to_value)" ]
191
+ it "has the correct value for #post_conversion" do
192
+ builder.post_conversion.must_equal [ "_v2 = GLib::PtrArray.wrap(:utf8, _v1.to_value)" ]
212
193
  end
213
194
  end
214
195
 
215
196
  describe "for :error" do
216
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
217
197
  let(:arg_info) {
218
198
  get_introspection_data("GIMarshallingTests", "gerror_out").args[0] }
219
199
 
220
- it "has the correct value for #pre" do
221
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :error]" ]
200
+ it "has the correct value for #pre_conversion" do
201
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :error]" ]
222
202
  end
223
203
 
224
- it "has the correct value for #post" do
225
- builder.post.must_equal [ "_v2 = GLib::Error.wrap(_v1.to_value)" ]
204
+ it "has the correct value for #post_conversion" do
205
+ builder.post_conversion.must_equal [ "_v2 = GLib::Error.wrap(_v1.to_value)" ]
226
206
  end
227
207
  end
228
208
 
229
209
  describe "for :c" do
230
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
231
210
 
232
211
  describe "with fixed size" do
233
212
  let(:arg_info) {
234
213
  get_introspection_data("GIMarshallingTests", "array_fixed_out").args[0] }
235
214
 
236
- it "has the correct value for #pre" do
237
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :c]" ]
215
+ it "has the correct value for #pre_conversion" do
216
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :c]" ]
238
217
  end
239
218
 
240
- it "has the correct value for #post" do
241
- builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:gint32, 4, _v1.to_value)" ]
219
+ it "has the correct value for #post_conversion" do
220
+ builder.post_conversion.must_equal [ "_v2 = GirFFI::SizedArray.wrap(:gint32, 4, _v1.to_value)" ]
242
221
  end
243
222
  end
244
223
 
@@ -248,114 +227,104 @@ describe GirFFI::Builders::ArgumentBuilder do
248
227
 
249
228
  let(:length_argument) { Object.new }
250
229
  before do
251
- stub(length_argument).retname { "bar" }
230
+ stub(length_argument).post_converted_name { "bar" }
252
231
  builder.length_arg = length_argument
253
232
  end
254
233
 
255
- it "has the correct value for #pre" do
256
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :c]" ]
234
+ it "has the correct value for #pre_conversion" do
235
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :c]" ]
257
236
  end
258
237
 
259
- it "has the correct value for #post" do
260
- builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:gint32, bar, _v1.to_value)" ]
238
+ it "has the correct value for #post_conversion" do
239
+ builder.post_conversion.must_equal [ "_v2 = GirFFI::SizedArray.wrap(:gint32, bar, _v1.to_value)" ]
261
240
  end
262
241
  end
263
242
  end
264
243
 
265
244
  describe "for :glist" do
266
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
267
245
  let(:arg_info) {
268
246
  get_introspection_data("GIMarshallingTests", "glist_utf8_none_out").args[0] }
269
247
 
270
- it "has the correct value for #pre" do
271
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :glist]" ]
248
+ it "has the correct value for #pre_conversion" do
249
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :glist]" ]
272
250
  end
273
251
 
274
- it "has the correct value for #post" do
275
- builder.post.must_equal [ "_v2 = GLib::List.wrap(:utf8, _v1.to_value)" ]
252
+ it "has the correct value for #post_conversion" do
253
+ builder.post_conversion.must_equal [ "_v2 = GLib::List.wrap(:utf8, _v1.to_value)" ]
276
254
  end
277
255
  end
278
256
 
279
257
  describe "for :gslist" do
280
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
281
258
  let(:arg_info) {
282
259
  get_introspection_data("GIMarshallingTests", "gslist_utf8_none_out").args[0] }
283
260
 
284
- it "has the correct value for #pre" do
285
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :gslist]" ]
261
+ it "has the correct value for #pre_conversion" do
262
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :gslist]" ]
286
263
  end
287
264
 
288
- it "has the correct value for #post" do
289
- builder.post.must_equal [ "_v2 = GLib::SList.wrap(:utf8, _v1.to_value)" ]
265
+ it "has the correct value for #post_conversion" do
266
+ builder.post_conversion.must_equal [ "_v2 = GLib::SList.wrap(:utf8, _v1.to_value)" ]
290
267
  end
291
268
  end
292
269
 
293
270
  describe "for :ghash" do
294
- let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
295
271
  let(:arg_info) {
296
272
  get_introspection_data("GIMarshallingTests", "ghashtable_utf8_none_out").args[0] }
297
273
 
298
- it "has the correct value for #pre" do
299
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :ghash]" ]
274
+ it "has the correct value for #pre_conversion" do
275
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, [:ghash, :utf8, :utf8]]" ]
300
276
  end
301
277
 
302
- it "has the correct value for #post" do
303
- builder.post.must_equal [ "_v2 = GLib::HashTable.wrap([:utf8, :utf8], _v1.to_value)" ]
278
+ it "has the correct value for #post_conversion" do
279
+ builder.post_conversion.must_equal [ "_v2 = GLib::HashTable.wrap([:utf8, :utf8], _v1.to_value)" ]
304
280
  end
305
281
  end
306
282
  end
307
283
 
308
284
  describe "for an argument with direction :inout" do
309
- let(:direction) { :inout }
310
-
311
285
  describe "for :enum" do
312
- let(:argument_class_name) { 'Bar::Foo' }
313
- before do
314
- stub(type_info).flattened_tag { :enum }
315
- stub(type_info).tag_or_class { Bar::Foo }
316
- end
286
+ let(:arg_info) {
287
+ get_introspection_data("GIMarshallingTests", "enum_inout").args[0] }
317
288
 
318
- it "has the correct value for #pre" do
319
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from Bar::Foo, foo" ]
289
+ it "has the correct value for #pre_conversion" do
290
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for GIMarshallingTests::Enum",
291
+ "_v1.set_value #{arg_info.name}" ]
320
292
  end
321
293
 
322
- it "has the correct value for #post" do
323
- builder.post.must_equal [ "_v2 = _v1.to_value" ]
294
+ it "has the correct value for #post_conversion" do
295
+ builder.post_conversion.must_equal [ "_v2 = _v1.to_value" ]
324
296
  end
325
297
  end
326
298
 
327
299
  describe "for :flags" do
328
- let(:argument_class_name) { 'Bar::Foo' }
329
- before do
330
- stub(type_info).flattened_tag { :flags }
331
- stub(type_info).tag_or_class { Bar::Foo }
332
- end
300
+ let(:arg_info) {
301
+ get_introspection_data("GIMarshallingTests", "no_type_flags_inout").args[0] }
333
302
 
334
- it "has the correct value for #pre" do
335
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from Bar::Foo, foo" ]
303
+ it "has the correct value for #pre_conversion" do
304
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for GIMarshallingTests::NoTypeFlags",
305
+ "_v1.set_value #{arg_info.name}" ]
336
306
  end
337
307
 
338
- it "has the correct value for #post" do
339
- builder.post.must_equal [ "_v2 = _v1.to_value" ]
308
+ it "has the correct value for #post_conversion" do
309
+ builder.post_conversion.must_equal [ "_v2 = _v1.to_value" ]
340
310
  end
341
311
  end
342
312
 
343
313
  describe "for :gint32" do
344
- before do
345
- stub(type_info).flattened_tag { :gint32 }
346
- stub(type_info).tag_or_class { :gint32 }
347
- end
314
+ let(:arg_info) {
315
+ get_introspection_data("GIMarshallingTests", "int32_inout_min_max").args[0] }
348
316
 
349
- it "has the correct value for inarg" do
350
- builder.inarg.must_equal "foo"
317
+ it "has the correct value for method_argument_name" do
318
+ builder.method_argument_name.must_equal "#{arg_info.name}"
351
319
  end
352
320
 
353
- it "has the correct value for #pre" do
354
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from :gint32, foo" ]
321
+ it "has the correct value for #pre_conversion" do
322
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for :gint32",
323
+ "_v1.set_value #{arg_info.name}" ]
355
324
  end
356
325
 
357
- it "has the correct value for #post" do
358
- builder.post.must_equal [ "_v2 = _v1.to_value" ]
326
+ it "has the correct value for #post_conversion" do
327
+ builder.post_conversion.must_equal [ "_v2 = _v1.to_value" ]
359
328
  end
360
329
  end
361
330
 
@@ -364,8 +333,6 @@ describe GirFFI::Builders::ArgumentBuilder do
364
333
  get_introspection_data('Regress', 'test_array_int_inout') }
365
334
  let(:arg_info) { function_info.args[0] }
366
335
  let(:array_arg_info) { function_info.args[1] }
367
- let(:builder) {
368
- GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
369
336
  let(:array_arg_builder) {
370
337
  GirFFI::Builders::ArgumentBuilder.new(var_gen, array_arg_info) }
371
338
 
@@ -373,193 +340,152 @@ describe GirFFI::Builders::ArgumentBuilder do
373
340
  builder.array_arg = array_arg_builder
374
341
  end
375
342
 
376
- it "has the correct value for #pre" do
377
- builder.pre.must_equal [ "n_ints = ints.nil? ? 0 : ints.length",
378
- "_v1 = GirFFI::InOutPointer.from :gint32, n_ints" ]
343
+ it "has the correct value for #pre_conversion" do
344
+ builder.pre_conversion.must_equal [ "n_ints = ints.nil? ? 0 : ints.length",
345
+ "_v1 = GirFFI::InOutPointer.for :gint32",
346
+ "_v1.set_value n_ints" ]
379
347
  end
380
348
 
381
- it "has the correct value for #post" do
382
- builder.post.must_equal [ "_v2 = _v1.to_value" ]
349
+ it "has the correct value for #post_conversion" do
350
+ builder.post_conversion.must_equal [ "_v2 = _v1.to_value" ]
383
351
  end
384
352
  end
385
353
 
386
354
  describe "for :strv" do
387
- let(:argument_class_name) { 'GLib::Strv' }
388
- before do
389
- stub(type_info).flattened_tag { :strv }
390
- stub(type_info).tag_or_class { [:pointer, :array] }
391
- end
355
+ let(:arg_info) {
356
+ get_introspection_data("GIMarshallingTests", "gstrv_inout").args[0] }
392
357
 
393
- it "has the correct value for #pre" do
394
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from [:pointer, :array], GLib::Strv.from(foo)" ]
358
+ it "has the correct value for #pre_conversion" do
359
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :strv]",
360
+ "_v1.set_value GLib::Strv.from(g_strv)" ]
395
361
  end
396
362
 
397
- it "has the correct value for #post" do
398
- builder.post.must_equal [ "_v2 = GLib::Strv.wrap(_v1.to_value)" ]
363
+ it "has the correct value for #post_conversion" do
364
+ builder.post_conversion.must_equal [ "_v2 = GLib::Strv.wrap(_v1.to_value)" ]
399
365
  end
400
366
  end
401
367
 
402
368
  describe "for :ptr_array" do
403
- let(:conversion_arguments) { [:foo] }
404
- let(:argument_class_name) { 'GLib::PtrArray' }
405
-
406
- before do
407
- stub(type_info).flattened_tag { :ptr_array }
408
- stub(type_info).tag_or_class { [:pointer, :array] }
409
- end
369
+ let(:arg_info) {
370
+ get_introspection_data("GIMarshallingTests", "gptrarray_utf8_none_inout").args[0] }
410
371
 
411
- it "has the correct value for #pre" do
412
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from [:pointer, :array], GLib::PtrArray.from(:foo, foo)" ]
372
+ it "has the correct value for #pre_conversion" do
373
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for [:pointer, :ptr_array]",
374
+ "_v1.set_value GLib::PtrArray.from(:utf8, parray_)" ]
413
375
  end
414
376
 
415
- it "has the correct value for #post" do
416
- builder.post.must_equal [ "_v2 = GLib::PtrArray.wrap(:foo, _v1.to_value)" ]
377
+ it "has the correct value for #post_conversion" do
378
+ builder.post_conversion.must_equal [ "_v2 = GLib::PtrArray.wrap(:utf8, _v1.to_value)" ]
417
379
  end
418
380
  end
419
381
 
420
382
  describe "for :utf8" do
421
- let(:conversion_arguments) { [:utf8] }
422
- let(:argument_class_name) { 'GirFFI::InPointer' }
423
-
424
- before do
425
- stub(type_info).flattened_tag { :utf8 }
426
- stub(type_info).tag_or_class { :utf8 }
427
- end
383
+ let(:arg_info) {
384
+ get_introspection_data("GIMarshallingTests", "utf8_none_inout").args[0] }
428
385
 
429
- it "has the correct value for #pre" do
430
- builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.from :utf8, GirFFI::InPointer.from(:utf8, foo)" ]
386
+ it "has the correct value for #pre_conversion" do
387
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for :utf8",
388
+ "_v1.set_value GirFFI::InPointer.from(:utf8, utf8)" ]
431
389
  end
432
390
 
433
- it "has the correct value for #post" do
434
- builder.post.must_equal [ "_v2 = _v1.to_value.to_utf8" ]
391
+ it "has the correct value for #post_conversion" do
392
+ builder.post_conversion.must_equal [ "_v2 = _v1.to_value.to_utf8" ]
435
393
  end
436
394
  end
437
395
 
438
396
  describe "for :c" do
439
- let(:argument_class_name) { 'GLib::SizedArray' }
440
-
441
- before do
442
- stub(type_info).flattened_tag { :c }
443
- stub(type_info).tag_or_class { [:pointer, :c] }
444
- stub(type_info).subtype_tag_or_class { :bar }
445
- end
446
-
447
397
  describe "with fixed size" do
448
- let(:conversion_arguments) { [:bar, 3] }
449
-
450
- before do
451
- stub(type_info).array_fixed_size { 3 }
452
- end
398
+ let(:arg_info) {
399
+ get_introspection_data("GIMarshallingTests", "array_fixed_inout").args[0] }
453
400
 
454
- it "has the correct value for #pre" do
455
- builder.pre.must_equal [
456
- "GirFFI::ArgHelper.check_fixed_array_size 3, foo, \"foo\"",
457
- "_v1 = GirFFI::InOutPointer.from [:pointer, :c], GLib::SizedArray.from(:bar, 3, foo)"
401
+ it "has the correct value for #pre_conversion" do
402
+ builder.pre_conversion.must_equal [
403
+ "GirFFI::ArgHelper.check_fixed_array_size 4, ints, \"ints\"",
404
+ "_v1 = GirFFI::InOutPointer.for [:pointer, :c]",
405
+ "_v1.set_value GirFFI::SizedArray.from(:gint32, 4, ints)"
458
406
  ]
459
407
  end
460
408
 
461
- it "has the correct value for #post" do
462
- builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:bar, 3, _v1.to_value)" ]
409
+ it "has the correct value for #post_conversion" do
410
+ builder.post_conversion.must_equal [ "_v2 = GirFFI::SizedArray.wrap(:gint32, 4, _v1.to_value)" ]
463
411
  end
464
412
  end
465
413
 
466
414
  describe "with separate size parameter" do
467
- let(:length_argument) { Object.new }
468
- let(:conversion_arguments) { [:bar, -1] }
415
+ let(:function_info) {
416
+ get_introspection_data('Regress', 'test_array_int_inout') }
417
+ let(:length_arg_info) { function_info.args[0] }
418
+ let(:arg_info) { function_info.args[1] }
419
+ let(:length_arg_builder) {
420
+ GirFFI::Builders::ArgumentBuilder.new(var_gen, length_arg_info) }
421
+
469
422
  before do
470
- stub(type_info).array_fixed_size { -1 }
471
- stub(length_argument).retname { "baz" }
472
- builder.length_arg = length_argument
423
+ builder.length_arg = length_arg_builder
473
424
  end
474
425
 
475
- it "has the correct value for #pre" do
476
- builder.pre.must_equal [
477
- "_v1 = GirFFI::InOutPointer.from [:pointer, :c], GLib::SizedArray.from(:bar, -1, foo)"
426
+ it "has the correct value for #pre_conversion" do
427
+ builder.pre_conversion.must_equal [
428
+ "_v1 = GirFFI::InOutPointer.for [:pointer, :c]",
429
+ "_v1.set_value GirFFI::SizedArray.from(:gint32, -1, ints)"
478
430
  ]
479
431
  end
480
432
 
481
- it "has the correct value for #post" do
482
- builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:bar, baz, _v1.to_value)" ]
433
+ it "has the correct value for #post_conversion" do
434
+ builder.post_conversion.must_equal [ "_v3 = GirFFI::SizedArray.wrap(:gint32, _v2, _v1.to_value)" ]
483
435
  end
484
436
  end
485
437
  end
486
438
  end
487
439
 
488
440
  describe "for a skipped argument with direction :in" do
489
- let(:direction) { :in }
441
+ let(:arg_info) {
442
+ get_method_introspection_data("Regress", "TestObj", "skip_param").args[2] }
490
443
 
491
- before do
492
- stub(argument_info).skip? { true }
444
+ it "has the correct value for method_argument_name" do
445
+ builder.method_argument_name.must_be_nil
493
446
  end
494
447
 
495
- describe "for :gint32" do
496
- before do
497
- stub(type_info).flattened_tag { :gint32 }
498
- end
499
-
500
- it "has the correct value for inarg" do
501
- builder.inarg.must_be_nil
502
- end
503
-
504
- it "has the correct value for #pre" do
505
- builder.pre.must_equal [ "_v1 = 0" ]
506
- end
448
+ it "has the correct value for #pre_conversion" do
449
+ builder.pre_conversion.must_equal [ "_v1 = 0" ]
450
+ end
507
451
 
508
- it "has the correct value for #post" do
509
- builder.post.must_equal []
510
- end
452
+ it "has the correct value for #post_conversion" do
453
+ builder.post_conversion.must_equal []
511
454
  end
512
455
  end
513
456
 
514
457
  describe "for a skipped argument with direction :inout" do
515
- let(:direction) { :inout }
458
+ let(:arg_info) {
459
+ get_method_introspection_data("Regress", "TestObj", "skip_inout_param").args[3] }
516
460
 
517
- before do
518
- stub(argument_info).skip? { true }
461
+ it "has the correct value for method_argument_name" do
462
+ builder.method_argument_name.must_be_nil
519
463
  end
520
464
 
521
- describe "for :gint32" do
522
- before do
523
- stub(type_info).flattened_tag { :gint32 }
524
- end
525
-
526
- it "has the correct value for inarg" do
527
- builder.inarg.must_be_nil
528
- end
529
-
530
- it "has the correct value for #pre" do
531
- builder.pre.must_equal [ "_v1 = nil" ]
532
- end
465
+ it "has the correct value for #pre_conversion" do
466
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for :gint32",
467
+ "_v1.set_value 0" ]
468
+ end
533
469
 
534
- it "has the correct value for #post" do
535
- builder.post.must_equal []
536
- end
470
+ it "has the correct value for #post_conversion" do
471
+ builder.post_conversion.must_equal []
537
472
  end
538
473
  end
539
474
 
540
475
  describe "for a skipped argument with direction :out" do
541
- let(:direction) { :out }
476
+ let(:arg_info) {
477
+ get_method_introspection_data("Regress", "TestObj", "skip_out_param").args[1] }
542
478
 
543
- before do
544
- stub(argument_info).skip? { true }
479
+ it "has the correct value for method_argument_name" do
480
+ builder.method_argument_name.must_be_nil
545
481
  end
546
482
 
547
- describe "for :gint32" do
548
- before do
549
- stub(type_info).flattened_tag { :gint32 }
550
- end
551
-
552
- it "has the correct value for inarg" do
553
- builder.inarg.must_be_nil
554
- end
555
-
556
- it "has the correct value for #pre" do
557
- builder.pre.must_equal [ "_v1 = nil" ]
558
- end
483
+ it "has the correct value for #pre_conversion" do
484
+ builder.pre_conversion.must_equal [ "_v1 = GirFFI::InOutPointer.for :gint32" ]
485
+ end
559
486
 
560
- it "has the correct value for #post" do
561
- builder.post.must_equal []
562
- end
487
+ it "has the correct value for #post_conversion" do
488
+ builder.post_conversion.must_equal []
563
489
  end
564
490
  end
565
491
  end