gir_ffi 0.15.2 → 0.15.3
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 +11 -0
- data/Gemfile +1 -1
- data/lib/ffi-gobject/value.rb +3 -1
- data/lib/ffi-gobject_introspection/i_base_info.rb +1 -1
- data/lib/gir_ffi/builder_helper.rb +6 -1
- data/lib/gir_ffi/builders/callback_builder.rb +13 -1
- data/lib/gir_ffi/builders/enum_builder.rb +6 -2
- data/lib/gir_ffi/builders/field_builder.rb +2 -1
- data/lib/gir_ffi/builders/module_builder.rb +3 -1
- data/lib/gir_ffi/builders/struct_builder.rb +3 -1
- data/lib/gir_ffi/callback_base.rb +3 -5
- data/lib/gir_ffi/class_base.rb +1 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/test/ffi-gobject/object_test.rb +3 -2
- data/test/ffi-gobject/value_test.rb +1 -1
- data/test/ffi-gobject_introspection/i_base_info_test.rb +1 -1
- data/test/ffi-gobject_test.rb +4 -2
- data/test/gir_ffi/arg_helper_test.rb +13 -6
- data/test/gir_ffi/boxed_base_test.rb +1 -1
- data/test/gir_ffi/builder_test.rb +3 -157
- data/test/gir_ffi/builders/argument_builder_test.rb +73 -33
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +6 -2
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +5 -2
- data/test/gir_ffi/builders/constructor_builder_test.rb +3 -1
- data/test/gir_ffi/builders/field_builder_test.rb +9 -3
- data/test/gir_ffi/builders/function_builder_test.rb +30 -10
- data/test/gir_ffi/builders/initializer_builder_test.rb +3 -1
- data/test/gir_ffi/builders/object_builder_test.rb +6 -6
- data/test/gir_ffi/builders/property_builder_test.rb +5 -2
- data/test/gir_ffi/builders/return_value_builder_test.rb +20 -9
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +9 -7
- data/test/gir_ffi/builders/struct_builder_test.rb +6 -3
- data/test/gir_ffi/builders/user_defined_builder_test.rb +7 -3
- data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +11 -5
- data/test/gir_ffi/builders/vfunc_builder_test.rb +10 -6
- data/test/gir_ffi/class_base_test.rb +17 -12
- data/test/gir_ffi/core_test.rb +4 -3
- data/test/gir_ffi/ffi_ext/pointer_test.rb +4 -2
- data/test/gir_ffi/info_ext/i_callback_info_test.rb +2 -1
- data/test/gir_ffi/info_ext/i_type_info_test.rb +2 -1
- data/test/gir_ffi/method_stubber_test.rb +3 -1
- data/test/integration/derived_classes_test.rb +1 -0
- data/test/integration/generated_everything_test.rb +2 -1
- data/test/integration/generated_gimarshallingtests_test.rb +57 -44
- data/test/integration/generated_gtk_source_test.rb +6 -17
- data/test/integration/generated_regress_test.rb +16 -2
- data/test/integration/generated_warnlib_test.rb +4 -2
- data/test/introspection_test_helper.rb +2 -1
- metadata +22 -8
@@ -21,7 +21,9 @@ describe GirFFI::Builders::InitializerBuilder do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "for constructors with a custom name" do
|
24
|
-
let(:function_info)
|
24
|
+
let(:function_info) do
|
25
|
+
get_method_introspection_data "Regress", "TestObj", "new_from_file"
|
26
|
+
end
|
25
27
|
it "builds a custom initializer" do
|
26
28
|
_(code).must_equal <<~CODE
|
27
29
|
def initialize_from_file(x)
|
@@ -17,20 +17,20 @@ describe GirFFI::Builders::ObjectBuilder do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "#find_signal" do
|
20
|
-
it 'finds
|
20
|
+
it 'finds a signal defined on the class itself' do
|
21
21
|
sig = obj_builder.find_signal "test"
|
22
22
|
_(sig.name).must_equal "test"
|
23
23
|
end
|
24
24
|
|
25
|
-
it 'finds
|
25
|
+
it 'finds a signal defined on a superclass' do
|
26
26
|
sig = sub_obj_builder.find_signal "test"
|
27
27
|
_(sig.name).must_equal "test"
|
28
28
|
end
|
29
29
|
|
30
|
-
it 'finds
|
31
|
-
|
32
|
-
sig =
|
33
|
-
_(sig.name).must_equal "
|
30
|
+
it 'finds signals defined on interfaces' do
|
31
|
+
skip_below "1.57.2"
|
32
|
+
sig = sub_obj_builder.find_signal "interface-signal"
|
33
|
+
_(sig.name).must_equal "interface-signal"
|
34
34
|
end
|
35
35
|
|
36
36
|
it "returns nil for a signal that doesn't exist" do
|
@@ -32,7 +32,9 @@ describe GirFFI::Builders::PropertyBuilder do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe "for a property of type :ghash" do
|
35
|
-
let(:property_info)
|
35
|
+
let(:property_info) do
|
36
|
+
get_property_introspection_data("Regress", "TestObj", "hash-table")
|
37
|
+
end
|
36
38
|
it "generates the correct getter definition" do
|
37
39
|
expected = <<~CODE
|
38
40
|
def hash_table
|
@@ -148,7 +150,8 @@ describe GirFFI::Builders::PropertyBuilder do
|
|
148
150
|
before do
|
149
151
|
allow(property_info).to receive(:container).and_return container_info
|
150
152
|
allow(property_info).to receive(:name).and_return "foo-bar"
|
151
|
-
allow(container_info)
|
153
|
+
allow(container_info)
|
154
|
+
.to receive(:find_instance_method).with("foo_bar").and_return true
|
152
155
|
end
|
153
156
|
|
154
157
|
it "finds methods with underscores for properties with dashes" do
|
@@ -6,7 +6,9 @@ describe GirFFI::Builders::ReturnValueBuilder do
|
|
6
6
|
let(:var_gen) { GirFFI::VariableNameGenerator.new }
|
7
7
|
let(:type_info) { method_info.return_type }
|
8
8
|
let(:ownership_transfer) { method_info.caller_owns }
|
9
|
-
let(:return_type_info)
|
9
|
+
let(:return_type_info) do
|
10
|
+
GirFFI::ReturnValueInfo.new(type_info, ownership_transfer, false)
|
11
|
+
end
|
10
12
|
let(:builder) do
|
11
13
|
GirFFI::Builders::ReturnValueBuilder.new(var_gen, return_type_info)
|
12
14
|
end
|
@@ -37,7 +39,8 @@ describe GirFFI::Builders::ReturnValueBuilder do
|
|
37
39
|
|
38
40
|
it "wraps and copies the result in #post_conversion" do
|
39
41
|
_(builder.capture_variable_name).must_equal "_v1"
|
40
|
-
_(builder.post_conversion)
|
42
|
+
_(builder.post_conversion)
|
43
|
+
.must_equal ["_v2 = GIMarshallingTests::BoxedStruct.wrap_copy(_v1)"]
|
41
44
|
end
|
42
45
|
|
43
46
|
it "returns the copied result" do
|
@@ -56,7 +59,8 @@ describe GirFFI::Builders::ReturnValueBuilder do
|
|
56
59
|
|
57
60
|
it "wraps the result in #post_conversion" do
|
58
61
|
_(builder.capture_variable_name).must_equal "_v1"
|
59
|
-
_(builder.post_conversion)
|
62
|
+
_(builder.post_conversion)
|
63
|
+
.must_equal ["_v2 = GIMarshallingTests::Union.wrap_copy(_v1)"]
|
60
64
|
end
|
61
65
|
|
62
66
|
it "returns the wrapped result" do
|
@@ -112,7 +116,9 @@ describe GirFFI::Builders::ReturnValueBuilder do
|
|
112
116
|
it "wraps the result in #post_conversion" do
|
113
117
|
_(builder.capture_variable_name).must_equal "_v1"
|
114
118
|
_(builder.post_conversion)
|
115
|
-
.must_equal [
|
119
|
+
.must_equal [
|
120
|
+
"_v2 = GIMarshallingTests::Object.wrap(_v1).tap { |it| it && it.ref }"
|
121
|
+
]
|
116
122
|
end
|
117
123
|
|
118
124
|
it "returns the wrapped result" do
|
@@ -149,7 +155,8 @@ describe GirFFI::Builders::ReturnValueBuilder do
|
|
149
155
|
|
150
156
|
it "wraps the result in #post_conversion" do
|
151
157
|
_(builder.capture_variable_name).must_equal "_v1"
|
152
|
-
_(builder.post_conversion)
|
158
|
+
_(builder.post_conversion)
|
159
|
+
.must_equal ["_v2 = GirFFI::ZeroTerminated.wrap(:guint8, _v1)"]
|
153
160
|
end
|
154
161
|
|
155
162
|
it "returns the wrapped result" do
|
@@ -234,7 +241,8 @@ describe GirFFI::Builders::ReturnValueBuilder do
|
|
234
241
|
|
235
242
|
it "wraps the result in #post_conversion" do
|
236
243
|
_(builder.capture_variable_name).must_equal "_v1"
|
237
|
-
_(builder.post_conversion)
|
244
|
+
_(builder.post_conversion)
|
245
|
+
.must_equal ["_v2 = GLib::HashTable.wrap([:gint32, :gint32], _v1)"]
|
238
246
|
end
|
239
247
|
|
240
248
|
it "returns the wrapped result" do
|
@@ -286,7 +294,8 @@ describe GirFFI::Builders::ReturnValueBuilder do
|
|
286
294
|
|
287
295
|
it "converts the result in #post_conversion" do
|
288
296
|
_(builder.capture_variable_name).must_equal "_v1"
|
289
|
-
_(builder.post_conversion)
|
297
|
+
_(builder.post_conversion)
|
298
|
+
.must_equal ["_v2 = GirFFI::SizedArray.wrap(:gint32, 4, _v1)"]
|
290
299
|
end
|
291
300
|
|
292
301
|
it "returns the wrapped result" do
|
@@ -310,7 +319,8 @@ describe GirFFI::Builders::ReturnValueBuilder do
|
|
310
319
|
|
311
320
|
it "converts the result in #post_conversion" do
|
312
321
|
_(builder.capture_variable_name).must_equal "_v1"
|
313
|
-
_(builder.post_conversion)
|
322
|
+
_(builder.post_conversion)
|
323
|
+
.must_equal ["_v2 = GirFFI::SizedArray.wrap(:gint32, bar, _v1)"]
|
314
324
|
end
|
315
325
|
|
316
326
|
it "returns the wrapped result" do
|
@@ -403,7 +413,8 @@ describe GirFFI::Builders::ReturnValueBuilder do
|
|
403
413
|
|
404
414
|
it "fetches the stored object in #post_conversion" do
|
405
415
|
_(builder.capture_variable_name).must_equal "_v1"
|
406
|
-
_(builder.post_conversion)
|
416
|
+
_(builder.post_conversion)
|
417
|
+
.must_equal ["_v2 = GirFFI::ArgHelper::OBJECT_STORE.fetch(_v1)"]
|
407
418
|
end
|
408
419
|
|
409
420
|
it "returns the stored object" do
|
@@ -134,19 +134,21 @@ describe GirFFI::Builders::SignalClosureBuilder do
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
-
describe "for a signal returning
|
137
|
+
describe "for a signal returning a string" do
|
138
138
|
let(:signal_info) do
|
139
|
-
get_signal_introspection_data "
|
139
|
+
get_signal_introspection_data "Regress", "AnnotationObject", "attribute-signal"
|
140
140
|
end
|
141
141
|
|
142
|
-
it "returns a mapping method that passes the string result to return_value directly"
|
142
|
+
it "returns a mapping method that passes the string result to return_value directly" \
|
143
|
+
do
|
143
144
|
expected = <<~CODE
|
144
145
|
def self.marshaller(closure, return_value, param_values, _invocation_hint, _marshal_data)
|
145
|
-
_instance,
|
146
|
+
_instance, arg1, arg2 = param_values.map(&:get_value_plain)
|
146
147
|
_v1 = _instance
|
147
|
-
_v2 =
|
148
|
-
_v3 =
|
149
|
-
|
148
|
+
_v2 = arg1
|
149
|
+
_v3 = arg2
|
150
|
+
_v4 = wrap(closure.to_ptr).invoke_block(_v1, _v2, _v3)
|
151
|
+
return_value.set_value _v4
|
150
152
|
end
|
151
153
|
CODE
|
152
154
|
|
@@ -34,9 +34,12 @@ describe GirFFI::Builders::StructBuilder do
|
|
34
34
|
|
35
35
|
describe "for a struct with a layout with a complex type" do
|
36
36
|
it "does not flatten the complex type specification" do
|
37
|
-
expect(simplefield = Object.new)
|
38
|
-
|
39
|
-
expect(
|
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]
|
40
43
|
|
41
44
|
allow(struct).to receive(:safe_name).and_return "Bar"
|
42
45
|
allow(struct).to receive(:namespace).and_return "Foo"
|
@@ -94,11 +94,14 @@ describe GirFFI::Builders::UserDefinedBuilder do
|
|
94
94
|
_(q.instance_size).must_equal expected_size
|
95
95
|
end
|
96
96
|
|
97
|
-
it "
|
97
|
+
it "creates fields for the parents and properties in the type's Struct" do
|
98
98
|
offsets = derived_class::Struct.offsets
|
99
99
|
alignment = derived_class::Struct.alignment
|
100
100
|
_(alignment).must_equal 8 # TODO: Fix tests for platforms where this fails.
|
101
|
-
_(offsets).must_equal [[:parent, 0],
|
101
|
+
_(offsets).must_equal [[:parent, 0],
|
102
|
+
[:string_prop, 32],
|
103
|
+
[:int_prop, 40],
|
104
|
+
[:long_prop, 48]]
|
102
105
|
end
|
103
106
|
|
104
107
|
it "creates accessor functions for the string property" do
|
@@ -194,7 +197,8 @@ describe GirFFI::Builders::UserDefinedBuilder do
|
|
194
197
|
|
195
198
|
_(object_ref_count(object)).must_equal 1
|
196
199
|
obj.set_property("object_prop", object)
|
197
|
-
|
200
|
+
# Expect 4 due to extra Value#set_value + Value#get_value
|
201
|
+
_(object_ref_count(object)).must_equal 4
|
198
202
|
end
|
199
203
|
end
|
200
204
|
|
@@ -23,7 +23,8 @@ describe GirFFI::Builders::VFuncArgumentBuilder do
|
|
23
23
|
|
24
24
|
describe "for a transfer-none in argument" do
|
25
25
|
let(:vfunc_info) do
|
26
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
26
|
+
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
27
|
+
"vfunc_in_object_transfer_none"
|
27
28
|
end
|
28
29
|
let(:arg_info) { vfunc_info.args[0] }
|
29
30
|
|
@@ -38,7 +39,8 @@ describe GirFFI::Builders::VFuncArgumentBuilder do
|
|
38
39
|
|
39
40
|
describe "for a transfer-none outgoing object argument" do
|
40
41
|
let(:vfunc_info) do
|
41
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
42
|
+
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
43
|
+
"vfunc_out_object_transfer_none"
|
42
44
|
end
|
43
45
|
let(:arg_info) { vfunc_info.args[0] }
|
44
46
|
|
@@ -53,7 +55,8 @@ describe GirFFI::Builders::VFuncArgumentBuilder do
|
|
53
55
|
|
54
56
|
describe "for a full-transfer outgoing object argument" do
|
55
57
|
let(:vfunc_info) do
|
56
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
58
|
+
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
59
|
+
"vfunc_out_object_transfer_full"
|
57
60
|
end
|
58
61
|
let(:arg_info) { vfunc_info.args[0] }
|
59
62
|
|
@@ -63,7 +66,8 @@ describe GirFFI::Builders::VFuncArgumentBuilder do
|
|
63
66
|
|
64
67
|
it "has the correct value for #post_conversion" do
|
65
68
|
builder.pre_conversion
|
66
|
-
_(builder.post_conversion)
|
69
|
+
_(builder.post_conversion)
|
70
|
+
.must_equal ["_v2.ref", "_v1.put_pointer 0, GObject::Object.from(_v2)"]
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
@@ -76,7 +80,9 @@ describe GirFFI::Builders::VFuncArgumentBuilder do
|
|
76
80
|
|
77
81
|
it "has the correct value for #pre_conversion" do
|
78
82
|
_(builder.pre_conversion)
|
79
|
-
.must_equal [
|
83
|
+
.must_equal [
|
84
|
+
"_v1 = FFI::MemoryPointer.new(:int8).tap { |ptr| out.put_pointer 0, ptr }"
|
85
|
+
]
|
80
86
|
end
|
81
87
|
|
82
88
|
it "has the correct value for #post_conversion" do
|
@@ -85,7 +85,7 @@ describe GirFFI::Builders::VFuncBuilder do
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
describe "for a vfunc with an out argument allocated by
|
88
|
+
describe "for a vfunc with an out argument allocated by the callee" do
|
89
89
|
let(:vfunc_info) do
|
90
90
|
get_vfunc_introspection_data("GIMarshallingTests", "Object",
|
91
91
|
"method_int8_arg_and_out_callee")
|
@@ -106,7 +106,7 @@ describe GirFFI::Builders::VFuncBuilder do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
describe "for a vfunc with a GObject::Value out argument allocated by
|
109
|
+
describe "for a vfunc with a GObject::Value out argument allocated by the caller" do
|
110
110
|
let(:vfunc_info) do
|
111
111
|
get_vfunc_introspection_data("GIMarshallingTests", "Object",
|
112
112
|
"vfunc_caller_allocated_out_parameter")
|
@@ -153,7 +153,8 @@ describe GirFFI::Builders::VFuncBuilder do
|
|
153
153
|
|
154
154
|
describe "for a vfunc with a full-transfer return value" do
|
155
155
|
let(:vfunc_info) do
|
156
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
156
|
+
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
157
|
+
"vfunc_return_object_transfer_full"
|
157
158
|
end
|
158
159
|
|
159
160
|
it "returns a valid mapping method" do
|
@@ -173,7 +174,8 @@ describe GirFFI::Builders::VFuncBuilder do
|
|
173
174
|
|
174
175
|
describe "for a vfunc with a transfer-none in argument" do
|
175
176
|
let(:vfunc_info) do
|
176
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
177
|
+
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
178
|
+
"vfunc_in_object_transfer_none"
|
177
179
|
end
|
178
180
|
|
179
181
|
it "returns a valid mapping method" do
|
@@ -192,7 +194,8 @@ describe GirFFI::Builders::VFuncBuilder do
|
|
192
194
|
|
193
195
|
describe "for a vfunc with a full-transfer outgoing argument" do
|
194
196
|
let(:vfunc_info) do
|
195
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
197
|
+
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
198
|
+
"vfunc_out_object_transfer_full"
|
196
199
|
end
|
197
200
|
|
198
201
|
it "returns a valid mapping method" do
|
@@ -230,7 +233,8 @@ describe GirFFI::Builders::VFuncBuilder do
|
|
230
233
|
|
231
234
|
describe "for a vfunc returning an object" do
|
232
235
|
let(:vfunc_info) do
|
233
|
-
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
236
|
+
get_vfunc_introspection_data "GIMarshallingTests", "Object",
|
237
|
+
"vfunc_return_object_transfer_full"
|
234
238
|
end
|
235
239
|
|
236
240
|
it "returns :pointer" do
|
@@ -19,14 +19,14 @@ describe GirFFI::ClassBase do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#==" do
|
22
|
-
it "returns true
|
22
|
+
it "returns true for an object of the same class and pointer" do
|
23
23
|
other = object_class.wrap object.to_ptr
|
24
24
|
|
25
25
|
_(object).must_be :==, other
|
26
26
|
_(other).must_be :==, object
|
27
27
|
end
|
28
28
|
|
29
|
-
it "returns true
|
29
|
+
it "returns true for an object of the same class and pointer with the same address" do
|
30
30
|
ptr = FFI::Pointer.new object.to_ptr
|
31
31
|
other = object_class.wrap ptr
|
32
32
|
|
@@ -34,7 +34,7 @@ describe GirFFI::ClassBase do
|
|
34
34
|
_(other).must_be :==, object
|
35
35
|
end
|
36
36
|
|
37
|
-
it "returns false
|
37
|
+
it "returns false for an object of a sub/superclass and the same pointer" do
|
38
38
|
subclass = Class.new(object_class)
|
39
39
|
other = subclass.wrap object.to_ptr
|
40
40
|
|
@@ -42,29 +42,30 @@ describe GirFFI::ClassBase do
|
|
42
42
|
_(other).wont_be :==, object
|
43
43
|
end
|
44
44
|
|
45
|
-
it "returns false
|
45
|
+
it "returns false for an object of the same class and different pointer" do
|
46
46
|
other = object_class.wrap FFI::MemoryPointer.new(:int32)
|
47
47
|
|
48
48
|
_(object).wont_be :==, other
|
49
49
|
_(other).wont_be :==, object
|
50
50
|
end
|
51
51
|
|
52
|
-
it "returns false
|
52
|
+
it "returns false for an object that doesn't respond to #to_ptr" do
|
53
53
|
other = Object.new
|
54
54
|
|
55
55
|
_(object).wont_be :==, other
|
56
56
|
_(other).wont_be :==, object
|
57
57
|
end
|
58
58
|
|
59
|
-
it "returns false
|
59
|
+
it "returns false for an object of a different class and same pointer" do
|
60
60
|
allow(other = Object.new).to receive(:to_ptr).and_return object.to_ptr
|
61
61
|
|
62
62
|
_(object).wont_be :==, other
|
63
63
|
_(other).wont_be :==, object
|
64
64
|
end
|
65
65
|
|
66
|
-
it "returns false
|
67
|
-
allow(other = Object.new)
|
66
|
+
it "returns false for an object of a different class and different pointer" do
|
67
|
+
allow(other = Object.new)
|
68
|
+
.to receive(:to_ptr).and_return FFI::MemoryPointer.new(:int32)
|
68
69
|
|
69
70
|
_(object).wont_be :==, other
|
70
71
|
_(other).wont_be :==, object
|
@@ -116,11 +117,13 @@ describe GirFFI::ClassBase do
|
|
116
117
|
|
117
118
|
describe "#setup_and_call" do
|
118
119
|
it "looks up instance methods in all builders" do
|
119
|
-
expect(builder = Object.new)
|
120
|
+
expect(builder = Object.new)
|
121
|
+
.to receive(:setup_instance_method).with("foo").and_return "foo"
|
120
122
|
klass = Class.new GirFFI::ClassBase
|
121
123
|
klass.const_set :GIR_FFI_BUILDER, builder
|
122
124
|
|
123
|
-
expect(sub_builder = Object.new)
|
125
|
+
expect(sub_builder = Object.new)
|
126
|
+
.to receive(:setup_instance_method).with("foo").and_return nil
|
124
127
|
sub_klass = Class.new klass do
|
125
128
|
def foo; end
|
126
129
|
|
@@ -134,7 +137,8 @@ describe GirFFI::ClassBase do
|
|
134
137
|
end
|
135
138
|
|
136
139
|
it "calls the method given by the result of .setup_instance_method" do
|
137
|
-
expect(builder = Object.new)
|
140
|
+
expect(builder = Object.new)
|
141
|
+
.to receive(:setup_instance_method).with("foo").and_return "bar"
|
138
142
|
klass = Class.new GirFFI::ClassBase do
|
139
143
|
def bar
|
140
144
|
"correct-result"
|
@@ -151,7 +155,8 @@ describe GirFFI::ClassBase do
|
|
151
155
|
end
|
152
156
|
|
153
157
|
it "raises a sensible error if the method is not found" do
|
154
|
-
expect(builder = Object.new)
|
158
|
+
expect(builder = Object.new)
|
159
|
+
.to receive(:setup_instance_method).with("foo").and_return nil
|
155
160
|
klass = Class.new GirFFI::ClassBase do
|
156
161
|
def initialize; end
|
157
162
|
end
|
data/test/gir_ffi/core_test.rb
CHANGED
@@ -18,12 +18,13 @@ describe GirFFI::Core do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "sets up dependencies" do
|
21
|
-
save_module :
|
21
|
+
save_module :Utility
|
22
22
|
save_module :Regress
|
23
|
+
refute Object.const_defined?(:Utility)
|
23
24
|
GirFFI.setup :Regress
|
24
|
-
assert Object.const_defined?(:
|
25
|
+
assert Object.const_defined?(:Utility)
|
25
26
|
restore_module :Regress
|
26
|
-
restore_module :
|
27
|
+
restore_module :Utility
|
27
28
|
end
|
28
29
|
|
29
30
|
describe ".setup" do
|
@@ -10,8 +10,10 @@ describe GirFFI::FFIExt::Pointer do
|
|
10
10
|
expect(ptr).to receive(:null?).and_return false
|
11
11
|
object_class = Class.new
|
12
12
|
|
13
|
-
expect(GObject)
|
14
|
-
|
13
|
+
expect(GObject)
|
14
|
+
.to receive(:type_from_instance_pointer).with(ptr).and_return 0xdeadbeef
|
15
|
+
expect(GirFFI::Builder)
|
16
|
+
.to receive(:build_by_gtype).with(0xdeadbeef).and_return object_class
|
15
17
|
expect(object_class).to receive(:direct_wrap).with(ptr).and_return "good-result"
|
16
18
|
|
17
19
|
_(ptr.to_object).must_equal "good-result"
|