gir_ffi 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/History.txt +14 -0
  2. data/TODO.rdoc +23 -5
  3. data/lib/ffi-glib/array.rb +14 -15
  4. data/lib/ffi-glib/container_class_methods.rb +0 -1
  5. data/lib/ffi-glib/hash_table.rb +3 -4
  6. data/lib/ffi-glib/ptr_array.rb +12 -4
  7. data/lib/ffi-glib/sized_array.rb +27 -7
  8. data/lib/ffi-gobject.rb +14 -15
  9. data/lib/ffi-gobject/closure.rb +1 -1
  10. data/lib/ffi-gobject/object.rb +40 -15
  11. data/lib/ffi-gobject/ruby_closure.rb +0 -1
  12. data/lib/ffi-gobject/value.rb +45 -21
  13. data/lib/ffi-gobject_introspection/i_arg_info.rb +4 -0
  14. data/lib/ffi-gobject_introspection/i_base_info.rb +42 -2
  15. data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
  16. data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -4
  17. data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
  18. data/lib/ffi-gobject_introspection/i_object_info.rb +2 -0
  19. data/lib/ffi-gobject_introspection/i_repository.rb +2 -3
  20. data/lib/ffi-gobject_introspection/i_struct_info.rb +3 -8
  21. data/lib/ffi-gobject_introspection/lib.rb +3 -0
  22. data/lib/gir_ffi-base.rb +3 -1
  23. data/lib/gir_ffi-base/gir_ffi/struct.rb +27 -0
  24. data/lib/gir_ffi-base/glib/boolean.rb +13 -1
  25. data/lib/gir_ffi-base/gobject.rb +7 -0
  26. data/lib/gir_ffi-base/gobject/lib.rb +0 -2
  27. data/lib/gir_ffi.rb +1 -3
  28. data/lib/gir_ffi/arg_helper.rb +4 -85
  29. data/lib/gir_ffi/builder.rb +5 -5
  30. data/lib/gir_ffi/builder_helper.rb +7 -0
  31. data/lib/gir_ffi/builders/argument_builder.rb +132 -0
  32. data/lib/gir_ffi/{base_argument_builder.rb → builders/base_argument_builder.rb} +32 -41
  33. data/lib/gir_ffi/builders/base_type_builder.rb +47 -0
  34. data/lib/gir_ffi/builders/callback_builder.rb +38 -0
  35. data/lib/gir_ffi/builders/constant_builder.rb +18 -0
  36. data/lib/gir_ffi/builders/enum_builder.rb +62 -0
  37. data/lib/gir_ffi/builders/error_argument_builder.rb +18 -0
  38. data/lib/gir_ffi/builders/field_builder.rb +94 -0
  39. data/lib/gir_ffi/builders/function_builder.rb +123 -0
  40. data/lib/gir_ffi/builders/interface_builder.rb +29 -0
  41. data/lib/gir_ffi/builders/mapping_method_builder.rb +88 -0
  42. data/lib/gir_ffi/builders/module_builder.rb +124 -0
  43. data/lib/gir_ffi/{null_argument_builder.rb → builders/null_argument_builder.rb} +0 -0
  44. data/lib/gir_ffi/builders/null_builder.rb +11 -0
  45. data/lib/gir_ffi/builders/object_builder.rb +123 -0
  46. data/lib/gir_ffi/{builder/property.rb → builders/property_builder.rb} +0 -0
  47. data/lib/gir_ffi/builders/registered_type_builder.rb +50 -0
  48. data/lib/gir_ffi/builders/return_value_builder.rb +68 -0
  49. data/lib/gir_ffi/builders/signal_builder.rb +91 -0
  50. data/lib/gir_ffi/builders/struct_builder.rb +35 -0
  51. data/lib/gir_ffi/builders/type_builder.rb +40 -0
  52. data/lib/gir_ffi/builders/unintrospectable_builder.rb +35 -0
  53. data/lib/gir_ffi/builders/union_builder.rb +34 -0
  54. data/lib/gir_ffi/builders/user_defined_builder.rb +103 -0
  55. data/lib/gir_ffi/builders/with_layout.rb +55 -0
  56. data/lib/gir_ffi/builders/with_methods.rb +44 -0
  57. data/lib/gir_ffi/callback_base.rb +31 -0
  58. data/lib/gir_ffi/class_base.rb +16 -10
  59. data/lib/gir_ffi/enum_base.rb +8 -4
  60. data/lib/gir_ffi/ffi_ext/pointer.rb +19 -2
  61. data/lib/gir_ffi/in_out_pointer.rb +38 -39
  62. data/lib/gir_ffi/in_pointer.rb +33 -18
  63. data/lib/gir_ffi/info_ext.rb +0 -4
  64. data/lib/gir_ffi/info_ext/i_arg_info.rb +0 -18
  65. data/lib/gir_ffi/info_ext/i_callable_info.rb +2 -1
  66. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +6 -8
  67. data/lib/gir_ffi/info_ext/i_signal_info.rb +6 -21
  68. data/lib/gir_ffi/info_ext/i_type_info.rb +54 -29
  69. data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -1
  70. data/lib/gir_ffi/interface_base.rb +1 -1
  71. data/lib/gir_ffi/module_base.rb +5 -1
  72. data/lib/gir_ffi/object_base.rb +5 -1
  73. data/lib/gir_ffi/setter_argument_info.rb +4 -0
  74. data/lib/gir_ffi/signal_base.rb +21 -0
  75. data/lib/gir_ffi/struct_base.rb +24 -0
  76. data/lib/gir_ffi/type_base.rb +11 -0
  77. data/lib/gir_ffi/type_map.rb +4 -2
  78. data/lib/gir_ffi/union_base.rb +24 -0
  79. data/lib/gir_ffi/version.rb +1 -1
  80. data/tasks/test.rake +73 -7
  81. data/test/base_test_helper.rb +3 -19
  82. data/test/ffi-glib/array_test.rb +6 -0
  83. data/test/ffi-glib/ptr_array_test.rb +13 -0
  84. data/test/ffi-glib/ruby_closure_test.rb +7 -7
  85. data/test/ffi-glib/sized_array_test.rb +2 -2
  86. data/test/ffi-gobject/gobject_test.rb +3 -12
  87. data/test/ffi-gobject/object_test.rb +33 -2
  88. data/test/ffi-gobject/value_test.rb +114 -1
  89. data/test/ffi-gobject_introspection/i_enum_info_test.rb +2 -2
  90. data/test/ffi-gobject_introspection/i_object_info_test.rb +3 -3
  91. data/test/ffi-gobject_introspection/i_repository_test.rb +26 -21
  92. data/test/ffi-gobject_test.rb +14 -14
  93. data/test/gir_ffi-base/glib/boolean_test.rb +6 -0
  94. data/test/gir_ffi/arg_helper_test.rb +2 -122
  95. data/test/gir_ffi/builder_test.rb +67 -204
  96. data/test/gir_ffi/{argument_builder_test.rb → builders/argument_builder_test.rb} +230 -108
  97. data/test/gir_ffi/builders/base_argument_builder_test.rb +5 -0
  98. data/test/gir_ffi/builders/callback_builder_test.rb +50 -0
  99. data/test/gir_ffi/builders/constant_builder_test.rb +4 -0
  100. data/test/gir_ffi/{builder/type/enum_test.rb → builders/enum_builder_test.rb} +2 -3
  101. data/test/gir_ffi/builders/field_builder_test.rb +94 -0
  102. data/test/gir_ffi/{function_builder_test.rb → builders/function_builder_test.rb} +43 -24
  103. data/test/gir_ffi/{builder/type/interface_test.rb → builders/interface_builder_test.rb} +2 -2
  104. data/test/gir_ffi/{builder/module_test.rb → builders/module_builder_test.rb} +12 -13
  105. data/test/gir_ffi/{builder/type/object_test.rb → builders/object_builder_test.rb} +9 -9
  106. data/test/gir_ffi/{return_value_builder_test.rb → builders/return_value_builder_test.rb} +94 -58
  107. data/test/gir_ffi/builders/signal_builder_test.rb +62 -0
  108. data/test/gir_ffi/{builder/type/struct_test.rb → builders/struct_builder_test.rb} +36 -19
  109. data/test/gir_ffi/{builder/type/unintrospectable_test.rb → builders/unintrospectable_builder_test.rb} +3 -3
  110. data/test/gir_ffi/builders/union_builder_test.rb +29 -0
  111. data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb} +2 -2
  112. data/test/gir_ffi/callback_base_test.rb +11 -0
  113. data/test/gir_ffi/class_base_test.rb +22 -22
  114. data/test/gir_ffi/ffi_ext/pointer_test.rb +18 -0
  115. data/test/gir_ffi/in_out_pointer_test.rb +0 -7
  116. data/test/gir_ffi/in_pointer_test.rb +27 -3
  117. data/test/gir_ffi/info_ext/i_signal_info_test.rb +16 -44
  118. data/test/gir_ffi/info_ext/i_type_info_test.rb +315 -74
  119. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +6 -0
  120. data/test/gir_ffi/interface_base_test.rb +3 -5
  121. data/test/gir_ffi/object_base_test.rb +10 -6
  122. data/test/gir_ffi/type_map_test.rb +2 -2
  123. data/test/gir_ffi/unintrospectable_type_info_test.rb +2 -2
  124. data/test/gir_ffi_test_helper.rb +12 -4
  125. data/test/integration/generated_gimarshallingtests_test.rb +436 -76
  126. data/test/integration/generated_gio_test.rb +5 -11
  127. data/test/integration/generated_gobject_test.rb +8 -0
  128. data/test/integration/generated_regress_test.rb +755 -309
  129. data/test/integration/generated_secret_test.rb +2 -1
  130. metadata +73 -72
  131. data/lib/ffi-gobject/ruby_style.rb +0 -23
  132. data/lib/gir_ffi/argument_builder.rb +0 -154
  133. data/lib/gir_ffi/builder/field.rb +0 -60
  134. data/lib/gir_ffi/builder/module.rb +0 -127
  135. data/lib/gir_ffi/builder/type.rb +0 -39
  136. data/lib/gir_ffi/builder/type/base.rb +0 -48
  137. data/lib/gir_ffi/builder/type/callback.rb +0 -30
  138. data/lib/gir_ffi/builder/type/constant.rb +0 -22
  139. data/lib/gir_ffi/builder/type/enum.rb +0 -66
  140. data/lib/gir_ffi/builder/type/interface.rb +0 -33
  141. data/lib/gir_ffi/builder/type/object.rb +0 -134
  142. data/lib/gir_ffi/builder/type/registered_type.rb +0 -62
  143. data/lib/gir_ffi/builder/type/struct.rb +0 -34
  144. data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -39
  145. data/lib/gir_ffi/builder/type/union.rb +0 -34
  146. data/lib/gir_ffi/builder/type/user_defined.rb +0 -107
  147. data/lib/gir_ffi/builder/type/with_layout.rb +0 -62
  148. data/lib/gir_ffi/builder/type/with_methods.rb +0 -64
  149. data/lib/gir_ffi/callback.rb +0 -72
  150. data/lib/gir_ffi/callback_helper.rb +0 -11
  151. data/lib/gir_ffi/error_argument_builder.rb +0 -17
  152. data/lib/gir_ffi/function_builder.rb +0 -112
  153. data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -11
  154. data/lib/gir_ffi/info_ext/i_object_info.rb +0 -11
  155. data/lib/gir_ffi/info_ext/i_struct_info.rb +0 -11
  156. data/lib/gir_ffi/info_ext/i_union_info.rb +0 -12
  157. data/lib/gir_ffi/return_value_builder.rb +0 -81
  158. data/test/ffi-gobject/ruby_style_test.rb +0 -38
  159. data/test/gir_ffi/base_argument_builder_test.rb +0 -13
  160. data/test/gir_ffi/builder/type/callback_test.rb +0 -6
  161. data/test/gir_ffi/builder/type/constant_test.rb +0 -4
  162. data/test/gir_ffi/builder/type/union_test.rb +0 -12
  163. data/test/gir_ffi/callback_helper_test.rb +0 -10
  164. data/test/gir_ffi/callback_test.rb +0 -49
  165. data/test/gir_ffi/info_ext/i_arg_info_test.rb +0 -39
  166. data/test/gir_ffi/info_ext/i_object_info_test.rb +0 -14
@@ -2,17 +2,11 @@ require 'gir_ffi_test_helper'
2
2
 
3
3
  # Tests generated methods and functions in the Gio namespace.
4
4
  describe "The generated Gio module" do
5
- setup do
5
+ before do
6
6
  GirFFI.setup :Gio
7
7
  end
8
8
 
9
9
  describe "#file_new_for_path, a method returning an interface," do
10
- it "does not throw an error when generated" do
11
- assert_nothing_raised {
12
- Gio.file_new_for_path('/')
13
- }
14
- end
15
-
16
10
  it "returns an object of a more specific class" do
17
11
  file = Gio.file_new_for_path('/')
18
12
  refute_instance_of Gio::File, file
@@ -41,14 +35,14 @@ describe "The generated Gio module" do
41
35
  end
42
36
  end
43
37
 
44
- context "the FileInfo class" do
45
- context "an instance" do
46
- setup do
38
+ describe "the FileInfo class" do
39
+ describe "an instance" do
40
+ before do
47
41
  file = Gio.file_new_for_path('/')
48
42
  @fileinfo = file.query_info "*", :none, nil
49
43
  end
50
44
 
51
- should "hava a working #get_attribute_type method" do
45
+ it "has a working #get_attribute_type method" do
52
46
  type = @fileinfo.get_attribute_type "standard::display-name"
53
47
  assert_equal :string, type
54
48
  end
@@ -27,4 +27,12 @@ describe "The generated GObject module" do
27
27
  assert_includes klass.ancestors, GObject::TypePlugin
28
28
  end
29
29
  end
30
+
31
+ describe "the ValueArray struct class" do
32
+ it "uses the constructor provided by GObject" do
33
+ instance = GObject::ValueArray.new 16
34
+ instance.n_prealloced.must_equal 16
35
+ instance.n_values.must_equal 0
36
+ end
37
+ end
30
38
  end
@@ -148,6 +148,30 @@ describe Regress do
148
148
  end
149
149
 
150
150
  describe "Regress::TestBoxed" do
151
+ let(:instance) { Regress::TestBoxed.new_alternative_constructor1 123 }
152
+
153
+ it "has a writable field some_int8" do
154
+ instance.some_int8.must_equal 123
155
+ instance.some_int8 = -43
156
+ instance.some_int8.must_equal(-43)
157
+ end
158
+
159
+ it "has a writable field nested_a" do
160
+ instance.nested_a.some_int.must_equal 0
161
+ nested = Regress::TestSimpleBoxedA.new
162
+ nested.some_int = 12345
163
+ instance.nested_a = nested
164
+ instance.nested_a.some_int.must_equal 12345
165
+ end
166
+
167
+ it "has a writable field priv" do
168
+ instance.priv.wont_be_nil
169
+ other = Regress::TestBoxed.new
170
+ instance.priv.wont_equal other.priv
171
+ instance.priv = other.priv
172
+ instance.priv.must_equal other.priv
173
+ end
174
+
151
175
  it "creates an instance using #new" do
152
176
  tb = Regress::TestBoxed.new
153
177
  assert_instance_of Regress::TestBoxed, tb
@@ -175,8 +199,6 @@ describe Regress do
175
199
  assert Regress::TestBoxed.get_gtype > 0
176
200
  end
177
201
 
178
- let(:instance) { Regress::TestBoxed.new_alternative_constructor1 123 }
179
-
180
202
  it "has a working method #copy" do
181
203
  tb2 = instance.copy
182
204
  assert_instance_of Regress::TestBoxed, tb2
@@ -192,13 +214,25 @@ describe Regress do
192
214
  end
193
215
 
194
216
  describe "Regress::TestBoxedB" do
217
+ let(:instance) { Regress::TestBoxedB.new 8, 42 }
218
+
219
+ it "has a writable field some_int8" do
220
+ instance.some_int8.must_equal 8
221
+ instance.some_int8 = -43
222
+ instance.some_int8.must_equal(-43)
223
+ end
224
+
225
+ it "has a writable field some_long" do
226
+ instance.some_long.must_equal 42
227
+ instance.some_long = -4342
228
+ instance.some_long.must_equal(-4342)
229
+ end
230
+
195
231
  it "creates an instance using #new" do
196
232
  tb = Regress::TestBoxedB.new 8, 42
197
233
  assert_instance_of Regress::TestBoxedB, tb
198
234
  end
199
235
 
200
- let(:instance) { Regress::TestBoxedB.new 8, 42 }
201
-
202
236
  it "has a working method #copy" do
203
237
  cp = instance.copy
204
238
  cp.must_be_instance_of Regress::TestBoxedB
@@ -213,6 +247,21 @@ describe Regress do
213
247
  before do
214
248
  skip unless get_introspection_data 'Regress', 'TestBoxedC'
215
249
  end
250
+
251
+ let(:instance) { Regress::TestBoxedC.new }
252
+
253
+ it "has a writable field refcount" do
254
+ instance.refcount.must_equal 1
255
+ instance.refcount = 2
256
+ instance.refcount.must_equal 2
257
+ end
258
+
259
+ it "has a writable field another_thing" do
260
+ instance.another_thing.must_equal 42
261
+ instance.another_thing = 4342
262
+ instance.another_thing.must_equal 4342
263
+ end
264
+
216
265
  it "creates an instance using #new" do
217
266
  tb = Regress::TestBoxedC.new
218
267
  assert_instance_of Regress::TestBoxedC, tb
@@ -223,17 +272,29 @@ describe Regress do
223
272
  before do
224
273
  skip unless get_introspection_data 'Regress', 'TestBoxedD'
225
274
  end
275
+
226
276
  it "creates an instance using #new" do
227
- skip
277
+ instance = Regress::TestBoxedD.new "foo", 42
278
+ instance.must_be_instance_of Regress::TestBoxedD
228
279
  end
280
+
229
281
  it "has a working method #copy" do
230
- skip
282
+ instance = Regress::TestBoxedD.new "foo", 42
283
+ copy = instance.copy
284
+ copy.must_be_instance_of Regress::TestBoxedD
285
+ instance.get_magic.must_equal copy.get_magic
286
+ instance.wont_equal copy
231
287
  end
288
+
232
289
  it "has a working method #free" do
233
- skip
290
+ instance = Regress::TestBoxedD.new "foo", 42
291
+ instance.free
292
+ pass
234
293
  end
294
+
235
295
  it "has a working method #get_magic" do
236
- skip
296
+ instance = Regress::TestBoxedD.new "foo", 42
297
+ instance.get_magic.must_equal "foo".length + 42
237
298
  end
238
299
  end
239
300
 
@@ -350,7 +411,7 @@ describe Regress do
350
411
  end
351
412
 
352
413
  describe "an instance" do
353
- setup do
414
+ before do
354
415
  @o = Regress::TestFloating.new
355
416
  end
356
417
 
@@ -391,11 +452,6 @@ describe Regress do
391
452
 
392
453
  let(:instance) { Regress::TestFundamentalSubObject.new "foo" }
393
454
 
394
- it "can be instantiated" do
395
- instance
396
- pass
397
- end
398
-
399
455
  it "is a subclass of TestFundamentalObject" do
400
456
  assert_kind_of Regress::TestFundamentalObject, instance
401
457
  end
@@ -405,9 +461,7 @@ describe Regress do
405
461
  end
406
462
 
407
463
  it "can access its parent class' fields directly" do
408
- assert_nothing_raised do
409
- instance.flags
410
- end
464
+ instance.flags.must_equal 0
411
465
  end
412
466
 
413
467
  # NOTE: The following tests test fields and methods on the abstract parent
@@ -492,241 +546,465 @@ describe Regress do
492
546
  end
493
547
  end
494
548
 
495
- describe "#get_property" do
496
- it "gets the 'bare' property" do
549
+ it "has a reference count of 1" do
550
+ assert_equal 1, ref_count(instance)
551
+ end
552
+
553
+ it "does not float" do
554
+ assert !is_floating?(instance)
555
+ end
556
+
557
+ it "has a working method #matrix" do
558
+ instance.matrix("bar").must_equal 42
559
+ end
560
+
561
+ it "has a working method #do_matrix" do
562
+ instance.do_matrix("bar").must_equal 42
563
+ end
564
+
565
+ it "has a working method #emit_sig_with_foreign_struct" do
566
+ skip unless get_method_introspection_data('Regress', 'TestObj',
567
+ 'emit_sig_with_foreign_struct')
568
+ has_fired = false
569
+ instance.signal_connect "sig-with-foreign-struct" do |obj, cr|
570
+ has_fired = true
571
+ cr.must_be_instance_of Cairo::Context
572
+ end
573
+ instance.emit_sig_with_foreign_struct
574
+ assert has_fired
575
+ end
576
+
577
+ it "has a working method #emit_sig_with_int64" do
578
+ skip "This does not work yet"
579
+ instance.signal_connect "sig-with-int64-prop" do |obj, i, ud|
580
+ int
581
+ end
582
+ instance.emit_sig_with_int64
583
+ end
584
+
585
+ it "has a working method #emit_sig_with_obj" do
586
+ has_fired = false
587
+ instance.signal_connect "sig-with-obj" do |it, obj|
588
+ has_fired = true
589
+ obj.int.must_equal 3
590
+ end
591
+ instance.emit_sig_with_obj
592
+ assert has_fired
593
+ end
594
+
595
+ it "has a working method #emit_sig_with_uint64" do
596
+ skip "This does not work yet"
597
+ instance.signal_connect "sig-with-uint64-prop" do |obj, i, ud|
598
+ i
599
+ end
600
+ instance.emit_sig_with_uint64
601
+ end
602
+
603
+ it "has a working method #forced_method" do
604
+ instance.forced_method
605
+ pass
606
+ end
607
+
608
+ it "has a working method #instance_method" do
609
+ rv = instance.instance_method
610
+ assert_equal(-1, rv)
611
+ end
612
+
613
+ it "has a working method #instance_method_callback" do
614
+ a = 1
615
+ instance.instance_method_callback Proc.new { a = 2 }
616
+ assert_equal 2, a
617
+ end
618
+
619
+ it "has a working method #set_bare" do
620
+ obj = Regress::TestObj.new_from_file("bar")
621
+ instance.set_bare obj
622
+ instance.bare.must_equal obj
623
+ end
624
+
625
+ it "has a working method #skip_inout_param" do
626
+ a = 1
627
+ c = 2.0
628
+ num1 = 3
629
+ num2 = 4
630
+ result, out_b, sum = instance.skip_inout_param a, c, num1, num2
631
+ result.must_equal true
632
+ out_b.must_equal a + 1
633
+ sum.must_equal num1 + 10 * num2
634
+ end
635
+
636
+ it "has a working method #skip_out_param" do
637
+ a = 1
638
+ c = 2.0
639
+ d = 3
640
+ num1 = 4
641
+ num2 = 5
642
+ result, out_d, sum = instance.skip_out_param a, c, d, num1, num2
643
+ result.must_equal true
644
+ out_d.must_equal d + 1
645
+ sum.must_equal num1 + 10 * num2
646
+ end
647
+
648
+ it "has a working method #skip_param" do
649
+ a = 1
650
+ d = 3
651
+ num1 = 4
652
+ num2 = 5
653
+ result, out_b, out_d, sum = instance.skip_param a, d, num1, num2
654
+ result.must_equal true
655
+ out_b.must_equal a + 1
656
+ out_d.must_equal d + 1
657
+ sum.must_equal num1 + 10 * num2
658
+ end
659
+
660
+ it "has a working method #skip_return_val" do
661
+ a = 1
662
+ c = 2.0
663
+ d = 3
664
+ num1 = 4
665
+ num2 = 5
666
+ out_b, out_d, out_sum = instance.skip_return_val a, c, d, num1, num2
667
+ out_b.must_equal a + 1
668
+ out_d.must_equal d + 1
669
+ out_sum.must_equal num1 + 10 * num2
670
+ end
671
+
672
+ it "has a working method #skip_return_val_no_out" do
673
+ result = instance.skip_return_val_no_out 1
674
+ result.must_be_nil
675
+
676
+ lambda { instance.skip_return_val_no_out 0 }.must_raise RuntimeError
677
+ end
678
+
679
+ it "has a working method #torture_signature_0" do
680
+ y, z, q = instance.torture_signature_0(-21, "hello", 13)
681
+ assert_equal [-21, 2 * -21, "hello".length + 13],
682
+ [y, z, q]
683
+ end
684
+
685
+ it "has a working method #torture_signature_1" do
686
+ ret, y, z, q = instance.torture_signature_1(-21, "hello", 12)
687
+ assert_equal [true, -21, 2 * -21, "hello".length + 12],
688
+ [ret, y, z, q]
689
+ assert_raises RuntimeError do
690
+ instance.torture_signature_1(-21, "hello", 11)
691
+ end
692
+ end
693
+
694
+ describe "its 'bare' property" do
695
+ it "can be retrieved with #get_property" do
696
+ instance.get_property("bare").must_be_nil
697
+ end
698
+
699
+ it "can be retrieved with #bare" do
700
+ instance.bare.must_be_nil
701
+ end
702
+
703
+ it "can be set with #set_property" do
497
704
  obj = Regress::TestObj.new_from_file("bar")
498
- instance.set_bare obj
705
+ instance.set_property "bare", obj
706
+ instance.get_property("bare").must_equal obj
707
+ end
499
708
 
500
- obj2 = instance.get_property("bare")
709
+ it "can be set with #bare=" do
710
+ obj = Regress::TestObj.new_from_file("bar")
711
+ instance.bare = obj
712
+
713
+ instance.bare.must_equal obj
714
+ instance.get_property("bare").must_equal obj
715
+ end
716
+ end
501
717
 
502
- assert_instance_of Regress::TestObj, obj2
503
- obj2.must_equal obj
718
+ describe "its 'boxed' property" do
719
+ it "can be retrieved with #get_property" do
720
+ instance.get_property("boxed").must_be_nil
504
721
  end
505
722
 
506
- it "gets the 'boxed' property" do
723
+ it "can be retrieved with #boxed" do
724
+ instance.boxed.must_be_nil
725
+ end
726
+
727
+ it "can be set with #set_property" do
507
728
  tb = Regress::TestBoxed.new_alternative_constructor1 75
508
729
  instance.set_property "boxed", tb
730
+ instance.get_property("boxed").some_int8.must_equal 75
731
+ end
509
732
 
510
- tb2 = instance.get_property("boxed")
733
+ it "can be set with #boxed=" do
734
+ tb = Regress::TestBoxed.new_alternative_constructor1 75
735
+ instance.boxed = tb
736
+ instance.boxed.some_int8.must_equal tb.some_int8
737
+ instance.get_property("boxed").some_int8.must_equal tb.some_int8
738
+ end
739
+ end
511
740
 
512
- assert_instance_of Regress::TestBoxed, tb2
513
- assert_equal 75, tb2.some_int8
741
+ describe "its 'double' property" do
742
+ it "can be retrieved with #get_property" do
743
+ instance.get_property("double").must_equal 0.0
514
744
  end
515
745
 
516
- it "gets the 'hash-table' property" do
517
- ht = GLib::HashTable.new :utf8, :gint8
518
- ht.insert "foo", 34
519
- ht.insert "bar", 83
746
+ it "can be retrieved with #double" do
747
+ instance.double.must_equal 0.0
748
+ end
520
749
 
521
- instance.set_property "hash-table", ht
750
+ it "can be set with #set_property" do
751
+ instance.set_property "double", 3.14
752
+ instance.get_property("double").must_equal 3.14
753
+ end
522
754
 
523
- ht2 = instance.get_property "hash-table"
524
- assert_equal({"foo" => 34, "bar" => 83}, ht2.to_hash)
755
+ it "can be set with #double=" do
756
+ instance.double = 3.14
757
+ instance.double.must_equal 3.14
758
+ instance.get_property("double").must_equal 3.14
525
759
  end
760
+ end
526
761
 
527
- it "gets the 'float' property" do
528
- instance.set_property "float", 3.14
529
- assert_in_epsilon 3.14, instance.get_property("float")
762
+ describe "its 'float' property" do
763
+ it "can be retrieved with #get_property" do
764
+ instance.get_property("float").must_equal 0.0
530
765
  end
531
766
 
532
- it "gets the 'double' property" do
533
- instance.set_property "double", 3.14
534
- assert_in_epsilon 3.14, instance.get_property("double")
767
+ it "can be retrieved with #float" do
768
+ instance.float.must_equal 0.0
535
769
  end
536
770
 
537
- it "gets the 'int' property" do
538
- instance.set_property "int", 42
539
- assert_equal 42, instance.get_property("int")
771
+ it "can be set with #set_property" do
772
+ instance.set_property "float", 3.14
773
+ instance.get_property("float").must_be_close_to 3.14
540
774
  end
541
775
 
542
- it "gets the 'list' property" do
543
- lst = GLib::List.new(:utf8).append("foo").append("bar")
776
+ it "can be set with #float=" do
777
+ instance.float = 3.14
778
+ instance.float.must_be_close_to 3.14
779
+ instance.get_property("float").must_be_close_to 3.14
780
+ end
781
+ end
544
782
 
545
- instance.set_property "list", lst
783
+ describe "its 'gtype' property" do
784
+ before do
785
+ skip unless get_property_introspection_data("Regress", "TestObj", "gtype")
786
+ end
546
787
 
547
- lst2 = instance.get_property "list"
548
- lst2.must_be :==, ["foo", "bar"]
788
+ it "can be retrieved with #get_property" do
789
+ instance.get_property("gtype").must_equal 0
549
790
  end
550
791
 
551
- it "gets the 'string' property" do
552
- instance.set_property "string", "foobar"
553
- assert_equal "foobar", instance.get_property("string")
792
+ it "can be retrieved with #gtype" do
793
+ instance.gtype.must_equal 0
554
794
  end
555
- end
556
795
 
557
- describe "#set_property" do
558
- it "sets the 'bare' property" do
559
- obj = Regress::TestObj.new_from_file("bar")
560
- instance.set_property "bare", obj
561
- instance.bare.must_equal obj
796
+ it "can be set with #set_property" do
797
+ instance.set_property "gtype", GObject::TYPE_INT64
798
+ instance.get_property("gtype").must_equal GObject::TYPE_INT64
562
799
  end
563
800
 
564
- it "sets the 'boxed' property" do
565
- tb = Regress::TestBoxed.new_alternative_constructor1 75
566
- instance.set_property "boxed", tb
567
- tb2 = instance.boxed
568
- assert_equal 75, tb2.some_int8
801
+ it "can be set with #gtype=" do
802
+ instance.gtype = GObject::TYPE_STRING
803
+ instance.gtype.must_equal GObject::TYPE_STRING
804
+ instance.get_property("gtype").must_equal GObject::TYPE_STRING
569
805
  end
806
+ end
570
807
 
571
- it "sets the 'hash-table' property" do
572
- instance.set_property("hash-table", {"foo" => 34, "bar" => 83})
808
+ describe "its 'hash-table' property" do
809
+ it "can be retrieved with #get_property" do
810
+ instance.get_property("hash-table").must_be_nil
811
+ end
573
812
 
574
- ht = instance.hash_table
575
- ht.key_type = :utf8
576
- ht.value_type = :gint32
813
+ it "can be retrieved with #hash_table" do
814
+ instance.hash_table.must_be_nil
815
+ end
577
816
 
578
- assert_equal({"foo" => 34, "bar" => 83}, ht.to_hash)
817
+ it "can be set with #set_property" do
818
+ instance.set_property "hash-table", {"foo" => 34, "bar" => 83}
819
+ instance.get_property("hash-table").to_hash.must_equal({"foo" => 34,
820
+ "bar" => 83})
579
821
  end
580
822
 
581
- it "sets the 'float' property" do
582
- instance.set_property "float", 3.14
583
- assert_in_epsilon 3.14, get_field_value(instance, :some_float)
823
+ it "can be set with #hash_table=" do
824
+ instance.set_property "hash-table", {"foo" => 34, "bar" => 83}
825
+ instance.hash_table.to_hash.must_equal({"foo" => 34, "bar" => 83})
826
+ instance.get_property("hash-table").to_hash.must_equal({"foo" => 34,
827
+ "bar" => 83})
584
828
  end
829
+ end
585
830
 
586
- it "sets the 'double' property" do
587
- instance.set_property "double", 3.14
588
- assert_in_epsilon 3.14, get_field_value(instance, :some_double)
831
+ describe "its 'hash-table-old' property" do
832
+ it "can be retrieved with #get_property" do
833
+ instance.get_property("hash-table-old").must_be_nil
589
834
  end
590
835
 
591
- it "sets the 'int' property" do
592
- instance.set_property "int", 42
593
- assert_equal 42, get_field_value(instance, :some_int8)
836
+ it "can be retrieved with #hash_table_old" do
837
+ instance.hash_table_old.must_be_nil
594
838
  end
595
839
 
596
- it "sets the 'list' property" do
597
- instance.set_property "list", ["foo", "bar"]
598
- instance.list.must_be :==, ["foo", "bar"]
840
+ it "can be set with #set_property" do
841
+ instance.set_property "hash-table-old", {"foo" => 34,
842
+ "bar" => 83}
843
+
844
+ instance.get_property("hash-table-old").to_hash.must_equal({"foo" => 34,
845
+ "bar" => 83})
599
846
  end
600
847
 
601
- it "sets the 'string' property" do
602
- instance.set_property "string", "foobar"
603
- assert_equal "foobar", instance.string
848
+ it "can be set with #hash_table_old=" do
849
+ instance.set_property "hash-table-old", {"foo" => 34,
850
+ "bar" => 83}
851
+
852
+ instance.hash_table_old.to_hash.must_equal({"foo" => 34, "bar" => 83})
853
+ instance.get_property("hash-table-old").to_hash.must_equal({"foo" => 34,
854
+ "bar" => 83})
604
855
  end
605
856
  end
606
857
 
607
858
  describe "its 'int' property" do
608
- it "is set with #int=" do
859
+ it "can be retrieved with #get_property" do
860
+ assert_equal 0, instance.get_property("int")
861
+ end
862
+
863
+ it "can be retrieved with #int" do
864
+ assert_equal 0, instance.int
865
+ end
866
+
867
+ it "can be set with #set_property" do
868
+ instance.set_property "int", 42
869
+ assert_equal 42, instance.get_property("int")
870
+ end
871
+
872
+ it "can be set with #int=" do
609
873
  instance.int = 41
610
874
  assert_equal 41, instance.get_property("int")
875
+ assert_equal 41, instance.int
611
876
  end
877
+ end
612
878
 
613
- it "is retrieved with #int" do
614
- instance.set_property "int", 43
615
- assert_equal 43, instance.int
879
+ describe "its 'list' property" do
880
+ it "can be retrieved with #get_property" do
881
+ instance.get_property("list").must_be_nil
616
882
  end
617
- end
618
883
 
619
- it "has a reference count of 1" do
620
- assert_equal 1, ref_count(instance)
621
- end
884
+ it "can be retrieved with #list" do
885
+ instance.list.must_be_nil
886
+ end
622
887
 
623
- it "does not float" do
624
- assert !is_floating?(instance)
625
- end
888
+ it "can be set with #set_property" do
889
+ instance.set_property "list", ["foo", "bar"]
890
+ instance.get_property("list").must_be :==, ["foo", "bar"]
891
+ end
626
892
 
627
- it "has a working method #matrix" do
628
- instance.matrix("bar").must_equal 42
893
+ it "can be set with #list=" do
894
+ instance.list = ["foo", "bar"]
895
+ instance.list.must_be :==, ["foo", "bar"]
896
+ instance.get_property("list").must_be :==, ["foo", "bar"]
897
+ end
629
898
  end
630
899
 
631
- it "has a working method #do_matrix" do
632
- instance.do_matrix("bar").must_equal 42
633
- end
900
+ describe "its 'list-old' property" do
901
+ it "can be retrieved with #get_property" do
902
+ instance.get_property("list-old").must_be_nil
903
+ end
634
904
 
635
- it "has a working method #emit_sig_with_foreign_struct" do
636
- skip
637
- end
905
+ it "can be retrieved with #list_old" do
906
+ instance.list_old.must_be_nil
907
+ end
638
908
 
639
- it "has a working method #emit_sig_with_int64" do
640
- skip "This does not work yet"
641
- instance.signal_connect "sig-with-int64-prop" do |obj, int, ud|
642
- int
909
+ it "can be set with #set_property" do
910
+ instance.set_property "list-old", ["foo", "bar"]
911
+ instance.get_property("list-old").must_be :==, ["foo", "bar"]
912
+ end
913
+
914
+ it "can be set with #list_old=" do
915
+ instance.list_old = ["foo", "bar"]
916
+ instance.list_old.must_be :==, ["foo", "bar"]
917
+ instance.get_property("list-old").must_be :==, ["foo", "bar"]
643
918
  end
644
- instance.emit_sig_with_int64
645
919
  end
646
920
 
647
- it "has a working method #emit_sig_with_obj" do
648
- skip
921
+ describe "its 'string' property" do
922
+ it "can be retrieved with #get_property" do
923
+ assert_nil instance.get_property("string")
924
+ end
925
+
926
+ it "can be retrieved with #string" do
927
+ assert_nil instance.string
928
+ end
929
+
930
+ it "can be set with #set_property" do
931
+ instance.set_property "string", "foobar"
932
+ assert_equal "foobar", instance.get_property("string")
933
+ end
934
+
935
+ it "can be set with #string=" do
936
+ instance.string = "foobar"
937
+ assert_equal "foobar", instance.string
938
+ assert_equal "foobar", instance.get_property("string")
939
+ end
649
940
  end
650
- it "has a working method #emit_sig_with_uint64" do
651
- skip
941
+
942
+ it "handles the 'all' signal" do
943
+ a = nil
944
+ GObject.signal_connect(instance, "all") { a = 4 }
945
+ GObject.signal_emit instance, "all"
946
+ a.must_equal 4
652
947
  end
653
- it "has a working method #forced_method" do
654
- skip
948
+
949
+ it "handles the 'cleanup' signal" do
950
+ a = nil
951
+ GObject.signal_connect(instance, "cleanup") { a = 4 }
952
+ GObject.signal_emit instance, "cleanup"
953
+ a.must_equal 4
655
954
  end
656
- it "has a working method #instance_method" do
657
- rv = instance.instance_method
658
- assert_equal(-1, rv)
955
+
956
+ it "handles the 'first' signal" do
957
+ a = nil
958
+ GObject.signal_connect(instance, "first") { a = 4 }
959
+ GObject.signal_emit instance, "first"
960
+ a.must_equal 4
659
961
  end
660
962
 
661
- it "has a working method #instance_method_callback" do
662
- a = 1
663
- instance.instance_method_callback Proc.new { a = 2 }
664
- assert_equal 2, a
963
+ it "handles the 'sig-with-array-len-prop' signal" do
964
+ skip
665
965
  end
666
966
 
667
- it "has a working method #set_bare" do
668
- obj = Regress::TestObj.new_from_file("bar")
669
- # XXX: Sometimes uses set_property, and it shouldn't?
670
- instance.set_bare obj
671
- instance.bare.must_equal obj
967
+ it "handles the 'sig-with-array-prop' signal" do
968
+ a = nil
969
+ GObject.signal_connect(instance, "sig-with-array-prop") {|_, arr, _| a = arr }
970
+ # TODO: Automatically convert arguments to signal_emit.
971
+ GObject.signal_emit instance, "sig-with-array-prop",
972
+ GLib::Array.from(:uint, [1, 2, 3])
973
+ a.to_a.must_equal [1, 2, 3]
672
974
  end
673
975
 
674
- it "has a working method #skip_inout_param" do
976
+ it "handles the 'sig-with-foreign-struct' signal" do
675
977
  skip
676
978
  end
677
- it "has a working method #skip_out_param" do
979
+ it "handles the 'sig-with-hash-prop' signal" do
678
980
  skip
679
981
  end
680
- it "has a working method #skip_param" do
982
+ it "handles the 'sig-with-int64-prop' signal" do
681
983
  skip
682
984
  end
683
- it "has a working method #skip_return_val" do
985
+ it "handles the 'sig-with-intarray-ret' signal" do
684
986
  skip
685
987
  end
686
- it "has a working method #skip_return_val_no_out" do
988
+ it "handles the 'sig-with-obj' signal" do
687
989
  skip
688
990
  end
689
- it "has a working method #torture_signature_0" do
690
- y, z, q = instance.torture_signature_0(-21, "hello", 13)
691
- assert_equal [-21, 2 * -21, "hello".length + 13],
692
- [y, z, q]
693
- end
694
-
695
- it "has a working method #torture_signature_1" do
696
- # TODO: Merge with below
991
+ it "handles the 'sig-with-strv' signal" do
697
992
  skip
698
993
  end
699
-
700
- describe "its #torture_signature_1" do
701
- it "works for m even" do
702
- ret, y, z, q = instance.torture_signature_1(-21, "hello", 12)
703
- assert_equal [true, -21, 2 * -21, "hello".length + 12],
704
- [ret, y, z, q]
705
- end
706
-
707
- it "throws an exception for m odd" do
708
- assert_raises RuntimeError do
709
- instance.torture_signature_1(-21, "hello", 11)
710
- end
711
- end
994
+ it "handles the 'sig-with-uint64-prop' signal" do
995
+ skip
712
996
  end
713
997
 
714
- it "does not respond to #static_method" do
715
- assert_raises(NoMethodError) { instance.static_method 1 }
998
+ it "handles the 'test' signal" do
999
+ a = b = nil
1000
+ o = Regress::TestSubObj.new
1001
+ GObject.signal_connect(o, "test", 2) { |i, d| a = d; b = i }
1002
+ GObject.signal_emit o, "test"
1003
+ assert_equal [2, o], [a, b]
716
1004
  end
717
- # TODO: Test instance's fields and properies.
718
-
719
- describe "its 'test' signal" do
720
- it "properly passes its arguments" do
721
- a = b = nil
722
- o = Regress::TestSubObj.new
723
- GObject.signal_connect(o, "test", 2) { |i, d| a = d; b = i }
724
- GObject.signal_emit o, "test"
725
- assert_equal [2, o], [a, b]
726
- end
1005
+ it "handles the 'test-with-static-scope-arg' signal" do
1006
+ skip
727
1007
  end
728
-
729
- # TODO: Test other signals.
730
1008
  end
731
1009
 
732
1010
  describe "Regress::TestOtherError" do
@@ -773,12 +1051,9 @@ describe Regress do
773
1051
  instance.this_is_public_before.must_equal 42
774
1052
  end
775
1053
 
776
- it "cannot read from field this_is_private" do
1054
+ it "has a private field this_is_private" do
777
1055
  skip "GIR identifies this field as readable"
778
1056
  proc { instance.this_is_private }.must_raise NoMethodError
779
- end
780
-
781
- it "cannot write to field this_is_private" do
782
1057
  proc { instance.this_is_private = 42 }.must_raise NoMethodError
783
1058
  end
784
1059
 
@@ -819,80 +1094,89 @@ describe Regress do
819
1094
  assert_instance_of Regress::TestSimpleBoxedA, obj
820
1095
  end
821
1096
 
1097
+ let(:instance) { Regress::TestSimpleBoxedA.new }
1098
+
822
1099
  it "has a working method #copy" do
823
- skip
1100
+ instance.some_int = 4236
1101
+
1102
+ obj2 = instance.copy
1103
+ obj2.must_be_instance_of Regress::TestSimpleBoxedA
1104
+ obj2.some_int.must_equal instance.some_int
1105
+
1106
+ instance.some_int = 89
1107
+ obj2.some_int.wont_equal instance.some_int
824
1108
  end
1109
+
825
1110
  it "has a working method #equals" do
826
- skip
1111
+ instance.some_int = 4236
1112
+
1113
+ ob2 = Regress::TestSimpleBoxedA.new
1114
+ ob2.some_int = 4236
1115
+ ob2.equals(instance).must_equal true
1116
+ ob2.some_enum = :value3
1117
+ ob2.equals(instance).must_equal true
1118
+ ob2.some_int = 42
1119
+ ob2.equals(instance).wont_equal true
827
1120
  end
1121
+
828
1122
  it "has a working function #const_return" do
829
- skip
1123
+ result = Regress::TestSimpleBoxedA.const_return
1124
+ [result.some_int, result.some_int8, result.some_double].must_equal [5, 6, 7.0]
830
1125
  end
1126
+ end
831
1127
 
832
- describe "an instance" do
833
- setup do
834
- @obj = Regress::TestSimpleBoxedA.new
835
- @obj.some_int = 4236
836
- @obj.some_int8 = 36
837
- @obj.some_double = 23.53
838
- @obj.some_enum = :value2
839
- end
840
-
841
- describe "its equals method" do
842
- setup do
843
- @ob2 = Regress::TestSimpleBoxedA.new
844
- @ob2.some_int = 4236
845
- @ob2.some_int8 = 36
846
- @ob2.some_double = 23.53
847
- @ob2.some_enum = :value2
848
- end
849
-
850
- it "returns true if values are the same" do
851
- assert_equal true, @obj.equals(@ob2)
852
- end
853
-
854
- it "returns true if enum values differ" do
855
- @ob2.some_enum = :value3
856
- assert_equal true, @obj.equals(@ob2)
857
- end
858
-
859
- it "returns false if other values differ" do
860
- @ob2.some_int = 1
861
- assert_equal false, @obj.equals(@ob2)
862
- end
863
- end
1128
+ describe "Regress::TestSimpleBoxedB" do
1129
+ let(:instance) { Regress::TestSimpleBoxedB.new }
1130
+ it "has a writable field some_int8" do
1131
+ instance.some_int8.must_equal 0
1132
+ instance.some_int8 = 42
1133
+ instance.some_int8.must_equal 42
1134
+ end
864
1135
 
865
- describe "its copy method" do
866
- setup do
867
- @ob2 = @obj.copy
868
- end
869
-
870
- it "returns an instance of TestSimpleBoxedA" do
871
- assert_instance_of Regress::TestSimpleBoxedA, @ob2
872
- end
873
-
874
- it "copies fields" do
875
- assert_equal 4236, @ob2.some_int
876
- assert_equal 36, @ob2.some_int8
877
- assert_equal 23.53, @ob2.some_double
878
- assert_equal :value2, @ob2.some_enum
879
- end
880
-
881
- it "creates a true copy" do
882
- @obj.some_int8 = 89
883
- assert_equal 36, @ob2.some_int8
884
- end
885
- end
1136
+ it "has a writable field nested_a" do
1137
+ instance.nested_a.some_int.must_equal 0
1138
+ instance.nested_a = Regress::TestSimpleBoxedA.const_return
1139
+ instance.nested_a.some_int.must_equal 5
886
1140
  end
887
- end
888
1141
 
889
- describe "Regress::TestSimpleBoxedB" do
890
1142
  it "has a working method #copy" do
891
- skip
1143
+ instance.some_int8 = -42
1144
+ instance.nested_a.some_int = 4242
1145
+
1146
+ copy = instance.copy
1147
+ [copy.some_int8, copy.nested_a.some_int].must_equal [-42, 4242]
1148
+
1149
+ instance.some_int8 = 103
1150
+ copy.some_int8.must_equal(-42)
892
1151
  end
893
1152
  end
894
1153
 
895
1154
  describe "Regress::TestStructA" do
1155
+ let(:instance) { Regress::TestStructA.new }
1156
+ it "has a writable field some_int" do
1157
+ instance.some_int.must_equal 0
1158
+ instance.some_int = 2556
1159
+ instance.some_int.must_equal 2556
1160
+ end
1161
+
1162
+ it "has a writable field some_int8" do
1163
+ instance.some_int8.must_equal 0
1164
+ instance.some_int8 = -10
1165
+ instance.some_int8.must_equal(-10)
1166
+ end
1167
+
1168
+ it "has a writable field some_double" do
1169
+ instance.some_double.must_equal 0.0
1170
+ instance.some_double = 1.03455e20
1171
+ instance.some_double.must_equal 1.03455e20
1172
+ end
1173
+
1174
+ it "has a writable field some_enum" do
1175
+ instance.some_enum.must_equal :value1
1176
+ instance.some_enum = :value2
1177
+ instance.some_enum.must_equal :value2
1178
+ end
1179
+
896
1180
  it "has a working method #clone" do
897
1181
  a = Regress::TestStructA.new
898
1182
  a.some_int = 2556
@@ -909,11 +1193,30 @@ describe Regress do
909
1193
  end
910
1194
 
911
1195
  it "has a working function #parse" do
912
- skip
1196
+ skip unless get_method_introspection_data 'Regress', 'TestStructA', 'parse'
1197
+ a = Regress::TestStructA.parse("this string is actually ignored")
1198
+ a.some_int.must_equal 23
913
1199
  end
914
1200
  end
915
1201
 
916
1202
  describe "Regress::TestStructB" do
1203
+ let(:instance) { Regress::TestStructB.new }
1204
+ it "has a writable field some_int8" do
1205
+ instance.some_int8.must_equal 0
1206
+ instance.some_int8 = 42
1207
+ instance.some_int8.must_equal 42
1208
+ end
1209
+
1210
+ it "has a writable field nested_a" do
1211
+ instance.nested_a.some_int.must_equal 0
1212
+
1213
+ nested = Regress::TestStructA.new
1214
+ nested.some_int = -4321
1215
+
1216
+ instance.nested_a = nested
1217
+ instance.nested_a.some_int.must_equal(-4321)
1218
+ end
1219
+
917
1220
  it "has a working method #clone" do
918
1221
  a = Regress::TestStructB.new
919
1222
  a.some_int8 = 42
@@ -973,23 +1276,137 @@ describe Regress do
973
1276
  end
974
1277
 
975
1278
  describe "Regress::TestStructE" do
976
- it "must be tested" do
977
- skip
1279
+ let(:instance) { Regress::TestStructE.new }
1280
+ it "has a writable field some_type" do
1281
+ instance.some_type.must_equal 0
1282
+ instance.some_type = GObject::TYPE_STRING
1283
+ instance.some_type.must_equal GObject::TYPE_STRING
1284
+ end
1285
+
1286
+ it "has a writable field some_union" do
1287
+ instance.some_union.map(&:v_int).must_equal [0, 0]
1288
+
1289
+ union1 = Regress::TestStructE__some_union__union.new
1290
+ union1.v_int = 42
1291
+ union2 = Regress::TestStructE__some_union__union.new
1292
+ union2.v_int = 84
1293
+
1294
+ instance.some_union = [union1, union2]
1295
+
1296
+ instance.some_union.map(&:v_int).must_equal [42, 84]
978
1297
  end
979
1298
  end
980
1299
  describe "Regress::TestStructE__some_union__union" do
981
- it "must be tested" do
982
- skip
1300
+ let(:instance) { Regress::TestStructE__some_union__union.new }
1301
+ it "has a writable field v_int" do
1302
+ instance.v_int.must_equal 0
1303
+ instance.v_int = -54321
1304
+ instance.v_int.must_equal(-54321)
1305
+ end
1306
+
1307
+ it "has a writable field v_uint" do
1308
+ instance.v_uint.must_equal 0
1309
+ instance.v_uint = 54321
1310
+ instance.v_uint.must_equal 54321
1311
+ end
1312
+
1313
+ it "has a writable field v_long" do
1314
+ instance.v_long.must_equal 0
1315
+ instance.v_long = -54321
1316
+ instance.v_long.must_equal(-54321)
1317
+ end
1318
+
1319
+ it "has a writable field v_ulong" do
1320
+ instance.v_long.must_equal 0
1321
+ instance.v_long = 54321
1322
+ instance.v_long.must_equal 54321
1323
+ end
1324
+
1325
+ it "has a writable field v_int64" do
1326
+ instance.v_int64.must_equal 0
1327
+ instance.v_int64 = -54_321_000_000_000
1328
+ instance.v_int64.must_equal(-54_321_000_000_000)
1329
+ end
1330
+ it "has a writable field v_uint64" do
1331
+ instance.v_uint64.must_equal 0
1332
+ instance.v_uint64 = 54_321_000_000_000
1333
+ instance.v_uint64.must_equal 54_321_000_000_000
1334
+ end
1335
+ it "has a writable field v_float" do
1336
+ instance.v_float.must_equal 0
1337
+ instance.v_float = 3.1415
1338
+ instance.v_float.must_be_close_to 3.1415
1339
+ end
1340
+ it "has a writable field v_double" do
1341
+ instance.v_double.must_equal 0
1342
+ instance.v_double = 3.1415
1343
+ instance.v_double.must_equal 3.1415
1344
+ end
1345
+ it "has a writable field v_pointer" do
1346
+ instance.v_pointer.must_be :null?
1347
+ instance.v_pointer = FFI::Pointer.new 54321
1348
+ instance.v_pointer.address.must_equal 54321
983
1349
  end
984
1350
  end
985
1351
  describe "Regress::TestStructF" do
986
- it "must be tested" do
987
- skip
1352
+ before do
1353
+ skip unless get_introspection_data 'Regress', 'TestStructF'
1354
+ end
1355
+
1356
+ let(:instance) { Regress::TestStructF.new }
1357
+
1358
+ it "has a writable field ref_count" do
1359
+ instance.ref_count.must_equal 0
1360
+ instance.ref_count = 1
1361
+ instance.ref_count.must_equal 1
1362
+ end
1363
+
1364
+ it "has a writable field data1" do
1365
+ instance.data1.must_be :null?
1366
+ instance.data1 = GirFFI::InOutPointer.from(:gint32, 42)
1367
+ instance.data1.read_int32.must_equal 42
1368
+ end
1369
+
1370
+ it "has a writable field data2" do
1371
+ skip "Introspection data cannot deal with type of this field yet"
1372
+ end
1373
+
1374
+ it "has a writable field data3" do
1375
+ skip "Introspection data cannot deal with type of this field yet"
1376
+ end
1377
+
1378
+ it "has a writable field data4" do
1379
+ skip "Introspection data cannot deal with type of this field yet"
1380
+ end
1381
+
1382
+ it "has a writable field data5" do
1383
+ skip "Introspection data cannot deal with type of this field yet"
1384
+ end
1385
+
1386
+ it "has a writable field data6" do
1387
+ skip "Introspection data cannot deal with type of this field yet"
988
1388
  end
989
1389
  end
1390
+
990
1391
  describe "Regress::TestStructFixedArray" do
1392
+ let(:instance) { Regress::TestStructFixedArray.new }
1393
+ it "has a writable field just_int" do
1394
+ instance.just_int.must_equal 0
1395
+ instance.just_int = 42
1396
+ instance.just_int.must_equal 42
1397
+ end
1398
+
1399
+ it "has a writable field array" do
1400
+ instance.array.must_be :==, [0] * 10
1401
+ instance.array = (1..10).to_a
1402
+ instance.array.must_be :==, (1..10).to_a
1403
+ end
1404
+
991
1405
  it "has a working method #frob" do
992
- skip
1406
+ instance.array = (0..9).to_a
1407
+ instance.frob
1408
+ instance.array.must_be :==, (42..42+9).to_a
1409
+ instance.just_int.must_equal 7
993
1410
  end
994
1411
  end
995
1412
 
@@ -1029,42 +1446,45 @@ describe Regress do
1029
1446
  let(:instance) { Regress::TestWi8021x.new }
1030
1447
 
1031
1448
  it "has a working method #get_testbool" do
1032
- instance.set_testbool false
1033
- assert_equal false, instance.get_testbool
1034
- instance.set_testbool true
1035
- assert_equal true, instance.get_testbool
1449
+ instance.get_testbool.must_equal true
1036
1450
  end
1037
1451
 
1038
1452
  it "has a working method #set_testbool" do
1039
1453
  instance.set_testbool true
1040
- assert_equal true, get_field_value(instance, :testbool)
1454
+ instance.get_testbool.must_equal true
1041
1455
  instance.set_testbool false
1042
- assert_equal false, get_field_value(instance, :testbool)
1456
+ instance.get_testbool.must_equal false
1043
1457
  end
1044
1458
 
1045
- describe "an instance" do
1046
- setup do
1047
- @obj = instance
1459
+ describe "its 'testbool' property" do
1460
+ it "can be retrieved with #get_property" do
1461
+ instance.get_property("testbool").must_equal true
1048
1462
  end
1049
1463
 
1050
- it "gets its boolean field with #get_property" do
1051
- @obj.set_testbool true
1052
- val = @obj.get_property "testbool"
1053
- assert_equal true, val
1464
+ it "can be retrieved with #testbool" do
1465
+ instance.testbool.must_equal true
1054
1466
  end
1055
1467
 
1056
- it "gets its boolean field with #testbool" do
1057
- @obj.set_testbool true
1058
- assert_equal true, @obj.testbool
1059
- @obj.set_testbool false
1060
- assert_equal false, @obj.testbool
1468
+ it "can be set with #set_property" do
1469
+ instance.set_property "testbool", true
1470
+ instance.get_testbool.must_equal true
1471
+ instance.get_property("testbool").must_equal true
1472
+
1473
+ instance.set_property "testbool", false
1474
+ instance.get_testbool.must_equal false
1475
+ instance.get_property("testbool").must_equal false
1061
1476
  end
1062
1477
 
1063
- it "sets its boolean field with #testbool=" do
1064
- @obj.testbool = true
1065
- assert_equal true, @obj.testbool
1066
- @obj.testbool = false
1067
- assert_equal false, @obj.testbool
1478
+ it "can be set with #testbool=" do
1479
+ instance.testbool = true
1480
+ instance.testbool.must_equal true
1481
+ instance.get_testbool.must_equal true
1482
+ instance.get_property("testbool").must_equal true
1483
+
1484
+ instance.testbool = false
1485
+ instance.testbool.must_equal false
1486
+ instance.get_testbool.must_equal false
1487
+ instance.get_property("testbool").must_equal false
1068
1488
  end
1069
1489
  end
1070
1490
  end
@@ -1074,14 +1494,22 @@ describe Regress do
1074
1494
  end
1075
1495
 
1076
1496
  it "has a working function #aliased_caller_alloc" do
1077
- skip
1497
+ result = Regress.aliased_caller_alloc
1498
+ result.must_be_instance_of Regress::TestBoxed
1078
1499
  end
1500
+
1079
1501
  it "has a working function #atest_error_quark" do
1080
- skip
1502
+ skip unless get_introspection_data 'Regress', 'atest_error_quark'
1503
+ result = Regress.atest_error_quark
1504
+ GLib.quark_to_string(result).must_equal "regress-atest-error"
1081
1505
  end
1506
+
1082
1507
  it "has a working function #func_obj_null_in" do
1083
- skip
1508
+ Regress.func_obj_null_in nil
1509
+ Regress.func_obj_null_in Regress::TestObj.constructor
1510
+ pass
1084
1511
  end
1512
+
1085
1513
  it "has a working function #global_get_flags_out" do
1086
1514
  skip
1087
1515
  end
@@ -1095,6 +1523,7 @@ describe Regress do
1095
1523
  it "has a working function #set_abort_on_error" do
1096
1524
  Regress.set_abort_on_error false
1097
1525
  Regress.set_abort_on_error true
1526
+ pass
1098
1527
  end
1099
1528
 
1100
1529
  it "has a working function #test_abc_error_quark" do
@@ -1175,7 +1604,8 @@ describe Regress do
1175
1604
  end
1176
1605
 
1177
1606
  it "has a working function #test_array_int_null_in" do
1178
- assert_nothing_raised { Regress.test_array_int_null_in nil }
1607
+ Regress.test_array_int_null_in nil
1608
+ pass
1179
1609
  end
1180
1610
 
1181
1611
  it "has a working function #test_array_int_null_out" do
@@ -1345,7 +1775,6 @@ describe Regress do
1345
1775
  skip
1346
1776
  end
1347
1777
 
1348
- # TODO: Find a way to test encoding issues.
1349
1778
  it "has a working function #test_filename_return" do
1350
1779
  arr = Regress.test_filename_return
1351
1780
  arr.must_be :==, ["åäö", "/etc/fstab"]
@@ -1383,8 +1812,9 @@ describe Regress do
1383
1812
 
1384
1813
  it "has a working function #test_ghash_everything_return" do
1385
1814
  ghash = Regress.test_ghash_everything_return
1386
- ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
1387
- "qux" => "quux"}
1815
+ ghash.to_hash.must_be :==, {"foo" => "bar",
1816
+ "baz" => "bat",
1817
+ "qux" => "quux"}
1388
1818
  end
1389
1819
 
1390
1820
  it "has a working function #test_ghash_gvalue_in" do
@@ -1401,25 +1831,29 @@ describe Regress do
1401
1831
  end
1402
1832
 
1403
1833
  it "has a working function #test_ghash_nothing_in" do
1404
- Regress.test_ghash_nothing_in({"foo" => "bar", "baz" => "bat",
1405
- "qux" => "quux"})
1834
+ Regress.test_ghash_nothing_in({"foo" => "bar",
1835
+ "baz" => "bat",
1836
+ "qux" => "quux"})
1406
1837
  end
1407
1838
 
1408
1839
  it "has a working function #test_ghash_nothing_in2" do
1409
- Regress.test_ghash_nothing_in2({"foo" => "bar", "baz" => "bat",
1410
- "qux" => "quux"})
1840
+ Regress.test_ghash_nothing_in2({"foo" => "bar",
1841
+ "baz" => "bat",
1842
+ "qux" => "quux"})
1411
1843
  end
1412
1844
 
1413
1845
  it "has a working function #test_ghash_nothing_return" do
1414
1846
  ghash = Regress.test_ghash_nothing_return
1415
- ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
1416
- "qux" => "quux"}
1847
+ ghash.to_hash.must_be :==, {"foo" => "bar",
1848
+ "baz" => "bat",
1849
+ "qux" => "quux"}
1417
1850
  end
1418
1851
 
1419
1852
  it "has a working function #test_ghash_nothing_return2" do
1420
1853
  ghash = Regress.test_ghash_nothing_return2
1421
- ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
1422
- "qux" => "quux"}
1854
+ ghash.to_hash.must_be :==, {"foo" => "bar",
1855
+ "baz" => "bat",
1856
+ "qux" => "quux"}
1423
1857
  end
1424
1858
 
1425
1859
  it "has a working function #test_ghash_null_in" do
@@ -1448,15 +1882,13 @@ describe Regress do
1448
1882
  end
1449
1883
 
1450
1884
  it "has a working function #test_glist_nothing_in" do
1451
- assert_nothing_raised {
1452
- Regress.test_glist_nothing_in ["1", "2", "3"]
1453
- }
1885
+ Regress.test_glist_nothing_in ["1", "2", "3"]
1886
+ pass
1454
1887
  end
1455
1888
 
1456
1889
  it "has a working function #test_glist_nothing_in2" do
1457
- assert_nothing_raised {
1458
- Regress.test_glist_nothing_in2 ["1", "2", "3"]
1459
- }
1890
+ Regress.test_glist_nothing_in2 ["1", "2", "3"]
1891
+ pass
1460
1892
  end
1461
1893
 
1462
1894
  it "has a working function #test_glist_nothing_return" do
@@ -1470,9 +1902,8 @@ describe Regress do
1470
1902
  end
1471
1903
 
1472
1904
  it "has a working function #test_glist_null_in" do
1473
- assert_nothing_raised {
1474
- Regress.test_glist_null_in nil
1475
- }
1905
+ Regress.test_glist_null_in nil
1906
+ pass
1476
1907
  end
1477
1908
 
1478
1909
  it "has a working function #test_glist_null_out" do
@@ -1492,15 +1923,13 @@ describe Regress do
1492
1923
  end
1493
1924
 
1494
1925
  it "has a working function #test_gslist_nothing_in" do
1495
- assert_nothing_raised {
1496
- Regress.test_gslist_nothing_in ["1", "2", "3"]
1497
- }
1926
+ Regress.test_gslist_nothing_in ["1", "2", "3"]
1927
+ pass
1498
1928
  end
1499
1929
 
1500
1930
  it "has a working function #test_gslist_nothing_in2" do
1501
- assert_nothing_raised {
1502
- Regress.test_gslist_nothing_in2 ["1", "2", "3"]
1503
- }
1931
+ Regress.test_gslist_nothing_in2 ["1", "2", "3"]
1932
+ pass
1504
1933
  end
1505
1934
 
1506
1935
  it "has a working function #test_gslist_nothing_return" do
@@ -1514,9 +1943,8 @@ describe Regress do
1514
1943
  end
1515
1944
 
1516
1945
  it "has a working function #test_gslist_null_in" do
1517
- assert_nothing_raised {
1518
- Regress.test_gslist_null_in nil
1519
- }
1946
+ Regress.test_gslist_null_in nil
1947
+ pass
1520
1948
  end
1521
1949
 
1522
1950
  it "has a working function #test_gslist_null_out" do
@@ -1530,22 +1958,32 @@ describe Regress do
1530
1958
  end
1531
1959
 
1532
1960
  it "has a working function #test_gvariant_as" do
1533
- skip
1961
+ Regress.test_gvariant_as.get_strv.to_a.must_equal ["one", "two", "three"]
1534
1962
  end
1963
+
1535
1964
  it "has a working function #test_gvariant_asv" do
1536
- skip
1965
+ result = Regress.test_gvariant_asv
1966
+ result.n_children.must_equal 2
1967
+ result.lookup_value("name", nil).get_string.must_equal "foo"
1968
+ result.lookup_value("timeout", nil).get_int32.must_equal 10
1537
1969
  end
1970
+
1538
1971
  it "has a working function #test_gvariant_i" do
1539
- skip
1972
+ Regress.test_gvariant_i.get_int32.must_equal 1
1540
1973
  end
1974
+
1541
1975
  it "has a working function #test_gvariant_s" do
1542
- skip
1976
+ Regress.test_gvariant_s.get_string.must_equal "one"
1543
1977
  end
1978
+
1544
1979
  it "has a working function #test_gvariant_v" do
1545
- skip
1980
+ Regress.test_gvariant_v.get_variant.get_string.must_equal "contents"
1546
1981
  end
1982
+
1547
1983
  it "has a working function #test_hash_table_callback" do
1548
- skip
1984
+ value = nil
1985
+ Regress.test_hash_table_callback({"foo" => 42}, Proc.new {|hash| value = hash})
1986
+ value.to_hash.must_equal({"foo" => 42})
1549
1987
  end
1550
1988
 
1551
1989
  it "has a working function #test_int" do
@@ -1609,16 +2047,23 @@ describe Regress do
1609
2047
  end
1610
2048
 
1611
2049
  it "has a working function #test_multiline_doc_comments" do
1612
- skip
2050
+ Regress.test_multiline_doc_comments.must_be_nil
1613
2051
  end
2052
+
1614
2053
  it "has a working function #test_nested_parameter" do
1615
- skip
2054
+ Regress.test_nested_parameter(3).must_be_nil
1616
2055
  end
2056
+
1617
2057
  it "has a working function #test_null_gerror_callback" do
1618
- skip
2058
+ value = nil
2059
+ Regress.test_owned_gerror_callback Proc.new {|err| value = err }
2060
+ value.message.must_equal "regression test owned error"
1619
2061
  end
2062
+
1620
2063
  it "has a working function #test_owned_gerror_callback" do
1621
- skip
2064
+ value = nil
2065
+ Regress.test_owned_gerror_callback Proc.new {|err| value = err }
2066
+ value.message.must_equal "regression test owned error"
1622
2067
  end
1623
2068
 
1624
2069
  it "has a working function #test_short" do
@@ -1646,7 +2091,10 @@ describe Regress do
1646
2091
  end
1647
2092
 
1648
2093
  it "has a working function #test_struct_a_parse" do
1649
- skip
2094
+ skip unless get_introspection_data 'Regress', 'test_struct_a_parse'
2095
+ a = Regress.test_struct_a_parse("this string is actually ignored")
2096
+ a.must_be_instance_of Regress::TestStructA
2097
+ a.some_int.must_equal 23
1650
2098
  end
1651
2099
 
1652
2100
  it "has a working function #test_strv_in" do
@@ -1753,9 +2201,8 @@ describe Regress do
1753
2201
  end
1754
2202
 
1755
2203
  it "has a working function #test_utf8_const_in" do
1756
- assert_nothing_raised do
1757
- Regress.test_utf8_const_in("const \xe2\x99\xa5 utf8")
1758
- end
2204
+ Regress.test_utf8_const_in("const \xe2\x99\xa5 utf8")
2205
+ pass
1759
2206
  end
1760
2207
 
1761
2208
  it "has a working function #test_utf8_const_return" do
@@ -1774,9 +2221,8 @@ describe Regress do
1774
2221
  end
1775
2222
 
1776
2223
  it "has a working function #test_utf8_null_in" do
1777
- assert_nothing_raised do
1778
- Regress.test_utf8_null_in nil
1779
- end
2224
+ Regress.test_utf8_null_in nil
2225
+ pass
1780
2226
  end
1781
2227
 
1782
2228
  it "has a working function #test_utf8_null_out" do