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,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GirFFI::Builders::StructBuilder do
|
6
|
-
describe "#layout_specification" do
|
7
|
-
it "returns the correct layout for Regress::TestStructA" do
|
8
|
-
info = get_introspection_data "Regress", "TestStructA"
|
9
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
10
|
-
_(builder.layout_specification).must_equal [:some_int, :int32, 0,
|
11
|
-
:some_int8, :int8, 4,
|
12
|
-
:some_double, :double, 8,
|
13
|
-
:some_enum, Regress::TestEnum, 16]
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "for a struct with a simple layout" do
|
17
|
-
before do
|
18
|
-
@field = Object.new
|
19
|
-
|
20
|
-
@struct = Object.new
|
21
|
-
allow(@struct).to receive(:namespace).and_return "Foo"
|
22
|
-
allow(@struct).to receive(:safe_name).and_return "Bar"
|
23
|
-
allow(@struct).to receive(:fields).and_return [@field]
|
24
|
-
|
25
|
-
@builder = GirFFI::Builders::StructBuilder.new @struct
|
26
|
-
end
|
27
|
-
|
28
|
-
it "creates the correct layout specification" do
|
29
|
-
expect(@field).to receive(:layout_specification).and_return [:bar, :int32, 0]
|
30
|
-
spec = @builder.layout_specification
|
31
|
-
assert_equal [:bar, :int32, 0], spec
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "for a struct with a layout with a complex type" do
|
36
|
-
it "does not flatten the complex type specification" do
|
37
|
-
expect(simplefield = Object.new)
|
38
|
-
.to receive(:layout_specification).and_return [:bar, :foo, 0]
|
39
|
-
expect(complexfield = Object.new)
|
40
|
-
.to receive(:layout_specification).and_return [:baz, [:qux, 2], 0]
|
41
|
-
expect(struct = Object.new)
|
42
|
-
.to receive(:fields).and_return [simplefield, complexfield]
|
43
|
-
|
44
|
-
allow(struct).to receive(:safe_name).and_return "Bar"
|
45
|
-
allow(struct).to receive(:namespace).and_return "Foo"
|
46
|
-
|
47
|
-
builder = GirFFI::Builders::StructBuilder.new struct
|
48
|
-
spec = builder.layout_specification
|
49
|
-
assert_equal [:bar, :foo, 0, :baz, [:qux, 2], 0], spec
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "#superclass" do
|
55
|
-
it "returns StructBase for a normal struct" do
|
56
|
-
info = get_introspection_data "Regress", "TestStructA"
|
57
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
58
|
-
_(builder.superclass).must_equal GirFFI::StructBase
|
59
|
-
end
|
60
|
-
|
61
|
-
it "returns BoxedBase for a boxed type" do
|
62
|
-
info = get_introspection_data "Regress", "TestSimpleBoxedB"
|
63
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
64
|
-
_(builder.superclass).must_equal GirFFI::BoxedBase
|
65
|
-
end
|
66
|
-
|
67
|
-
it "returns the GObject parent class for a type class" do
|
68
|
-
info = get_introspection_data "GIMarshallingTests", "SubSubObjectClass"
|
69
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
70
|
-
_(builder.superclass).must_equal GIMarshallingTests::SubObjectClass
|
71
|
-
end
|
72
|
-
|
73
|
-
it "returns ObjectClass for InitiallyUnownedClass" do
|
74
|
-
info = get_introspection_data "GObject", "InitiallyUnownedClass"
|
75
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
76
|
-
_(builder.superclass).must_equal GObject::ObjectClass
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "#setup_class" do
|
81
|
-
before do
|
82
|
-
save_module :Regress
|
83
|
-
end
|
84
|
-
|
85
|
-
it "stubs the structs methods" do
|
86
|
-
info = get_introspection_data "Regress", "TestStructA"
|
87
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
88
|
-
builder.setup_class
|
89
|
-
assert_defines_instance_method Regress::TestStructA, :clone
|
90
|
-
end
|
91
|
-
|
92
|
-
after do
|
93
|
-
restore_module :Regress
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
GirFFI.setup :GIMarshallingTests
|
6
|
-
|
7
|
-
describe GirFFI::Builders::UnintrospectableBoxedBuilder do
|
8
|
-
let(:instance) { GIMarshallingTests::PropertiesObject.new }
|
9
|
-
let(:property) { instance.object_class.find_property "some-boxed-glist" }
|
10
|
-
let(:gtype) { property.value_type }
|
11
|
-
let(:info) { GirFFI::UnintrospectableBoxedInfo.new(gtype) }
|
12
|
-
let(:bldr) { GirFFI::Builders::UnintrospectableBoxedBuilder.new(info) }
|
13
|
-
let(:boxed_class) { bldr.build_class }
|
14
|
-
|
15
|
-
it "builds a class" do
|
16
|
-
_(boxed_class).must_be_instance_of Class
|
17
|
-
end
|
18
|
-
|
19
|
-
it "builds a class derived from GirFFI::BoxedBase" do
|
20
|
-
_(boxed_class.superclass).must_equal GirFFI::BoxedBase
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns the same class when built again" do
|
24
|
-
other_bldr = GirFFI::Builders::UnintrospectableBoxedBuilder.new(info)
|
25
|
-
other_class = other_bldr.build_class
|
26
|
-
|
27
|
-
_(other_class).must_equal boxed_class
|
28
|
-
end
|
29
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
GirFFI.setup :Gio
|
6
|
-
GirFFI.setup :Gst
|
7
|
-
|
8
|
-
describe GirFFI::Builders::UnintrospectableBuilder do
|
9
|
-
describe "building the GLocalFile type" do
|
10
|
-
before do
|
11
|
-
Gio.file_new_for_path "/"
|
12
|
-
|
13
|
-
@gtype = GObject.type_from_name "GLocalFile"
|
14
|
-
@info = GirFFI::UnintrospectableTypeInfo.new(@gtype)
|
15
|
-
@bldr = GirFFI::Builders::UnintrospectableBuilder.new(@info)
|
16
|
-
@klass = @bldr.build_class
|
17
|
-
end
|
18
|
-
|
19
|
-
it "builds a class" do
|
20
|
-
assert_instance_of Class, @klass
|
21
|
-
end
|
22
|
-
|
23
|
-
it "builds a class derived from GObject::Object" do
|
24
|
-
assert_includes @klass.registered_ancestors, GObject::Object
|
25
|
-
end
|
26
|
-
|
27
|
-
it "builds a class derived from Gio::File" do
|
28
|
-
assert_includes @klass.registered_ancestors, Gio::File
|
29
|
-
end
|
30
|
-
|
31
|
-
it "returns the same class when built again" do
|
32
|
-
other_bldr = GirFFI::Builders::UnintrospectableBuilder.new(@info)
|
33
|
-
other_klass = other_bldr.build_class
|
34
|
-
|
35
|
-
assert_equal @klass, other_klass
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "its #find_signal method" do
|
39
|
-
it "returns nil for a signal that doesn't exist" do
|
40
|
-
_(@bldr.find_signal("foo")).must_be_nil
|
41
|
-
end
|
42
|
-
|
43
|
-
it "finds signals in ancestor classes" do
|
44
|
-
signal = @bldr.find_signal "notify"
|
45
|
-
_(signal.name).must_equal "notify"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "#object_class_struct" do
|
50
|
-
it "returns the parent class struct" do
|
51
|
-
_(@bldr.object_class_struct).must_equal GObject::ObjectClass
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "building the GstFakeSink type" do
|
57
|
-
let(:instance) { Gst::ElementFactory.make("fakesink", "sink") }
|
58
|
-
let(:sink_class) { instance.class }
|
59
|
-
let(:builder) { sink_class.gir_ffi_builder }
|
60
|
-
|
61
|
-
before do
|
62
|
-
Gst.init []
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "its #find_signal method" do
|
66
|
-
it "finds signals that are not defined in the GIR" do
|
67
|
-
signal = builder.find_signal "handoff"
|
68
|
-
_(signal).wont_be_nil
|
69
|
-
_(signal.name).must_equal "handoff"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "its #find_property method" do
|
74
|
-
it "returns nil for a property that doesn't exist" do
|
75
|
-
_(builder.find_property("foo")).must_be_nil
|
76
|
-
end
|
77
|
-
|
78
|
-
it "finds properies in ancestor classes" do
|
79
|
-
property = builder.find_property "name"
|
80
|
-
_(property.name).must_equal "name"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GirFFI::Builders::UnionBuilder do
|
6
|
-
let(:union_info) { get_introspection_data("Regress", "FooBUnion") }
|
7
|
-
let(:builder) { GirFFI::Builders::UnionBuilder.new union_info }
|
8
|
-
|
9
|
-
describe "#setup_instance_method" do
|
10
|
-
it "returns nil looking for a method that doesn't exist" do
|
11
|
-
_(builder.setup_instance_method("blub")).must_be_nil
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#layout_specification" do
|
16
|
-
it "returns the correct layout for Regress::FooBUnion" do
|
17
|
-
_(builder.layout_specification).must_equal [:type, :int32, 0,
|
18
|
-
:v, :double, 0,
|
19
|
-
:rect, :pointer, 0]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#layout_superclass" do
|
24
|
-
it "returns GirFFI::Union" do
|
25
|
-
_(builder.layout_superclass).must_equal GirFFI::Union
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,528 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
GirFFI.setup :GIMarshallingTests
|
6
|
-
GirFFI.setup :Regress
|
7
|
-
|
8
|
-
describe GirFFI::Builders::UserDefinedBuilder do
|
9
|
-
let(:base_class) { GIMarshallingTests::Object }
|
10
|
-
let(:derived_class) do
|
11
|
-
Object.const_set("DerivedClass#{Sequence.next}", Class.new(base_class))
|
12
|
-
end
|
13
|
-
let(:builder) { GirFFI::Builders::UserDefinedBuilder.new info }
|
14
|
-
let(:info) { GirFFI::UserDefinedObjectInfo.new derived_class }
|
15
|
-
|
16
|
-
describe "#build_class" do
|
17
|
-
before do
|
18
|
-
builder.build_class
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "with type info containing one integer property" do
|
22
|
-
let(:info) do
|
23
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
24
|
-
it.install_property GObject.param_spec_int("foo-bar", "foo bar",
|
25
|
-
"The Foo Bar Property",
|
26
|
-
10, 20, 15,
|
27
|
-
readable: true, writable: true)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it "registers a type that is bigger than the parent" do
|
32
|
-
gtype = derived_class.gtype
|
33
|
-
q = GObject.type_query gtype
|
34
|
-
_(q.instance_size).must_be :>, GIMarshallingTests::Object::Struct.size
|
35
|
-
end
|
36
|
-
|
37
|
-
it "gives the type's Struct fields for the parent and the property" do
|
38
|
-
_(derived_class::Struct.members).must_equal [:parent, :foo_bar]
|
39
|
-
end
|
40
|
-
|
41
|
-
it "creates accessor functions for the property" do
|
42
|
-
obj = derived_class.new
|
43
|
-
obj.foo_bar = 13
|
44
|
-
_(obj.foo_bar).must_equal 13
|
45
|
-
end
|
46
|
-
|
47
|
-
it "makes the property retrievable using #get_property" do
|
48
|
-
obj = derived_class.new
|
49
|
-
obj.foo_bar = 13
|
50
|
-
_(obj.get_property("foo-bar")).must_equal 13
|
51
|
-
end
|
52
|
-
|
53
|
-
it "makes the property settable using #set_property" do
|
54
|
-
obj = derived_class.new
|
55
|
-
obj.set_property("foo-bar", 20)
|
56
|
-
_(obj.foo_bar).must_equal 20
|
57
|
-
end
|
58
|
-
|
59
|
-
it "keeps parent properties accessible through their accessors" do
|
60
|
-
obj = derived_class.new
|
61
|
-
obj.int = 24
|
62
|
-
_(obj.int).must_equal 24
|
63
|
-
end
|
64
|
-
|
65
|
-
it "keeps parent properties accessible through get_property and set_property" do
|
66
|
-
obj = derived_class.new
|
67
|
-
obj.set_property("int", 24)
|
68
|
-
_(obj.get_property("int")).must_equal 24
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "with type info containing properties of several different types" do
|
73
|
-
let(:info) do
|
74
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
75
|
-
it.install_property GObject.param_spec_string("string-prop", "string property",
|
76
|
-
"The String Property",
|
77
|
-
"this is the default value",
|
78
|
-
readable: true, writable: true)
|
79
|
-
it.install_property GObject.param_spec_int("int-prop", "integer property",
|
80
|
-
"The Integer Property",
|
81
|
-
10, 20, 15,
|
82
|
-
readable: true, writable: true)
|
83
|
-
it.install_property GObject.param_spec_long("long-prop", "long property",
|
84
|
-
"The Long Property",
|
85
|
-
10.0, 50.0, 42.0,
|
86
|
-
readable: true, writable: true)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it "registers a type of the proper size" do
|
91
|
-
expected_size = derived_class::Struct.size
|
92
|
-
gtype = derived_class.gtype
|
93
|
-
q = GObject.type_query gtype
|
94
|
-
_(q.instance_size).must_equal expected_size
|
95
|
-
end
|
96
|
-
|
97
|
-
it "creates fields for the parents and properties in the type's Struct" do
|
98
|
-
offsets = derived_class::Struct.offsets
|
99
|
-
alignment = derived_class::Struct.alignment
|
100
|
-
_(alignment).must_equal 8 # TODO: Fix tests for platforms where this fails.
|
101
|
-
_(offsets).must_equal [[:parent, 0],
|
102
|
-
[:string_prop, 32],
|
103
|
-
[:int_prop, 40],
|
104
|
-
[:long_prop, 48]]
|
105
|
-
end
|
106
|
-
|
107
|
-
it "creates accessor functions for the string property" do
|
108
|
-
obj = derived_class.new
|
109
|
-
obj.string_prop = "hello!"
|
110
|
-
_(obj.string_prop).must_equal "hello!"
|
111
|
-
end
|
112
|
-
|
113
|
-
it "creates accessor functions for the integer property" do
|
114
|
-
obj = derived_class.new
|
115
|
-
obj.int_prop = 13
|
116
|
-
_(obj.int_prop).must_equal 13
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "with a boxed property" do
|
121
|
-
let(:boxed_gtype) { GIMarshallingTests::BoxedStruct.gtype }
|
122
|
-
let(:info) do
|
123
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
124
|
-
it.install_property GObject.param_spec_boxed("boxed-prop", "boxed property",
|
125
|
-
"The Boxed Property",
|
126
|
-
boxed_gtype,
|
127
|
-
readable: true, writable: true)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
it "registers a type of the proper size" do
|
132
|
-
expected_size = derived_class::Struct.size
|
133
|
-
gtype = derived_class.gtype
|
134
|
-
q = GObject.type_query gtype
|
135
|
-
_(q.instance_size).must_equal expected_size
|
136
|
-
end
|
137
|
-
|
138
|
-
it "gives the type's Struct fields for the parent and the property" do
|
139
|
-
_(derived_class::Struct.members).must_equal [:parent, :boxed_prop]
|
140
|
-
end
|
141
|
-
|
142
|
-
it "creates accessor functions for the property" do
|
143
|
-
obj = derived_class.new
|
144
|
-
boxed = GIMarshallingTests::BoxedStruct.new
|
145
|
-
boxed.long_ = 423
|
146
|
-
obj.boxed_prop = boxed
|
147
|
-
_(obj.boxed_prop.long_).must_equal 423
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "with an object property" do
|
152
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
153
|
-
let(:info) do
|
154
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
155
|
-
it.install_property GObject.param_spec_object("object-prop", "object property",
|
156
|
-
"The Object Property",
|
157
|
-
object_gtype,
|
158
|
-
readable: true, writable: true)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
it "registers a type of the proper size" do
|
163
|
-
expected_size = derived_class::Struct.size
|
164
|
-
gtype = derived_class.gtype
|
165
|
-
q = GObject.type_query gtype
|
166
|
-
_(q.instance_size).must_equal expected_size
|
167
|
-
end
|
168
|
-
|
169
|
-
it "gives the type's Struct fields for the parent and the property" do
|
170
|
-
_(derived_class::Struct.members).must_equal [:parent, :object_prop]
|
171
|
-
end
|
172
|
-
|
173
|
-
it "creates accessor functions for the property" do
|
174
|
-
obj = derived_class.new
|
175
|
-
object = GIMarshallingTests::Object.new 42
|
176
|
-
object.int = 423
|
177
|
-
obj.object_prop = object
|
178
|
-
_(obj.object_prop.int).must_equal 423
|
179
|
-
end
|
180
|
-
|
181
|
-
it "allows clearing the property throught the setter method" do
|
182
|
-
obj = derived_class.new
|
183
|
-
obj.object_prop = nil
|
184
|
-
_(obj.object_prop).must_be_nil
|
185
|
-
end
|
186
|
-
|
187
|
-
it "handles reference counting correctly when using the accessor" do
|
188
|
-
obj = derived_class.new
|
189
|
-
object = GIMarshallingTests::Object.new 42
|
190
|
-
obj.object_prop = object
|
191
|
-
_(object_ref_count(object)).must_equal 2
|
192
|
-
end
|
193
|
-
|
194
|
-
it "handles reference counting correctly when using the set_property method" do
|
195
|
-
obj = derived_class.new
|
196
|
-
object = GIMarshallingTests::Object.new 42
|
197
|
-
|
198
|
-
_(object_ref_count(object)).must_equal 1
|
199
|
-
obj.set_property("object_prop", object)
|
200
|
-
# Expect 4 due to extra Value#set_value + Value#get_value
|
201
|
-
_(object_ref_count(object)).must_equal 4
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
describe "with a boolean property" do
|
206
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
207
|
-
let(:info) do
|
208
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
209
|
-
it.install_property GObject.param_spec_boolean("the-prop", "the property",
|
210
|
-
"The Property",
|
211
|
-
true,
|
212
|
-
readable: true, writable: true)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
it "creates accessor functions for the property" do
|
217
|
-
obj = derived_class.new
|
218
|
-
obj.the_prop = true
|
219
|
-
_(obj.the_prop).must_equal true
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "with a char property" do
|
224
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
225
|
-
let(:info) do
|
226
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
227
|
-
it.install_property GObject.param_spec_char("the-prop", "the property",
|
228
|
-
"The Property",
|
229
|
-
-20, 100, 15,
|
230
|
-
readable: true, writable: true)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
it "creates accessor functions for the property" do
|
235
|
-
obj = derived_class.new
|
236
|
-
obj.the_prop = -13
|
237
|
-
_(obj.the_prop).must_equal(-13)
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
describe "with a uchar property" do
|
242
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
243
|
-
let(:info) do
|
244
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
245
|
-
it.install_property GObject.param_spec_uchar("the-prop", "the property",
|
246
|
-
"The Property",
|
247
|
-
10, 100, 15,
|
248
|
-
readable: true, writable: true)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
it "creates accessor functions for the property" do
|
253
|
-
obj = derived_class.new
|
254
|
-
obj.the_prop = 13
|
255
|
-
_(obj.the_prop).must_equal 13
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
describe "with a uint property" do
|
260
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
261
|
-
let(:info) do
|
262
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
263
|
-
it.install_property GObject.param_spec_uint("the-prop", "the property",
|
264
|
-
"The Property",
|
265
|
-
10, 100, 15,
|
266
|
-
readable: true, writable: true)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
it "creates accessor functions for the property" do
|
271
|
-
obj = derived_class.new
|
272
|
-
obj.the_prop = 423
|
273
|
-
_(obj.the_prop).must_equal 423
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
describe "with a ulong property" do
|
278
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
279
|
-
let(:info) do
|
280
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
281
|
-
it.install_property GObject.param_spec_ulong("the-prop", "the property",
|
282
|
-
"The Property",
|
283
|
-
10, 100, 15,
|
284
|
-
readable: true, writable: true)
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
it "creates accessor functions for the property" do
|
289
|
-
obj = derived_class.new
|
290
|
-
obj.the_prop = 423_432
|
291
|
-
_(obj.the_prop).must_equal 423_432
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
describe "with a int64 property" do
|
296
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
297
|
-
let(:info) do
|
298
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
299
|
-
it.install_property GObject.param_spec_int64("the-prop", "the property",
|
300
|
-
"The Property",
|
301
|
-
10, 100, 15,
|
302
|
-
readable: true, writable: true)
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
it "creates accessor functions for the property" do
|
307
|
-
obj = derived_class.new
|
308
|
-
obj.the_prop = -423_432
|
309
|
-
_(obj.the_prop).must_equal(-423_432)
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
describe "with a uint64 property" do
|
314
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
315
|
-
let(:info) do
|
316
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
317
|
-
it.install_property GObject.param_spec_uint64("the-prop", "the property",
|
318
|
-
"The Property",
|
319
|
-
10, 100, 15,
|
320
|
-
readable: true, writable: true)
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
it "creates accessor functions for the property" do
|
325
|
-
obj = derived_class.new
|
326
|
-
obj.the_prop = 423_432
|
327
|
-
_(obj.the_prop).must_equal 423_432
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
describe "with a float property" do
|
332
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
333
|
-
let(:info) do
|
334
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
335
|
-
it.install_property GObject.param_spec_float("the-prop", "the property",
|
336
|
-
"The Property",
|
337
|
-
10.0, 100.0, 15.0,
|
338
|
-
readable: true, writable: true)
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
it "creates accessor functions for the property" do
|
343
|
-
obj = derived_class.new
|
344
|
-
obj.the_prop = 42.23
|
345
|
-
_(obj.the_prop).must_be_within_epsilon 42.23
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
describe "with a double property" do
|
350
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
351
|
-
let(:info) do
|
352
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
353
|
-
it.install_property GObject.param_spec_double("the-prop", "the property",
|
354
|
-
"The Property",
|
355
|
-
10.0, 100.0, 15.0,
|
356
|
-
readable: true, writable: true)
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
it "creates accessor functions for the property" do
|
361
|
-
obj = derived_class.new
|
362
|
-
obj.the_prop = 42.23
|
363
|
-
_(obj.the_prop).must_equal 42.23
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
describe "with an enum property" do
|
368
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
369
|
-
let(:info) do
|
370
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
371
|
-
prop = GObject.param_spec_enum("the-prop", "the property",
|
372
|
-
"The Property",
|
373
|
-
GIMarshallingTests::GEnum.gtype, 0,
|
374
|
-
readable: true, writable: true)
|
375
|
-
it.install_property prop
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
it "creates accessor functions for the property" do
|
380
|
-
obj = derived_class.new
|
381
|
-
obj.the_prop = :value2
|
382
|
-
_(obj.the_prop).must_equal :value2
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
describe "with a flags property" do
|
387
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
388
|
-
let(:info) do
|
389
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
390
|
-
prop = GObject.param_spec_flags("the-prop", "the property",
|
391
|
-
"The Property",
|
392
|
-
GIMarshallingTests::Flags.gtype, 0,
|
393
|
-
readable: true, writable: true)
|
394
|
-
it.install_property prop
|
395
|
-
end
|
396
|
-
end
|
397
|
-
|
398
|
-
it "creates accessor functions for the property" do
|
399
|
-
obj = derived_class.new
|
400
|
-
obj.the_prop = { value2: true }
|
401
|
-
_(obj.the_prop).must_equal value2: true
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
describe "when deriving from a class with hidden struct size" do
|
406
|
-
let(:parent_class) { Regress::TestInheritDrawable }
|
407
|
-
let(:parent_size) do
|
408
|
-
GObject.type_query(parent_class.gtype).instance_size
|
409
|
-
end
|
410
|
-
let(:derived_class) do
|
411
|
-
Object.const_set("DerivedClass#{Sequence.next}", Class.new(parent_class))
|
412
|
-
end
|
413
|
-
let(:info) do
|
414
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
415
|
-
it.install_property GObject.param_spec_int("int-prop", "integer property",
|
416
|
-
"Integer Property",
|
417
|
-
10, 20, 15,
|
418
|
-
readable: true, writable: true)
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
it "registers a type that is bigger than the parent" do
|
423
|
-
class_size = GObject.type_query(derived_class.gtype).instance_size
|
424
|
-
_(class_size).must_be :>, parent_size
|
425
|
-
end
|
426
|
-
|
427
|
-
it "leaves enough space in derived struct layout" do
|
428
|
-
struct_size = derived_class::Struct.size
|
429
|
-
_(struct_size).must_be :>, parent_size
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
describe "with type info containing an overridden g_name" do
|
434
|
-
let(:info) do
|
435
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
436
|
-
it.g_name = "OtherName#{Sequence.next}"
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
it "registers a type under the overridden name" do
|
441
|
-
registered_name = GObject.type_name(derived_class.gtype)
|
442
|
-
_(registered_name).must_equal info.g_name
|
443
|
-
_(registered_name).wont_equal derived_class.name
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
describe "with type info containing a vfunc" do
|
448
|
-
let(:info) do
|
449
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
450
|
-
it.install_vfunc_implementation :method_int8_in, proc { |instance, in_|
|
451
|
-
instance.int = in_
|
452
|
-
}
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
it "allows the vfunc to be called through its invoker" do
|
457
|
-
obj = derived_class.new
|
458
|
-
obj.method_int8_in 12
|
459
|
-
_(obj.int).must_equal 12
|
460
|
-
end
|
461
|
-
end
|
462
|
-
|
463
|
-
describe "when using a default vfunc implementation" do
|
464
|
-
let(:base_class) { Regress::TestObj }
|
465
|
-
let(:info) do
|
466
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
467
|
-
it.install_vfunc_implementation :matrix
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
before do
|
472
|
-
derived_class.class_eval do
|
473
|
-
def matrix(_arg)
|
474
|
-
44
|
475
|
-
end
|
476
|
-
end
|
477
|
-
end
|
478
|
-
|
479
|
-
it "allows the vfunc to be called through its invoker" do
|
480
|
-
obj = derived_class.new
|
481
|
-
_(obj.do_matrix("bar")).must_equal 44
|
482
|
-
end
|
483
|
-
end
|
484
|
-
|
485
|
-
describe "with type info containing a vfunc from an included Interface" do
|
486
|
-
let(:info) do
|
487
|
-
derived_class.class_eval { include GIMarshallingTests::Interface }
|
488
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
489
|
-
it.install_vfunc_implementation :test_int8_in,
|
490
|
-
proc { |instance, in_| instance.int = in_ }
|
491
|
-
end
|
492
|
-
end
|
493
|
-
|
494
|
-
it "marks the type as conforming to the included Interface" do
|
495
|
-
iface_gtype = GIMarshallingTests::Interface.gtype
|
496
|
-
_(GObject.type_interfaces(derived_class.gtype).to_a).must_equal [iface_gtype]
|
497
|
-
end
|
498
|
-
|
499
|
-
it "allows the vfunc to be called through its invoker" do
|
500
|
-
obj = derived_class.new
|
501
|
-
obj.test_int8_in 12
|
502
|
-
_(obj.int).must_equal 12
|
503
|
-
end
|
504
|
-
end
|
505
|
-
|
506
|
-
it "keeps the gtype for an already registered class" do
|
507
|
-
gtype = derived_class.gtype
|
508
|
-
other_builder = GirFFI::Builders::UserDefinedBuilder.new info
|
509
|
-
other_class = other_builder.build_class
|
510
|
-
_(other_class.gtype).must_equal gtype
|
511
|
-
end
|
512
|
-
|
513
|
-
it "creates a class with a new GType" do
|
514
|
-
_(derived_class.gtype).wont_equal GIMarshallingTests::Object.gtype
|
515
|
-
end
|
516
|
-
|
517
|
-
it "makes the registered class return objects with the correct GType" do
|
518
|
-
obj = derived_class.new
|
519
|
-
_(GObject.type_from_instance(obj)).must_equal derived_class.gtype
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
|
-
describe "#object_class_struct" do
|
524
|
-
it "returns the parent class struct" do
|
525
|
-
_(builder.object_class_struct).must_equal GIMarshallingTests::ObjectClass
|
526
|
-
end
|
527
|
-
end
|
528
|
-
end
|