gir_ffi 0.15.3 → 0.15.4
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 +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,65 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
GirFFI.setup :GIMarshallingTests
|
6
|
-
|
7
|
-
describe GirFFI::BoxedBase do
|
8
|
-
describe "initialize" do
|
9
|
-
it "sets up the held struct pointer" do
|
10
|
-
# NOTE: GObject::Value uses the generic constructor, unlike
|
11
|
-
# GIMarshallingTests::BoxedStruct, which has its own constructor.
|
12
|
-
value = GObject::Value.new
|
13
|
-
_(value.to_ptr).wont_be_nil
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "copy_from" do
|
18
|
-
it "returns a copy with owned false" do
|
19
|
-
original = GIMarshallingTests::BoxedStruct.new
|
20
|
-
copy = GIMarshallingTests::BoxedStruct.copy_from(original)
|
21
|
-
ptr = copy.to_ptr
|
22
|
-
_(ptr).wont_be :==, original.to_ptr
|
23
|
-
_(ptr).wont_be :autorelease? if ptr.respond_to? :autorelease?
|
24
|
-
_(copy.struct).wont_be :owned?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "wrap_own" do
|
29
|
-
it "wraps and owns the supplied pointer" do
|
30
|
-
original = GIMarshallingTests::BoxedStruct.new
|
31
|
-
copy = GIMarshallingTests::BoxedStruct.wrap_own(original.to_ptr)
|
32
|
-
ptr = copy.to_ptr
|
33
|
-
_(ptr).must_equal original.to_ptr
|
34
|
-
_(ptr).wont_be :autorelease? if ptr.respond_to? :autorelease?
|
35
|
-
_(copy.struct).must_be :owned?
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "upon garbage collection" do
|
40
|
-
it "frees and disowns the underlying struct if it is owned" do
|
41
|
-
skip "cannot be reliably tested on JRuby" if jruby?
|
42
|
-
|
43
|
-
allow(GObject).to receive(:boxed_free)
|
44
|
-
gtype = GIMarshallingTests::BoxedStruct.gtype
|
45
|
-
|
46
|
-
owned_struct = GIMarshallingTests::BoxedStruct.new.struct
|
47
|
-
owned_ptr = owned_struct.to_ptr
|
48
|
-
|
49
|
-
unowned_struct = GIMarshallingTests::BoxedStruct.new.struct
|
50
|
-
unowned_struct.owned = false
|
51
|
-
unowned_ptr = unowned_struct.to_ptr
|
52
|
-
|
53
|
-
GC.start
|
54
|
-
# Creating a new object is sometimes needed to trigger enough garbage collection.
|
55
|
-
GIMarshallingTests::BoxedStruct.new
|
56
|
-
sleep 1
|
57
|
-
GC.start
|
58
|
-
GC.start
|
59
|
-
|
60
|
-
expect(GObject).to have_received(:boxed_free).with(gtype, owned_ptr)
|
61
|
-
expect(GObject).not_to have_received(:boxed_free).with(gtype, unowned_ptr)
|
62
|
-
_(owned_struct).wont_be :owned?
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,168 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
GirFFI.setup :Regress
|
6
|
-
GirFFI.setup :GIMarshallingTests
|
7
|
-
|
8
|
-
describe GirFFI::Builder do
|
9
|
-
let(:gir) { GObjectIntrospection::IRepository.default }
|
10
|
-
|
11
|
-
describe ".build_class" do
|
12
|
-
it "does not replace existing classes" do
|
13
|
-
oldclass = GObject::Object
|
14
|
-
GirFFI::Builder.build_class get_introspection_data("GObject", "Object")
|
15
|
-
_(GObject::Object).must_equal oldclass
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe ".build_module" do
|
20
|
-
it "refuses to build existing modules defined elsewhere" do
|
21
|
-
result = _(-> { GirFFI::Builder.build_module("Array") }).must_raise RuntimeError
|
22
|
-
_(result.message).must_equal "The module Array was already defined elsewhere"
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "building a module for the first time" do
|
26
|
-
before do
|
27
|
-
save_module :Regress
|
28
|
-
GirFFI::Builder.build_module "Regress"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "creates a Lib module ready to attach functions from the shared library" do
|
32
|
-
gir = GObjectIntrospection::IRepository.default
|
33
|
-
expected = [gir.shared_library("Regress")]
|
34
|
-
assert_equal expected, Regress::Lib.ffi_libraries.map(&:name)
|
35
|
-
end
|
36
|
-
|
37
|
-
after do
|
38
|
-
restore_module :Regress
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "building a module that already exists" do
|
43
|
-
it "does not replace the existing module" do
|
44
|
-
oldmodule = Regress
|
45
|
-
GirFFI::Builder.build_module "Regress"
|
46
|
-
assert_equal oldmodule, Regress
|
47
|
-
end
|
48
|
-
|
49
|
-
it "does not replace the existing Lib module" do
|
50
|
-
oldmodule = Regress::Lib
|
51
|
-
GirFFI::Builder.build_module "Regress"
|
52
|
-
assert_equal oldmodule, Regress::Lib
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
it "passes the version on to ModuleBuilder" do
|
57
|
-
builder = double(generate: nil)
|
58
|
-
expect(GirFFI::Builders::ModuleBuilder).to receive(:new)
|
59
|
-
.with("Foo", namespace: "Foo", version: "1.0")
|
60
|
-
.and_return builder
|
61
|
-
|
62
|
-
GirFFI::Builder.build_module "Foo", "1.0"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe ".build_by_gtype" do
|
67
|
-
it "returns the class types known to the GIR" do
|
68
|
-
result = GirFFI::Builder.build_by_gtype GObject::Object.gtype
|
69
|
-
_(result).must_equal GObject::Object
|
70
|
-
end
|
71
|
-
|
72
|
-
it "returns the class for user-defined types" do
|
73
|
-
klass = Class.new GIMarshallingTests::OverridesObject
|
74
|
-
Object.const_set "Derived#{Sequence.next}", klass
|
75
|
-
gtype = GirFFI.define_type klass
|
76
|
-
|
77
|
-
found_klass = GirFFI::Builder.build_by_gtype gtype
|
78
|
-
_(found_klass).must_equal klass
|
79
|
-
end
|
80
|
-
|
81
|
-
it "returns the class for user-defined types not derived from GObject" do
|
82
|
-
klass = Class.new Regress::TestFundamentalObject
|
83
|
-
Object.const_set "Derived#{Sequence.next}", klass
|
84
|
-
gtype = GirFFI.define_type klass
|
85
|
-
|
86
|
-
found_klass = GirFFI::Builder.build_by_gtype gtype
|
87
|
-
_(found_klass).must_equal klass
|
88
|
-
end
|
89
|
-
|
90
|
-
it "returns a valid class for boxed classes unknown to GIR" do
|
91
|
-
object_class = GIMarshallingTests::PropertiesObject.object_class
|
92
|
-
property = object_class.find_property "some-boxed-glist"
|
93
|
-
gtype = property.value_type
|
94
|
-
|
95
|
-
_(gtype).wont_equal GObject::TYPE_NONE
|
96
|
-
|
97
|
-
found_klass = GirFFI::Builder.build_by_gtype gtype
|
98
|
-
_(found_klass.name).must_be_nil
|
99
|
-
_(found_klass.superclass).must_equal GirFFI::BoxedBase
|
100
|
-
end
|
101
|
-
|
102
|
-
it "refuse to build classes for base types" do
|
103
|
-
_(-> { GirFFI::Builder.build_by_gtype GObject::TYPE_INT })
|
104
|
-
.must_raise RuntimeError, "Unable to handle type gint"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe ".attach_ffi_function" do
|
109
|
-
let(:lib) { Module.new }
|
110
|
-
|
111
|
-
it "attaches regress_test_callback_destroy_notify with the correct types" do
|
112
|
-
function_info = get_introspection_data "Regress", "test_callback_destroy_notify"
|
113
|
-
|
114
|
-
expect(lib)
|
115
|
-
.to receive(:attach_function)
|
116
|
-
.with("regress_test_callback_destroy_notify",
|
117
|
-
[Regress::TestCallbackUserData, :pointer, GLib::DestroyNotify],
|
118
|
-
:int32)
|
119
|
-
.and_return true
|
120
|
-
|
121
|
-
GirFFI::Builder.attach_ffi_function(lib, function_info)
|
122
|
-
end
|
123
|
-
|
124
|
-
it "attaches regress_test_obj_torture_signature_0 with the correct types" do
|
125
|
-
info = get_method_introspection_data "Regress", "TestObj", "torture_signature_0"
|
126
|
-
|
127
|
-
expect(lib)
|
128
|
-
.to receive(:attach_function)
|
129
|
-
.with("regress_test_obj_torture_signature_0",
|
130
|
-
[:pointer, :int32, :pointer, :pointer, :pointer, :pointer, :uint32],
|
131
|
-
:void)
|
132
|
-
.and_return true
|
133
|
-
|
134
|
-
GirFFI::Builder.attach_ffi_function(lib, info)
|
135
|
-
end
|
136
|
-
|
137
|
-
it "attaches regress_test_obj_instance_method with the correct types" do
|
138
|
-
info = get_method_introspection_data "Regress", "TestObj", "instance_method"
|
139
|
-
expect(lib).to receive(:attach_function)
|
140
|
-
.with("regress_test_obj_instance_method", [:pointer], :int32)
|
141
|
-
.and_return true
|
142
|
-
GirFFI::Builder.attach_ffi_function(lib, info)
|
143
|
-
end
|
144
|
-
|
145
|
-
it "calls attach_function with the correct types for Regress.test_array_gint32_in" do
|
146
|
-
info = get_introspection_data "Regress", "test_array_gint32_in"
|
147
|
-
expect(lib).to receive(:attach_function)
|
148
|
-
.with("regress_test_array_gint32_in", [:int32, :pointer], :int32)
|
149
|
-
.and_return true
|
150
|
-
GirFFI::Builder.attach_ffi_function(lib, info)
|
151
|
-
end
|
152
|
-
|
153
|
-
it "calls attach_function with the correct types for Regress.test_enum_param" do
|
154
|
-
info = get_introspection_data "Regress", "test_enum_param"
|
155
|
-
expect(lib).to receive(:attach_function)
|
156
|
-
.with("regress_test_enum_param", [Regress::TestEnum], :pointer)
|
157
|
-
.and_return true
|
158
|
-
GirFFI::Builder.attach_ffi_function(lib, info)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "does not attach the function if it is already defined" do
|
162
|
-
info = get_introspection_data "Regress", "test_array_gint32_in"
|
163
|
-
allow(lib).to receive(:method_defined?).and_return true
|
164
|
-
expect(lib).not_to receive(:attach_function)
|
165
|
-
GirFFI::Builder.attach_ffi_function(lib, info)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
@@ -1,691 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GirFFI::Builders::ArgumentBuilder do
|
6
|
-
let(:var_gen) { GirFFI::VariableNameGenerator.new }
|
7
|
-
let(:builder) { GirFFI::Builders::ArgumentBuilder.new(var_gen, arg_info) }
|
8
|
-
|
9
|
-
describe "for an argument with direction :in" do
|
10
|
-
describe "for :c" do
|
11
|
-
describe "with full ownership transfer" do
|
12
|
-
let(:arg_info) do
|
13
|
-
get_introspection_data("GIMarshallingTests", "array_struct_take_in").args[0]
|
14
|
-
end
|
15
|
-
|
16
|
-
it "has the correct value for #pre_conversion" do
|
17
|
-
_(builder.pre_conversion)
|
18
|
-
.must_equal [
|
19
|
-
"_v1 = GirFFI::SizedArray.copy_from(" \
|
20
|
-
"[:pointer, GIMarshallingTests::BoxedStruct], -1, structs)"
|
21
|
-
]
|
22
|
-
end
|
23
|
-
|
24
|
-
it "has the correct value for #post_conversion" do
|
25
|
-
_(builder.post_conversion).must_equal []
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "for :callback" do
|
31
|
-
let(:arg_info) do
|
32
|
-
get_introspection_data("Regress", "test_callback_destroy_notify").args[0]
|
33
|
-
end
|
34
|
-
|
35
|
-
it "has the correct value for #pre_conversion" do
|
36
|
-
_(builder.pre_conversion)
|
37
|
-
.must_equal ["_v1 = Regress::TestCallbackUserData.from(callback)"]
|
38
|
-
end
|
39
|
-
|
40
|
-
it "has the correct value for #post_conversion" do
|
41
|
-
_(builder.post_conversion).must_equal []
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "for :zero_terminated" do
|
46
|
-
let(:arg_info) do
|
47
|
-
get_introspection_data("GIMarshallingTests",
|
48
|
-
"array_in_len_zero_terminated").args[0]
|
49
|
-
end
|
50
|
-
|
51
|
-
it "has the correct value for #pre_conversion" do
|
52
|
-
_(builder.pre_conversion)
|
53
|
-
.must_equal ["_v1 = GirFFI::ZeroTerminated.from(:gint32, ints)"]
|
54
|
-
end
|
55
|
-
|
56
|
-
it "has the correct value for #post_conversion" do
|
57
|
-
_(builder.post_conversion).must_equal []
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "for :void" do
|
62
|
-
let(:arg_info) do
|
63
|
-
get_introspection_data("Regress", "test_callback_user_data").args[1]
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "when it is a regular argument" do
|
67
|
-
it "has the correct value for method_argument_name" do
|
68
|
-
_(builder.method_argument_name).must_equal arg_info.name
|
69
|
-
end
|
70
|
-
|
71
|
-
it "has the correct value for #pre_conversion" do
|
72
|
-
_(builder.pre_conversion).must_equal ["_v1 = user_data"]
|
73
|
-
end
|
74
|
-
|
75
|
-
it "has the correct value for #post_conversion" do
|
76
|
-
_(builder.post_conversion).must_equal []
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "when it is a closure" do
|
81
|
-
before do
|
82
|
-
callback = Object.new
|
83
|
-
allow(callback).to receive(:call_argument_name).and_return "foo"
|
84
|
-
builder.mark_as_user_data callback
|
85
|
-
end
|
86
|
-
|
87
|
-
it "has the correct value for method_argument_name" do
|
88
|
-
_(builder.method_argument_name).must_be_nil
|
89
|
-
end
|
90
|
-
|
91
|
-
it "has the correct value for #pre_conversion" do
|
92
|
-
_(builder.pre_conversion).must_equal ["_v1 = GirFFI::ArgHelper.store(foo)"]
|
93
|
-
end
|
94
|
-
|
95
|
-
it "has the correct value for #post_conversion" do
|
96
|
-
_(builder.post_conversion).must_equal []
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "for an argument with direction :out" do
|
103
|
-
describe "for :enum" do
|
104
|
-
let(:arg_info) { get_introspection_data("GIMarshallingTests", "genum_out").args[0] }
|
105
|
-
|
106
|
-
it "has the correct value for #pre_conversion" do
|
107
|
-
_(builder.pre_conversion)
|
108
|
-
.must_equal ["_v1 = FFI::MemoryPointer.new GIMarshallingTests::GEnum"]
|
109
|
-
end
|
110
|
-
|
111
|
-
it "has the correct value for #post_conversion" do
|
112
|
-
_(builder.post_conversion)
|
113
|
-
.must_equal ["_v2 = GIMarshallingTests::GEnum.get_value_from_pointer(_v1, 0)"]
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "for :flags" do
|
118
|
-
let(:arg_info) do
|
119
|
-
get_introspection_data("GIMarshallingTests", "flags_out").args[0]
|
120
|
-
end
|
121
|
-
|
122
|
-
it "has the correct value for #pre_conversion" do
|
123
|
-
_(builder.pre_conversion)
|
124
|
-
.must_equal ["_v1 = FFI::MemoryPointer.new GIMarshallingTests::Flags"]
|
125
|
-
end
|
126
|
-
|
127
|
-
it "has the correct value for #post_conversion" do
|
128
|
-
_(builder.post_conversion)
|
129
|
-
.must_equal ["_v2 = GIMarshallingTests::Flags.get_value_from_pointer(_v1, 0)"]
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "for :object" do
|
134
|
-
describe "with full ownership transfer" do
|
135
|
-
let(:arg_info) do
|
136
|
-
get_method_introspection_data("Regress", "TestObj", "null_out").args[0]
|
137
|
-
end
|
138
|
-
|
139
|
-
it "has the correct value for #pre_conversion" do
|
140
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
141
|
-
end
|
142
|
-
|
143
|
-
it "has the correct value for #post_conversion" do
|
144
|
-
_(builder.post_conversion)
|
145
|
-
.must_equal ["_v2 = Regress::TestObj.wrap(_v1.get_pointer(0))"]
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "with no ownership transfer" do
|
150
|
-
let(:arg_info) do
|
151
|
-
get_method_introspection_data("GIMarshallingTests", "Object", "none_out").args[0]
|
152
|
-
end
|
153
|
-
|
154
|
-
it "has the correct value for #pre_conversion" do
|
155
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
156
|
-
end
|
157
|
-
|
158
|
-
it "has the correct value for #post_conversion" do
|
159
|
-
_(builder.post_conversion)
|
160
|
-
.must_equal [
|
161
|
-
"_v2 = GIMarshallingTests::Object.wrap(_v1.get_pointer(0)).tap" \
|
162
|
-
" { |it| it && it.ref }"
|
163
|
-
]
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe "for :struct" do
|
169
|
-
describe "when not allocated by the caller" do
|
170
|
-
let(:arg_info) do
|
171
|
-
get_introspection_data("GIMarshallingTests", "boxed_struct_out").args[0]
|
172
|
-
end
|
173
|
-
|
174
|
-
it "has the correct value for #pre_conversion" do
|
175
|
-
_(builder.pre_conversion).must_equal [
|
176
|
-
"_v1 = FFI::MemoryPointer.new :pointer"
|
177
|
-
]
|
178
|
-
end
|
179
|
-
|
180
|
-
it "has the correct value for #post_conversion" do
|
181
|
-
_(builder.post_conversion)
|
182
|
-
.must_equal ["_v2 = GIMarshallingTests::BoxedStruct.wrap_copy("\
|
183
|
-
"_v1.get_pointer(0))"]
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
describe "when allocated by the caller" do
|
188
|
-
let(:arg_info) do
|
189
|
-
get_method_introspection_data("Regress", "TestStructA", "clone").args[0]
|
190
|
-
end
|
191
|
-
|
192
|
-
it "has the correct value for #pre_conversion" do
|
193
|
-
_(builder.pre_conversion).must_equal ["_v1 = Regress::TestStructA.new"]
|
194
|
-
end
|
195
|
-
|
196
|
-
it "has empty #post_conversion" do
|
197
|
-
_(builder.post_conversion).must_equal []
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
describe "for :strv" do
|
203
|
-
let(:arg_info) do
|
204
|
-
get_introspection_data("GIMarshallingTests", "gstrv_out").args[0]
|
205
|
-
end
|
206
|
-
|
207
|
-
it "has the correct value for #pre_conversion" do
|
208
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
209
|
-
end
|
210
|
-
|
211
|
-
it "has the correct value for #post_conversion" do
|
212
|
-
_(builder.post_conversion).must_equal ["_v2 = GLib::Strv.wrap(_v1.get_pointer(0))"]
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe "for :array" do
|
217
|
-
describe "when allocated by the callee" do
|
218
|
-
let(:arg_info) do
|
219
|
-
get_introspection_data("GIMarshallingTests", "garray_utf8_none_out").args[0]
|
220
|
-
end
|
221
|
-
|
222
|
-
it "has the correct value for #pre_conversion" do
|
223
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
224
|
-
end
|
225
|
-
|
226
|
-
it "has the correct value for #post_conversion" do
|
227
|
-
_(builder.post_conversion)
|
228
|
-
.must_equal ["_v2 = GLib::Array.wrap(:utf8, _v1.get_pointer(0))"]
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
describe "when allocated by the caller" do
|
233
|
-
let(:function_info) do
|
234
|
-
get_introspection_data("GIMarshallingTests",
|
235
|
-
"garray_utf8_full_out_caller_allocated")
|
236
|
-
end
|
237
|
-
|
238
|
-
let(:arg_info) { function_info.args[0] }
|
239
|
-
|
240
|
-
it "has the correct value for #pre_conversion" do
|
241
|
-
_(builder.pre_conversion).must_equal ["_v1 = GLib::Array.new :utf8"]
|
242
|
-
end
|
243
|
-
|
244
|
-
it "has empty #post_conversion" do
|
245
|
-
_(builder.post_conversion).must_equal []
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
describe "for :ptr_array" do
|
251
|
-
let(:arg_info) do
|
252
|
-
get_introspection_data("GIMarshallingTests", "gptrarray_utf8_none_out").args[0]
|
253
|
-
end
|
254
|
-
|
255
|
-
it "has the correct value for #pre_conversion" do
|
256
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
257
|
-
end
|
258
|
-
|
259
|
-
it "has the correct value for #post_conversion" do
|
260
|
-
_(builder.post_conversion)
|
261
|
-
.must_equal ["_v2 = GLib::PtrArray.wrap(:utf8, _v1.get_pointer(0))"]
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
describe "for :error" do
|
266
|
-
let(:arg_info) do
|
267
|
-
get_introspection_data("GIMarshallingTests", "gerror_out").args[0]
|
268
|
-
end
|
269
|
-
|
270
|
-
it "has the correct value for #pre_conversion" do
|
271
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
272
|
-
end
|
273
|
-
|
274
|
-
it "has the correct value for #post_conversion" do
|
275
|
-
_(builder.post_conversion).must_equal ["_v2 = GLib::Error.wrap(_v1.get_pointer(0))"]
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
describe "for :c" do
|
280
|
-
describe "with fixed size" do
|
281
|
-
let(:arg_info) do
|
282
|
-
get_introspection_data("GIMarshallingTests", "array_fixed_out").args[0]
|
283
|
-
end
|
284
|
-
|
285
|
-
it "has the correct value for #pre_conversion" do
|
286
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
287
|
-
end
|
288
|
-
|
289
|
-
it "has the correct value for #post_conversion" do
|
290
|
-
_(builder.post_conversion)
|
291
|
-
.must_equal ["_v2 = GirFFI::SizedArray.wrap(:gint32, 4, _v1.get_pointer(0))"]
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
describe "with separate size parameter" do
|
296
|
-
let(:arg_info) do
|
297
|
-
get_introspection_data("GIMarshallingTests", "array_out").args[0]
|
298
|
-
end
|
299
|
-
|
300
|
-
let(:length_argument) { Object.new }
|
301
|
-
before do
|
302
|
-
allow(length_argument).to receive(:post_converted_name).and_return "bar"
|
303
|
-
builder.length_arg = length_argument
|
304
|
-
end
|
305
|
-
|
306
|
-
it "has the correct value for #pre_conversion" do
|
307
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
308
|
-
end
|
309
|
-
|
310
|
-
it "has the correct value for #post_conversion" do
|
311
|
-
_(builder.post_conversion)
|
312
|
-
.must_equal ["_v2 = GirFFI::SizedArray.wrap(:gint32, bar, _v1.get_pointer(0))"]
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
describe "for :glist" do
|
318
|
-
let(:arg_info) do
|
319
|
-
get_introspection_data("GIMarshallingTests", "glist_utf8_none_out").args[0]
|
320
|
-
end
|
321
|
-
|
322
|
-
it "has the correct value for #pre_conversion" do
|
323
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
324
|
-
end
|
325
|
-
|
326
|
-
it "has the correct value for #post_conversion" do
|
327
|
-
_(builder.post_conversion)
|
328
|
-
.must_equal ["_v2 = GLib::List.wrap(:utf8, _v1.get_pointer(0))"]
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
describe "for :gslist" do
|
333
|
-
let(:arg_info) do
|
334
|
-
get_introspection_data("GIMarshallingTests", "gslist_utf8_none_out").args[0]
|
335
|
-
end
|
336
|
-
|
337
|
-
it "has the correct value for #pre_conversion" do
|
338
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
339
|
-
end
|
340
|
-
|
341
|
-
it "has the correct value for #post_conversion" do
|
342
|
-
_(builder.post_conversion)
|
343
|
-
.must_equal ["_v2 = GLib::SList.wrap(:utf8, _v1.get_pointer(0))"]
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
describe "for :ghash" do
|
348
|
-
let(:arg_info) do
|
349
|
-
get_introspection_data("GIMarshallingTests", "ghashtable_utf8_none_out").args[0]
|
350
|
-
end
|
351
|
-
|
352
|
-
it "has the correct value for #pre_conversion" do
|
353
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
354
|
-
end
|
355
|
-
|
356
|
-
it "has the correct value for #post_conversion" do
|
357
|
-
_(builder.post_conversion)
|
358
|
-
.must_equal ["_v2 = GLib::HashTable.wrap([:utf8, :utf8], _v1.get_pointer(0))"]
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
describe "for :utf8" do
|
363
|
-
describe "with full ownership transfer" do
|
364
|
-
let(:arg_info) do
|
365
|
-
get_introspection_data("GIMarshallingTests", "utf8_full_out").args[0]
|
366
|
-
end
|
367
|
-
|
368
|
-
it "has the correct value for #pre_conversion" do
|
369
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
370
|
-
end
|
371
|
-
|
372
|
-
it "has the correct value for #post_conversion" do
|
373
|
-
_(builder.post_conversion).must_equal [
|
374
|
-
"_v2 = GirFFI::AllocationHelper.free_after _v1.get_pointer(0), &:to_utf8"
|
375
|
-
]
|
376
|
-
end
|
377
|
-
|
378
|
-
it "has the correct value for #return_value_name" do
|
379
|
-
builder.post_conversion
|
380
|
-
_(builder.return_value_name).must_equal "_v2"
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
|
-
describe "with no ownership transfer" do
|
385
|
-
let(:arg_info) do
|
386
|
-
get_introspection_data("GIMarshallingTests", "utf8_none_out").args[0]
|
387
|
-
end
|
388
|
-
|
389
|
-
it "has the correct value for #pre_conversion" do
|
390
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
391
|
-
end
|
392
|
-
|
393
|
-
it "has the correct value for #post_conversion" do
|
394
|
-
_(builder.post_conversion).must_equal ["_v2 = _v1.get_pointer(0).to_utf8"]
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
describe "for :void" do
|
400
|
-
let(:function_info) do
|
401
|
-
get_introspection_data("Everything", "one_outparam_gpointer")
|
402
|
-
end
|
403
|
-
let(:arg_info) { function_info.args[0] }
|
404
|
-
|
405
|
-
before { skip_below "1.47.1" }
|
406
|
-
|
407
|
-
it "has the correct value for #pre_conversion" do
|
408
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer"]
|
409
|
-
end
|
410
|
-
|
411
|
-
it "has the correct value for #post_conversion" do
|
412
|
-
_(builder.post_conversion).must_equal ["_v2 = _v1.get_pointer(0)"]
|
413
|
-
end
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
describe "for an argument with direction :inout" do
|
418
|
-
describe "for :enum" do
|
419
|
-
let(:arg_info) do
|
420
|
-
get_introspection_data("GIMarshallingTests", "enum_inout").args[0]
|
421
|
-
end
|
422
|
-
|
423
|
-
it "has the correct value for #pre_conversion" do
|
424
|
-
_(builder.pre_conversion)
|
425
|
-
.must_equal [
|
426
|
-
"_v1 = FFI::MemoryPointer.new GIMarshallingTests::Enum",
|
427
|
-
"GIMarshallingTests::Enum.copy_value_to_pointer(#{arg_info.name}, _v1)"
|
428
|
-
]
|
429
|
-
end
|
430
|
-
|
431
|
-
it "has the correct value for #post_conversion" do
|
432
|
-
_(builder.post_conversion)
|
433
|
-
.must_equal ["_v2 = GIMarshallingTests::Enum.get_value_from_pointer(_v1, 0)"]
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
describe "for :flags" do
|
438
|
-
let(:arg_info) do
|
439
|
-
get_introspection_data("GIMarshallingTests", "no_type_flags_inout").args[0]
|
440
|
-
end
|
441
|
-
|
442
|
-
it "has the correct value for #pre_conversion" do
|
443
|
-
_(builder.pre_conversion)
|
444
|
-
.must_equal [
|
445
|
-
"_v1 = FFI::MemoryPointer.new GIMarshallingTests::NoTypeFlags",
|
446
|
-
"GIMarshallingTests::NoTypeFlags.copy_value_to_pointer(#{arg_info.name}, _v1)"
|
447
|
-
]
|
448
|
-
end
|
449
|
-
|
450
|
-
it "has the correct value for #post_conversion" do
|
451
|
-
_(builder.post_conversion)
|
452
|
-
.must_equal [
|
453
|
-
"_v2 = GIMarshallingTests::NoTypeFlags.get_value_from_pointer(_v1, 0)"
|
454
|
-
]
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
describe "for :gint32" do
|
459
|
-
let(:arg_info) do
|
460
|
-
get_introspection_data("GIMarshallingTests", "int32_inout_min_max").args[0]
|
461
|
-
end
|
462
|
-
|
463
|
-
it "has the correct value for method_argument_name" do
|
464
|
-
_(builder.method_argument_name).must_equal arg_info.name
|
465
|
-
end
|
466
|
-
|
467
|
-
it "has the correct value for #pre_conversion" do
|
468
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :int32",
|
469
|
-
"_v1.put_int32 0, #{arg_info.name}"]
|
470
|
-
end
|
471
|
-
|
472
|
-
it "has the correct value for #post_conversion" do
|
473
|
-
_(builder.post_conversion).must_equal ["_v2 = _v1.get_int32(0)"]
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
describe "for an array length" do
|
478
|
-
let(:function_info) do
|
479
|
-
get_introspection_data("Regress", "test_array_int_inout")
|
480
|
-
end
|
481
|
-
let(:arg_info) { function_info.args[0] }
|
482
|
-
let(:array_arg_info) { function_info.args[1] }
|
483
|
-
let(:array_arg_builder) do
|
484
|
-
GirFFI::Builders::ArgumentBuilder.new(var_gen, array_arg_info)
|
485
|
-
end
|
486
|
-
|
487
|
-
before do
|
488
|
-
builder.array_arg = array_arg_builder
|
489
|
-
end
|
490
|
-
|
491
|
-
it "has the correct value for #pre_conversion" do
|
492
|
-
_(builder.pre_conversion).must_equal ["n_ints = ints.nil? ? 0 : ints.length",
|
493
|
-
"_v1 = FFI::MemoryPointer.new :int32",
|
494
|
-
"_v1.put_int32 0, n_ints"]
|
495
|
-
end
|
496
|
-
|
497
|
-
it "has the correct value for #post_conversion" do
|
498
|
-
_(builder.post_conversion).must_equal ["_v2 = _v1.get_int32(0)"]
|
499
|
-
end
|
500
|
-
end
|
501
|
-
|
502
|
-
describe "for :strv" do
|
503
|
-
let(:arg_info) do
|
504
|
-
get_introspection_data("GIMarshallingTests", "gstrv_inout").args[0]
|
505
|
-
end
|
506
|
-
|
507
|
-
it "has the correct value for #pre_conversion" do
|
508
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :pointer",
|
509
|
-
"_v1.put_pointer 0, GLib::Strv.from(g_strv)"]
|
510
|
-
end
|
511
|
-
|
512
|
-
it "has the correct value for #post_conversion" do
|
513
|
-
_(builder.post_conversion).must_equal ["_v2 = GLib::Strv.wrap(_v1.get_pointer(0))"]
|
514
|
-
end
|
515
|
-
end
|
516
|
-
|
517
|
-
describe "for :ptr_array" do
|
518
|
-
let(:arg_info) do
|
519
|
-
get_introspection_data("GIMarshallingTests", "gptrarray_utf8_none_inout").args[0]
|
520
|
-
end
|
521
|
-
|
522
|
-
it "has the correct value for #pre_conversion" do
|
523
|
-
_(builder.pre_conversion)
|
524
|
-
.must_equal ["_v1 = FFI::MemoryPointer.new :pointer",
|
525
|
-
"_v1.put_pointer 0, GLib::PtrArray.from(:utf8, parray_)"]
|
526
|
-
end
|
527
|
-
|
528
|
-
it "has the correct value for #post_conversion" do
|
529
|
-
_(builder.post_conversion)
|
530
|
-
.must_equal ["_v2 = GLib::PtrArray.wrap(:utf8, _v1.get_pointer(0))"]
|
531
|
-
end
|
532
|
-
end
|
533
|
-
|
534
|
-
describe "for :utf8" do
|
535
|
-
let(:arg_info) do
|
536
|
-
get_introspection_data("GIMarshallingTests", "utf8_none_inout").args[0]
|
537
|
-
end
|
538
|
-
|
539
|
-
it "has the correct value for #pre_conversion" do
|
540
|
-
_(builder.pre_conversion)
|
541
|
-
.must_equal ["_v1 = FFI::MemoryPointer.new :pointer",
|
542
|
-
"_v1.put_pointer 0, GirFFI::InPointer.from_utf8(utf8)"]
|
543
|
-
end
|
544
|
-
|
545
|
-
it "has the correct value for #post_conversion" do
|
546
|
-
_(builder.post_conversion).must_equal ["_v2 = _v1.get_pointer(0).to_utf8"]
|
547
|
-
end
|
548
|
-
end
|
549
|
-
|
550
|
-
describe "for :struct" do
|
551
|
-
describe "with full ownership transfer" do
|
552
|
-
let(:arg_info) do
|
553
|
-
get_introspection_data("GIMarshallingTests", "boxed_struct_inout").args[0]
|
554
|
-
end
|
555
|
-
|
556
|
-
it "has the correct value for #pre_conversion" do
|
557
|
-
_(builder.pre_conversion).must_equal [
|
558
|
-
"_v1 = FFI::MemoryPointer.new :pointer",
|
559
|
-
"_v1.put_pointer 0, GIMarshallingTests::BoxedStruct.copy_from(struct_)"
|
560
|
-
]
|
561
|
-
end
|
562
|
-
|
563
|
-
it "has the correct value for #post_conversion" do
|
564
|
-
_(builder.post_conversion)
|
565
|
-
.must_equal [
|
566
|
-
"_v2 = GIMarshallingTests::BoxedStruct.wrap_own(_v1.get_pointer(0))"
|
567
|
-
]
|
568
|
-
end
|
569
|
-
end
|
570
|
-
end
|
571
|
-
|
572
|
-
describe "for :c" do
|
573
|
-
describe "with fixed size" do
|
574
|
-
let(:arg_info) do
|
575
|
-
get_introspection_data("GIMarshallingTests", "array_fixed_inout").args[0]
|
576
|
-
end
|
577
|
-
|
578
|
-
it "has the correct value for #pre_conversion" do
|
579
|
-
_(builder.pre_conversion).must_equal [
|
580
|
-
'GirFFI::ArgHelper.check_fixed_array_size 4, ints, "ints"',
|
581
|
-
"_v1 = FFI::MemoryPointer.new :pointer",
|
582
|
-
"_v1.put_pointer 0, GirFFI::SizedArray.from(:gint32, 4, ints)"
|
583
|
-
]
|
584
|
-
end
|
585
|
-
|
586
|
-
it "has the correct value for #post_conversion" do
|
587
|
-
_(builder.post_conversion)
|
588
|
-
.must_equal ["_v2 = GirFFI::SizedArray.wrap(:gint32, 4, _v1.get_pointer(0))"]
|
589
|
-
end
|
590
|
-
end
|
591
|
-
|
592
|
-
describe "with separate size parameter" do
|
593
|
-
let(:function_info) do
|
594
|
-
get_introspection_data("Regress", "test_array_int_inout")
|
595
|
-
end
|
596
|
-
let(:length_arg_info) { function_info.args[0] }
|
597
|
-
let(:arg_info) { function_info.args[1] }
|
598
|
-
let(:length_arg_builder) do
|
599
|
-
GirFFI::Builders::ArgumentBuilder.new(var_gen, length_arg_info)
|
600
|
-
end
|
601
|
-
|
602
|
-
before do
|
603
|
-
builder.length_arg = length_arg_builder
|
604
|
-
end
|
605
|
-
|
606
|
-
it "has the correct value for #pre_conversion" do
|
607
|
-
_(builder.pre_conversion).must_equal [
|
608
|
-
"_v1 = FFI::MemoryPointer.new :pointer",
|
609
|
-
"_v1.put_pointer 0, GirFFI::SizedArray.copy_from(:gint32, -1, ints)"
|
610
|
-
]
|
611
|
-
end
|
612
|
-
|
613
|
-
it "has the correct value for #post_conversion" do
|
614
|
-
_(builder.post_conversion)
|
615
|
-
.must_equal ["_v3 = GirFFI::SizedArray.wrap(:gint32, _v2, _v1.get_pointer(0))"]
|
616
|
-
end
|
617
|
-
end
|
618
|
-
end
|
619
|
-
end
|
620
|
-
|
621
|
-
describe "for a skipped argument with direction :in" do
|
622
|
-
let(:arg_info) do
|
623
|
-
get_method_introspection_data("Regress", "TestObj", "skip_param").args[2]
|
624
|
-
end
|
625
|
-
|
626
|
-
it "has the correct value for method_argument_name" do
|
627
|
-
_(builder.method_argument_name).must_be_nil
|
628
|
-
end
|
629
|
-
|
630
|
-
it "has the correct value for #pre_conversion" do
|
631
|
-
_(builder.pre_conversion).must_equal ["_v1 = 0"]
|
632
|
-
end
|
633
|
-
|
634
|
-
it "has the correct value for #post_conversion" do
|
635
|
-
_(builder.post_conversion).must_equal []
|
636
|
-
end
|
637
|
-
end
|
638
|
-
|
639
|
-
describe "for a skipped argument with direction :inout" do
|
640
|
-
let(:arg_info) do
|
641
|
-
get_method_introspection_data("Regress", "TestObj", "skip_inout_param").args[3]
|
642
|
-
end
|
643
|
-
|
644
|
-
it "has the correct value for method_argument_name" do
|
645
|
-
_(builder.method_argument_name).must_be_nil
|
646
|
-
end
|
647
|
-
|
648
|
-
it "has the correct value for #pre_conversion" do
|
649
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :int32",
|
650
|
-
"_v1.put_int32 0, 0"]
|
651
|
-
end
|
652
|
-
|
653
|
-
it "has the correct value for #post_conversion" do
|
654
|
-
_(builder.post_conversion).must_equal []
|
655
|
-
end
|
656
|
-
end
|
657
|
-
|
658
|
-
describe "for a skipped argument with direction :out" do
|
659
|
-
let(:arg_info) do
|
660
|
-
get_method_introspection_data("Regress", "TestObj", "skip_out_param").args[1]
|
661
|
-
end
|
662
|
-
|
663
|
-
it "has the correct value for method_argument_name" do
|
664
|
-
_(builder.method_argument_name).must_be_nil
|
665
|
-
end
|
666
|
-
|
667
|
-
it "has the correct value for #pre_conversion" do
|
668
|
-
_(builder.pre_conversion).must_equal ["_v1 = FFI::MemoryPointer.new :int32"]
|
669
|
-
end
|
670
|
-
|
671
|
-
it "has the correct value for #post_conversion" do
|
672
|
-
_(builder.post_conversion).must_equal []
|
673
|
-
end
|
674
|
-
end
|
675
|
-
|
676
|
-
describe "for an argument with direction :error" do
|
677
|
-
let(:arg_info) { GirFFI::ErrorArgumentInfo.new }
|
678
|
-
|
679
|
-
it "has the correct value for #pre_conversion" do
|
680
|
-
_(builder.pre_conversion).must_equal [
|
681
|
-
"_v1 = FFI::MemoryPointer.new(:pointer).write_pointer nil"
|
682
|
-
]
|
683
|
-
end
|
684
|
-
|
685
|
-
it "has the correct value for #post_conversion" do
|
686
|
-
_(builder.post_conversion).must_equal [
|
687
|
-
"GirFFI::ArgHelper.check_error(_v1)"
|
688
|
-
]
|
689
|
-
end
|
690
|
-
end
|
691
|
-
end
|