gir_ffi 0.15.1 → 0.15.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog.md +42 -0
- data/README.md +10 -10
- 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/container_class_methods.rb +1 -3
- 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 +2 -5
- data/lib/ffi-gobject/object.rb +102 -92
- data/lib/ffi-gobject/object_class.rb +1 -1
- data/lib/ffi-gobject/ruby_closure.rb +1 -1
- data/lib/ffi-gobject/value.rb +108 -117
- data/lib/ffi-gobject_introspection/i_base_info.rb +35 -27
- data/lib/ffi-gobject_introspection/lib.rb +1 -1
- data/lib/gir_ffi-base/gobject/lib.rb +4 -0
- data/lib/gir_ffi/array_element_convertor.rb +2 -3
- data/lib/gir_ffi/boxed_base.rb +13 -11
- data/lib/gir_ffi/builder.rb +3 -4
- data/lib/gir_ffi/builder_helper.rb +10 -2
- 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 +25 -11
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +4 -6
- data/lib/gir_ffi/builders/enum_builder.rb +9 -5
- data/lib/gir_ffi/builders/field_builder.rb +2 -1
- data/lib/gir_ffi/builders/function_builder.rb +1 -1
- 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/module_builder.rb +4 -2
- 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 +18 -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 +34 -7
- 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 +7 -8
- data/lib/gir_ffi/class_base.rb +1 -0
- 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/type_map.rb +1 -0
- 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 +106 -143
- 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 -122
- 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 -151
- data/test/gir_ffi/allocation_helper_test.rb +0 -36
- data/test/gir_ffi/arg_helper_test.rb +0 -139
- 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 -322
- data/test/gir_ffi/builders/argument_builder_test.rb +0 -651
- data/test/gir_ffi/builders/base_argument_builder_test.rb +0 -6
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +0 -126
- data/test/gir_ffi/builders/callback_builder_test.rb +0 -117
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +0 -81
- data/test/gir_ffi/builders/constant_builder_test.rb +0 -6
- data/test/gir_ffi/builders/constructor_builder_test.rb +0 -37
- data/test/gir_ffi/builders/enum_builder_test.rb +0 -23
- data/test/gir_ffi/builders/field_builder_test.rb +0 -134
- data/test/gir_ffi/builders/function_builder_test.rb +0 -550
- data/test/gir_ffi/builders/initializer_builder_test.rb +0 -54
- 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 -158
- data/test/gir_ffi/builders/registered_type_builder_test.rb +0 -54
- data/test/gir_ffi/builders/return_value_builder_test.rb +0 -433
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +0 -197
- data/test/gir_ffi/builders/struct_builder_test.rb +0 -93
- 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 -524
- data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +0 -101
- data/test/gir_ffi/builders/vfunc_builder_test.rb +0 -241
- data/test/gir_ffi/callback_base_test.rb +0 -22
- data/test/gir_ffi/class_base_test.rb +0 -166
- data/test/gir_ffi/core_test.rb +0 -98
- 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 -20
- 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 -21
- 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 -711
- 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 -65
- 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 -53
- data/test/integration/generated_everything_test.rb +0 -452
- data/test/integration/generated_gimarshallingtests_test.rb +0 -3096
- 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 -32
- 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 -4038
- 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 -43
- data/test/integration/method_lookup_test.rb +0 -34
- data/test/introspection_test_helper.rb +0 -93
- 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,197 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GirFFI::Builders::SignalClosureBuilder do
|
6
|
-
let(:builder) { GirFFI::Builders::SignalClosureBuilder.new signal_info }
|
7
|
-
|
8
|
-
describe "#build_class" do
|
9
|
-
let(:signal_info) do
|
10
|
-
get_signal_introspection_data "Regress", "TestObj", "test"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "builds a descendant of RubyClosure" do
|
14
|
-
klass = builder.build_class
|
15
|
-
_(klass.superclass).must_equal GObject::RubyClosure
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#marshaller_definition" do
|
20
|
-
describe "for a signal with no arguments or return value" do
|
21
|
-
let(:signal_info) do
|
22
|
-
get_signal_introspection_data "Regress", "TestObj", "test"
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns a valid marshaller converting only the receiver" do
|
26
|
-
expected = <<~CODE
|
27
|
-
def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
|
28
|
-
_instance = param_values.first.get_value_plain
|
29
|
-
_v1 = _instance
|
30
|
-
wrap(closure.to_ptr).invoke_block(_v1)
|
31
|
-
end
|
32
|
-
CODE
|
33
|
-
|
34
|
-
_(builder.marshaller_definition).must_equal expected
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "for a signal with an argument and a return value" do
|
39
|
-
let(:signal_info) do
|
40
|
-
get_signal_introspection_data "Regress", "TestObj", "sig-with-int64-prop"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "returns a valid mapping method" do
|
44
|
-
expected = <<~CODE
|
45
|
-
def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
|
46
|
-
_instance, i = param_values.map(&:get_value_plain)
|
47
|
-
_v1 = _instance
|
48
|
-
_v2 = i
|
49
|
-
_v3 = wrap(closure.to_ptr).invoke_block(_v1, _v2)
|
50
|
-
return_value.set_value _v3
|
51
|
-
end
|
52
|
-
CODE
|
53
|
-
|
54
|
-
_(builder.marshaller_definition).must_equal expected
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "for a signal with an enum argument" do
|
59
|
-
let(:signal_info) do
|
60
|
-
get_signal_introspection_data "Gio", "MountOperation", "reply"
|
61
|
-
end
|
62
|
-
|
63
|
-
it "returns a valid mapping method" do
|
64
|
-
expected = <<~CODE
|
65
|
-
def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
|
66
|
-
_instance, result = param_values.map(&:get_value_plain)
|
67
|
-
_v1 = _instance
|
68
|
-
_v2 = result
|
69
|
-
wrap(closure.to_ptr).invoke_block(_v1, _v2)
|
70
|
-
end
|
71
|
-
CODE
|
72
|
-
|
73
|
-
_(builder.marshaller_definition).must_equal expected
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "for a signal with a array plus length arguments" do
|
78
|
-
let(:signal_info) do
|
79
|
-
get_signal_introspection_data "Regress", "TestObj", "sig-with-array-len-prop"
|
80
|
-
end
|
81
|
-
|
82
|
-
it "returns a valid mapping method" do
|
83
|
-
expected = <<~CODE
|
84
|
-
def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
|
85
|
-
_instance, arr, len = param_values.map(&:get_value_plain)
|
86
|
-
_v1 = _instance
|
87
|
-
_v2 = len
|
88
|
-
_v3 = GirFFI::SizedArray.wrap(:guint32, _v2, arr)
|
89
|
-
wrap(closure.to_ptr).invoke_block(_v1, _v3)
|
90
|
-
end
|
91
|
-
CODE
|
92
|
-
|
93
|
-
_(builder.marshaller_definition).must_equal expected
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "for a signal with a struct argument" do
|
98
|
-
let(:signal_info) do
|
99
|
-
get_signal_introspection_data "Regress", "TestObj", "test-with-static-scope-arg"
|
100
|
-
end
|
101
|
-
|
102
|
-
it "returns a valid mapping method" do
|
103
|
-
expected = <<~CODE
|
104
|
-
def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
|
105
|
-
_instance, object = param_values.map(&:get_value_plain)
|
106
|
-
_v1 = _instance
|
107
|
-
_v2 = Regress::TestSimpleBoxedA.wrap(object)
|
108
|
-
wrap(closure.to_ptr).invoke_block(_v1, _v2)
|
109
|
-
end
|
110
|
-
CODE
|
111
|
-
|
112
|
-
_(builder.marshaller_definition).must_equal expected
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "for a signal returning an array of integers" do
|
117
|
-
let(:signal_info) do
|
118
|
-
get_signal_introspection_data "Regress", "TestObj", "sig-with-intarray-ret"
|
119
|
-
end
|
120
|
-
|
121
|
-
it "returns a valid mapping method" do
|
122
|
-
expected = <<~CODE
|
123
|
-
def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
|
124
|
-
_instance, i = param_values.map(&:get_value_plain)
|
125
|
-
_v1 = _instance
|
126
|
-
_v2 = i
|
127
|
-
_v3 = wrap(closure.to_ptr).invoke_block(_v1, _v2)
|
128
|
-
_v4 = GLib::Array.from(:gint32, _v3)
|
129
|
-
return_value.set_value _v4
|
130
|
-
end
|
131
|
-
CODE
|
132
|
-
|
133
|
-
_(builder.marshaller_definition).must_equal expected
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe "for a signal returning an string" do
|
138
|
-
let(:signal_info) do
|
139
|
-
get_signal_introspection_data "Gtk", "Scale", "format-value"
|
140
|
-
end
|
141
|
-
|
142
|
-
it "returns a mapping method that passes the string result to return_value directly" do
|
143
|
-
expected = <<~CODE
|
144
|
-
def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
|
145
|
-
_instance, value = param_values.map(&:get_value_plain)
|
146
|
-
_v1 = _instance
|
147
|
-
_v2 = value
|
148
|
-
_v3 = wrap(closure.to_ptr).invoke_block(_v1, _v2)
|
149
|
-
return_value.set_value _v3
|
150
|
-
end
|
151
|
-
CODE
|
152
|
-
|
153
|
-
_(builder.marshaller_definition).must_equal expected
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe "for a signal with GList argument" do
|
158
|
-
let(:signal_info) do
|
159
|
-
get_signal_introspection_data "Regress", "AnnotationObject", "list-signal"
|
160
|
-
end
|
161
|
-
|
162
|
-
it "returns a valid mapping method" do
|
163
|
-
expected = <<~CODE
|
164
|
-
def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
|
165
|
-
_instance, list = param_values.map(&:get_value_plain)
|
166
|
-
_v1 = _instance
|
167
|
-
_v2 = GLib::List.wrap(:utf8, list)
|
168
|
-
wrap(closure.to_ptr).invoke_block(_v1, _v2)
|
169
|
-
end
|
170
|
-
CODE
|
171
|
-
|
172
|
-
_(builder.marshaller_definition).must_equal expected
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "for a signal with GError argument" do
|
177
|
-
let(:signal_info) do
|
178
|
-
get_signal_introspection_data "Regress", "TestObj", "sig-with-gerror"
|
179
|
-
end
|
180
|
-
|
181
|
-
it "returns a valid mapping method" do
|
182
|
-
skip_below "1.61.1"
|
183
|
-
|
184
|
-
expected = <<~CODE
|
185
|
-
def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
|
186
|
-
_instance, error = param_values.map(&:get_value_plain)
|
187
|
-
_v1 = _instance
|
188
|
-
_v2 = GLib::Error.wrap(error)
|
189
|
-
wrap(closure.to_ptr).invoke_block(_v1, _v2)
|
190
|
-
end
|
191
|
-
CODE
|
192
|
-
|
193
|
-
_(builder.marshaller_definition).must_equal expected
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
@@ -1,93 +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).to receive(:layout_specification).and_return [:bar, :foo, 0]
|
38
|
-
expect(complexfield = Object.new).to receive(:layout_specification).and_return [:baz, [:qux, 2], 0]
|
39
|
-
expect(struct = Object.new).to receive(:fields).and_return [simplefield, complexfield]
|
40
|
-
|
41
|
-
allow(struct).to receive(:safe_name).and_return "Bar"
|
42
|
-
allow(struct).to receive(:namespace).and_return "Foo"
|
43
|
-
|
44
|
-
builder = GirFFI::Builders::StructBuilder.new struct
|
45
|
-
spec = builder.layout_specification
|
46
|
-
assert_equal [:bar, :foo, 0, :baz, [:qux, 2], 0], spec
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "#superclass" do
|
52
|
-
it "returns StructBase for a normal struct" do
|
53
|
-
info = get_introspection_data "Regress", "TestStructA"
|
54
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
55
|
-
_(builder.superclass).must_equal GirFFI::StructBase
|
56
|
-
end
|
57
|
-
|
58
|
-
it "returns BoxedBase for a boxed type" do
|
59
|
-
info = get_introspection_data "Regress", "TestSimpleBoxedB"
|
60
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
61
|
-
_(builder.superclass).must_equal GirFFI::BoxedBase
|
62
|
-
end
|
63
|
-
|
64
|
-
it "returns the GObject parent class for a type class" do
|
65
|
-
info = get_introspection_data "GIMarshallingTests", "SubSubObjectClass"
|
66
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
67
|
-
_(builder.superclass).must_equal GIMarshallingTests::SubObjectClass
|
68
|
-
end
|
69
|
-
|
70
|
-
it "returns ObjectClass for InitiallyUnownedClass" do
|
71
|
-
info = get_introspection_data "GObject", "InitiallyUnownedClass"
|
72
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
73
|
-
_(builder.superclass).must_equal GObject::ObjectClass
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "#setup_class" do
|
78
|
-
before do
|
79
|
-
save_module :Regress
|
80
|
-
end
|
81
|
-
|
82
|
-
it "stubs the structs methods" do
|
83
|
-
info = get_introspection_data "Regress", "TestStructA"
|
84
|
-
builder = GirFFI::Builders::StructBuilder.new info
|
85
|
-
builder.setup_class
|
86
|
-
assert_defines_instance_method Regress::TestStructA, :clone
|
87
|
-
end
|
88
|
-
|
89
|
-
after do
|
90
|
-
restore_module :Regress
|
91
|
-
end
|
92
|
-
end
|
93
|
-
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,524 +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 "gives the type's Struct fields for the parent and the properties with the correct offsets" 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], [:string_prop, 32], [:int_prop, 40], [:long_prop, 48]]
|
102
|
-
end
|
103
|
-
|
104
|
-
it "creates accessor functions for the string property" do
|
105
|
-
obj = derived_class.new
|
106
|
-
obj.string_prop = "hello!"
|
107
|
-
_(obj.string_prop).must_equal "hello!"
|
108
|
-
end
|
109
|
-
|
110
|
-
it "creates accessor functions for the integer property" do
|
111
|
-
obj = derived_class.new
|
112
|
-
obj.int_prop = 13
|
113
|
-
_(obj.int_prop).must_equal 13
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "with a boxed property" do
|
118
|
-
let(:boxed_gtype) { GIMarshallingTests::BoxedStruct.gtype }
|
119
|
-
let(:info) do
|
120
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
121
|
-
it.install_property GObject.param_spec_boxed("boxed-prop", "boxed property",
|
122
|
-
"The Boxed Property",
|
123
|
-
boxed_gtype,
|
124
|
-
readable: true, writable: true)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
it "registers a type of the proper size" do
|
129
|
-
expected_size = derived_class::Struct.size
|
130
|
-
gtype = derived_class.gtype
|
131
|
-
q = GObject.type_query gtype
|
132
|
-
_(q.instance_size).must_equal expected_size
|
133
|
-
end
|
134
|
-
|
135
|
-
it "gives the type's Struct fields for the parent and the property" do
|
136
|
-
_(derived_class::Struct.members).must_equal [:parent, :boxed_prop]
|
137
|
-
end
|
138
|
-
|
139
|
-
it "creates accessor functions for the property" do
|
140
|
-
obj = derived_class.new
|
141
|
-
boxed = GIMarshallingTests::BoxedStruct.new
|
142
|
-
boxed.long_ = 423
|
143
|
-
obj.boxed_prop = boxed
|
144
|
-
_(obj.boxed_prop.long_).must_equal 423
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "with an object property" do
|
149
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
150
|
-
let(:info) do
|
151
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
152
|
-
it.install_property GObject.param_spec_object("object-prop", "object property",
|
153
|
-
"The Object Property",
|
154
|
-
object_gtype,
|
155
|
-
readable: true, writable: true)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
it "registers a type of the proper size" do
|
160
|
-
expected_size = derived_class::Struct.size
|
161
|
-
gtype = derived_class.gtype
|
162
|
-
q = GObject.type_query gtype
|
163
|
-
_(q.instance_size).must_equal expected_size
|
164
|
-
end
|
165
|
-
|
166
|
-
it "gives the type's Struct fields for the parent and the property" do
|
167
|
-
_(derived_class::Struct.members).must_equal [:parent, :object_prop]
|
168
|
-
end
|
169
|
-
|
170
|
-
it "creates accessor functions for the property" do
|
171
|
-
obj = derived_class.new
|
172
|
-
object = GIMarshallingTests::Object.new 42
|
173
|
-
object.int = 423
|
174
|
-
obj.object_prop = object
|
175
|
-
_(obj.object_prop.int).must_equal 423
|
176
|
-
end
|
177
|
-
|
178
|
-
it "allows clearing the property throught the setter method" do
|
179
|
-
obj = derived_class.new
|
180
|
-
obj.object_prop = nil
|
181
|
-
_(obj.object_prop).must_be_nil
|
182
|
-
end
|
183
|
-
|
184
|
-
it "handles reference counting correctly when using the accessor" do
|
185
|
-
obj = derived_class.new
|
186
|
-
object = GIMarshallingTests::Object.new 42
|
187
|
-
obj.object_prop = object
|
188
|
-
_(object_ref_count(object)).must_equal 2
|
189
|
-
end
|
190
|
-
|
191
|
-
it "handles reference counting correctly when using the set_property method" do
|
192
|
-
obj = derived_class.new
|
193
|
-
object = GIMarshallingTests::Object.new 42
|
194
|
-
|
195
|
-
_(object_ref_count(object)).must_equal 1
|
196
|
-
obj.set_property("object_prop", object)
|
197
|
-
_(object_ref_count(object)).must_equal 4 # Due to extra Value#set_value + Value#get_value
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
describe "with a boolean property" do
|
202
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
203
|
-
let(:info) do
|
204
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
205
|
-
it.install_property GObject.param_spec_boolean("the-prop", "the property",
|
206
|
-
"The Property",
|
207
|
-
true,
|
208
|
-
readable: true, writable: true)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
it "creates accessor functions for the property" do
|
213
|
-
obj = derived_class.new
|
214
|
-
obj.the_prop = true
|
215
|
-
_(obj.the_prop).must_equal true
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
describe "with a char property" do
|
220
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
221
|
-
let(:info) do
|
222
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
223
|
-
it.install_property GObject.param_spec_char("the-prop", "the property",
|
224
|
-
"The Property",
|
225
|
-
-20, 100, 15,
|
226
|
-
readable: true, writable: true)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
it "creates accessor functions for the property" do
|
231
|
-
obj = derived_class.new
|
232
|
-
obj.the_prop = -13
|
233
|
-
_(obj.the_prop).must_equal(-13)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe "with a uchar property" do
|
238
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
239
|
-
let(:info) do
|
240
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
241
|
-
it.install_property GObject.param_spec_uchar("the-prop", "the property",
|
242
|
-
"The Property",
|
243
|
-
10, 100, 15,
|
244
|
-
readable: true, writable: true)
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
it "creates accessor functions for the property" do
|
249
|
-
obj = derived_class.new
|
250
|
-
obj.the_prop = 13
|
251
|
-
_(obj.the_prop).must_equal 13
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
describe "with a uint property" do
|
256
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
257
|
-
let(:info) do
|
258
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
259
|
-
it.install_property GObject.param_spec_uint("the-prop", "the property",
|
260
|
-
"The Property",
|
261
|
-
10, 100, 15,
|
262
|
-
readable: true, writable: true)
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
it "creates accessor functions for the property" do
|
267
|
-
obj = derived_class.new
|
268
|
-
obj.the_prop = 423
|
269
|
-
_(obj.the_prop).must_equal 423
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
describe "with a ulong property" do
|
274
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
275
|
-
let(:info) do
|
276
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
277
|
-
it.install_property GObject.param_spec_ulong("the-prop", "the property",
|
278
|
-
"The Property",
|
279
|
-
10, 100, 15,
|
280
|
-
readable: true, writable: true)
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
it "creates accessor functions for the property" do
|
285
|
-
obj = derived_class.new
|
286
|
-
obj.the_prop = 423_432
|
287
|
-
_(obj.the_prop).must_equal 423_432
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
describe "with a int64 property" do
|
292
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
293
|
-
let(:info) do
|
294
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
295
|
-
it.install_property GObject.param_spec_int64("the-prop", "the property",
|
296
|
-
"The Property",
|
297
|
-
10, 100, 15,
|
298
|
-
readable: true, writable: true)
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
it "creates accessor functions for the property" do
|
303
|
-
obj = derived_class.new
|
304
|
-
obj.the_prop = -423_432
|
305
|
-
_(obj.the_prop).must_equal(-423_432)
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
describe "with a uint64 property" do
|
310
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
311
|
-
let(:info) do
|
312
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
313
|
-
it.install_property GObject.param_spec_uint64("the-prop", "the property",
|
314
|
-
"The Property",
|
315
|
-
10, 100, 15,
|
316
|
-
readable: true, writable: true)
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
it "creates accessor functions for the property" do
|
321
|
-
obj = derived_class.new
|
322
|
-
obj.the_prop = 423_432
|
323
|
-
_(obj.the_prop).must_equal 423_432
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
describe "with a float property" do
|
328
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
329
|
-
let(:info) do
|
330
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
331
|
-
it.install_property GObject.param_spec_float("the-prop", "the property",
|
332
|
-
"The Property",
|
333
|
-
10.0, 100.0, 15.0,
|
334
|
-
readable: true, writable: true)
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
it "creates accessor functions for the property" do
|
339
|
-
obj = derived_class.new
|
340
|
-
obj.the_prop = 42.23
|
341
|
-
_(obj.the_prop).must_be_within_epsilon 42.23
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
describe "with a double property" do
|
346
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
347
|
-
let(:info) do
|
348
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
349
|
-
it.install_property GObject.param_spec_double("the-prop", "the property",
|
350
|
-
"The Property",
|
351
|
-
10.0, 100.0, 15.0,
|
352
|
-
readable: true, writable: true)
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
it "creates accessor functions for the property" do
|
357
|
-
obj = derived_class.new
|
358
|
-
obj.the_prop = 42.23
|
359
|
-
_(obj.the_prop).must_equal 42.23
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
describe "with an enum property" do
|
364
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
365
|
-
let(:info) do
|
366
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
367
|
-
prop = GObject.param_spec_enum("the-prop", "the property",
|
368
|
-
"The Property",
|
369
|
-
GIMarshallingTests::GEnum.gtype, 0,
|
370
|
-
readable: true, writable: true)
|
371
|
-
it.install_property prop
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
it "creates accessor functions for the property" do
|
376
|
-
obj = derived_class.new
|
377
|
-
obj.the_prop = :value2
|
378
|
-
_(obj.the_prop).must_equal :value2
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
describe "with a flags property" do
|
383
|
-
let(:object_gtype) { GIMarshallingTests::Object.gtype }
|
384
|
-
let(:info) do
|
385
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
386
|
-
prop = GObject.param_spec_flags("the-prop", "the property",
|
387
|
-
"The Property",
|
388
|
-
GIMarshallingTests::Flags.gtype, 0,
|
389
|
-
readable: true, writable: true)
|
390
|
-
it.install_property prop
|
391
|
-
end
|
392
|
-
end
|
393
|
-
|
394
|
-
it "creates accessor functions for the property" do
|
395
|
-
obj = derived_class.new
|
396
|
-
obj.the_prop = { value2: true }
|
397
|
-
_(obj.the_prop).must_equal value2: true
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
describe "when deriving from a class with hidden struct size" do
|
402
|
-
let(:parent_class) { Regress::TestInheritDrawable }
|
403
|
-
let(:parent_size) do
|
404
|
-
GObject.type_query(parent_class.gtype).instance_size
|
405
|
-
end
|
406
|
-
let(:derived_class) do
|
407
|
-
Object.const_set("DerivedClass#{Sequence.next}", Class.new(parent_class))
|
408
|
-
end
|
409
|
-
let(:info) do
|
410
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
411
|
-
it.install_property GObject.param_spec_int("int-prop", "integer property",
|
412
|
-
"Integer Property",
|
413
|
-
10, 20, 15,
|
414
|
-
readable: true, writable: true)
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
it "registers a type that is bigger than the parent" do
|
419
|
-
class_size = GObject.type_query(derived_class.gtype).instance_size
|
420
|
-
_(class_size).must_be :>, parent_size
|
421
|
-
end
|
422
|
-
|
423
|
-
it "leaves enough space in derived struct layout" do
|
424
|
-
struct_size = derived_class::Struct.size
|
425
|
-
_(struct_size).must_be :>, parent_size
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
|
-
describe "with type info containing an overridden g_name" do
|
430
|
-
let(:info) do
|
431
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
432
|
-
it.g_name = "OtherName#{Sequence.next}"
|
433
|
-
end
|
434
|
-
end
|
435
|
-
|
436
|
-
it "registers a type under the overridden name" do
|
437
|
-
registered_name = GObject.type_name(derived_class.gtype)
|
438
|
-
_(registered_name).must_equal info.g_name
|
439
|
-
_(registered_name).wont_equal derived_class.name
|
440
|
-
end
|
441
|
-
end
|
442
|
-
|
443
|
-
describe "with type info containing a vfunc" do
|
444
|
-
let(:info) do
|
445
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
446
|
-
it.install_vfunc_implementation :method_int8_in, proc { |instance, in_|
|
447
|
-
instance.int = in_
|
448
|
-
}
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
it "allows the vfunc to be called through its invoker" do
|
453
|
-
obj = derived_class.new
|
454
|
-
obj.method_int8_in 12
|
455
|
-
_(obj.int).must_equal 12
|
456
|
-
end
|
457
|
-
end
|
458
|
-
|
459
|
-
describe "when using a default vfunc implementation" do
|
460
|
-
let(:base_class) { Regress::TestObj }
|
461
|
-
let(:info) do
|
462
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
463
|
-
it.install_vfunc_implementation :matrix
|
464
|
-
end
|
465
|
-
end
|
466
|
-
|
467
|
-
before do
|
468
|
-
derived_class.class_eval do
|
469
|
-
def matrix(_arg)
|
470
|
-
44
|
471
|
-
end
|
472
|
-
end
|
473
|
-
end
|
474
|
-
|
475
|
-
it "allows the vfunc to be called through its invoker" do
|
476
|
-
obj = derived_class.new
|
477
|
-
_(obj.do_matrix("bar")).must_equal 44
|
478
|
-
end
|
479
|
-
end
|
480
|
-
|
481
|
-
describe "with type info containing a vfunc from an included Interface" do
|
482
|
-
let(:info) do
|
483
|
-
derived_class.class_eval { include GIMarshallingTests::Interface }
|
484
|
-
GirFFI::UserDefinedObjectInfo.new derived_class do |it|
|
485
|
-
it.install_vfunc_implementation :test_int8_in,
|
486
|
-
proc { |instance, in_| instance.int = in_ }
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
it "marks the type as conforming to the included Interface" do
|
491
|
-
iface_gtype = GIMarshallingTests::Interface.gtype
|
492
|
-
_(GObject.type_interfaces(derived_class.gtype).to_a).must_equal [iface_gtype]
|
493
|
-
end
|
494
|
-
|
495
|
-
it "allows the vfunc to be called through its invoker" do
|
496
|
-
obj = derived_class.new
|
497
|
-
obj.test_int8_in 12
|
498
|
-
_(obj.int).must_equal 12
|
499
|
-
end
|
500
|
-
end
|
501
|
-
|
502
|
-
it "keeps the gtype for an already registered class" do
|
503
|
-
gtype = derived_class.gtype
|
504
|
-
other_builder = GirFFI::Builders::UserDefinedBuilder.new info
|
505
|
-
other_class = other_builder.build_class
|
506
|
-
_(other_class.gtype).must_equal gtype
|
507
|
-
end
|
508
|
-
|
509
|
-
it "creates a class with a new GType" do
|
510
|
-
_(derived_class.gtype).wont_equal GIMarshallingTests::Object.gtype
|
511
|
-
end
|
512
|
-
|
513
|
-
it "makes the registered class return objects with the correct GType" do
|
514
|
-
obj = derived_class.new
|
515
|
-
_(GObject.type_from_instance(obj)).must_equal derived_class.gtype
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
describe "#object_class_struct" do
|
520
|
-
it "returns the parent class struct" do
|
521
|
-
_(builder.object_class_struct).must_equal GIMarshallingTests::ObjectClass
|
522
|
-
end
|
523
|
-
end
|
524
|
-
end
|