gir_ffi 0.7.8 → 0.7.9
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.
- checksums.yaml +4 -4
- data/Changelog.md +16 -0
- data/README.md +24 -11
- data/TODO.md +10 -2
- data/gir_ffi.gemspec +2 -2
- data/lib/ffi-glib/array.rb +1 -1
- data/lib/ffi-glib/hash_table.rb +0 -4
- data/lib/ffi-gobject.rb +10 -6
- data/lib/ffi-gobject/object.rb +17 -0
- data/lib/ffi-gobject/ruby_closure.rb +1 -1
- data/lib/ffi-gobject/value.rb +28 -4
- data/lib/ffi-gobject_introspection.rb +4 -0
- data/lib/ffi-gobject_introspection/g_error.rb +2 -2
- data/lib/ffi-gobject_introspection/i_base_info.rb +1 -3
- data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
- data/lib/ffi-gobject_introspection/i_registered_type_info.rb +2 -0
- data/lib/ffi-gobject_introspection/i_repository.rb +4 -4
- data/lib/ffi-gobject_introspection/lib.rb +57 -32
- data/lib/gir_ffi.rb +1 -1
- data/lib/gir_ffi/boxed_base.rb +40 -0
- data/lib/gir_ffi/builders/argument_builder.rb +11 -3
- data/lib/gir_ffi/builders/base_argument_builder.rb +4 -0
- data/lib/gir_ffi/builders/boxed_builder.rb +29 -0
- data/lib/gir_ffi/builders/callback_builder.rb +3 -1
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +9 -1
- data/lib/gir_ffi/builders/field_builder.rb +68 -18
- data/lib/gir_ffi/builders/function_builder.rb +12 -2
- data/lib/gir_ffi/builders/mapping_method_builder.rb +7 -5
- data/lib/gir_ffi/builders/marshalling_method_builder.rb +1 -1
- data/lib/gir_ffi/builders/module_builder.rb +1 -1
- data/lib/gir_ffi/builders/registered_type_builder.rb +0 -9
- data/lib/gir_ffi/builders/return_value_builder.rb +0 -1
- data/lib/gir_ffi/builders/signal_closure_builder.rb +3 -1
- data/lib/gir_ffi/builders/struct_builder.rb +4 -16
- data/lib/gir_ffi/builders/union_builder.rb +2 -13
- data/lib/gir_ffi/builders/user_defined_builder.rb +6 -6
- data/lib/gir_ffi/builders/vfunc_argument_builder.rb +44 -0
- data/lib/gir_ffi/builders/vfunc_builder.rb +3 -1
- data/lib/gir_ffi/callback_base.rb +5 -2
- data/lib/gir_ffi/class_base.rb +6 -7
- data/lib/gir_ffi/enum_base.rb +5 -0
- data/lib/gir_ffi/ffi_ext/pointer.rb +1 -0
- data/lib/gir_ffi/field_argument_info.rb +4 -0
- data/lib/gir_ffi/in_out_pointer.rb +1 -1
- data/lib/gir_ffi/in_pointer.rb +2 -2
- data/lib/gir_ffi/info_ext/i_arg_info.rb +12 -2
- data/lib/gir_ffi/info_ext/i_callable_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_callback_info.rb +7 -2
- data/lib/gir_ffi/info_ext/i_field_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_function_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +7 -2
- data/lib/gir_ffi/info_ext/i_type_info.rb +21 -9
- data/lib/gir_ffi/info_ext/i_unresolved_info.rb +5 -0
- data/lib/gir_ffi/interface_base.rb +5 -0
- data/lib/gir_ffi/object_base.rb +5 -0
- data/lib/gir_ffi/receiver_argument_info.rb +5 -0
- data/lib/gir_ffi/registered_type_base.rb +5 -0
- data/lib/gir_ffi/return_value_info.rb +3 -1
- data/lib/gir_ffi/sized_array.rb +1 -1
- data/lib/gir_ffi/struct_base.rb +2 -24
- data/lib/gir_ffi/type_map.rb +5 -1
- data/lib/gir_ffi/union_base.rb +2 -2
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi/zero_terminated.rb +1 -1
- data/test/base_test_helper.rb +6 -6
- data/test/ffi-glib/hash_table_test.rb +7 -7
- data/test/ffi-glib/iconv_test.rb +2 -3
- data/test/ffi-glib/main_loop_test.rb +2 -2
- data/test/ffi-gobject/gobject_test.rb +1 -1
- data/test/ffi-gobject/object_test.rb +5 -14
- data/test/ffi-gobject/value_test.rb +30 -6
- data/test/ffi-gobject_introspection/i_base_info_test.rb +6 -6
- data/test/ffi-gobject_introspection/i_repository_test.rb +2 -4
- data/test/gir_ffi/arg_helper_test.rb +1 -1
- data/test/gir_ffi/builder_test.rb +18 -12
- data/test/gir_ffi/builders/argument_builder_test.rb +2 -5
- data/test/gir_ffi/builders/callback_builder_test.rb +1 -1
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +11 -10
- data/test/gir_ffi/builders/field_builder_test.rb +0 -2
- data/test/gir_ffi/builders/function_builder_test.rb +156 -147
- data/test/gir_ffi/builders/interface_builder_test.rb +1 -1
- data/test/gir_ffi/builders/module_builder_test.rb +2 -2
- data/test/gir_ffi/builders/object_builder_test.rb +2 -2
- data/test/gir_ffi/builders/property_builder_test.rb +5 -5
- data/test/gir_ffi/builders/return_value_builder_test.rb +30 -30
- data/test/gir_ffi/builders/struct_builder_test.rb +14 -14
- data/test/gir_ffi/builders/user_defined_builder_test.rb +21 -22
- data/test/gir_ffi/builders/vfunc_builder_test.rb +57 -0
- data/test/gir_ffi/class_base_test.rb +8 -8
- data/test/gir_ffi/ffi_ext/pointer_test.rb +4 -4
- data/test/gir_ffi/g_type_test.rb +1 -1
- data/test/gir_ffi/in_pointer_test.rb +2 -2
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +3 -3
- data/test/gir_ffi/info_ext/i_callback_info_test.rb +2 -2
- data/test/gir_ffi/info_ext/i_field_info_test.rb +8 -8
- data/test/gir_ffi/info_ext/i_function_info_test.rb +13 -13
- data/test/gir_ffi/info_ext/i_type_info_test.rb +131 -132
- data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +2 -2
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +2 -2
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +2 -2
- data/test/gir_ffi/interface_base_test.rb +3 -3
- data/test/gir_ffi/object_base_test.rb +3 -3
- data/test/gir_ffi/sized_array_test.rb +2 -2
- data/test/gir_ffi/type_map_test.rb +3 -3
- data/test/gir_ffi/unintrospectable_type_info_test.rb +14 -14
- data/test/gir_ffi/user_defined_property_info_test.rb +1 -1
- data/test/gir_ffi/user_defined_type_info_test.rb +25 -12
- data/test/gir_ffi/zero_terminated_test.rb +0 -1
- data/test/gir_ffi_test.rb +3 -3
- data/test/gir_ffi_test_helper.rb +4 -0
- data/test/integration/generated_gimarshallingtests_test.rb +31 -25
- 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 +18 -22
- metadata +11 -8
@@ -55,14 +55,14 @@ describe GirFFI::ClassBase do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns false when comparing to an object of a different class and same pointer' do
|
58
|
-
|
58
|
+
allow(other = Object.new).to receive(:to_ptr).and_return object.to_ptr
|
59
59
|
|
60
60
|
object.wont_be :==, other
|
61
61
|
other.wont_be :==, object
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'returns false when comparing to an object of a different class and different pointer' do
|
65
|
-
|
65
|
+
allow(other = Object.new).to receive(:to_ptr).and_return FFI::MemoryPointer.new(:int32)
|
66
66
|
|
67
67
|
object.wont_be :==, other
|
68
68
|
other.wont_be :==, object
|
@@ -72,11 +72,11 @@ describe GirFFI::ClassBase do
|
|
72
72
|
|
73
73
|
describe '.setup_and_call' do
|
74
74
|
it 'looks up class methods in all builders' do
|
75
|
-
|
75
|
+
expect(builder = Object.new).to receive(:setup_method).with('foo').and_return 'foo'
|
76
76
|
klass = Class.new GirFFI::ClassBase
|
77
77
|
klass.const_set :GIR_FFI_BUILDER, builder
|
78
78
|
|
79
|
-
|
79
|
+
expect(sub_builder = Object.new).to receive(:setup_method).with('foo').and_return nil
|
80
80
|
sub_klass = Class.new klass do
|
81
81
|
def self.foo; end
|
82
82
|
end
|
@@ -86,7 +86,7 @@ describe GirFFI::ClassBase do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'calls the method given by the result of .setup_method' do
|
89
|
-
|
89
|
+
expect(builder = Object.new).to receive(:setup_method).with('foo').and_return 'bar'
|
90
90
|
klass = Class.new GirFFI::ClassBase do
|
91
91
|
def self.bar
|
92
92
|
'correct-result'
|
@@ -104,11 +104,11 @@ describe GirFFI::ClassBase do
|
|
104
104
|
|
105
105
|
describe '#setup_and_call' do
|
106
106
|
it 'looks up instance methods in all builders' do
|
107
|
-
|
107
|
+
expect(builder = Object.new).to receive(:setup_instance_method).with('foo').and_return 'foo'
|
108
108
|
klass = Class.new GirFFI::ClassBase
|
109
109
|
klass.const_set :GIR_FFI_BUILDER, builder
|
110
110
|
|
111
|
-
|
111
|
+
expect(sub_builder = Object.new).to receive(:setup_instance_method).with('foo').and_return nil
|
112
112
|
sub_klass = Class.new klass do
|
113
113
|
def foo; end
|
114
114
|
|
@@ -125,7 +125,7 @@ describe GirFFI::ClassBase do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'calls the method given by the result of .setup_instance_method' do
|
128
|
-
|
128
|
+
expect(builder = Object.new).to receive(:setup_instance_method).with('foo').and_return 'bar'
|
129
129
|
klass = Class.new GirFFI::ClassBase do
|
130
130
|
def bar
|
131
131
|
'correct-result'
|
@@ -5,12 +5,12 @@ describe GirFFI::FFIExt::Pointer do
|
|
5
5
|
describe '#to_object' do
|
6
6
|
it 'finds the wrapping class by gtype and wraps the pointer in it' do
|
7
7
|
ptr = klass.new
|
8
|
-
|
8
|
+
expect(ptr).to receive(:null?).and_return false
|
9
9
|
object_class = Class.new
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
expect(GObject).to receive(:type_from_instance_pointer).with(ptr).and_return 0xdeadbeef
|
12
|
+
expect(GirFFI::Builder).to receive(:build_by_gtype).with(0xdeadbeef).and_return object_class
|
13
|
+
expect(object_class).to receive(:direct_wrap).with(ptr).and_return 'good-result'
|
14
14
|
|
15
15
|
ptr.to_object.must_equal 'good-result'
|
16
16
|
end
|
data/test/gir_ffi/g_type_test.rb
CHANGED
@@ -3,7 +3,7 @@ require 'gir_ffi_test_helper'
|
|
3
3
|
require 'gir_ffi/g_type'
|
4
4
|
|
5
5
|
describe GirFFI::GType do
|
6
|
-
let(:gobject_gtype) { GObject::Object.
|
6
|
+
let(:gobject_gtype) { GObject::Object.gtype }
|
7
7
|
let(:gobject_type_query) { GObject.type_query gobject_gtype }
|
8
8
|
|
9
9
|
describe '#to_i' do
|
@@ -16,7 +16,7 @@ describe GirFFI::InPointer do
|
|
16
16
|
it 'handles enum types' do
|
17
17
|
e = Module.new do
|
18
18
|
extend GirFFI::EnumBase
|
19
|
-
self::Enum = FFI::Enum.new [:foo, :bar, :baz]
|
19
|
+
self::Enum = FFI::Enum.new [:foo, :bar, :baz], :qux
|
20
20
|
end
|
21
21
|
ptr = GirFFI::InPointer.from_array e, [:bar, :foo, :baz]
|
22
22
|
ptr.read_array_of_int32(3).must_equal [1, 0, 2]
|
@@ -146,7 +146,7 @@ describe GirFFI::InPointer do
|
|
146
146
|
|
147
147
|
it 'handles enum types' do
|
148
148
|
e = Module.new do
|
149
|
-
self::Enum = FFI::Enum.new [:foo, :bar, :baz]
|
149
|
+
self::Enum = FFI::Enum.new [:foo, :bar, :baz], :qux
|
150
150
|
def self.[] val
|
151
151
|
self::Enum[val]
|
152
152
|
end
|
@@ -11,9 +11,9 @@ describe GirFFI::InfoExt::ICallableInfo do
|
|
11
11
|
describe '#argument_ffi_types' do
|
12
12
|
describe 'for a simple callable with several arguments' do
|
13
13
|
before do
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
allow(arg_info1 = Object.new).to receive(:to_ffi_type).and_return :type1
|
15
|
+
allow(arg_info2 = Object.new).to receive(:to_ffi_type).and_return :type2
|
16
|
+
allow(callable_info).to receive(:args).and_return [arg_info1, arg_info2]
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'returns the ffi types of the arguments' do
|
@@ -10,8 +10,8 @@ describe GirFFI::InfoExt::ICallbackInfo do
|
|
10
10
|
|
11
11
|
describe '#return_ffi_type' do
|
12
12
|
it 'returns the callback ffi type of the return type' do
|
13
|
-
|
14
|
-
|
13
|
+
allow(return_type_info = Object.new).to receive(:to_callback_ffi_type).and_return :some_type
|
14
|
+
allow(callback_info).to receive(:return_type).and_return return_type_info
|
15
15
|
|
16
16
|
callback_info.return_ffi_type.must_equal :some_type
|
17
17
|
end
|
@@ -9,11 +9,11 @@ describe GirFFI::InfoExt::IFieldInfo do
|
|
9
9
|
let(:field_info) { klass.new }
|
10
10
|
describe '#layout_specification' do
|
11
11
|
it 'returns an array of name, typespec and offset' do
|
12
|
-
|
12
|
+
expect(type = Object.new).to receive(:to_ffi_type).and_return :bar
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
expect(field_info).to receive(:name).and_return 'foo'
|
15
|
+
expect(field_info).to receive(:field_type).and_return type
|
16
|
+
expect(field_info).to receive(:offset).and_return 0
|
17
17
|
|
18
18
|
result = field_info.layout_specification
|
19
19
|
|
@@ -21,11 +21,11 @@ describe GirFFI::InfoExt::IFieldInfo do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'keeps a complex typespec intact' do
|
24
|
-
|
24
|
+
expect(type = Object.new).to receive(:to_ffi_type).and_return [:bar, 2]
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
expect(field_info).to receive(:name).and_return 'foo'
|
27
|
+
expect(field_info).to receive(:field_type).and_return type
|
28
|
+
expect(field_info).to receive(:offset).and_return 0
|
29
29
|
|
30
30
|
result = field_info.layout_specification
|
31
31
|
|
@@ -11,15 +11,15 @@ describe GirFFI::InfoExt::IFunctionInfo do
|
|
11
11
|
|
12
12
|
describe '#argument_ffi_types' do
|
13
13
|
before do
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
allow(arg_info1 = Object.new).to receive(:to_ffi_type).and_return :type1
|
15
|
+
allow(arg_info2 = Object.new).to receive(:to_ffi_type).and_return :type2
|
16
|
+
allow(function_info).to receive(:args).and_return [arg_info1, arg_info2]
|
17
17
|
end
|
18
18
|
|
19
19
|
describe 'for a simple function with several arguments' do
|
20
20
|
before do
|
21
|
-
|
22
|
-
|
21
|
+
allow(function_info).to receive(:method?).and_return false
|
22
|
+
allow(function_info).to receive(:throws?).and_return false
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'returns the ffi types of the arguments' do
|
@@ -29,8 +29,8 @@ describe GirFFI::InfoExt::IFunctionInfo do
|
|
29
29
|
|
30
30
|
describe 'for a throwing function with several arguments' do
|
31
31
|
before do
|
32
|
-
|
33
|
-
|
32
|
+
allow(function_info).to receive(:method?).and_return false
|
33
|
+
allow(function_info).to receive(:throws?).and_return true
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'appends :pointer to represent the error argument' do
|
@@ -40,8 +40,8 @@ describe GirFFI::InfoExt::IFunctionInfo do
|
|
40
40
|
|
41
41
|
describe 'for a method with several arguments' do
|
42
42
|
before do
|
43
|
-
|
44
|
-
|
43
|
+
allow(function_info).to receive(:method?).and_return true
|
44
|
+
allow(function_info).to receive(:throws?).and_return false
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'prepends :pointer to represent the method reciever' do
|
@@ -51,8 +51,8 @@ describe GirFFI::InfoExt::IFunctionInfo do
|
|
51
51
|
|
52
52
|
describe 'for a throwing method with several arguments' do
|
53
53
|
before do
|
54
|
-
|
55
|
-
|
54
|
+
allow(function_info).to receive(:method?).and_return true
|
55
|
+
allow(function_info).to receive(:throws?).and_return true
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'adds :pointer for both the reciever and the error argument' do
|
@@ -63,8 +63,8 @@ describe GirFFI::InfoExt::IFunctionInfo do
|
|
63
63
|
|
64
64
|
describe '#return_ffi_type' do
|
65
65
|
it 'returns the ffi type of the return type' do
|
66
|
-
|
67
|
-
|
66
|
+
allow(return_type_info = Object.new).to receive(:to_ffi_type).and_return :some_type
|
67
|
+
allow(function_info).to receive(:return_type).and_return return_type_info
|
68
68
|
|
69
69
|
function_info.return_ffi_type.must_equal :some_type
|
70
70
|
end
|
@@ -21,72 +21,72 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
21
21
|
'test_ghash_nested_everything_return').return_type
|
22
22
|
}
|
23
23
|
|
24
|
-
describe '#
|
24
|
+
describe '#to_ffi_type' do
|
25
25
|
it 'returns an array with elements subtype and size for type :array' do
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
expect(type_info).to receive(:pointer?).and_return false
|
27
|
+
allow(type_info).to receive(:tag).and_return :array
|
28
|
+
expect(type_info).to receive(:array_fixed_size).and_return 2
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
expect(elmtype_info).to receive(:to_ffi_type).and_return :foo
|
31
|
+
expect(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
32
32
|
|
33
|
-
result = type_info.
|
33
|
+
result = type_info.to_ffi_type
|
34
34
|
assert_equal [:foo, 2], result
|
35
35
|
end
|
36
36
|
|
37
37
|
describe 'for an :interface type' do
|
38
38
|
before do
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
allow(type_info).to receive(:interface).and_return iface_info
|
40
|
+
allow(type_info).to receive(:tag).and_return :interface
|
41
|
+
allow(type_info).to receive(:pointer?).and_return false
|
42
42
|
end
|
43
43
|
|
44
|
-
it "maps a the interface's
|
45
|
-
|
44
|
+
it "maps a the interface's ffi_type" do
|
45
|
+
allow(iface_info).to receive(:to_ffi_type).and_return :foo
|
46
46
|
|
47
|
-
type_info.
|
47
|
+
type_info.to_ffi_type.must_equal :foo
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe '#element_type' do
|
53
53
|
it 'returns the element type for lists' do
|
54
|
-
|
55
|
-
|
54
|
+
allow(elmtype_info).to receive(:tag).and_return :foo
|
55
|
+
expect(elmtype_info).to receive(:pointer?).and_return false
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
expect(type_info).to receive(:tag).and_return :glist
|
58
|
+
expect(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
59
59
|
|
60
60
|
result = type_info.element_type
|
61
61
|
result.must_equal :foo
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'returns the key and value types for ghashes' do
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
allow(keytype_info).to receive(:tag).and_return :foo
|
66
|
+
expect(keytype_info).to receive(:pointer?).and_return false
|
67
|
+
allow(valtype_info).to receive(:tag).and_return :bar
|
68
|
+
expect(valtype_info).to receive(:pointer?).and_return false
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
expect(type_info).to receive(:tag).and_return :ghash
|
71
|
+
expect(type_info).to receive(:param_type).with(0).and_return keytype_info
|
72
|
+
expect(type_info).to receive(:param_type).with(1).and_return valtype_info
|
73
73
|
|
74
74
|
result = type_info.element_type
|
75
75
|
result.must_equal [:foo, :bar]
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'returns nil for other types' do
|
79
|
-
|
79
|
+
expect(type_info).to receive(:tag).and_return :foo
|
80
80
|
|
81
81
|
result = type_info.element_type
|
82
82
|
result.must_be_nil
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'returns [:pointer, :void] if the element type is a pointer with tag :void' do
|
86
|
-
|
86
|
+
allow(elmtype_info).to receive(:tag_or_class).and_return [:pointer, :void]
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
expect(type_info).to receive(:tag).and_return :glist
|
89
|
+
expect(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
90
90
|
|
91
91
|
assert_equal [:pointer, :void], type_info.element_type
|
92
92
|
end
|
@@ -95,7 +95,7 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
95
95
|
describe '#flattened_tag' do
|
96
96
|
describe 'for a simple type' do
|
97
97
|
it 'returns the type tag' do
|
98
|
-
|
98
|
+
allow(type_info).to receive(:tag).and_return :uint32
|
99
99
|
|
100
100
|
type_info.flattened_tag.must_equal :uint32
|
101
101
|
end
|
@@ -103,15 +103,15 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
103
103
|
|
104
104
|
describe 'for a zero-terminated array' do
|
105
105
|
before do
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
allow(type_info).to receive(:tag).and_return :array
|
107
|
+
allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
108
|
+
allow(type_info).to receive(:zero_terminated?).and_return true
|
109
109
|
end
|
110
110
|
|
111
111
|
describe 'of utf8' do
|
112
112
|
it 'returns :strv' do
|
113
|
-
|
114
|
-
|
113
|
+
allow(elmtype_info).to receive(:tag).and_return :utf8
|
114
|
+
allow(elmtype_info).to receive(:pointer?).and_return true
|
115
115
|
|
116
116
|
type_info.flattened_tag.must_equal :strv
|
117
117
|
end
|
@@ -119,8 +119,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
119
119
|
|
120
120
|
describe 'of filename' do
|
121
121
|
it 'returns :strv' do
|
122
|
-
|
123
|
-
|
122
|
+
allow(elmtype_info).to receive(:tag).and_return :filename
|
123
|
+
allow(elmtype_info).to receive(:pointer?).and_return true
|
124
124
|
|
125
125
|
type_info.flattened_tag.must_equal :strv
|
126
126
|
end
|
@@ -128,8 +128,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
128
128
|
|
129
129
|
describe 'of another type' do
|
130
130
|
it 'returns :zero_terminated' do
|
131
|
-
|
132
|
-
|
131
|
+
allow(elmtype_info).to receive(:tag).and_return :foo
|
132
|
+
allow(elmtype_info).to receive(:pointer?).and_return false
|
133
133
|
|
134
134
|
type_info.flattened_tag.must_equal :zero_terminated
|
135
135
|
end
|
@@ -138,9 +138,9 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
138
138
|
|
139
139
|
describe 'for a fixed length c-like array' do
|
140
140
|
it 'returns :c' do
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
expect(type_info).to receive(:tag).and_return :array
|
142
|
+
expect(type_info).to receive(:zero_terminated?).and_return false
|
143
|
+
expect(type_info).to receive(:array_type).and_return :c
|
144
144
|
|
145
145
|
type_info.flattened_tag.must_equal :c
|
146
146
|
end
|
@@ -148,9 +148,9 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
148
148
|
|
149
149
|
describe 'for a GLib array' do
|
150
150
|
it 'returns :c' do
|
151
|
-
|
152
|
-
|
153
|
-
|
151
|
+
expect(type_info).to receive(:tag).and_return :array
|
152
|
+
expect(type_info).to receive(:zero_terminated?).and_return false
|
153
|
+
expect(type_info).to receive(:array_type).and_return :array
|
154
154
|
|
155
155
|
type_info.flattened_tag.must_equal :array
|
156
156
|
end
|
@@ -160,8 +160,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
160
160
|
describe '#tag_or_class' do
|
161
161
|
describe 'for a simple type' do
|
162
162
|
it "returns the type's tag" do
|
163
|
-
|
164
|
-
|
163
|
+
allow(type_info).to receive(:tag).and_return :foo
|
164
|
+
expect(type_info).to receive(:pointer?).and_return false
|
165
165
|
|
166
166
|
type_info.tag_or_class.must_equal :foo
|
167
167
|
end
|
@@ -169,8 +169,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
169
169
|
|
170
170
|
describe 'for utf8 strings' do
|
171
171
|
it 'returns the tag :utf8' do
|
172
|
-
|
173
|
-
|
172
|
+
allow(type_info).to receive(:tag).and_return :utf8
|
173
|
+
expect(type_info).to receive(:pointer?).and_return true
|
174
174
|
|
175
175
|
type_info.tag_or_class.must_equal :utf8
|
176
176
|
end
|
@@ -178,8 +178,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
178
178
|
|
179
179
|
describe 'for filename strings' do
|
180
180
|
it 'returns the tag :filename' do
|
181
|
-
|
182
|
-
|
181
|
+
allow(type_info).to receive(:tag).and_return :filename
|
182
|
+
expect(type_info).to receive(:pointer?).and_return true
|
183
183
|
|
184
184
|
type_info.tag_or_class.must_equal :filename
|
185
185
|
end
|
@@ -189,16 +189,16 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
189
189
|
let(:interface) { Object.new }
|
190
190
|
|
191
191
|
before do
|
192
|
-
|
193
|
-
|
194
|
-
|
192
|
+
allow(type_info).to receive(:tag).and_return :interface
|
193
|
+
allow(type_info).to receive(:interface).and_return iface_info
|
194
|
+
expect(type_info).to receive(:pointer?).and_return false
|
195
195
|
|
196
|
-
|
196
|
+
expect(GirFFI::Builder).to receive(:build_class).with(iface_info).and_return interface
|
197
197
|
end
|
198
198
|
|
199
199
|
describe 'when the interface type is :enum' do
|
200
200
|
it 'returns the built interface module' do
|
201
|
-
|
201
|
+
allow(iface_info).to receive(:info_type).and_return :enum
|
202
202
|
|
203
203
|
type_info.tag_or_class.must_equal interface
|
204
204
|
end
|
@@ -206,7 +206,7 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
206
206
|
|
207
207
|
describe 'when the interface type is :object' do
|
208
208
|
it 'returns the built interface class' do
|
209
|
-
|
209
|
+
allow(iface_info).to receive(:info_type).and_return :object
|
210
210
|
|
211
211
|
type_info.tag_or_class.must_equal interface
|
212
212
|
end
|
@@ -214,12 +214,11 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
214
214
|
|
215
215
|
describe 'when the interface type is :struct' do
|
216
216
|
it 'returns the built interface class' do
|
217
|
-
|
217
|
+
allow(iface_info).to receive(:info_type).and_return :struct
|
218
218
|
|
219
219
|
type_info.tag_or_class.must_equal interface
|
220
220
|
end
|
221
221
|
end
|
222
|
-
|
223
222
|
end
|
224
223
|
|
225
224
|
describe 'for a callback' do
|
@@ -230,8 +229,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
230
229
|
|
231
230
|
describe 'for a pointer to simple type :foo' do
|
232
231
|
it 'returns [:pointer, :foo]' do
|
233
|
-
|
234
|
-
|
232
|
+
allow(type_info).to receive(:tag).and_return :foo
|
233
|
+
expect(type_info).to receive(:pointer?).and_return true
|
235
234
|
|
236
235
|
type_info.tag_or_class.must_equal [:pointer, :foo]
|
237
236
|
end
|
@@ -239,8 +238,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
239
238
|
|
240
239
|
describe 'for a pointer to :void' do
|
241
240
|
it 'returns [:pointer, :void]' do
|
242
|
-
|
243
|
-
|
241
|
+
allow(type_info).to receive(:tag).and_return :void
|
242
|
+
allow(type_info).to receive(:pointer?).and_return true
|
244
243
|
|
245
244
|
type_info.tag_or_class.must_equal [:pointer, :void]
|
246
245
|
end
|
@@ -258,24 +257,24 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
258
257
|
end
|
259
258
|
end
|
260
259
|
|
261
|
-
describe '#
|
260
|
+
describe '#to_callback_ffi_type' do
|
262
261
|
describe 'for an :interface argument' do
|
263
262
|
before do
|
264
|
-
|
265
|
-
|
266
|
-
|
263
|
+
allow(type_info).to receive(:interface).and_return iface_info
|
264
|
+
allow(type_info).to receive(:tag).and_return :interface
|
265
|
+
allow(type_info).to receive(:pointer?).and_return false
|
267
266
|
end
|
268
267
|
|
269
268
|
it 'correctly maps a :union argument to :pointer' do
|
270
|
-
|
269
|
+
allow(iface_info).to receive(:info_type).and_return :union
|
271
270
|
|
272
|
-
type_info.
|
271
|
+
type_info.to_callback_ffi_type.must_equal :pointer
|
273
272
|
end
|
274
273
|
|
275
274
|
it 'correctly maps a :flags argument to :int32' do
|
276
|
-
|
275
|
+
allow(iface_info).to receive(:info_type).and_return :flags
|
277
276
|
|
278
|
-
type_info.
|
277
|
+
type_info.to_callback_ffi_type.must_equal :int32
|
279
278
|
end
|
280
279
|
end
|
281
280
|
end
|
@@ -283,7 +282,7 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
283
282
|
describe '#extra_conversion_arguments' do
|
284
283
|
describe 'for normal types' do
|
285
284
|
before do
|
286
|
-
|
285
|
+
allow(type_info).to receive(:tag).and_return :foo
|
287
286
|
end
|
288
287
|
|
289
288
|
it 'returns an empty array' do
|
@@ -293,7 +292,7 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
293
292
|
|
294
293
|
describe 'for a string' do
|
295
294
|
before do
|
296
|
-
|
295
|
+
allow(type_info).to receive(:tag).and_return :utf8
|
297
296
|
end
|
298
297
|
|
299
298
|
it 'returns an array containing :utf8' do
|
@@ -303,13 +302,13 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
303
302
|
|
304
303
|
describe 'for a fixed-size array' do
|
305
304
|
before do
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
305
|
+
allow(type_info).to receive(:tag).and_return :array
|
306
|
+
allow(type_info).to receive(:zero_terminated?).and_return false
|
307
|
+
allow(type_info).to receive(:array_type).and_return :c
|
308
|
+
allow(type_info).to receive(:array_fixed_size).and_return 3
|
310
309
|
|
311
|
-
|
312
|
-
|
310
|
+
allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
311
|
+
allow(elmtype_info).to receive(:tag_or_class).and_return :foo
|
313
312
|
end
|
314
313
|
|
315
314
|
it 'returns an array containing the element type' do
|
@@ -319,11 +318,11 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
319
318
|
|
320
319
|
describe 'for a zero-terminated array' do
|
321
320
|
before do
|
322
|
-
|
323
|
-
|
321
|
+
allow(type_info).to receive(:tag).and_return :array
|
322
|
+
allow(type_info).to receive(:zero_terminated?).and_return true
|
324
323
|
|
325
|
-
|
326
|
-
|
324
|
+
allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
325
|
+
allow(elmtype_info).to receive(:tag_or_class).and_return :foo
|
327
326
|
end
|
328
327
|
|
329
328
|
it 'returns an array containing the element type' do
|
@@ -333,12 +332,12 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
333
332
|
|
334
333
|
describe 'for a GArray' do
|
335
334
|
before do
|
336
|
-
|
337
|
-
|
338
|
-
|
335
|
+
allow(type_info).to receive(:tag).and_return :array
|
336
|
+
allow(type_info).to receive(:zero_terminated?).and_return false
|
337
|
+
allow(type_info).to receive(:array_type).and_return :array
|
339
338
|
|
340
|
-
|
341
|
-
|
339
|
+
allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
340
|
+
allow(elmtype_info).to receive(:tag_or_class).and_return :foo
|
342
341
|
end
|
343
342
|
|
344
343
|
it 'returns an array containing the element type' do
|
@@ -348,12 +347,12 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
348
347
|
|
349
348
|
describe 'for a GHashTable' do
|
350
349
|
before do
|
351
|
-
|
352
|
-
|
353
|
-
|
350
|
+
allow(type_info).to receive(:tag).and_return :ghash
|
351
|
+
allow(type_info).to receive(:param_type).with(0).and_return keytype_info
|
352
|
+
allow(type_info).to receive(:param_type).with(1).and_return valtype_info
|
354
353
|
|
355
|
-
|
356
|
-
|
354
|
+
allow(keytype_info).to receive(:tag_or_class).and_return :foo
|
355
|
+
allow(valtype_info).to receive(:tag_or_class).and_return :bar
|
357
356
|
end
|
358
357
|
|
359
358
|
it 'returns an array containing the element type pair' do
|
@@ -363,10 +362,10 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
363
362
|
|
364
363
|
describe 'for a GList' do
|
365
364
|
before do
|
366
|
-
|
365
|
+
allow(type_info).to receive(:tag).and_return :glist
|
367
366
|
|
368
|
-
|
369
|
-
|
367
|
+
allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
368
|
+
allow(elmtype_info).to receive(:tag_or_class).and_return :foo
|
370
369
|
end
|
371
370
|
|
372
371
|
it 'returns an array containing the element type' do
|
@@ -376,10 +375,10 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
376
375
|
|
377
376
|
describe 'for a GSList' do
|
378
377
|
before do
|
379
|
-
|
378
|
+
allow(type_info).to receive(:tag).and_return :gslist
|
380
379
|
|
381
|
-
|
382
|
-
|
380
|
+
allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
381
|
+
allow(elmtype_info).to receive(:tag_or_class).and_return :foo
|
383
382
|
end
|
384
383
|
|
385
384
|
it 'returns an array containing the element type' do
|
@@ -389,12 +388,12 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
389
388
|
|
390
389
|
describe 'for a GPtrArray' do
|
391
390
|
before do
|
392
|
-
|
393
|
-
|
394
|
-
|
391
|
+
allow(type_info).to receive(:tag).and_return :array
|
392
|
+
allow(type_info).to receive(:zero_terminated?).and_return false
|
393
|
+
allow(type_info).to receive(:array_type).and_return :ptr_array
|
395
394
|
|
396
|
-
|
397
|
-
|
395
|
+
allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
396
|
+
allow(elmtype_info).to receive(:tag_or_class).and_return :foo
|
398
397
|
end
|
399
398
|
|
400
399
|
it 'returns an array containing the element type' do
|
@@ -404,11 +403,11 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
404
403
|
|
405
404
|
describe 'for a :callback' do
|
406
405
|
before do
|
407
|
-
|
408
|
-
|
406
|
+
allow(interface_type_info = Object.new).to receive(:namespace).and_return 'Bar'
|
407
|
+
allow(interface_type_info).to receive(:name).and_return 'Foo'
|
409
408
|
|
410
|
-
|
411
|
-
|
409
|
+
allow(type_info).to receive(:tag).and_return :callback
|
410
|
+
allow(type_info).to receive(:interface).and_return interface_type_info
|
412
411
|
end
|
413
412
|
|
414
413
|
it 'returns an empty array' do
|
@@ -419,7 +418,7 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
419
418
|
|
420
419
|
describe '#argument_class_name' do
|
421
420
|
before do
|
422
|
-
|
421
|
+
allow(type_info).to receive(:tag).and_return tag
|
423
422
|
end
|
424
423
|
|
425
424
|
describe 'for :gint32' do
|
@@ -434,9 +433,9 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
434
433
|
let(:tag) { :interface }
|
435
434
|
|
436
435
|
before do
|
437
|
-
|
438
|
-
|
439
|
-
|
436
|
+
allow(type_info).to receive(:interface).and_return iface_info
|
437
|
+
allow(iface_info).to receive(:info_type).and_return interface_type
|
438
|
+
allow(iface_info).to receive(:full_type_name).and_return 'Bar::Foo'
|
440
439
|
end
|
441
440
|
|
442
441
|
describe 'for :struct' do
|
@@ -489,13 +488,13 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
489
488
|
describe 'for arrays' do
|
490
489
|
let(:tag) { :array }
|
491
490
|
before do
|
492
|
-
|
493
|
-
|
491
|
+
allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
492
|
+
allow(elmtype_info).to receive(:tag_or_class).and_return :foo
|
494
493
|
end
|
495
494
|
|
496
495
|
describe 'for :zero_terminated' do
|
497
496
|
before do
|
498
|
-
|
497
|
+
allow(type_info).to receive(:zero_terminated?).and_return true
|
499
498
|
end
|
500
499
|
|
501
500
|
it 'equals GirFFI::ZeroTerminated' do
|
@@ -505,8 +504,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
505
504
|
|
506
505
|
describe 'for :byte_array' do
|
507
506
|
before do
|
508
|
-
|
509
|
-
|
507
|
+
allow(type_info).to receive(:zero_terminated?).and_return false
|
508
|
+
allow(type_info).to receive(:array_type).and_return :byte_array
|
510
509
|
end
|
511
510
|
|
512
511
|
it 'equals GLib::ByteArray' do
|
@@ -516,8 +515,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
516
515
|
|
517
516
|
describe 'for :ptr_array' do
|
518
517
|
before do
|
519
|
-
|
520
|
-
|
518
|
+
allow(type_info).to receive(:zero_terminated?).and_return false
|
519
|
+
allow(type_info).to receive(:array_type).and_return :ptr_array
|
521
520
|
end
|
522
521
|
|
523
522
|
it 'equals GLib::PtrArray' do
|
@@ -527,8 +526,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
527
526
|
|
528
527
|
describe 'for :array' do
|
529
528
|
before do
|
530
|
-
|
531
|
-
|
529
|
+
allow(type_info).to receive(:zero_terminated?).and_return false
|
530
|
+
allow(type_info).to receive(:array_type).and_return :array
|
532
531
|
end
|
533
532
|
|
534
533
|
it 'equals GLib::Array' do
|
@@ -572,8 +571,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
572
571
|
|
573
572
|
describe '#g_type' do
|
574
573
|
before do
|
575
|
-
|
576
|
-
|
574
|
+
allow(type_info).to receive(:tag).and_return tag
|
575
|
+
allow(type_info).to receive(:pointer?).and_return pointer?
|
577
576
|
end
|
578
577
|
|
579
578
|
describe 'for :void' do
|
@@ -645,8 +644,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
645
644
|
|
646
645
|
describe 'for pointer to GArray' do
|
647
646
|
before do
|
648
|
-
|
649
|
-
|
647
|
+
allow(type_info).to receive(:zero_terminated?).and_return false
|
648
|
+
allow(type_info).to receive(:array_type).and_return :array
|
650
649
|
end
|
651
650
|
|
652
651
|
it 'equals the GArray type' do
|
@@ -656,8 +655,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
656
655
|
|
657
656
|
describe 'for a C array' do
|
658
657
|
before do
|
659
|
-
|
660
|
-
|
658
|
+
allow(type_info).to receive(:zero_terminated?).and_return false
|
659
|
+
allow(type_info).to receive(:array_type).and_return :c
|
661
660
|
end
|
662
661
|
|
663
662
|
it 'equals the gpointer type' do
|
@@ -667,14 +666,14 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
667
666
|
|
668
667
|
describe 'for a zero-terminated array' do
|
669
668
|
before do
|
670
|
-
|
671
|
-
|
669
|
+
allow(type_info).to receive(:param_type).with(0).and_return elmtype_info
|
670
|
+
allow(type_info).to receive(:zero_terminated?).and_return true
|
672
671
|
end
|
673
672
|
|
674
673
|
describe 'of utf8' do
|
675
674
|
it 'equals the GStrv type' do
|
676
|
-
|
677
|
-
|
675
|
+
allow(elmtype_info).to receive(:tag).and_return :utf8
|
676
|
+
allow(elmtype_info).to receive(:pointer?).and_return true
|
678
677
|
|
679
678
|
GObject.type_name(type_info.g_type).must_equal 'GStrv'
|
680
679
|
end
|
@@ -682,8 +681,8 @@ describe GirFFI::InfoExt::ITypeInfo do
|
|
682
681
|
|
683
682
|
describe 'of filename' do
|
684
683
|
it 'equals the GStrv type' do
|
685
|
-
|
686
|
-
|
684
|
+
allow(elmtype_info).to receive(:tag).and_return :filename
|
685
|
+
allow(elmtype_info).to receive(:pointer?).and_return true
|
687
686
|
|
688
687
|
GObject.type_name(type_info.g_type).must_equal 'GStrv'
|
689
688
|
end
|