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,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::FFIExt::Pointer do
|
6
6
|
let(:pointer_class) { Class.new { include GirFFI::FFIExt::Pointer } }
|
7
|
-
describe
|
8
|
-
it
|
7
|
+
describe "#to_object" do
|
8
|
+
it "finds the wrapping class by gtype and wraps the pointer in it" do
|
9
9
|
ptr = pointer_class.new
|
10
10
|
expect(ptr).to receive(:null?).and_return false
|
11
11
|
object_class = Class.new
|
12
12
|
|
13
13
|
expect(GObject).to receive(:type_from_instance_pointer).with(ptr).and_return 0xdeadbeef
|
14
14
|
expect(GirFFI::Builder).to receive(:build_by_gtype).with(0xdeadbeef).and_return object_class
|
15
|
-
expect(object_class).to receive(:direct_wrap).with(ptr).and_return
|
15
|
+
expect(object_class).to receive(:direct_wrap).with(ptr).and_return "good-result"
|
16
16
|
|
17
|
-
ptr.to_object.must_equal
|
17
|
+
_(ptr.to_object).must_equal "good-result"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/test/gir_ffi/g_type_test.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
|
-
require
|
5
|
+
require "gir_ffi/g_type"
|
6
6
|
|
7
7
|
describe GirFFI::GType do
|
8
8
|
let(:gobject_gtype) { GObject::Object.gtype }
|
9
9
|
let(:gobject_type_query) { GObject.type_query gobject_gtype }
|
10
10
|
|
11
|
-
describe
|
12
|
-
it
|
11
|
+
describe "#to_i" do
|
12
|
+
it "returns the integer gtype" do
|
13
13
|
gt = GirFFI::GType.new(gobject_gtype)
|
14
|
-
gt.to_i.must_equal gobject_gtype
|
14
|
+
_(gt.to_i).must_equal gobject_gtype
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
it
|
18
|
+
describe "#class_size" do
|
19
|
+
it "returns the class size for object types" do
|
20
20
|
gt = GirFFI::GType.new(gobject_gtype)
|
21
|
-
gt.class_size.must_equal gobject_type_query.class_size
|
21
|
+
_(gt.class_size).must_equal gobject_type_query.class_size
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
26
|
-
it
|
25
|
+
describe "#instance_size" do
|
26
|
+
it "returns the instance size for object types" do
|
27
27
|
gt = GirFFI::GType.new(gobject_gtype)
|
28
|
-
gt.instance_size.must_equal gobject_type_query.instance_size
|
28
|
+
_(gt.instance_size).must_equal gobject_type_query.instance_size
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -1,30 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
|
-
require
|
5
|
+
require "gir_ffi/in_pointer"
|
6
6
|
|
7
7
|
describe GirFFI::InPointer do
|
8
|
-
describe
|
9
|
-
it
|
8
|
+
describe ".from_array" do
|
9
|
+
it "returns nil when passed nil" do
|
10
10
|
result = GirFFI::InPointer.from_array :gint32, nil
|
11
11
|
assert_nil result
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it "handles type tag :GType" do
|
15
15
|
GirFFI::InPointer.from_array :GType, [2]
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it "handles enum types" do
|
19
19
|
e = Module.new do
|
20
20
|
extend GirFFI::EnumBase
|
21
21
|
self::Enum = FFI::Enum.new [:foo, :bar, :baz], :qux
|
22
22
|
end
|
23
23
|
ptr = GirFFI::InPointer.from_array e, [:bar, :foo, :baz]
|
24
|
-
ptr.read_array_of_int32(3).must_equal [1, 0, 2]
|
24
|
+
_(ptr.read_array_of_int32(3)).must_equal [1, 0, 2]
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it "handles struct types" do
|
28
28
|
e = Class.new(GirFFI::StructBase) do
|
29
29
|
self::Struct = Class.new(GirFFI::Struct) do
|
30
30
|
layout :foo, :int32, :bar, :int32
|
@@ -34,109 +34,109 @@ describe GirFFI::InPointer do
|
|
34
34
|
struct[:foo] = 42
|
35
35
|
struct[:bar] = 24
|
36
36
|
ptr = GirFFI::InPointer.from_array e, [struct]
|
37
|
-
ptr.wont_be :==, struct.to_ptr
|
37
|
+
_(ptr).wont_be :==, struct.to_ptr
|
38
38
|
new_struct = e::Struct.new ptr
|
39
|
-
new_struct[:foo].must_equal 42
|
40
|
-
new_struct[:bar].must_equal 24
|
39
|
+
_(new_struct[:foo]).must_equal 42
|
40
|
+
_(new_struct[:bar]).must_equal 24
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it "handles typed pointers" do
|
44
44
|
p1 = GirFFI::InPointer.from :gint32, 42
|
45
45
|
p2 = GirFFI::InPointer.from :gint32, 24
|
46
46
|
|
47
47
|
ptr = GirFFI::InPointer.from_array [:pointer, :gint32], [p1, p2]
|
48
48
|
|
49
|
-
ptr.read_array_of_pointer(2).must_equal [p1, p2]
|
49
|
+
_(ptr.read_array_of_pointer(2)).must_equal [p1, p2]
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
52
|
+
it "handles pointer casting" do
|
53
53
|
ptr = GirFFI::InPointer.from_array [:pointer, :gint32], [42, 24]
|
54
54
|
|
55
|
-
ptr.read_array_of_pointer(2).map(&:address).must_equal [42, 24]
|
55
|
+
_(ptr.read_array_of_pointer(2).map(&:address)).must_equal [42, 24]
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
describe
|
59
|
+
describe "an instance created with .from_array :gint32" do
|
60
60
|
before do
|
61
61
|
@result = GirFFI::InPointer.from_array :gint32, [24, 13]
|
62
62
|
end
|
63
63
|
|
64
|
-
it
|
64
|
+
it "holds a pointer to the correct input values" do
|
65
65
|
assert_equal 24, @result.get_int(0)
|
66
66
|
assert_equal 13, @result.get_int(4)
|
67
67
|
end
|
68
68
|
|
69
|
-
it
|
70
|
-
@result.must_be_instance_of FFI::MemoryPointer
|
69
|
+
it "is an instance of FFI::MemoryPointer" do
|
70
|
+
_(@result).must_be_instance_of FFI::MemoryPointer
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
73
|
+
it "is zero-terminated" do
|
74
74
|
assert_equal 0, @result.get_int(8)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
describe
|
78
|
+
describe "an instance created with .from_array :utf8" do
|
79
79
|
before do
|
80
80
|
@result = GirFFI::InPointer.from_array :utf8, %w(foo bar baz)
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it "returns an array of pointers to strings" do
|
84
84
|
ary = @result.read_array_of_pointer(3)
|
85
85
|
assert_equal %w(foo bar baz), ary.map(&:read_string)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
describe
|
89
|
+
describe "an instance created with .from_array :filename" do
|
90
90
|
before do
|
91
91
|
@result = GirFFI::InPointer.from_array :filename, %w(foo bar baz)
|
92
92
|
end
|
93
93
|
|
94
|
-
it
|
94
|
+
it "returns an array of pointers to strings" do
|
95
95
|
ary = @result.read_array_of_pointer(3)
|
96
96
|
assert_equal %w(foo bar baz), ary.map(&:read_string)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
describe
|
100
|
+
describe "an instance created with .from :utf8" do
|
101
101
|
before do
|
102
|
-
@result = GirFFI::InPointer.from :utf8,
|
102
|
+
@result = GirFFI::InPointer.from :utf8, "foo"
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
106
|
-
assert_equal
|
105
|
+
it "returns a pointer to the given string" do
|
106
|
+
assert_equal "foo", @result.read_string
|
107
107
|
end
|
108
108
|
|
109
|
-
it
|
110
|
-
@result.must_be_instance_of FFI::MemoryPointer
|
109
|
+
it "is an instance of FFI::MemoryPointer" do
|
110
|
+
_(@result).must_be_instance_of FFI::MemoryPointer
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
describe
|
114
|
+
describe "an instance created with .from :guint32" do
|
115
115
|
before do
|
116
116
|
@result = GirFFI::InPointer.from :guint32, 12_345
|
117
117
|
end
|
118
118
|
|
119
|
-
it
|
119
|
+
it "returns a pointer with an address equal to the given value" do
|
120
120
|
assert_equal 12_345, @result.address
|
121
121
|
end
|
122
122
|
|
123
|
-
it
|
124
|
-
@result.must_be_instance_of FFI::Pointer
|
123
|
+
it "is an instance of FFI::Pointer" do
|
124
|
+
_(@result).must_be_instance_of FFI::Pointer
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
describe
|
128
|
+
describe "an instance created with .from :filename" do
|
129
129
|
before do
|
130
|
-
@result = GirFFI::InPointer.from :filename,
|
130
|
+
@result = GirFFI::InPointer.from :filename, "foo"
|
131
131
|
end
|
132
132
|
|
133
|
-
it
|
134
|
-
assert_equal
|
133
|
+
it "returns a pointer to the given string" do
|
134
|
+
assert_equal "foo", @result.read_string
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
describe
|
139
|
-
it
|
138
|
+
describe ".from" do
|
139
|
+
it "returns nil when passed nil" do
|
140
140
|
result = GirFFI::InPointer.from :foo, nil
|
141
141
|
assert_nil result
|
142
142
|
end
|
@@ -146,37 +146,57 @@ describe GirFFI::InPointer do
|
|
146
146
|
assert_equal 23, result.address
|
147
147
|
end
|
148
148
|
|
149
|
-
it
|
149
|
+
it "returns a pointer to the value for type :gint64" do
|
150
|
+
result = GirFFI::InPointer.from :gint64, -0x90000000
|
151
|
+
assert_equal(-0x90000000, result.get_int64(0))
|
152
|
+
end
|
153
|
+
|
154
|
+
it "returns a pointer to the value for type :guint64" do
|
155
|
+
result = GirFFI::InPointer.from :guint64, 0xf0000000
|
156
|
+
assert_equal 0xf0000000, result.get_uint64(0)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "returns a pointer to the value for type :gdouble" do
|
160
|
+
result = GirFFI::InPointer.from :gdouble, 0.1
|
161
|
+
assert_in_epsilon 0.1, result.read_double
|
162
|
+
end
|
163
|
+
|
164
|
+
it "returns a pointer to the value for type :gfloat" do
|
165
|
+
result = GirFFI::InPointer.from :gfloat, 0.1
|
166
|
+
assert_in_epsilon 0.1, result.read_float
|
167
|
+
end
|
168
|
+
|
169
|
+
it "handles enum types" do
|
150
170
|
e = Module.new do
|
151
171
|
extend GirFFI::EnumBase
|
152
172
|
self::Enum = FFI::Enum.new [:foo, :bar, :baz], :qux
|
153
173
|
end
|
154
174
|
ptr = GirFFI::InPointer.from e, :bar
|
155
|
-
ptr.address.must_equal 1
|
175
|
+
_(ptr.address).must_equal 1
|
156
176
|
end
|
157
177
|
|
158
|
-
describe
|
159
|
-
it
|
178
|
+
describe "for type :void" do
|
179
|
+
it "returns the result of to_ptr" do
|
160
180
|
obj = Object.new
|
161
181
|
def obj.to_ptr
|
162
182
|
:test_value
|
163
183
|
end
|
164
|
-
GirFFI::InPointer.from(:void, obj).must_equal :test_value
|
184
|
+
_(GirFFI::InPointer.from(:void, obj)).must_equal :test_value
|
165
185
|
end
|
166
186
|
|
167
|
-
it
|
168
|
-
GirFFI::InPointer.from(:void, nil).must_be_nil
|
187
|
+
it "returns nil when passed nil" do
|
188
|
+
_(GirFFI::InPointer.from(:void, nil)).must_be_nil
|
169
189
|
end
|
170
190
|
end
|
171
191
|
|
172
|
-
describe
|
173
|
-
it
|
192
|
+
describe "for types that are classes" do
|
193
|
+
it "returns the result of to_ptr" do
|
174
194
|
klass = Class.new
|
175
195
|
obj = klass.new
|
176
196
|
def obj.to_ptr
|
177
197
|
:test_value
|
178
198
|
end
|
179
|
-
GirFFI::InPointer.from(klass, obj).must_equal :test_value
|
199
|
+
_(GirFFI::InPointer.from(klass, obj)).must_equal :test_value
|
180
200
|
end
|
181
201
|
end
|
182
202
|
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::ICallableInfo do
|
6
6
|
let(:info_class) do
|
@@ -10,16 +10,16 @@ describe GirFFI::InfoExt::ICallableInfo do
|
|
10
10
|
end
|
11
11
|
let(:callable_info) { info_class.new }
|
12
12
|
|
13
|
-
describe
|
14
|
-
describe
|
13
|
+
describe "#argument_ffi_types" do
|
14
|
+
describe "for a simple callable with several arguments" do
|
15
15
|
before do
|
16
16
|
allow(arg_info1 = Object.new).to receive(:to_ffi_type).and_return :type1
|
17
17
|
allow(arg_info2 = Object.new).to receive(:to_ffi_type).and_return :type2
|
18
18
|
allow(callable_info).to receive(:args).and_return [arg_info1, arg_info2]
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
callable_info.argument_ffi_types.must_equal [:type1, :type2]
|
21
|
+
it "returns the ffi types of the arguments" do
|
22
|
+
_(callable_info.argument_ffi_types).must_equal [:type1, :type2]
|
23
23
|
end
|
24
24
|
end
|
25
25
|
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::ICallbackInfo do
|
6
6
|
let(:callback_class) do
|
@@ -10,12 +10,12 @@ describe GirFFI::InfoExt::ICallbackInfo do
|
|
10
10
|
end
|
11
11
|
let(:callback_info) { callback_class.new }
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
13
|
+
describe "#return_ffi_type" do
|
14
|
+
it "returns the callback ffi type of the return type" do
|
15
15
|
allow(return_type_info = Object.new).to receive(:to_callback_ffi_type).and_return :some_type
|
16
16
|
allow(callback_info).to receive(:return_type).and_return return_type_info
|
17
17
|
|
18
|
-
callback_info.return_ffi_type.must_equal :some_type
|
18
|
+
_(callback_info.return_ffi_type).must_equal :some_type
|
19
19
|
end
|
20
20
|
end
|
21
21
|
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::IFieldInfo do
|
6
6
|
let(:info_class) do
|
@@ -9,11 +9,11 @@ describe GirFFI::InfoExt::IFieldInfo do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
let(:field_info) { info_class.new }
|
12
|
-
describe
|
13
|
-
it
|
12
|
+
describe "#layout_specification" do
|
13
|
+
it "returns an array of name, typespec and offset" do
|
14
14
|
expect(type = Object.new).to receive(:to_ffi_type).and_return :bar
|
15
15
|
|
16
|
-
expect(field_info).to receive(:name).and_return
|
16
|
+
expect(field_info).to receive(:name).and_return "foo"
|
17
17
|
expect(field_info).to receive(:field_type).and_return type
|
18
18
|
expect(field_info).to receive(:offset).and_return 0
|
19
19
|
|
@@ -22,10 +22,10 @@ describe GirFFI::InfoExt::IFieldInfo do
|
|
22
22
|
assert_equal [:foo, :bar, 0], result
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it "keeps a complex typespec intact" do
|
26
26
|
expect(type = Object.new).to receive(:to_ffi_type).and_return [:bar, 2]
|
27
27
|
|
28
|
-
expect(field_info).to receive(:name).and_return
|
28
|
+
expect(field_info).to receive(:name).and_return "foo"
|
29
29
|
expect(field_info).to receive(:field_type).and_return type
|
30
30
|
expect(field_info).to receive(:offset).and_return 0
|
31
31
|
|
@@ -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::IFunctionInfo do
|
6
6
|
let(:info_class) do
|
@@ -11,64 +11,64 @@ describe GirFFI::InfoExt::IFunctionInfo do
|
|
11
11
|
end
|
12
12
|
let(:function_info) { info_class.new }
|
13
13
|
|
14
|
-
describe
|
14
|
+
describe "#argument_ffi_types" do
|
15
15
|
before do
|
16
16
|
allow(arg_info1 = Object.new).to receive(:to_ffi_type).and_return :type1
|
17
17
|
allow(arg_info2 = Object.new).to receive(:to_ffi_type).and_return :type2
|
18
18
|
allow(function_info).to receive(:args).and_return [arg_info1, arg_info2]
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
21
|
+
describe "for a simple function with several arguments" do
|
22
22
|
before do
|
23
23
|
allow(function_info).to receive(:method?).and_return false
|
24
24
|
allow(function_info).to receive(:throws?).and_return false
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
function_info.argument_ffi_types.must_equal [:type1, :type2]
|
27
|
+
it "returns the ffi types of the arguments" do
|
28
|
+
_(function_info.argument_ffi_types).must_equal [:type1, :type2]
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
32
|
+
describe "for a throwing function with several arguments" do
|
33
33
|
before do
|
34
34
|
allow(function_info).to receive(:method?).and_return false
|
35
35
|
allow(function_info).to receive(:throws?).and_return true
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
39
|
-
function_info.argument_ffi_types.must_equal [:type1, :type2, :pointer]
|
38
|
+
it "appends :pointer to represent the error argument" do
|
39
|
+
_(function_info.argument_ffi_types).must_equal [:type1, :type2, :pointer]
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe
|
43
|
+
describe "for a method with several arguments" do
|
44
44
|
before do
|
45
45
|
allow(function_info).to receive(:method?).and_return true
|
46
46
|
allow(function_info).to receive(:throws?).and_return false
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
50
|
-
function_info.argument_ffi_types.must_equal [:pointer, :type1, :type2]
|
49
|
+
it "prepends :pointer to represent the method reciever" do
|
50
|
+
_(function_info.argument_ffi_types).must_equal [:pointer, :type1, :type2]
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
54
|
+
describe "for a throwing method with several arguments" do
|
55
55
|
before do
|
56
56
|
allow(function_info).to receive(:method?).and_return true
|
57
57
|
allow(function_info).to receive(:throws?).and_return true
|
58
58
|
end
|
59
59
|
|
60
|
-
it
|
61
|
-
function_info.argument_ffi_types.must_equal [:pointer, :type1, :type2, :pointer]
|
60
|
+
it "adds :pointer for both the reciever and the error argument" do
|
61
|
+
_(function_info.argument_ffi_types).must_equal [:pointer, :type1, :type2, :pointer]
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
describe
|
67
|
-
it
|
66
|
+
describe "#return_ffi_type" do
|
67
|
+
it "returns the ffi type of the return type" do
|
68
68
|
allow(return_type_info = Object.new).to receive(:to_ffi_type).and_return :some_type
|
69
69
|
allow(function_info).to receive(:return_type).and_return return_type_info
|
70
70
|
|
71
|
-
function_info.return_ffi_type.must_equal :some_type
|
71
|
+
_(function_info.return_ffi_type).must_equal :some_type
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|