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.
- data/History.txt +7 -0
- data/{README.rdoc → README.md} +31 -25
- data/Rakefile +1 -1
- data/TODO.rdoc +1 -1
- data/lib/ffi-glib.rb +5 -5
- data/lib/ffi-glib/container_class_methods.rb +1 -2
- data/lib/ffi-glib/list_methods.rb +16 -6
- data/lib/ffi-gobject.rb +4 -7
- data/lib/ffi-gobject/helper.rb +6 -6
- data/lib/ffi-gobject/object.rb +4 -4
- data/lib/ffi-gobject_introspection.rb +0 -1
- data/lib/ffi-gobject_introspection/g_error.rb +15 -5
- data/lib/ffi-gobject_introspection/i_base_info.rb +7 -4
- data/lib/ffi-gobject_introspection/i_function_info.rb +3 -1
- data/lib/ffi-gobject_introspection/i_repository.rb +8 -15
- data/lib/ffi-gobject_introspection/i_struct_info.rb +5 -10
- data/lib/gir_ffi-base.rb +2 -0
- data/lib/gir_ffi-base/glib/strv.rb +43 -0
- data/lib/{ffi-gobject_introspection/gobject_lib.rb → gir_ffi-base/gobject/lib.rb} +4 -2
- data/lib/gir_ffi/arg_helper.rb +4 -2
- data/lib/gir_ffi/builder.rb +1 -7
- data/lib/gir_ffi/builder/argument.rb +34 -108
- data/lib/gir_ffi/builder/argument/base.rb +26 -20
- data/lib/gir_ffi/builder/type/object.rb +14 -2
- data/lib/gir_ffi/builder/type/registered_type.rb +1 -11
- data/lib/gir_ffi/class_base.rb +21 -26
- data/lib/gir_ffi/in_pointer.rb +11 -5
- data/lib/gir_ffi/info_ext/i_type_info.rb +26 -0
- data/lib/gir_ffi/interface_base.rb +10 -0
- data/lib/gir_ffi/module_base.rb +14 -4
- data/lib/gir_ffi/object_base.rb +39 -0
- data/lib/gir_ffi/type_map.rb +1 -3
- data/lib/gir_ffi/version.rb +1 -1
- data/tasks/test.rake +33 -44
- data/test/{test_helper.rb → base_test_helper.rb} +2 -11
- data/test/ffi-glib/array_test.rb +1 -1
- data/test/ffi-glib/byte_array_test.rb +1 -1
- data/test/ffi-glib/hash_table_test.rb +30 -1
- data/test/ffi-glib/list_test.rb +1 -1
- data/test/ffi-glib/ptr_array_test.rb +1 -1
- data/test/ffi-glib/ruby_closure_test.rb +54 -0
- data/test/ffi-glib/s_list_test.rb +1 -1
- data/test/ffi-gobject/gobject_test.rb +1 -1
- data/test/ffi-gobject/helper_test.rb +103 -0
- data/test/ffi-gobject/object_class_test.rb +1 -1
- data/test/ffi-gobject/object_test.rb +1 -1
- data/test/ffi-gobject/ruby_style_test.rb +1 -1
- data/test/ffi-gobject/value_test.rb +1 -1
- data/test/ffi-gobject_introspection/i_base_info_test.rb +1 -1
- data/test/ffi-gobject_introspection/i_constant_info_test.rb +1 -1
- data/test/ffi-gobject_introspection/i_function_info_test.rb +1 -1
- data/test/ffi-gobject_introspection/i_object_info_test.rb +1 -1
- data/test/ffi-gobject_introspection/i_repository_test.rb +1 -1
- data/test/ffi-gobject_introspection/lib_test.rb +1 -1
- data/test/ffi-gobject_test.rb +120 -0
- data/test/{ffi-glib → gir_ffi-base/glib}/strv_test.rb +8 -5
- data/test/{unit → gir_ffi}/arg_helper_test.rb +2 -2
- data/test/{unit/argument_builder_test.rb → gir_ffi/builder/argument/base_test.rb} +1 -13
- data/test/{unit/function_builder_test.rb → gir_ffi/builder/function_test.rb} +2 -2
- data/test/{unit/module_builder_test.rb → gir_ffi/builder/module_test.rb} +1 -1
- data/test/{unit/callback_builder_test.rb → gir_ffi/builder/type/callback_test.rb} +1 -1
- data/test/{unit/constant_builder_test.rb → gir_ffi/builder/type/constant_test.rb} +1 -1
- data/test/{unit/enum_builder_test.rb → gir_ffi/builder/type/enum_test.rb} +1 -1
- data/test/{unit/interface_builder_test.rb → gir_ffi/builder/type/interface_test.rb} +1 -4
- data/test/{unit/object_type_builder_test.rb → gir_ffi/builder/type/object_test.rb} +21 -2
- data/test/{unit/struct_builder_test.rb → gir_ffi/builder/type/struct_test.rb} +1 -1
- data/test/{unit/unintrospectable_type_builder_test.rb → gir_ffi/builder/type/unintrospectable_test.rb} +1 -1
- data/test/{unit/union_builder_test.rb → gir_ffi/builder/type/union_test.rb} +9 -3
- data/test/{unit/user_defined_type_builder_test.rb → gir_ffi/builder/type/user_defined_test.rb} +4 -2
- data/test/gir_ffi/builder_test.rb +398 -0
- data/test/{unit → gir_ffi}/callback_helper_test.rb +1 -1
- data/test/{unit → gir_ffi}/class_base_test.rb +1 -1
- data/test/{unit → gir_ffi}/in_out_pointer_test.rb +1 -1
- data/test/{unit → gir_ffi}/in_pointer_test.rb +24 -3
- data/test/{unit → gir_ffi/info_ext}/i_field_info_test.rb +1 -1
- data/test/gir_ffi/info_ext/i_type_info_test.rb +71 -0
- data/test/{unit/user_defined_object_info_test.rb → gir_ffi/user_defined/i_object_info_test.rb} +1 -1
- data/test/{unit/user_defined_property_info_test.rb → gir_ffi/user_defined/i_property_info_test.rb} +1 -1
- data/test/{unit/user_defined_registered_type_info_test.rb → gir_ffi/user_defined/i_registered_type_info_test.rb} +1 -1
- data/test/{unit → gir_ffi}/variable_name_generator_test.rb +1 -1
- data/test/{unit/gir_ffi_test.rb → gir_ffi_test.rb} +24 -4
- data/test/gir_ffi_test_helper.rb +1 -1
- data/test/integration/derived_classes_test.rb +1 -1
- data/test/integration/generated_gimarshallingtests_test.rb +1 -1
- data/test/integration/generated_gio_test.rb +1 -1
- data/test/integration/generated_gobject_test.rb +1 -1
- data/test/integration/generated_regress_test.rb +2 -3
- data/test/integration/method_lookup_test.rb +1 -1
- data/test/integration/pretty_print_test.rb +1 -1
- data/test/introspection_test_helper.rb +11 -0
- metadata +71 -77
- data/lib/ffi-glib/strv.rb +0 -31
- data/test/builder_test.rb +0 -264
- data/test/ffi-glib/glib_overrides_test.rb +0 -38
- data/test/ffi-gobject/g_object_overrides_test.rb +0 -274
- data/test/girffi_test.rb +0 -27
- data/test/integration/generated_pango_test.rb +0 -20
- data/test/type_builder_test.rb +0 -36
- data/test/unit/builder_test.rb +0 -143
- data/test/unit/hash_table_element_type_provider_test.rb +0 -16
- data/test/unit/i_type_info_test.rb +0 -23
- data/test/unit/list_element_type_provider_test.rb +0 -13
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'gir_ffi_test_helper'
|
2
|
+
|
3
|
+
describe GObject::Helper do
|
4
|
+
before do
|
5
|
+
GirFFI.setup :Regress
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#signal_arguments_to_gvalue_array" do
|
9
|
+
describe "the result of wrapping test-with-static-scope-arg" do
|
10
|
+
setup do
|
11
|
+
o = Regress::TestSubObj.new
|
12
|
+
b = Regress::TestSimpleBoxedA.new
|
13
|
+
|
14
|
+
@gva =
|
15
|
+
GObject::Helper.signal_arguments_to_gvalue_array(
|
16
|
+
"test-with-static-scope-arg", o, b)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "be a GObject::ValueArray" do
|
20
|
+
assert_instance_of GObject::ValueArray, @gva
|
21
|
+
end
|
22
|
+
|
23
|
+
should "contain two values" do
|
24
|
+
assert_equal 2, @gva.n_values
|
25
|
+
end
|
26
|
+
|
27
|
+
should "have a first value with GType for TestSubObj" do
|
28
|
+
assert_equal Regress::TestSubObj.get_gtype, (@gva.get_nth 0).current_gtype
|
29
|
+
end
|
30
|
+
|
31
|
+
should "have a second value with GType for TestSimpleBoxedA" do
|
32
|
+
assert_equal Regress::TestSimpleBoxedA.get_gtype, (@gva.get_nth 1).current_gtype
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#signal_argument_to_gvalue" do
|
38
|
+
it "maps a :utf8 argument to a string-valued GValue" do
|
39
|
+
stub(arg_t = Object.new).tag { :utf8 }
|
40
|
+
stub(info = Object.new).argument_type { arg_t }
|
41
|
+
val =
|
42
|
+
GObject::Helper.signal_argument_to_gvalue(
|
43
|
+
info, "foo")
|
44
|
+
assert_instance_of GObject::Value, val
|
45
|
+
assert_equal "foo", val.get_string
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#cast_back_signal_arguments" do
|
50
|
+
it "correctly casts back pointers for the test-with-static-scope-arg signal" do
|
51
|
+
o = Regress::TestSubObj.new
|
52
|
+
b = Regress::TestSimpleBoxedA.new
|
53
|
+
ud = GirFFI::ArgHelper.object_to_inptr "Hello!"
|
54
|
+
|
55
|
+
assert_equal "Hello!", GirFFI::ArgHelper::OBJECT_STORE[ud.address]
|
56
|
+
|
57
|
+
sig = o.class.find_signal "test-with-static-scope-arg"
|
58
|
+
|
59
|
+
gva =
|
60
|
+
GObject::Helper.cast_back_signal_arguments(
|
61
|
+
sig, o.class, o.to_ptr, b.to_ptr, ud)
|
62
|
+
|
63
|
+
klasses = gva.map {|it| it.class}
|
64
|
+
klasses.must_equal [ Regress::TestSubObj,
|
65
|
+
Regress::TestSimpleBoxedA,
|
66
|
+
String ]
|
67
|
+
gva[2].must_equal "Hello!"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#cast_signal_argument" do
|
72
|
+
describe "with info for an enum" do
|
73
|
+
before do
|
74
|
+
enuminfo = get_introspection_data 'GLib', 'DateMonth'
|
75
|
+
stub(arg_t = Object.new).interface { enuminfo }
|
76
|
+
stub(arg_t).tag { :interface }
|
77
|
+
stub(@info = Object.new).argument_type { arg_t }
|
78
|
+
end
|
79
|
+
|
80
|
+
it "casts an integer to its enum symbol" do
|
81
|
+
res = GObject::Helper.cast_signal_argument @info, 7
|
82
|
+
assert_equal :july, res
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "with info for an interface" do
|
87
|
+
before do
|
88
|
+
ifaceinfo = get_introspection_data 'Regress', 'TestInterface'
|
89
|
+
stub(arg_t = Object.new).interface { ifaceinfo }
|
90
|
+
stub(arg_t).tag { :interface }
|
91
|
+
stub(@info = Object.new).argument_type { arg_t }
|
92
|
+
end
|
93
|
+
|
94
|
+
it "casts the argument by calling #to_object on it" do
|
95
|
+
mock(ptr = Object.new).to_object { "good-result" }
|
96
|
+
res = GObject::Helper.cast_signal_argument @info, ptr
|
97
|
+
res.must_equal "good-result"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'gir_ffi_test_helper'
|
2
|
+
|
3
|
+
describe GObject do
|
4
|
+
before do
|
5
|
+
GirFFI.setup :Regress
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "::signal_emit" do
|
9
|
+
should "emit a signal" do
|
10
|
+
a = 1
|
11
|
+
o = Regress::TestSubObj.new
|
12
|
+
::GObject::Lib.g_signal_connect_data o, "test", Proc.new { a = 2 }, nil, nil, 0
|
13
|
+
GObject.signal_emit o, "test"
|
14
|
+
assert_equal 2, a
|
15
|
+
end
|
16
|
+
|
17
|
+
should "handle return values" do
|
18
|
+
s = Gio::SocketService.new
|
19
|
+
|
20
|
+
argtypes = [:pointer, :pointer, :pointer, :pointer]
|
21
|
+
callback = FFI::Function.new(:bool, argtypes) { |a,b,c,d| true }
|
22
|
+
::GObject::Lib.g_signal_connect_data s, "incoming", callback, nil, nil, 0
|
23
|
+
rv = GObject.signal_emit s, "incoming"
|
24
|
+
assert_equal true, rv.get_boolean
|
25
|
+
end
|
26
|
+
|
27
|
+
should "pass in extra arguments" do
|
28
|
+
o = Regress::TestSubObj.new
|
29
|
+
sb = Regress::TestSimpleBoxedA.new
|
30
|
+
sb.some_int8 = 31
|
31
|
+
sb.some_double = 2.42
|
32
|
+
sb.some_enum = :value2
|
33
|
+
b2 = nil
|
34
|
+
|
35
|
+
argtypes = [:pointer, :pointer, :pointer]
|
36
|
+
callback = FFI::Function.new(:void, argtypes) do |a,b,c|
|
37
|
+
b2 = b
|
38
|
+
end
|
39
|
+
::GObject::Lib.g_signal_connect_data o, "test-with-static-scope-arg", callback, nil, nil, 0
|
40
|
+
GObject.signal_emit o, "test-with-static-scope-arg", sb
|
41
|
+
|
42
|
+
sb2 = Regress::TestSimpleBoxedA.wrap b2
|
43
|
+
assert sb.equals(sb2)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "::signal_connect" do
|
48
|
+
should "install a signal handler" do
|
49
|
+
a = 1
|
50
|
+
o = Regress::TestSubObj.new
|
51
|
+
GObject.signal_connect(o, "test") { a = 2 }
|
52
|
+
GObject.signal_emit o, "test"
|
53
|
+
assert_equal 2, a
|
54
|
+
end
|
55
|
+
|
56
|
+
should "pass user data to handler" do
|
57
|
+
a = 1
|
58
|
+
o = Regress::TestSubObj.new
|
59
|
+
GObject.signal_connect(o, "test", 2) { |i, d| a = d }
|
60
|
+
GObject.signal_emit o, "test"
|
61
|
+
assert_equal 2, a
|
62
|
+
end
|
63
|
+
|
64
|
+
should "pass object to handler" do
|
65
|
+
o = Regress::TestSubObj.new
|
66
|
+
o2 = nil
|
67
|
+
GObject.signal_connect(o, "test") { |i, d| o2 = i }
|
68
|
+
GObject.signal_emit o, "test"
|
69
|
+
assert_instance_of Regress::TestSubObj, o2
|
70
|
+
assert_equal o.to_ptr, o2.to_ptr
|
71
|
+
end
|
72
|
+
|
73
|
+
should "not allow connecting an invalid signal" do
|
74
|
+
o = Regress::TestSubObj.new
|
75
|
+
assert_raises RuntimeError do
|
76
|
+
GObject.signal_connect(o, "not-really-a-signal") {}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
should "handle return values" do
|
81
|
+
s = Gio::SocketService.new
|
82
|
+
GObject.signal_connect(s, "incoming") { true }
|
83
|
+
rv = GObject.signal_emit s, "incoming"
|
84
|
+
assert_equal true, rv.get_boolean
|
85
|
+
end
|
86
|
+
|
87
|
+
should "require a block" do
|
88
|
+
o = Regress::TestSubObj.new
|
89
|
+
assert_raises ArgumentError do
|
90
|
+
GObject.signal_connect o, "test"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "connecting a signal with extra arguments" do
|
95
|
+
setup do
|
96
|
+
@a = nil
|
97
|
+
@b = 2
|
98
|
+
|
99
|
+
o = Regress::TestSubObj.new
|
100
|
+
sb = Regress::TestSimpleBoxedA.new
|
101
|
+
sb.some_int = 23
|
102
|
+
|
103
|
+
GObject.signal_connect(o, "test-with-static-scope-arg", 2) { |i, object, d|
|
104
|
+
@a = d
|
105
|
+
@b = object
|
106
|
+
}
|
107
|
+
GObject.signal_emit o, "test-with-static-scope-arg", sb
|
108
|
+
end
|
109
|
+
|
110
|
+
should "move the user data argument" do
|
111
|
+
assert_equal 2, @a
|
112
|
+
end
|
113
|
+
|
114
|
+
should "pass on the extra arguments" do
|
115
|
+
assert_instance_of Regress::TestSimpleBoxedA, @b
|
116
|
+
assert_equal 23, @b.some_int
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require 'ffi-glib/strv'
|
1
|
+
require 'base_test_helper'
|
4
2
|
|
5
3
|
describe GLib::Strv do
|
6
4
|
it "wraps a pointer" do
|
@@ -18,8 +16,13 @@ describe GLib::Strv do
|
|
18
16
|
|
19
17
|
describe "#each" do
|
20
18
|
it "yields each string element" do
|
21
|
-
|
22
|
-
|
19
|
+
ary = ["one", "two", "three"]
|
20
|
+
ptrs = ary.map {|a| FFI::MemoryPointer.from_string(a)}
|
21
|
+
ptrs << nil
|
22
|
+
block = FFI::MemoryPointer.new(:pointer, ptrs.length)
|
23
|
+
block.write_array_of_pointer ptrs
|
24
|
+
|
25
|
+
strv = GLib::Strv.new block
|
23
26
|
arr = []
|
24
27
|
strv.each do |str|
|
25
28
|
arr << str
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::ArgHelper do
|
4
4
|
describe "::ptr_to_typed_array" do
|
@@ -91,7 +91,7 @@ describe GirFFI::ArgHelper do
|
|
91
91
|
|
92
92
|
describe "::object_pointer_to_object" do
|
93
93
|
it "finds the wrapping class by gtype and wraps the pointer in it" do
|
94
|
-
klsptr = GirFFI::InOutPointer.from :
|
94
|
+
klsptr = GirFFI::InOutPointer.from :GType, 0xdeadbeef
|
95
95
|
objptr = GirFFI::InOutPointer.from :pointer, klsptr
|
96
96
|
|
97
97
|
object_class = Class.new
|
@@ -1,18 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::Builder::Argument::Base do
|
4
|
-
describe "#subtype_tag" do
|
5
|
-
it "returns :gpointer if the param_type is a pointer with tag :void" do
|
6
|
-
stub(subtype0 = Object.new).tag { :void }
|
7
|
-
stub(subtype0).pointer? { true }
|
8
|
-
stub(type = Object.new).param_type(0) { subtype0 }
|
9
|
-
|
10
|
-
provider = GirFFI::Builder::Argument::Base.new nil, nil, type
|
11
|
-
|
12
|
-
assert_equal :gpointer, provider.subtype_tag
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
4
|
describe "#subtype_tag_or_class_name" do
|
17
5
|
describe "for a simple type" do
|
18
6
|
it "returns the string ':void'" do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::Builder::Function do
|
4
4
|
describe "#pretty_print" do
|
@@ -56,7 +56,7 @@ describe GirFFI::Builder::Function do
|
|
56
56
|
def self.test_callback_destroy_notify callback, user_data, notify
|
57
57
|
_v1 = GirFFI::CallbackHelper.wrap_in_callback_args_mapper \"Regress\", \"TestCallbackUserData\", callback
|
58
58
|
DummyLib::CALLBACKS << _v1
|
59
|
-
_v2 = GirFFI::
|
59
|
+
_v2 = GirFFI::InPointer.from :void, user_data
|
60
60
|
_v3 = GirFFI::CallbackHelper.wrap_in_callback_args_mapper \"GLib\", \"DestroyNotify\", notify
|
61
61
|
DummyLib::CALLBACKS << _v3
|
62
62
|
_v4 = DummyLib.regress_test_callback_destroy_notify _v1, _v2, _v3
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::Builder::Type::Interface do
|
4
4
|
describe "#pretty_print" do
|
@@ -28,6 +28,3 @@ describe GirFFI::Builder::Type::Interface do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
@@ -1,6 +1,26 @@
|
|
1
|
-
require
|
1
|
+
require 'gir_ffi_test_helper'
|
2
2
|
|
3
3
|
describe GirFFI::Builder::Type::Object do
|
4
|
+
describe '#find_signal' do
|
5
|
+
it 'finds the signal "test" for TestObj' do
|
6
|
+
builder = GirFFI::Builder::Type::Object.new get_introspection_data('Regress', 'TestObj')
|
7
|
+
sig = builder.find_signal 'test'
|
8
|
+
assert_equal 'test', sig.name
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'finds the signal "test" for TestSubObj' do
|
12
|
+
builder = GirFFI::Builder::Type::Object.new get_introspection_data('Regress', 'TestSubObj')
|
13
|
+
sig = builder.find_signal 'test'
|
14
|
+
assert_equal 'test', sig.name
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'finds the signal "changed" for Gtk::Entry' do
|
18
|
+
builder = GirFFI::Builder::Type::Object.new get_introspection_data('Gtk', 'Entry')
|
19
|
+
sig = builder.find_signal 'changed'
|
20
|
+
assert_equal 'changed', sig.name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
4
24
|
describe "#find_property" do
|
5
25
|
it "finds a property specified on the class itself" do
|
6
26
|
builder = GirFFI::Builder::Type::Object.new(
|
@@ -38,5 +58,4 @@ describe GirFFI::Builder::Type::Object do
|
|
38
58
|
end
|
39
59
|
|
40
60
|
end
|
41
|
-
|
42
61
|
end
|