gir_ffi 0.14.1 → 0.15.0
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 +21 -0
- data/Gemfile +6 -4
- data/README.md +4 -4
- data/Rakefile +5 -5
- 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-glib.rb +16 -16
- 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 +37 -28
- data/lib/ffi-gobject.rb +13 -13
- 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/ffi-gobject_introspection.rb +20 -20
- 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/builders/argument_builder.rb +17 -17
- 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 +3 -3
- 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 +2 -2
- data/lib/gir_ffi/builders/field_builder.rb +16 -15
- 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 +4 -6
- 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 +4 -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 +6 -6
- data/lib/gir_ffi/builders/with_layout.rb +2 -2
- data/lib/gir_ffi/callback_base.rb +1 -1
- data/lib/gir_ffi/class_base.rb +5 -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/pointer.rb +1 -1
- data/lib/gir_ffi/ffi_ext.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/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 +2 -2
- 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/info_ext.rb +15 -15
- 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 +1 -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/lib/gir_ffi-base/gobject/lib.rb +3 -2
- data/lib/gir_ffi-base/gobject.rb +26 -25
- data/lib/gir_ffi-base.rb +1 -1
- data/lib/gir_ffi.rb +3 -3
- 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 +49 -67
- 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 +8 -8
- 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 +31 -31
- 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 +44 -44
- data/test/gir_ffi/allocation_helper_test.rb +13 -13
- data/test/gir_ffi/arg_helper_test.rb +63 -64
- 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 +115 -93
- data/test/gir_ffi/builders/argument_builder_test.rb +280 -286
- data/test/gir_ffi/builders/base_argument_builder_test.rb +1 -1
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +53 -56
- data/test/gir_ffi/builders/callback_builder_test.rb +71 -72
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +36 -40
- data/test/gir_ffi/builders/constant_builder_test.rb +1 -1
- data/test/gir_ffi/builders/constructor_builder_test.rb +10 -10
- data/test/gir_ffi/builders/enum_builder_test.rb +10 -10
- data/test/gir_ffi/builders/field_builder_test.rb +42 -42
- data/test/gir_ffi/builders/function_builder_test.rb +236 -224
- data/test/gir_ffi/builders/initializer_builder_test.rb +14 -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 +38 -38
- data/test/gir_ffi/builders/property_builder_test.rb +91 -94
- data/test/gir_ffi/builders/registered_type_builder_test.rb +35 -11
- data/test/gir_ffi/builders/return_value_builder_test.rb +215 -222
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +122 -113
- data/test/gir_ffi/builders/struct_builder_test.rb +32 -32
- data/test/gir_ffi/builders/unintrospectable_boxed_builder_test.rb +8 -14
- data/test/gir_ffi/builders/unintrospectable_builder_test.rb +23 -23
- data/test/gir_ffi/builders/union_builder_test.rb +12 -15
- data/test/gir_ffi/builders/user_defined_builder_test.rb +147 -147
- data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +40 -40
- data/test/gir_ffi/builders/vfunc_builder_test.rb +145 -157
- data/test/gir_ffi/callback_base_test.rb +9 -9
- data/test/gir_ffi/class_base_test.rb +49 -51
- data/test/gir_ffi/core_test.rb +32 -32
- 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 +5 -5
- 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 +4 -4
- 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 +229 -215
- 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 +19 -19
- data/test/gir_ffi/object_base_test.rb +19 -19
- 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 +6 -6
- 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 +13 -13
- data/test/integration/generated_everything_test.rb +224 -224
- data/test/integration/generated_gimarshallingtests_test.rb +1118 -1017
- 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 +16 -16
- data/test/integration/generated_gtk_source_test.rb +22 -17
- 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 +1809 -1621
- 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 +13 -19
- data/test/integration/method_lookup_test.rb +6 -6
- data/test/introspection_test_helper.rb +48 -7
- data/test/minitest/stats_plugin.rb +1 -1
- metadata +11 -28
- 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,10 @@ describe GirFFI::Builders::ConstructorBuilder do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
24
|
-
let(:function_info) { get_method_introspection_data
|
25
|
-
it
|
26
|
-
code.must_equal
|
23
|
+
describe "for constructors with a custom name" do
|
24
|
+
let(:function_info) { get_method_introspection_data "Regress", "TestObj", "new_from_file" }
|
25
|
+
it "builds a custom constructor" do
|
26
|
+
_(code).must_equal <<~CODE
|
27
27
|
def self.new_from_file(*args, &block)
|
28
28
|
raise NoMethodError unless self == Regress::TestObj
|
29
29
|
obj = allocate
|
@@ -1,23 +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
|
-
let(:info) { get_introspection_data
|
6
|
+
describe "#build_class" do
|
7
|
+
let(:info) { get_introspection_data "Regress", "TestEnum" }
|
8
8
|
let(:builder) { GirFFI::Builders::EnumBuilder.new info }
|
9
9
|
|
10
|
-
it
|
10
|
+
it "makes the created type know its proper name" do
|
11
11
|
enum = builder.build_class
|
12
|
-
enum.inspect.must_equal
|
12
|
+
_(enum.inspect).must_equal "Regress::TestEnum"
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it "adds constants for the values" do
|
16
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]
|
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]
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -1,40 +1,40 @@
|
|
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) { get_field_introspection_data
|
11
|
-
it
|
12
|
-
expected =
|
9
|
+
describe "for a field of type :gint8 with an offset" do
|
10
|
+
let(:field_info) { get_field_introspection_data "Regress", "TestSimpleBoxedA", "some_int8" }
|
11
|
+
it "creates the right getter method" do
|
12
|
+
expected = <<~CODE
|
13
13
|
def some_int8
|
14
14
|
_v1 = @struct.to_ptr
|
15
15
|
_v2 = _v1.get_int8(#{field_info.offset})
|
16
16
|
_v2
|
17
17
|
end
|
18
18
|
CODE
|
19
|
-
instance.getter_def.must_equal expected
|
19
|
+
_(instance.getter_def).must_equal expected
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
expected =
|
22
|
+
it "creates the right setter method" do
|
23
|
+
expected = <<~CODE
|
24
24
|
def some_int8= value
|
25
25
|
_v1 = @struct.to_ptr
|
26
26
|
_v2 = value
|
27
27
|
_v1.put_int8 #{field_info.offset}, _v2
|
28
28
|
end
|
29
29
|
CODE
|
30
|
-
instance.setter_def.must_equal expected
|
30
|
+
_(instance.setter_def).must_equal expected
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
35
|
-
let(:field_info) { get_field_introspection_data
|
36
|
-
it
|
37
|
-
expected =
|
34
|
+
describe "for a field of type :struct" do
|
35
|
+
let(:field_info) { get_field_introspection_data "Regress", "TestBoxed", "nested_a" }
|
36
|
+
it "creates the right getter method" do
|
37
|
+
expected = <<~CODE
|
38
38
|
def nested_a
|
39
39
|
_v1 = @struct.to_ptr
|
40
40
|
_v2 = Regress::TestSimpleBoxedA.get_value_from_pointer(_v1, #{field_info.offset})
|
@@ -42,39 +42,39 @@ describe GirFFI::Builders::FieldBuilder do
|
|
42
42
|
_v3
|
43
43
|
end
|
44
44
|
CODE
|
45
|
-
instance.getter_def.must_equal expected
|
45
|
+
_(instance.getter_def).must_equal expected
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
49
|
-
expected =
|
48
|
+
it "creates the right setter method" do
|
49
|
+
expected = <<~CODE
|
50
50
|
def nested_a= value
|
51
51
|
_v1 = @struct.to_ptr
|
52
52
|
_v2 = Regress::TestSimpleBoxedA.copy_from(value)
|
53
53
|
Regress::TestSimpleBoxedA.copy_value_to_pointer(_v2, _v1, #{field_info.offset})
|
54
54
|
end
|
55
55
|
CODE
|
56
|
-
instance.setter_def.must_equal expected
|
56
|
+
_(instance.setter_def).must_equal expected
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
describe
|
61
|
-
let(:field_info) { get_field_introspection_data
|
62
|
-
it
|
63
|
-
expected =
|
60
|
+
describe "for a field of type :enum" do
|
61
|
+
let(:field_info) { get_field_introspection_data "Regress", "TestStructA", "some_enum" }
|
62
|
+
it "creates the right getter method" do
|
63
|
+
expected = <<~CODE
|
64
64
|
def some_enum
|
65
65
|
_v1 = @struct.to_ptr
|
66
66
|
_v2 = Regress::TestEnum.get_value_from_pointer(_v1, #{field_info.offset})
|
67
67
|
_v2
|
68
68
|
end
|
69
69
|
CODE
|
70
|
-
instance.getter_def.must_equal expected
|
70
|
+
_(instance.getter_def).must_equal expected
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
describe
|
75
|
-
let(:field_info) { get_field_introspection_data
|
76
|
-
it
|
77
|
-
expected =
|
74
|
+
describe "for an inline fixed-size array field" do
|
75
|
+
let(:field_info) { get_field_introspection_data "Regress", "TestStructE", "some_union" }
|
76
|
+
it "creates the right getter method" do
|
77
|
+
expected = <<~CODE
|
78
78
|
def some_union
|
79
79
|
_v1 = @struct.to_ptr
|
80
80
|
_v2 = GirFFI::SizedArray.get_value_from_pointer(_v1, #{field_info.offset})
|
@@ -82,11 +82,11 @@ describe GirFFI::Builders::FieldBuilder do
|
|
82
82
|
_v3
|
83
83
|
end
|
84
84
|
CODE
|
85
|
-
instance.getter_def.must_equal expected
|
85
|
+
_(instance.getter_def).must_equal expected
|
86
86
|
end
|
87
87
|
|
88
|
-
it
|
89
|
-
expected =
|
88
|
+
it "creates the right setter method" do
|
89
|
+
expected = <<~CODE
|
90
90
|
def some_union= value
|
91
91
|
_v1 = @struct.to_ptr
|
92
92
|
GirFFI::ArgHelper.check_fixed_array_size 2, value, \"value\"
|
@@ -94,31 +94,31 @@ describe GirFFI::Builders::FieldBuilder do
|
|
94
94
|
GirFFI::SizedArray.copy_value_to_pointer(_v2, _v1, #{field_info.offset})
|
95
95
|
end
|
96
96
|
CODE
|
97
|
-
instance.setter_def.must_equal expected
|
97
|
+
_(instance.setter_def).must_equal expected
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
describe
|
102
|
-
let(:field_info) { get_field_introspection_data
|
103
|
-
it
|
104
|
-
expected =
|
101
|
+
describe "for a field of type :callback" do
|
102
|
+
let(:field_info) { get_field_introspection_data "GObject", "TypeInfo", "class_init" }
|
103
|
+
it "creates the right setter method" do
|
104
|
+
expected = <<~CODE
|
105
105
|
def class_init= value
|
106
106
|
_v1 = @struct.to_ptr
|
107
107
|
_v2 = GObject::ClassInitFunc.from(value)
|
108
108
|
GObject::ClassInitFunc.copy_value_to_pointer(_v2, _v1, #{field_info.offset})
|
109
109
|
end
|
110
110
|
CODE
|
111
|
-
instance.setter_def.must_equal expected
|
111
|
+
_(instance.setter_def).must_equal expected
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
describe
|
116
|
-
let(:field_info) { get_field_introspection_data
|
117
|
-
let(:n_params_field_info) { get_field_introspection_data
|
115
|
+
describe "for a field with a related array length field" do
|
116
|
+
let(:field_info) { get_field_introspection_data "GObject", "SignalQuery", "param_types" }
|
117
|
+
let(:n_params_field_info) { get_field_introspection_data "GObject", "SignalQuery", "n_params" }
|
118
118
|
|
119
|
-
it
|
119
|
+
it "creates the right getter method" do
|
120
120
|
skip if field_info.field_type.array_length < 0
|
121
|
-
expected =
|
121
|
+
expected = <<~CODE
|
122
122
|
def param_types
|
123
123
|
_v1 = @struct.to_ptr
|
124
124
|
_v2 = _v1.get_uint32(#{n_params_field_info.offset})
|
@@ -128,7 +128,7 @@ describe GirFFI::Builders::FieldBuilder do
|
|
128
128
|
_v5
|
129
129
|
end
|
130
130
|
CODE
|
131
|
-
instance.getter_def.must_equal expected
|
131
|
+
_(instance.getter_def).must_equal expected
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
@@ -1,27 +1,26 @@
|
|
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) { get_method_introspection_data
|
10
|
+
describe "generally" do
|
11
|
+
let(:function_info) { get_method_introspection_data "GObject", "Object", "get_property" }
|
12
12
|
|
13
|
-
it
|
13
|
+
it "returns the same result when called twice" do
|
14
14
|
original = builder.method_definition
|
15
15
|
copy = builder.method_definition
|
16
|
-
copy.must_equal original
|
16
|
+
_(copy).must_equal original
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
describe
|
21
|
-
let(:function_info) { get_introspection_data
|
22
|
-
it
|
23
|
-
|
24
|
-
code.must_equal <<-CODE.reset_indentation
|
20
|
+
describe "for Regress:test_array_fixed_out_objects" do
|
21
|
+
let(:function_info) { get_introspection_data "Regress", "test_array_fixed_out_objects" }
|
22
|
+
it "builds a correct definition" do
|
23
|
+
_(code).must_equal <<~CODE
|
25
24
|
def self.test_array_fixed_out_objects
|
26
25
|
_v1 = FFI::MemoryPointer.new :pointer
|
27
26
|
Regress::Lib.regress_test_array_fixed_out_objects _v1
|
@@ -32,10 +31,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
describe
|
36
|
-
let(:function_info) { get_introspection_data
|
37
|
-
it
|
38
|
-
code.must_equal
|
34
|
+
describe "for functions having a linked length argument" do
|
35
|
+
let(:function_info) { get_introspection_data "Regress", "test_array_gint16_in" }
|
36
|
+
it "builds a correct definition" do
|
37
|
+
_(code).must_equal <<~CODE
|
39
38
|
def self.test_array_gint16_in(ints)
|
40
39
|
n_ints = ints.nil? ? 0 : ints.length
|
41
40
|
_v1 = n_ints
|
@@ -47,11 +46,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
describe
|
51
|
-
let(:function_info) { get_method_introspection_data
|
52
|
-
it
|
53
|
-
|
54
|
-
code.must_equal <<-CODE.reset_indentation
|
49
|
+
describe "for methods taking a zero-terminated array with length argument" do
|
50
|
+
let(:function_info) { get_method_introspection_data "Regress", "AnnotationObject", "parse_args" }
|
51
|
+
it "builds a correct definition" do
|
52
|
+
_(code).must_equal <<~CODE
|
55
53
|
def parse_args(argv)
|
56
54
|
argc = argv.nil? ? 0 : argv.length
|
57
55
|
_v1 = FFI::MemoryPointer.new :int32
|
@@ -66,10 +64,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
66
64
|
end
|
67
65
|
end
|
68
66
|
|
69
|
-
describe
|
70
|
-
let(:function_info) { get_introspection_data
|
71
|
-
it
|
72
|
-
code.must_equal
|
67
|
+
describe "for functions with callbacks" do
|
68
|
+
let(:function_info) { get_introspection_data "Regress", "test_callback_destroy_notify" }
|
69
|
+
it "builds a correct definition" do
|
70
|
+
_(code).must_equal <<~CODE
|
73
71
|
def self.test_callback_destroy_notify(&callback)
|
74
72
|
_v1 = Regress::TestCallbackUserData.from(callback)
|
75
73
|
_v2 = GirFFI::ArgHelper.store(_v1)
|
@@ -81,10 +79,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
81
79
|
end
|
82
80
|
end
|
83
81
|
|
84
|
-
describe
|
85
|
-
let(:function_info) { get_introspection_data
|
86
|
-
it
|
87
|
-
code.must_equal
|
82
|
+
describe "for functions that take a GValue" do
|
83
|
+
let(:function_info) { get_introspection_data "GIMarshallingTests", "gvalue_in" }
|
84
|
+
it "creates a call to GObject::Value#from" do
|
85
|
+
_(code).must_equal <<~CODE
|
88
86
|
def self.gvalue_in(value)
|
89
87
|
_v1 = GObject::Value.from(value)
|
90
88
|
GIMarshallingTests::Lib.gi_marshalling_tests_gvalue_in _v1
|
@@ -93,10 +91,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
93
91
|
end
|
94
92
|
end
|
95
93
|
|
96
|
-
describe
|
97
|
-
let(:function_info) { get_introspection_data
|
98
|
-
it
|
99
|
-
code.must_equal
|
94
|
+
describe "for functions that return a GValue" do
|
95
|
+
let(:function_info) { get_introspection_data "GIMarshallingTests", "gvalue_return" }
|
96
|
+
it "creates a call to #get_value" do
|
97
|
+
_(code).must_equal <<~CODE
|
100
98
|
def self.gvalue_return
|
101
99
|
_v1 = GIMarshallingTests::Lib.gi_marshalling_tests_gvalue_return
|
102
100
|
_v2 = GObject::Value.wrap(_v1).get_value
|
@@ -106,10 +104,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
106
104
|
end
|
107
105
|
end
|
108
106
|
|
109
|
-
describe
|
110
|
-
let(:function_info) { get_introspection_data
|
111
|
-
it
|
112
|
-
code.must_equal
|
107
|
+
describe "for functions that have a GValue out argument" do
|
108
|
+
let(:function_info) { get_introspection_data "GIMarshallingTests", "gvalue_out" }
|
109
|
+
it "creates a call to #get_value" do
|
110
|
+
_(code).must_equal <<~CODE
|
113
111
|
def self.gvalue_out
|
114
112
|
_v1 = FFI::MemoryPointer.new :pointer
|
115
113
|
GIMarshallingTests::Lib.gi_marshalling_tests_gvalue_out _v1
|
@@ -120,12 +118,11 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
120
118
|
end
|
121
119
|
end
|
122
120
|
|
123
|
-
describe
|
124
|
-
let(:function_info) { get_introspection_data
|
121
|
+
describe "for functions that have a caller-allocated GValue out argument" do
|
122
|
+
let(:function_info) { get_introspection_data "GIMarshallingTests", "gvalue_out_caller_allocates" }
|
125
123
|
|
126
|
-
it
|
127
|
-
|
128
|
-
code.must_equal <<-CODE.reset_indentation
|
124
|
+
it "creates a call to #get_value" do
|
125
|
+
_(code).must_equal <<~CODE
|
129
126
|
def self.gvalue_out_caller_allocates
|
130
127
|
_v1 = GObject::Value.new
|
131
128
|
GIMarshallingTests::Lib.gi_marshalling_tests_gvalue_out_caller_allocates _v1
|
@@ -136,10 +133,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
136
133
|
end
|
137
134
|
end
|
138
135
|
|
139
|
-
describe
|
140
|
-
let(:function_info) { get_introspection_data
|
141
|
-
it
|
142
|
-
code.must_equal
|
136
|
+
describe "for functions with a nullable input array" do
|
137
|
+
let(:function_info) { get_introspection_data "Regress", "test_array_int_null_in" }
|
138
|
+
it "builds correct definition" do
|
139
|
+
_(code).must_equal <<~CODE
|
143
140
|
def self.test_array_int_null_in(arr = nil)
|
144
141
|
len = arr.nil? ? 0 : arr.length
|
145
142
|
_v1 = len
|
@@ -150,10 +147,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
150
147
|
end
|
151
148
|
end
|
152
149
|
|
153
|
-
describe
|
154
|
-
let(:function_info) { get_introspection_data
|
155
|
-
it
|
156
|
-
code.must_equal
|
150
|
+
describe "for functions with a nullable output array" do
|
151
|
+
let(:function_info) { get_introspection_data "Regress", "test_array_int_null_out" }
|
152
|
+
it "builds correct definition" do
|
153
|
+
_(code).must_equal <<~CODE
|
157
154
|
def self.test_array_int_null_out
|
158
155
|
_v1 = FFI::MemoryPointer.new :int32
|
159
156
|
_v2 = FFI::MemoryPointer.new :pointer
|
@@ -166,10 +163,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
166
163
|
end
|
167
164
|
end
|
168
165
|
|
169
|
-
describe
|
170
|
-
let(:function_info) { get_method_introspection_data
|
171
|
-
it
|
172
|
-
code.must_equal
|
166
|
+
describe "for a method with an inout array with size argument" do
|
167
|
+
let(:function_info) { get_method_introspection_data "GIMarshallingTests", "Object", "method_array_inout" }
|
168
|
+
it "builds the correct definition" do
|
169
|
+
_(code).must_equal <<~CODE
|
173
170
|
def method_array_inout(ints)
|
174
171
|
length = ints.nil? ? 0 : ints.length
|
175
172
|
_v1 = FFI::MemoryPointer.new :int32
|
@@ -185,11 +182,11 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
185
182
|
end
|
186
183
|
end
|
187
184
|
|
188
|
-
describe
|
189
|
-
let(:function_info) { get_method_introspection_data
|
185
|
+
describe "for a simple method" do
|
186
|
+
let(:function_info) { get_method_introspection_data "Regress", "TestObj", "instance_method" }
|
190
187
|
|
191
|
-
it
|
192
|
-
code.must_equal
|
188
|
+
it "builds a correct definition" do
|
189
|
+
_(code).must_equal <<~CODE
|
193
190
|
def instance_method
|
194
191
|
_v1 = Regress::Lib.regress_test_obj_instance_method self
|
195
192
|
return _v1
|
@@ -198,11 +195,11 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
198
195
|
end
|
199
196
|
end
|
200
197
|
|
201
|
-
describe
|
202
|
-
let(:function_info) { get_method_introspection_data
|
203
|
-
it
|
198
|
+
describe "for GLib::Variant.get_strv" do
|
199
|
+
let(:function_info) { get_method_introspection_data "GLib", "Variant", "get_strv" }
|
200
|
+
it "builds a correct definition" do
|
204
201
|
size_type = ":uint#{FFI.type_size(:size_t) * 8}"
|
205
|
-
code.must_equal
|
202
|
+
_(code).must_equal <<~CODE
|
206
203
|
def get_strv
|
207
204
|
_v1 = FFI::MemoryPointer.new #{size_type}
|
208
205
|
_v2 = GLib::Lib.g_variant_get_strv self, _v1
|
@@ -213,12 +210,11 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
213
210
|
end
|
214
211
|
end
|
215
212
|
|
216
|
-
describe
|
217
|
-
let(:function_info) { get_introspection_data
|
213
|
+
describe "for Regress.has_parameter_named_attrs" do
|
214
|
+
let(:function_info) { get_introspection_data "Regress", "has_parameter_named_attrs" }
|
218
215
|
|
219
|
-
it
|
220
|
-
|
221
|
-
code.must_equal <<-CODE.reset_indentation
|
216
|
+
it "builds a correct definition" do
|
217
|
+
_(code).must_equal <<~CODE
|
222
218
|
def self.has_parameter_named_attrs(foo, attributes)
|
223
219
|
_v1 = foo
|
224
220
|
GirFFI::ArgHelper.check_fixed_array_size 32, attributes, \"attributes\"
|
@@ -229,15 +225,14 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
229
225
|
end
|
230
226
|
end
|
231
227
|
|
232
|
-
describe
|
228
|
+
describe "for GIMarshallingTests::Object#method_int8_arg_and_out_callee" do
|
233
229
|
let(:function_info) do
|
234
|
-
get_method_introspection_data(
|
235
|
-
|
230
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
231
|
+
"method_int8_arg_and_out_callee")
|
236
232
|
end
|
237
233
|
|
238
|
-
it
|
239
|
-
|
240
|
-
code.must_equal <<-CODE.reset_indentation
|
234
|
+
it "builds a correct definition" do
|
235
|
+
_(code).must_equal <<~CODE
|
241
236
|
def method_int8_arg_and_out_callee(arg)
|
242
237
|
_v1 = arg
|
243
238
|
_v2 = FFI::MemoryPointer.new :pointer
|
@@ -249,237 +244,254 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
249
244
|
end
|
250
245
|
end
|
251
246
|
|
252
|
-
describe
|
253
|
-
describe
|
247
|
+
describe "object ownership transfer" do
|
248
|
+
describe "for GIMarshallingTests::Object#full_in" do
|
254
249
|
let(:function_info) do
|
255
|
-
get_method_introspection_data(
|
256
|
-
|
250
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
251
|
+
"full_in")
|
257
252
|
end
|
258
253
|
|
259
254
|
# NOTE: This method is transfer-ownership: none, despite the name.
|
260
|
-
it
|
261
|
-
code.must_equal
|
262
|
-
|
263
|
-
|
264
|
-
|
255
|
+
it "builds a correct definition" do
|
256
|
+
_(code).must_equal <<~CODE
|
257
|
+
def full_in
|
258
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_full_in self
|
259
|
+
end
|
265
260
|
CODE
|
266
261
|
end
|
267
262
|
end
|
268
263
|
|
269
|
-
describe
|
264
|
+
describe "for GIMarshallingTests::Object.full_inout" do
|
270
265
|
let(:function_info) do
|
271
|
-
get_method_introspection_data(
|
272
|
-
|
266
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
267
|
+
"full_inout")
|
273
268
|
end
|
274
269
|
|
275
|
-
it
|
276
|
-
code.must_equal
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
270
|
+
it "builds a correct definition" do
|
271
|
+
_(code).must_equal <<~CODE
|
272
|
+
def self.full_inout(object)
|
273
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
274
|
+
_v1.put_pointer 0, GIMarshallingTests::Object.from(object && object.ref)
|
275
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_full_inout _v1
|
276
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1.get_pointer(0))
|
277
|
+
return _v2
|
278
|
+
end
|
284
279
|
CODE
|
285
280
|
end
|
286
281
|
end
|
287
282
|
|
288
|
-
describe
|
283
|
+
describe "for GIMarshallingTests::Object.full_out" do
|
289
284
|
let(:function_info) do
|
290
|
-
get_method_introspection_data(
|
291
|
-
|
285
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
286
|
+
"full_out")
|
292
287
|
end
|
293
288
|
|
294
|
-
it
|
295
|
-
code.must_equal
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
289
|
+
it "builds a correct definition" do
|
290
|
+
_(code).must_equal <<~CODE
|
291
|
+
def self.full_out
|
292
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
293
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_full_out _v1
|
294
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1.get_pointer(0))
|
295
|
+
return _v2
|
296
|
+
end
|
302
297
|
CODE
|
303
298
|
end
|
304
299
|
end
|
305
300
|
|
306
|
-
describe
|
301
|
+
describe "for GIMarshallingTests::Object.full_return" do
|
307
302
|
let(:function_info) do
|
308
|
-
get_method_introspection_data(
|
309
|
-
|
303
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
304
|
+
"full_return")
|
310
305
|
end
|
311
306
|
|
312
|
-
it
|
313
|
-
code.must_equal
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
307
|
+
it "builds a correct definition" do
|
308
|
+
_(code).must_equal <<~CODE
|
309
|
+
def self.full_return
|
310
|
+
_v1 = GIMarshallingTests::Lib.gi_marshalling_tests_object_full_return
|
311
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1)
|
312
|
+
return _v2
|
313
|
+
end
|
319
314
|
CODE
|
320
315
|
end
|
321
316
|
end
|
322
317
|
|
323
|
-
describe
|
318
|
+
describe "for GIMarshallingTests::Object#none_in" do
|
324
319
|
let(:function_info) do
|
325
|
-
get_method_introspection_data(
|
326
|
-
|
320
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
321
|
+
"none_in")
|
327
322
|
end
|
328
323
|
|
329
|
-
it
|
330
|
-
code.must_equal
|
331
|
-
|
332
|
-
|
333
|
-
|
324
|
+
it "builds a correct definition" do
|
325
|
+
_(code).must_equal <<~CODE
|
326
|
+
def none_in
|
327
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_none_in self
|
328
|
+
end
|
334
329
|
CODE
|
335
330
|
end
|
336
331
|
end
|
337
332
|
|
338
|
-
describe
|
333
|
+
describe "for GIMarshallingTests::Object.none_inout" do
|
339
334
|
let(:function_info) do
|
340
|
-
get_method_introspection_data(
|
341
|
-
|
335
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
336
|
+
"none_inout")
|
342
337
|
end
|
343
338
|
|
344
|
-
it
|
345
|
-
code.must_equal
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
339
|
+
it "builds a correct definition" do
|
340
|
+
_(code).must_equal <<~CODE
|
341
|
+
def self.none_inout(object)
|
342
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
343
|
+
_v1.put_pointer 0, GIMarshallingTests::Object.from(object)
|
344
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_none_inout _v1
|
345
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1.get_pointer(0)).tap { |it| it && it.ref }
|
346
|
+
return _v2
|
347
|
+
end
|
353
348
|
CODE
|
354
349
|
end
|
355
350
|
end
|
356
351
|
|
357
|
-
describe
|
352
|
+
describe "for GIMarshallingTests::Object.none_out" do
|
358
353
|
let(:function_info) do
|
359
|
-
get_method_introspection_data(
|
360
|
-
|
354
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
355
|
+
"none_out")
|
361
356
|
end
|
362
357
|
|
363
|
-
it
|
364
|
-
code.must_equal
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
358
|
+
it "builds a correct definition" do
|
359
|
+
_(code).must_equal <<~CODE
|
360
|
+
def self.none_out
|
361
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
362
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_object_none_out _v1
|
363
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1.get_pointer(0)).tap { |it| it && it.ref }
|
364
|
+
return _v2
|
365
|
+
end
|
371
366
|
CODE
|
372
367
|
end
|
373
368
|
end
|
374
369
|
|
375
|
-
describe
|
370
|
+
describe "for GIMarshallingTests::Object.none_return" do
|
376
371
|
let(:function_info) do
|
377
|
-
get_method_introspection_data(
|
378
|
-
|
372
|
+
get_method_introspection_data("GIMarshallingTests", "Object",
|
373
|
+
"none_return")
|
379
374
|
end
|
380
375
|
|
381
|
-
it
|
382
|
-
code.must_equal
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
376
|
+
it "builds a correct definition" do
|
377
|
+
_(code).must_equal <<~CODE
|
378
|
+
def self.none_return
|
379
|
+
_v1 = GIMarshallingTests::Lib.gi_marshalling_tests_object_none_return
|
380
|
+
_v2 = GIMarshallingTests::Object.wrap(_v1).tap { |it| it && it.ref }
|
381
|
+
return _v2
|
382
|
+
end
|
388
383
|
CODE
|
389
384
|
end
|
390
385
|
end
|
391
386
|
|
392
|
-
describe
|
387
|
+
describe "for Regress::TestObj#instance_method_full" do
|
393
388
|
let(:function_info) do
|
394
|
-
get_method_introspection_data(
|
395
|
-
|
389
|
+
get_method_introspection_data("Regress", "TestObj",
|
390
|
+
"instance_method_full")
|
396
391
|
end
|
397
392
|
|
398
|
-
it
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
end
|
393
|
+
it "builds a correct definition including self.ref" do
|
394
|
+
_(code).must_equal <<~CODE
|
395
|
+
def instance_method_full
|
396
|
+
Regress::Lib.regress_test_obj_instance_method_full self.ref
|
397
|
+
end
|
404
398
|
CODE
|
405
399
|
end
|
406
400
|
end
|
407
401
|
end
|
408
402
|
|
409
|
-
describe
|
410
|
-
describe
|
403
|
+
describe "struct ownership transfer" do
|
404
|
+
describe "for Regress::FooRectangle#add" do
|
411
405
|
let(:function_info) do
|
412
|
-
get_method_introspection_data(
|
406
|
+
get_method_introspection_data("Regress", "FooRectangle",
|
407
|
+
"add")
|
413
408
|
end
|
414
409
|
|
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
|
410
|
+
it "builds a correct definition without #ref" do
|
411
|
+
_(code).must_equal <<~CODE
|
412
|
+
def add(r2)
|
413
|
+
_v1 = Regress::FooRectangle.from(r2)
|
414
|
+
Regress::Lib.regress_foo_rectangle_add self, _v1
|
415
|
+
end
|
424
416
|
CODE
|
425
417
|
end
|
426
418
|
end
|
419
|
+
end
|
427
420
|
|
428
|
-
|
421
|
+
describe "boxed struct ownership transfer" do
|
422
|
+
describe "for GIMarshallingTests::BoxedStruct.inout" do
|
429
423
|
let(:function_info) do
|
430
|
-
get_method_introspection_data(
|
424
|
+
get_method_introspection_data("GIMarshallingTests", "BoxedStruct", "inout")
|
431
425
|
end
|
432
426
|
|
433
|
-
it
|
434
|
-
code.must_equal
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
427
|
+
it "builds a correct definition" do
|
428
|
+
_(code).must_equal <<~CODE
|
429
|
+
def self.inout(struct_)
|
430
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
431
|
+
_v1.put_pointer 0, GIMarshallingTests::BoxedStruct.copy_from(struct_)
|
432
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_boxed_struct_inout _v1
|
433
|
+
_v2 = GIMarshallingTests::BoxedStruct.wrap_own(_v1.get_pointer(0))
|
434
|
+
return _v2
|
435
|
+
end
|
441
436
|
CODE
|
442
437
|
end
|
443
438
|
end
|
444
439
|
|
445
|
-
describe
|
440
|
+
describe "for GIMarshallingTests::BoxedStruct.out" do
|
446
441
|
let(:function_info) do
|
447
|
-
get_method_introspection_data(
|
442
|
+
get_method_introspection_data("GIMarshallingTests", "BoxedStruct", "out")
|
448
443
|
end
|
449
444
|
|
450
|
-
it
|
451
|
-
code.must_equal
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
445
|
+
it "builds a correct definition" do
|
446
|
+
_(code).must_equal <<~CODE
|
447
|
+
def self.out
|
448
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
449
|
+
GIMarshallingTests::Lib.gi_marshalling_tests_boxed_struct_out _v1
|
450
|
+
_v2 = GIMarshallingTests::BoxedStruct.wrap_copy(_v1.get_pointer(0))
|
451
|
+
return _v2
|
452
|
+
end
|
457
453
|
CODE
|
458
454
|
end
|
459
455
|
end
|
460
|
-
end
|
461
456
|
|
462
|
-
|
463
|
-
|
464
|
-
|
457
|
+
describe "for GIMarshallingTests::BoxedStruct.returnv" do
|
458
|
+
let(:function_info) do
|
459
|
+
get_method_introspection_data("GIMarshallingTests", "BoxedStruct", "returnv")
|
460
|
+
end
|
465
461
|
|
466
|
-
it
|
467
|
-
code.must_equal
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
462
|
+
it "builds a correct definition" do
|
463
|
+
_(code).must_equal <<~CODE
|
464
|
+
def self.returnv
|
465
|
+
_v1 = GIMarshallingTests::Lib.gi_marshalling_tests_boxed_struct_returnv
|
466
|
+
_v2 = GIMarshallingTests::BoxedStruct.wrap_copy(_v1)
|
467
|
+
return _v2
|
468
|
+
end
|
469
|
+
CODE
|
470
|
+
end
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
describe "string ownership transfer" do
|
475
|
+
describe "for Regress.test_utf8_out" do
|
476
|
+
let(:function_info) { get_introspection_data "Regress", "test_utf8_out" }
|
477
|
+
|
478
|
+
it "builds a correct definition" do
|
479
|
+
_(code).must_equal <<~CODE
|
480
|
+
def self.test_utf8_out
|
481
|
+
_v1 = FFI::MemoryPointer.new :pointer
|
482
|
+
Regress::Lib.regress_test_utf8_out _v1
|
483
|
+
_v2 = GirFFI::AllocationHelper.free_after _v1.get_pointer(0), &:to_utf8
|
484
|
+
return _v2
|
485
|
+
end
|
474
486
|
CODE
|
475
487
|
end
|
476
488
|
end
|
477
489
|
end
|
478
490
|
|
479
|
-
describe
|
480
|
-
let(:function_info) { get_introspection_data
|
481
|
-
it
|
482
|
-
code.must_equal
|
491
|
+
describe "for functions with an allow-none ingoing parameter" do
|
492
|
+
let(:function_info) { get_introspection_data "Regress", "test_utf8_null_in" }
|
493
|
+
it "builds correct definition with default parameter value" do
|
494
|
+
_(code).must_equal <<~CODE
|
483
495
|
def self.test_utf8_null_in(in_ = nil)
|
484
496
|
_v1 = GirFFI::InPointer.from_utf8(in_)
|
485
497
|
Regress::Lib.regress_test_utf8_null_in _v1
|
@@ -488,10 +500,10 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
488
500
|
end
|
489
501
|
end
|
490
502
|
|
491
|
-
describe
|
492
|
-
let(:function_info) { get_introspection_data
|
493
|
-
it
|
494
|
-
code.must_equal
|
503
|
+
describe "for functions where some allow-none cannot be honored" do
|
504
|
+
let(:function_info) { get_introspection_data "GIMarshallingTests", "array_in_utf8_two_in_out_of_order" }
|
505
|
+
it "builds correct definition with default parameter value on the later arguments" do
|
506
|
+
_(code).must_equal <<~CODE
|
495
507
|
def self.array_in_utf8_two_in_out_of_order(a, ints, b = nil)
|
496
508
|
length = ints.nil? ? 0 : ints.length
|
497
509
|
_v1 = length
|
@@ -504,12 +516,12 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
504
516
|
end
|
505
517
|
end
|
506
518
|
|
507
|
-
describe
|
508
|
-
describe
|
509
|
-
let(:function_info) { get_introspection_data
|
519
|
+
describe "ownership transfer for an ingoing array of structs" do
|
520
|
+
describe "with no ownership transfer of the elements" do
|
521
|
+
let(:function_info) { get_introspection_data "GIMarshallingTests", "array_struct_in" }
|
510
522
|
|
511
|
-
it
|
512
|
-
code.must_equal
|
523
|
+
it "builds a correct definition" do
|
524
|
+
_(code).must_equal <<~CODE
|
513
525
|
def self.array_struct_in(structs)
|
514
526
|
length = structs.nil? ? 0 : structs.length
|
515
527
|
_v1 = length
|
@@ -519,11 +531,11 @@ describe GirFFI::Builders::FunctionBuilder do
|
|
519
531
|
CODE
|
520
532
|
end
|
521
533
|
end
|
522
|
-
describe
|
523
|
-
let(:function_info) { get_introspection_data
|
534
|
+
describe "with ownership transfer of the elements" do
|
535
|
+
let(:function_info) { get_introspection_data "GIMarshallingTests", "array_struct_take_in" }
|
524
536
|
|
525
|
-
it
|
526
|
-
code.must_equal
|
537
|
+
it "builds a correct definition" do
|
538
|
+
_(code).must_equal <<~CODE
|
527
539
|
def self.array_struct_take_in(structs)
|
528
540
|
length = structs.nil? ? 0 : structs.length
|
529
541
|
_v1 = length
|