gir_ffi 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/History.txt +7 -0
  2. data/{README.rdoc → README.md} +31 -25
  3. data/Rakefile +1 -1
  4. data/TODO.rdoc +1 -1
  5. data/lib/ffi-glib.rb +5 -5
  6. data/lib/ffi-glib/container_class_methods.rb +1 -2
  7. data/lib/ffi-glib/list_methods.rb +16 -6
  8. data/lib/ffi-gobject.rb +4 -7
  9. data/lib/ffi-gobject/helper.rb +6 -6
  10. data/lib/ffi-gobject/object.rb +4 -4
  11. data/lib/ffi-gobject_introspection.rb +0 -1
  12. data/lib/ffi-gobject_introspection/g_error.rb +15 -5
  13. data/lib/ffi-gobject_introspection/i_base_info.rb +7 -4
  14. data/lib/ffi-gobject_introspection/i_function_info.rb +3 -1
  15. data/lib/ffi-gobject_introspection/i_repository.rb +8 -15
  16. data/lib/ffi-gobject_introspection/i_struct_info.rb +5 -10
  17. data/lib/gir_ffi-base.rb +2 -0
  18. data/lib/gir_ffi-base/glib/strv.rb +43 -0
  19. data/lib/{ffi-gobject_introspection/gobject_lib.rb → gir_ffi-base/gobject/lib.rb} +4 -2
  20. data/lib/gir_ffi/arg_helper.rb +4 -2
  21. data/lib/gir_ffi/builder.rb +1 -7
  22. data/lib/gir_ffi/builder/argument.rb +34 -108
  23. data/lib/gir_ffi/builder/argument/base.rb +26 -20
  24. data/lib/gir_ffi/builder/type/object.rb +14 -2
  25. data/lib/gir_ffi/builder/type/registered_type.rb +1 -11
  26. data/lib/gir_ffi/class_base.rb +21 -26
  27. data/lib/gir_ffi/in_pointer.rb +11 -5
  28. data/lib/gir_ffi/info_ext/i_type_info.rb +26 -0
  29. data/lib/gir_ffi/interface_base.rb +10 -0
  30. data/lib/gir_ffi/module_base.rb +14 -4
  31. data/lib/gir_ffi/object_base.rb +39 -0
  32. data/lib/gir_ffi/type_map.rb +1 -3
  33. data/lib/gir_ffi/version.rb +1 -1
  34. data/tasks/test.rake +33 -44
  35. data/test/{test_helper.rb → base_test_helper.rb} +2 -11
  36. data/test/ffi-glib/array_test.rb +1 -1
  37. data/test/ffi-glib/byte_array_test.rb +1 -1
  38. data/test/ffi-glib/hash_table_test.rb +30 -1
  39. data/test/ffi-glib/list_test.rb +1 -1
  40. data/test/ffi-glib/ptr_array_test.rb +1 -1
  41. data/test/ffi-glib/ruby_closure_test.rb +54 -0
  42. data/test/ffi-glib/s_list_test.rb +1 -1
  43. data/test/ffi-gobject/gobject_test.rb +1 -1
  44. data/test/ffi-gobject/helper_test.rb +103 -0
  45. data/test/ffi-gobject/object_class_test.rb +1 -1
  46. data/test/ffi-gobject/object_test.rb +1 -1
  47. data/test/ffi-gobject/ruby_style_test.rb +1 -1
  48. data/test/ffi-gobject/value_test.rb +1 -1
  49. data/test/ffi-gobject_introspection/i_base_info_test.rb +1 -1
  50. data/test/ffi-gobject_introspection/i_constant_info_test.rb +1 -1
  51. data/test/ffi-gobject_introspection/i_function_info_test.rb +1 -1
  52. data/test/ffi-gobject_introspection/i_object_info_test.rb +1 -1
  53. data/test/ffi-gobject_introspection/i_repository_test.rb +1 -1
  54. data/test/ffi-gobject_introspection/lib_test.rb +1 -1
  55. data/test/ffi-gobject_test.rb +120 -0
  56. data/test/{ffi-glib → gir_ffi-base/glib}/strv_test.rb +8 -5
  57. data/test/{unit → gir_ffi}/arg_helper_test.rb +2 -2
  58. data/test/{unit/argument_builder_test.rb → gir_ffi/builder/argument/base_test.rb} +1 -13
  59. data/test/{unit/function_builder_test.rb → gir_ffi/builder/function_test.rb} +2 -2
  60. data/test/{unit/module_builder_test.rb → gir_ffi/builder/module_test.rb} +1 -1
  61. data/test/{unit/callback_builder_test.rb → gir_ffi/builder/type/callback_test.rb} +1 -1
  62. data/test/{unit/constant_builder_test.rb → gir_ffi/builder/type/constant_test.rb} +1 -1
  63. data/test/{unit/enum_builder_test.rb → gir_ffi/builder/type/enum_test.rb} +1 -1
  64. data/test/{unit/interface_builder_test.rb → gir_ffi/builder/type/interface_test.rb} +1 -4
  65. data/test/{unit/object_type_builder_test.rb → gir_ffi/builder/type/object_test.rb} +21 -2
  66. data/test/{unit/struct_builder_test.rb → gir_ffi/builder/type/struct_test.rb} +1 -1
  67. data/test/{unit/unintrospectable_type_builder_test.rb → gir_ffi/builder/type/unintrospectable_test.rb} +1 -1
  68. data/test/{unit/union_builder_test.rb → gir_ffi/builder/type/union_test.rb} +9 -3
  69. data/test/{unit/user_defined_type_builder_test.rb → gir_ffi/builder/type/user_defined_test.rb} +4 -2
  70. data/test/gir_ffi/builder_test.rb +398 -0
  71. data/test/{unit → gir_ffi}/callback_helper_test.rb +1 -1
  72. data/test/{unit → gir_ffi}/class_base_test.rb +1 -1
  73. data/test/{unit → gir_ffi}/in_out_pointer_test.rb +1 -1
  74. data/test/{unit → gir_ffi}/in_pointer_test.rb +24 -3
  75. data/test/{unit → gir_ffi/info_ext}/i_field_info_test.rb +1 -1
  76. data/test/gir_ffi/info_ext/i_type_info_test.rb +71 -0
  77. data/test/{unit/user_defined_object_info_test.rb → gir_ffi/user_defined/i_object_info_test.rb} +1 -1
  78. data/test/{unit/user_defined_property_info_test.rb → gir_ffi/user_defined/i_property_info_test.rb} +1 -1
  79. data/test/{unit/user_defined_registered_type_info_test.rb → gir_ffi/user_defined/i_registered_type_info_test.rb} +1 -1
  80. data/test/{unit → gir_ffi}/variable_name_generator_test.rb +1 -1
  81. data/test/{unit/gir_ffi_test.rb → gir_ffi_test.rb} +24 -4
  82. data/test/gir_ffi_test_helper.rb +1 -1
  83. data/test/integration/derived_classes_test.rb +1 -1
  84. data/test/integration/generated_gimarshallingtests_test.rb +1 -1
  85. data/test/integration/generated_gio_test.rb +1 -1
  86. data/test/integration/generated_gobject_test.rb +1 -1
  87. data/test/integration/generated_regress_test.rb +2 -3
  88. data/test/integration/method_lookup_test.rb +1 -1
  89. data/test/integration/pretty_print_test.rb +1 -1
  90. data/test/introspection_test_helper.rb +11 -0
  91. metadata +71 -77
  92. data/lib/ffi-glib/strv.rb +0 -31
  93. data/test/builder_test.rb +0 -264
  94. data/test/ffi-glib/glib_overrides_test.rb +0 -38
  95. data/test/ffi-gobject/g_object_overrides_test.rb +0 -274
  96. data/test/girffi_test.rb +0 -27
  97. data/test/integration/generated_pango_test.rb +0 -20
  98. data/test/type_builder_test.rb +0 -36
  99. data/test/unit/builder_test.rb +0 -143
  100. data/test/unit/hash_table_element_type_provider_test.rb +0 -16
  101. data/test/unit/i_type_info_test.rb +0 -23
  102. data/test/unit/list_element_type_provider_test.rb +0 -13
@@ -1,31 +0,0 @@
1
- module GLib
2
- # Represents a null-terminated array of strings.
3
- class Strv
4
- include Enumerable
5
-
6
- POINTER_SIZE = FFI.type_size(:pointer)
7
-
8
- def initialize ptr
9
- @ptr = ptr
10
- end
11
-
12
- def to_ptr
13
- @ptr
14
- end
15
-
16
- def each
17
- return if @ptr.null?
18
- offset = 0
19
- loop do
20
- ptr = @ptr.get_pointer offset
21
- break if ptr.null?
22
- yield ptr.read_string
23
- offset += POINTER_SIZE
24
- end
25
- end
26
-
27
- def self.wrap ptr
28
- self.new ptr
29
- end
30
- end
31
- end
@@ -1,264 +0,0 @@
1
- require File.expand_path('gir_ffi_test_helper.rb', File.dirname(__FILE__))
2
-
3
- class BuilderTest < MiniTest::Spec
4
- context "The GirFFI::Builder module" do
5
- setup do
6
- @gir = GObjectIntrospection::IRepository.default
7
- end
8
-
9
- context "building GObject::Object" do
10
- before do
11
- save_module :GObject
12
- GirFFI::Builder.build_class get_introspection_data('GObject', 'Object')
13
- end
14
-
15
- should "create a Lib module in the parent namespace ready to attach functions from gobject-2.0" do
16
- expected = @gir.shared_library('GObject')
17
- assert_equal [expected], GObject::Lib.ffi_libraries.map(&:name)
18
- end
19
-
20
- should "create an array CALLBACKS inside the GObject::Lib module" do
21
- assert_equal [], GObject::Lib::CALLBACKS
22
- end
23
-
24
- should "not replace existing classes" do
25
- oldclass = GObject::Object
26
- GirFFI::Builder.build_class get_introspection_data('GObject', 'Object')
27
- assert_equal oldclass, GObject::Object
28
- end
29
-
30
- after do
31
- restore_module :GObject
32
- end
33
- end
34
-
35
- context "looking at Regress.test_callback_destroy_notify" do
36
- before do
37
- save_module :GLib
38
- save_module :GObject
39
- save_module :Regress
40
- GirFFI::Builder.build_module 'GLib'
41
- GirFFI::Builder.build_module 'GObject'
42
- GirFFI::Builder.build_module 'Regress'
43
- @go = get_introspection_data 'Regress', 'test_callback_destroy_notify'
44
- end
45
-
46
- should "have the correct types of the arguments for the attached function" do
47
- argtypes = GirFFI::Builder.send(:ffi_function_argument_types, @go)
48
- assert_equal [Regress::TestCallbackUserData, :pointer, GLib::DestroyNotify],
49
- argtypes
50
- end
51
-
52
- should "define ffi callback types :Callback and :ClosureNotify" do
53
- Regress._setup_method 'test_callback_destroy_notify'
54
- tcud = Regress::Lib.find_type :TestCallbackUserData
55
- dn = GLib::Lib.find_type :DestroyNotify
56
-
57
- assert_equal FFI.find_type(:int32), tcud.result_type
58
- assert_equal FFI.find_type(:void), dn.result_type
59
- assert_equal [FFI.find_type(:pointer)], tcud.param_types
60
- assert_equal [FFI.find_type(:pointer)], dn.param_types
61
- end
62
-
63
- # FIXME: Test passes but does not test what it claims to test.
64
- should "define ffi enum type ConnectFlags" do
65
- assert_equal({:after => 1, :swapped => 2}, GObject::ConnectFlags.to_h)
66
- end
67
-
68
- after do
69
- restore_module :Regress
70
- restore_module :GObject
71
- restore_module :GLib
72
- end
73
- end
74
-
75
- context "building Regress::TestStructA" do
76
- setup do
77
- GirFFI::Builder.build_class get_introspection_data('Regress', 'TestStructA')
78
- end
79
-
80
- should "set up the correct struct members" do
81
- assert_equal [:some_int, :some_int8, :some_double, :some_enum],
82
- Regress::TestStructA::Struct.members
83
- end
84
-
85
- should "set up struct members with the correct offset" do
86
- info = @gir.find_by_name 'Regress', 'TestStructA'
87
- assert_equal info.fields.map{|f| [f.name.to_sym, f.offset]},
88
- Regress::TestStructA::Struct.offsets
89
- end
90
-
91
- should "set up struct members with the correct types" do
92
- tags = [:int, :int8, :double, Regress::TestEnum]
93
- assert_equal tags.map {|t| FFI.find_type t},
94
- Regress::TestStructA::Struct.layout.fields.map {|f| f.type}
95
- end
96
- end
97
-
98
- context "building GObject::TypeCValue" do
99
- setup do
100
- GirFFI::Builder.build_class get_introspection_data('GObject', 'TypeCValue')
101
- end
102
-
103
- should "set up the correct union members" do
104
- assert_equal [:v_int, :v_long, :v_int64, :v_double, :v_pointer],
105
- GObject::TypeCValue::Struct.members
106
- end
107
-
108
- should "set up union members with the correct offset" do
109
- assert_equal [0, 0, 0, 0, 0],
110
- GObject::TypeCValue::Struct.offsets.map {|o| o[1]}
111
- end
112
-
113
- should "set up the inner class as derived from FFI::Union" do
114
- assert_equal FFI::Union, GObject::TypeCValue::Struct.superclass
115
- end
116
- end
117
-
118
- context "building GObject::ValueArray" do
119
- should "use provided constructor if present" do
120
- GirFFI::Builder.build_class get_introspection_data('GObject', 'ValueArray')
121
- assert_nothing_raised {
122
- GObject::ValueArray.new 2
123
- }
124
- end
125
- end
126
-
127
- context "building Regress::TestBoxed" do
128
- setup do
129
- GirFFI::Builder.build_class get_introspection_data('Regress', 'TestBoxed')
130
- end
131
-
132
- should "set up #wrap" do
133
- assert Regress::TestBoxed.respond_to? "wrap"
134
- end
135
-
136
- should "set up #allocate" do
137
- assert Regress::TestBoxed.respond_to? "allocate"
138
- end
139
- end
140
-
141
- context "built Regress module" do
142
- before do
143
- save_module :Regress
144
- GirFFI::Builder.build_module 'Regress'
145
- end
146
-
147
- should "autocreate singleton methods" do
148
- refute_defines_singleton_method Regress, :test_uint
149
- Regress.test_uint 31
150
- assert_defines_singleton_method Regress, :test_uint
151
- end
152
-
153
- should "autocreate the TestObj class" do
154
- assert !Regress.const_defined?(:TestObj)
155
- assert_nothing_raised {Regress::TestObj}
156
- assert Regress.const_defined? :TestObj
157
- end
158
-
159
- should "know its own module builder" do
160
- assert GirFFI::Builder::Module === Regress._builder
161
- end
162
-
163
- after do
164
- restore_module :Regress
165
- end
166
- end
167
-
168
- context "built Regress::TestObj" do
169
- before do
170
- save_module :Regress
171
- GirFFI::Builder.build_class get_introspection_data('Regress', 'TestObj')
172
- end
173
-
174
- should "make autocreated instance method available to all instances" do
175
- o1 = Regress::TestObj.new_from_file("foo")
176
- o2 = Regress::TestObj.new_from_file("foo")
177
- o1.instance_method
178
- Regress::TestObj.class_eval do
179
- undef method_missing
180
- end
181
- assert_nothing_raised { o2.instance_method }
182
- end
183
-
184
- should "attach C functions to Regress::Lib" do
185
- o = Regress::TestObj.new_from_file("foo")
186
- o.instance_method
187
- assert Regress::Lib.respond_to? :regress_test_obj_instance_method
188
- end
189
-
190
- should "know its own GIR info" do
191
- assert_equal 'TestObj', Regress::TestObj.gir_info.name
192
- end
193
-
194
- should "know its own class builder" do
195
- assert GirFFI::Builder::Type::Base === Regress::TestObj._builder
196
- end
197
-
198
- context "its #torture_signature_0 method" do
199
- should "have the correct types of the arguments for the attached function" do
200
- info = get_method_introspection_data 'Regress', 'TestObj',
201
- 'torture_signature_0'
202
- assert_equal [:pointer, :int32, :pointer, :pointer, :pointer, :pointer, :uint32],
203
- GirFFI::Builder.send(:ffi_function_argument_types, info)
204
- end
205
- end
206
-
207
- after do
208
- restore_module :Regress
209
- end
210
- end
211
-
212
- context "built Regress::TestSubObj" do
213
- before do
214
- save_module :Regress
215
- GirFFI::Builder.build_class get_introspection_data('Regress', 'TestSubObj')
216
- end
217
-
218
- should "autocreate parent class' set_bare inside the parent class" do
219
- o1 = Regress::TestSubObj.new
220
- o2 = Regress::TestObj.new_from_file("foo")
221
-
222
- assert_nothing_raised {o1.set_bare(nil)}
223
-
224
- Regress::TestObj.class_eval do
225
- undef method_missing
226
- end
227
-
228
- assert_nothing_raised {o2.set_bare(nil)}
229
- end
230
-
231
- should "use its own version of instance_method when parent's version has been created" do
232
- obj = Regress::TestObj.new_from_file("foo")
233
- assert_equal(-1, obj.instance_method)
234
- subobj = Regress::TestSubObj.new
235
- assert_equal 0, subobj.instance_method
236
- end
237
-
238
- after do
239
- restore_module :Regress
240
- end
241
- end
242
-
243
- context "built Gio::ThreadedSocketService" do
244
- before do
245
- save_module :Gio
246
- GirFFI::Builder.build_module 'Gio'
247
- end
248
-
249
- context "when parent constructor has been called" do
250
- setup do
251
- Gio::SocketService.new
252
- end
253
-
254
- should "still use its own constructor" do
255
- assert_nothing_raised { Gio::ThreadedSocketService.new 2 }
256
- end
257
- end
258
-
259
- after do
260
- restore_module :Gio
261
- end
262
- end
263
- end
264
- end
@@ -1,38 +0,0 @@
1
- require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
2
-
3
- require 'ffi-glib'
4
-
5
- describe "With the GLib overrides" do
6
- describe "a HashTable provided by the system" do
7
- before do
8
- GirFFI.setup :Regress
9
- @hash = Regress.test_ghash_container_return
10
- end
11
-
12
- it "has a working #each method" do
13
- a = {}
14
- @hash.each {|k, v| a[k] = v}
15
- a.must_be :==, {"foo" => "bar", "baz" => "bat",
16
- "qux" => "quux"}
17
- end
18
-
19
- it "includes Enumerable" do
20
- GLib::HashTable.must_include Enumerable
21
- end
22
-
23
- it "has a working #to_hash method" do
24
- @hash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
25
- "qux" => "quux"}
26
- end
27
- end
28
-
29
- describe "HashTable" do
30
- it "allows key-value pairs to be inserted" do
31
- h = GLib::HashTable.new :utf8, :utf8
32
- h.insert "foo", "bar"
33
- h.to_hash.must_be :==, {"foo" => "bar"}
34
- end
35
- end
36
- end
37
-
38
-
@@ -1,274 +0,0 @@
1
- require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
2
-
3
- require 'ffi-gobject'
4
-
5
- class GObjectOverridesTest < MiniTest::Spec
6
- context "In the GObject module with overridden functions" do
7
- setup do
8
- GirFFI.setup :Regress
9
- end
10
-
11
- context "the signal_emit function" do
12
- should "emit a signal" do
13
- a = 1
14
- o = Regress::TestSubObj.new
15
- ::GObject::Lib.g_signal_connect_data o, "test", Proc.new { a = 2 }, nil, nil, 0
16
- GObject.signal_emit o, "test"
17
- assert_equal 2, a
18
- end
19
-
20
- should "handle return values" do
21
- s = Gio::SocketService.new
22
-
23
- argtypes = [:pointer, :pointer, :pointer, :pointer]
24
- callback = FFI::Function.new(:bool, argtypes) { |a,b,c,d| true }
25
- ::GObject::Lib.g_signal_connect_data s, "incoming", callback, nil, nil, 0
26
- rv = GObject.signal_emit s, "incoming"
27
- assert_equal true, rv.get_boolean
28
- end
29
-
30
- should "pass in extra arguments" do
31
- o = Regress::TestSubObj.new
32
- sb = Regress::TestSimpleBoxedA.new
33
- sb.some_int8 = 31
34
- sb.some_double = 2.42
35
- sb.some_enum = :value2
36
- b2 = nil
37
-
38
- argtypes = [:pointer, :pointer, :pointer]
39
- callback = FFI::Function.new(:void, argtypes) do |a,b,c|
40
- b2 = b
41
- end
42
- ::GObject::Lib.g_signal_connect_data o, "test-with-static-scope-arg", callback, nil, nil, 0
43
- GObject.signal_emit o, "test-with-static-scope-arg", sb
44
-
45
- sb2 = Regress::TestSimpleBoxedA.wrap b2
46
- assert sb.equals(sb2)
47
- end
48
- end
49
-
50
- context "the signal_connect function" do
51
- should "install a signal handler" do
52
- a = 1
53
- o = Regress::TestSubObj.new
54
- GObject.signal_connect(o, "test") { a = 2 }
55
- GObject.signal_emit o, "test"
56
- assert_equal 2, a
57
- end
58
-
59
- should "pass user data to handler" do
60
- a = 1
61
- o = Regress::TestSubObj.new
62
- GObject.signal_connect(o, "test", 2) { |i, d| a = d }
63
- GObject.signal_emit o, "test"
64
- assert_equal 2, a
65
- end
66
-
67
- should "pass object to handler" do
68
- o = Regress::TestSubObj.new
69
- o2 = nil
70
- GObject.signal_connect(o, "test") { |i, d| o2 = i }
71
- GObject.signal_emit o, "test"
72
- assert_instance_of Regress::TestSubObj, o2
73
- assert_equal o.to_ptr, o2.to_ptr
74
- end
75
-
76
- should "not allow connecting an invalid signal" do
77
- o = Regress::TestSubObj.new
78
- assert_raises RuntimeError do
79
- GObject.signal_connect(o, "not-really-a-signal") {}
80
- end
81
- end
82
-
83
- should "handle return values" do
84
- s = Gio::SocketService.new
85
- GObject.signal_connect(s, "incoming") { true }
86
- rv = GObject.signal_emit s, "incoming"
87
- assert_equal true, rv.get_boolean
88
- end
89
-
90
- should "require a block" do
91
- o = Regress::TestSubObj.new
92
- assert_raises ArgumentError do
93
- GObject.signal_connect o, "test"
94
- end
95
- end
96
-
97
- context "connecting a signal with extra arguments" do
98
- setup do
99
- @a = nil
100
- @b = 2
101
-
102
- o = Regress::TestSubObj.new
103
- sb = Regress::TestSimpleBoxedA.new
104
- sb.some_int = 23
105
-
106
- GObject.signal_connect(o, "test-with-static-scope-arg", 2) { |i, object, d|
107
- @a = d
108
- @b = object
109
- }
110
- GObject.signal_emit o, "test-with-static-scope-arg", sb
111
- end
112
-
113
- should "move the user data argument" do
114
- assert_equal 2, @a
115
- end
116
-
117
- should "pass on the extra arguments" do
118
- assert_instance_of Regress::TestSimpleBoxedA, @b
119
- assert_equal 23, @b.some_int
120
- end
121
- end
122
-
123
- end
124
-
125
- context "The GObject overrides Helper module" do
126
- context "#signal_arguments_to_gvalue_array" do
127
- context "the result of wrapping test-with-static-scope-arg" do
128
- setup do
129
- o = Regress::TestSubObj.new
130
- b = Regress::TestSimpleBoxedA.new
131
-
132
- @gva =
133
- GObject::Helper.signal_arguments_to_gvalue_array(
134
- "test-with-static-scope-arg", o, b)
135
- end
136
-
137
- should "be a GObject::ValueArray" do
138
- assert_instance_of GObject::ValueArray, @gva
139
- end
140
-
141
- should "contain two values" do
142
- assert_equal 2, @gva.n_values
143
- end
144
-
145
- should "have a first value with GType for TestSubObj" do
146
- assert_equal Regress::TestSubObj.get_gtype, (@gva.get_nth 0).current_gtype
147
- end
148
-
149
- should "have a second value with GType for TestSimpleBoxedA" do
150
- assert_equal Regress::TestSimpleBoxedA.get_gtype, (@gva.get_nth 1).current_gtype
151
- end
152
- end
153
- end
154
-
155
- describe "#signal_argument_to_gvalue" do
156
- it "maps a :utf8 argument to a string-valued GValue" do
157
- stub(arg_t = Object.new).tag { :utf8 }
158
- stub(info = Object.new).argument_type { arg_t }
159
- val =
160
- GObject::Helper.signal_argument_to_gvalue(
161
- info, "foo")
162
- assert_instance_of GObject::Value, val
163
- assert_equal "foo", val.get_string
164
- end
165
- end
166
-
167
- describe "#cast_back_signal_arguments" do
168
- it "correctly casts back pointers for the test-with-static-scope-arg signal" do
169
- o = Regress::TestSubObj.new
170
- b = Regress::TestSimpleBoxedA.new
171
- ud = GirFFI::ArgHelper.object_to_inptr "Hello!"
172
-
173
- assert_equal "Hello!", GirFFI::ArgHelper::OBJECT_STORE[ud.address]
174
-
175
- sig = o.class._find_signal "test-with-static-scope-arg"
176
-
177
- gva =
178
- GObject::Helper.cast_back_signal_arguments(
179
- sig, o.class, o.to_ptr, b.to_ptr, ud)
180
-
181
- klasses = gva.map {|it| it.class}
182
- klasses.must_equal [ Regress::TestSubObj,
183
- Regress::TestSimpleBoxedA,
184
- String ]
185
- gva[2].must_equal "Hello!"
186
- end
187
- end
188
-
189
- describe "#cast_signal_argument" do
190
- describe "with info for an enum" do
191
- before do
192
- enuminfo = get_introspection_data 'GLib', 'DateMonth'
193
- stub(arg_t = Object.new).interface { enuminfo }
194
- stub(arg_t).tag { :interface }
195
- stub(@info = Object.new).argument_type { arg_t }
196
- end
197
-
198
- it "casts an integer to its enum symbol" do
199
- res = GObject::Helper.cast_signal_argument @info, 7
200
- assert_equal :july, res
201
- end
202
- end
203
-
204
- describe "with info for an interface" do
205
- before do
206
- ifaceinfo = get_introspection_data 'Regress', 'TestInterface'
207
- stub(arg_t = Object.new).interface { ifaceinfo }
208
- stub(arg_t).tag { :interface }
209
- stub(@info = Object.new).argument_type { arg_t }
210
- end
211
-
212
- it "casts the argument by calling #to_object on it" do
213
- mock(ptr = Object.new).to_object { "good-result" }
214
- res = GObject::Helper.cast_signal_argument @info, ptr
215
- res.must_equal "good-result"
216
- end
217
- end
218
- end
219
- end
220
-
221
- context "The RubyClosure class" do
222
- should "have a constructor with a block argument" do
223
- assert_raises ArgumentError do
224
- GObject::RubyClosure.new
225
- end
226
- end
227
-
228
- should "be a kind of Closure" do
229
- c = GObject::RubyClosure.new {}
230
- assert_kind_of GObject::Closure, c
231
- end
232
-
233
- should "be able to retrieve its block from its struct" do
234
- a = 0
235
- c = GObject::RubyClosure.new { a = 2 }
236
- c2 = GObject::RubyClosure.wrap(c.to_ptr)
237
- c2.block.call
238
- assert_equal 2, a
239
- end
240
-
241
- context "its #marshaller singleton method" do
242
- should "invoke its closure argument's block" do
243
- a = 0
244
- c = GObject::RubyClosure.new { a = 2 }
245
- GObject::RubyClosure.marshaller(c, nil, 0, nil, nil, nil)
246
- assert_equal 2, a
247
- end
248
-
249
- should "work when its closure argument is a GObject::Closure" do
250
- a = 0
251
- c = GObject::RubyClosure.new { a = 2 }
252
- c2 = GObject::Closure.wrap(c.to_ptr)
253
- GObject::RubyClosure.marshaller(c2, nil, 0, nil, nil, nil)
254
- assert_equal 2, a
255
- end
256
-
257
- should "store the closure's return value in the proper gvalue" do
258
- c = GObject::RubyClosure.new { 2 }
259
- gv = GObject::Value.new
260
- GObject::RubyClosure.marshaller(c, gv, 0, nil, nil, nil)
261
- assert_equal 2, gv.ruby_value
262
- end
263
- end
264
-
265
- should "have GObject::Closure#invoke call its block" do
266
- a = 0
267
- c = GObject::RubyClosure.new { a = 2 }
268
- c2 = GObject::Closure.wrap(c.to_ptr)
269
- c2.invoke nil, nil, nil
270
- assert_equal 2, a
271
- end
272
- end
273
- end
274
- end