gir_ffi 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/README.rdoc +28 -14
- data/Rakefile +1 -1
- data/TODO.rdoc +3 -24
- data/examples/05_notification.rb +35 -0
- data/lib/gir_ffi/arg_helper.rb +15 -279
- data/lib/gir_ffi/builder/argument/base.rb +110 -0
- data/lib/gir_ffi/builder/argument/hash_table_base.rb +20 -0
- data/lib/gir_ffi/builder/argument/in_base.rb +19 -0
- data/lib/gir_ffi/builder/argument/in_out_base.rb +25 -0
- data/lib/gir_ffi/builder/argument/list_base.rb +16 -0
- data/lib/gir_ffi/builder/argument/out_base.rb +27 -0
- data/lib/gir_ffi/builder/argument.rb +167 -357
- data/lib/gir_ffi/builder/function.rb +2 -0
- data/lib/gir_ffi/builder/module.rb +2 -2
- data/lib/gir_ffi/builder/type/base.rb +7 -0
- data/lib/gir_ffi/builder/type/callback.rb +1 -8
- data/lib/gir_ffi/builder/type/constant.rb +1 -6
- data/lib/gir_ffi/builder/type/enum.rb +2 -7
- data/lib/gir_ffi/builder/type/interface.rb +12 -14
- data/lib/gir_ffi/builder/type/object.rb +32 -13
- data/lib/gir_ffi/builder/type/registered_type.rb +1 -78
- data/lib/gir_ffi/builder/type/struct.rb +2 -0
- data/lib/gir_ffi/builder/type/struct_based.rb +9 -24
- data/lib/gir_ffi/builder/type/unintrospectable.rb +63 -0
- data/lib/gir_ffi/builder/type/union.rb +8 -7
- data/lib/gir_ffi/builder/type/with_layout.rb +43 -0
- data/lib/gir_ffi/builder/type/with_methods.rb +61 -0
- data/lib/gir_ffi/builder.rb +39 -0
- data/lib/gir_ffi/callback_helper.rb +58 -0
- data/lib/gir_ffi/class_base.rb +17 -5
- data/lib/gir_ffi/i_repository.rb +0 -4
- data/lib/gir_ffi/in_out_pointer.rb +76 -0
- data/lib/gir_ffi/in_pointer.rb +46 -0
- data/lib/gir_ffi/interface_base.rb +12 -0
- data/lib/gir_ffi/module_base.rb +7 -3
- data/lib/gir_ffi/overrides/glib.rb +14 -3
- data/lib/gir_ffi/overrides/gobject.rb +37 -15
- data/lib/gir_ffi/overrides/gtk.rb +1 -1
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi.rb +3 -0
- data/tasks/rdoc.rake +6 -0
- data/tasks/test.rake +22 -3
- data/tasks/yardoc.rake +6 -0
- data/test/arg_helper_test.rb +2 -72
- data/test/builder_test.rb +15 -19
- data/test/function_definition_builder_test.rb +30 -37
- data/test/g_object_overrides_test.rb +29 -1
- data/test/glib_overrides_test.rb +4 -0
- data/test/gtk_overrides_test.rb +21 -15
- data/test/i_repository_test.rb +2 -1
- data/test/{generated_gimarshallingtests_test.rb → integration/generated_gimarshallingtests_test.rb} +1 -1
- data/test/integration/generated_gio_test.rb +98 -0
- data/test/integration/generated_gobject_test.rb +30 -0
- data/test/{generated_gtk_test.rb → integration/generated_gtk_test.rb} +5 -5
- data/test/{generated_regress_test.rb → integration/generated_regress_test.rb} +19 -5
- data/test/interface_type_builder_test.rb +1 -1
- data/test/module_builder_test.rb +3 -3
- data/test/test_helper.rb +4 -9
- data/test/type_builder_test.rb +5 -5
- data/test/{dynamic_type_builder_test.rb → unintrospectable_type_builder_test.rb} +12 -8
- data/test/unit/builder_test.rb +31 -0
- data/test/unit/callback_helper_test.rb +19 -0
- data/test/unit/constant_builder_test.rb +5 -0
- data/test/unit/i_constant_info_test.rb +17 -0
- data/test/unit/in_out_pointer_test.rb +118 -0
- data/test/unit/in_pointer_test.rb +69 -0
- data/test/unit/object_type_builder_test.rb +20 -0
- metadata +47 -19
- data/lib/gir_ffi/builder/dynamic_type.rb +0 -41
- data/test/generated_gio_test.rb +0 -39
- data/test/generated_gobject_test.rb +0 -15
- data/test/object_type_builder_test.rb +0 -34
data/test/builder_test.rb
CHANGED
@@ -9,7 +9,7 @@ class BuilderTest < MiniTest::Spec
|
|
9
9
|
context "building GObject::Object" do
|
10
10
|
before do
|
11
11
|
save_module :GObject
|
12
|
-
GirFFI::Builder.build_class
|
12
|
+
GirFFI::Builder.build_class get_introspection_data('GObject', 'Object')
|
13
13
|
end
|
14
14
|
|
15
15
|
should "create a Lib module in the parent namespace ready to attach functions from gobject-2.0" do
|
@@ -23,7 +23,7 @@ class BuilderTest < MiniTest::Spec
|
|
23
23
|
|
24
24
|
should "not replace existing classes" do
|
25
25
|
oldclass = GObject::Object
|
26
|
-
GirFFI::Builder.build_class
|
26
|
+
GirFFI::Builder.build_class get_introspection_data('GObject', 'Object')
|
27
27
|
assert_equal oldclass, GObject::Object
|
28
28
|
end
|
29
29
|
|
@@ -36,7 +36,7 @@ class BuilderTest < MiniTest::Spec
|
|
36
36
|
before do
|
37
37
|
save_module :Gtk
|
38
38
|
save_module :GObject
|
39
|
-
GirFFI::Builder.build_class
|
39
|
+
GirFFI::Builder.build_class get_introspection_data('Gtk', 'Window')
|
40
40
|
end
|
41
41
|
|
42
42
|
should "build Gtk namespace" do
|
@@ -67,10 +67,6 @@ class BuilderTest < MiniTest::Spec
|
|
67
67
|
assert Gtk::Window.instance_methods.map(&:to_sym).include? :to_ptr
|
68
68
|
end
|
69
69
|
|
70
|
-
should "result in Gtk::Window.new to succeed" do
|
71
|
-
assert_nothing_raised {Gtk::Window.new(:toplevel)}
|
72
|
-
end
|
73
|
-
|
74
70
|
after do
|
75
71
|
restore_module :Gtk
|
76
72
|
restore_module :GObject
|
@@ -112,7 +108,7 @@ class BuilderTest < MiniTest::Spec
|
|
112
108
|
|
113
109
|
context "looking at Gtk.main" do
|
114
110
|
setup do
|
115
|
-
@go =
|
111
|
+
@go = get_introspection_data 'Gtk', 'main'
|
116
112
|
end
|
117
113
|
|
118
114
|
should "have correct introspection data" do
|
@@ -137,7 +133,7 @@ class BuilderTest < MiniTest::Spec
|
|
137
133
|
context "looking at Gtk.init" do
|
138
134
|
setup do
|
139
135
|
GirFFI::Builder.build_module 'Gtk'
|
140
|
-
@go =
|
136
|
+
@go = get_introspection_data 'Gtk', 'init'
|
141
137
|
end
|
142
138
|
|
143
139
|
should "have :pointer, :pointer as types of the arguments for the attached function" do
|
@@ -168,7 +164,7 @@ class BuilderTest < MiniTest::Spec
|
|
168
164
|
GirFFI::Builder.build_module 'GLib'
|
169
165
|
GirFFI::Builder.build_module 'GObject'
|
170
166
|
GirFFI::Builder.build_module 'Regress'
|
171
|
-
@go =
|
167
|
+
@go = get_introspection_data 'Regress', 'test_callback_destroy_notify'
|
172
168
|
end
|
173
169
|
|
174
170
|
should "have the correct types of the arguments for the attached function" do
|
@@ -178,7 +174,7 @@ class BuilderTest < MiniTest::Spec
|
|
178
174
|
end
|
179
175
|
|
180
176
|
should "define ffi callback types :Callback and :ClosureNotify" do
|
181
|
-
Regress.
|
177
|
+
Regress._setup_method 'test_callback_destroy_notify'
|
182
178
|
tcud = Regress::Lib.find_type :TestCallbackUserData
|
183
179
|
dn = GLib::Lib.find_type :DestroyNotify
|
184
180
|
|
@@ -202,7 +198,7 @@ class BuilderTest < MiniTest::Spec
|
|
202
198
|
|
203
199
|
context "building Regress::TestStructA" do
|
204
200
|
setup do
|
205
|
-
GirFFI::Builder.build_class
|
201
|
+
GirFFI::Builder.build_class get_introspection_data('Regress', 'TestStructA')
|
206
202
|
end
|
207
203
|
|
208
204
|
should "set up the correct struct members" do
|
@@ -225,7 +221,7 @@ class BuilderTest < MiniTest::Spec
|
|
225
221
|
|
226
222
|
context "building GObject::TypeCValue" do
|
227
223
|
setup do
|
228
|
-
GirFFI::Builder.build_class
|
224
|
+
GirFFI::Builder.build_class get_introspection_data('GObject', 'TypeCValue')
|
229
225
|
end
|
230
226
|
|
231
227
|
should "set up the correct union members" do
|
@@ -245,7 +241,7 @@ class BuilderTest < MiniTest::Spec
|
|
245
241
|
|
246
242
|
context "building GObject::ValueArray" do
|
247
243
|
should "use provided constructor if present" do
|
248
|
-
GirFFI::Builder.build_class
|
244
|
+
GirFFI::Builder.build_class get_introspection_data('GObject', 'ValueArray')
|
249
245
|
assert_nothing_raised {
|
250
246
|
GObject::ValueArray.new 2
|
251
247
|
}
|
@@ -254,7 +250,7 @@ class BuilderTest < MiniTest::Spec
|
|
254
250
|
|
255
251
|
context "building Regress::TestBoxed" do
|
256
252
|
setup do
|
257
|
-
GirFFI::Builder.build_class
|
253
|
+
GirFFI::Builder.build_class get_introspection_data('Regress', 'TestBoxed')
|
258
254
|
end
|
259
255
|
|
260
256
|
should "set up #wrap" do
|
@@ -284,7 +280,7 @@ class BuilderTest < MiniTest::Spec
|
|
284
280
|
end
|
285
281
|
|
286
282
|
should "know its own module builder" do
|
287
|
-
assert GirFFI::Builder::Module === Regress.
|
283
|
+
assert GirFFI::Builder::Module === Regress._builder
|
288
284
|
end
|
289
285
|
|
290
286
|
after do
|
@@ -295,7 +291,7 @@ class BuilderTest < MiniTest::Spec
|
|
295
291
|
context "built Regress::TestObj" do
|
296
292
|
before do
|
297
293
|
save_module :Regress
|
298
|
-
GirFFI::Builder.build_class
|
294
|
+
GirFFI::Builder.build_class get_introspection_data('Regress', 'TestObj')
|
299
295
|
end
|
300
296
|
|
301
297
|
should "make autocreated instance method available to all instances" do
|
@@ -319,7 +315,7 @@ class BuilderTest < MiniTest::Spec
|
|
319
315
|
end
|
320
316
|
|
321
317
|
should "know its own class builder" do
|
322
|
-
assert GirFFI::Builder::Type::Base === Regress::TestObj.
|
318
|
+
assert GirFFI::Builder::Type::Base === Regress::TestObj._builder
|
323
319
|
end
|
324
320
|
|
325
321
|
context "its #torture_signature_0 method" do
|
@@ -339,7 +335,7 @@ class BuilderTest < MiniTest::Spec
|
|
339
335
|
context "built Regress::TestSubObj" do
|
340
336
|
before do
|
341
337
|
save_module :Regress
|
342
|
-
GirFFI::Builder.build_class
|
338
|
+
GirFFI::Builder.build_class get_introspection_data('Regress', 'TestSubObj')
|
343
339
|
end
|
344
340
|
|
345
341
|
should "autocreate parent class' set_bare inside the parent class" do
|
@@ -3,20 +3,18 @@ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
|
3
3
|
class FunctionDefinitionBuilderTest < MiniTest::Spec
|
4
4
|
context "The Builder::Function class" do
|
5
5
|
should "build correct definition of Gtk.init" do
|
6
|
-
go =
|
6
|
+
go = get_introspection_data 'Gtk', 'init'
|
7
7
|
fbuilder = GirFFI::Builder::Function.new go, Lib
|
8
8
|
code = fbuilder.generate
|
9
9
|
|
10
10
|
expected = "
|
11
11
|
def init argv
|
12
12
|
argc = argv.length
|
13
|
-
_v1 = GirFFI::
|
14
|
-
|
15
|
-
::Lib.gtk_init _v1,
|
16
|
-
|
17
|
-
GirFFI::ArgHelper.
|
18
|
-
_v4 = GirFFI::ArgHelper.outptr_to_utf8_array _v3, _v2
|
19
|
-
GirFFI::ArgHelper.cleanup_ptr_array_ptr _v3, _v2
|
13
|
+
_v1 = GirFFI::InOutPointer.from :gint32, argc
|
14
|
+
_v2 = GirFFI::InOutPointer.from_array :utf8, argv
|
15
|
+
::Lib.gtk_init _v1, _v2
|
16
|
+
_v3 = _v1.to_value
|
17
|
+
_v4 = GirFFI::ArgHelper.outptr_to_utf8_array _v2, _v3
|
20
18
|
return _v4
|
21
19
|
end
|
22
20
|
"
|
@@ -39,16 +37,16 @@ class FunctionDefinitionBuilderTest < MiniTest::Spec
|
|
39
37
|
end
|
40
38
|
|
41
39
|
should "build correct definition of Regress.test_callback_destroy_notify" do
|
42
|
-
go =
|
40
|
+
go = get_introspection_data 'Regress', 'test_callback_destroy_notify'
|
43
41
|
fbuilder = GirFFI::Builder::Function.new go, Lib
|
44
42
|
code = fbuilder.generate
|
45
43
|
|
46
44
|
expected =
|
47
45
|
"def test_callback_destroy_notify callback, user_data, notify
|
48
|
-
_v1 = GirFFI::
|
46
|
+
_v1 = GirFFI::CallbackHelper.wrap_in_callback_args_mapper \"Regress\", \"TestCallbackUserData\", callback
|
49
47
|
::Lib::CALLBACKS << _v1
|
50
48
|
_v2 = GirFFI::ArgHelper.object_to_inptr user_data
|
51
|
-
_v3 = GirFFI::
|
49
|
+
_v3 = GirFFI::CallbackHelper.wrap_in_callback_args_mapper \"GLib\", \"DestroyNotify\", notify
|
52
50
|
::Lib::CALLBACKS << _v3
|
53
51
|
_v4 = ::Lib.regress_test_callback_destroy_notify _v1, _v2, _v3
|
54
52
|
return _v4
|
@@ -64,49 +62,46 @@ class FunctionDefinitionBuilderTest < MiniTest::Spec
|
|
64
62
|
|
65
63
|
expected =
|
66
64
|
"def new_from_file x
|
67
|
-
_v1 = GirFFI::
|
68
|
-
|
69
|
-
|
70
|
-
GirFFI::ArgHelper.check_error(
|
71
|
-
|
72
|
-
return
|
65
|
+
_v1 = GirFFI::InPointer.from :utf8, x
|
66
|
+
_v2 = FFI::MemoryPointer.new(:pointer).write_pointer nil
|
67
|
+
_v3 = ::Lib.regress_test_obj_new_from_file _v1, _v2
|
68
|
+
GirFFI::ArgHelper.check_error(_v2)
|
69
|
+
_v4 = self.constructor_wrap(_v3)
|
70
|
+
return _v4
|
73
71
|
end"
|
74
72
|
|
75
73
|
assert_equal cws(expected), cws(code)
|
76
74
|
end
|
77
75
|
|
78
76
|
should "build correct definition of Regress:test_array_int_null_in" do
|
79
|
-
go =
|
77
|
+
go = get_introspection_data 'Regress', 'test_array_int_null_in'
|
80
78
|
fbuilder = GirFFI::Builder::Function.new go, Lib
|
81
79
|
code = fbuilder.generate
|
82
80
|
|
83
81
|
expected =
|
84
82
|
"def test_array_int_null_in arr
|
85
|
-
_v1 = GirFFI::
|
83
|
+
_v1 = GirFFI::InPointer.from_array :gint32, arr
|
86
84
|
len = arr.nil? ? 0 : arr.length
|
87
85
|
_v2 = len
|
88
86
|
::Lib.regress_test_array_int_null_in _v1, _v2
|
89
|
-
GirFFI::ArgHelper.cleanup_ptr _v1
|
90
87
|
end"
|
91
88
|
|
92
89
|
assert_equal cws(expected), cws(code)
|
93
90
|
end
|
94
91
|
|
95
92
|
should "build correct definition of Regress:test_array_int_null_out" do
|
96
|
-
go =
|
93
|
+
go = get_introspection_data 'Regress', 'test_array_int_null_out'
|
97
94
|
fbuilder = GirFFI::Builder::Function.new go, Lib
|
98
95
|
code = fbuilder.generate
|
99
96
|
|
100
97
|
expected =
|
101
98
|
"def test_array_int_null_out
|
102
|
-
_v1 = GirFFI::
|
103
|
-
|
104
|
-
::Lib.regress_test_array_int_null_out _v1,
|
105
|
-
|
106
|
-
GirFFI::ArgHelper.
|
107
|
-
|
108
|
-
GirFFI::ArgHelper.cleanup_ptr_ptr _v1
|
109
|
-
return _v2
|
99
|
+
_v1 = GirFFI::InOutPointer.for :pointer
|
100
|
+
_v2 = GirFFI::InOutPointer.for :gint32
|
101
|
+
::Lib.regress_test_array_int_null_out _v1, _v2
|
102
|
+
_v3 = _v2.to_value
|
103
|
+
_v4 = GirFFI::ArgHelper.outptr_to_gint32_array _v1, _v3
|
104
|
+
return _v4
|
110
105
|
end"
|
111
106
|
|
112
107
|
assert_equal cws(expected), cws(code)
|
@@ -119,15 +114,13 @@ class FunctionDefinitionBuilderTest < MiniTest::Spec
|
|
119
114
|
|
120
115
|
expected =
|
121
116
|
"def method_array_inout ints
|
122
|
-
_v1 = GirFFI::
|
117
|
+
_v1 = GirFFI::InOutPointer.from_array :gint32, ints
|
123
118
|
length = ints.length
|
124
|
-
|
125
|
-
::Lib.gi_marshalling_tests_object_method_array_inout self, _v1,
|
126
|
-
|
127
|
-
GirFFI::ArgHelper.
|
128
|
-
|
129
|
-
GirFFI::ArgHelper.cleanup_ptr _v1
|
130
|
-
return _v2
|
119
|
+
_v2 = GirFFI::InOutPointer.from :gint32, length
|
120
|
+
::Lib.gi_marshalling_tests_object_method_array_inout self, _v1, _v2
|
121
|
+
_v3 = _v2.to_value
|
122
|
+
_v4 = GirFFI::ArgHelper.outptr_to_gint32_array _v1, _v3
|
123
|
+
return _v4
|
131
124
|
end"
|
132
125
|
|
133
126
|
assert_equal cws(expected), cws(code)
|
@@ -180,6 +180,18 @@ class GObjectOverridesTest < MiniTest::Spec
|
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
|
+
describe "#signal_argument_to_gvalue" do
|
184
|
+
it "maps a :utf8 argument to a string-valued GValue" do
|
185
|
+
stub(arg_t = Object.new).tag { :utf8 }
|
186
|
+
stub(info = Object.new).argument_type { arg_t }
|
187
|
+
val =
|
188
|
+
GirFFI::Overrides::GObject::Helper.signal_argument_to_gvalue(
|
189
|
+
info, "foo")
|
190
|
+
assert_instance_of GObject::Value, val
|
191
|
+
assert_equal "foo", val.get_string
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
183
195
|
context "#cast_back_signal_arguments" do
|
184
196
|
context "the result of casting pointers for the test-with-static-scope-arg signal" do
|
185
197
|
setup do
|
@@ -187,7 +199,7 @@ class GObjectOverridesTest < MiniTest::Spec
|
|
187
199
|
o = Regress::TestSubObj.new
|
188
200
|
b = Regress::TestSimpleBoxedA.new
|
189
201
|
ud = GirFFI::ArgHelper.object_to_inptr "Hello!"
|
190
|
-
sig = o.class.
|
202
|
+
sig = o.class._find_signal sig_name
|
191
203
|
|
192
204
|
@gva =
|
193
205
|
GirFFI::Overrides::GObject::Helper.cast_back_signal_arguments(
|
@@ -217,6 +229,22 @@ class GObjectOverridesTest < MiniTest::Spec
|
|
217
229
|
end
|
218
230
|
end
|
219
231
|
end
|
232
|
+
|
233
|
+
describe "#cast_signal_argument" do
|
234
|
+
describe "with info for an enum" do
|
235
|
+
before do
|
236
|
+
enuminfo = get_introspection_data 'GLib', 'DateMonth'
|
237
|
+
stub(arg_t = Object.new).interface { enuminfo }
|
238
|
+
stub(arg_t).tag { :interface }
|
239
|
+
stub(@info = Object.new).argument_type { arg_t }
|
240
|
+
end
|
241
|
+
|
242
|
+
it "casts an integer to its enum symbol" do
|
243
|
+
res = GirFFI::Overrides::GObject::Helper.cast_signal_argument @info, 7
|
244
|
+
assert_equal :july, res
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
220
248
|
end
|
221
249
|
|
222
250
|
context "The RubyClosure class" do
|
data/test/glib_overrides_test.rb
CHANGED
data/test/gtk_overrides_test.rb
CHANGED
@@ -1,25 +1,31 @@
|
|
1
1
|
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
|
+
require 'gir_ffi/overrides/gtk'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
describe GirFFI::Overrides::Gtk do
|
5
|
+
before do
|
6
|
+
@gtk = Module.new do
|
7
|
+
def self.init arr
|
8
|
+
["baz", "qux", "zonk"]
|
9
|
+
end
|
7
10
|
end
|
11
|
+
stub(@gtk)._setup_method { }
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
assert_raises(ArgumentError) { Gtk.init ["foo"] }
|
12
|
-
assert_nothing_raised { Gtk.init }
|
13
|
+
@gtk.instance_eval do
|
14
|
+
include GirFFI::Overrides::Gtk
|
13
15
|
end
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Gtk.init
|
21
|
-
assert_same_elements ["foo"], ARGV
|
18
|
+
context "The .init function" do
|
19
|
+
should "not take any arguments" do
|
20
|
+
assert_raises(ArgumentError) { @gtk.init 1, ["foo"] }
|
21
|
+
assert_raises(ArgumentError) { @gtk.init ["foo"] }
|
22
|
+
assert_nothing_raised { @gtk.init }
|
22
23
|
end
|
24
|
+
|
25
|
+
should "replace ARGV with the tail of the result of the original init function" do
|
26
|
+
ARGV.replace ["foo", "bar"]
|
27
|
+
@gtk.init
|
28
|
+
assert_equal ["qux", "zonk"], ARGV.to_a
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
data/test/i_repository_test.rb
CHANGED
data/test/{generated_gimarshallingtests_test.rb → integration/generated_gimarshallingtests_test.rb}
RENAMED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
|
+
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
3
3
|
|
4
4
|
# Tests generated methods and functions in the GIMarshallingTests namespace.
|
5
5
|
describe "GIMarshallingTests" do
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
# Tests generated methods and functions in the Gio namespace.
|
4
|
+
describe "The generated Gio module" do
|
5
|
+
setup do
|
6
|
+
GirFFI.setup :Gio
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#file_new_for_path, a method returning an interface," do
|
10
|
+
it "does not throw an error when generated" do
|
11
|
+
assert_nothing_raised {
|
12
|
+
Gio.file_new_for_path('/')
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns an object of a more specific class" do
|
17
|
+
file = Gio.file_new_for_path('/')
|
18
|
+
refute_instance_of Gio::File, file
|
19
|
+
assert_includes file.class.ancestors, Gio::File
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "the result of #file_new_from_path" do
|
24
|
+
before do
|
25
|
+
@it = Gio.file_new_for_path('/')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is able to set up a method in a class that is not the first ancestor" do
|
29
|
+
anc = @it.class.ancestors
|
30
|
+
assert_equal Gio::File, anc[1]
|
31
|
+
assert_equal GObject::Object, anc[2]
|
32
|
+
refute_includes Gio::File.instance_methods.map(&:to_s),
|
33
|
+
'get_qdata'
|
34
|
+
assert_includes GObject::Object.instance_methods.map(&:to_s),
|
35
|
+
'get_qdata'
|
36
|
+
@it.setup_and_call :get_qdata, 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "the FileInfo class" do
|
41
|
+
context "an instance" do
|
42
|
+
setup do
|
43
|
+
file = Gio.file_new_for_path('/')
|
44
|
+
@fileinfo = file.query_info "*", :none, nil
|
45
|
+
end
|
46
|
+
|
47
|
+
should "hava a working #get_attribute_type method" do
|
48
|
+
type = @fileinfo.get_attribute_type "standard::display-name"
|
49
|
+
assert_equal :string, type
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "the action-added signal" do
|
55
|
+
before do
|
56
|
+
@grp = Gio::SimpleActionGroup.new
|
57
|
+
end
|
58
|
+
|
59
|
+
it "correctly passes on the string parameter 'action_name'" do
|
60
|
+
a = nil
|
61
|
+
GObject.signal_connect @grp, "action-added" do |grp, action_name, user_data|
|
62
|
+
a = action_name
|
63
|
+
end
|
64
|
+
GObject.signal_emit @grp, "action-added", "foo"
|
65
|
+
assert_equal "foo", a
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "the reply signal" do
|
70
|
+
before do
|
71
|
+
@mo = Gio::MountOperation.new
|
72
|
+
end
|
73
|
+
|
74
|
+
it "correctly passes on the enum parameter 'result'" do
|
75
|
+
a = nil
|
76
|
+
GObject.signal_connect @mo, "reply" do |mnt, result, user_data|
|
77
|
+
a = result
|
78
|
+
end
|
79
|
+
GObject.signal_emit @mo, "reply", 2
|
80
|
+
assert_equal :unhandled, a
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "the CharsetConverter class" do
|
85
|
+
it "includes two interfaces" do
|
86
|
+
klass = Gio::CharsetConverter
|
87
|
+
assert_includes klass.ancestors, Gio::Converter
|
88
|
+
assert_includes klass.ancestors, Gio::Initable
|
89
|
+
end
|
90
|
+
|
91
|
+
it "allows an instance to find the #reset method" do
|
92
|
+
cnv = Gio::CharsetConverter.new "utf8", "utf8"
|
93
|
+
cnv.reset
|
94
|
+
pass
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe "The generated GObject module" do
|
4
|
+
before do
|
5
|
+
GirFFI.setup :GObject
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#type_interfaces" do
|
9
|
+
it "works, showing that returning an array of GType works" do
|
10
|
+
tp = GObject.type_from_name 'GTypeModule'
|
11
|
+
ifcs = GObject.type_interfaces tp
|
12
|
+
assert_equal 1, ifcs.size
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "the TypePlugin interface" do
|
17
|
+
it "is implemented as a module" do
|
18
|
+
mod = GObject::TypePlugin
|
19
|
+
assert_instance_of Module, mod
|
20
|
+
refute_instance_of Class, mod
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "the TypeModule class" do
|
25
|
+
it "has the GObject::TypePlugin module as an ancestor" do
|
26
|
+
klass = GObject::TypeModule
|
27
|
+
assert_includes klass.ancestors, GObject::TypePlugin
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
1
|
+
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
# Since the tests will call Gtk+ functions, Gtk+ must be initialized.
|
4
|
+
GirFFI.setup :Gtk, '2.0'
|
5
|
+
Gtk.init
|
2
6
|
|
3
7
|
# Tests generated methods and functions in the Gtk namespace.
|
4
8
|
class GeneratedGtkTest < MiniTest::Spec
|
5
9
|
context "In the generated Gtk module" do
|
6
|
-
setup do
|
7
|
-
GirFFI.setup :Gtk, '2.0'
|
8
|
-
end
|
9
|
-
|
10
10
|
context "a Gtk::Builder instance" do
|
11
11
|
setup do
|
12
12
|
@builder = Gtk::Builder.new
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
|
+
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
3
3
|
|
4
4
|
# Tests generated methods and functions in the Regress namespace.
|
5
5
|
class GeneratedRegressTest < MiniTest::Spec
|
@@ -129,6 +129,7 @@ class GeneratedRegressTest < MiniTest::Spec
|
|
129
129
|
assert_instance_of Regress::TestObj, o
|
130
130
|
end
|
131
131
|
|
132
|
+
# TODO: Test that callback is called
|
132
133
|
should "create an instance using #new_callback" do
|
133
134
|
o = Regress::TestObj.new_callback Proc.new { }, nil, nil
|
134
135
|
assert_instance_of Regress::TestObj, o
|
@@ -212,7 +213,21 @@ class GeneratedRegressTest < MiniTest::Spec
|
|
212
213
|
should "not respond to #static_method" do
|
213
214
|
assert_raises(NoMethodError) { @o.static_method 1 }
|
214
215
|
end
|
216
|
+
# TODO: Test instance's fields and properies.
|
215
217
|
end
|
218
|
+
|
219
|
+
describe "its 'test' signal" do
|
220
|
+
it "properly passes its arguments" do
|
221
|
+
a = b = nil
|
222
|
+
o = Regress::TestSubObj.new
|
223
|
+
GObject.signal_connect(o, "test", 2) { |i, d| a = d; b = i }
|
224
|
+
GObject.signal_emit o, "test"
|
225
|
+
# TODO: store o's identity somewhere so we can make o == b.
|
226
|
+
assert_equal [2, o.to_ptr], [a, b.to_ptr]
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# TODO: Test other signals.
|
216
231
|
end
|
217
232
|
|
218
233
|
context "the Regress::TestSimpleBoxedA class" do
|
@@ -467,15 +482,15 @@ class GeneratedRegressTest < MiniTest::Spec
|
|
467
482
|
end
|
468
483
|
|
469
484
|
should "have correct test_async_ready_callback" do
|
470
|
-
GirFFI.setup :Gtk, '2.0'
|
471
485
|
a = 1
|
486
|
+
main_loop = GLib.main_loop_new nil, false
|
472
487
|
|
473
488
|
Regress.test_async_ready_callback Proc.new {
|
474
|
-
|
489
|
+
main_loop.quit
|
475
490
|
a = 2
|
476
491
|
}
|
477
492
|
|
478
|
-
|
493
|
+
main_loop.run
|
479
494
|
|
480
495
|
assert_equal 2, a
|
481
496
|
end
|
@@ -975,7 +990,6 @@ class GeneratedRegressTest < MiniTest::Spec
|
|
975
990
|
end
|
976
991
|
|
977
992
|
should "have correct test_utf8_const_in" do
|
978
|
-
# TODO: Capture stderr to automatically look for error messages.
|
979
993
|
assert_nothing_raised do
|
980
994
|
Regress.test_utf8_const_in("const \xe2\x99\xa5 utf8")
|
981
995
|
end
|
@@ -2,7 +2,7 @@ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
describe GirFFI::Builder::Type::Interface do
|
4
4
|
before do
|
5
|
-
info =
|
5
|
+
info = get_introspection_data 'GObject', 'TypePlugin'
|
6
6
|
@bldr = GirFFI::Builder::Type::Interface.new info
|
7
7
|
@iface = @bldr.build_class
|
8
8
|
end
|
data/test/module_builder_test.rb
CHANGED
@@ -9,7 +9,7 @@ class ModuleBuilderTest < MiniTest::Spec
|
|
9
9
|
|
10
10
|
context "looking at Gtk.main" do
|
11
11
|
setup do
|
12
|
-
@go =
|
12
|
+
@go = get_introspection_data 'Gtk', 'main'
|
13
13
|
end
|
14
14
|
|
15
15
|
should "build correct definition of Gtk.main" do
|
@@ -21,7 +21,7 @@ class ModuleBuilderTest < MiniTest::Spec
|
|
21
21
|
|
22
22
|
context "looking at Gtk.init" do
|
23
23
|
setup do
|
24
|
-
@go =
|
24
|
+
@go = get_introspection_data 'Gtk', 'init'
|
25
25
|
end
|
26
26
|
|
27
27
|
should "delegate definition to Builder::Function" do
|
@@ -39,7 +39,7 @@ class ModuleBuilderTest < MiniTest::Spec
|
|
39
39
|
|
40
40
|
context "looking at Regress.test_callback_destroy_notify" do
|
41
41
|
setup do
|
42
|
-
@go =
|
42
|
+
@go = get_introspection_data 'Regress', 'test_callback_destroy_notify'
|
43
43
|
end
|
44
44
|
|
45
45
|
should "delegate definition to Builder::Function" do
|