gir_ffi 0.14.0 → 0.15.3
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 +45 -0
- data/Gemfile +6 -4
- data/README.md +11 -10
- data/Rakefile +5 -5
- data/lib/ffi-glib.rb +16 -16
- data/lib/ffi-glib/array.rb +14 -4
- data/lib/ffi-glib/byte_array.rb +7 -2
- data/lib/ffi-glib/container_class_methods.rb +1 -1
- data/lib/ffi-glib/error.rb +1 -1
- data/lib/ffi-glib/hash_table.rb +3 -3
- data/lib/ffi-glib/list.rb +1 -1
- data/lib/ffi-glib/list_methods.rb +1 -1
- data/lib/ffi-glib/main_loop.rb +3 -3
- data/lib/ffi-glib/ptr_array.rb +30 -8
- data/lib/ffi-glib/s_list.rb +1 -1
- data/lib/ffi-glib/variant.rb +1 -1
- data/lib/ffi-gobject.rb +13 -13
- data/lib/ffi-gobject/object.rb +23 -32
- data/lib/ffi-gobject/param_spec.rb +1 -1
- data/lib/ffi-gobject/ruby_closure.rb +2 -2
- data/lib/ffi-gobject/value.rb +40 -29
- data/lib/ffi-gobject_introspection.rb +20 -20
- data/lib/ffi-gobject_introspection/gobject_type_init.rb +2 -2
- data/lib/ffi-gobject_introspection/i_arg_info.rb +2 -2
- data/lib/ffi-gobject_introspection/i_base_info.rb +27 -17
- data/lib/ffi-gobject_introspection/i_callable_info.rb +4 -4
- data/lib/ffi-gobject_introspection/i_constant_info.rb +2 -2
- data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_field_info.rb +1 -1
- data/lib/ffi-gobject_introspection/i_function_info.rb +1 -1
- data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -1
- data/lib/ffi-gobject_introspection/i_object_info.rb +2 -2
- data/lib/ffi-gobject_introspection/i_property_info.rb +2 -2
- data/lib/ffi-gobject_introspection/i_repository.rb +9 -6
- data/lib/ffi-gobject_introspection/i_struct_info.rb +2 -1
- data/lib/ffi-gobject_introspection/i_type_info.rb +13 -7
- data/lib/ffi-gobject_introspection/i_unresolved_info.rb +1 -1
- data/lib/ffi-gobject_introspection/i_vfunc_info.rb +1 -1
- data/lib/ffi-gobject_introspection/lib.rb +30 -19
- data/lib/ffi-gobject_introspection/strv.rb +1 -1
- data/lib/gir_ffi-base.rb +1 -1
- data/lib/gir_ffi-base/gobject.rb +26 -25
- data/lib/gir_ffi-base/gobject/lib.rb +3 -2
- data/lib/gir_ffi.rb +3 -3
- data/lib/gir_ffi/allocation_helper.rb +1 -1
- data/lib/gir_ffi/arg_helper.rb +4 -4
- data/lib/gir_ffi/{in_out_pointer.rb → array_element_convertor.rb} +16 -23
- data/lib/gir_ffi/boolean.rb +1 -1
- data/lib/gir_ffi/boxed_base.rb +1 -1
- data/lib/gir_ffi/builder.rb +18 -10
- data/lib/gir_ffi/builder_helper.rb +6 -1
- data/lib/gir_ffi/builders/argument_builder.rb +19 -19
- data/lib/gir_ffi/builders/argument_builder_collection.rb +2 -2
- data/lib/gir_ffi/builders/base_argument_builder.rb +1 -0
- data/lib/gir_ffi/builders/base_method_builder.rb +7 -7
- data/lib/gir_ffi/builders/base_return_value_builder.rb +1 -1
- data/lib/gir_ffi/builders/base_type_builder.rb +1 -1
- data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +5 -5
- data/lib/gir_ffi/builders/callback_argument_builder.rb +8 -8
- data/lib/gir_ffi/builders/callback_builder.rb +16 -4
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +2 -2
- data/lib/gir_ffi/builders/closure_argument_builder.rb +1 -1
- data/lib/gir_ffi/builders/closure_return_value_builder.rb +1 -1
- data/lib/gir_ffi/builders/constant_builder.rb +1 -1
- data/lib/gir_ffi/builders/constructor_builder.rb +9 -9
- data/lib/gir_ffi/builders/enum_builder.rb +16 -3
- data/lib/gir_ffi/builders/field_builder.rb +20 -18
- data/lib/gir_ffi/builders/flags_builder.rb +2 -2
- data/lib/gir_ffi/builders/full_c_to_ruby_convertor.rb +1 -1
- data/lib/gir_ffi/builders/function_builder.rb +11 -5
- data/lib/gir_ffi/builders/initializer_builder.rb +3 -3
- data/lib/gir_ffi/builders/initializer_return_value_builder.rb +2 -2
- data/lib/gir_ffi/builders/interface_builder.rb +2 -2
- data/lib/gir_ffi/builders/mapping_method_builder.rb +9 -9
- data/lib/gir_ffi/builders/marshalling_method_builder.rb +7 -7
- data/lib/gir_ffi/builders/method_template.rb +1 -1
- data/lib/gir_ffi/builders/module_builder.rb +7 -7
- data/lib/gir_ffi/builders/object_builder.rb +6 -6
- data/lib/gir_ffi/builders/property_argument_builder.rb +1 -1
- data/lib/gir_ffi/builders/property_builder.rb +13 -12
- data/lib/gir_ffi/builders/property_return_value_builder.rb +1 -1
- data/lib/gir_ffi/builders/registered_type_builder.rb +14 -5
- data/lib/gir_ffi/builders/return_value_builder.rb +4 -4
- data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +6 -6
- data/lib/gir_ffi/builders/signal_closure_builder.rb +2 -2
- data/lib/gir_ffi/builders/struct_builder.rb +6 -4
- data/lib/gir_ffi/builders/struct_like.rb +1 -1
- data/lib/gir_ffi/builders/type_builder.rb +12 -12
- data/lib/gir_ffi/builders/unintrospectable_boxed_builder.rb +2 -2
- data/lib/gir_ffi/builders/unintrospectable_builder.rb +2 -2
- data/lib/gir_ffi/builders/union_builder.rb +4 -4
- data/lib/gir_ffi/builders/user_defined_builder.rb +2 -2
- data/lib/gir_ffi/builders/vfunc_argument_builder.rb +1 -1
- data/lib/gir_ffi/builders/vfunc_builder.rb +8 -8
- data/lib/gir_ffi/builders/with_layout.rb +2 -2
- data/lib/gir_ffi/callback_base.rb +4 -6
- data/lib/gir_ffi/class_base.rb +6 -5
- data/lib/gir_ffi/core.rb +19 -20
- data/lib/gir_ffi/enum_base.rb +1 -1
- data/lib/gir_ffi/enum_like_base.rb +2 -2
- data/lib/gir_ffi/error_argument_info.rb +2 -2
- data/lib/gir_ffi/error_type_info.rb +1 -1
- data/lib/gir_ffi/ffi_ext.rb +1 -1
- data/lib/gir_ffi/ffi_ext/pointer.rb +1 -1
- data/lib/gir_ffi/flags_base.rb +1 -1
- data/lib/gir_ffi/in_pointer.rb +10 -0
- data/lib/gir_ffi/info_ext.rb +15 -14
- data/lib/gir_ffi/info_ext/full_type_name.rb +3 -3
- data/lib/gir_ffi/info_ext/i_arg_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_callable_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_callback_info.rb +1 -1
- 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_property_info.rb +2 -2
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +4 -5
- data/lib/gir_ffi/info_ext/i_signal_info.rb +7 -3
- data/lib/gir_ffi/info_ext/i_type_info.rb +48 -26
- data/lib/gir_ffi/info_ext/i_unresolved_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_value_info.rb +25 -0
- data/lib/gir_ffi/info_ext/i_vfunc_info.rb +2 -2
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -8
- data/lib/gir_ffi/info_ext/safe_function_name.rb +2 -2
- data/lib/gir_ffi/interface_base.rb +3 -3
- data/lib/gir_ffi/lib_c.rb +1 -1
- data/lib/gir_ffi/method_stubber.rb +1 -1
- data/lib/gir_ffi/module_base.rb +1 -1
- data/lib/gir_ffi/object_base.rb +3 -4
- data/lib/gir_ffi/receiver_argument_info.rb +1 -1
- data/lib/gir_ffi/receiver_type_info.rb +2 -2
- data/lib/gir_ffi/registered_type_base.rb +1 -1
- data/lib/gir_ffi/sized_array.rb +4 -2
- data/lib/gir_ffi/struct.rb +1 -1
- data/lib/gir_ffi/struct_base.rb +1 -1
- data/lib/gir_ffi/type_map.rb +2 -23
- data/lib/gir_ffi/unintrospectable_boxed_info.rb +2 -2
- data/lib/gir_ffi/unintrospectable_type_info.rb +5 -1
- data/lib/gir_ffi/union.rb +1 -1
- data/lib/gir_ffi/union_base.rb +1 -1
- data/lib/gir_ffi/user_defined_object_info.rb +6 -2
- data/lib/gir_ffi/user_defined_property_info.rb +33 -33
- data/lib/gir_ffi/version.rb +1 -1
- data/tasks/test.rake +3 -2
- data/test/base_test_helper.rb +16 -9
- data/test/ffi-glib/array_test.rb +71 -56
- data/test/ffi-glib/byte_array_test.rb +13 -7
- data/test/ffi-glib/bytes_test.rb +24 -19
- data/test/ffi-glib/closure_test.rb +11 -11
- data/test/ffi-glib/destroy_notify_test.rb +6 -6
- data/test/ffi-glib/hash_table_test.rb +27 -27
- data/test/ffi-glib/list_test.rb +22 -22
- data/test/ffi-glib/main_loop_test.rb +12 -12
- data/test/ffi-glib/ptr_array_test.rb +39 -39
- data/test/ffi-glib/ruby_closure_test.rb +10 -10
- data/test/ffi-glib/s_list_test.rb +20 -20
- data/test/ffi-glib/strv_test.rb +19 -19
- data/test/ffi-glib/variant_test.rb +5 -5
- data/test/ffi-gobject/gobject_test.rb +48 -44
- data/test/ffi-gobject/object_class_test.rb +8 -8
- data/test/ffi-gobject/object_test.rb +51 -68
- data/test/ffi-gobject/param_spec_test.rb +12 -12
- data/test/ffi-gobject/value_test.rb +145 -125
- data/test/ffi-gobject_introspection/gobject_type_init_test.rb +9 -9
- data/test/ffi-gobject_introspection/i_base_info_test.rb +15 -16
- data/test/ffi-gobject_introspection/i_constant_info_test.rb +9 -13
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +7 -7
- data/test/ffi-gobject_introspection/i_function_info_test.rb +1 -1
- data/test/ffi-gobject_introspection/i_interface_info_test.rb +10 -10
- data/test/ffi-gobject_introspection/i_object_info_test.rb +23 -23
- data/test/ffi-gobject_introspection/i_property_info_test.rb +19 -19
- data/test/ffi-gobject_introspection/i_registered_type_info_test.rb +10 -10
- data/test/ffi-gobject_introspection/i_repository_test.rb +34 -34
- data/test/ffi-gobject_introspection/i_struct_info_test.rb +10 -10
- data/test/ffi-gobject_introspection/i_type_info_test.rb +12 -15
- data/test/ffi-gobject_introspection/i_union_info_test.rb +7 -7
- data/test/ffi-gobject_introspection/i_vfunc_info_test.rb +16 -16
- data/test/ffi-gobject_introspection/lib_test.rb +3 -3
- data/test/ffi-gobject_introspection/strv_test.rb +9 -9
- data/test/ffi-gobject_test.rb +47 -45
- data/test/gir_ffi/allocation_helper_test.rb +13 -13
- data/test/gir_ffi/arg_helper_test.rb +71 -65
- data/test/gir_ffi/boolean_test.rb +20 -20
- data/test/gir_ffi/boxed_base_test.rb +18 -18
- data/test/gir_ffi/builder_test.rb +81 -213
- data/test/gir_ffi/builders/argument_builder_test.rb +321 -287
- data/test/gir_ffi/builders/base_argument_builder_test.rb +1 -1
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +57 -56
- data/test/gir_ffi/builders/callback_builder_test.rb +71 -72
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +40 -41
- data/test/gir_ffi/builders/constant_builder_test.rb +1 -1
- data/test/gir_ffi/builders/constructor_builder_test.rb +12 -10
- data/test/gir_ffi/builders/enum_builder_test.rb +12 -11
- data/test/gir_ffi/builders/field_builder_test.rb +48 -42
- data/test/gir_ffi/builders/function_builder_test.rb +256 -224
- data/test/gir_ffi/builders/initializer_builder_test.rb +16 -14
- data/test/gir_ffi/builders/interface_builder_test.rb +9 -9
- data/test/gir_ffi/builders/module_builder_test.rb +18 -18
- data/test/gir_ffi/builders/object_builder_test.rb +41 -41
- data/test/gir_ffi/builders/property_builder_test.rb +94 -94
- data/test/gir_ffi/builders/registered_type_builder_test.rb +35 -11
- data/test/gir_ffi/builders/return_value_builder_test.rb +227 -223
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +124 -113
- data/test/gir_ffi/builders/struct_builder_test.rb +38 -35
- data/test/gir_ffi/builders/unintrospectable_boxed_builder_test.rb +8 -14
- data/test/gir_ffi/builders/unintrospectable_builder_test.rb +34 -23
- data/test/gir_ffi/builders/union_builder_test.rb +12 -15
- data/test/gir_ffi/builders/user_defined_builder_test.rb +152 -148
- data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +46 -40
- data/test/gir_ffi/builders/vfunc_builder_test.rb +149 -157
- data/test/gir_ffi/callback_base_test.rb +9 -9
- data/test/gir_ffi/class_base_test.rb +56 -53
- data/test/gir_ffi/core_test.rb +36 -35
- data/test/gir_ffi/enum_base_test.rb +19 -19
- data/test/gir_ffi/error_type_info_test.rb +23 -23
- data/test/gir_ffi/ffi_ext/pointer_test.rb +9 -7
- data/test/gir_ffi/g_type_test.rb +11 -11
- data/test/gir_ffi/in_pointer_test.rb +70 -50
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +5 -5
- data/test/gir_ffi/info_ext/i_callback_info_test.rb +6 -5
- data/test/gir_ffi/info_ext/i_field_info_test.rb +6 -6
- data/test/gir_ffi/info_ext/i_function_info_test.rb +17 -17
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +8 -8
- data/test/gir_ffi/info_ext/i_type_info_test.rb +231 -216
- data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +4 -4
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +8 -8
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +8 -8
- data/test/gir_ffi/interface_base_test.rb +8 -8
- data/test/gir_ffi/method_stubber_test.rb +21 -19
- data/test/gir_ffi/object_base_test.rb +23 -23
- data/test/gir_ffi/object_store_test.rb +13 -13
- data/test/gir_ffi/receiver_argument_info_test.rb +15 -15
- data/test/gir_ffi/sized_array_test.rb +68 -68
- data/test/gir_ffi/struct_base_test.rb +8 -8
- data/test/gir_ffi/struct_like_base_test.rb +64 -64
- data/test/gir_ffi/type_map_test.rb +8 -8
- data/test/gir_ffi/unintrospectable_type_info_test.rb +33 -33
- data/test/gir_ffi/union_base_test.rb +8 -8
- data/test/gir_ffi/user_defined_object_info_test.rb +34 -34
- data/test/gir_ffi/user_defined_property_info_test.rb +16 -16
- data/test/gir_ffi/variable_name_generator_test.rb +8 -8
- data/test/gir_ffi/version_test.rb +4 -4
- data/test/gir_ffi/zero_terminated_test.rb +34 -34
- data/test/gir_ffi_test_helper.rb +3 -3
- data/test/integration/callback_exceptions_test.rb +17 -21
- data/test/integration/derived_classes_test.rb +14 -13
- data/test/integration/generated_everything_test.rb +225 -224
- data/test/integration/generated_gimarshallingtests_test.rb +1174 -1060
- data/test/integration/generated_gio_test.rb +36 -36
- data/test/integration/generated_glib_test.rb +4 -6
- data/test/integration/generated_gobject_test.rb +43 -35
- data/test/integration/generated_gst_test.rb +20 -16
- data/test/integration/generated_gtk_source_test.rb +9 -15
- data/test/integration/generated_gtop_test.rb +8 -15
- data/test/integration/generated_pango_ft2_test.rb +2 -2
- data/test/integration/generated_pango_test.rb +4 -4
- data/test/integration/generated_regress_test.rb +1858 -1632
- data/test/integration/generated_secret_test.rb +8 -11
- data/test/integration/generated_utility_test.rb +81 -81
- data/test/integration/generated_warnlib_test.rb +17 -21
- data/test/integration/method_lookup_test.rb +6 -6
- data/test/introspection_test_helper.rb +49 -7
- data/test/minitest/stats_plugin.rb +1 -1
- metadata +21 -23
- data/lib/ffi-glib/array_methods.rb +0 -16
- data/test/gir_ffi/in_out_pointer_test.rb +0 -56
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::Builders::ConstructorBuilder do
|
6
|
-
describe
|
6
|
+
describe "#method_definition" do
|
7
7
|
let(:builder) { GirFFI::Builders::ConstructorBuilder.new function_info }
|
8
8
|
let(:code) { builder.method_definition }
|
9
9
|
|
10
|
-
describe
|
11
|
-
let(:function_info) { get_method_introspection_data
|
12
|
-
it
|
13
|
-
code.must_equal
|
10
|
+
describe "for constructors with the default name" do
|
11
|
+
let(:function_info) { get_method_introspection_data "Regress", "TestObj", "new" }
|
12
|
+
it "builds a constructor" do
|
13
|
+
_(code).must_equal <<~CODE
|
14
14
|
def self.new(*args, &block)
|
15
15
|
obj = allocate
|
16
16
|
obj.__send__ :initialize, *args, &block
|
@@ -20,10 +20,12 @@ describe GirFFI::Builders::ConstructorBuilder do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
24
|
-
let(:function_info)
|
25
|
-
|
26
|
-
|
23
|
+
describe "for constructors with a custom name" do
|
24
|
+
let(:function_info) do
|
25
|
+
get_method_introspection_data "Regress", "TestObj", "new_from_file"
|
26
|
+
end
|
27
|
+
it "builds a custom constructor" do
|
28
|
+
_(code).must_equal <<~CODE
|
27
29
|
def self.new_from_file(*args, &block)
|
28
30
|
raise NoMethodError unless self == Regress::TestObj
|
29
31
|
obj = allocate
|
@@ -1,22 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::Builders::EnumBuilder do
|
6
|
-
describe
|
7
|
-
|
8
|
-
|
9
|
-
end
|
6
|
+
describe "#build_class" do
|
7
|
+
let(:info) { get_introspection_data "Regress", "TestEnum" }
|
8
|
+
let(:builder) { GirFFI::Builders::EnumBuilder.new info }
|
10
9
|
|
11
|
-
it
|
12
|
-
info = get_introspection_data 'Regress', 'TestEnum'
|
13
|
-
builder = GirFFI::Builders::EnumBuilder.new info
|
10
|
+
it "makes the created type know its proper name" do
|
14
11
|
enum = builder.build_class
|
15
|
-
enum.inspect.must_equal
|
12
|
+
_(enum.inspect).must_equal "Regress::TestEnum"
|
16
13
|
end
|
17
14
|
|
18
|
-
|
19
|
-
|
15
|
+
it "adds constants for the values" do
|
16
|
+
enum = builder.build_class
|
17
|
+
_(enum::VALUE1).must_equal enum[:value1]
|
18
|
+
_(enum::VALUE2).must_equal enum[:value2]
|
19
|
+
_(enum::VALUE3).must_equal enum[:value3]
|
20
|
+
_(enum::VALUE4).must_equal enum[:value4]
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -1,40 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::Builders::FieldBuilder do
|
6
|
-
let(:target_class) {
|
6
|
+
let(:target_class) { "dummy" }
|
7
7
|
let(:instance) { GirFFI::Builders::FieldBuilder.new field_info, target_class }
|
8
8
|
|
9
|
-
describe
|
10
|
-
let(:field_info)
|
11
|
-
|
12
|
-
|
9
|
+
describe "for a field of type :gint8 with an offset" do
|
10
|
+
let(:field_info) do
|
11
|
+
get_field_introspection_data "Regress", "TestSimpleBoxedA", "some_int8"
|
12
|
+
end
|
13
|
+
it "creates the right getter method" do
|
14
|
+
expected = <<~CODE
|
13
15
|
def some_int8
|
14
16
|
_v1 = @struct.to_ptr
|
15
17
|
_v2 = _v1.get_int8(#{field_info.offset})
|
16
18
|
_v2
|
17
19
|
end
|
18
20
|
CODE
|
19
|
-
instance.getter_def.must_equal expected
|
21
|
+
_(instance.getter_def).must_equal expected
|
20
22
|
end
|
21
23
|
|
22
|
-
it
|
23
|
-
expected =
|
24
|
+
it "creates the right setter method" do
|
25
|
+
expected = <<~CODE
|
24
26
|
def some_int8= value
|
25
27
|
_v1 = @struct.to_ptr
|
26
28
|
_v2 = value
|
27
29
|
_v1.put_int8 #{field_info.offset}, _v2
|
28
30
|
end
|
29
31
|
CODE
|
30
|
-
instance.setter_def.must_equal expected
|
32
|
+
_(instance.setter_def).must_equal expected
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
describe
|
35
|
-
let(:field_info) { get_field_introspection_data
|
36
|
-
it
|
37
|
-
expected =
|
36
|
+
describe "for a field of type :struct" do
|
37
|
+
let(:field_info) { get_field_introspection_data "Regress", "TestBoxed", "nested_a" }
|
38
|
+
it "creates the right getter method" do
|
39
|
+
expected = <<~CODE
|
38
40
|
def nested_a
|
39
41
|
_v1 = @struct.to_ptr
|
40
42
|
_v2 = Regress::TestSimpleBoxedA.get_value_from_pointer(_v1, #{field_info.offset})
|
@@ -42,39 +44,39 @@ describe GirFFI::Builders::FieldBuilder do
|
|
42
44
|
_v3
|
43
45
|
end
|
44
46
|
CODE
|
45
|
-
instance.getter_def.must_equal expected
|
47
|
+
_(instance.getter_def).must_equal expected
|
46
48
|
end
|
47
49
|
|
48
|
-
it
|
49
|
-
expected =
|
50
|
+
it "creates the right setter method" do
|
51
|
+
expected = <<~CODE
|
50
52
|
def nested_a= value
|
51
53
|
_v1 = @struct.to_ptr
|
52
54
|
_v2 = Regress::TestSimpleBoxedA.copy_from(value)
|
53
55
|
Regress::TestSimpleBoxedA.copy_value_to_pointer(_v2, _v1, #{field_info.offset})
|
54
56
|
end
|
55
57
|
CODE
|
56
|
-
instance.setter_def.must_equal expected
|
58
|
+
_(instance.setter_def).must_equal expected
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
|
-
describe
|
61
|
-
let(:field_info) { get_field_introspection_data
|
62
|
-
it
|
63
|
-
expected =
|
62
|
+
describe "for a field of type :enum" do
|
63
|
+
let(:field_info) { get_field_introspection_data "Regress", "TestStructA", "some_enum" }
|
64
|
+
it "creates the right getter method" do
|
65
|
+
expected = <<~CODE
|
64
66
|
def some_enum
|
65
67
|
_v1 = @struct.to_ptr
|
66
68
|
_v2 = Regress::TestEnum.get_value_from_pointer(_v1, #{field_info.offset})
|
67
69
|
_v2
|
68
70
|
end
|
69
71
|
CODE
|
70
|
-
instance.getter_def.must_equal expected
|
72
|
+
_(instance.getter_def).must_equal expected
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
74
|
-
describe
|
75
|
-
let(:field_info) { get_field_introspection_data
|
76
|
-
it
|
77
|
-
expected =
|
76
|
+
describe "for an inline fixed-size array field" do
|
77
|
+
let(:field_info) { get_field_introspection_data "Regress", "TestStructE", "some_union" }
|
78
|
+
it "creates the right getter method" do
|
79
|
+
expected = <<~CODE
|
78
80
|
def some_union
|
79
81
|
_v1 = @struct.to_ptr
|
80
82
|
_v2 = GirFFI::SizedArray.get_value_from_pointer(_v1, #{field_info.offset})
|
@@ -82,11 +84,11 @@ describe GirFFI::Builders::FieldBuilder do
|
|
82
84
|
_v3
|
83
85
|
end
|
84
86
|
CODE
|
85
|
-
instance.getter_def.must_equal expected
|
87
|
+
_(instance.getter_def).must_equal expected
|
86
88
|
end
|
87
89
|
|
88
|
-
it
|
89
|
-
expected =
|
90
|
+
it "creates the right setter method" do
|
91
|
+
expected = <<~CODE
|
90
92
|
def some_union= value
|
91
93
|
_v1 = @struct.to_ptr
|
92
94
|
GirFFI::ArgHelper.check_fixed_array_size 2, value, \"value\"
|
@@ -94,31 +96,35 @@ describe GirFFI::Builders::FieldBuilder do
|
|
94
96
|
GirFFI::SizedArray.copy_value_to_pointer(_v2, _v1, #{field_info.offset})
|
95
97
|
end
|
96
98
|
CODE
|
97
|
-
instance.setter_def.must_equal expected
|
99
|
+
_(instance.setter_def).must_equal expected
|
98
100
|
end
|
99
101
|
end
|
100
102
|
|
101
|
-
describe
|
102
|
-
let(:field_info) { get_field_introspection_data
|
103
|
-
it
|
104
|
-
expected =
|
103
|
+
describe "for a field of type :callback" do
|
104
|
+
let(:field_info) { get_field_introspection_data "GObject", "TypeInfo", "class_init" }
|
105
|
+
it "creates the right setter method" do
|
106
|
+
expected = <<~CODE
|
105
107
|
def class_init= value
|
106
108
|
_v1 = @struct.to_ptr
|
107
109
|
_v2 = GObject::ClassInitFunc.from(value)
|
108
110
|
GObject::ClassInitFunc.copy_value_to_pointer(_v2, _v1, #{field_info.offset})
|
109
111
|
end
|
110
112
|
CODE
|
111
|
-
instance.setter_def.must_equal expected
|
113
|
+
_(instance.setter_def).must_equal expected
|
112
114
|
end
|
113
115
|
end
|
114
116
|
|
115
|
-
describe
|
116
|
-
let(:field_info)
|
117
|
-
|
117
|
+
describe "for a field with a related array length field" do
|
118
|
+
let(:field_info) do
|
119
|
+
get_field_introspection_data "GObject", "SignalQuery", "param_types"
|
120
|
+
end
|
121
|
+
let(:n_params_field_info) do
|
122
|
+
get_field_introspection_data "GObject", "SignalQuery", "n_params"
|
123
|
+
end
|
118
124
|
|
119
|
-
it
|
125
|
+
it "creates the right getter method" do
|
120
126
|
skip if field_info.field_type.array_length < 0
|
121
|
-
expected =
|
127
|
+
expected = <<~CODE
|
122
128
|
def param_types
|
123
129
|
_v1 = @struct.to_ptr
|
124
130
|
_v2 = _v1.get_uint32(#{n_params_field_info.offset})
|
@@ -128,7 +134,7 @@ describe GirFFI::Builders::FieldBuilder do
|
|
128
134
|
_v5
|
129
135
|
end
|
130
136
|
CODE
|
131
|
-
instance.getter_def.must_equal expected
|
137
|
+
_(instance.getter_def).must_equal expected
|
132
138
|
end
|
133
139
|
end
|
134
140
|
end
|
@@ -1,27 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::Builders::FunctionBuilder do
|
6
|
-
describe
|
6
|
+
describe "#method_definition" do
|
7
7
|
let(:builder) { GirFFI::Builders::FunctionBuilder.new function_info }
|
8
8
|
let(:code) { builder.method_definition }
|
9
9
|
|
10
|
-
describe
|
11
|
-
let(:function_info)
|
10
|
+
describe "generally" do
|
11
|
+
let(:function_info) do
|
12
|
+
get_method_introspection_data "GObject", "Object", "get_property"
|
13
|
+
end
|
12
14
|
|
13
|
-
it
|
15
|
+
it "returns the same result when called twice" do
|
14
16
|
original = builder.method_definition
|
15
17
|
copy = builder.method_definition
|
16
|
-
copy.must_equal original
|
18
|
+
_(copy).must_equal original
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
describe
|
21
|
-
let(:function_info)
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
describe "for Regress:test_array_fixed_out_objects" do
|
23
|
+
let(:function_info) do
|
24
|
+
get_introspection_data "Regress", "test_array_fixed_out_objects"
|
25
|
+
end
|
26
|
+
it "builds a correct definition" do
|
27
|
+
_(code).must_equal <<~CODE
|
25
28
|
def self.test_array_fixed_out_objects
|
26
29
|
_v1 = FFI::MemoryPointer.new :pointer
|
27
30
|
Regress::Lib.regress_test_array_fixed_out_objects _v1
|
@@ -32,10 +35,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
|
-
describe
|
36
|
-
let(:function_info) { get_introspection_data
|
37
|
-
it
|
38
|
-
code.must_equal
|
38
|
+
describe "for functions having a linked length argument" do
|
39
|
+
let(:function_info) { get_introspection_data "Regress", "test_array_gint16_in" }
|
40
|
+
it "builds a correct definition" do
|
41
|
+
_(code).must_equal <<~CODE
|
39
42
|
def self.test_array_gint16_in(ints)
|
40
43
|
n_ints = ints.nil? ? 0 : ints.length
|
41
44
|
_v1 = n_ints
|
@@ -47,11 +50,12 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
50
|
-
describe
|
51
|
-
let(:function_info)
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
describe "for methods taking a zero-terminated array with length argument" do
|
54
|
+
let(:function_info) do
|
55
|
+
get_method_introspection_data "Regress", "AnnotationObject", "parse_args"
|
56
|
+
end
|
57
|
+
it "builds a correct definition" do
|
58
|
+
_(code).must_equal <<~CODE
|
55
59
|
def parse_args(argv)
|
56
60
|
argc = argv.nil? ? 0 : argv.length
|
57
61
|
_v1 = FFI::MemoryPointer.new :int32
|
@@ -66,10 +70,12 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
69
|
-
describe
|
70
|
-
let(:function_info)
|
71
|
-
|
72
|
-
|
73
|
+
describe "for functions with callbacks" do
|
74
|
+
let(:function_info) do
|
75
|
+
get_introspection_data "Regress", "test_callback_destroy_notify"
|
76
|
+
end
|
77
|
+
it "builds a correct definition" do
|
78
|
+
_(code).must_equal <<~CODE
|
73
79
|
def self.test_callback_destroy_notify(&callback)
|
74
80
|
_v1 = Regress::TestCallbackUserData.from(callback)
|
75
81
|
_v2 = GirFFI::ArgHelper.store(_v1)
|
@@ -81,10 +87,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
84
|
-
describe
|
85
|
-
let(:function_info) { get_introspection_data
|
86
|
-
it
|
87
|
-
code.must_equal
|
90
|
+
describe "for functions that take a GValue" do
|
91
|
+
let(:function_info) { get_introspection_data "GIMarshallingTests", "gvalue_in" }
|
92
|
+
it "creates a call to GObject::Value#from" do
|
93
|
+
_(code).must_equal <<~CODE
|
88
94
|
def self.gvalue_in(value)
|
89
95
|
_v1 = GObject::Value.from(value)
|
90
96
|
GIMarshallingTests::Lib.gi_marshalling_tests_gvalue_in _v1
|
@@ -93,10 +99,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
93
99
|
end
|
94
100
|
end
|
95
101
|
|
96
|
-
describe
|
97
|
-
let(:function_info) { get_introspection_data
|
98
|
-
it
|
99
|
-
code.must_equal
|
102
|
+
describe "for functions that return a GValue" do
|
103
|
+
let(:function_info) { get_introspection_data "GIMarshallingTests", "gvalue_return" }
|
104
|
+
it "creates a call to #get_value" do
|
105
|
+
_(code).must_equal <<~CODE
|
100
106
|
def self.gvalue_return
|
101
107
|
_v1 = GIMarshallingTests::Lib.gi_marshalling_tests_gvalue_return
|
102
108
|
_v2 = GObject::Value.wrap(_v1).get_value
|
@@ -106,10 +112,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
106
112
|
end
|
107
113
|
end
|
108
114
|
|
109
|
-
describe
|
110
|
-
let(:function_info) { get_introspection_data
|
111
|
-
it
|
112
|
-
code.must_equal
|
115
|
+
describe "for functions that have a GValue out argument" do
|
116
|
+
let(:function_info) { get_introspection_data "GIMarshallingTests", "gvalue_out" }
|
117
|
+
it "creates a call to #get_value" do
|
118
|
+
_(code).must_equal <<~CODE
|
113
119
|
def self.gvalue_out
|
114
120
|
_v1 = FFI::MemoryPointer.new :pointer
|
115
121
|
GIMarshallingTests::Lib.gi_marshalling_tests_gvalue_out _v1
|
@@ -120,12 +126,13 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
120
126
|
end
|
121
127
|
end
|
122
128
|
|
123
|
-
describe
|
124
|
-
let(:function_info)
|
129
|
+
describe "for functions that have a caller-allocated GValue out argument" do
|
130
|
+
let(:function_info) do
|
131
|
+
get_introspection_data "GIMarshallingTests", "gvalue_out_caller_allocates"
|
132
|
+
end
|
125
133
|
|
126
|
-
it
|
127
|
-
|
128
|
-
code.must_equal <<-CODE.reset_indentation
|
134
|
+
it "creates a call to #get_value" do
|
135
|
+
_(code).must_equal <<~CODE
|
129
136
|
def self.gvalue_out_caller_allocates
|
130
137
|
_v1 = GObject::Value.new
|
131
138
|
GIMarshallingTests::Lib.gi_marshalling_tests_gvalue_out_caller_allocates _v1
|
@@ -136,10 +143,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
136
143
|
end
|
137
144
|
end
|
138
145
|
|
139
|
-
describe
|
140
|
-
let(:function_info) { get_introspection_data
|
141
|
-
it
|
142
|
-
code.must_equal
|
146
|
+
describe "for functions with a nullable input array" do
|
147
|
+
let(:function_info) { get_introspection_data "Regress", "test_array_int_null_in" }
|
148
|
+
it "builds correct definition" do
|
149
|
+
_(code).must_equal <<~CODE
|
143
150
|
def self.test_array_int_null_in(arr = nil)
|
144
151
|
len = arr.nil? ? 0 : arr.length
|
145
152
|
_v1 = len
|
@@ -150,10 +157,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
150
157
|
end
|
151
158
|
end
|
152
159
|
|
153
|
-
describe
|
154
|
-
let(:function_info) { get_introspection_data
|
155
|
-
it
|
156
|
-
code.must_equal
|
160
|
+
describe "for functions with a nullable output array" do
|
161
|
+
let(:function_info) { get_introspection_data "Regress", "test_array_int_null_out" }
|
162
|
+
it "builds correct definition" do
|
163
|
+
_(code).must_equal <<~CODE
|
157
164
|
def self.test_array_int_null_out
|
158
165
|
_v1 = FFI::MemoryPointer.new :int32
|
159
166
|
_v2 = FFI::MemoryPointer.new :pointer
|
@@ -166,10 +173,12 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
166
173
|
end
|
167
174
|
end
|
168
175
|
|
169
|
-
describe
|
170
|
-
let(:function_info)
|
171
|
-
|
172
|
-
|
176
|
+
describe "for a method with an inout array with size argument" do
|
177
|
+
let(:function_info) do
|
178
|
+
get_method_introspection_data "GIMarshallingTests", "Object", "method_array_inout"
|
179
|
+
end
|
180
|
+
it "builds the correct definition" do
|
181
|
+
_(code).must_equal <<~CODE
|
173
182
|
def method_array_inout(ints)
|
174
183
|
length = ints.nil? ? 0 : ints.length
|
175
184
|
_v1 = FFI::MemoryPointer.new :int32
|
@@ -185,11 +194,13 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
185
194
|
end
|
186
195
|
end
|
187
196
|
|
188
|
-
describe
|
189
|
-
let(:function_info)
|
197
|
+
describe "for a simple method" do
|
198
|
+
let(:function_info) do
|
199
|
+
get_method_introspection_data "Regress", "TestObj", "instance_method"
|
200
|
+
end
|
190
201
|
|
191
|
-
it
|
192
|
-
code.must_equal
|
202
|
+
it "builds a correct definition" do
|
203
|
+
_(code).must_equal <<~CODE
|
193
204
|
def instance_method
|
194
205
|
_v1 = Regress::Lib.regress_test_obj_instance_method self
|
195
206
|
return _v1
|
@@ -198,11 +209,11 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
198
209
|
end
|
199
210
|
end
|
200
211
|
|
201
|
-
describe
|
202
|
-
let(:function_info) { get_method_introspection_data
|
203
|
-
it
|
212
|
+
describe "for GLib::Variant.get_strv" do
|
213
|
+
let(:function_info) { get_method_introspection_data "GLib", "Variant", "get_strv" }
|
214
|
+
it "builds a correct definition" do
|
204
215
|
size_type = ":uint#{FFI.type_size(:size_t) * 8}"
|
205
|
-
code.must_equal
|
216
|
+
_(code).must_equal <<~CODE
|
206
217
|
def get_strv
|
207
218
|
_v1 = FFI::MemoryPointer.new #{size_type}
|
208
219
|
_v2 = GLib::Lib.g_variant_get_strv self, _v1
|
@@ -213,12 +224,11 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
213
224
|
end
|
214
225
|
end
|
215
226
|
|
216
|
-
describe
|
217
|
-
let(:function_info) { get_introspection_data
|
227
|
+
describe "for Regress.has_parameter_named_attrs" do
|
228
|
+
let(:function_info) { get_introspection_data "Regress", "has_parameter_named_attrs" }
|
218
229
|
|
219
|
-
it
|
220
|
-
|
221
|
-
code.must_equal <<-CODE.reset_indentation
|
230
|
+
it "builds a correct definition" do
|
231
|
+
_(code).must_equal <<~CODE
|
222
232
|
def self.has_parameter_named_attrs(foo, attributes)
|
223
233
|
_v1 = foo
|
224
234
|
GirFFI::ArgHelper.check_fixed_array_size 32, attributes, \"attributes\"
|
@@ -229,15 +239,14 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
229
239
|
end
|
230
240
|
end
|
231
241
|
|
232
|
-
describe
|
242
|
+
describe "for GIMarshallingTests::Object#method_int8_arg_and_out_callee" do
|
233
243
|
let(:function_info) do
|
234
|
-
get_method_introspection_data(
|
235
|
-
|
244
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
245
|
+
"method_int8_arg_and_out_callee")
|
236
246
|
end
|
237
247
|
|
238
|
-
it
|
239
|
-
|
240
|
-
code.must_equal <<-CODE.reset_indentation
|
248
|
+
it "builds a correct definition" do
|
249
|
+
_(code).must_equal <<~CODE
|
241
250
|
def method_int8_arg_and_out_callee(arg)
|
242
251
|
_v1 = arg
|
243
252
|
_v2 = FFI::MemoryPointer.new :pointer
|
@@ -249,237 +258,254 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
249
258
|
end
|
250
259
|
end
|
251
260
|
|
252
|
-
describe
|
253
|
-
describe
|
261
|
+
describe "object ownership transfer" do
|
262
|
+
describe "for GIMarshallingTests::Object#full_in" do
|
254
263
|
let(:function_info) do
|
255
|
-
get_method_introspection_data(
|
256
|
-
|
264
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
265
|
+
"full_in")
|
257
266
|
end
|
258
267
|
|
259
268
|
# NOTE: This method is transfer-ownership: none, despite the name.
|
260
|
-
it
|
261
|
-
code.must_equal
|
262
|
-
|
263
|
-
|
264
|
-
|
269
|
+
it "builds a correct definition" do
|
270
|
+
_(code).must_equal <<~CODE
|
271
|
+
def full_in
|
272
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_full_in self
|
273
|
+
end
|
265
274
|
CODE
|
266
275
|
end
|
267
276
|
end
|
268
277
|
|
269
|
-
describe
|
278
|
+
describe "for GIMarshallingTests::Object.full_inout" do
|
270
279
|
let(:function_info) do
|
271
|
-
get_method_introspection_data(
|
272
|
-
|
280
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
281
|
+
"full_inout")
|
273
282
|
end
|
274
283
|
|
275
|
-
it
|
276
|
-
code.must_equal
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
+
it "builds a correct definition" do
|
285
|
+
_(code).must_equal <<~CODE
|
286
|
+
def self.full_inout(object)
|
287
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
288
|
+
_v1.put_pointer 0, GIMarshallingTests::Object.from(object && object.ref)
|
289
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_full_inout _v1
|
290
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1.get_pointer(0))
|
291
|
+
return _v2
|
292
|
+
end
|
284
293
|
CODE
|
285
294
|
end
|
286
295
|
end
|
287
296
|
|
288
|
-
describe
|
297
|
+
describe "for GIMarshallingTests::Object.full_out" do
|
289
298
|
let(:function_info) do
|
290
|
-
get_method_introspection_data(
|
291
|
-
|
299
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
300
|
+
"full_out")
|
292
301
|
end
|
293
302
|
|
294
|
-
it
|
295
|
-
code.must_equal
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
303
|
+
it "builds a correct definition" do
|
304
|
+
_(code).must_equal <<~CODE
|
305
|
+
def self.full_out
|
306
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
307
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_full_out _v1
|
308
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1.get_pointer(0))
|
309
|
+
return _v2
|
310
|
+
end
|
302
311
|
CODE
|
303
312
|
end
|
304
313
|
end
|
305
314
|
|
306
|
-
describe
|
315
|
+
describe "for GIMarshallingTests::Object.full_return" do
|
307
316
|
let(:function_info) do
|
308
|
-
get_method_introspection_data(
|
309
|
-
|
317
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
318
|
+
"full_return")
|
310
319
|
end
|
311
320
|
|
312
|
-
it
|
313
|
-
code.must_equal
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
321
|
+
it "builds a correct definition" do
|
322
|
+
_(code).must_equal <<~CODE
|
323
|
+
def self.full_return
|
324
|
+
_v1 = GIMarshallingTests::Lib.gi_marshalling_tests_object_full_return
|
325
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1)
|
326
|
+
return _v2
|
327
|
+
end
|
319
328
|
CODE
|
320
329
|
end
|
321
330
|
end
|
322
331
|
|
323
|
-
describe
|
332
|
+
describe "for GIMarshallingTests::Object#none_in" do
|
324
333
|
let(:function_info) do
|
325
|
-
get_method_introspection_data(
|
326
|
-
|
334
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
335
|
+
"none_in")
|
327
336
|
end
|
328
337
|
|
329
|
-
it
|
330
|
-
code.must_equal
|
331
|
-
|
332
|
-
|
333
|
-
|
338
|
+
it "builds a correct definition" do
|
339
|
+
_(code).must_equal <<~CODE
|
340
|
+
def none_in
|
341
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_none_in self
|
342
|
+
end
|
334
343
|
CODE
|
335
344
|
end
|
336
345
|
end
|
337
346
|
|
338
|
-
describe
|
347
|
+
describe "for GIMarshallingTests::Object.none_inout" do
|
339
348
|
let(:function_info) do
|
340
|
-
get_method_introspection_data(
|
341
|
-
|
349
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
350
|
+
"none_inout")
|
342
351
|
end
|
343
352
|
|
344
|
-
it
|
345
|
-
code.must_equal
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
+
it "builds a correct definition" do
|
354
|
+
_(code).must_equal <<~CODE
|
355
|
+
def self.none_inout(object)
|
356
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
357
|
+
_v1.put_pointer 0, GIMarshallingTests::Object.from(object)
|
358
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_none_inout _v1
|
359
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1.get_pointer(0)).tap { |it| it && it.ref }
|
360
|
+
return _v2
|
361
|
+
end
|
353
362
|
CODE
|
354
363
|
end
|
355
364
|
end
|
356
365
|
|
357
|
-
describe
|
366
|
+
describe "for GIMarshallingTests::Object.none_out" do
|
358
367
|
let(:function_info) do
|
359
|
-
get_method_introspection_data(
|
360
|
-
|
368
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
369
|
+
"none_out")
|
361
370
|
end
|
362
371
|
|
363
|
-
it
|
364
|
-
code.must_equal
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
372
|
+
it "builds a correct definition" do
|
373
|
+
_(code).must_equal <<~CODE
|
374
|
+
def self.none_out
|
375
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
376
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_none_out _v1
|
377
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1.get_pointer(0)).tap { |it| it && it.ref }
|
378
|
+
return _v2
|
379
|
+
end
|
371
380
|
CODE
|
372
381
|
end
|
373
382
|
end
|
374
383
|
|
375
|
-
describe
|
384
|
+
describe "for GIMarshallingTests::Object.none_return" do
|
376
385
|
let(:function_info) do
|
377
|
-
get_method_introspection_data(
|
378
|
-
|
386
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
387
|
+
"none_return")
|
379
388
|
end
|
380
389
|
|
381
|
-
it
|
382
|
-
code.must_equal
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
390
|
+
it "builds a correct definition" do
|
391
|
+
_(code).must_equal <<~CODE
|
392
|
+
def self.none_return
|
393
|
+
_v1 = GIMarshallingTests::Lib.gi_marshalling_tests_object_none_return
|
394
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1).tap { |it| it && it.ref }
|
395
|
+
return _v2
|
396
|
+
end
|
388
397
|
CODE
|
389
398
|
end
|
390
399
|
end
|
391
400
|
|
392
|
-
describe
|
401
|
+
describe "for Regress::TestObj#instance_method_full" do
|
393
402
|
let(:function_info) do
|
394
|
-
get_method_introspection_data(
|
395
|
-
|
403
|
+
get_method_introspection_data("Regress", "TestObj",
|
404
|
+
"instance_method_full")
|
396
405
|
end
|
397
406
|
|
398
|
-
it
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
end
|
407
|
+
it "builds a correct definition including self.ref" do
|
408
|
+
_(code).must_equal <<~CODE
|
409
|
+
def instance_method_full
|
410
|
+
Regress::Lib.regress_test_obj_instance_method_full self.ref
|
411
|
+
end
|
404
412
|
CODE
|
405
413
|
end
|
406
414
|
end
|
407
415
|
end
|
408
416
|
|
409
|
-
describe
|
410
|
-
describe
|
417
|
+
describe "struct ownership transfer" do
|
418
|
+
describe "for Regress::FooRectangle#add" do
|
411
419
|
let(:function_info) do
|
412
|
-
get_method_introspection_data(
|
420
|
+
get_method_introspection_data("Regress", "FooRectangle",
|
421
|
+
"add")
|
413
422
|
end
|
414
423
|
|
415
|
-
it
|
416
|
-
code.must_equal
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
_v2 = GIMarshallingTests::BoxedStruct.wrap_own(_v1.get_pointer(0))
|
422
|
-
return _v2
|
423
|
-
end
|
424
|
+
it "builds a correct definition without #ref" do
|
425
|
+
_(code).must_equal <<~CODE
|
426
|
+
def add(r2)
|
427
|
+
_v1 = Regress::FooRectangle.from(r2)
|
428
|
+
Regress::Lib.regress_foo_rectangle_add self, _v1
|
429
|
+
end
|
424
430
|
CODE
|
425
431
|
end
|
426
432
|
end
|
433
|
+
end
|
427
434
|
|
428
|
-
|
435
|
+
describe "boxed struct ownership transfer" do
|
436
|
+
describe "for GIMarshallingTests::BoxedStruct.inout" do
|
429
437
|
let(:function_info) do
|
430
|
-
get_method_introspection_data(
|
438
|
+
get_method_introspection_data("GIMarshallingTests", "BoxedStruct", "inout")
|
431
439
|
end
|
432
440
|
|
433
|
-
it
|
434
|
-
code.must_equal
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
+
it "builds a correct definition" do
|
442
|
+
_(code).must_equal <<~CODE
|
443
|
+
def self.inout(struct_)
|
444
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
445
|
+
_v1.put_pointer 0, GIMarshallingTests::BoxedStruct.copy_from(struct_)
|
446
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_boxed_struct_inout _v1
|
447
|
+
_v2 = GIMarshallingTests::BoxedStruct.wrap_own(_v1.get_pointer(0))
|
448
|
+
return _v2
|
449
|
+
end
|
441
450
|
CODE
|
442
451
|
end
|
443
452
|
end
|
444
453
|
|
445
|
-
describe
|
454
|
+
describe "for GIMarshallingTests::BoxedStruct.out" do
|
446
455
|
let(:function_info) do
|
447
|
-
get_method_introspection_data(
|
456
|
+
get_method_introspection_data("GIMarshallingTests", "BoxedStruct", "out")
|
448
457
|
end
|
449
458
|
|
450
|
-
it
|
451
|
-
code.must_equal
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
459
|
+
it "builds a correct definition" do
|
460
|
+
_(code).must_equal <<~CODE
|
461
|
+
def self.out
|
462
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
463
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_boxed_struct_out _v1
|
464
|
+
_v2 = GIMarshallingTests::BoxedStruct.wrap_copy(_v1.get_pointer(0))
|
465
|
+
return _v2
|
466
|
+
end
|
457
467
|
CODE
|
458
468
|
end
|
459
469
|
end
|
460
|
-
end
|
461
470
|
|
462
|
-
|
463
|
-
|
464
|
-
|
471
|
+
describe "for GIMarshallingTests::BoxedStruct.returnv" do
|
472
|
+
let(:function_info) do
|
473
|
+
get_method_introspection_data("GIMarshallingTests", "BoxedStruct", "returnv")
|
474
|
+
end
|
465
475
|
|
466
|
-
it
|
467
|
-
code.must_equal
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
476
|
+
it "builds a correct definition" do
|
477
|
+
_(code).must_equal <<~CODE
|
478
|
+
def self.returnv
|
479
|
+
_v1 = GIMarshallingTests::Lib.gi_marshalling_tests_boxed_struct_returnv
|
480
|
+
_v2 = GIMarshallingTests::BoxedStruct.wrap_copy(_v1)
|
481
|
+
return _v2
|
482
|
+
end
|
483
|
+
CODE
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
describe "string ownership transfer" do
|
489
|
+
describe "for Regress.test_utf8_out" do
|
490
|
+
let(:function_info) { get_introspection_data "Regress", "test_utf8_out" }
|
491
|
+
|
492
|
+
it "builds a correct definition" do
|
493
|
+
_(code).must_equal <<~CODE
|
494
|
+
def self.test_utf8_out
|
495
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
496
|
+
Regress::Lib.regress_test_utf8_out _v1
|
497
|
+
_v2 = GirFFI::AllocationHelper.free_after _v1.get_pointer(0), &:to_utf8
|
498
|
+
return _v2
|
499
|
+
end
|
474
500
|
CODE
|
475
501
|
end
|
476
502
|
end
|
477
503
|
end
|
478
504
|
|
479
|
-
describe
|
480
|
-
let(:function_info) { get_introspection_data
|
481
|
-
it
|
482
|
-
code.must_equal
|
505
|
+
describe "for functions with an allow-none ingoing parameter" do
|
506
|
+
let(:function_info) { get_introspection_data "Regress", "test_utf8_null_in" }
|
507
|
+
it "builds correct definition with default parameter value" do
|
508
|
+
_(code).must_equal <<~CODE
|
483
509
|
def self.test_utf8_null_in(in_ = nil)
|
484
510
|
_v1 = GirFFI::InPointer.from_utf8(in_)
|
485
511
|
Regress::Lib.regress_test_utf8_null_in _v1
|
@@ -488,10 +514,12 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
488
514
|
end
|
489
515
|
end
|
490
516
|
|
491
|
-
describe
|
492
|
-
let(:function_info)
|
493
|
-
|
494
|
-
|
517
|
+
describe "for functions where some allow-none cannot be honored" do
|
518
|
+
let(:function_info) do
|
519
|
+
get_introspection_data "GIMarshallingTests", "array_in_utf8_two_in_out_of_order"
|
520
|
+
end
|
521
|
+
it "builds correct definition with default parameter value on the later arguments" do
|
522
|
+
_(code).must_equal <<~CODE
|
495
523
|
def self.array_in_utf8_two_in_out_of_order(a, ints, b = nil)
|
496
524
|
length = ints.nil? ? 0 : ints.length
|
497
525
|
_v1 = length
|
@@ -504,12 +532,14 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
504
532
|
end
|
505
533
|
end
|
506
534
|
|
507
|
-
describe
|
508
|
-
describe
|
509
|
-
let(:function_info)
|
535
|
+
describe "ownership transfer for an ingoing array of structs" do
|
536
|
+
describe "with no ownership transfer of the elements" do
|
537
|
+
let(:function_info) do
|
538
|
+
get_introspection_data "GIMarshallingTests", "array_struct_in"
|
539
|
+
end
|
510
540
|
|
511
|
-
it
|
512
|
-
code.must_equal
|
541
|
+
it "builds a correct definition" do
|
542
|
+
_(code).must_equal <<~CODE
|
513
543
|
def self.array_struct_in(structs)
|
514
544
|
length = structs.nil? ? 0 : structs.length
|
515
545
|
_v1 = length
|
@@ -519,11 +549,13 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
519
549
|
CODE
|
520
550
|
end
|
521
551
|
end
|
522
|
-
describe
|
523
|
-
let(:function_info)
|
552
|
+
describe "with ownership transfer of the elements" do
|
553
|
+
let(:function_info) do
|
554
|
+
get_introspection_data "GIMarshallingTests", "array_struct_take_in"
|
555
|
+
end
|
524
556
|
|
525
|
-
it
|
526
|
-
code.must_equal
|
557
|
+
it "builds a correct definition" do
|
558
|
+
_(code).must_equal <<~CODE
|
527
559
|
def self.array_struct_take_in(structs)
|
528
560
|
length = structs.nil? ? 0 : structs.length
|
529
561
|
_v1 = length
|