gir_ffi 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +14 -0
- data/README.rdoc +3 -1
- data/examples/02_hello_world.rb +1 -0
- data/examples/03_upgraded_hello_world.rb +2 -1
- data/examples/05_notification.rb +2 -2
- data/examples/hard_coded.rb +31 -8
- data/lib/ffi-glib/array.rb +1 -1
- data/lib/ffi-glib/container_class_methods.rb +25 -0
- data/lib/ffi-glib/hash_table.rb +41 -38
- data/lib/ffi-glib/list.rb +15 -22
- data/lib/ffi-glib/list_methods.rb +16 -16
- data/lib/ffi-glib/ptr_array.rb +20 -15
- data/lib/ffi-glib/s_list.rb +15 -23
- data/lib/ffi-glib.rb +7 -0
- data/lib/ffi-gobject/base.rb +0 -13
- data/lib/ffi-gobject/object.rb +6 -0
- data/lib/ffi-gobject/ruby_style.rb +21 -0
- data/lib/ffi-gobject.rb +44 -0
- data/lib/ffi-gobject_introspection/i_object_info.rb +7 -0
- data/lib/ffi-gobject_introspection/lib.rb +1 -0
- data/lib/gir_ffi/arg_helper.rb +8 -6
- data/lib/gir_ffi/builder/argument.rb +1 -1
- data/lib/gir_ffi/builder/field.rb +6 -3
- data/lib/gir_ffi/builder/property.rb +28 -0
- data/lib/gir_ffi/builder/type/base.rb +6 -4
- data/lib/gir_ffi/builder/type/interface.rb +1 -0
- data/lib/gir_ffi/builder/type/object.rb +26 -1
- data/lib/gir_ffi/builder/type/registered_type.rb +9 -1
- data/lib/gir_ffi/builder/type/unintrospectable.rb +26 -8
- data/lib/gir_ffi/builder/type/user_defined.rb +119 -0
- data/lib/gir_ffi/builder/type/with_layout.rb +3 -3
- data/lib/gir_ffi/builder.rb +5 -0
- data/lib/gir_ffi/class_base.rb +6 -6
- data/lib/gir_ffi/info_ext/i_property_info.rb +12 -0
- data/lib/gir_ffi/info_ext/i_type_info.rb +4 -0
- data/lib/gir_ffi/user_defined/i_base_info.rb +7 -0
- data/lib/gir_ffi/user_defined/i_object_info.rb +13 -0
- data/lib/gir_ffi/user_defined/i_property_info.rb +9 -0
- data/lib/gir_ffi/user_defined/i_registered_type_info.rb +10 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi.rb +6 -0
- data/tasks/test.rake +12 -2
- data/test/builder_test.rb +0 -124
- data/test/ffi-glib/hash_table_test.rb +0 -14
- data/test/ffi-glib/list_test.rb +0 -13
- data/test/ffi-glib/ptr_array_test.rb +26 -8
- data/test/ffi-glib/s_list_test.rb +4 -4
- data/test/ffi-gobject/g_object_overrides_test.rb +16 -32
- data/test/ffi-gobject/gobject_test.rb +28 -1
- data/test/ffi-gobject/object_class_test.rb +21 -0
- data/test/ffi-gobject/object_test.rb +4 -0
- data/test/ffi-gobject/ruby_style_test.rb +38 -0
- data/test/ffi-gobject_introspection/i_constant_info_test.rb +5 -5
- data/test/ffi-gobject_introspection/i_repository_test.rb +4 -4
- data/test/ffi-gtk/gtk_test.rb +36 -0
- data/test/gir_ffi_test_helper.rb +8 -4
- data/test/integration/derived_classes_test.rb +34 -18
- data/test/integration/generated_gimarshallingtests_test.rb +20 -23
- data/test/integration/generated_gio_test.rb +5 -0
- data/test/integration/generated_gobject_test.rb +2 -2
- data/test/integration/generated_gtk_test.rb +1 -1
- data/test/integration/generated_pango_test.rb +20 -0
- data/test/integration/generated_regress_test.rb +1003 -955
- data/test/integration/pretty_print_test.rb +3 -1
- data/test/test_helper.rb +5 -0
- data/test/type_builder_test.rb +2 -19
- data/test/unit/arg_helper_test.rb +87 -1
- data/test/unit/builder_test.rb +113 -1
- data/test/unit/function_builder_test.rb +6 -5
- data/test/unit/gir_ffi_test.rb +69 -0
- data/test/unit/in_out_pointer_test.rb +3 -3
- data/test/unit/in_pointer_test.rb +1 -1
- data/test/unit/interface_builder_test.rb +16 -0
- data/test/unit/object_type_builder_test.rb +15 -0
- data/test/unit/struct_builder_test.rb +5 -1
- data/test/{unintrospectable_type_builder_test.rb → unit/unintrospectable_type_builder_test.rb} +18 -1
- data/test/unit/user_defined_object_info_test.rb +18 -0
- data/test/unit/user_defined_property_info_test.rb +14 -0
- data/test/unit/user_defined_registered_type_info_test.rb +10 -0
- data/test/unit/user_defined_type_builder_test.rb +41 -0
- metadata +34 -17
- data/tasks/notes.rake +0 -121
- data/tasks/rdoc.rake +0 -9
- data/tasks/yardoc.rake +0 -9
- data/test/arg_helper_test.rb +0 -33
- data/test/gtk_overrides_test.rb +0 -35
- data/test/interface_type_builder_test.rb +0 -17
data/test/builder_test.rb
CHANGED
@@ -32,130 +32,6 @@ class BuilderTest < MiniTest::Spec
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context "building Gtk::Window" do
|
36
|
-
before do
|
37
|
-
save_module :Gtk
|
38
|
-
save_module :GObject
|
39
|
-
GirFFI::Builder.build_class get_introspection_data('Gtk', 'Window')
|
40
|
-
end
|
41
|
-
|
42
|
-
should "build Gtk namespace" do
|
43
|
-
assert Gtk.const_defined? :Lib
|
44
|
-
assert Gtk.respond_to? :method_missing
|
45
|
-
end
|
46
|
-
|
47
|
-
should "build parent classes also" do
|
48
|
-
assert Gtk.const_defined? :Widget
|
49
|
-
assert Object.const_defined? :GObject
|
50
|
-
assert GObject.const_defined? :InitiallyUnowned
|
51
|
-
assert GObject.const_defined? :Object
|
52
|
-
end
|
53
|
-
|
54
|
-
should "set up inheritance chain" do
|
55
|
-
ancestors = Gtk::Window.ancestors
|
56
|
-
assert_equal [
|
57
|
-
Gtk::Window,
|
58
|
-
Gtk::Bin,
|
59
|
-
Gtk::Container,
|
60
|
-
Gtk::Widget
|
61
|
-
], ancestors[0..3]
|
62
|
-
assert ancestors.include? GObject::InitiallyUnowned
|
63
|
-
assert ancestors.include? GObject::Object
|
64
|
-
end
|
65
|
-
|
66
|
-
should "create a Gtk::Window#to_ptr method" do
|
67
|
-
assert Gtk::Window.public_method_defined? :to_ptr
|
68
|
-
end
|
69
|
-
|
70
|
-
after do
|
71
|
-
restore_module :Gtk
|
72
|
-
restore_module :GObject
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "building Gtk" do
|
77
|
-
before do
|
78
|
-
save_module :Gtk
|
79
|
-
GirFFI::Builder.build_module 'Gtk'
|
80
|
-
end
|
81
|
-
|
82
|
-
should "create a Lib module ready to attach functions from gtk-x11-2.0" do
|
83
|
-
# The Gtk module has more than one library on my current machine.
|
84
|
-
expected = (@gir.shared_library 'Gtk').split(',')
|
85
|
-
assert_equal expected.sort, Gtk::Lib.ffi_libraries.map(&:name).sort
|
86
|
-
end
|
87
|
-
|
88
|
-
should "create an array CALLBACKS inside the Gtk::Lib module" do
|
89
|
-
assert_equal [], Gtk::Lib::CALLBACKS
|
90
|
-
end
|
91
|
-
|
92
|
-
should "not replace existing module" do
|
93
|
-
oldmodule = Gtk
|
94
|
-
GirFFI::Builder.build_module 'Gtk'
|
95
|
-
assert_equal oldmodule, Gtk
|
96
|
-
end
|
97
|
-
|
98
|
-
should "not replace existing Lib module" do
|
99
|
-
oldmodule = Gtk::Lib
|
100
|
-
GirFFI::Builder.build_module 'Gtk'
|
101
|
-
assert_equal oldmodule, Gtk::Lib
|
102
|
-
end
|
103
|
-
|
104
|
-
after do
|
105
|
-
restore_module :Gtk
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "looking at Gtk.main" do
|
110
|
-
setup do
|
111
|
-
@go = get_introspection_data 'Gtk', 'main'
|
112
|
-
end
|
113
|
-
|
114
|
-
should "have correct introspection data" do
|
115
|
-
@gir.require "Gtk", "2.0"
|
116
|
-
go2 = @gir.find_by_name "Gtk", "main"
|
117
|
-
assert_equal go2, @go
|
118
|
-
end
|
119
|
-
|
120
|
-
should "attach function to Whatever::Lib" do
|
121
|
-
mod = Module.new
|
122
|
-
mod.const_set :Lib, libmod = Module.new
|
123
|
-
libmod.module_eval do
|
124
|
-
extend FFI::Library
|
125
|
-
ffi_lib "gtk-x11-2.0"
|
126
|
-
end
|
127
|
-
|
128
|
-
GirFFI::Builder.send :attach_ffi_function, libmod, @go
|
129
|
-
assert_defines_singleton_method libmod, :gtk_main
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "looking at Gtk.init" do
|
134
|
-
setup do
|
135
|
-
GirFFI::Builder.build_module 'Gtk'
|
136
|
-
@go = get_introspection_data 'Gtk', 'init'
|
137
|
-
end
|
138
|
-
|
139
|
-
should "have :pointer, :pointer as types of the arguments for the attached function" do
|
140
|
-
assert_equal [:pointer, :pointer], GirFFI::Builder.send(:ffi_function_argument_types, @go)
|
141
|
-
end
|
142
|
-
|
143
|
-
should "have :void as return type for the attached function" do
|
144
|
-
assert_equal :void, GirFFI::Builder.send(:ffi_function_return_type, @go)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context "looking at Gtk::Widget#show" do
|
149
|
-
setup do
|
150
|
-
@go = get_method_introspection_data 'Gtk', 'Widget', 'show'
|
151
|
-
end
|
152
|
-
|
153
|
-
should "have :pointer as types of the arguments for the attached function" do
|
154
|
-
assert_equal [:pointer], GirFFI::Builder.send(:ffi_function_argument_types, @go)
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
35
|
context "looking at Regress.test_callback_destroy_notify" do
|
160
36
|
before do
|
161
37
|
save_module :GLib
|
@@ -7,20 +7,6 @@ describe GLib::HashTable do
|
|
7
7
|
assert_equal :utf8, hsh.value_type
|
8
8
|
end
|
9
9
|
|
10
|
-
describe "::from_hash" do
|
11
|
-
it "creates a GHashTable from a Ruby array" do
|
12
|
-
hsh = GLib::HashTable.from_hash [:utf8, :gint32],
|
13
|
-
{"foo" => 23, "bar" => 32}
|
14
|
-
assert_equal({"foo" => 23, "bar" => 32}, hsh.to_hash)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "return its argument if given a GHashTable" do
|
18
|
-
hsh = GLib::HashTable.from_hash [:utf8, :gint32], {"foo" => 23, "bar" => 32}
|
19
|
-
hsh2 = GLib::HashTable.from_hash [:utf8, :gint32], hsh
|
20
|
-
assert_equal hsh, hsh2
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
10
|
describe "::from" do
|
25
11
|
it "creates a GHashTable from a Ruby array" do
|
26
12
|
hsh = GLib::HashTable.from [:utf8, :gint32],
|
data/test/ffi-glib/list_test.rb
CHANGED
@@ -31,19 +31,6 @@ describe GLib::List do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe "::from_array" do
|
35
|
-
it "creates a GList from a Ruby array" do
|
36
|
-
lst = GLib::List.from_array :gint32, [3, 2, 1]
|
37
|
-
assert_equal [3, 2, 1], lst.to_a
|
38
|
-
end
|
39
|
-
|
40
|
-
it "return its argument if given a GList" do
|
41
|
-
lst = GLib::List.from_array :gint32, [3, 2, 1]
|
42
|
-
lst2 = GLib::List.from_array :gint32, lst
|
43
|
-
assert_equal lst, lst2
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
34
|
describe "::from" do
|
48
35
|
it "creates a GList from a Ruby array" do
|
49
36
|
lst = GLib::List.from :gint32, [3, 2, 1]
|
@@ -16,17 +16,35 @@ describe GLib::PtrArray do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
describe "#each" do
|
20
|
+
it "works normally" do
|
21
|
+
arr = GLib::PtrArray.new :utf8
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
GLib::PtrArray.add arr, "test1"
|
24
|
+
GLib::PtrArray.add arr, "test2"
|
25
|
+
GLib::PtrArray.add arr, "test3"
|
26
|
+
|
27
|
+
a = []
|
28
|
+
arr.each {|v| a << v}
|
25
29
|
|
26
|
-
|
27
|
-
|
30
|
+
assert_equal ["test1", "test2", "test3"], a
|
31
|
+
end
|
32
|
+
|
33
|
+
it "works when exiting the loop prematurely" do
|
34
|
+
arr = GLib::PtrArray.new :utf8
|
28
35
|
|
29
|
-
|
36
|
+
GLib::PtrArray.add arr, "test1"
|
37
|
+
GLib::PtrArray.add arr, "test2"
|
38
|
+
GLib::PtrArray.add arr, "test3"
|
39
|
+
|
40
|
+
a = []
|
41
|
+
arr.each do |v|
|
42
|
+
a << v
|
43
|
+
break if v == "test2"
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_equal ["test1", "test2"], a
|
47
|
+
end
|
30
48
|
end
|
31
49
|
|
32
50
|
it "includes Enumerable" do
|
@@ -31,15 +31,15 @@ describe GLib::SList do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe "::
|
34
|
+
describe "::from" do
|
35
35
|
it "creates a GSList from a Ruby array" do
|
36
|
-
lst = GLib::SList.
|
36
|
+
lst = GLib::SList.from :gint32, [3, 2, 1]
|
37
37
|
assert_equal [3, 2, 1], lst.to_a
|
38
38
|
end
|
39
39
|
|
40
40
|
it "return its argument if given a GSList" do
|
41
|
-
lst = GLib::SList.
|
42
|
-
lst2 = GLib::SList.
|
41
|
+
lst = GLib::SList.from :gint32, [3, 2, 1]
|
42
|
+
lst2 = GLib::SList.from :gint32, lst
|
43
43
|
assert_equal lst, lst2
|
44
44
|
end
|
45
45
|
end
|
@@ -164,42 +164,26 @@ class GObjectOverridesTest < MiniTest::Spec
|
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
b = Regress::TestSimpleBoxedA.new
|
173
|
-
ud = GirFFI::ArgHelper.object_to_inptr "Hello!"
|
174
|
-
sig = o.class._find_signal sig_name
|
175
|
-
|
176
|
-
@gva =
|
177
|
-
GObject::Helper.cast_back_signal_arguments(
|
178
|
-
sig, o.class, o.to_ptr, b.to_ptr, ud)
|
179
|
-
end
|
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!"
|
180
172
|
|
181
|
-
|
182
|
-
assert_equal 3, @gva.length
|
183
|
-
end
|
173
|
+
assert_equal "Hello!", GirFFI::ArgHelper::OBJECT_STORE[ud.address]
|
184
174
|
|
185
|
-
|
186
|
-
should "be a TestSubObj" do
|
187
|
-
assert_instance_of Regress::TestSubObj, @gva[0]
|
188
|
-
end
|
189
|
-
end
|
175
|
+
sig = o.class._find_signal "test-with-static-scope-arg"
|
190
176
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
end
|
195
|
-
end
|
177
|
+
gva =
|
178
|
+
GObject::Helper.cast_back_signal_arguments(
|
179
|
+
sig, o.class, o.to_ptr, b.to_ptr, ud)
|
196
180
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
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
|
203
187
|
end
|
204
188
|
|
205
189
|
describe "#cast_signal_argument" do
|
@@ -2,6 +2,8 @@ require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
require 'ffi-gobject'
|
4
4
|
|
5
|
+
GirFFI.setup :GIMarshallingTests
|
6
|
+
|
5
7
|
describe GObject do
|
6
8
|
it "has type_init as a public method" do
|
7
9
|
assert GObject.respond_to?('type_init')
|
@@ -48,5 +50,30 @@ describe GObject do
|
|
48
50
|
assert_equal "GStrv", GObject.type_name(GObject::TYPE_STRV)
|
49
51
|
assert_equal "GHashTable", GObject.type_name(GObject::TYPE_HASH_TABLE)
|
50
52
|
end
|
51
|
-
end
|
52
53
|
|
54
|
+
describe "::object_class_from_instance" do
|
55
|
+
it "returns a GObject::ObjectClass with the correct GType" do
|
56
|
+
obj = GIMarshallingTests::OverridesObject.new
|
57
|
+
object_class = GObject.object_class_from_instance obj
|
58
|
+
gtype = object_class.g_type_class.g_type
|
59
|
+
|
60
|
+
object_class.must_be_instance_of GObject::ObjectClass
|
61
|
+
gtype.must_equal GIMarshallingTests::OverridesObject.get_gtype
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "creating ParamSpecs" do
|
66
|
+
describe "#param_spec_int" do
|
67
|
+
it "creates a GObject::ParamSpecInt" do
|
68
|
+
spec = GObject.param_spec_int("foo", "foo bar",
|
69
|
+
"The Foo Bar Property",
|
70
|
+
10, 20, 15,
|
71
|
+
3)
|
72
|
+
spec.must_be_instance_of GObject::ParamSpecInt
|
73
|
+
spec.minimum.must_equal 10
|
74
|
+
spec.maximum.must_equal 20
|
75
|
+
spec.default_value.must_equal 15
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'ffi-gobject'
|
4
|
+
|
5
|
+
describe GObject::ObjectClass do
|
6
|
+
describe "#list_properties" do
|
7
|
+
it "returns GIMarshallingTests::OverridesObject's properties" do
|
8
|
+
obj = GIMarshallingTests::OverridesObject.new
|
9
|
+
object_class = GObject.object_class_from_instance obj
|
10
|
+
|
11
|
+
info = get_introspection_data 'GIMarshallingTests', 'OverridesObject'
|
12
|
+
expected_props = info.properties.map(&:name)
|
13
|
+
expected_props += info.parent.properties.map(&:name)
|
14
|
+
|
15
|
+
props = object_class.list_properties
|
16
|
+
prop_names = props.map(&:get_name)
|
17
|
+
|
18
|
+
prop_names.sort.must_equal expected_props.sort
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'ffi-gobject/ruby_style'
|
4
|
+
|
5
|
+
describe GObject::RubyStyle do
|
6
|
+
class RubyStyleTest
|
7
|
+
include GObject::RubyStyle
|
8
|
+
def get_x
|
9
|
+
@x
|
10
|
+
end
|
11
|
+
def set_x(val)
|
12
|
+
@x = val
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { RubyStyleTest.new }
|
17
|
+
|
18
|
+
it 'reads x by calling get_x' do
|
19
|
+
subject.set_x(1)
|
20
|
+
assert_equal 1, subject.x
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'writes x by calling set_x' do
|
24
|
+
subject.x = 2
|
25
|
+
assert_equal 2, subject.x
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'delegates signal_connect to GObject' do
|
29
|
+
mock(GObject).signal_connect(subject, 'some-event')
|
30
|
+
subject.signal_connect('some-event') do
|
31
|
+
nothing
|
32
|
+
end
|
33
|
+
|
34
|
+
RR.verify
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe GObjectIntrospection::IConstantInfo do
|
4
|
-
describe "for GLib::
|
4
|
+
describe "for GLib::USEC_PER_SEC, a constant of type :gint32" do
|
5
5
|
before do
|
6
|
-
@info = get_introspection_data 'GLib', '
|
6
|
+
@info = get_introspection_data 'GLib', 'USEC_PER_SEC'
|
7
7
|
end
|
8
8
|
|
9
9
|
it "returns :gint32 as its type" do
|
10
10
|
assert_equal :gint32, @info.constant_type.tag
|
11
11
|
end
|
12
12
|
|
13
|
-
it "returns a value union with member :v_int32 with value
|
14
|
-
assert_equal
|
13
|
+
it "returns a value union with member :v_int32 with value 1_000_000" do
|
14
|
+
assert_equal 1_000_000, @info.value_union[:v_int32]
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns 1 as its value" do
|
18
|
-
assert_equal
|
18
|
+
assert_equal 1_000_000, @info.value
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -40,18 +40,18 @@ describe GObjectIntrospection::IRepository do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe "enumerating the infos for
|
43
|
+
describe "enumerating the infos for GObject" do
|
44
44
|
setup do
|
45
45
|
@gir = GObjectIntrospection::IRepository.default
|
46
|
-
@gir.require '
|
46
|
+
@gir.require 'GObject', "2.0"
|
47
47
|
end
|
48
48
|
|
49
49
|
should "yield more than one object" do
|
50
|
-
assert_operator @gir.n_infos('
|
50
|
+
assert_operator @gir.n_infos('GObject'), :>, 0
|
51
51
|
end
|
52
52
|
|
53
53
|
should "yield IBaseInfo objects" do
|
54
|
-
assert_kind_of GObjectIntrospection::IBaseInfo, @gir.info('
|
54
|
+
assert_kind_of GObjectIntrospection::IBaseInfo, @gir.info('GObject', 0)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'ffi-gtk3'
|
4
|
+
|
5
|
+
describe Gtk do
|
6
|
+
describe "::init" do
|
7
|
+
before do
|
8
|
+
save_module :Gtk
|
9
|
+
::Object.const_set :Gtk, Module.new
|
10
|
+
Gtk.class_eval do
|
11
|
+
def self.init arr
|
12
|
+
["baz", "qux", "zonk"]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
stub(Gtk)._setup_method { }
|
16
|
+
|
17
|
+
load 'ffi-gtk/base.rb'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "does not take any arguments" do
|
21
|
+
assert_raises(ArgumentError) { Gtk.init 1, ["foo"] }
|
22
|
+
assert_raises(ArgumentError) { Gtk.init ["foo"] }
|
23
|
+
assert_nothing_raised { Gtk.init }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "replaces ARGV with the tail of the result of the original init function" do
|
27
|
+
ARGV.replace ["foo", "bar"]
|
28
|
+
Gtk.init
|
29
|
+
assert_equal ["qux", "zonk"], ARGV.to_a
|
30
|
+
end
|
31
|
+
|
32
|
+
after do
|
33
|
+
restore_module :Gtk
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/test/gir_ffi_test_helper.rb
CHANGED
@@ -21,14 +21,18 @@ module GObjectIntrospection
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
# Preload data for Gtk+ version 2.0.
|
25
|
-
gir = GObjectIntrospection::IRepository.default
|
26
|
-
gir.require "Gtk", "2.0"
|
27
|
-
|
28
24
|
# Need a dummy module for some tests.
|
29
25
|
module DummyLib
|
30
26
|
end
|
31
27
|
|
28
|
+
# Global sequence provider. Needed to make unique class names.
|
29
|
+
class Sequence
|
30
|
+
@@seq = 0
|
31
|
+
def self.next
|
32
|
+
@@seq += 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
32
36
|
class MiniTest::Unit::TestCase
|
33
37
|
def cws code
|
34
38
|
code.gsub(/(^\s*|\s*$)/, "")
|
@@ -1,31 +1,47 @@
|
|
1
1
|
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
|
4
|
-
describe "Class derivation" do
|
5
|
-
before do
|
6
|
-
save_module :GIMarshallingTests
|
7
|
-
GirFFI.setup :GIMarshallingTests
|
8
|
-
end
|
3
|
+
GirFFI.setup :Regress
|
9
4
|
|
10
|
-
|
5
|
+
# Tests deriving Ruby classes from GObject classes.
|
6
|
+
describe "For derived classes" do
|
7
|
+
describe "setting up methods when first called" do
|
11
8
|
before do
|
12
|
-
|
13
|
-
|
9
|
+
save_module :GIMarshallingTests
|
10
|
+
GirFFI.setup :GIMarshallingTests
|
14
11
|
end
|
15
12
|
|
16
|
-
|
17
|
-
|
13
|
+
describe "when an interface is mixed in" do
|
14
|
+
before do
|
15
|
+
@klass = Class.new GIMarshallingTests::OverridesObject
|
16
|
+
@klass.send :include, GIMarshallingTests::Interface
|
17
|
+
end
|
18
|
+
|
19
|
+
it "finds class methods in the superclass" do
|
20
|
+
@klass.returnv
|
21
|
+
end
|
22
|
+
|
23
|
+
it "finds instance methods in the superclass" do
|
24
|
+
obj = @klass.new
|
25
|
+
result = obj.method
|
26
|
+
result.must_equal 42
|
27
|
+
end
|
18
28
|
end
|
19
29
|
|
20
|
-
|
21
|
-
|
22
|
-
result = obj.method
|
23
|
-
result.must_equal 42
|
30
|
+
after do
|
31
|
+
restore_module :GIMarshallingTests
|
24
32
|
end
|
25
33
|
end
|
26
34
|
|
27
|
-
|
28
|
-
|
35
|
+
describe "the initializer" do
|
36
|
+
it "does not have to call super" do
|
37
|
+
klass = Class.new Regress::TestSubObj do
|
38
|
+
def initialize *args
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
obj = klass.new
|
43
|
+
obj.must_be_instance_of klass
|
44
|
+
obj.to_ptr.wont_be_nil
|
45
|
+
end
|
29
46
|
end
|
30
47
|
end
|
31
|
-
|