gir_ffi 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +14 -0
- data/TODO.rdoc +23 -5
- data/lib/ffi-glib/array.rb +14 -15
- data/lib/ffi-glib/container_class_methods.rb +0 -1
- data/lib/ffi-glib/hash_table.rb +3 -4
- data/lib/ffi-glib/ptr_array.rb +12 -4
- data/lib/ffi-glib/sized_array.rb +27 -7
- data/lib/ffi-gobject.rb +14 -15
- data/lib/ffi-gobject/closure.rb +1 -1
- data/lib/ffi-gobject/object.rb +40 -15
- data/lib/ffi-gobject/ruby_closure.rb +0 -1
- data/lib/ffi-gobject/value.rb +45 -21
- data/lib/ffi-gobject_introspection/i_arg_info.rb +4 -0
- data/lib/ffi-gobject_introspection/i_base_info.rb +42 -2
- data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
- data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -4
- data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_object_info.rb +2 -0
- data/lib/ffi-gobject_introspection/i_repository.rb +2 -3
- data/lib/ffi-gobject_introspection/i_struct_info.rb +3 -8
- data/lib/ffi-gobject_introspection/lib.rb +3 -0
- data/lib/gir_ffi-base.rb +3 -1
- data/lib/gir_ffi-base/gir_ffi/struct.rb +27 -0
- data/lib/gir_ffi-base/glib/boolean.rb +13 -1
- data/lib/gir_ffi-base/gobject.rb +7 -0
- data/lib/gir_ffi-base/gobject/lib.rb +0 -2
- data/lib/gir_ffi.rb +1 -3
- data/lib/gir_ffi/arg_helper.rb +4 -85
- data/lib/gir_ffi/builder.rb +5 -5
- data/lib/gir_ffi/builder_helper.rb +7 -0
- data/lib/gir_ffi/builders/argument_builder.rb +132 -0
- data/lib/gir_ffi/{base_argument_builder.rb → builders/base_argument_builder.rb} +32 -41
- data/lib/gir_ffi/builders/base_type_builder.rb +47 -0
- data/lib/gir_ffi/builders/callback_builder.rb +38 -0
- data/lib/gir_ffi/builders/constant_builder.rb +18 -0
- data/lib/gir_ffi/builders/enum_builder.rb +62 -0
- data/lib/gir_ffi/builders/error_argument_builder.rb +18 -0
- data/lib/gir_ffi/builders/field_builder.rb +94 -0
- data/lib/gir_ffi/builders/function_builder.rb +123 -0
- data/lib/gir_ffi/builders/interface_builder.rb +29 -0
- data/lib/gir_ffi/builders/mapping_method_builder.rb +88 -0
- data/lib/gir_ffi/builders/module_builder.rb +124 -0
- data/lib/gir_ffi/{null_argument_builder.rb → builders/null_argument_builder.rb} +0 -0
- data/lib/gir_ffi/builders/null_builder.rb +11 -0
- data/lib/gir_ffi/builders/object_builder.rb +123 -0
- data/lib/gir_ffi/{builder/property.rb → builders/property_builder.rb} +0 -0
- data/lib/gir_ffi/builders/registered_type_builder.rb +50 -0
- data/lib/gir_ffi/builders/return_value_builder.rb +68 -0
- data/lib/gir_ffi/builders/signal_builder.rb +91 -0
- data/lib/gir_ffi/builders/struct_builder.rb +35 -0
- data/lib/gir_ffi/builders/type_builder.rb +40 -0
- data/lib/gir_ffi/builders/unintrospectable_builder.rb +35 -0
- data/lib/gir_ffi/builders/union_builder.rb +34 -0
- data/lib/gir_ffi/builders/user_defined_builder.rb +103 -0
- data/lib/gir_ffi/builders/with_layout.rb +55 -0
- data/lib/gir_ffi/builders/with_methods.rb +44 -0
- data/lib/gir_ffi/callback_base.rb +31 -0
- data/lib/gir_ffi/class_base.rb +16 -10
- data/lib/gir_ffi/enum_base.rb +8 -4
- data/lib/gir_ffi/ffi_ext/pointer.rb +19 -2
- data/lib/gir_ffi/in_out_pointer.rb +38 -39
- data/lib/gir_ffi/in_pointer.rb +33 -18
- data/lib/gir_ffi/info_ext.rb +0 -4
- data/lib/gir_ffi/info_ext/i_arg_info.rb +0 -18
- data/lib/gir_ffi/info_ext/i_callable_info.rb +2 -1
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +6 -8
- data/lib/gir_ffi/info_ext/i_signal_info.rb +6 -21
- data/lib/gir_ffi/info_ext/i_type_info.rb +54 -29
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -1
- data/lib/gir_ffi/interface_base.rb +1 -1
- data/lib/gir_ffi/module_base.rb +5 -1
- data/lib/gir_ffi/object_base.rb +5 -1
- data/lib/gir_ffi/setter_argument_info.rb +4 -0
- data/lib/gir_ffi/signal_base.rb +21 -0
- data/lib/gir_ffi/struct_base.rb +24 -0
- data/lib/gir_ffi/type_base.rb +11 -0
- data/lib/gir_ffi/type_map.rb +4 -2
- data/lib/gir_ffi/union_base.rb +24 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/tasks/test.rake +73 -7
- data/test/base_test_helper.rb +3 -19
- data/test/ffi-glib/array_test.rb +6 -0
- data/test/ffi-glib/ptr_array_test.rb +13 -0
- data/test/ffi-glib/ruby_closure_test.rb +7 -7
- data/test/ffi-glib/sized_array_test.rb +2 -2
- data/test/ffi-gobject/gobject_test.rb +3 -12
- data/test/ffi-gobject/object_test.rb +33 -2
- data/test/ffi-gobject/value_test.rb +114 -1
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +2 -2
- data/test/ffi-gobject_introspection/i_object_info_test.rb +3 -3
- data/test/ffi-gobject_introspection/i_repository_test.rb +26 -21
- data/test/ffi-gobject_test.rb +14 -14
- data/test/gir_ffi-base/glib/boolean_test.rb +6 -0
- data/test/gir_ffi/arg_helper_test.rb +2 -122
- data/test/gir_ffi/builder_test.rb +67 -204
- data/test/gir_ffi/{argument_builder_test.rb → builders/argument_builder_test.rb} +230 -108
- data/test/gir_ffi/builders/base_argument_builder_test.rb +5 -0
- data/test/gir_ffi/builders/callback_builder_test.rb +50 -0
- data/test/gir_ffi/builders/constant_builder_test.rb +4 -0
- data/test/gir_ffi/{builder/type/enum_test.rb → builders/enum_builder_test.rb} +2 -3
- data/test/gir_ffi/builders/field_builder_test.rb +94 -0
- data/test/gir_ffi/{function_builder_test.rb → builders/function_builder_test.rb} +43 -24
- data/test/gir_ffi/{builder/type/interface_test.rb → builders/interface_builder_test.rb} +2 -2
- data/test/gir_ffi/{builder/module_test.rb → builders/module_builder_test.rb} +12 -13
- data/test/gir_ffi/{builder/type/object_test.rb → builders/object_builder_test.rb} +9 -9
- data/test/gir_ffi/{return_value_builder_test.rb → builders/return_value_builder_test.rb} +94 -58
- data/test/gir_ffi/builders/signal_builder_test.rb +62 -0
- data/test/gir_ffi/{builder/type/struct_test.rb → builders/struct_builder_test.rb} +36 -19
- data/test/gir_ffi/{builder/type/unintrospectable_test.rb → builders/unintrospectable_builder_test.rb} +3 -3
- data/test/gir_ffi/builders/union_builder_test.rb +29 -0
- data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb} +2 -2
- data/test/gir_ffi/callback_base_test.rb +11 -0
- data/test/gir_ffi/class_base_test.rb +22 -22
- data/test/gir_ffi/ffi_ext/pointer_test.rb +18 -0
- data/test/gir_ffi/in_out_pointer_test.rb +0 -7
- data/test/gir_ffi/in_pointer_test.rb +27 -3
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +16 -44
- data/test/gir_ffi/info_ext/i_type_info_test.rb +315 -74
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +6 -0
- data/test/gir_ffi/interface_base_test.rb +3 -5
- data/test/gir_ffi/object_base_test.rb +10 -6
- data/test/gir_ffi/type_map_test.rb +2 -2
- data/test/gir_ffi/unintrospectable_type_info_test.rb +2 -2
- data/test/gir_ffi_test_helper.rb +12 -4
- data/test/integration/generated_gimarshallingtests_test.rb +436 -76
- data/test/integration/generated_gio_test.rb +5 -11
- data/test/integration/generated_gobject_test.rb +8 -0
- data/test/integration/generated_regress_test.rb +755 -309
- data/test/integration/generated_secret_test.rb +2 -1
- metadata +73 -72
- data/lib/ffi-gobject/ruby_style.rb +0 -23
- data/lib/gir_ffi/argument_builder.rb +0 -154
- data/lib/gir_ffi/builder/field.rb +0 -60
- data/lib/gir_ffi/builder/module.rb +0 -127
- data/lib/gir_ffi/builder/type.rb +0 -39
- data/lib/gir_ffi/builder/type/base.rb +0 -48
- data/lib/gir_ffi/builder/type/callback.rb +0 -30
- data/lib/gir_ffi/builder/type/constant.rb +0 -22
- data/lib/gir_ffi/builder/type/enum.rb +0 -66
- data/lib/gir_ffi/builder/type/interface.rb +0 -33
- data/lib/gir_ffi/builder/type/object.rb +0 -134
- data/lib/gir_ffi/builder/type/registered_type.rb +0 -62
- data/lib/gir_ffi/builder/type/struct.rb +0 -34
- data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -39
- data/lib/gir_ffi/builder/type/union.rb +0 -34
- data/lib/gir_ffi/builder/type/user_defined.rb +0 -107
- data/lib/gir_ffi/builder/type/with_layout.rb +0 -62
- data/lib/gir_ffi/builder/type/with_methods.rb +0 -64
- data/lib/gir_ffi/callback.rb +0 -72
- data/lib/gir_ffi/callback_helper.rb +0 -11
- data/lib/gir_ffi/error_argument_builder.rb +0 -17
- data/lib/gir_ffi/function_builder.rb +0 -112
- data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_object_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_struct_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_union_info.rb +0 -12
- data/lib/gir_ffi/return_value_builder.rb +0 -81
- data/test/ffi-gobject/ruby_style_test.rb +0 -38
- data/test/gir_ffi/base_argument_builder_test.rb +0 -13
- data/test/gir_ffi/builder/type/callback_test.rb +0 -6
- data/test/gir_ffi/builder/type/constant_test.rb +0 -4
- data/test/gir_ffi/builder/type/union_test.rb +0 -12
- data/test/gir_ffi/callback_helper_test.rb +0 -10
- data/test/gir_ffi/callback_test.rb +0 -49
- data/test/gir_ffi/info_ext/i_arg_info_test.rb +0 -39
- data/test/gir_ffi/info_ext/i_object_info_test.rb +0 -14
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'gir_ffi_test_helper'
|
2
|
+
|
3
|
+
describe GirFFI::Builders::UnionBuilder do
|
4
|
+
let(:union_info) { get_introspection_data('GObject', 'TypeCValue') }
|
5
|
+
let(:builder) { GirFFI::Builders::UnionBuilder.new union_info }
|
6
|
+
|
7
|
+
describe "#setup_instance_method" do
|
8
|
+
it "returns false looking for a method that doesn't exist" do
|
9
|
+
builder.setup_instance_method('blub').must_equal false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#layout_specification" do
|
14
|
+
it "returns the correct layout for GObject::TypeCValue" do
|
15
|
+
builder.layout_specification.must_equal [:v_int, :int32, 0,
|
16
|
+
:v_long, :int64, 0,
|
17
|
+
:v_int64, :int64, 0,
|
18
|
+
:v_double, :double, 0,
|
19
|
+
:v_pointer, :pointer, 0]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#layout_superclass" do
|
24
|
+
it "returns FFI::Union" do
|
25
|
+
builder.layout_superclass.must_equal FFI::Union
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb}
RENAMED
@@ -2,7 +2,7 @@ require 'gir_ffi_test_helper'
|
|
2
2
|
|
3
3
|
GirFFI.setup :GIMarshallingTests
|
4
4
|
|
5
|
-
describe GirFFI::
|
5
|
+
describe GirFFI::Builders::UserDefinedBuilder do
|
6
6
|
describe "with type info containing one property" do
|
7
7
|
before do
|
8
8
|
@klass = Class.new GIMarshallingTests::OverridesObject
|
@@ -15,7 +15,7 @@ describe GirFFI::Builder::Type::UserDefined do
|
|
15
15
|
3)
|
16
16
|
end
|
17
17
|
|
18
|
-
@builder = GirFFI::
|
18
|
+
@builder = GirFFI::Builders::UserDefinedBuilder.new @info
|
19
19
|
@builder.build_class
|
20
20
|
end
|
21
21
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'gir_ffi_test_helper'
|
2
|
+
|
3
|
+
describe GirFFI::CallbackBase do
|
4
|
+
describe ".store_callback" do
|
5
|
+
it "stores the passed in proc in CALLBACKS" do
|
6
|
+
GirFFI::CallbackBase.store_callback "some-callback"
|
7
|
+
GirFFI::CallbackBase::CALLBACKS.last.must_equal "some-callback"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
@@ -21,51 +21,51 @@ describe GirFFI::ClassBase do
|
|
21
21
|
other = klass.wrap object.to_ptr
|
22
22
|
|
23
23
|
object.must_be :==, other
|
24
|
+
other.must_be :==, object
|
24
25
|
end
|
25
26
|
|
26
|
-
it "returns
|
27
|
-
|
28
|
-
|
29
|
-
object.wont_be :==, other
|
30
|
-
end
|
31
|
-
|
32
|
-
it "returns false when comparing to an object of a different class" do
|
33
|
-
other = Object.new
|
27
|
+
it "returns true when comparing to an object of the same class and a pointer with the same address" do
|
28
|
+
ptr = FFI::Pointer.new object.to_ptr
|
29
|
+
other = klass.wrap ptr
|
34
30
|
|
35
|
-
object.
|
31
|
+
object.must_be :==, other
|
32
|
+
other.must_be :==, object
|
36
33
|
end
|
37
34
|
|
38
|
-
it "returns
|
35
|
+
it "returns false when comparing to an object of a sub/superclass and the same pointer" do
|
39
36
|
subclass = Class.new(klass)
|
40
37
|
other = subclass.wrap object.to_ptr
|
41
38
|
|
42
|
-
object.
|
39
|
+
object.wont_be :==, other
|
40
|
+
other.wont_be :==, object
|
43
41
|
end
|
44
|
-
end
|
45
42
|
|
46
|
-
|
47
|
-
|
48
|
-
other = klass.wrap object.to_ptr
|
43
|
+
it "returns false when comparing to an object of the same class and different pointer" do
|
44
|
+
other = klass.wrap FFI::MemoryPointer.new(:int32)
|
49
45
|
|
50
|
-
object.
|
46
|
+
object.wont_be :==, other
|
47
|
+
other.wont_be :==, object
|
51
48
|
end
|
52
49
|
|
53
|
-
it "returns false when comparing to an object
|
54
|
-
other =
|
50
|
+
it "returns false when comparing to an object that doesn't respond to #to_ptr" do
|
51
|
+
other = Object.new
|
55
52
|
|
56
|
-
object.
|
53
|
+
object.wont_be :==, other
|
54
|
+
other.wont_be :==, object
|
57
55
|
end
|
58
56
|
|
59
|
-
it "returns
|
57
|
+
it "returns false when comparing to an object of a different class and same pointer" do
|
60
58
|
stub(other = Object.new).to_ptr { object.to_ptr }
|
61
59
|
|
62
|
-
object.
|
60
|
+
object.wont_be :==, other
|
61
|
+
other.wont_be :==, object
|
63
62
|
end
|
64
63
|
|
65
64
|
it "returns false when comparing to an object of a different class and different pointer" do
|
66
65
|
stub(other = Object.new).to_ptr { FFI::MemoryPointer.new(:int32) }
|
67
66
|
|
68
|
-
object.
|
67
|
+
object.wont_be :==, other
|
68
|
+
other.wont_be :==, object
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'gir_ffi_test_helper'
|
2
|
+
|
3
|
+
describe GirFFI::FFIExt::Pointer do
|
4
|
+
let(:klass) { Class.new { include GirFFI::FFIExt::Pointer } }
|
5
|
+
describe "#to_object" do
|
6
|
+
it "finds the wrapping class by gtype and wraps the pointer in it" do
|
7
|
+
ptr = klass.new
|
8
|
+
mock(ptr).null? { false }
|
9
|
+
object_class = Class.new
|
10
|
+
|
11
|
+
mock(GObject).type_from_instance_pointer(ptr) { 0xdeadbeef }
|
12
|
+
mock(GirFFI::Builder).build_by_gtype(0xdeadbeef) { object_class }
|
13
|
+
mock(object_class).direct_wrap(ptr) { "good-result" }
|
14
|
+
|
15
|
+
ptr.to_object.must_equal "good-result"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -103,11 +103,4 @@ describe GirFFI::InOutPointer do
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
107
|
-
describe "#value_ffi_type" do
|
108
|
-
it "returns :int for the :gboolean value type" do
|
109
|
-
ptr = GirFFI::InOutPointer.from :gboolean, true
|
110
|
-
ptr.value_ffi_type.must_equal :int
|
111
|
-
end
|
112
|
-
end
|
113
106
|
end
|
@@ -23,8 +23,8 @@ describe GirFFI::InPointer do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "handles struct types" do
|
26
|
-
e = Class.new do
|
27
|
-
self::Struct = Class.new(
|
26
|
+
e = Class.new(GirFFI::StructBase) do
|
27
|
+
self::Struct = Class.new(GirFFI::Struct) do
|
28
28
|
layout :foo, :int32, :bar, :int32
|
29
29
|
end
|
30
30
|
end
|
@@ -149,5 +149,29 @@ describe GirFFI::InPointer do
|
|
149
149
|
ptr.address.must_equal 1
|
150
150
|
end
|
151
151
|
end
|
152
|
-
end
|
153
152
|
|
153
|
+
describe ".from_object" do
|
154
|
+
describe "when called with an object implementing to_ptr" do
|
155
|
+
it "returns the result of to_ptr" do
|
156
|
+
obj = Object.new
|
157
|
+
def obj.to_ptr; :test_value; end
|
158
|
+
GirFFI::InPointer.from_object(obj).must_equal :test_value
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "when called with nil" do
|
163
|
+
it "returns nil" do
|
164
|
+
GirFFI::InPointer.from_object(nil).must_equal nil
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "when called with a string" do
|
169
|
+
it "stores the string in GirFFI::ArgHelper::OBJECT_STORE" do
|
170
|
+
str = "Foo"
|
171
|
+
ptr = GirFFI::InPointer.from_object(str)
|
172
|
+
result = GirFFI::ArgHelper::OBJECT_STORE[ptr.address]
|
173
|
+
result.must_equal str
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -7,53 +7,25 @@ describe GirFFI::InfoExt::ISignalInfo do
|
|
7
7
|
end }
|
8
8
|
let(:signal_info) { klass.new }
|
9
9
|
|
10
|
-
describe "#cast_back_signal_arguments" do
|
11
|
-
# TODO: Move to integration tests
|
12
|
-
it "correctly casts back pointers for the test-with-static-scope-arg signal" do
|
13
|
-
o = Regress::TestSubObj.new
|
14
|
-
b = Regress::TestSimpleBoxedA.new
|
15
|
-
ud = GirFFI::ArgHelper.object_to_inptr "Hello!"
|
16
|
-
|
17
|
-
assert_equal "Hello!", GirFFI::ArgHelper::OBJECT_STORE[ud.address]
|
18
|
-
|
19
|
-
sig = o.class.find_signal "test-with-static-scope-arg"
|
20
|
-
|
21
|
-
gva = sig.cast_back_signal_arguments(o.to_ptr, b.to_ptr, ud)
|
22
|
-
|
23
|
-
klasses = gva.map {|it| it.class}
|
24
|
-
klasses.must_equal [ Regress::TestSubObj,
|
25
|
-
Regress::TestSimpleBoxedA,
|
26
|
-
String ]
|
27
|
-
gva[2].must_equal "Hello!"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
10
|
describe "#signal_arguments_to_gvalue_array" do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
should "be a GObject::ValueArray" do
|
43
|
-
assert_instance_of GObject::ValueArray, @gva
|
44
|
-
end
|
45
|
-
|
46
|
-
should "contain two values" do
|
47
|
-
assert_equal 2, @gva.n_values
|
48
|
-
end
|
11
|
+
let(:object) { Regress::TestSubObj.new }
|
12
|
+
let(:boxed) { Regress::TestSimpleBoxedA.const_return }
|
13
|
+
let(:signal_info) { Regress::TestSubObj.find_signal "test-with-static-scope-arg" }
|
14
|
+
let(:result) { signal_info.signal_arguments_to_gvalue_array(object, boxed) }
|
15
|
+
|
16
|
+
it "wraps its arguments in a GObject::ValueArray" do
|
17
|
+
result.must_be_instance_of GObject::ValueArray
|
18
|
+
result.n_values.must_equal 2
|
19
|
+
end
|
49
20
|
|
50
|
-
|
51
|
-
|
52
|
-
|
21
|
+
it "correctly wraps :object" do
|
22
|
+
result.get_nth(0).get_value.must_equal object
|
23
|
+
end
|
53
24
|
|
54
|
-
|
55
|
-
|
56
|
-
|
25
|
+
it "correctly wraps :struct" do
|
26
|
+
result_boxed = result.get_nth(1).get_value
|
27
|
+
result_boxed.some_int8.must_equal boxed.some_int8
|
28
|
+
result_boxed.some_int.must_equal boxed.some_int
|
57
29
|
end
|
58
30
|
end
|
59
31
|
|
@@ -4,12 +4,16 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
4
4
|
let(:klass) { Class.new do
|
5
5
|
include GirFFI::InfoExt::ITypeInfo
|
6
6
|
end }
|
7
|
+
|
7
8
|
let(:type_info) { klass.new }
|
8
9
|
let(:elmtype_info) { klass.new }
|
9
10
|
let(:keytype_info) { klass.new }
|
10
11
|
let(:valtype_info) { klass.new }
|
11
12
|
let(:iface_info) { Object.new }
|
12
13
|
|
14
|
+
let(:callback_type_info) {
|
15
|
+
get_introspection_data('Regress', 'test_callback').args[0].argument_type }
|
16
|
+
|
13
17
|
describe "#to_ffitype" do
|
14
18
|
it "returns an array with elements subtype and size for type :array" do
|
15
19
|
mock(type_info).pointer? { false }
|
@@ -90,14 +94,14 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
90
94
|
end
|
91
95
|
end
|
92
96
|
|
93
|
-
|
97
|
+
describe "for a zero-terminated array" do
|
94
98
|
before do
|
95
99
|
stub(type_info).tag { :array }
|
96
100
|
stub(type_info).param_type(0) { elmtype_info }
|
97
101
|
stub(type_info).zero_terminated? { true }
|
98
102
|
end
|
99
103
|
|
100
|
-
|
104
|
+
describe "of utf8" do
|
101
105
|
it "returns :strv" do
|
102
106
|
stub(elmtype_info).tag { :utf8 }
|
103
107
|
stub(elmtype_info).pointer? { true }
|
@@ -106,7 +110,7 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
106
110
|
end
|
107
111
|
end
|
108
112
|
|
109
|
-
|
113
|
+
describe "of filename" do
|
110
114
|
it "returns :strv" do
|
111
115
|
stub(elmtype_info).tag { :filename }
|
112
116
|
stub(elmtype_info).pointer? { true }
|
@@ -115,7 +119,7 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
115
119
|
end
|
116
120
|
end
|
117
121
|
|
118
|
-
|
122
|
+
describe "of another type" do
|
119
123
|
it "returns :zero_terminated" do
|
120
124
|
stub(elmtype_info).tag { :foo }
|
121
125
|
stub(elmtype_info).pointer? { false }
|
@@ -135,16 +139,13 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
135
139
|
end
|
136
140
|
end
|
137
141
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
mock(elmtype_info).tag_or_class_name { ":foo" }
|
144
|
-
|
145
|
-
mock(type_info).param_type(0) { elmtype_info }
|
142
|
+
describe "for a GLib array" do
|
143
|
+
it "returns :c" do
|
144
|
+
mock(type_info).tag { :array }
|
145
|
+
mock(type_info).zero_terminated? { false }
|
146
|
+
mock(type_info).array_type { :array }
|
146
147
|
|
147
|
-
type_info.
|
148
|
+
type_info.flattened_tag.must_equal :array
|
148
149
|
end
|
149
150
|
end
|
150
151
|
end
|
@@ -161,64 +162,6 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
161
162
|
end
|
162
163
|
end
|
163
164
|
|
164
|
-
describe "#tag_or_class_name" do
|
165
|
-
describe "for the simple type :foo" do
|
166
|
-
it "returns the string ':foo'" do
|
167
|
-
stub(type_info).tag { :foo }
|
168
|
-
mock(type_info).pointer? { false }
|
169
|
-
|
170
|
-
assert_equal ":foo", type_info.tag_or_class_name
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe "for :utf8" do
|
175
|
-
it "returns the string ':utf8'" do
|
176
|
-
stub(type_info).tag { :utf8 }
|
177
|
-
mock(type_info).pointer? { true }
|
178
|
-
|
179
|
-
assert_equal ":utf8", type_info.tag_or_class_name
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "for an interface named Foo::Bar" do
|
184
|
-
let(:interface) { Object.new }
|
185
|
-
|
186
|
-
before do
|
187
|
-
stub(type_info).tag { :interface }
|
188
|
-
stub(type_info).interface { iface_info }
|
189
|
-
mock(type_info).pointer? { false }
|
190
|
-
stub(interface).inspect { "Foo::Bar" }
|
191
|
-
|
192
|
-
mock(GirFFI::Builder).build_class(iface_info) { interface }
|
193
|
-
end
|
194
|
-
|
195
|
-
context "when the interface type is :enum" do
|
196
|
-
it "returns the interface's full class name" do
|
197
|
-
stub(iface_info).info_type { :enum }
|
198
|
-
|
199
|
-
assert_equal "Foo::Bar", type_info.tag_or_class_name
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context "when the interface type is :object" do
|
204
|
-
it "returns the string [:pointer, Foo::Bar]" do
|
205
|
-
stub(iface_info).info_type { :object }
|
206
|
-
|
207
|
-
assert_equal "[:pointer, Foo::Bar]", type_info.tag_or_class_name
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
describe "for a pointer to simple type :foo" do
|
213
|
-
it "returns the string '[:pointer, :foo]'" do
|
214
|
-
mock(type_info).tag { :foo }
|
215
|
-
mock(type_info).pointer? { true }
|
216
|
-
|
217
|
-
assert_equal "[:pointer, :foo]", type_info.tag_or_class_name
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
165
|
describe "#tag_or_class" do
|
223
166
|
describe "for a simple type" do
|
224
167
|
it "returns the type's tag" do
|
@@ -258,7 +201,7 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
258
201
|
mock(GirFFI::Builder).build_class(iface_info) { interface }
|
259
202
|
end
|
260
203
|
|
261
|
-
|
204
|
+
describe "when the interface type is :enum" do
|
262
205
|
it "returns the built interface module" do
|
263
206
|
stub(iface_info).info_type { :enum }
|
264
207
|
|
@@ -266,7 +209,7 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
266
209
|
end
|
267
210
|
end
|
268
211
|
|
269
|
-
|
212
|
+
describe "when the interface type is :object" do
|
270
213
|
it "returns an array with elements :pointer and built interface class" do
|
271
214
|
stub(iface_info).info_type { :object }
|
272
215
|
|
@@ -274,13 +217,20 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
274
217
|
end
|
275
218
|
end
|
276
219
|
|
277
|
-
|
220
|
+
describe "when the interface type is :struct" do
|
278
221
|
it "returns the built interface class" do
|
279
222
|
stub(iface_info).info_type { :struct }
|
280
223
|
|
281
224
|
type_info.tag_or_class.must_equal interface
|
282
225
|
end
|
283
226
|
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
describe "for a callback" do
|
231
|
+
it "returns :callback" do
|
232
|
+
callback_type_info.tag_or_class.must_equal :callback
|
233
|
+
end
|
284
234
|
end
|
285
235
|
|
286
236
|
describe "for a pointer to simple type :foo" do
|
@@ -323,4 +273,295 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
323
273
|
end
|
324
274
|
end
|
325
275
|
end
|
276
|
+
|
277
|
+
describe "#extra_conversion_arguments" do
|
278
|
+
describe "for normal types" do
|
279
|
+
before do
|
280
|
+
stub(type_info).tag { :foo }
|
281
|
+
end
|
282
|
+
|
283
|
+
it "returns an empty array" do
|
284
|
+
type_info.extra_conversion_arguments.must_equal []
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe "for a string" do
|
289
|
+
before do
|
290
|
+
stub(type_info).tag { :utf8 }
|
291
|
+
end
|
292
|
+
|
293
|
+
it "returns an array containing :utf8" do
|
294
|
+
type_info.extra_conversion_arguments.must_equal [:utf8]
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
describe "for a fixed-size array" do
|
299
|
+
before do
|
300
|
+
stub(type_info).tag { :array }
|
301
|
+
stub(type_info).zero_terminated? { false }
|
302
|
+
stub(type_info).array_type { :c }
|
303
|
+
stub(type_info).array_fixed_size { 3 }
|
304
|
+
|
305
|
+
stub(type_info).param_type(0) { elmtype_info }
|
306
|
+
stub(elmtype_info).tag_or_class { :foo }
|
307
|
+
end
|
308
|
+
|
309
|
+
it "returns an array containing the element type" do
|
310
|
+
type_info.extra_conversion_arguments.must_equal [:foo, 3]
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "for a zero-terminated array" do
|
315
|
+
before do
|
316
|
+
stub(type_info).tag { :array }
|
317
|
+
stub(type_info).zero_terminated? { true }
|
318
|
+
|
319
|
+
stub(type_info).param_type(0) { elmtype_info }
|
320
|
+
stub(elmtype_info).tag_or_class { :foo }
|
321
|
+
end
|
322
|
+
|
323
|
+
it "returns an array containing the element type" do
|
324
|
+
type_info.extra_conversion_arguments.must_equal [:foo]
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
describe "for a GArray" do
|
329
|
+
before do
|
330
|
+
stub(type_info).tag { :array }
|
331
|
+
stub(type_info).zero_terminated? { false }
|
332
|
+
stub(type_info).array_type { :array }
|
333
|
+
|
334
|
+
stub(type_info).param_type(0) { elmtype_info }
|
335
|
+
stub(elmtype_info).tag_or_class { :foo }
|
336
|
+
end
|
337
|
+
|
338
|
+
it "returns an array containing the element type" do
|
339
|
+
type_info.extra_conversion_arguments.must_equal [:foo]
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
describe "for a GHashTable" do
|
344
|
+
before do
|
345
|
+
stub(type_info).tag {:ghash}
|
346
|
+
stub(type_info).param_type(0) { keytype_info }
|
347
|
+
stub(type_info).param_type(1) { valtype_info }
|
348
|
+
|
349
|
+
stub(keytype_info).tag_or_class { :foo }
|
350
|
+
stub(valtype_info).tag_or_class { :bar }
|
351
|
+
end
|
352
|
+
|
353
|
+
it "returns an array containing the element type pair" do
|
354
|
+
type_info.extra_conversion_arguments.must_equal [[:foo, :bar]]
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
describe "for a GList" do
|
359
|
+
before do
|
360
|
+
stub(type_info).tag { :glist }
|
361
|
+
|
362
|
+
stub(type_info).param_type(0) { elmtype_info }
|
363
|
+
stub(elmtype_info).tag_or_class { :foo }
|
364
|
+
end
|
365
|
+
|
366
|
+
it "returns an array containing the element type" do
|
367
|
+
type_info.extra_conversion_arguments.must_equal [:foo]
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
describe "for a GSList" do
|
372
|
+
before do
|
373
|
+
stub(type_info).tag { :gslist }
|
374
|
+
|
375
|
+
stub(type_info).param_type(0) { elmtype_info }
|
376
|
+
stub(elmtype_info).tag_or_class { :foo }
|
377
|
+
end
|
378
|
+
|
379
|
+
it "returns an array containing the element type" do
|
380
|
+
type_info.extra_conversion_arguments.must_equal [:foo]
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
describe "for a GPtrArray" do
|
385
|
+
before do
|
386
|
+
stub(type_info).tag { :array }
|
387
|
+
stub(type_info).zero_terminated? { false }
|
388
|
+
stub(type_info).array_type { :ptr_array }
|
389
|
+
|
390
|
+
|
391
|
+
stub(type_info).param_type(0) { elmtype_info }
|
392
|
+
stub(elmtype_info).tag_or_class { :foo }
|
393
|
+
end
|
394
|
+
|
395
|
+
it "returns an array containing the element type" do
|
396
|
+
type_info.extra_conversion_arguments.must_equal [:foo]
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
describe "for a :callback" do
|
401
|
+
before do
|
402
|
+
stub(interface_type_info = Object.new).namespace { "Bar" }
|
403
|
+
stub(interface_type_info).name { "Foo" }
|
404
|
+
|
405
|
+
stub(type_info).tag { :callback }
|
406
|
+
stub(type_info).interface { interface_type_info }
|
407
|
+
end
|
408
|
+
|
409
|
+
it "has the correct value for #pre" do
|
410
|
+
type_info.extra_conversion_arguments.must_equal []
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
describe "#argument_class_name" do
|
416
|
+
before do
|
417
|
+
stub(type_info).tag { tag }
|
418
|
+
end
|
419
|
+
|
420
|
+
describe "for :gint32" do
|
421
|
+
let(:tag) { :gint32 }
|
422
|
+
|
423
|
+
it "is nil" do
|
424
|
+
type_info.argument_class_name.must_be_nil
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
describe "for interfaces" do
|
429
|
+
let(:tag) { :interface }
|
430
|
+
|
431
|
+
before do
|
432
|
+
stub(type_info).interface { iface_info }
|
433
|
+
stub(iface_info).info_type { interface_type }
|
434
|
+
stub(iface_info).full_type_name { 'Bar::Foo' }
|
435
|
+
end
|
436
|
+
|
437
|
+
describe "for :struct" do
|
438
|
+
let(:interface_type) { :struct }
|
439
|
+
it "equals the struct class name" do
|
440
|
+
type_info.argument_class_name.must_equal 'Bar::Foo'
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
describe "for :union" do
|
445
|
+
let(:interface_type) { :union }
|
446
|
+
it "equals the union class name" do
|
447
|
+
type_info.argument_class_name.must_equal 'Bar::Foo'
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
describe "for :interface" do
|
452
|
+
let(:interface_type) { :interface }
|
453
|
+
|
454
|
+
it "equals the interface module name" do
|
455
|
+
type_info.argument_class_name.must_equal 'Bar::Foo'
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
describe "for :object" do
|
460
|
+
let(:interface_type) { :object }
|
461
|
+
|
462
|
+
it "equals the object class name" do
|
463
|
+
type_info.argument_class_name.must_equal 'Bar::Foo'
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
describe "for :callback" do
|
468
|
+
let(:interface_type) { :callback }
|
469
|
+
|
470
|
+
it "equals the callback type name" do
|
471
|
+
type_info.argument_class_name.must_equal 'Bar::Foo'
|
472
|
+
end
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
describe "for :strv" do
|
477
|
+
let(:tag) { :strv }
|
478
|
+
|
479
|
+
it "equals GLib::Strv" do
|
480
|
+
type_info.argument_class_name.must_equal 'GLib::Strv'
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
describe "for arrays" do
|
485
|
+
let(:tag) { :array }
|
486
|
+
before do
|
487
|
+
stub(type_info).param_type(0) { elmtype_info }
|
488
|
+
stub(elmtype_info).tag_or_class { :foo }
|
489
|
+
end
|
490
|
+
|
491
|
+
describe "for :zero_terminated" do
|
492
|
+
before do
|
493
|
+
stub(type_info).zero_terminated? { true }
|
494
|
+
end
|
495
|
+
|
496
|
+
it "equals GirFFI::ZeroTerminated" do
|
497
|
+
type_info.argument_class_name.must_equal "GirFFI::ZeroTerminated"
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
describe "for :byte_array" do
|
502
|
+
before do
|
503
|
+
stub(type_info).zero_terminated? { false }
|
504
|
+
stub(type_info).array_type { :byte_array }
|
505
|
+
end
|
506
|
+
|
507
|
+
it "equals GLib::ByteArray" do
|
508
|
+
type_info.argument_class_name.must_equal 'GLib::ByteArray'
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
describe "for :ptr_array" do
|
513
|
+
before do
|
514
|
+
stub(type_info).zero_terminated? { false }
|
515
|
+
stub(type_info).array_type { :ptr_array }
|
516
|
+
end
|
517
|
+
|
518
|
+
it "equals GLib::PtrArray" do
|
519
|
+
type_info.argument_class_name.must_equal 'GLib::PtrArray'
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
describe "for :array" do
|
524
|
+
before do
|
525
|
+
stub(type_info).zero_terminated? { false }
|
526
|
+
stub(type_info).array_type { :array }
|
527
|
+
end
|
528
|
+
|
529
|
+
it "equals GLib::Array" do
|
530
|
+
type_info.argument_class_name.must_equal 'GLib::Array'
|
531
|
+
end
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
535
|
+
describe "for :glist" do
|
536
|
+
let(:tag) { :glist }
|
537
|
+
|
538
|
+
it "equals GLib::List" do
|
539
|
+
type_info.argument_class_name.must_equal 'GLib::List'
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
describe "for :gslist" do
|
544
|
+
let(:tag) { :gslist }
|
545
|
+
|
546
|
+
it "equals GLib::SList" do
|
547
|
+
type_info.argument_class_name.must_equal 'GLib::SList'
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
describe "for :ghash" do
|
552
|
+
let(:tag) { :ghash }
|
553
|
+
|
554
|
+
it "equals GLib::HashTable" do
|
555
|
+
type_info.argument_class_name.must_equal 'GLib::HashTable'
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
describe "for :error" do
|
560
|
+
let(:tag) { :error }
|
561
|
+
|
562
|
+
it "equals GLib::Error" do
|
563
|
+
type_info.argument_class_name.must_equal 'GLib::Error'
|
564
|
+
end
|
565
|
+
end
|
566
|
+
end
|
326
567
|
end
|