gir_ffi 0.15.3 → 0.15.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +15 -0
- data/README.md +5 -6
- data/TODO.md +14 -35
- data/docs/Documentation.md +6 -0
- data/docs/Subclassing.md +38 -0
- data/lib/ffi-glib.rb +8 -3
- data/lib/ffi-glib/byte_array.rb +2 -1
- data/lib/ffi-glib/destroy_notify.rb +2 -2
- data/lib/ffi-glib/hash_table.rb +1 -2
- data/lib/ffi-glib/list.rb +11 -5
- data/lib/ffi-glib/list_methods.rb +12 -0
- data/lib/ffi-glib/s_list.rb +10 -4
- data/lib/ffi-gobject.rb +0 -3
- data/lib/ffi-gobject/object.rb +77 -73
- data/lib/ffi-gobject/object_class.rb +1 -1
- data/lib/ffi-gobject/value.rb +107 -108
- data/lib/ffi-gobject_introspection/i_base_info.rb +20 -19
- data/lib/gir_ffi-base/gobject/lib.rb +4 -0
- data/lib/gir_ffi/array_element_convertor.rb +1 -2
- data/lib/gir_ffi/boxed_base.rb +1 -5
- data/lib/gir_ffi/builder.rb +1 -1
- data/lib/gir_ffi/builder_helper.rb +7 -4
- data/lib/gir_ffi/builders/base_argument_builder.rb +2 -2
- data/lib/gir_ffi/builders/base_method_builder.rb +1 -1
- data/lib/gir_ffi/builders/base_type_builder.rb +1 -1
- data/lib/gir_ffi/builders/callback_argument_builder.rb +2 -0
- data/lib/gir_ffi/builders/callback_builder.rb +14 -12
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +4 -6
- data/lib/gir_ffi/builders/class_struct_builder.rb +24 -0
- data/lib/gir_ffi/builders/enum_builder.rb +3 -3
- data/lib/gir_ffi/builders/interface_builder.rb +3 -1
- data/lib/gir_ffi/builders/mapping_method_builder.rb +1 -1
- data/lib/gir_ffi/builders/marshalling_method_builder.rb +5 -2
- data/lib/gir_ffi/builders/method_template.rb +4 -4
- data/lib/gir_ffi/builders/null_argument_builder.rb +0 -2
- data/lib/gir_ffi/builders/null_return_value_builder.rb +0 -2
- data/lib/gir_ffi/builders/object_builder.rb +16 -6
- data/lib/gir_ffi/builders/property_builder.rb +1 -2
- data/lib/gir_ffi/builders/signal_closure_builder.rb +3 -5
- data/lib/gir_ffi/builders/struct_builder.rb +5 -5
- data/lib/gir_ffi/builders/user_defined_builder.rb +8 -1
- data/lib/gir_ffi/builders/vfunc_argument_builder.rb +1 -1
- data/lib/gir_ffi/callback_base.rb +3 -3
- data/lib/gir_ffi/core.rb +17 -2
- data/lib/gir_ffi/glib_error.rb +1 -2
- data/lib/gir_ffi/in_pointer.rb +7 -0
- data/lib/gir_ffi/object_base.rb +27 -0
- data/lib/gir_ffi/return_value_info.rb +1 -2
- data/lib/gir_ffi/struct_base.rb +1 -9
- data/lib/gir_ffi/struct_like_base.rb +9 -5
- data/lib/gir_ffi/unintrospectable_type_info.rb +1 -1
- data/lib/gir_ffi/union_base.rb +1 -9
- data/lib/gir_ffi/user_defined_object_info.rb +3 -2
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi/vfunc_implementation.rb +1 -0
- metadata +86 -136
- data/Gemfile +0 -14
- data/Rakefile +0 -9
- data/tasks/test.rake +0 -204
- data/test/base_test_helper.rb +0 -70
- data/test/ffi-glib/array_test.rb +0 -203
- data/test/ffi-glib/byte_array_test.rb +0 -28
- data/test/ffi-glib/bytes_test.rb +0 -61
- data/test/ffi-glib/closure_test.rb +0 -38
- data/test/ffi-glib/destroy_notify_test.rb +0 -18
- data/test/ffi-glib/hash_table_test.rb +0 -68
- data/test/ffi-glib/list_test.rb +0 -86
- data/test/ffi-glib/main_loop_test.rb +0 -53
- data/test/ffi-glib/ptr_array_test.rb +0 -112
- data/test/ffi-glib/ruby_closure_test.rb +0 -62
- data/test/ffi-glib/s_list_test.rb +0 -76
- data/test/ffi-glib/strv_test.rb +0 -60
- data/test/ffi-glib/variant_test.rb +0 -12
- data/test/ffi-gobject/gobject_test.rb +0 -76
- data/test/ffi-gobject/object_class_test.rb +0 -31
- data/test/ffi-gobject/object_test.rb +0 -123
- data/test/ffi-gobject/param_spec_test.rb +0 -32
- data/test/ffi-gobject/value_test.rb +0 -390
- data/test/ffi-gobject_introspection/gobject_type_init_test.rb +0 -26
- data/test/ffi-gobject_introspection/i_base_info_test.rb +0 -52
- data/test/ffi-gobject_introspection/i_constant_info_test.rb +0 -29
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +0 -18
- data/test/ffi-gobject_introspection/i_function_info_test.rb +0 -6
- data/test/ffi-gobject_introspection/i_interface_info_test.rb +0 -23
- data/test/ffi-gobject_introspection/i_object_info_test.rb +0 -49
- data/test/ffi-gobject_introspection/i_property_info_test.rb +0 -47
- data/test/ffi-gobject_introspection/i_registered_type_info_test.rb +0 -27
- data/test/ffi-gobject_introspection/i_repository_test.rb +0 -81
- data/test/ffi-gobject_introspection/i_struct_info_test.rb +0 -23
- data/test/ffi-gobject_introspection/i_type_info_test.rb +0 -30
- data/test/ffi-gobject_introspection/i_union_info_test.rb +0 -17
- data/test/ffi-gobject_introspection/i_vfunc_info_test.rb +0 -41
- data/test/ffi-gobject_introspection/lib_test.rb +0 -13
- data/test/ffi-gobject_introspection/strv_test.rb +0 -46
- data/test/ffi-gobject_test.rb +0 -153
- data/test/gir_ffi/allocation_helper_test.rb +0 -36
- data/test/gir_ffi/arg_helper_test.rb +0 -146
- data/test/gir_ffi/boolean_test.rb +0 -43
- data/test/gir_ffi/boxed_base_test.rb +0 -65
- data/test/gir_ffi/builder_test.rb +0 -168
- data/test/gir_ffi/builders/argument_builder_test.rb +0 -691
- data/test/gir_ffi/builders/base_argument_builder_test.rb +0 -6
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +0 -130
- data/test/gir_ffi/builders/callback_builder_test.rb +0 -117
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +0 -84
- data/test/gir_ffi/builders/constant_builder_test.rb +0 -6
- data/test/gir_ffi/builders/constructor_builder_test.rb +0 -39
- data/test/gir_ffi/builders/enum_builder_test.rb +0 -23
- data/test/gir_ffi/builders/field_builder_test.rb +0 -140
- data/test/gir_ffi/builders/function_builder_test.rb +0 -570
- data/test/gir_ffi/builders/initializer_builder_test.rb +0 -56
- data/test/gir_ffi/builders/interface_builder_test.rb +0 -32
- data/test/gir_ffi/builders/module_builder_test.rb +0 -43
- data/test/gir_ffi/builders/object_builder_test.rb +0 -98
- data/test/gir_ffi/builders/property_builder_test.rb +0 -161
- data/test/gir_ffi/builders/registered_type_builder_test.rb +0 -54
- data/test/gir_ffi/builders/return_value_builder_test.rb +0 -444
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +0 -199
- data/test/gir_ffi/builders/struct_builder_test.rb +0 -96
- data/test/gir_ffi/builders/unintrospectable_boxed_builder_test.rb +0 -29
- data/test/gir_ffi/builders/unintrospectable_builder_test.rb +0 -84
- data/test/gir_ffi/builders/union_builder_test.rb +0 -28
- data/test/gir_ffi/builders/user_defined_builder_test.rb +0 -528
- data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +0 -107
- data/test/gir_ffi/builders/vfunc_builder_test.rb +0 -245
- data/test/gir_ffi/callback_base_test.rb +0 -22
- data/test/gir_ffi/class_base_test.rb +0 -171
- data/test/gir_ffi/core_test.rb +0 -99
- data/test/gir_ffi/enum_base_test.rb +0 -43
- data/test/gir_ffi/error_type_info_test.rb +0 -50
- data/test/gir_ffi/ffi_ext/pointer_test.rb +0 -22
- data/test/gir_ffi/g_type_test.rb +0 -31
- data/test/gir_ffi/in_pointer_test.rb +0 -203
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +0 -26
- data/test/gir_ffi/info_ext/i_callback_info_test.rb +0 -22
- data/test/gir_ffi/info_ext/i_field_info_test.rb +0 -37
- data/test/gir_ffi/info_ext/i_function_info_test.rb +0 -74
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +0 -32
- data/test/gir_ffi/info_ext/i_type_info_test.rb +0 -712
- data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +0 -19
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +0 -26
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +0 -26
- data/test/gir_ffi/interface_base_test.rb +0 -20
- data/test/gir_ffi/method_stubber_test.rb +0 -67
- data/test/gir_ffi/object_base_test.rb +0 -64
- data/test/gir_ffi/object_store_test.rb +0 -41
- data/test/gir_ffi/receiver_argument_info_test.rb +0 -33
- data/test/gir_ffi/sized_array_test.rb +0 -206
- data/test/gir_ffi/struct_base_test.rb +0 -23
- data/test/gir_ffi/struct_like_base_test.rb +0 -167
- data/test/gir_ffi/type_map_test.rb +0 -17
- data/test/gir_ffi/unintrospectable_type_info_test.rb +0 -121
- data/test/gir_ffi/union_base_test.rb +0 -23
- data/test/gir_ffi/user_defined_object_info_test.rb +0 -119
- data/test/gir_ffi/user_defined_property_info_test.rb +0 -39
- data/test/gir_ffi/variable_name_generator_test.rb +0 -18
- data/test/gir_ffi/version_test.rb +0 -9
- data/test/gir_ffi/zero_terminated_test.rb +0 -108
- data/test/gir_ffi_test_helper.rb +0 -84
- data/test/integration/callback_exceptions_test.rb +0 -59
- data/test/integration/derived_classes_test.rb +0 -54
- data/test/integration/generated_everything_test.rb +0 -453
- data/test/integration/generated_gimarshallingtests_test.rb +0 -3109
- data/test/integration/generated_gio_test.rb +0 -116
- data/test/integration/generated_glib_test.rb +0 -10
- data/test/integration/generated_gobject_test.rb +0 -124
- data/test/integration/generated_gst_test.rb +0 -38
- data/test/integration/generated_gtk_source_test.rb +0 -21
- data/test/integration/generated_gtop_test.rb +0 -22
- data/test/integration/generated_pango_ft2_test.rb +0 -17
- data/test/integration/generated_pango_test.rb +0 -24
- data/test/integration/generated_regress_test.rb +0 -4076
- data/test/integration/generated_secret_test.rb +0 -14
- data/test/integration/generated_utility_test.rb +0 -174
- data/test/integration/generated_warnlib_test.rb +0 -45
- data/test/integration/method_lookup_test.rb +0 -34
- data/test/introspection_test_helper.rb +0 -94
- data/test/lib/Makefile.am +0 -110
- data/test/lib/autogen.sh +0 -4
- data/test/lib/configure.ac +0 -34
- data/test/lib/m4/jhflags.m4 +0 -21
- data/test/minitest/stats_plugin.rb +0 -30
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GLib::Variant do
|
6
|
-
describe "#get_string" do
|
7
|
-
it "returns just the contained string" do
|
8
|
-
var = GLib::Variant.new_string("Foo")
|
9
|
-
_(var.get_string).must_equal "Foo"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
require "ffi-gobject"
|
6
|
-
|
7
|
-
GirFFI.setup :GIMarshallingTests
|
8
|
-
|
9
|
-
describe GObject do
|
10
|
-
describe ".type_init" do
|
11
|
-
it "does not raise an error" do
|
12
|
-
GObject.type_init
|
13
|
-
pass
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "has constants for the fundamental GTypes" do
|
18
|
-
_(GObject::TYPE_INVALID).must_equal GObject.type_from_name("invalid")
|
19
|
-
_(GObject.type_name(GObject::TYPE_INVALID)).must_be_nil
|
20
|
-
|
21
|
-
_(GObject.type_name(GObject::TYPE_NONE)).must_equal "void"
|
22
|
-
_(GObject.type_name(GObject::TYPE_INTERFACE)).must_equal "GInterface"
|
23
|
-
_(GObject.type_name(GObject::TYPE_CHAR)).must_equal "gchar"
|
24
|
-
_(GObject.type_name(GObject::TYPE_UCHAR)).must_equal "guchar"
|
25
|
-
_(GObject.type_name(GObject::TYPE_BOOLEAN)).must_equal "gboolean"
|
26
|
-
_(GObject.type_name(GObject::TYPE_INT)).must_equal "gint"
|
27
|
-
_(GObject.type_name(GObject::TYPE_UINT)).must_equal "guint"
|
28
|
-
_(GObject.type_name(GObject::TYPE_LONG)).must_equal "glong"
|
29
|
-
_(GObject.type_name(GObject::TYPE_ULONG)).must_equal "gulong"
|
30
|
-
_(GObject.type_name(GObject::TYPE_INT64)).must_equal "gint64"
|
31
|
-
_(GObject.type_name(GObject::TYPE_UINT64)).must_equal "guint64"
|
32
|
-
_(GObject.type_name(GObject::TYPE_ENUM)).must_equal "GEnum"
|
33
|
-
_(GObject.type_name(GObject::TYPE_FLAGS)).must_equal "GFlags"
|
34
|
-
_(GObject.type_name(GObject::TYPE_FLOAT)).must_equal "gfloat"
|
35
|
-
_(GObject.type_name(GObject::TYPE_DOUBLE)).must_equal "gdouble"
|
36
|
-
_(GObject.type_name(GObject::TYPE_STRING)).must_equal "gchararray"
|
37
|
-
_(GObject.type_name(GObject::TYPE_POINTER)).must_equal "gpointer"
|
38
|
-
_(GObject.type_name(GObject::TYPE_BOXED)).must_equal "GBoxed"
|
39
|
-
_(GObject.type_name(GObject::TYPE_PARAM)).must_equal "GParam"
|
40
|
-
_(GObject.type_name(GObject::TYPE_OBJECT)).must_equal "GObject"
|
41
|
-
_(GObject.type_name(GObject::TYPE_GTYPE)).must_equal "GType"
|
42
|
-
_(GObject.type_name(GObject::TYPE_VARIANT)).must_equal "GVariant"
|
43
|
-
|
44
|
-
_(GObject.type_name(GObject::TYPE_ARRAY)).must_equal "GArray"
|
45
|
-
_(GObject.type_name(GObject::TYPE_BYTE_ARRAY)).must_equal "GByteArray"
|
46
|
-
_(GObject.type_name(GObject::TYPE_ERROR)).must_equal "GError"
|
47
|
-
_(GObject.type_name(GObject::TYPE_HASH_TABLE)).must_equal "GHashTable"
|
48
|
-
_(GObject.type_name(GObject::TYPE_STRV)).must_equal "GStrv"
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "::object_class_from_instance" do
|
52
|
-
it "returns a GObject::ObjectClass with the correct GType" do
|
53
|
-
obj = GIMarshallingTests::OverridesObject.new
|
54
|
-
object_class = GObject.object_class_from_instance obj
|
55
|
-
gtype = object_class.g_type_class.g_type
|
56
|
-
|
57
|
-
_(object_class).must_be_instance_of GObject::ObjectClass
|
58
|
-
_(gtype).must_equal GIMarshallingTests::OverridesObject.gtype
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "creating ParamSpecs" do
|
63
|
-
describe "#param_spec_int" do
|
64
|
-
it "creates a GObject::ParamSpecInt" do
|
65
|
-
spec = GObject.param_spec_int("foo", "foo bar",
|
66
|
-
"The Foo Bar Property",
|
67
|
-
10, 20, 15,
|
68
|
-
3)
|
69
|
-
_(spec).must_be_instance_of GObject::ParamSpecInt
|
70
|
-
_(spec.struct[:minimum]).must_equal 10
|
71
|
-
_(spec.struct[:maximum]).must_equal 20
|
72
|
-
_(spec.get_default_value).must_equal 15
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
require "ffi-gobject"
|
6
|
-
|
7
|
-
describe GObject::ObjectClass do
|
8
|
-
describe "#list_properties" do
|
9
|
-
it "returns GIMarshallingTests::OverridesObject's properties" do
|
10
|
-
obj = GIMarshallingTests::OverridesObject.new
|
11
|
-
object_class = GObject.object_class_from_instance obj
|
12
|
-
|
13
|
-
info = get_introspection_data "GIMarshallingTests", "OverridesObject"
|
14
|
-
expected_props = info.properties.map(&:name)
|
15
|
-
expected_props += info.parent.properties.map(&:name)
|
16
|
-
|
17
|
-
props = object_class.list_properties
|
18
|
-
prop_names = props.map(&:get_name)
|
19
|
-
|
20
|
-
_(prop_names.sort).must_equal expected_props.sort
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#gtype" do
|
25
|
-
it "returns the correct GType" do
|
26
|
-
obj = GIMarshallingTests::OverridesObject.new
|
27
|
-
object_class = GObject.object_class_from_instance obj
|
28
|
-
_(object_class.gtype).must_equal GIMarshallingTests::OverridesObject.gtype
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
require "ffi-gobject"
|
6
|
-
GirFFI.setup :GIMarshallingTests
|
7
|
-
|
8
|
-
describe GObject::Object do
|
9
|
-
describe ".new" do
|
10
|
-
it "is overridden to take only one argument" do
|
11
|
-
_(GObject::Object.new({})).must_be_instance_of GObject::Object
|
12
|
-
end
|
13
|
-
|
14
|
-
it "can be used to create objects with properties" do
|
15
|
-
obj = GIMarshallingTests::SubObject.new(int: 13)
|
16
|
-
_(obj.int).must_equal 13
|
17
|
-
end
|
18
|
-
|
19
|
-
it "allows omission of the first argument" do
|
20
|
-
_(GObject::Object.new).must_be_instance_of GObject::Object
|
21
|
-
end
|
22
|
-
|
23
|
-
it "raises an error for properties that do not exist" do
|
24
|
-
_(proc { GObject::Object.new(dog: "bark") }).must_raise GirFFI::PropertyNotFoundError
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#get_property" do
|
29
|
-
it "is overridden to have arity 1" do
|
30
|
-
_(GObject::Object.instance_method("get_property").arity).must_equal 1
|
31
|
-
end
|
32
|
-
|
33
|
-
it "raises an error for a property that does not exist" do
|
34
|
-
instance = GObject::Object.new
|
35
|
-
_(proc { instance.get_property "foo-bar" }).must_raise GirFFI::PropertyNotFoundError
|
36
|
-
end
|
37
|
-
|
38
|
-
it "raises an error for a property that does not exist" do
|
39
|
-
instance = GObject::Object.new
|
40
|
-
_(proc { instance.get_property "foo-bar" })
|
41
|
-
.must_raise GirFFI::PropertyNotFoundError
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#get_property_extended" do
|
46
|
-
it "raises an error for a property that does not exist" do
|
47
|
-
instance = GObject::Object.new
|
48
|
-
_(proc { instance.get_property_extended "foo-bar" })
|
49
|
-
.must_raise GirFFI::PropertyNotFoundError
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#set_property" do
|
54
|
-
it "raises an error for a property that does not exist" do
|
55
|
-
instance = GObject::Object.new
|
56
|
-
_(proc { instance.set_property "foo-bar", 123 })
|
57
|
-
.must_raise GirFFI::PropertyNotFoundError
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#set_property_extended" do
|
62
|
-
it "raises an error for a property that does not exist" do
|
63
|
-
instance = GObject::Object.new
|
64
|
-
_(proc { instance.set_property_extended "foo-bar", 123 })
|
65
|
-
.must_raise GirFFI::PropertyNotFoundError
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "#signal_connect" do
|
70
|
-
subject { GObject::Object.new }
|
71
|
-
|
72
|
-
it "delegates to GObject" do
|
73
|
-
expect(GObject).to receive(:signal_connect).with(subject, "some-event", nil)
|
74
|
-
subject.signal_connect("some-event") do
|
75
|
-
nothing
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it "delegates to GObject if an optional data argument is passed" do
|
80
|
-
expect(GObject).to receive(:signal_connect).with(subject, "some-event", "data")
|
81
|
-
subject.signal_connect("some-event", "data") do
|
82
|
-
nothing
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "#signal_connect_after" do
|
88
|
-
subject { GObject::Object.new }
|
89
|
-
|
90
|
-
it "delegates to GObject" do
|
91
|
-
expect(GObject).to receive(:signal_connect_after).with(subject, "some-event", nil)
|
92
|
-
subject.signal_connect_after("some-event") do
|
93
|
-
nothing
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
it "delegates to GObject if an optional data argument is passed" do
|
98
|
-
expect(GObject).to receive(:signal_connect_after).with(subject, "some-event", "data")
|
99
|
-
subject.signal_connect_after("some-event", "data") do
|
100
|
-
nothing
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "upon garbage collection" do
|
106
|
-
it "lowers the reference count" do
|
107
|
-
skip "cannot be reliably tested on JRuby" if jruby?
|
108
|
-
|
109
|
-
ptr = GObject::Object.new.to_ptr
|
110
|
-
_(object_ref_count(ptr)).must_equal 1
|
111
|
-
|
112
|
-
GC.start
|
113
|
-
# Creating a new object is sometimes needed to trigger enough garbage collection.
|
114
|
-
GObject::Object.new
|
115
|
-
sleep 1
|
116
|
-
|
117
|
-
GC.start
|
118
|
-
GC.start
|
119
|
-
|
120
|
-
_(object_ref_count(ptr)).must_equal 0
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
require "ffi-gobject"
|
6
|
-
describe GObject::ParamSpec do
|
7
|
-
let(:pspec) do
|
8
|
-
GObject.param_spec_int("foo-bar", "foo bar",
|
9
|
-
"Foo Bar",
|
10
|
-
1, 3, 2,
|
11
|
-
readable: true, writable: true)
|
12
|
-
end
|
13
|
-
let(:pspec_struct) { GObject::ParamSpec::Struct.new(pspec.to_ptr) }
|
14
|
-
|
15
|
-
describe "#ref" do
|
16
|
-
it "increases the ref count" do
|
17
|
-
old = pspec_struct[:ref_count]
|
18
|
-
pspec.ref
|
19
|
-
_(pspec_struct[:ref_count]).must_equal old + 1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#accessor_name" do
|
24
|
-
it "returns a safe ruby method name" do
|
25
|
-
_(pspec.accessor_name).must_equal "foo_bar"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it "cannot be instantiated directly" do
|
30
|
-
_(proc { GObject::ParamSpec.new }).must_raise NoMethodError
|
31
|
-
end
|
32
|
-
end
|
@@ -1,390 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
GirFFI.setup :Regress
|
6
|
-
GirFFI.setup :Gio
|
7
|
-
|
8
|
-
describe GObject::Value do
|
9
|
-
describe "::Struct" do
|
10
|
-
describe "layout" do
|
11
|
-
let(:layout) { GObject::Value::Struct.layout }
|
12
|
-
|
13
|
-
it "consists of :g_type and :data" do
|
14
|
-
_(layout.members).must_equal [:g_type, :data]
|
15
|
-
end
|
16
|
-
|
17
|
-
it "has an array as its second element" do
|
18
|
-
types = layout.fields.map(&:type)
|
19
|
-
_(types[1].class).must_equal FFI::Type::Array
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe ".for_gtype" do
|
25
|
-
it "handles char" do
|
26
|
-
gv = GObject::Value.for_gtype GObject::TYPE_CHAR
|
27
|
-
_(gv.current_gtype).must_equal GObject::TYPE_CHAR
|
28
|
-
end
|
29
|
-
|
30
|
-
it "handles invalid type" do
|
31
|
-
gv = GObject::Value.for_gtype GObject::TYPE_INVALID
|
32
|
-
_(gv.current_gtype).must_equal GObject::TYPE_INVALID
|
33
|
-
end
|
34
|
-
|
35
|
-
it "handles void type" do
|
36
|
-
gv = GObject::Value.for_gtype GObject::TYPE_NONE
|
37
|
-
_(gv.current_gtype).must_equal GObject::TYPE_INVALID
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "::wrap_ruby_value" do
|
42
|
-
it "wraps a boolean false" do
|
43
|
-
gv = GObject::Value.wrap_ruby_value false
|
44
|
-
assert_instance_of GObject::Value, gv
|
45
|
-
_(gv.get_boolean).must_equal false
|
46
|
-
end
|
47
|
-
|
48
|
-
it "wraps a boolean true" do
|
49
|
-
gv = GObject::Value.wrap_ruby_value true
|
50
|
-
assert_instance_of GObject::Value, gv
|
51
|
-
_(gv.get_boolean).must_equal true
|
52
|
-
end
|
53
|
-
|
54
|
-
it "wraps an Integer" do
|
55
|
-
gv = GObject::Value.wrap_ruby_value 42
|
56
|
-
_(gv.get_int).must_equal 42
|
57
|
-
end
|
58
|
-
|
59
|
-
it "wraps a String" do
|
60
|
-
gv = GObject::Value.wrap_ruby_value "Some Random String"
|
61
|
-
_(gv.get_string).must_equal "Some Random String"
|
62
|
-
end
|
63
|
-
|
64
|
-
it "wraps nil" do
|
65
|
-
gv = GObject::Value.wrap_ruby_value nil
|
66
|
-
assert_instance_of GObject::Value, gv
|
67
|
-
_(gv.get_value).must_be_nil
|
68
|
-
end
|
69
|
-
|
70
|
-
it "wraps object values" do
|
71
|
-
value = GObject::Object.new({})
|
72
|
-
gv = GObject::Value.wrap_ruby_value value
|
73
|
-
_(object_ref_count(value)).must_equal 2
|
74
|
-
_(gv.get_value).must_equal value
|
75
|
-
_(object_ref_count(value)).must_equal 3
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "#set_value" do
|
80
|
-
it "handles signed char values" do
|
81
|
-
value = -83
|
82
|
-
gv = GObject::Value.for_gtype GObject::TYPE_CHAR
|
83
|
-
gv.set_value value
|
84
|
-
_(gv.get_schar).must_equal value
|
85
|
-
end
|
86
|
-
|
87
|
-
it "handles unsigned char values" do
|
88
|
-
value = 174
|
89
|
-
gv = GObject::Value.for_gtype GObject::TYPE_UCHAR
|
90
|
-
gv.set_value value
|
91
|
-
_(gv.get_uchar).must_equal value
|
92
|
-
end
|
93
|
-
|
94
|
-
it "handles enum values presented as symbols" do
|
95
|
-
value = :value2
|
96
|
-
gv = GObject::Value.for_gtype Regress::TestEnum.gtype
|
97
|
-
gv.set_value value
|
98
|
-
_(gv.get_value).must_equal value
|
99
|
-
end
|
100
|
-
|
101
|
-
it "handles enum values presented as numbers" do
|
102
|
-
value = :value2
|
103
|
-
gv = GObject::Value.for_gtype Regress::TestEnum.gtype
|
104
|
-
gv.set_value Regress::TestEnum[value]
|
105
|
-
_(gv.get_value).must_equal value
|
106
|
-
end
|
107
|
-
|
108
|
-
it "handles flag values presented as hashes" do
|
109
|
-
value = { flag2: true }
|
110
|
-
gv = GObject::Value.for_gtype Regress::TestFlags.gtype
|
111
|
-
gv.set_value value
|
112
|
-
_(gv.get_value).must_equal value
|
113
|
-
end
|
114
|
-
|
115
|
-
it "handles flag values presented as symbols" do
|
116
|
-
gv = GObject::Value.for_gtype Regress::TestFlags.gtype
|
117
|
-
gv.set_value :flag2
|
118
|
-
_(gv.get_value).must_equal(flag2: true)
|
119
|
-
end
|
120
|
-
|
121
|
-
it "handles flag values presented as numbers" do
|
122
|
-
value = { flag2: true }
|
123
|
-
gv = GObject::Value.for_gtype Regress::TestFlags.gtype
|
124
|
-
gv.set_value Regress::TestFlags.to_native(value, nil)
|
125
|
-
_(gv.get_value).must_equal value
|
126
|
-
end
|
127
|
-
|
128
|
-
it "handles GType values" do
|
129
|
-
value = GObject::TYPE_STRING
|
130
|
-
gv = GObject::Value.for_gtype GObject::TYPE_GTYPE
|
131
|
-
gv.set_value value
|
132
|
-
_(gv.get_gtype).must_equal value
|
133
|
-
end
|
134
|
-
|
135
|
-
it "handles int64 values" do
|
136
|
-
value = 0x1234_5678_9012_3456
|
137
|
-
gv = GObject::Value.for_gtype GObject::TYPE_INT64
|
138
|
-
gv.set_value value
|
139
|
-
_(gv.get_int64).must_equal value
|
140
|
-
end
|
141
|
-
|
142
|
-
it "handles long values" do
|
143
|
-
value = FFI.type_size(:long) == 8 ? 0x1234_5678_9012_3456 : 0x1234_5678
|
144
|
-
gv = GObject::Value.for_gtype GObject::TYPE_LONG
|
145
|
-
gv.set_value value
|
146
|
-
_(gv.get_long).must_equal value
|
147
|
-
end
|
148
|
-
|
149
|
-
it "handles uchar values" do
|
150
|
-
value = 83
|
151
|
-
gv = GObject::Value.for_gtype GObject::TYPE_UCHAR
|
152
|
-
gv.set_value value
|
153
|
-
_(gv.get_uchar).must_equal value
|
154
|
-
end
|
155
|
-
|
156
|
-
it "handles uint values" do
|
157
|
-
value = 0x1234_5678
|
158
|
-
gv = GObject::Value.for_gtype GObject::TYPE_UINT
|
159
|
-
gv.set_value value
|
160
|
-
_(gv.get_uint).must_equal value
|
161
|
-
end
|
162
|
-
|
163
|
-
it "handles uint64 values" do
|
164
|
-
value = 0x1234_5678_9012_3456
|
165
|
-
gv = GObject::Value.for_gtype GObject::TYPE_UINT64
|
166
|
-
gv.set_value value
|
167
|
-
_(gv.get_uint64).must_equal value
|
168
|
-
end
|
169
|
-
|
170
|
-
it "handles ulong values" do
|
171
|
-
value = FFI.type_size(:long) == 8 ? 0x1234_5678_9012_3456 : 0x1234_5678
|
172
|
-
gv = GObject::Value.for_gtype GObject::TYPE_ULONG
|
173
|
-
gv.set_value value
|
174
|
-
_(gv.get_ulong).must_equal value
|
175
|
-
end
|
176
|
-
|
177
|
-
it "handles variant values" do
|
178
|
-
value = GLib::Variant.new_string("Foo")
|
179
|
-
gv = GObject::Value.for_gtype GObject::TYPE_VARIANT
|
180
|
-
gv.set_value value
|
181
|
-
_(gv.get_variant).must_equal value
|
182
|
-
end
|
183
|
-
|
184
|
-
it "handles object values" do
|
185
|
-
value = GObject::Object.new({})
|
186
|
-
gv = GObject::Value.for_gtype GObject::Object.gtype
|
187
|
-
gv.set_value value
|
188
|
-
_(gv.get_object).must_equal value
|
189
|
-
end
|
190
|
-
|
191
|
-
it "handles interface values" do
|
192
|
-
value = Gio.file_new_for_path("/")
|
193
|
-
gv = GObject::Value.for_gtype Gio::File.gtype
|
194
|
-
gv.set_value value
|
195
|
-
_(gv.get_object).must_equal value
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
describe "#get_value" do
|
200
|
-
it "unwraps a boolean false" do
|
201
|
-
gv = GObject::Value.wrap_ruby_value false
|
202
|
-
result = gv.get_value
|
203
|
-
_(result).must_equal false
|
204
|
-
end
|
205
|
-
|
206
|
-
it "unwraps a boolean true" do
|
207
|
-
gv = GObject::Value.wrap_ruby_value true
|
208
|
-
result = gv.get_value
|
209
|
-
_(result).must_equal true
|
210
|
-
end
|
211
|
-
|
212
|
-
it "unwraps a signed char" do
|
213
|
-
value = -42
|
214
|
-
gv = GObject::Value.for_gtype GObject::TYPE_CHAR
|
215
|
-
gv.set_schar value
|
216
|
-
_(gv.get_value).must_equal value
|
217
|
-
end
|
218
|
-
|
219
|
-
it "unwraps an unsigned char" do
|
220
|
-
value = 173
|
221
|
-
gv = GObject::Value.for_gtype GObject::TYPE_UCHAR
|
222
|
-
gv.set_uchar value
|
223
|
-
_(gv.get_value).must_equal value
|
224
|
-
end
|
225
|
-
|
226
|
-
it "unwraps an enum value" do
|
227
|
-
value = :value2
|
228
|
-
gv = GObject::Value.for_gtype Regress::TestEnum.gtype
|
229
|
-
gv.set_enum Regress::TestEnum[value]
|
230
|
-
_(gv.get_value).must_equal value
|
231
|
-
end
|
232
|
-
|
233
|
-
it "unwraps a flags value" do
|
234
|
-
value = { flag1: true, flag3: true }
|
235
|
-
gv = GObject::Value.for_gtype Regress::TestFlags.gtype
|
236
|
-
gv.set_flags Regress::TestFlags.to_native(value, nil)
|
237
|
-
_(gv.get_value).must_equal value
|
238
|
-
end
|
239
|
-
|
240
|
-
it "unwraps a GType" do
|
241
|
-
value = GObject::TYPE_STRING
|
242
|
-
gv = GObject::Value.for_gtype GObject::TYPE_GTYPE
|
243
|
-
gv.set_gtype value
|
244
|
-
_(gv.get_value).must_equal value
|
245
|
-
end
|
246
|
-
|
247
|
-
it "unwraps an int64" do
|
248
|
-
value = 0x1234_5678_9012_3456
|
249
|
-
gv = GObject::Value.for_gtype GObject::TYPE_INT64
|
250
|
-
gv.set_int64 value
|
251
|
-
_(gv.get_value).must_equal value
|
252
|
-
end
|
253
|
-
|
254
|
-
it "unwraps a long" do
|
255
|
-
value = FFI.type_size(:long) == 8 ? 0x1234_5678_9012_3456 : 0x1234_5678
|
256
|
-
gv = GObject::Value.for_gtype GObject::TYPE_LONG
|
257
|
-
gv.set_long value
|
258
|
-
_(gv.get_value).must_equal value
|
259
|
-
end
|
260
|
-
|
261
|
-
it "unwraps an uchar" do
|
262
|
-
value = 3
|
263
|
-
gv = GObject::Value.for_gtype GObject::TYPE_UCHAR
|
264
|
-
gv.set_uchar value
|
265
|
-
_(gv.get_value).must_equal value
|
266
|
-
end
|
267
|
-
|
268
|
-
it "unwraps an uint" do
|
269
|
-
value = 0x1234_5678
|
270
|
-
gv = GObject::Value.for_gtype GObject::TYPE_UINT
|
271
|
-
gv.set_uint value
|
272
|
-
_(gv.get_value).must_equal value
|
273
|
-
end
|
274
|
-
|
275
|
-
it "unwraps an uint64" do
|
276
|
-
value = 0x1234_5678_9012_3456
|
277
|
-
gv = GObject::Value.for_gtype GObject::TYPE_UINT64
|
278
|
-
gv.set_uint64 value
|
279
|
-
_(gv.get_value).must_equal value
|
280
|
-
end
|
281
|
-
|
282
|
-
it "unwraps an ulong" do
|
283
|
-
value = FFI.type_size(:long) == 8 ? 0x1234_5678_9012_3456 : 0x1234_5678
|
284
|
-
gv = GObject::Value.for_gtype GObject::TYPE_ULONG
|
285
|
-
gv.set_ulong value
|
286
|
-
_(gv.get_value).must_equal value
|
287
|
-
end
|
288
|
-
|
289
|
-
it "unwraps a variant" do
|
290
|
-
value = GLib::Variant.new_string("Foo")
|
291
|
-
gv = GObject::Value.for_gtype GObject::TYPE_VARIANT
|
292
|
-
gv.set_variant value
|
293
|
-
_(gv.get_value).must_equal value
|
294
|
-
end
|
295
|
-
|
296
|
-
it "works with a ByteArray" do
|
297
|
-
ba = GLib::ByteArray.new.append("some bytes")
|
298
|
-
v = GObject::Value.for_gtype GObject::TYPE_BYTE_ARRAY
|
299
|
-
v.set_boxed ba
|
300
|
-
|
301
|
-
result = v.get_value
|
302
|
-
|
303
|
-
_(result.to_string).must_equal "some bytes"
|
304
|
-
_(result).must_be_kind_of GLib::ByteArray
|
305
|
-
end
|
306
|
-
|
307
|
-
it "works with an Array" do
|
308
|
-
arr = GLib::Array.from(:uint, [1, 2, 3])
|
309
|
-
v = GObject::Value.for_gtype GObject::TYPE_ARRAY
|
310
|
-
v.set_boxed arr
|
311
|
-
|
312
|
-
result = v.get_value
|
313
|
-
|
314
|
-
_(result).must_be_kind_of GLib::Array
|
315
|
-
_(result.reset_typespec(:uint).to_a).must_equal [1, 2, 3]
|
316
|
-
end
|
317
|
-
|
318
|
-
it "unwraps a Strv" do
|
319
|
-
strv = GLib::Strv.from %w(foo bar)
|
320
|
-
val = GObject::Value.for_gtype GObject::TYPE_STRV
|
321
|
-
val.set_boxed strv
|
322
|
-
|
323
|
-
result = val.get_value
|
324
|
-
|
325
|
-
_(result).must_be_kind_of GLib::Strv
|
326
|
-
_(result.to_a).must_equal %w(foo bar)
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
describe "::from" do
|
331
|
-
it "creates a gint GValue from a Ruby Integer" do
|
332
|
-
gv = GObject::Value.from 21
|
333
|
-
_(gv.current_gtype_name).must_equal "gint"
|
334
|
-
_(gv.get_value).must_equal 21
|
335
|
-
end
|
336
|
-
|
337
|
-
it "returns its argument if given a GValue" do
|
338
|
-
gv = GObject::Value.from 21
|
339
|
-
gv2 = GObject::Value.from gv
|
340
|
-
_(gv2.current_gtype_name).must_equal "gint"
|
341
|
-
_(gv2.get_value).must_equal 21
|
342
|
-
end
|
343
|
-
|
344
|
-
it "creates a null GValue from a Ruby nil" do
|
345
|
-
gv = GObject::Value.from nil
|
346
|
-
_(gv.current_gtype).must_equal GObject::TYPE_INVALID
|
347
|
-
_(gv.get_value).must_be_nil
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
describe "#set_value" do
|
352
|
-
before do
|
353
|
-
GirFFI.setup :GIMarshallingTests
|
354
|
-
end
|
355
|
-
|
356
|
-
it "raises an error when setting an incompatible object type" do
|
357
|
-
o = GIMarshallingTests::Object.new 1
|
358
|
-
v = GObject::Value.new.init(GIMarshallingTests::OverridesObject.gtype)
|
359
|
-
_(proc { v.set_value o }).must_raise ArgumentError
|
360
|
-
end
|
361
|
-
|
362
|
-
it "works with a ByteArray" do
|
363
|
-
ba = GLib::ByteArray.new.append("some bytes")
|
364
|
-
v = GObject::Value.new.init(GObject.type_from_name("GByteArray"))
|
365
|
-
v.set_value ba
|
366
|
-
_(v.get_value.to_string).must_equal "some bytes"
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
describe "upon garbage collection" do
|
371
|
-
it "restores the underlying GValue to its pristine state" do
|
372
|
-
skip "cannot be reliably tested on JRuby" if jruby?
|
373
|
-
|
374
|
-
value = GObject::Value.from 42
|
375
|
-
|
376
|
-
# Drop reference to original GObject::Value
|
377
|
-
value = GObject::Value.wrap value.to_ptr
|
378
|
-
_(value.current_gtype_name).must_equal "gint"
|
379
|
-
|
380
|
-
GC.start
|
381
|
-
# Creating a new object is sometimes needed to trigger enough garbage collection.
|
382
|
-
GObject::Value.new
|
383
|
-
sleep 1
|
384
|
-
GC.start
|
385
|
-
GC.start
|
386
|
-
|
387
|
-
_(value.current_gtype_name).wont_equal "gint"
|
388
|
-
end
|
389
|
-
end
|
390
|
-
end
|