gir_ffi 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +12 -0
- data/TODO.rdoc +10 -0
- data/examples/04_webkit.rb +16 -0
- data/lib/gir_ffi/arg_helper.rb +130 -38
- data/lib/gir_ffi/builder/argument.rb +552 -0
- data/lib/gir_ffi/{class_builder.rb → builder/class.rb} +89 -67
- data/lib/gir_ffi/{function_definition_builder.rb → builder/function.rb} +10 -10
- data/lib/gir_ffi/{module_builder.rb → builder/module.rb} +17 -16
- data/lib/gir_ffi/builder.rb +33 -28
- data/lib/gir_ffi/class_base.rb +7 -2
- data/lib/gir_ffi/i_base_info.rb +8 -0
- data/lib/gir_ffi/i_repository.rb +6 -0
- data/lib/gir_ffi/i_struct_info.rb +5 -1
- data/lib/gir_ffi/lib.rb +2 -0
- data/lib/gir_ffi/overrides/glib.rb +30 -0
- data/lib/gir_ffi/overrides/gobject.rb +143 -26
- data/tasks/test.rake +14 -0
- data/test/arg_helper_test.rb +19 -3
- data/test/builder_test.rb +85 -73
- data/test/class_builder_test.rb +15 -11
- data/test/function_definition_builder_test.rb +32 -49
- data/test/g_object_overrides_test.rb +103 -48
- data/test/{generated_everything_test.rb → generated_regress_test.rb} +229 -167
- data/test/i_object_info_test.rb +2 -2
- data/test/i_repository_test.rb +2 -2
- data/test/lib/Makefile.am +30 -0
- data/test/lib/autogen.sh +87 -0
- data/test/lib/configure.ac +30 -0
- data/test/lib/m4/jhflags.m4 +21 -0
- data/test/module_builder_test.rb +10 -10
- data/test/test_helper.rb +14 -10
- metadata +22 -12
- data/lib/gir_ffi/argument_builder.rb +0 -382
@@ -1,19 +1,19 @@
|
|
1
1
|
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
class FunctionDefinitionBuilderTest < Test::Unit::TestCase
|
4
|
-
context "The
|
4
|
+
context "The Builder::Function class" do
|
5
5
|
should "build correct definition of Gtk.init" do
|
6
6
|
go = get_function_introspection_data 'Gtk', 'init'
|
7
|
-
fbuilder = GirFFI::
|
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::ArgHelper.
|
13
|
+
_v1 = GirFFI::ArgHelper.gint32_to_inoutptr argc
|
14
14
|
_v3 = GirFFI::ArgHelper.utf8_array_to_inoutptr argv
|
15
15
|
::Lib.gtk_init _v1, _v3
|
16
|
-
_v2 = GirFFI::ArgHelper.
|
16
|
+
_v2 = GirFFI::ArgHelper.outptr_to_gint32 _v1
|
17
17
|
GirFFI::ArgHelper.cleanup_ptr _v1
|
18
18
|
_v4 = GirFFI::ArgHelper.outptr_to_utf8_array _v3, _v2
|
19
19
|
GirFFI::ArgHelper.cleanup_ptr_array_ptr _v3, _v2
|
@@ -26,7 +26,7 @@ class FunctionDefinitionBuilderTest < Test::Unit::TestCase
|
|
26
26
|
|
27
27
|
should "build correct definition of Gtk::Widget.show" do
|
28
28
|
go = get_method_introspection_data 'Gtk', 'Widget', 'show'
|
29
|
-
fbuilder = GirFFI::
|
29
|
+
fbuilder = GirFFI::Builder::Function.new go, Lib
|
30
30
|
code = fbuilder.generate
|
31
31
|
|
32
32
|
expected = "
|
@@ -38,95 +38,78 @@ class FunctionDefinitionBuilderTest < Test::Unit::TestCase
|
|
38
38
|
assert_equal cws(expected), cws(code)
|
39
39
|
end
|
40
40
|
|
41
|
-
should "build correct definition of
|
42
|
-
go = get_function_introspection_data '
|
43
|
-
fbuilder = GirFFI::
|
41
|
+
should "build correct definition of Regress.test_callback_destroy_notify" do
|
42
|
+
go = get_function_introspection_data 'Regress', 'test_callback_destroy_notify'
|
43
|
+
fbuilder = GirFFI::Builder::Function.new go, Lib
|
44
44
|
code = fbuilder.generate
|
45
45
|
|
46
46
|
expected =
|
47
|
-
"def
|
48
|
-
_v1 = GirFFI::ArgHelper.
|
49
|
-
|
50
|
-
|
47
|
+
"def test_callback_destroy_notify callback, user_data, notify
|
48
|
+
_v1 = GirFFI::ArgHelper.wrap_in_callback_args_mapper \"Regress\", \"TestCallbackUserData\", callback
|
49
|
+
::Lib::CALLBACKS << _v1
|
50
|
+
_v2 = GirFFI::ArgHelper.object_to_inptr user_data
|
51
|
+
_v3 = GirFFI::ArgHelper.wrap_in_callback_args_mapper \"GLib\", \"DestroyNotify\", notify
|
51
52
|
::Lib::CALLBACKS << _v3
|
52
|
-
_v4 =
|
53
|
-
|
54
|
-
::Lib::CALLBACKS << _v5
|
55
|
-
_v6 = connect_flags
|
56
|
-
_v7 = ::Lib.g_signal_connect_data _v1, _v2, _v3, _v4, _v5, _v6
|
57
|
-
return _v7
|
53
|
+
_v4 = ::Lib.regress_test_callback_destroy_notify _v1, _v2, _v3
|
54
|
+
return _v4
|
58
55
|
end"
|
59
56
|
|
60
57
|
assert_equal cws(expected), cws(code)
|
61
58
|
end
|
62
59
|
|
63
|
-
should "build correct definition of
|
64
|
-
go = get_method_introspection_data '
|
65
|
-
fbuilder = GirFFI::
|
60
|
+
should "build correct definition of Regress::TestObj#new_from_file" do
|
61
|
+
go = get_method_introspection_data 'Regress', 'TestObj', 'new_from_file'
|
62
|
+
fbuilder = GirFFI::Builder::Function.new go, Lib
|
66
63
|
code = fbuilder.generate
|
67
64
|
|
68
65
|
expected =
|
69
66
|
"def new_from_file x
|
70
67
|
_v1 = GirFFI::ArgHelper.utf8_to_inptr x
|
71
68
|
_v4 = FFI::MemoryPointer.new(:pointer).write_pointer nil
|
72
|
-
_v2 = ::Lib.
|
69
|
+
_v2 = ::Lib.regress_test_obj_new_from_file _v1, _v4
|
73
70
|
GirFFI::ArgHelper.check_error(_v4)
|
74
|
-
_v3 = ::
|
71
|
+
_v3 = ::Regress::TestObj.constructor_wrap(_v2)
|
75
72
|
return _v3
|
76
73
|
end"
|
77
74
|
|
78
75
|
assert_equal cws(expected), cws(code)
|
79
76
|
end
|
80
77
|
|
81
|
-
should "build correct definition of
|
82
|
-
go = get_function_introspection_data '
|
83
|
-
fbuilder = GirFFI::
|
78
|
+
should "build correct definition of Regress:test_array_int_null_in" do
|
79
|
+
go = get_function_introspection_data 'Regress', 'test_array_int_null_in'
|
80
|
+
fbuilder = GirFFI::Builder::Function.new go, Lib
|
84
81
|
code = fbuilder.generate
|
85
82
|
|
86
83
|
expected =
|
87
84
|
"def test_array_int_null_in arr
|
88
|
-
_v1 = GirFFI::ArgHelper.
|
85
|
+
_v1 = GirFFI::ArgHelper.gint32_array_to_inptr arr
|
89
86
|
len = arr.nil? ? 0 : arr.length
|
90
87
|
_v2 = len
|
91
|
-
::Lib.
|
88
|
+
::Lib.regress_test_array_int_null_in _v1, _v2
|
92
89
|
GirFFI::ArgHelper.cleanup_ptr _v1
|
93
90
|
end"
|
94
91
|
|
95
92
|
assert_equal cws(expected), cws(code)
|
96
93
|
end
|
97
94
|
|
98
|
-
should "build correct definition of
|
99
|
-
go = get_function_introspection_data '
|
100
|
-
fbuilder = GirFFI::
|
95
|
+
should "build correct definition of Regress:test_array_int_null_out" do
|
96
|
+
go = get_function_introspection_data 'Regress', 'test_array_int_null_out'
|
97
|
+
fbuilder = GirFFI::Builder::Function.new go, Lib
|
101
98
|
code = fbuilder.generate
|
102
99
|
|
103
100
|
expected =
|
104
101
|
"def test_array_int_null_out
|
105
102
|
_v1 = GirFFI::ArgHelper.pointer_outptr
|
106
|
-
_v3 = GirFFI::ArgHelper.
|
107
|
-
::Lib.
|
108
|
-
_v4 = GirFFI::ArgHelper.
|
103
|
+
_v3 = GirFFI::ArgHelper.gint32_outptr
|
104
|
+
::Lib.regress_test_array_int_null_out _v1, _v3
|
105
|
+
_v4 = GirFFI::ArgHelper.outptr_to_gint32 _v3
|
109
106
|
GirFFI::ArgHelper.cleanup_ptr _v3
|
110
|
-
_v2 = GirFFI::ArgHelper.
|
107
|
+
_v2 = GirFFI::ArgHelper.outptr_to_gint32_array _v1, _v4
|
111
108
|
GirFFI::ArgHelper.cleanup_ptr_ptr _v1
|
112
109
|
return _v2
|
113
110
|
end"
|
114
111
|
|
115
112
|
assert_equal cws(expected), cws(code)
|
116
113
|
end
|
117
|
-
|
118
|
-
should "build correct definition of Everything:test_utf8_nonconst_in" do
|
119
|
-
go = get_function_introspection_data 'Everything', 'test_utf8_nonconst_in'
|
120
|
-
fbuilder = GirFFI::FunctionDefinitionBuilder.new go, Lib
|
121
|
-
code = fbuilder.generate
|
122
|
-
|
123
|
-
expected =
|
124
|
-
"def test_utf8_nonconst_in in_
|
125
|
-
_v1 = GirFFI::ArgHelper.utf8_to_inptr in_
|
126
|
-
::Lib.test_utf8_nonconst_in _v1
|
127
|
-
end"
|
128
|
-
|
129
|
-
assert_equal cws(expected), cws(code)
|
130
|
-
end
|
131
114
|
end
|
132
115
|
end
|
@@ -4,43 +4,45 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
4
4
|
context "In the GObject module with overridden functions" do
|
5
5
|
setup do
|
6
6
|
GirFFI.setup :GObject
|
7
|
-
GirFFI.setup :
|
7
|
+
GirFFI.setup :Regress
|
8
8
|
GirFFI.setup :Gio
|
9
9
|
end
|
10
10
|
|
11
|
-
context "the
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
context "the Value class" do
|
12
|
+
context "the wrap_ruby_value class method" do
|
13
|
+
should "wrap a boolean false" do
|
14
|
+
gv = GObject::Value.wrap_ruby_value false
|
15
|
+
assert_instance_of GObject::Value, gv
|
16
|
+
assert_equal false, gv.get_boolean
|
17
|
+
end
|
18
|
+
|
19
|
+
should "wrap a boolean true" do
|
20
|
+
gv = GObject::Value.wrap_ruby_value true
|
21
|
+
assert_instance_of GObject::Value, gv
|
22
|
+
assert_equal true, gv.get_boolean
|
23
|
+
end
|
16
24
|
end
|
17
25
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
should "unwrap a boolean true" do
|
33
|
-
gv = GObject.wrap_in_g_value true
|
34
|
-
result = GObject.unwrap_g_value gv
|
35
|
-
assert_equal true, result
|
26
|
+
context "the ruby_value method" do
|
27
|
+
should "unwrap a boolean false" do
|
28
|
+
gv = GObject::Value.wrap_ruby_value false
|
29
|
+
result = gv.ruby_value
|
30
|
+
assert_equal false, result
|
31
|
+
end
|
32
|
+
|
33
|
+
should "unwrap a boolean true" do
|
34
|
+
gv = GObject::Value.wrap_ruby_value true
|
35
|
+
result = gv.ruby_value
|
36
|
+
assert_equal true, result
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
41
|
context "the signal_emit function" do
|
40
42
|
should "emit a signal" do
|
41
43
|
a = 1
|
42
|
-
o =
|
43
|
-
GObject.
|
44
|
+
o = Regress::TestSubObj.new
|
45
|
+
::GObject::Lib.g_signal_connect_data o, "test", Proc.new { a = 2 }, nil, nil, 0
|
44
46
|
GObject.signal_emit o, "test"
|
45
47
|
assert_equal 2, a
|
46
48
|
end
|
@@ -50,14 +52,14 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
50
52
|
|
51
53
|
argtypes = [:pointer, :pointer, :pointer, :pointer]
|
52
54
|
callback = FFI::Function.new(:bool, argtypes) { |a,b,c,d| true }
|
53
|
-
GObject.
|
55
|
+
::GObject::Lib.g_signal_connect_data s, "incoming", callback, nil, nil, 0
|
54
56
|
rv = GObject.signal_emit s, "incoming"
|
55
57
|
assert_equal true, rv.get_boolean
|
56
58
|
end
|
57
59
|
|
58
60
|
should "pass in extra arguments" do
|
59
|
-
o =
|
60
|
-
sb =
|
61
|
+
o = Regress::TestSubObj.new
|
62
|
+
sb = Regress::TestSimpleBoxedA.new
|
61
63
|
sb[:some_int8] = 31
|
62
64
|
sb[:some_double] = 2.42
|
63
65
|
sb[:some_enum] = :value2
|
@@ -67,10 +69,10 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
67
69
|
callback = FFI::Function.new(:void, argtypes) do |a,b,c|
|
68
70
|
b2 = b
|
69
71
|
end
|
70
|
-
GObject.
|
72
|
+
::GObject::Lib.g_signal_connect_data o, "test-with-static-scope-arg", callback, nil, nil, 0
|
71
73
|
GObject.signal_emit o, "test-with-static-scope-arg", sb
|
72
74
|
|
73
|
-
sb2 =
|
75
|
+
sb2 = Regress::TestSimpleBoxedA.wrap b2
|
74
76
|
assert sb.equals(sb2)
|
75
77
|
end
|
76
78
|
end
|
@@ -78,7 +80,7 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
78
80
|
context "the signal_connect function" do
|
79
81
|
should "install a signal handler" do
|
80
82
|
a = 1
|
81
|
-
o =
|
83
|
+
o = Regress::TestSubObj.new
|
82
84
|
GObject.signal_connect(o, "test") { a = 2 }
|
83
85
|
GObject.signal_emit o, "test"
|
84
86
|
assert_equal 2, a
|
@@ -86,23 +88,23 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
86
88
|
|
87
89
|
should "pass user data to handler" do
|
88
90
|
a = 1
|
89
|
-
o =
|
91
|
+
o = Regress::TestSubObj.new
|
90
92
|
GObject.signal_connect(o, "test", 2) { |i, d| a = d }
|
91
93
|
GObject.signal_emit o, "test"
|
92
94
|
assert_equal 2, a
|
93
95
|
end
|
94
96
|
|
95
97
|
should "pass object to handler" do
|
96
|
-
o =
|
98
|
+
o = Regress::TestSubObj.new
|
97
99
|
o2 = nil
|
98
100
|
GObject.signal_connect(o, "test") { |i, d| o2 = i }
|
99
101
|
GObject.signal_emit o, "test"
|
100
|
-
assert_instance_of
|
102
|
+
assert_instance_of Regress::TestSubObj, o2
|
101
103
|
assert_equal o.to_ptr, o2.to_ptr
|
102
104
|
end
|
103
105
|
|
104
106
|
should "not allow connecting an invalid signal" do
|
105
|
-
o =
|
107
|
+
o = Regress::TestSubObj.new
|
106
108
|
assert_raises RuntimeError do
|
107
109
|
GObject.signal_connect(o, "not-really-a-signal") {}
|
108
110
|
end
|
@@ -116,7 +118,7 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
116
118
|
end
|
117
119
|
|
118
120
|
should "require a block" do
|
119
|
-
o =
|
121
|
+
o = Regress::TestSubObj.new
|
120
122
|
assert_raises ArgumentError do
|
121
123
|
GObject.signal_connect o, "test"
|
122
124
|
end
|
@@ -127,8 +129,8 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
127
129
|
@a = nil
|
128
130
|
@b = 2
|
129
131
|
|
130
|
-
o =
|
131
|
-
sb =
|
132
|
+
o = Regress::TestSubObj.new
|
133
|
+
sb = Regress::TestSimpleBoxedA.new
|
132
134
|
sb[:some_int] = 23
|
133
135
|
|
134
136
|
GObject.signal_connect(o, "test-with-static-scope-arg", 2) { |i, object, d|
|
@@ -143,7 +145,7 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
143
145
|
end
|
144
146
|
|
145
147
|
should "pass on the extra arguments" do
|
146
|
-
assert_instance_of
|
148
|
+
assert_instance_of Regress::TestSimpleBoxedA, @b
|
147
149
|
assert_equal 23, @b[:some_int]
|
148
150
|
end
|
149
151
|
end
|
@@ -154,8 +156,8 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
154
156
|
context "#signal_arguments_to_gvalue_array" do
|
155
157
|
context "the result of wrapping test-with-static-scope-arg" do
|
156
158
|
setup do
|
157
|
-
o =
|
158
|
-
b =
|
159
|
+
o = Regress::TestSubObj.new
|
160
|
+
b = Regress::TestSimpleBoxedA.new
|
159
161
|
|
160
162
|
@gva =
|
161
163
|
GirFFI::Overrides::GObject::Helper.signal_arguments_to_gvalue_array(
|
@@ -171,11 +173,11 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
171
173
|
end
|
172
174
|
|
173
175
|
should "have a first value with GType for TestSubObj" do
|
174
|
-
assert_equal
|
176
|
+
assert_equal Regress::TestSubObj.get_gtype, (@gva.get_nth 0)[:g_type]
|
175
177
|
end
|
176
178
|
|
177
179
|
should "have a second value with GType for TestSimpleBoxedA" do
|
178
|
-
assert_equal
|
180
|
+
assert_equal Regress::TestSimpleBoxedA.get_gtype, (@gva.get_nth 1)[:g_type]
|
179
181
|
end
|
180
182
|
end
|
181
183
|
end
|
@@ -184,8 +186,8 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
184
186
|
context "the result of casting pointers for the test-with-static-scope-arg signal" do
|
185
187
|
setup do
|
186
188
|
sig_name = "test-with-static-scope-arg"
|
187
|
-
o =
|
188
|
-
b =
|
189
|
+
o = Regress::TestSubObj.new
|
190
|
+
b = Regress::TestSimpleBoxedA.new
|
189
191
|
ud = GirFFI::ArgHelper.object_to_inptr "Hello!"
|
190
192
|
sig = o.class.gir_ffi_builder.find_signal sig_name
|
191
193
|
|
@@ -200,13 +202,13 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
200
202
|
|
201
203
|
context "its first value" do
|
202
204
|
should "be a TestSubObj" do
|
203
|
-
assert_instance_of
|
205
|
+
assert_instance_of Regress::TestSubObj, @gva[0]
|
204
206
|
end
|
205
207
|
end
|
206
208
|
|
207
209
|
context "its second value" do
|
208
210
|
should "be a TestSimpleBoxedA" do
|
209
|
-
assert_instance_of
|
211
|
+
assert_instance_of Regress::TestSimpleBoxedA, @gva[1]
|
210
212
|
end
|
211
213
|
end
|
212
214
|
|
@@ -218,6 +220,59 @@ class GObjectOverridesTest < Test::Unit::TestCase
|
|
218
220
|
end
|
219
221
|
end
|
220
222
|
end
|
223
|
+
|
224
|
+
context "The RubyClosure class" do
|
225
|
+
should "have a constructor with a block argument" do
|
226
|
+
assert_raises ArgumentError do
|
227
|
+
GObject::RubyClosure.new
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
should "be a kind of Closure" do
|
232
|
+
c = GObject::RubyClosure.new {}
|
233
|
+
assert_kind_of GObject::Closure, c
|
234
|
+
end
|
235
|
+
|
236
|
+
should "be able to retrieve its block from its struct" do
|
237
|
+
a = 0
|
238
|
+
c = GObject::RubyClosure.new { a = 2 }
|
239
|
+
c2 = GObject::RubyClosure.wrap(c.to_ptr)
|
240
|
+
c2.block.call
|
241
|
+
assert_equal 2, a
|
242
|
+
end
|
243
|
+
|
244
|
+
context "its #marshaller singleton method" do
|
245
|
+
should "invoke its closure argument's block" do
|
246
|
+
a = 0
|
247
|
+
c = GObject::RubyClosure.new { a = 2 }
|
248
|
+
GObject::RubyClosure.marshaller(c, nil, 0, nil, nil, nil)
|
249
|
+
assert_equal 2, a
|
250
|
+
end
|
251
|
+
|
252
|
+
should "work when its closure argument is a GObject::Closure" do
|
253
|
+
a = 0
|
254
|
+
c = GObject::RubyClosure.new { a = 2 }
|
255
|
+
c2 = GObject::Closure.wrap(c.to_ptr)
|
256
|
+
GObject::RubyClosure.marshaller(c2, nil, 0, nil, nil, nil)
|
257
|
+
assert_equal 2, a
|
258
|
+
end
|
259
|
+
|
260
|
+
should "store the closure's return value in the proper gvalue" do
|
261
|
+
c = GObject::RubyClosure.new { 2 }
|
262
|
+
gv = GObject::Value.new
|
263
|
+
GObject::RubyClosure.marshaller(c, gv, 0, nil, nil, nil)
|
264
|
+
assert_equal 2, gv.ruby_value
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
should "have GObject::Closure#invoke call its block" do
|
269
|
+
a = 0
|
270
|
+
c = GObject::RubyClosure.new { a = 2 }
|
271
|
+
c2 = GObject::Closure.wrap(c.to_ptr)
|
272
|
+
c2.invoke nil, nil, nil
|
273
|
+
assert_equal 2, a
|
274
|
+
end
|
275
|
+
end
|
221
276
|
end
|
222
277
|
end
|
223
278
|
|