gir_ffi 0.15.3 → 0.15.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +15 -0
- data/README.md +5 -6
- data/TODO.md +14 -35
- data/docs/Documentation.md +6 -0
- data/docs/Subclassing.md +38 -0
- data/lib/ffi-glib.rb +8 -3
- data/lib/ffi-glib/byte_array.rb +2 -1
- data/lib/ffi-glib/destroy_notify.rb +2 -2
- data/lib/ffi-glib/hash_table.rb +1 -2
- data/lib/ffi-glib/list.rb +11 -5
- data/lib/ffi-glib/list_methods.rb +12 -0
- data/lib/ffi-glib/s_list.rb +10 -4
- data/lib/ffi-gobject.rb +0 -3
- data/lib/ffi-gobject/object.rb +77 -73
- data/lib/ffi-gobject/object_class.rb +1 -1
- data/lib/ffi-gobject/value.rb +107 -108
- data/lib/ffi-gobject_introspection/i_base_info.rb +20 -19
- data/lib/gir_ffi-base/gobject/lib.rb +4 -0
- data/lib/gir_ffi/array_element_convertor.rb +1 -2
- data/lib/gir_ffi/boxed_base.rb +1 -5
- data/lib/gir_ffi/builder.rb +1 -1
- data/lib/gir_ffi/builder_helper.rb +7 -4
- data/lib/gir_ffi/builders/base_argument_builder.rb +2 -2
- data/lib/gir_ffi/builders/base_method_builder.rb +1 -1
- data/lib/gir_ffi/builders/base_type_builder.rb +1 -1
- data/lib/gir_ffi/builders/callback_argument_builder.rb +2 -0
- data/lib/gir_ffi/builders/callback_builder.rb +14 -12
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +4 -6
- data/lib/gir_ffi/builders/class_struct_builder.rb +24 -0
- data/lib/gir_ffi/builders/enum_builder.rb +3 -3
- data/lib/gir_ffi/builders/interface_builder.rb +3 -1
- data/lib/gir_ffi/builders/mapping_method_builder.rb +1 -1
- data/lib/gir_ffi/builders/marshalling_method_builder.rb +5 -2
- data/lib/gir_ffi/builders/method_template.rb +4 -4
- data/lib/gir_ffi/builders/null_argument_builder.rb +0 -2
- data/lib/gir_ffi/builders/null_return_value_builder.rb +0 -2
- data/lib/gir_ffi/builders/object_builder.rb +16 -6
- data/lib/gir_ffi/builders/property_builder.rb +1 -2
- data/lib/gir_ffi/builders/signal_closure_builder.rb +3 -5
- data/lib/gir_ffi/builders/struct_builder.rb +5 -5
- data/lib/gir_ffi/builders/user_defined_builder.rb +8 -1
- data/lib/gir_ffi/builders/vfunc_argument_builder.rb +1 -1
- data/lib/gir_ffi/callback_base.rb +3 -3
- data/lib/gir_ffi/core.rb +17 -2
- data/lib/gir_ffi/glib_error.rb +1 -2
- data/lib/gir_ffi/in_pointer.rb +7 -0
- data/lib/gir_ffi/object_base.rb +27 -0
- data/lib/gir_ffi/return_value_info.rb +1 -2
- data/lib/gir_ffi/struct_base.rb +1 -9
- data/lib/gir_ffi/struct_like_base.rb +9 -5
- data/lib/gir_ffi/unintrospectable_type_info.rb +1 -1
- data/lib/gir_ffi/union_base.rb +1 -9
- data/lib/gir_ffi/user_defined_object_info.rb +3 -2
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi/vfunc_implementation.rb +1 -0
- metadata +86 -136
- data/Gemfile +0 -14
- data/Rakefile +0 -9
- data/tasks/test.rake +0 -204
- data/test/base_test_helper.rb +0 -70
- data/test/ffi-glib/array_test.rb +0 -203
- data/test/ffi-glib/byte_array_test.rb +0 -28
- data/test/ffi-glib/bytes_test.rb +0 -61
- data/test/ffi-glib/closure_test.rb +0 -38
- data/test/ffi-glib/destroy_notify_test.rb +0 -18
- data/test/ffi-glib/hash_table_test.rb +0 -68
- data/test/ffi-glib/list_test.rb +0 -86
- data/test/ffi-glib/main_loop_test.rb +0 -53
- data/test/ffi-glib/ptr_array_test.rb +0 -112
- data/test/ffi-glib/ruby_closure_test.rb +0 -62
- data/test/ffi-glib/s_list_test.rb +0 -76
- data/test/ffi-glib/strv_test.rb +0 -60
- data/test/ffi-glib/variant_test.rb +0 -12
- data/test/ffi-gobject/gobject_test.rb +0 -76
- data/test/ffi-gobject/object_class_test.rb +0 -31
- data/test/ffi-gobject/object_test.rb +0 -123
- data/test/ffi-gobject/param_spec_test.rb +0 -32
- data/test/ffi-gobject/value_test.rb +0 -390
- data/test/ffi-gobject_introspection/gobject_type_init_test.rb +0 -26
- data/test/ffi-gobject_introspection/i_base_info_test.rb +0 -52
- data/test/ffi-gobject_introspection/i_constant_info_test.rb +0 -29
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +0 -18
- data/test/ffi-gobject_introspection/i_function_info_test.rb +0 -6
- data/test/ffi-gobject_introspection/i_interface_info_test.rb +0 -23
- data/test/ffi-gobject_introspection/i_object_info_test.rb +0 -49
- data/test/ffi-gobject_introspection/i_property_info_test.rb +0 -47
- data/test/ffi-gobject_introspection/i_registered_type_info_test.rb +0 -27
- data/test/ffi-gobject_introspection/i_repository_test.rb +0 -81
- data/test/ffi-gobject_introspection/i_struct_info_test.rb +0 -23
- data/test/ffi-gobject_introspection/i_type_info_test.rb +0 -30
- data/test/ffi-gobject_introspection/i_union_info_test.rb +0 -17
- data/test/ffi-gobject_introspection/i_vfunc_info_test.rb +0 -41
- data/test/ffi-gobject_introspection/lib_test.rb +0 -13
- data/test/ffi-gobject_introspection/strv_test.rb +0 -46
- data/test/ffi-gobject_test.rb +0 -153
- data/test/gir_ffi/allocation_helper_test.rb +0 -36
- data/test/gir_ffi/arg_helper_test.rb +0 -146
- data/test/gir_ffi/boolean_test.rb +0 -43
- data/test/gir_ffi/boxed_base_test.rb +0 -65
- data/test/gir_ffi/builder_test.rb +0 -168
- data/test/gir_ffi/builders/argument_builder_test.rb +0 -691
- data/test/gir_ffi/builders/base_argument_builder_test.rb +0 -6
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +0 -130
- data/test/gir_ffi/builders/callback_builder_test.rb +0 -117
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +0 -84
- data/test/gir_ffi/builders/constant_builder_test.rb +0 -6
- data/test/gir_ffi/builders/constructor_builder_test.rb +0 -39
- data/test/gir_ffi/builders/enum_builder_test.rb +0 -23
- data/test/gir_ffi/builders/field_builder_test.rb +0 -140
- data/test/gir_ffi/builders/function_builder_test.rb +0 -570
- data/test/gir_ffi/builders/initializer_builder_test.rb +0 -56
- data/test/gir_ffi/builders/interface_builder_test.rb +0 -32
- data/test/gir_ffi/builders/module_builder_test.rb +0 -43
- data/test/gir_ffi/builders/object_builder_test.rb +0 -98
- data/test/gir_ffi/builders/property_builder_test.rb +0 -161
- data/test/gir_ffi/builders/registered_type_builder_test.rb +0 -54
- data/test/gir_ffi/builders/return_value_builder_test.rb +0 -444
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +0 -199
- data/test/gir_ffi/builders/struct_builder_test.rb +0 -96
- data/test/gir_ffi/builders/unintrospectable_boxed_builder_test.rb +0 -29
- data/test/gir_ffi/builders/unintrospectable_builder_test.rb +0 -84
- data/test/gir_ffi/builders/union_builder_test.rb +0 -28
- data/test/gir_ffi/builders/user_defined_builder_test.rb +0 -528
- data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +0 -107
- data/test/gir_ffi/builders/vfunc_builder_test.rb +0 -245
- data/test/gir_ffi/callback_base_test.rb +0 -22
- data/test/gir_ffi/class_base_test.rb +0 -171
- data/test/gir_ffi/core_test.rb +0 -99
- data/test/gir_ffi/enum_base_test.rb +0 -43
- data/test/gir_ffi/error_type_info_test.rb +0 -50
- data/test/gir_ffi/ffi_ext/pointer_test.rb +0 -22
- data/test/gir_ffi/g_type_test.rb +0 -31
- data/test/gir_ffi/in_pointer_test.rb +0 -203
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +0 -26
- data/test/gir_ffi/info_ext/i_callback_info_test.rb +0 -22
- data/test/gir_ffi/info_ext/i_field_info_test.rb +0 -37
- data/test/gir_ffi/info_ext/i_function_info_test.rb +0 -74
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +0 -32
- data/test/gir_ffi/info_ext/i_type_info_test.rb +0 -712
- data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +0 -19
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +0 -26
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +0 -26
- data/test/gir_ffi/interface_base_test.rb +0 -20
- data/test/gir_ffi/method_stubber_test.rb +0 -67
- data/test/gir_ffi/object_base_test.rb +0 -64
- data/test/gir_ffi/object_store_test.rb +0 -41
- data/test/gir_ffi/receiver_argument_info_test.rb +0 -33
- data/test/gir_ffi/sized_array_test.rb +0 -206
- data/test/gir_ffi/struct_base_test.rb +0 -23
- data/test/gir_ffi/struct_like_base_test.rb +0 -167
- data/test/gir_ffi/type_map_test.rb +0 -17
- data/test/gir_ffi/unintrospectable_type_info_test.rb +0 -121
- data/test/gir_ffi/union_base_test.rb +0 -23
- data/test/gir_ffi/user_defined_object_info_test.rb +0 -119
- data/test/gir_ffi/user_defined_property_info_test.rb +0 -39
- data/test/gir_ffi/variable_name_generator_test.rb +0 -18
- data/test/gir_ffi/version_test.rb +0 -9
- data/test/gir_ffi/zero_terminated_test.rb +0 -108
- data/test/gir_ffi_test_helper.rb +0 -84
- data/test/integration/callback_exceptions_test.rb +0 -59
- data/test/integration/derived_classes_test.rb +0 -54
- data/test/integration/generated_everything_test.rb +0 -453
- data/test/integration/generated_gimarshallingtests_test.rb +0 -3109
- data/test/integration/generated_gio_test.rb +0 -116
- data/test/integration/generated_glib_test.rb +0 -10
- data/test/integration/generated_gobject_test.rb +0 -124
- data/test/integration/generated_gst_test.rb +0 -38
- data/test/integration/generated_gtk_source_test.rb +0 -21
- data/test/integration/generated_gtop_test.rb +0 -22
- data/test/integration/generated_pango_ft2_test.rb +0 -17
- data/test/integration/generated_pango_test.rb +0 -24
- data/test/integration/generated_regress_test.rb +0 -4076
- data/test/integration/generated_secret_test.rb +0 -14
- data/test/integration/generated_utility_test.rb +0 -174
- data/test/integration/generated_warnlib_test.rb +0 -45
- data/test/integration/method_lookup_test.rb +0 -34
- data/test/introspection_test_helper.rb +0 -94
- data/test/lib/Makefile.am +0 -110
- data/test/lib/autogen.sh +0 -4
- data/test/lib/configure.ac +0 -34
- data/test/lib/m4/jhflags.m4 +0 -21
- data/test/minitest/stats_plugin.rb +0 -30
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GirFFI::Builders::VFuncArgumentBuilder do
|
6
|
-
let(:var_gen) { GirFFI::VariableNameGenerator.new }
|
7
|
-
let(:builder) { GirFFI::Builders::VFuncArgumentBuilder.new(var_gen, arg_info) }
|
8
|
-
|
9
|
-
describe "for a plain in argument" do
|
10
|
-
let(:vfunc_info) do
|
11
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object", "method_int8_in"
|
12
|
-
end
|
13
|
-
let(:arg_info) { vfunc_info.args[0] }
|
14
|
-
|
15
|
-
it "has the correct value for #pre_conversion" do
|
16
|
-
_(builder.pre_conversion).must_equal ["_v1 = in_"]
|
17
|
-
end
|
18
|
-
|
19
|
-
it "has the correct value for #post_conversion" do
|
20
|
-
_(builder.post_conversion).must_equal []
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "for a transfer-none in argument" do
|
25
|
-
let(:vfunc_info) do
|
26
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
27
|
-
"vfunc_in_object_transfer_none"
|
28
|
-
end
|
29
|
-
let(:arg_info) { vfunc_info.args[0] }
|
30
|
-
|
31
|
-
it "has the correct value for #pre_conversion" do
|
32
|
-
_(builder.pre_conversion).must_equal ["_v1 = GObject::Object.wrap(object)", "_v1.ref"]
|
33
|
-
end
|
34
|
-
|
35
|
-
it "has the correct value for #post_conversion" do
|
36
|
-
_(builder.post_conversion).must_equal []
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "for a transfer-none outgoing object argument" do
|
41
|
-
let(:vfunc_info) do
|
42
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
43
|
-
"vfunc_out_object_transfer_none"
|
44
|
-
end
|
45
|
-
let(:arg_info) { vfunc_info.args[0] }
|
46
|
-
|
47
|
-
it "has the correct value for #pre_conversion" do
|
48
|
-
_(builder.pre_conversion).must_equal ["_v1 = object"]
|
49
|
-
end
|
50
|
-
|
51
|
-
it "has the correct value for #post_conversion" do
|
52
|
-
_(builder.post_conversion).must_equal ["_v1.put_pointer 0, GObject::Object.from(_v2)"]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "for a full-transfer outgoing object argument" do
|
57
|
-
let(:vfunc_info) do
|
58
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
59
|
-
"vfunc_out_object_transfer_full"
|
60
|
-
end
|
61
|
-
let(:arg_info) { vfunc_info.args[0] }
|
62
|
-
|
63
|
-
it "has the correct value for #pre_conversion" do
|
64
|
-
_(builder.pre_conversion).must_equal ["_v1 = object"]
|
65
|
-
end
|
66
|
-
|
67
|
-
it "has the correct value for #post_conversion" do
|
68
|
-
builder.pre_conversion
|
69
|
-
_(builder.post_conversion)
|
70
|
-
.must_equal ["_v2.ref", "_v1.put_pointer 0, GObject::Object.from(_v2)"]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "for a full-transfer outgoing non-object argument" do
|
75
|
-
let(:vfunc_info) do
|
76
|
-
get_vfunc_introspection_data("GIMarshallingTests", "Object",
|
77
|
-
"method_int8_arg_and_out_callee")
|
78
|
-
end
|
79
|
-
let(:arg_info) { vfunc_info.args[1] }
|
80
|
-
|
81
|
-
it "has the correct value for #pre_conversion" do
|
82
|
-
_(builder.pre_conversion)
|
83
|
-
.must_equal [
|
84
|
-
"_v1 = FFI::MemoryPointer.new(:int8).tap { |ptr| out.put_pointer 0, ptr }"
|
85
|
-
]
|
86
|
-
end
|
87
|
-
|
88
|
-
it "has the correct value for #post_conversion" do
|
89
|
-
_(builder.post_conversion).must_equal ["_v1.put_int8 0, _v2"]
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "for a receiver argument" do
|
94
|
-
let(:object_info) { get_introspection_data("GIMarshallingTests", "Object") }
|
95
|
-
let(:type_info) { GirFFI::ReceiverTypeInfo.new(object_info) }
|
96
|
-
let(:arg_info) { GirFFI::ReceiverArgumentInfo.new(type_info) }
|
97
|
-
|
98
|
-
it "has the correct value for #pre_conversion" do
|
99
|
-
_(builder.pre_conversion)
|
100
|
-
.must_equal ["_v1 = GIMarshallingTests::Object.wrap(_instance)"]
|
101
|
-
end
|
102
|
-
|
103
|
-
it "has the correct value for #post_conversion" do
|
104
|
-
_(builder.post_conversion).must_equal []
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,245 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GirFFI::Builders::VFuncBuilder do
|
6
|
-
let(:builder) { GirFFI::Builders::VFuncBuilder.new vfunc_info }
|
7
|
-
|
8
|
-
describe "#mapping_method_definition" do
|
9
|
-
let(:result) { builder.mapping_method_definition }
|
10
|
-
|
11
|
-
describe "for a vfunc with only one argument" do
|
12
|
-
let(:vfunc_info) do
|
13
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object", "method_int8_in"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns a valid mapping method including receiver" do
|
17
|
-
expected = <<~CODE
|
18
|
-
def self.call_with_argument_mapping(_proc, _instance, in_)
|
19
|
-
_v1 = GIMarshallingTests::Object.wrap(_instance)
|
20
|
-
_v2 = in_
|
21
|
-
_proc.call(_v1, _v2)
|
22
|
-
end
|
23
|
-
CODE
|
24
|
-
|
25
|
-
_(result).must_equal expected
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "for a vfunc returning an enum" do
|
30
|
-
let(:vfunc_info) do
|
31
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object", "vfunc_return_enum"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "returns a valid mapping method including receiver" do
|
35
|
-
expected = <<~CODE
|
36
|
-
def self.call_with_argument_mapping(_proc, _instance)
|
37
|
-
_v1 = GIMarshallingTests::Object.wrap(_instance)
|
38
|
-
_v2 = _proc.call(_v1)
|
39
|
-
_v3 = GIMarshallingTests::Enum.to_int(_v2)
|
40
|
-
return _v3
|
41
|
-
end
|
42
|
-
CODE
|
43
|
-
|
44
|
-
_(result).must_equal expected
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "for a vfunc with a callback argument" do
|
49
|
-
let(:vfunc_info) do
|
50
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object", "vfunc_with_callback"
|
51
|
-
end
|
52
|
-
|
53
|
-
it "returns a valid mapping method including receiver" do
|
54
|
-
expected = <<~CODE
|
55
|
-
def self.call_with_argument_mapping(_proc, _instance, callback, callback_data)
|
56
|
-
_v1 = GIMarshallingTests::Object.wrap(_instance)
|
57
|
-
_v2 = GIMarshallingTests::CallbackIntInt.wrap(callback)
|
58
|
-
_v3 = GirFFI::ArgHelper::OBJECT_STORE.fetch(callback_data)
|
59
|
-
_proc.call(_v1, _v2, _v3)
|
60
|
-
end
|
61
|
-
CODE
|
62
|
-
|
63
|
-
_(result).must_equal expected
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "for a vfunc with an out argument allocated by them, the caller" do
|
68
|
-
let(:vfunc_info) do
|
69
|
-
get_vfunc_introspection_data("GIMarshallingTests", "Object",
|
70
|
-
"method_int8_arg_and_out_caller")
|
71
|
-
end
|
72
|
-
|
73
|
-
it "returns a valid mapping method including receiver" do
|
74
|
-
expected = <<~CODE
|
75
|
-
def self.call_with_argument_mapping(_proc, _instance, arg, out)
|
76
|
-
_v1 = GIMarshallingTests::Object.wrap(_instance)
|
77
|
-
_v2 = arg
|
78
|
-
_v3 = out
|
79
|
-
_v4 = _proc.call(_v1, _v2)
|
80
|
-
_v3.put_int8 0, _v4
|
81
|
-
end
|
82
|
-
CODE
|
83
|
-
|
84
|
-
_(result).must_equal expected
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "for a vfunc with an out argument allocated by the callee" do
|
89
|
-
let(:vfunc_info) do
|
90
|
-
get_vfunc_introspection_data("GIMarshallingTests", "Object",
|
91
|
-
"method_int8_arg_and_out_callee")
|
92
|
-
end
|
93
|
-
|
94
|
-
it "returns a valid mapping method including receiver" do
|
95
|
-
expected = <<~CODE
|
96
|
-
def self.call_with_argument_mapping(_proc, _instance, arg, out)
|
97
|
-
_v1 = GIMarshallingTests::Object.wrap(_instance)
|
98
|
-
_v2 = arg
|
99
|
-
_v3 = FFI::MemoryPointer.new(:int8).tap { |ptr| out.put_pointer 0, ptr }
|
100
|
-
_v4 = _proc.call(_v1, _v2)
|
101
|
-
_v3.put_int8 0, _v4
|
102
|
-
end
|
103
|
-
CODE
|
104
|
-
|
105
|
-
_(result).must_equal expected
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "for a vfunc with a GObject::Value out argument allocated by the caller" do
|
110
|
-
let(:vfunc_info) do
|
111
|
-
get_vfunc_introspection_data("GIMarshallingTests", "Object",
|
112
|
-
"vfunc_caller_allocated_out_parameter")
|
113
|
-
end
|
114
|
-
|
115
|
-
it "returns a valid mapping method including receiver" do
|
116
|
-
expected = <<~CODE
|
117
|
-
def self.call_with_argument_mapping(_proc, _instance, a)
|
118
|
-
_v1 = GIMarshallingTests::Object.wrap(_instance)
|
119
|
-
_v2 = a
|
120
|
-
_v3 = _proc.call(_v1)
|
121
|
-
GObject::Value.copy_value_to_pointer(GObject::Value.from(_v3), _v2)
|
122
|
-
end
|
123
|
-
CODE
|
124
|
-
|
125
|
-
_(result).must_equal expected
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "for a vfunc with an error argument" do
|
130
|
-
let(:vfunc_info) do
|
131
|
-
get_vfunc_introspection_data("GIMarshallingTests", "Object",
|
132
|
-
"vfunc_meth_with_err")
|
133
|
-
end
|
134
|
-
|
135
|
-
it "returns a valid mapping method including receiver" do
|
136
|
-
expected = <<~CODE
|
137
|
-
def self.call_with_argument_mapping(_proc, _instance, x, _error)
|
138
|
-
_v1 = GIMarshallingTests::Object.wrap(_instance)
|
139
|
-
_v2 = x
|
140
|
-
_v3 = _error
|
141
|
-
begin
|
142
|
-
_v4 = _proc.call(_v1, _v2)
|
143
|
-
rescue => _v5
|
144
|
-
_v3.put_pointer 0, GLib::Error.from(_v5)
|
145
|
-
end
|
146
|
-
return _v4
|
147
|
-
end
|
148
|
-
CODE
|
149
|
-
|
150
|
-
_(result).must_equal expected
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe "for a vfunc with a full-transfer return value" do
|
155
|
-
let(:vfunc_info) do
|
156
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
157
|
-
"vfunc_return_object_transfer_full"
|
158
|
-
end
|
159
|
-
|
160
|
-
it "returns a valid mapping method" do
|
161
|
-
expected = <<~CODE
|
162
|
-
def self.call_with_argument_mapping(_proc, _instance)
|
163
|
-
_v1 = GIMarshallingTests::Object.wrap(_instance)
|
164
|
-
_v2 = _proc.call(_v1)
|
165
|
-
_v2.ref
|
166
|
-
_v3 = GObject::Object.from(_v2).to_ptr
|
167
|
-
return _v3
|
168
|
-
end
|
169
|
-
CODE
|
170
|
-
|
171
|
-
_(result).must_equal expected
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe "for a vfunc with a transfer-none in argument" do
|
176
|
-
let(:vfunc_info) do
|
177
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
178
|
-
"vfunc_in_object_transfer_none"
|
179
|
-
end
|
180
|
-
|
181
|
-
it "returns a valid mapping method" do
|
182
|
-
expected = <<~CODE
|
183
|
-
def self.call_with_argument_mapping(_proc, _instance, object)
|
184
|
-
_v1 = GIMarshallingTests::Object.wrap(_instance)
|
185
|
-
_v2 = GObject::Object.wrap(object)
|
186
|
-
_v2.ref
|
187
|
-
_proc.call(_v1, _v2)
|
188
|
-
end
|
189
|
-
CODE
|
190
|
-
|
191
|
-
_(result).must_equal expected
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe "for a vfunc with a full-transfer outgoing argument" do
|
196
|
-
let(:vfunc_info) do
|
197
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
198
|
-
"vfunc_out_object_transfer_full"
|
199
|
-
end
|
200
|
-
|
201
|
-
it "returns a valid mapping method" do
|
202
|
-
expected = <<~CODE
|
203
|
-
def self.call_with_argument_mapping(_proc, _instance, object)
|
204
|
-
_v1 = GIMarshallingTests::Object.wrap(_instance)
|
205
|
-
_v2 = object
|
206
|
-
_v3 = _proc.call(_v1)
|
207
|
-
_v3.ref
|
208
|
-
_v2.put_pointer 0, GObject::Object.from(_v3)
|
209
|
-
end
|
210
|
-
CODE
|
211
|
-
|
212
|
-
_(result).must_equal expected
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
describe "#argument_ffi_types" do
|
218
|
-
let(:result) { builder.argument_ffi_types }
|
219
|
-
|
220
|
-
describe "for a vfunc with only one argument" do
|
221
|
-
let(:vfunc_info) do
|
222
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object", "method_int8_in"
|
223
|
-
end
|
224
|
-
|
225
|
-
it "returns the correct FFI types including :pointer for the receiver" do
|
226
|
-
_(result).must_equal [:pointer, :int8]
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
describe "#return_ffi_type" do
|
232
|
-
let(:result) { builder.return_ffi_type }
|
233
|
-
|
234
|
-
describe "for a vfunc returning an object" do
|
235
|
-
let(:vfunc_info) do
|
236
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
237
|
-
"vfunc_return_object_transfer_full"
|
238
|
-
end
|
239
|
-
|
240
|
-
it "returns :pointer" do
|
241
|
-
_(result).must_equal :pointer
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GirFFI::CallbackBase do
|
6
|
-
describe ".store_callback" do
|
7
|
-
it "stores the passed in proc in CALLBACKS" do
|
8
|
-
dummy_proc = "some-callback"
|
9
|
-
GirFFI::CallbackBase.store_callback dummy_proc
|
10
|
-
_(GirFFI::CallbackBase::CALLBACKS[dummy_proc.object_id]).must_equal dummy_proc
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe ".drop_callback" do
|
15
|
-
it "removes the corresponding proc from CALLBACKS" do
|
16
|
-
dummy_proc = "some-callback"
|
17
|
-
GirFFI::CallbackBase.store_callback dummy_proc
|
18
|
-
GirFFI::CallbackBase.drop_callback dummy_proc
|
19
|
-
_(GirFFI::CallbackBase::CALLBACKS[dummy_proc.object_id]).must_be_nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,171 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GirFFI::ClassBase do
|
6
|
-
describe "a simple descendant" do
|
7
|
-
let(:object_class) do
|
8
|
-
Class.new(GirFFI::ClassBase) do
|
9
|
-
self::Struct = Class.new(GirFFI::Struct) do
|
10
|
-
layout :foo, :int32
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
let(:object) { object_class.wrap FFI::MemoryPointer.new(:int32) }
|
15
|
-
|
16
|
-
it "has #from as a pass-through method" do
|
17
|
-
result = object_class.from :foo
|
18
|
-
_(result).must_equal :foo
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#==" do
|
22
|
-
it "returns true for an object of the same class and pointer" do
|
23
|
-
other = object_class.wrap object.to_ptr
|
24
|
-
|
25
|
-
_(object).must_be :==, other
|
26
|
-
_(other).must_be :==, object
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns true for an object of the same class and pointer with the same address" do
|
30
|
-
ptr = FFI::Pointer.new object.to_ptr
|
31
|
-
other = object_class.wrap ptr
|
32
|
-
|
33
|
-
_(object).must_be :==, other
|
34
|
-
_(other).must_be :==, object
|
35
|
-
end
|
36
|
-
|
37
|
-
it "returns false for an object of a sub/superclass and the same pointer" do
|
38
|
-
subclass = Class.new(object_class)
|
39
|
-
other = subclass.wrap object.to_ptr
|
40
|
-
|
41
|
-
_(object).wont_be :==, other
|
42
|
-
_(other).wont_be :==, object
|
43
|
-
end
|
44
|
-
|
45
|
-
it "returns false for an object of the same class and different pointer" do
|
46
|
-
other = object_class.wrap FFI::MemoryPointer.new(:int32)
|
47
|
-
|
48
|
-
_(object).wont_be :==, other
|
49
|
-
_(other).wont_be :==, object
|
50
|
-
end
|
51
|
-
|
52
|
-
it "returns false for an object that doesn't respond to #to_ptr" do
|
53
|
-
other = Object.new
|
54
|
-
|
55
|
-
_(object).wont_be :==, other
|
56
|
-
_(other).wont_be :==, object
|
57
|
-
end
|
58
|
-
|
59
|
-
it "returns false for an object of a different class and same pointer" do
|
60
|
-
allow(other = Object.new).to receive(:to_ptr).and_return object.to_ptr
|
61
|
-
|
62
|
-
_(object).wont_be :==, other
|
63
|
-
_(other).wont_be :==, object
|
64
|
-
end
|
65
|
-
|
66
|
-
it "returns false for an object of a different class and different pointer" do
|
67
|
-
allow(other = Object.new)
|
68
|
-
.to receive(:to_ptr).and_return FFI::MemoryPointer.new(:int32)
|
69
|
-
|
70
|
-
_(object).wont_be :==, other
|
71
|
-
_(other).wont_be :==, object
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe ".setup_and_call" do
|
77
|
-
it "looks up class methods in all builders" do
|
78
|
-
expect(builder = Object.new).to receive(:setup_method).with("foo").and_return "foo"
|
79
|
-
klass = Class.new GirFFI::ClassBase
|
80
|
-
klass.const_set :GIR_FFI_BUILDER, builder
|
81
|
-
|
82
|
-
expect(sub_builder = Object.new).to receive(:setup_method).with("foo").and_return nil
|
83
|
-
sub_klass = Class.new klass do
|
84
|
-
def self.foo; end
|
85
|
-
end
|
86
|
-
sub_klass.const_set :GIR_FFI_BUILDER, sub_builder
|
87
|
-
|
88
|
-
sub_klass.setup_and_call :foo, []
|
89
|
-
end
|
90
|
-
|
91
|
-
it "calls the method given by the result of .setup_method" do
|
92
|
-
expect(builder = Object.new).to receive(:setup_method).with("foo").and_return "bar"
|
93
|
-
klass = Class.new GirFFI::ClassBase do
|
94
|
-
def self.bar
|
95
|
-
"correct-result"
|
96
|
-
end
|
97
|
-
|
98
|
-
def initialize; end
|
99
|
-
end
|
100
|
-
klass.const_set :GIR_FFI_BUILDER, builder
|
101
|
-
|
102
|
-
result = klass.setup_and_call :foo, []
|
103
|
-
_(result).must_equal "correct-result"
|
104
|
-
end
|
105
|
-
|
106
|
-
it "raises a sensible error if the method is not found" do
|
107
|
-
expect(builder = Object.new).to receive(:setup_method).with("foo").and_return nil
|
108
|
-
klass = Class.new GirFFI::ClassBase do
|
109
|
-
def initialize; end
|
110
|
-
end
|
111
|
-
klass.const_set :GIR_FFI_BUILDER, builder
|
112
|
-
|
113
|
-
exception = _(proc { klass.setup_and_call :foo, [] }).must_raise(NoMethodError)
|
114
|
-
_(exception.message).must_match(/^undefined method `foo' for/)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "#setup_and_call" do
|
119
|
-
it "looks up instance methods in all builders" do
|
120
|
-
expect(builder = Object.new)
|
121
|
-
.to receive(:setup_instance_method).with("foo").and_return "foo"
|
122
|
-
klass = Class.new GirFFI::ClassBase
|
123
|
-
klass.const_set :GIR_FFI_BUILDER, builder
|
124
|
-
|
125
|
-
expect(sub_builder = Object.new)
|
126
|
-
.to receive(:setup_instance_method).with("foo").and_return nil
|
127
|
-
sub_klass = Class.new klass do
|
128
|
-
def foo; end
|
129
|
-
|
130
|
-
def initialize; end
|
131
|
-
end
|
132
|
-
sub_klass.const_set :GIR_FFI_BUILDER, sub_builder
|
133
|
-
|
134
|
-
obj = sub_klass.new
|
135
|
-
|
136
|
-
obj.setup_and_call :foo, []
|
137
|
-
end
|
138
|
-
|
139
|
-
it "calls the method given by the result of .setup_instance_method" do
|
140
|
-
expect(builder = Object.new)
|
141
|
-
.to receive(:setup_instance_method).with("foo").and_return "bar"
|
142
|
-
klass = Class.new GirFFI::ClassBase do
|
143
|
-
def bar
|
144
|
-
"correct-result"
|
145
|
-
end
|
146
|
-
|
147
|
-
def initialize; end
|
148
|
-
end
|
149
|
-
klass.const_set :GIR_FFI_BUILDER, builder
|
150
|
-
|
151
|
-
obj = klass.new
|
152
|
-
|
153
|
-
result = obj.setup_and_call :foo, []
|
154
|
-
_(result).must_equal "correct-result"
|
155
|
-
end
|
156
|
-
|
157
|
-
it "raises a sensible error if the method is not found" do
|
158
|
-
expect(builder = Object.new)
|
159
|
-
.to receive(:setup_instance_method).with("foo").and_return nil
|
160
|
-
klass = Class.new GirFFI::ClassBase do
|
161
|
-
def initialize; end
|
162
|
-
end
|
163
|
-
klass.const_set :GIR_FFI_BUILDER, builder
|
164
|
-
|
165
|
-
obj = klass.new
|
166
|
-
|
167
|
-
exception = _(proc { obj.setup_and_call :foo, [] }).must_raise(NoMethodError)
|
168
|
-
_(exception.message).must_match(/^undefined method `foo' for/)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|