gir_ffi 0.2.3 → 0.3.0
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 +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
@@ -7,10 +7,12 @@ GirFFI.setup :Regress
|
|
7
7
|
describe "Pretty-printing" do
|
8
8
|
def assert_syntax_ok str
|
9
9
|
tmp = Tempfile.new "gir_ffi"
|
10
|
+
# TODO: Make #pretty_print add this preamble.
|
11
|
+
tmp.write "# coding: utf-8\n"
|
10
12
|
tmp.write str
|
11
13
|
tmp.flush
|
12
14
|
is_ok = `ruby -c #{tmp.path} 2>&1`
|
13
|
-
|
15
|
+
is_ok.must_match(/^Syntax OK/)
|
14
16
|
end
|
15
17
|
|
16
18
|
describe "for the Regress module" do
|
data/test/test_helper.rb
CHANGED
data/test/type_builder_test.rb
CHANGED
@@ -1,26 +1,9 @@
|
|
1
1
|
require File.expand_path('gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
|
+
require 'ffi-gtk3'
|
4
|
+
|
3
5
|
class TypeBuilderTest < MiniTest::Spec
|
4
6
|
context "The Builder::Type class" do
|
5
|
-
context "for Gtk::Widget" do
|
6
|
-
setup do
|
7
|
-
@cbuilder = GirFFI::Builder::Type::Object.new get_introspection_data('Gtk', 'Widget')
|
8
|
-
end
|
9
|
-
|
10
|
-
context "looking at Gtk::Widget#show" do
|
11
|
-
setup do
|
12
|
-
@go = get_method_introspection_data 'Gtk', 'Widget', 'show'
|
13
|
-
end
|
14
|
-
|
15
|
-
should "delegate definition to Builder::Function" do
|
16
|
-
code = @cbuilder.send :function_definition, @go
|
17
|
-
expected = GirFFI::Builder::Function.new(@go, Gtk::Lib).generate
|
18
|
-
assert_equal cws(expected), cws(code)
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
7
|
context 'the find_signal method' do
|
25
8
|
should 'find the signal "test" for TestObj' do
|
26
9
|
builder = GirFFI::Builder::Type::Object.new get_introspection_data('Regress', 'TestObj')
|
@@ -2,18 +2,104 @@ require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
describe GirFFI::ArgHelper do
|
4
4
|
describe "::ptr_to_typed_array" do
|
5
|
-
describe "for pointers to class types" do
|
5
|
+
describe "for pointers to arrays of pointers to class types" do
|
6
6
|
it "reads an array of pointers and wraps each in the class" do
|
7
7
|
c = Class.new do
|
8
8
|
def self.wrap a; "wrapped: #{a}"; end
|
9
9
|
end
|
10
10
|
|
11
11
|
mock(ptr = Object.new).read_array_of_pointer(2) { [:a, :b] }
|
12
|
+
mock(ptr).null? { false }
|
12
13
|
|
13
14
|
result = GirFFI::ArgHelper.ptr_to_typed_array [:pointer, c], ptr, 2
|
14
15
|
|
15
16
|
assert_equal ["wrapped: a", "wrapped: b"], result
|
16
17
|
end
|
18
|
+
|
19
|
+
it "returns an empty array when passed a null pointer" do
|
20
|
+
result = GirFFI::ArgHelper.ptr_to_typed_array [:pointer, Class.new], FFI::Pointer.new(0), 42
|
21
|
+
result.must_equal []
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns an empty array when passed nil" do
|
25
|
+
result = GirFFI::ArgHelper.ptr_to_typed_array [:pointer, Class.new], nil, 42
|
26
|
+
result.must_equal []
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "for pointers to arrays of class types" do
|
31
|
+
it "returns an empty array when passed a null pointer" do
|
32
|
+
result = GirFFI::ArgHelper.ptr_to_typed_array Class.new, FFI::Pointer.new(0), 42
|
33
|
+
result.must_equal []
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns an empty array when passed nil" do
|
37
|
+
result = GirFFI::ArgHelper.ptr_to_typed_array Class.new, nil, 42
|
38
|
+
result.must_equal []
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "for pointers to string arrays" do
|
43
|
+
it "returns an empty array when passed a null pointer" do
|
44
|
+
result = GirFFI::ArgHelper.ptr_to_typed_array :utf8, FFI::Pointer.new(0), 42
|
45
|
+
result.must_equal []
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns an empty array when passed nil" do
|
49
|
+
result = GirFFI::ArgHelper.ptr_to_typed_array :utf8, nil, 42
|
50
|
+
result.must_equal []
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "for pointers to arrays of base types" do
|
55
|
+
it "returns an empty array when passed a null pointer" do
|
56
|
+
result = GirFFI::ArgHelper.ptr_to_typed_array :gint32, FFI::Pointer.new(0), 0
|
57
|
+
result.must_equal []
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns an empty array when passed nil" do
|
61
|
+
result = GirFFI::ArgHelper.ptr_to_typed_array :gint32, nil, 0
|
62
|
+
result.must_equal []
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#object_to_inptr" do
|
68
|
+
describe "when called with an object implementing to_ptr" do
|
69
|
+
it "returns the result of to_ptr" do
|
70
|
+
obj = Object.new
|
71
|
+
def obj.to_ptr; :test_value; end
|
72
|
+
assert_equal :test_value, GirFFI::ArgHelper.object_to_inptr(obj)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "when called with nil" do
|
77
|
+
it "returns nil" do
|
78
|
+
assert_equal nil, GirFFI::ArgHelper.object_to_inptr(nil)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "when called with a string" do
|
83
|
+
it "stores the string in GirFFI::ArgHelper::OBJECT_STORE" do
|
84
|
+
str = "Foo"
|
85
|
+
ptr = GirFFI::ArgHelper.object_to_inptr(str)
|
86
|
+
result = GirFFI::ArgHelper::OBJECT_STORE[ptr.address]
|
87
|
+
result.must_equal str
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "::object_pointer_to_object" do
|
93
|
+
it "finds the wrapping class by gtype and wraps the pointer in it" do
|
94
|
+
klsptr = GirFFI::InOutPointer.from :gtype, 0xdeadbeef
|
95
|
+
objptr = GirFFI::InOutPointer.from :pointer, klsptr
|
96
|
+
|
97
|
+
object_class = Class.new
|
98
|
+
mock(GirFFI::Builder).build_by_gtype(0xdeadbeef) { object_class }
|
99
|
+
mock(object_class).wrap(objptr) { "good-result" }
|
100
|
+
|
101
|
+
r = GirFFI::ArgHelper.object_pointer_to_object objptr
|
102
|
+
assert_equal "good-result", r
|
17
103
|
end
|
18
104
|
end
|
19
105
|
end
|
data/test/unit/builder_test.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
|
3
3
|
describe GirFFI::Builder do
|
4
4
|
describe "::itypeinfo_to_callback_ffitype" do
|
5
5
|
describe "for an :interface argument" do
|
6
|
-
|
6
|
+
before do
|
7
7
|
@iface = Object.new
|
8
8
|
stub(@info = Object.new).interface { @iface }
|
9
9
|
stub(@info).tag { :interface }
|
@@ -27,5 +27,117 @@ describe GirFFI::Builder do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
describe "building Regress::TestSubObj" do
|
32
|
+
before do
|
33
|
+
save_module :Regress
|
34
|
+
save_module :GObject
|
35
|
+
GirFFI::Builder.build_class get_introspection_data('Regress', 'TestSubObj')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "builds Regress namespace" do
|
39
|
+
assert Regress.const_defined? :Lib
|
40
|
+
assert Regress.respond_to? :method_missing
|
41
|
+
end
|
42
|
+
|
43
|
+
it "builds parent classes also" do
|
44
|
+
assert Regress.const_defined? :TestObj
|
45
|
+
assert Object.const_defined? :GObject
|
46
|
+
assert GObject.const_defined? :Object
|
47
|
+
end
|
48
|
+
|
49
|
+
it "sets up the inheritance chain" do
|
50
|
+
ancestors = Regress::TestSubObj.ancestors
|
51
|
+
assert_equal [
|
52
|
+
Regress::TestSubObj,
|
53
|
+
Regress::TestObj,
|
54
|
+
GObject::Object
|
55
|
+
], ancestors[0..2]
|
56
|
+
end
|
57
|
+
|
58
|
+
it "creates a Regress::TestSubObj#to_ptr method" do
|
59
|
+
assert Regress::TestSubObj.public_method_defined? :to_ptr
|
60
|
+
end
|
61
|
+
|
62
|
+
after do
|
63
|
+
restore_module :Regress
|
64
|
+
restore_module :GObject
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "building Regress" do
|
69
|
+
before do
|
70
|
+
save_module :Regress
|
71
|
+
GirFFI::Builder.build_module 'Regress'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "creates a Lib module ready to attach functions from the shared library" do
|
75
|
+
gir = GObjectIntrospection::IRepository.default
|
76
|
+
expected = [gir.shared_library('Regress')]
|
77
|
+
assert_equal expected, Regress::Lib.ffi_libraries.map(&:name)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "creates an array CALLBACKS inside the Regress::Lib module" do
|
81
|
+
assert_equal [], Regress::Lib::CALLBACKS
|
82
|
+
end
|
83
|
+
|
84
|
+
it "does not replace existing module" do
|
85
|
+
oldmodule = Regress
|
86
|
+
GirFFI::Builder.build_module 'Regress'
|
87
|
+
assert_equal oldmodule, Regress
|
88
|
+
end
|
89
|
+
|
90
|
+
it "does not replace existing Lib module" do
|
91
|
+
oldmodule = Regress::Lib
|
92
|
+
GirFFI::Builder.build_module 'Regress'
|
93
|
+
assert_equal oldmodule, Regress::Lib
|
94
|
+
end
|
95
|
+
|
96
|
+
after do
|
97
|
+
restore_module :Regress
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "looking at Regress.test_array_gint32_in" do
|
102
|
+
setup do
|
103
|
+
save_module :Regress
|
104
|
+
GirFFI::Builder.build_module 'Regress'
|
105
|
+
@go = get_introspection_data 'Regress', 'test_array_gint32_in'
|
106
|
+
end
|
107
|
+
|
108
|
+
it "has correct introspection data" do
|
109
|
+
gir = GObjectIntrospection::IRepository.default
|
110
|
+
gir.require "Regress", nil
|
111
|
+
go2 = gir.find_by_name "Regress", "test_array_gint32_in"
|
112
|
+
assert_equal go2, @go
|
113
|
+
end
|
114
|
+
|
115
|
+
it "attaches function to Regress::Lib" do
|
116
|
+
GirFFI::Builder.send :attach_ffi_function, Regress::Lib, @go
|
117
|
+
assert_defines_singleton_method Regress::Lib, :regress_test_array_gint32_in
|
118
|
+
end
|
119
|
+
|
120
|
+
it "has :pointer, :pointer as types of the arguments for the attached function" do
|
121
|
+
assert_equal [:int32, :pointer], GirFFI::Builder.send(:ffi_function_argument_types, @go)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "has :void as return type for the attached function" do
|
125
|
+
assert_equal :int32, GirFFI::Builder.send(:ffi_function_return_type, @go)
|
126
|
+
end
|
127
|
+
|
128
|
+
after do
|
129
|
+
restore_module :Regress
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "looking at Regress::TestObj#instance_method" do
|
134
|
+
setup do
|
135
|
+
@go = get_method_introspection_data 'Regress', 'TestObj', 'instance_method'
|
136
|
+
end
|
137
|
+
|
138
|
+
it "has :pointer as types of the arguments for the attached function" do
|
139
|
+
assert_equal [:pointer], GirFFI::Builder.send(:ffi_function_argument_types, @go)
|
140
|
+
end
|
141
|
+
end
|
30
142
|
end
|
31
143
|
|
@@ -13,6 +13,7 @@ describe GirFFI::Builder::Function do
|
|
13
13
|
|
14
14
|
it "builds a correct definition of Regress:test_array_fixed_out_objects" do
|
15
15
|
go = get_introspection_data 'Regress', 'test_array_fixed_out_objects'
|
16
|
+
skip unless go
|
16
17
|
fbuilder = GirFFI::Builder::Function.new go, DummyLib
|
17
18
|
code = fbuilder.generate
|
18
19
|
|
@@ -23,7 +24,7 @@ describe GirFFI::Builder::Function do
|
|
23
24
|
_v2 = _v1.to_sized_array_value 2
|
24
25
|
return _v2
|
25
26
|
end
|
26
|
-
|
27
|
+
CODE
|
27
28
|
|
28
29
|
assert_equal expected.reset_indentation, code
|
29
30
|
end
|
@@ -159,14 +160,14 @@ describe GirFFI::Builder::Function do
|
|
159
160
|
end
|
160
161
|
|
161
162
|
it "builds a correct definition for a simple method" do
|
162
|
-
go = get_method_introspection_data '
|
163
|
+
go = get_method_introspection_data 'Regress', 'TestObj', 'instance_method'
|
163
164
|
fbuilder = GirFFI::Builder::Function.new go, DummyLib
|
164
165
|
code = fbuilder.generate
|
165
166
|
|
166
167
|
expected = <<-CODE
|
167
|
-
def
|
168
|
-
DummyLib.
|
169
|
-
|
168
|
+
def instance_method
|
169
|
+
_v1 = DummyLib.regress_test_obj_instance_method self
|
170
|
+
return _v1
|
170
171
|
end
|
171
172
|
CODE
|
172
173
|
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
GirFFI.setup :GIMarshallingTests
|
4
|
+
|
5
|
+
describe GirFFI do
|
6
|
+
describe "::define_type" do
|
7
|
+
describe "without a block" do
|
8
|
+
before do
|
9
|
+
@klass = Class.new GIMarshallingTests::OverridesObject
|
10
|
+
Object.const_set "Derived#{Sequence.next}", @klass
|
11
|
+
@gtype = GirFFI.define_type @klass
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a GType for the derived class" do
|
15
|
+
parent_gtype = GIMarshallingTests::OverridesObject.get_gtype
|
16
|
+
@gtype.wont_equal parent_gtype
|
17
|
+
GObject.type_name(@gtype).must_equal @klass.name
|
18
|
+
end
|
19
|
+
|
20
|
+
it "makes #get_gtype on the registered class return the new GType" do
|
21
|
+
@klass.get_gtype.must_equal @gtype
|
22
|
+
end
|
23
|
+
|
24
|
+
it "registers a type with the same size as the parent" do
|
25
|
+
q = GObject.type_query @gtype
|
26
|
+
q.instance_size.must_equal GIMarshallingTests::OverridesObject::Struct.size
|
27
|
+
end
|
28
|
+
|
29
|
+
it "creates a struct class for the derived class with just one member" do
|
30
|
+
@klass::Struct.members.must_equal [:parent]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "allows the new class to be instantiated" do
|
34
|
+
obj = @klass.new
|
35
|
+
type = GObject.type_from_instance obj
|
36
|
+
type.must_equal @gtype
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "with a block with a call to #install_property" do
|
41
|
+
before do
|
42
|
+
@klass = Class.new GIMarshallingTests::OverridesObject
|
43
|
+
Object.const_set "Derived#{Sequence.next}", @klass
|
44
|
+
@gtype = GirFFI.define_type @klass do
|
45
|
+
install_property GObject.param_spec_int("foo", "foo bar",
|
46
|
+
"The Foo Bar Property",
|
47
|
+
10, 20, 15,
|
48
|
+
3)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "registers a type that is bigger than the parent" do
|
53
|
+
q = GObject.type_query @gtype
|
54
|
+
q.instance_size.must_be :>, GIMarshallingTests::OverridesObject::Struct.size
|
55
|
+
end
|
56
|
+
|
57
|
+
it "gives the types Struct the fields :parent and :foo" do
|
58
|
+
@klass::Struct.members.must_equal [:parent, :foo]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "creates accessor functions for the property" do
|
62
|
+
obj = @klass.new
|
63
|
+
obj.foo = 13
|
64
|
+
obj.foo.must_equal 13
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -4,7 +4,7 @@ require 'gir_ffi/in_out_pointer'
|
|
4
4
|
|
5
5
|
describe GirFFI::InOutPointer do
|
6
6
|
describe "an instance created with .from" do
|
7
|
-
|
7
|
+
before do
|
8
8
|
@result = GirFFI::InOutPointer.from :gint32, 23
|
9
9
|
end
|
10
10
|
|
@@ -28,7 +28,7 @@ describe GirFFI::InOutPointer do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "an instance created with .from_array" do
|
31
|
-
|
31
|
+
before do
|
32
32
|
@result = GirFFI::InOutPointer.from_array :gint32, [24, 13]
|
33
33
|
end
|
34
34
|
|
@@ -67,7 +67,7 @@ describe GirFFI::InOutPointer do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
describe "in instance created with .for" do
|
70
|
-
|
70
|
+
before do
|
71
71
|
@result = GirFFI::InOutPointer.for :gint32
|
72
72
|
end
|
73
73
|
|
@@ -11,6 +11,22 @@ describe GirFFI::Builder::Type::Interface do
|
|
11
11
|
assert_equal "module Bar\n extend InterfaceBase\nend", builder.pretty_print
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
describe "#build_class" do
|
16
|
+
before do
|
17
|
+
info = get_introspection_data 'GObject', 'TypePlugin'
|
18
|
+
@bldr = GirFFI::Builder::Type::Interface.new info
|
19
|
+
@iface = @bldr.build_class
|
20
|
+
end
|
21
|
+
|
22
|
+
it "builds an interface as a module" do
|
23
|
+
assert_instance_of Module, @iface
|
24
|
+
end
|
25
|
+
|
26
|
+
it "creates methods on the interface" do
|
27
|
+
assert_defines_instance_method @iface, :complete_interface_info
|
28
|
+
end
|
29
|
+
end
|
14
30
|
end
|
15
31
|
|
16
32
|
|
@@ -24,4 +24,19 @@ describe GirFFI::Builder::Type::Object do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
describe "#function_definition" do
|
29
|
+
before do
|
30
|
+
@cbuilder = GirFFI::Builder::Type::Object.new get_introspection_data('Regress', 'TestObj')
|
31
|
+
@go = get_method_introspection_data 'Regress', 'TestObj', 'instance_method'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "delegates definition to Builder::Function" do
|
35
|
+
code = @cbuilder.send :function_definition, @go
|
36
|
+
expected = GirFFI::Builder::Function.new(@go, Regress::Lib).generate
|
37
|
+
assert_equal cws(expected), cws(code)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
27
42
|
end
|
@@ -75,11 +75,15 @@ describe GirFFI::Builder::Type::Struct do
|
|
75
75
|
stub(GirFFI::Builder).build_module('Foo') { m }
|
76
76
|
|
77
77
|
c = Class.new
|
78
|
+
c::Struct = Class.new
|
78
79
|
|
79
80
|
refute c.method_defined?(:bar)
|
80
81
|
refute c.method_defined?(:bar=)
|
81
82
|
|
82
|
-
@builder.instance_eval {
|
83
|
+
@builder.instance_eval {
|
84
|
+
@klass = c
|
85
|
+
@structklass = c::Struct
|
86
|
+
}
|
83
87
|
@builder.send :setup_field_accessors
|
84
88
|
|
85
89
|
assert c.method_defined?(:bar)
|
data/test/{unintrospectable_type_builder_test.rb → unit/unintrospectable_type_builder_test.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
1
|
+
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe GirFFI::Builder::Type::Unintrospectable do
|
4
4
|
describe "building the GLocalFile type" do
|
@@ -47,4 +47,21 @@ describe GirFFI::Builder::Type::Unintrospectable do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
# FIXME: Testing a private method, and with rather a lot of
|
52
|
+
# mocking, too.
|
53
|
+
describe "#interfaces" do
|
54
|
+
it "skips interfaces that have no introspection data" do
|
55
|
+
bldr = GirFFI::Builder::Type::Unintrospectable.new(:some_type)
|
56
|
+
|
57
|
+
mock(bldr).interface_gtypes { [:foo, :bar ] }
|
58
|
+
mock(gir = Object.new).find_by_gtype(:foo) { :foo_info }
|
59
|
+
mock(gir).find_by_gtype(:bar) { nil }
|
60
|
+
bldr.instance_eval { @gir = gir }
|
61
|
+
mock(GirFFI::Builder).build_class(:foo_info) { :foo_module }
|
62
|
+
|
63
|
+
result = bldr.send :interfaces
|
64
|
+
result.must_equal [:foo_module]
|
65
|
+
end
|
66
|
+
end
|
50
67
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe GirFFI::UserDefined::IObjectInfo do
|
4
|
+
it "has the attribute #properties" do
|
5
|
+
inf = GirFFI::UserDefined::IObjectInfo.new
|
6
|
+
inf.properties.must_equal []
|
7
|
+
inf.properties << :foo
|
8
|
+
inf.properties.must_equal [:foo]
|
9
|
+
inf.properties = [:bar, :baz]
|
10
|
+
inf.properties.must_equal [:bar, :baz]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "derives from GirFFI::UserDefined::IRegisteredTypeInfo" do
|
14
|
+
inf = GirFFI::UserDefined::IObjectInfo.new
|
15
|
+
inf.must_be_kind_of GirFFI::UserDefined::IRegisteredTypeInfo
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe GirFFI::UserDefined::IPropertyInfo do
|
4
|
+
it "has the attribute #property_type" do
|
5
|
+
inf = GirFFI::UserDefined::IPropertyInfo.new
|
6
|
+
inf.property_type = :foo
|
7
|
+
inf.property_type.must_equal :foo
|
8
|
+
end
|
9
|
+
|
10
|
+
it "derives from GirFFI::UserDefined::IBaseInfo" do
|
11
|
+
inf = GirFFI::UserDefined::IPropertyInfo.new
|
12
|
+
inf.must_be_kind_of GirFFI::UserDefined::IBaseInfo
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe GirFFI::UserDefined::IRegisteredTypeInfo do
|
4
|
+
it "derives from GirFFI::UserDefined::IBaseInfo" do
|
5
|
+
inf = GirFFI::UserDefined::IRegisteredTypeInfo.new
|
6
|
+
inf.must_be_kind_of GirFFI::UserDefined::IBaseInfo
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe GirFFI::Builder::Type::UserDefined do
|
4
|
+
describe "with a block with a call to #install_property" do
|
5
|
+
before do
|
6
|
+
@klass = Class.new GIMarshallingTests::OverridesObject
|
7
|
+
Object.const_set "Derived#{Sequence.next}", @klass
|
8
|
+
@builder = GirFFI::Builder::Type::UserDefined.new @klass do
|
9
|
+
install_property GObject.param_spec_int("foo", "foo bar",
|
10
|
+
"The Foo Bar Property",
|
11
|
+
10, 20, 15,
|
12
|
+
3)
|
13
|
+
end
|
14
|
+
@builder.build_class
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has one property of type GirFFI::UserDefined::IPropertyInfo" do
|
18
|
+
props = @builder.send(:properties)
|
19
|
+
props.length.must_equal 1
|
20
|
+
props[0].must_be_instance_of GirFFI::UserDefined::IPropertyInfo
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "the info attribute" do
|
24
|
+
before do
|
25
|
+
@info = @builder.info
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is an object of type GirFFI::UserDefined::IObjectInfo" do
|
29
|
+
@info.must_be_instance_of GirFFI::UserDefined::IObjectInfo
|
30
|
+
end
|
31
|
+
|
32
|
+
it "knows about the single property :foo" do
|
33
|
+
props = @info.properties
|
34
|
+
props.length.must_equal 1
|
35
|
+
foo_property = props[0]
|
36
|
+
foo_property.must_be_instance_of GirFFI::UserDefined::IPropertyInfo
|
37
|
+
foo_property.name.must_equal "foo"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|