gir_ffi 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/History.txt +8 -0
  2. data/lib/ffi-glib/array.rb +1 -1
  3. data/lib/ffi-glib.rb +7 -12
  4. data/lib/ffi-gobject/closure.rb +1 -4
  5. data/lib/ffi-gobject/object.rb +2 -2
  6. data/lib/ffi-gobject/ruby_style.rb +2 -0
  7. data/lib/ffi-gobject/value.rb +19 -1
  8. data/lib/ffi-gobject.rb +14 -9
  9. data/lib/ffi-gobject_introspection/i_base_info.rb +5 -5
  10. data/lib/ffi-gobject_introspection/i_repository.rb +1 -1
  11. data/lib/ffi-gobject_introspection/lib.rb +1 -1
  12. data/lib/gir_ffi/arg_helper.rb +3 -3
  13. data/lib/gir_ffi/argument_builder.rb +21 -17
  14. data/lib/gir_ffi/base_argument_builder.rb +5 -3
  15. data/lib/gir_ffi/builder/type/object.rb +1 -0
  16. data/lib/gir_ffi/builder/type/user_defined.rb +2 -3
  17. data/lib/gir_ffi/builder.rb +2 -2
  18. data/lib/gir_ffi/builder_helper.rb +2 -2
  19. data/lib/gir_ffi/callback_helper.rb +9 -9
  20. data/lib/gir_ffi/function_builder.rb +2 -2
  21. data/lib/gir_ffi/in_out_pointer.rb +1 -3
  22. data/lib/gir_ffi/in_pointer.rb +15 -2
  23. data/lib/gir_ffi/info_ext/i_arg_info.rb +27 -0
  24. data/lib/gir_ffi/info_ext/i_field_info.rb +1 -0
  25. data/lib/gir_ffi/info_ext/i_property_info.rb +1 -0
  26. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +1 -1
  27. data/lib/gir_ffi/info_ext/i_signal_info.rb +65 -0
  28. data/lib/gir_ffi/info_ext/i_type_info.rb +15 -0
  29. data/lib/gir_ffi/info_ext/safe_constant_name.rb +1 -0
  30. data/lib/gir_ffi/info_ext/safe_function_name.rb +1 -0
  31. data/lib/gir_ffi/info_ext.rb +2 -0
  32. data/lib/gir_ffi/module_base.rb +1 -3
  33. data/lib/gir_ffi/return_value_builder.rb +1 -4
  34. data/lib/gir_ffi/version.rb +1 -2
  35. data/lib/gir_ffi/zero_terminated.rb +42 -0
  36. data/lib/gir_ffi.rb +1 -0
  37. data/test/ffi-gobject/value_test.rb +30 -1
  38. data/test/ffi-gobject_introspection/i_object_info_test.rb +4 -4
  39. data/test/ffi-gobject_test.rb +20 -0
  40. data/test/gir_ffi/arg_helper_test.rb +4 -4
  41. data/test/gir_ffi/argument_builder_test.rb +16 -0
  42. data/test/gir_ffi/builder_test.rb +0 -5
  43. data/test/gir_ffi/in_pointer_test.rb +20 -1
  44. data/test/gir_ffi/info_ext/i_arg_info_test.rb +39 -0
  45. data/test/gir_ffi/info_ext/i_signal_info_test.rb +51 -0
  46. data/test/gir_ffi/info_ext/i_type_info_test.rb +20 -20
  47. data/test/gir_ffi/return_value_builder_test.rb +2 -2
  48. data/test/gir_ffi/zero_terminated_test.rb +48 -0
  49. data/test/gir_ffi_test_helper.rb +3 -3
  50. data/test/integration/generated_gimarshallingtests_test.rb +38 -28
  51. data/test/integration/generated_regress_test.rb +2 -5
  52. metadata +11 -5
  53. data/lib/ffi-gobject/helper.rb +0 -114
  54. data/test/ffi-gobject/helper_test.rb +0 -103
@@ -67,7 +67,8 @@ describe GIMarshallingTests do
67
67
  end
68
68
 
69
69
  it "has the constant CONSTANT_GERROR_DEBUG_MESSAGE" do
70
- skip
70
+ GIMarshallingTests::CONSTANT_GERROR_DEBUG_MESSAGE.must_equal(
71
+ "we got an error, life is shit")
71
72
  end
72
73
 
73
74
  it "has the constant CONSTANT_GERROR_DOMAIN" do
@@ -124,19 +125,19 @@ describe GIMarshallingTests do
124
125
  end
125
126
 
126
127
  it "has a working function #in" do
127
- skip
128
+ skip "methods on enums are not supported yet"
128
129
  end
129
130
  it "has a working function #in_zero" do
130
- skip
131
+ skip "methods on enums are not supported yet"
131
132
  end
132
133
  it "has a working function #inout" do
133
- skip
134
+ skip "methods on enums are not supported yet"
134
135
  end
135
136
  it "has a working function #out" do
136
- skip
137
+ skip "methods on enums are not supported yet"
137
138
  end
138
139
  it "has a working function #returnv" do
139
- skip
140
+ skip "methods on enums are not supported yet"
140
141
  end
141
142
  end
142
143
 
@@ -151,16 +152,16 @@ describe GIMarshallingTests do
151
152
  assert_equal 42, GIMarshallingTests::GEnum[:value3]
152
153
  end
153
154
  it "has a working function #in" do
154
- skip
155
+ skip "methods on enums are not supported yet"
155
156
  end
156
157
  it "has a working function #inout" do
157
- skip
158
+ skip "methods on enums are not supported yet"
158
159
  end
159
160
  it "has a working function #out" do
160
- skip
161
+ skip "methods on enums are not supported yet"
161
162
  end
162
163
  it "has a working function #returnv" do
163
- skip
164
+ skip "methods on enums are not supported yet"
164
165
  end
165
166
  end
166
167
 
@@ -269,7 +270,10 @@ describe GIMarshallingTests do
269
270
  let(:instance) { GIMarshallingTests::Object.new 42 }
270
271
 
271
272
  it "has a working method #call_vfunc_with_callback" do
272
- skip
273
+ # NOTE: To call this method, the callback slot vfunc_with_callback has to
274
+ # be filled in the GIMarshallingTests::Object class structure. The
275
+ # GIMarshallingTests library doesn't do this.
276
+ skip "Needs vfunc setup"
273
277
  end
274
278
 
275
279
  it "has a working method #full_in" do
@@ -277,10 +281,11 @@ describe GIMarshallingTests do
277
281
  end
278
282
 
279
283
  it "has a working method #int8_in" do
280
- skip
284
+ skip "Needs vfunc setup"
281
285
  end
286
+
282
287
  it "has a working method #int8_out" do
283
- skip
288
+ skip "Needs vfunc setup"
284
289
  end
285
290
 
286
291
  # TODO: Avoid using common method names?
@@ -310,13 +315,15 @@ describe GIMarshallingTests do
310
315
  end
311
316
 
312
317
  it "has a working method #method_int8_in" do
313
- skip
318
+ skip "Needs vfunc setup"
314
319
  end
320
+
315
321
  it "has a working method #method_int8_out" do
316
- skip
322
+ skip "Needs vfunc setup"
317
323
  end
324
+
318
325
  it "has a working method #method_variant_array_in" do
319
- skip
326
+ skip "Needs vfunc setup"
320
327
  end
321
328
 
322
329
  it "has a working method #method_with_default_implementation" do
@@ -336,28 +343,28 @@ describe GIMarshallingTests do
336
343
  end
337
344
 
338
345
  it "has a working method #vfunc_caller_allocated_out_parameter" do
339
- skip
346
+ skip "Needs vfunc setup"
340
347
  end
341
348
  it "has a working method #vfunc_meth_with_error" do
342
- skip
349
+ skip "Needs vfunc setup"
343
350
  end
344
351
  it "has a working method #vfunc_multiple_out_parameters" do
345
- skip
352
+ skip "Needs vfunc setup"
346
353
  end
347
354
  it "has a working method #vfunc_one_out_parameter" do
348
- skip
355
+ skip "Needs vfunc setup"
349
356
  end
350
357
  it "has a working method #vfunc_return_value_and_multiple_out_parameters" do
351
- skip
358
+ skip "Needs vfunc setup"
352
359
  end
353
360
  it "has a working method #vfunc_return_value_and_one_out_parameter" do
354
- skip
361
+ skip "Needs vfunc setup"
355
362
  end
356
363
  it "has a working method #vfunc_return_value_only" do
357
- skip
364
+ skip "Needs vfunc setup"
358
365
  end
359
366
  it "has a working method #vfunc_with_callback" do
360
- skip
367
+ skip "Needs vfunc setup"
361
368
  end
362
369
 
363
370
  it "has a property 'int' containing the argument to #new" do
@@ -597,7 +604,7 @@ describe GIMarshallingTests do
597
604
  end
598
605
 
599
606
  it "has a working function #array_enum_in" do
600
- skip
607
+ GIMarshallingTests.array_enum_in [:value1, :value2, :value3]
601
608
  end
602
609
 
603
610
  it "has a working function #array_fixed_inout" do
@@ -704,9 +711,12 @@ describe GIMarshallingTests do
704
711
  it "has a working function #array_simple_struct_in" do
705
712
  skip
706
713
  end
714
+
707
715
  it "has a working function #array_string_in" do
708
- skip
716
+ GIMarshallingTests.array_string_in ["foo", "bar"]
717
+ pass
709
718
  end
719
+
710
720
  it "has a working function #array_struct_in" do
711
721
  skip
712
722
  end
@@ -808,8 +818,8 @@ describe GIMarshallingTests do
808
818
  ret = GIMarshallingTests.bytearray_full_return
809
819
  assert_instance_of GLib::ByteArray, ret
810
820
  assert_includes(
811
- ["0123".bytes.to_a, "\x001\xFF3".bytes.to_a],
812
- ret.to_string.bytes.to_a)
821
+ ["0123".bytes.to_a, "\x001\xFF3".bytes.to_a],
822
+ ret.to_string.bytes.to_a)
813
823
  end
814
824
 
815
825
  it "has a working function #bytearray_none_in" do
@@ -561,15 +561,12 @@ describe Regress do
561
561
  assert !is_floating?(instance)
562
562
  end
563
563
 
564
- # FIXME: Should it be possible to invoke this method by its virtual name?
565
564
  it "has a working method #matrix" do
566
- rv = instance.matrix "bar"
567
- assert_equal 42, rv
565
+ instance.matrix("bar").must_equal 42
568
566
  end
569
567
 
570
568
  it "has a working method #do_matrix" do
571
- result = instance.do_matrix "bar"
572
- result.must_equal 42
569
+ instance.do_matrix("bar").must_equal 42
573
570
  end
574
571
 
575
572
  it "has a working method #emit_sig_with_foreign_struct" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-01 00:00:00.000000000 Z
12
+ date: 2013-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -133,6 +133,7 @@ files:
133
133
  - lib/gir_ffi/user_defined/i_base_info.rb
134
134
  - lib/gir_ffi/user_defined/i_object_info.rb
135
135
  - lib/gir_ffi/user_defined/i_registered_type_info.rb
136
+ - lib/gir_ffi/zero_terminated.rb
136
137
  - lib/gir_ffi/callback.rb
137
138
  - lib/gir_ffi/argument_builder.rb
138
139
  - lib/gir_ffi/error_argument_builder.rb
@@ -148,10 +149,12 @@ files:
148
149
  - lib/gir_ffi/callback_helper.rb
149
150
  - lib/gir_ffi/builder.rb
150
151
  - lib/gir_ffi/interface_base.rb
152
+ - lib/gir_ffi/info_ext/i_arg_info.rb
151
153
  - lib/gir_ffi/info_ext/i_type_info.rb
152
154
  - lib/gir_ffi/info_ext/i_field_info.rb
153
155
  - lib/gir_ffi/info_ext/safe_constant_name.rb
154
156
  - lib/gir_ffi/info_ext/i_property_info.rb
157
+ - lib/gir_ffi/info_ext/i_signal_info.rb
155
158
  - lib/gir_ffi/info_ext/safe_function_name.rb
156
159
  - lib/gir_ffi/info_ext/i_registered_type_info.rb
157
160
  - lib/gir_ffi/module_base.rb
@@ -166,7 +169,6 @@ files:
166
169
  - lib/ffi-gobject/base.rb
167
170
  - lib/ffi-gobject/object.rb
168
171
  - lib/ffi-gobject/value.rb
169
- - lib/ffi-gobject/helper.rb
170
172
  - lib/ffi-gobject/initially_unowned.rb
171
173
  - lib/ffi-gobject/closure.rb
172
174
  - lib/ffi-glib.rb
@@ -224,6 +226,7 @@ files:
224
226
  - test/gir_ffi/builder/type/unintrospectable_test.rb
225
227
  - test/gir_ffi/builder/type/interface_test.rb
226
228
  - test/gir_ffi/builder/module_test.rb
229
+ - test/gir_ffi/zero_terminated_test.rb
227
230
  - test/gir_ffi/object_base_test.rb
228
231
  - test/gir_ffi/user_defined/i_registered_type_info_test.rb
229
232
  - test/gir_ffi/user_defined/i_object_info_test.rb
@@ -240,6 +243,8 @@ files:
240
243
  - test/gir_ffi/argument_builder_test.rb
241
244
  - test/gir_ffi/return_value_builder_test.rb
242
245
  - test/gir_ffi/info_ext/i_type_info_test.rb
246
+ - test/gir_ffi/info_ext/i_arg_info_test.rb
247
+ - test/gir_ffi/info_ext/i_signal_info_test.rb
243
248
  - test/gir_ffi/info_ext/safe_constant_name_test.rb
244
249
  - test/gir_ffi/info_ext/safe_function_name_test.rb
245
250
  - test/gir_ffi/info_ext/i_field_info_test.rb
@@ -249,7 +254,6 @@ files:
249
254
  - test/ffi-gobject/object_test.rb
250
255
  - test/ffi-gobject/gobject_test.rb
251
256
  - test/ffi-gobject/value_test.rb
252
- - test/ffi-gobject/helper_test.rb
253
257
  - test/ffi-gobject/ruby_style_test.rb
254
258
  - test/base_test_helper.rb
255
259
  - test/ffi-glib/s_list_test.rb
@@ -318,7 +322,6 @@ test_files:
318
322
  - test/ffi-glib/ruby_closure_test.rb
319
323
  - test/ffi-glib/s_list_test.rb
320
324
  - test/ffi-gobject/gobject_test.rb
321
- - test/ffi-gobject/helper_test.rb
322
325
  - test/ffi-gobject/object_class_test.rb
323
326
  - test/ffi-gobject/object_test.rb
324
327
  - test/ffi-gobject/ruby_style_test.rb
@@ -350,7 +353,9 @@ test_files:
350
353
  - test/gir_ffi/function_builder_test.rb
351
354
  - test/gir_ffi/in_out_pointer_test.rb
352
355
  - test/gir_ffi/in_pointer_test.rb
356
+ - test/gir_ffi/info_ext/i_arg_info_test.rb
353
357
  - test/gir_ffi/info_ext/i_field_info_test.rb
358
+ - test/gir_ffi/info_ext/i_signal_info_test.rb
354
359
  - test/gir_ffi/info_ext/i_type_info_test.rb
355
360
  - test/gir_ffi/info_ext/safe_constant_name_test.rb
356
361
  - test/gir_ffi/info_ext/safe_function_name_test.rb
@@ -361,6 +366,7 @@ test_files:
361
366
  - test/gir_ffi/user_defined/i_property_info_test.rb
362
367
  - test/gir_ffi/user_defined/i_registered_type_info_test.rb
363
368
  - test/gir_ffi/variable_name_generator_test.rb
369
+ - test/gir_ffi/zero_terminated_test.rb
364
370
  - test/gir_ffi_test.rb
365
371
  - test/gir_ffi_test_helper.rb
366
372
  - test/integration/derived_classes_test.rb
@@ -1,114 +0,0 @@
1
- module GObject
2
- module Helper
3
- # Create a signal hander callback. Wraps the given block in such a way that
4
- # arguments and return value are cast correctly to the ruby world and back.
5
- #
6
- # @param klass The class of the object that will receive the signal.
7
- # @param signal The name of the signal
8
- # @param block The body of the signal handler
9
- #
10
- # @return [FFI::Function] The signal handler, ready to be passed as a
11
- # callback to C.
12
- def self.signal_callback klass, signal, &block
13
- sig_info = klass.find_signal signal
14
-
15
- callback_block = signal_callback_args(sig_info, klass, &block)
16
-
17
- builder.build_callback sig_info, &callback_block
18
- end
19
-
20
- def self.builder= bldr
21
- @builder = bldr
22
- end
23
-
24
- def self.builder
25
- @builder ||= GirFFI::Builder
26
- end
27
-
28
- # FIXME: Move either to ISignalInfo or the base GObject class.
29
- def self.signal_callback_args sig, klass, &block
30
- raise ArgumentError, "Block needed" if block.nil?
31
- return Proc.new do |*args|
32
- mapped = cast_back_signal_arguments sig, klass, *args
33
- block.call(*mapped)
34
- end
35
- end
36
-
37
- def self.signal_arguments_to_gvalue_array signal, instance, *rest
38
- sig = instance.class.find_signal signal
39
-
40
- arr = ::GObject::ValueArray.new sig.n_args + 1
41
-
42
- arr.append signal_reciever_to_gvalue instance
43
-
44
- sig.args.zip(rest).each do |info, arg|
45
- arr.append signal_argument_to_gvalue info, arg
46
- end
47
-
48
- arr
49
- end
50
-
51
- def self.signal_reciever_to_gvalue instance
52
- val = ::GObject::Value.new
53
- val.init ::GObject.type_from_instance instance
54
- val.set_instance instance
55
- return val
56
- end
57
-
58
- def self.signal_argument_to_gvalue info, arg
59
- val = gvalue_for_type_info info.argument_type
60
- val.set_value arg
61
- end
62
-
63
- def self.gvalue_for_type_info info
64
- tag = info.tag
65
- gtype = case tag
66
- when :interface
67
- info.interface.g_type
68
- when :void
69
- return nil
70
- else
71
- TYPE_TAG_TO_GTYPE[tag]
72
- end
73
- raise "GType not found for type info with tag #{tag}" unless gtype
74
- Value.new.tap {|val| val.init gtype}
75
- end
76
-
77
- def self.gvalue_for_signal_return_value signal, object
78
- sig = object.class.find_signal signal
79
- rettypeinfo = sig.return_type
80
-
81
- gvalue_for_type_info rettypeinfo
82
- end
83
-
84
- # TODO: Generate cast back methods using existing Argument builders.
85
- def self.cast_back_signal_arguments signalinfo, klass, *args
86
- instance = klass.wrap args.shift
87
- user_data = GirFFI::ArgHelper::OBJECT_STORE[args.pop.address]
88
-
89
- extra_arguments = signalinfo.args.zip(args).map do |info, arg|
90
- cast_signal_argument(info, arg)
91
- end
92
-
93
- return [instance, *extra_arguments].push user_data
94
- end
95
-
96
- def self.cast_signal_argument info, arg
97
- arg_t = info.argument_type
98
- if arg_t.tag == :interface
99
- iface = arg_t.interface
100
- kls = GirFFI::Builder.build_class iface
101
- case iface.info_type
102
- when :enum, :flags
103
- kls[arg]
104
- when :interface
105
- arg.to_object
106
- else
107
- kls.wrap(arg)
108
- end
109
- else
110
- arg
111
- end
112
- end
113
- end
114
- end
@@ -1,103 +0,0 @@
1
- require 'gir_ffi_test_helper'
2
-
3
- describe GObject::Helper do
4
- before do
5
- GirFFI.setup :Regress
6
- end
7
-
8
- describe "#signal_arguments_to_gvalue_array" do
9
- describe "the result of wrapping test-with-static-scope-arg" do
10
- setup do
11
- o = Regress::TestSubObj.new
12
- b = Regress::TestSimpleBoxedA.new
13
-
14
- @gva =
15
- GObject::Helper.signal_arguments_to_gvalue_array(
16
- "test-with-static-scope-arg", o, b)
17
- end
18
-
19
- should "be a GObject::ValueArray" do
20
- assert_instance_of GObject::ValueArray, @gva
21
- end
22
-
23
- should "contain two values" do
24
- assert_equal 2, @gva.n_values
25
- end
26
-
27
- should "have a first value with GType for TestSubObj" do
28
- assert_equal Regress::TestSubObj.get_gtype, (@gva.get_nth 0).current_gtype
29
- end
30
-
31
- should "have a second value with GType for TestSimpleBoxedA" do
32
- assert_equal Regress::TestSimpleBoxedA.get_gtype, (@gva.get_nth 1).current_gtype
33
- end
34
- end
35
- end
36
-
37
- describe "#signal_argument_to_gvalue" do
38
- it "maps a :utf8 argument to a string-valued GValue" do
39
- stub(arg_t = Object.new).tag { :utf8 }
40
- stub(info = Object.new).argument_type { arg_t }
41
- val =
42
- GObject::Helper.signal_argument_to_gvalue(
43
- info, "foo")
44
- assert_instance_of GObject::Value, val
45
- assert_equal "foo", val.get_string
46
- end
47
- end
48
-
49
- describe "#cast_back_signal_arguments" do
50
- it "correctly casts back pointers for the test-with-static-scope-arg signal" do
51
- o = Regress::TestSubObj.new
52
- b = Regress::TestSimpleBoxedA.new
53
- ud = GirFFI::ArgHelper.object_to_inptr "Hello!"
54
-
55
- assert_equal "Hello!", GirFFI::ArgHelper::OBJECT_STORE[ud.address]
56
-
57
- sig = o.class.find_signal "test-with-static-scope-arg"
58
-
59
- gva =
60
- GObject::Helper.cast_back_signal_arguments(
61
- sig, o.class, o.to_ptr, b.to_ptr, ud)
62
-
63
- klasses = gva.map {|it| it.class}
64
- klasses.must_equal [ Regress::TestSubObj,
65
- Regress::TestSimpleBoxedA,
66
- String ]
67
- gva[2].must_equal "Hello!"
68
- end
69
- end
70
-
71
- describe "#cast_signal_argument" do
72
- describe "with info for an enum" do
73
- before do
74
- enuminfo = get_introspection_data 'GLib', 'DateMonth'
75
- stub(arg_t = Object.new).interface { enuminfo }
76
- stub(arg_t).tag { :interface }
77
- stub(@info = Object.new).argument_type { arg_t }
78
- end
79
-
80
- it "casts an integer to its enum symbol" do
81
- res = GObject::Helper.cast_signal_argument @info, 7
82
- assert_equal :july, res
83
- end
84
- end
85
-
86
- describe "with info for an interface" do
87
- before do
88
- ifaceinfo = get_introspection_data 'Regress', 'TestInterface'
89
- stub(arg_t = Object.new).interface { ifaceinfo }
90
- stub(arg_t).tag { :interface }
91
- stub(@info = Object.new).argument_type { arg_t }
92
- end
93
-
94
- it "casts the argument by calling #to_object on it" do
95
- mock(ptr = Object.new).to_object { "good-result" }
96
- res = GObject::Helper.cast_signal_argument @info, ptr
97
- res.must_equal "good-result"
98
- end
99
- end
100
- end
101
-
102
- end
103
-