gir_ffi 0.14.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::InfoExt::IUnresolvedInfo do
|
6
6
|
let(:info_class) do
|
@@ -11,9 +11,9 @@ describe GirFFI::InfoExt::IUnresolvedInfo do
|
|
11
11
|
|
12
12
|
let(:unresolved_info) { info_class.new }
|
13
13
|
|
14
|
-
describe
|
15
|
-
it
|
16
|
-
unresolved_info.to_ffi_type.must_equal :pointer
|
14
|
+
describe "#to_ffi_type" do
|
15
|
+
it "returns the most generic type" do
|
16
|
+
_(unresolved_info.to_ffi_type).must_equal :pointer
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::InfoExt::SafeConstantName do
|
6
6
|
let(:info_class) do
|
@@ -10,17 +10,17 @@ describe GirFFI::InfoExt::SafeConstantName do
|
|
10
10
|
end
|
11
11
|
let(:info) { info_class.new }
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
15
|
-
expect(info).to receive(:name).and_return
|
13
|
+
describe "#safe_name" do
|
14
|
+
it "makes names starting with an underscore safe" do
|
15
|
+
expect(info).to receive(:name).and_return "_foo"
|
16
16
|
|
17
|
-
assert_equal
|
17
|
+
assert_equal "Private___foo", info.safe_name
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
expect(info).to receive(:name).and_return
|
20
|
+
it "makes names with dashes safe" do
|
21
|
+
expect(info).to receive(:name).and_return "this-could-be-a-signal-name"
|
22
22
|
|
23
|
-
info.safe_name.must_equal
|
23
|
+
_(info.safe_name).must_equal "This_could_be_a_signal_name"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::InfoExt::SafeFunctionName do
|
6
6
|
let(:info_class) do
|
@@ -10,17 +10,17 @@ describe GirFFI::InfoExt::SafeFunctionName do
|
|
10
10
|
end
|
11
11
|
let(:info) { info_class.new }
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
15
|
-
expect(info).to receive(:name).and_return
|
13
|
+
describe "#safe_name" do
|
14
|
+
it "keeps lower case names lower case" do
|
15
|
+
expect(info).to receive(:name).and_return "foo"
|
16
16
|
|
17
|
-
assert_equal
|
17
|
+
assert_equal "foo", info.safe_name
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
expect(info).to receive(:name).and_return
|
20
|
+
it "returns a non-empty string if name is empty" do
|
21
|
+
expect(info).to receive(:name).and_return ""
|
22
22
|
|
23
|
-
assert_equal
|
23
|
+
assert_equal "_", info.safe_name
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::InterfaceBase do
|
6
6
|
let(:interface) { Module.new { extend GirFFI::InterfaceBase } }
|
7
7
|
|
8
|
-
describe
|
9
|
-
it
|
10
|
-
expect(ptr = Object.new).to receive(:to_object).and_return
|
11
|
-
interface.wrap(ptr).must_equal
|
8
|
+
describe "#wrap" do
|
9
|
+
it "delegates conversion to the wrapped pointer" do
|
10
|
+
expect(ptr = Object.new).to receive(:to_object).and_return "good-result"
|
11
|
+
_(interface.wrap(ptr)).must_equal "good-result"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe
|
16
|
-
it
|
17
|
-
interface.to_ffi_type.must_equal :pointer
|
15
|
+
describe ".to_ffi_type" do
|
16
|
+
it "returns :pointer" do
|
17
|
+
_(interface.to_ffi_type).must_equal :pointer
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::MethodStubber do
|
6
|
-
describe
|
6
|
+
describe "#method_stub" do
|
7
7
|
let(:stubber) { GirFFI::MethodStubber.new(method_info) }
|
8
8
|
let(:result) { stubber.method_stub }
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe "for a regular method" do
|
11
11
|
let(:method_info) do
|
12
|
-
get_method_introspection_data(
|
12
|
+
get_method_introspection_data("Regress", "TestObj", "instance_method")
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
result.must_equal
|
15
|
+
it "creates a method stub" do
|
16
|
+
_(result).must_equal <<~STUB
|
17
17
|
def instance_method *args, &block
|
18
18
|
setup_and_call "instance_method", args, &block
|
19
19
|
end
|
@@ -21,13 +21,13 @@ describe GirFFI::MethodStubber do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
24
|
+
describe "for a static method" do
|
25
25
|
let(:method_info) do
|
26
|
-
get_method_introspection_data(
|
26
|
+
get_method_introspection_data("Regress", "TestObj", "static_method")
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
result.must_equal
|
29
|
+
it "creates a class method stub" do
|
30
|
+
_(result).must_equal <<~STUB
|
31
31
|
def self.static_method *args, &block
|
32
32
|
setup_and_call "static_method", args, &block
|
33
33
|
end
|
@@ -35,13 +35,13 @@ describe GirFFI::MethodStubber do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe
|
38
|
+
describe "for a module function" do
|
39
39
|
let(:method_info) do
|
40
|
-
get_introspection_data(
|
40
|
+
get_introspection_data("Regress", "test_int")
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
result.must_equal
|
43
|
+
it "creates a module method stub" do
|
44
|
+
_(result).must_equal <<~STUB
|
45
45
|
def self.test_int *args, &block
|
46
46
|
setup_and_call "test_int", args, &block
|
47
47
|
end
|
@@ -49,12 +49,12 @@ describe GirFFI::MethodStubber do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
describe
|
53
|
-
let(:method_info) { get_method_introspection_data(
|
52
|
+
describe "for a method with an empty name" do
|
53
|
+
let(:method_info) { get_method_introspection_data("Regress", "TestObj", "instance_method") }
|
54
54
|
|
55
|
-
it
|
56
|
-
allow(method_info).to receive(:name).and_return
|
57
|
-
result.must_equal
|
55
|
+
it "creates a method stub with a safe name that sets up the unsafe method" do
|
56
|
+
allow(method_info).to receive(:name).and_return ""
|
57
|
+
_(result).must_equal <<~STUB
|
58
58
|
def _ *args, &block
|
59
59
|
setup_and_call "", args, &block
|
60
60
|
end
|
@@ -1,38 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
GirFFI.setup :Regress
|
6
6
|
|
7
7
|
describe GirFFI::ObjectBase do
|
8
8
|
let(:derived_class) { Class.new GirFFI::ObjectBase }
|
9
9
|
|
10
|
-
describe
|
11
|
-
it
|
12
|
-
expect(ptr = Object.new).to receive(:to_object).and_return
|
13
|
-
derived_class.wrap(ptr).must_equal
|
10
|
+
describe ".wrap" do
|
11
|
+
it "delegates conversion to the wrapped pointer" do
|
12
|
+
expect(ptr = Object.new).to receive(:to_object).and_return "good-result"
|
13
|
+
_(derived_class.wrap(ptr)).must_equal "good-result"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
describe
|
18
|
-
it
|
19
|
-
derived_class.to_ffi_type.must_equal derived_class
|
17
|
+
describe ".to_ffi_type" do
|
18
|
+
it "returns itself" do
|
19
|
+
_(derived_class.to_ffi_type).must_equal derived_class
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
24
|
-
it
|
25
|
-
Regress::TestObj.object_class.must_be_instance_of Regress::TestObjClass
|
23
|
+
describe ".object_class" do
|
24
|
+
it "returns an object of the class struct type" do
|
25
|
+
_(Regress::TestObj.object_class).must_be_instance_of Regress::TestObjClass
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it "caches its result" do
|
29
29
|
first = Regress::TestObj.object_class
|
30
30
|
second = Regress::TestObj.object_class
|
31
|
-
second.must_be :eql?, first
|
31
|
+
_(second).must_be :eql?, first
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe
|
35
|
+
describe "#included_interfaces" do
|
36
36
|
let(:base_class) { GIMarshallingTests::Object }
|
37
37
|
let(:derived_class) { Class.new(base_class) }
|
38
38
|
|
@@ -40,12 +40,12 @@ describe GirFFI::ObjectBase do
|
|
40
40
|
derived_class.class_eval { include GIMarshallingTests::Interface }
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
derived_class.included_interfaces.must_equal [GIMarshallingTests::Interface]
|
43
|
+
it "finds the included interface" do
|
44
|
+
_(derived_class.included_interfaces).must_equal [GIMarshallingTests::Interface]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe
|
48
|
+
describe "#registered_ancestors" do
|
49
49
|
let(:base_class) { GIMarshallingTests::Object }
|
50
50
|
let(:derived_class) { Class.new(base_class) }
|
51
51
|
|
@@ -53,8 +53,8 @@ describe GirFFI::ObjectBase do
|
|
53
53
|
derived_class.class_eval { include GIMarshallingTests::Interface }
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
57
|
-
derived_class.registered_ancestors.
|
56
|
+
it "finds the ancestor classes and included interface" do
|
57
|
+
_(derived_class.registered_ancestors).
|
58
58
|
must_equal [derived_class,
|
59
59
|
GIMarshallingTests::Interface,
|
60
60
|
GIMarshallingTests::Object,
|
@@ -1,41 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::ObjectStore do
|
6
6
|
let(:store) { GirFFI::ObjectStore.new }
|
7
7
|
|
8
|
-
describe
|
9
|
-
it
|
8
|
+
describe "#store" do
|
9
|
+
it "returns a non-null pointer when storing objects" do
|
10
10
|
obj = Object.new
|
11
11
|
ptr = store.store obj
|
12
|
-
ptr.wont_be :null?
|
12
|
+
_(ptr).wont_be :null?
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it "returns a null pointer when storing nil" do
|
16
16
|
ptr = store.store nil
|
17
|
-
ptr.must_be :null?
|
17
|
+
_(ptr).must_be :null?
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
it
|
21
|
+
describe "#fetch" do
|
22
|
+
it "returns the stored object when passed the key pointer" do
|
23
23
|
obj = Object.new
|
24
24
|
ptr = store.store obj
|
25
25
|
result = store.fetch ptr
|
26
|
-
result.must_equal obj
|
26
|
+
_(result).must_equal obj
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it "returns the nil object when passed a null pointer" do
|
30
30
|
ptr = FFI::Pointer.new(0)
|
31
31
|
result = store.fetch ptr
|
32
|
-
result.must_be_nil
|
32
|
+
_(result).must_be_nil
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it "returns the pointer itself when passed an unknown pointer" do
|
36
36
|
ptr = FFI::Pointer.new(42)
|
37
37
|
result = store.fetch ptr
|
38
|
-
result.must_equal ptr
|
38
|
+
_(result).must_equal ptr
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -1,33 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
|
+
require "gir_ffi/receiver_argument_info"
|
5
5
|
|
6
6
|
describe GirFFI::ReceiverArgumentInfo do
|
7
|
-
let(:dummy_type) {
|
7
|
+
let(:dummy_type) { "foo" }
|
8
8
|
let(:instance) { GirFFI::ReceiverArgumentInfo.new dummy_type }
|
9
9
|
|
10
|
-
describe
|
11
|
-
it
|
12
|
-
instance.argument_type.must_equal dummy_type
|
10
|
+
describe "#argument_type" do
|
11
|
+
it "returns the argument type" do
|
12
|
+
_(instance.argument_type).must_equal dummy_type
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
17
|
-
it
|
18
|
-
instance.direction.must_equal :in
|
16
|
+
describe "#direction" do
|
17
|
+
it "returns the correct value" do
|
18
|
+
_(instance.direction).must_equal :in
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
23
|
-
it
|
24
|
-
instance.ownership_transfer.must_equal :everything
|
22
|
+
describe "#ownership_transfer" do
|
23
|
+
it "returns the correct value" do
|
24
|
+
_(instance.ownership_transfer).must_equal :everything
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
29
|
-
it
|
30
|
-
instance.name.must_equal
|
28
|
+
describe "#name" do
|
29
|
+
it "returns the correct value" do
|
30
|
+
_(instance.name).must_equal "_instance"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GirFFI::SizedArray do
|
6
|
-
describe
|
7
|
-
it
|
6
|
+
describe "::wrap" do
|
7
|
+
it "takes a type, size and pointer and returns a GirFFI::SizedArray wrapping them" do
|
8
8
|
expect(ptr = Object.new).to receive(:null?).and_return false
|
9
9
|
sarr = GirFFI::SizedArray.wrap :gint32, 3, ptr
|
10
10
|
assert_instance_of GirFFI::SizedArray, sarr
|
@@ -13,15 +13,15 @@ describe GirFFI::SizedArray do
|
|
13
13
|
assert_equal :gint32, sarr.element_type
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it "returns nil if the wrapped pointer is null" do
|
17
17
|
expect(ptr = Object.new).to receive(:null?).and_return true
|
18
18
|
sarr = GirFFI::SizedArray.wrap :gint32, 3, ptr
|
19
|
-
sarr.must_be_nil
|
19
|
+
_(sarr).must_be_nil
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
24
|
-
it
|
23
|
+
describe "#each" do
|
24
|
+
it "yields each element" do
|
25
25
|
ary = %w(one two three)
|
26
26
|
ptrs = ary.map { |a| FFI::MemoryPointer.from_string(a) }
|
27
27
|
ptrs << nil
|
@@ -37,170 +37,170 @@ describe GirFFI::SizedArray do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
describe
|
41
|
-
describe
|
42
|
-
it
|
40
|
+
describe "::from" do
|
41
|
+
describe "from a Ruby array" do
|
42
|
+
it "creates a GirFFI::SizedArray with the same elements" do
|
43
43
|
arr = GirFFI::SizedArray.from :gint32, 3, [3, 2, 1]
|
44
|
-
arr.must_be_instance_of GirFFI::SizedArray
|
44
|
+
_(arr).must_be_instance_of GirFFI::SizedArray
|
45
45
|
assert_equal [3, 2, 1], arr.to_a
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
49
|
-
proc { GirFFI::SizedArray.from :gint32, 4, [3, 2, 1] }.must_raise ArgumentError
|
48
|
+
it "raises an error if the array has the wrong number of elements" do
|
49
|
+
_(proc { GirFFI::SizedArray.from :gint32, 4, [3, 2, 1] }).must_raise ArgumentError
|
50
50
|
end
|
51
51
|
|
52
52
|
it "uses the array's size if passed -1 as the size" do
|
53
53
|
arr = GirFFI::SizedArray.from :gint32, -1, [3, 2, 1]
|
54
|
-
arr.size.must_equal 3
|
54
|
+
_(arr.size).must_equal 3
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
describe
|
59
|
-
it
|
58
|
+
describe "from a GirFFI::SizedArray" do
|
59
|
+
it "return its argument" do
|
60
60
|
arr = GirFFI::SizedArray.from :gint32, 3, [3, 2, 1]
|
61
61
|
arr2 = GirFFI::SizedArray.from :gint32, 3, arr
|
62
62
|
assert_equal arr, arr2
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
65
|
+
it "raises an error if the argument has the wrong number of elements" do
|
66
66
|
arr = GirFFI::SizedArray.from :gint32, 3, [3, 2, 1]
|
67
|
-
proc { GirFFI::SizedArray.from :gint32, 4, arr }.must_raise ArgumentError
|
67
|
+
_(proc { GirFFI::SizedArray.from :gint32, 4, arr }).must_raise ArgumentError
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
71
|
+
it "returns nil when passed nil" do
|
72
72
|
arr = GirFFI::SizedArray.from :gint32, 0, nil
|
73
|
-
arr.must_be_nil
|
73
|
+
_(arr).must_be_nil
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
76
|
+
it "wraps its argument if given a pointer" do
|
77
77
|
arr = GirFFI::SizedArray.from :gint32, 3, [3, 2, 1]
|
78
78
|
arr2 = GirFFI::SizedArray.from :gint32, 3, arr.to_ptr
|
79
79
|
assert_instance_of GirFFI::SizedArray, arr2
|
80
80
|
refute arr2.equal? arr
|
81
|
-
arr2.to_ptr.must_equal arr.to_ptr
|
81
|
+
_(arr2.to_ptr).must_equal arr.to_ptr
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
describe
|
86
|
-
describe
|
87
|
-
it
|
85
|
+
describe ".copy_from" do
|
86
|
+
describe "from a Ruby array" do
|
87
|
+
it "creates an unowned GirFFI::SizedArray with the same elements" do
|
88
88
|
arr = GirFFI::SizedArray.copy_from :gint32, 3, [3, 2, 1]
|
89
|
-
arr.must_be_instance_of GirFFI::SizedArray
|
89
|
+
_(arr).must_be_instance_of GirFFI::SizedArray
|
90
90
|
assert_equal [3, 2, 1], arr.to_a
|
91
|
-
arr.to_ptr.wont_be :autorelease?
|
91
|
+
_(arr.to_ptr).wont_be :autorelease?
|
92
92
|
end
|
93
93
|
|
94
|
-
it
|
94
|
+
it "creates unowned copies of struct pointer elements" do
|
95
95
|
struct = GIMarshallingTests::BoxedStruct.new
|
96
96
|
struct.long_ = 2342
|
97
|
-
struct.struct.must_be :owned?
|
97
|
+
_(struct.struct).must_be :owned?
|
98
98
|
|
99
99
|
arr = GirFFI::SizedArray.copy_from([:pointer, GIMarshallingTests::BoxedStruct],
|
100
100
|
1,
|
101
101
|
[struct])
|
102
|
-
arr.must_be_instance_of GirFFI::SizedArray
|
103
|
-
arr.to_ptr.wont_be :autorelease?
|
102
|
+
_(arr).must_be_instance_of GirFFI::SizedArray
|
103
|
+
_(arr.to_ptr).wont_be :autorelease?
|
104
104
|
|
105
105
|
struct_copy = arr.first
|
106
|
-
struct_copy.long_.must_equal struct.long_
|
107
|
-
struct_copy.to_ptr.wont_be :==, struct.to_ptr
|
108
|
-
struct_copy.struct.wont_be :owned?
|
106
|
+
_(struct_copy.long_).must_equal struct.long_
|
107
|
+
_(struct_copy.to_ptr).wont_be :==, struct.to_ptr
|
108
|
+
_(struct_copy.struct).wont_be :owned?
|
109
109
|
end
|
110
110
|
|
111
|
-
it
|
111
|
+
it "increases the ref count of object pointer elements" do
|
112
112
|
obj = GIMarshallingTests::Object.new 42
|
113
113
|
arr = GirFFI::SizedArray.copy_from([:pointer, GIMarshallingTests::Object],
|
114
114
|
-1,
|
115
115
|
[obj, nil])
|
116
|
-
arr.must_be_instance_of GirFFI::SizedArray
|
117
|
-
arr.to_ptr.wont_be :autorelease?
|
116
|
+
_(arr).must_be_instance_of GirFFI::SizedArray
|
117
|
+
_(arr.to_ptr).wont_be :autorelease?
|
118
118
|
|
119
|
-
arr.to_a.must_equal [obj, nil]
|
120
|
-
object_ref_count(obj).must_equal 2
|
119
|
+
_(arr.to_a).must_equal [obj, nil]
|
120
|
+
_(object_ref_count(obj)).must_equal 2
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
describe
|
125
|
-
it
|
124
|
+
describe "from a GirFFI::SizedArray" do
|
125
|
+
it "return an unowned copy of its argument" do
|
126
126
|
arr = GirFFI::SizedArray.from :gint32, 3, [3, 2, 1]
|
127
127
|
arr2 = GirFFI::SizedArray.copy_from :gint32, 3, arr
|
128
|
-
arr.to_ptr.wont_be :==, arr2.to_ptr
|
129
|
-
arr2.to_a.must_equal [3, 2, 1]
|
130
|
-
arr2.to_ptr.wont_be :autorelease?
|
128
|
+
_(arr.to_ptr).wont_be :==, arr2.to_ptr
|
129
|
+
_(arr2.to_a).must_equal [3, 2, 1]
|
130
|
+
_(arr2.to_ptr).wont_be :autorelease?
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
it
|
134
|
+
it "returns nil when passed nil" do
|
135
135
|
arr = GirFFI::SizedArray.copy_from :gint32, 0, nil
|
136
|
-
arr.must_be_nil
|
136
|
+
_(arr).must_be_nil
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
describe
|
141
|
-
it
|
140
|
+
describe "#==" do
|
141
|
+
it "returns true when comparing to an array with the same elements" do
|
142
142
|
sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
|
143
143
|
|
144
|
-
sized.must_be :==, [1, 2, 3]
|
144
|
+
_(sized).must_be :==, [1, 2, 3]
|
145
145
|
end
|
146
146
|
|
147
|
-
it
|
147
|
+
it "returns false when comparing to an array with different elements" do
|
148
148
|
sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
|
149
149
|
|
150
|
-
sized.wont_be :==, [1, 2]
|
150
|
+
_(sized).wont_be :==, [1, 2]
|
151
151
|
end
|
152
152
|
|
153
|
-
it
|
153
|
+
it "returns true when comparing to a sized array with the same elements" do
|
154
154
|
sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
|
155
155
|
other = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
|
156
156
|
|
157
|
-
sized.must_be :==, other
|
157
|
+
_(sized).must_be :==, other
|
158
158
|
end
|
159
159
|
|
160
|
-
it
|
160
|
+
it "returns false when comparing to a sized array with different elements" do
|
161
161
|
sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
|
162
162
|
other = GirFFI::SizedArray.from :int32, 2, [1, 2]
|
163
163
|
|
164
|
-
sized.wont_be :==, other
|
164
|
+
_(sized).wont_be :==, other
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
|
-
describe
|
169
|
-
it
|
168
|
+
describe "#size_in_bytes" do
|
169
|
+
it "returns the correct value" do
|
170
170
|
sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
|
171
171
|
|
172
|
-
sized.size_in_bytes.must_equal 12
|
172
|
+
_(sized.size_in_bytes).must_equal 12
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
|
-
describe
|
177
|
-
it
|
176
|
+
describe ".get_value_from_pointer" do
|
177
|
+
it "returns just a pointer" do
|
178
178
|
sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
|
179
179
|
ptr = sized.to_ptr
|
180
180
|
result = GirFFI::SizedArray.get_value_from_pointer(ptr, 0)
|
181
|
-
result.must_be :==, ptr
|
181
|
+
_(result).must_be :==, ptr
|
182
182
|
end
|
183
183
|
|
184
|
-
it
|
184
|
+
it "offsets correctly" do
|
185
185
|
sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
|
186
186
|
ptr = sized.to_ptr
|
187
187
|
next_ptr = GirFFI::SizedArray.get_value_from_pointer(ptr, 4)
|
188
188
|
tail = GirFFI::SizedArray.from(:int32, 2, next_ptr)
|
189
|
-
tail.must_be :==, [2, 3]
|
189
|
+
_(tail).must_be :==, [2, 3]
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
|
-
describe
|
194
|
-
it
|
193
|
+
describe ".copy_value_to_pointer" do
|
194
|
+
it "copies data correctly" do
|
195
195
|
sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
|
196
196
|
target = FFI::MemoryPointer.new sized.size_in_bytes
|
197
197
|
GirFFI::SizedArray.copy_value_to_pointer(sized, target)
|
198
198
|
result = GirFFI::SizedArray.from :int32, 3, target
|
199
|
-
result.must_be :==, [1, 2, 3]
|
199
|
+
_(result).must_be :==, [1, 2, 3]
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
|
-
it
|
204
|
-
GirFFI::SizedArray.must_include Enumerable
|
203
|
+
it "includes Enumerable" do
|
204
|
+
_(GirFFI::SizedArray).must_include Enumerable
|
205
205
|
end
|
206
206
|
end
|