gir_ffi 0.2.3 → 0.3.0

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.
Files changed (87) hide show
  1. data/History.txt +14 -0
  2. data/README.rdoc +3 -1
  3. data/examples/02_hello_world.rb +1 -0
  4. data/examples/03_upgraded_hello_world.rb +2 -1
  5. data/examples/05_notification.rb +2 -2
  6. data/examples/hard_coded.rb +31 -8
  7. data/lib/ffi-glib/array.rb +1 -1
  8. data/lib/ffi-glib/container_class_methods.rb +25 -0
  9. data/lib/ffi-glib/hash_table.rb +41 -38
  10. data/lib/ffi-glib/list.rb +15 -22
  11. data/lib/ffi-glib/list_methods.rb +16 -16
  12. data/lib/ffi-glib/ptr_array.rb +20 -15
  13. data/lib/ffi-glib/s_list.rb +15 -23
  14. data/lib/ffi-glib.rb +7 -0
  15. data/lib/ffi-gobject/base.rb +0 -13
  16. data/lib/ffi-gobject/object.rb +6 -0
  17. data/lib/ffi-gobject/ruby_style.rb +21 -0
  18. data/lib/ffi-gobject.rb +44 -0
  19. data/lib/ffi-gobject_introspection/i_object_info.rb +7 -0
  20. data/lib/ffi-gobject_introspection/lib.rb +1 -0
  21. data/lib/gir_ffi/arg_helper.rb +8 -6
  22. data/lib/gir_ffi/builder/argument.rb +1 -1
  23. data/lib/gir_ffi/builder/field.rb +6 -3
  24. data/lib/gir_ffi/builder/property.rb +28 -0
  25. data/lib/gir_ffi/builder/type/base.rb +6 -4
  26. data/lib/gir_ffi/builder/type/interface.rb +1 -0
  27. data/lib/gir_ffi/builder/type/object.rb +26 -1
  28. data/lib/gir_ffi/builder/type/registered_type.rb +9 -1
  29. data/lib/gir_ffi/builder/type/unintrospectable.rb +26 -8
  30. data/lib/gir_ffi/builder/type/user_defined.rb +119 -0
  31. data/lib/gir_ffi/builder/type/with_layout.rb +3 -3
  32. data/lib/gir_ffi/builder.rb +5 -0
  33. data/lib/gir_ffi/class_base.rb +6 -6
  34. data/lib/gir_ffi/info_ext/i_property_info.rb +12 -0
  35. data/lib/gir_ffi/info_ext/i_type_info.rb +4 -0
  36. data/lib/gir_ffi/user_defined/i_base_info.rb +7 -0
  37. data/lib/gir_ffi/user_defined/i_object_info.rb +13 -0
  38. data/lib/gir_ffi/user_defined/i_property_info.rb +9 -0
  39. data/lib/gir_ffi/user_defined/i_registered_type_info.rb +10 -0
  40. data/lib/gir_ffi/version.rb +1 -1
  41. data/lib/gir_ffi.rb +6 -0
  42. data/tasks/test.rake +12 -2
  43. data/test/builder_test.rb +0 -124
  44. data/test/ffi-glib/hash_table_test.rb +0 -14
  45. data/test/ffi-glib/list_test.rb +0 -13
  46. data/test/ffi-glib/ptr_array_test.rb +26 -8
  47. data/test/ffi-glib/s_list_test.rb +4 -4
  48. data/test/ffi-gobject/g_object_overrides_test.rb +16 -32
  49. data/test/ffi-gobject/gobject_test.rb +28 -1
  50. data/test/ffi-gobject/object_class_test.rb +21 -0
  51. data/test/ffi-gobject/object_test.rb +4 -0
  52. data/test/ffi-gobject/ruby_style_test.rb +38 -0
  53. data/test/ffi-gobject_introspection/i_constant_info_test.rb +5 -5
  54. data/test/ffi-gobject_introspection/i_repository_test.rb +4 -4
  55. data/test/ffi-gtk/gtk_test.rb +36 -0
  56. data/test/gir_ffi_test_helper.rb +8 -4
  57. data/test/integration/derived_classes_test.rb +34 -18
  58. data/test/integration/generated_gimarshallingtests_test.rb +20 -23
  59. data/test/integration/generated_gio_test.rb +5 -0
  60. data/test/integration/generated_gobject_test.rb +2 -2
  61. data/test/integration/generated_gtk_test.rb +1 -1
  62. data/test/integration/generated_pango_test.rb +20 -0
  63. data/test/integration/generated_regress_test.rb +1003 -955
  64. data/test/integration/pretty_print_test.rb +3 -1
  65. data/test/test_helper.rb +5 -0
  66. data/test/type_builder_test.rb +2 -19
  67. data/test/unit/arg_helper_test.rb +87 -1
  68. data/test/unit/builder_test.rb +113 -1
  69. data/test/unit/function_builder_test.rb +6 -5
  70. data/test/unit/gir_ffi_test.rb +69 -0
  71. data/test/unit/in_out_pointer_test.rb +3 -3
  72. data/test/unit/in_pointer_test.rb +1 -1
  73. data/test/unit/interface_builder_test.rb +16 -0
  74. data/test/unit/object_type_builder_test.rb +15 -0
  75. data/test/unit/struct_builder_test.rb +5 -1
  76. data/test/{unintrospectable_type_builder_test.rb → unit/unintrospectable_type_builder_test.rb} +18 -1
  77. data/test/unit/user_defined_object_info_test.rb +18 -0
  78. data/test/unit/user_defined_property_info_test.rb +14 -0
  79. data/test/unit/user_defined_registered_type_info_test.rb +10 -0
  80. data/test/unit/user_defined_type_builder_test.rb +41 -0
  81. metadata +34 -17
  82. data/tasks/notes.rake +0 -121
  83. data/tasks/rdoc.rake +0 -9
  84. data/tasks/yardoc.rake +0 -9
  85. data/test/arg_helper_test.rb +0 -33
  86. data/test/gtk_overrides_test.rb +0 -35
  87. data/test/interface_type_builder_test.rb +0 -17
@@ -1,1245 +1,1293 @@
1
1
  # coding: utf-8
2
2
  require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
3
3
 
4
+ GirFFI.setup :Regress
5
+
6
+ def get_field_value obj, field
7
+ struct = obj.instance_variable_get :@struct
8
+ struct[field]
9
+ end
10
+
4
11
  # Tests generated methods and functions in the Regress namespace.
5
- class GeneratedRegressTest < MiniTest::Spec
6
- context "The generated Regress module" do
7
- setup do
8
- GirFFI.setup :Regress
12
+ describe Regress, "The generated Regress module" do
13
+ it "has the constant DOUBLE_CONSTANT" do
14
+ assert_equal 44.22, Regress::DOUBLE_CONSTANT
15
+ end
16
+
17
+ it "has the constant INT_CONSTANT" do
18
+ assert_equal 4422, Regress::INT_CONSTANT
19
+ end
20
+
21
+ it "has the constant Mixed_Case_Constant" do
22
+ assert_equal 4423, Regress::Mixed_Case_Constant
23
+ end
24
+
25
+ it "has the constant STRING_CONSTANT" do
26
+ assert_equal "Some String", Regress::STRING_CONSTANT
27
+ end
28
+
29
+ describe Regress::TestBoxed do
30
+ it "creates an instance using #new" do
31
+ tb = Regress::TestBoxed.new
32
+ assert_instance_of Regress::TestBoxed, tb
9
33
  end
10
34
 
11
- it "has the constant DOUBLE_CONSTANT" do
12
- assert_equal 44.22, Regress::DOUBLE_CONSTANT
35
+ it "creates an instance using #new_alternative_constructor1" do
36
+ tb = Regress::TestBoxed.new_alternative_constructor1 1
37
+ assert_instance_of Regress::TestBoxed, tb
38
+ assert_equal 1, tb.some_int8
13
39
  end
14
40
 
15
- it "has the constant INT_CONSTANT" do
16
- assert_equal 4422, Regress::INT_CONSTANT
41
+ it "creates an instance using #new_alternative_constructor2" do
42
+ tb = Regress::TestBoxed.new_alternative_constructor2 1, 2
43
+ assert_instance_of Regress::TestBoxed, tb
44
+ assert_equal 1 + 2, tb.some_int8
17
45
  end
18
46
 
19
- it "has the constant Mixed_Case_Constant" do
20
- assert_equal 4423, Regress::Mixed_Case_Constant
47
+ it "creates an instance using #new_alternative_constructor3" do
48
+ tb = Regress::TestBoxed.new_alternative_constructor3 "54"
49
+ assert_instance_of Regress::TestBoxed, tb
50
+ assert_equal 54, tb.some_int8
21
51
  end
22
52
 
23
- it "has the constant STRING_CONSTANT" do
24
- assert_equal "Some String", Regress::STRING_CONSTANT
53
+ it "has non-zero positive result for #get_gtype" do
54
+ assert Regress::TestBoxed.get_gtype > 0
25
55
  end
26
56
 
27
- context "the Regress::TestBoxed class" do
28
- should "create an instance using #new" do
29
- tb = Regress::TestBoxed.new
30
- assert_instance_of Regress::TestBoxed, tb
57
+ describe "an instance" do
58
+ setup do
59
+ @tb = Regress::TestBoxed.new_alternative_constructor1 123
31
60
  end
32
61
 
33
- should "create an instance using #new_alternative_constructor1" do
34
- tb = Regress::TestBoxed.new_alternative_constructor1 1
35
- assert_instance_of Regress::TestBoxed, tb
36
- assert_equal 1, tb.some_int8
62
+ it "has a working equals method" do
63
+ tb2 = Regress::TestBoxed.new_alternative_constructor2 120, 3
64
+ assert_equal true, @tb.equals(tb2)
37
65
  end
38
66
 
39
- should "create an instance using #new_alternative_constructor2" do
40
- tb = Regress::TestBoxed.new_alternative_constructor2 1, 2
41
- assert_instance_of Regress::TestBoxed, tb
42
- assert_equal 1 + 2, tb.some_int8
67
+ describe "its copy method" do
68
+ setup do
69
+ @tb2 = @tb.copy
70
+ end
71
+
72
+ it "returns an instance of TestBoxed" do
73
+ assert_instance_of Regress::TestBoxed, @tb2
74
+ end
75
+
76
+ it "copies fields" do
77
+ assert_equal 123, @tb2.some_int8
78
+ end
79
+
80
+ it "creates a true copy" do
81
+ @tb.some_int8 = 89
82
+ assert_equal 123, @tb2.some_int8
83
+ end
43
84
  end
85
+ end
86
+ end
87
+
88
+ describe "the Regress::TestEnum type" do
89
+ it "is of type FFI::Enum" do
90
+ assert_instance_of FFI::Enum, Regress::TestEnum
91
+ end
92
+ end
44
93
 
45
- should "create an instance using #new_alternative_constructor3" do
46
- tb = Regress::TestBoxed.new_alternative_constructor3 "54"
47
- assert_instance_of Regress::TestBoxed, tb
48
- assert_equal 54, tb.some_int8
94
+ it "has the bitfield TestFlags" do
95
+ assert_equal 1, Regress::TestFlags[:flag1]
96
+ assert_equal 2, Regress::TestFlags[:flag2]
97
+ assert_equal 4, Regress::TestFlags[:flag3]
98
+ end
99
+
100
+ describe Regress::TestFloating do
101
+ describe "an instance" do
102
+ setup do
103
+ @o = Regress::TestFloating.new
49
104
  end
50
105
 
51
- should "have non-zero positive result for #get_gtype" do
52
- assert Regress::TestBoxed.get_gtype > 0
106
+ it "has a reference count of 1" do
107
+ assert_equal 1, ref_count(@o)
53
108
  end
54
109
 
55
- context "an instance" do
56
- setup do
57
- @tb = Regress::TestBoxed.new_alternative_constructor1 123
58
- end
59
-
60
- should "have a working equals method" do
61
- tb2 = Regress::TestBoxed.new_alternative_constructor2 120, 3
62
- assert_equal true, @tb.equals(tb2)
63
- end
64
-
65
- context "its copy method" do
66
- setup do
67
- @tb2 = @tb.copy
68
- end
69
-
70
- should "return an instance of TestBoxed" do
71
- assert_instance_of Regress::TestBoxed, @tb2
72
- end
73
-
74
- should "copy fields" do
75
- assert_equal 123, @tb2.some_int8
76
- end
77
-
78
- should "create a true copy" do
79
- @tb.some_int8 = 89
80
- assert_equal 123, @tb2.some_int8
81
- end
82
- end
110
+ it "has been sunk" do
111
+ assert !is_floating?(@o)
83
112
  end
84
113
  end
114
+ end
85
115
 
86
- context "the Regress::TestEnum type" do
87
- should "be of type FFI::Enum" do
88
- assert_instance_of FFI::Enum, Regress::TestEnum
89
- end
116
+ describe "TestFundamentalObject" do
117
+ it "must exist" do
118
+ Regress::TestFundamentalObject
90
119
  end
91
120
 
92
- it "has the bitfield TestFlags" do
93
- assert_equal 1, Regress::TestFlags[:flag1]
94
- assert_equal 2, Regress::TestFlags[:flag2]
95
- assert_equal 4, Regress::TestFlags[:flag3]
121
+ it "does not have GObject::Object as an ancestor" do
122
+ refute_includes Regress::TestFundamentalObject.ancestors,
123
+ GObject::Object
96
124
  end
125
+ # TODO: Test more, if possible (e.g., cannot be instantiated).
126
+ end
97
127
 
98
- context "the Regress::TestFloating class" do
99
- context "an instance" do
100
- setup do
101
- @o = Regress::TestFloating.new
102
- end
128
+ describe "TestFundamentalSubObject" do
129
+ before do
130
+ @so = Regress::TestFundamentalSubObject.new "foo"
131
+ end
103
132
 
104
- should "have a reference count of 1" do
105
- assert_equal 1, ref_count(@o)
106
- end
133
+ it "can be instantiated" do
134
+ pass
135
+ end
107
136
 
108
- should "have been sunk" do
109
- assert !is_floating?(@o)
110
- end
111
- end
137
+ it "is a subclass of TestFundamentalObject" do
138
+ assert_kind_of Regress::TestFundamentalObject, @so
112
139
  end
113
140
 
114
- describe "TestFundamentalObject" do
115
- it "must exist" do
116
- Regress::TestFundamentalObject
117
- end
141
+ it "has a field :data storing the constructor parameter" do
142
+ assert_equal "foo", @so.data
143
+ end
118
144
 
119
- it "does not have GObject::Object as an ancestor" do
120
- refute_includes Regress::TestFundamentalObject.ancestors,
121
- GObject::Object
145
+ it "can access its parent class' fields directly" do
146
+ assert_nothing_raised do
147
+ @so.flags
122
148
  end
123
- # TODO: Test more, if possible (e.g., cannot be instantiated).
124
149
  end
125
150
 
126
- describe "TestFundamentalSubObject" do
127
- before do
128
- @so = Regress::TestFundamentalSubObject.new "foo"
129
- end
151
+ it "has a refcount of 1" do
152
+ # FIXME: Should be able to do @so.refcount
153
+ assert_equal 1, @so.fundamental_object.refcount
154
+ end
155
+ end
130
156
 
131
- it "can be instantiated" do
132
- pass
133
- end
157
+ describe "TestInterface" do
158
+ it "is a module" do
159
+ assert_instance_of Module, Regress::TestInterface
160
+ end
134
161
 
135
- it "is a subclass of TestFundamentalObject" do
136
- assert_kind_of Regress::TestFundamentalObject, @so
137
- end
162
+ it "extends InterfaceBase" do
163
+ metaclass = class << Regress::TestInterface; self; end
164
+ assert_includes metaclass.ancestors, GirFFI::InterfaceBase
165
+ end
138
166
 
139
- it "stores the constructor parameter in the :data field" do
140
- assert_equal "foo", @so.data
141
- end
167
+ it "has non-zero positive result for #get_gtype" do
168
+ Regress::TestInterface.get_gtype.must_be :>, 0
169
+ end
170
+ end
142
171
 
143
- it "has a refcount of 1" do
144
- assert_equal 1, @so.fundamental_object.refcount
145
- end
172
+ describe Regress::TestObj do
173
+ it "creates an instance using #new_from_file" do
174
+ o = Regress::TestObj.new_from_file("foo")
175
+ assert_instance_of Regress::TestObj, o
146
176
  end
147
177
 
148
- describe "TestInterface" do
149
- it "is a module" do
150
- assert_instance_of Module, Regress::TestInterface
151
- end
178
+ it "creates an instance using #new_callback" do
179
+ a = 1
180
+ o = Regress::TestObj.new_callback Proc.new { a = 2 }, nil, nil
181
+ assert_instance_of Regress::TestObj, o
182
+ a.must_equal 2
183
+ end
152
184
 
153
- it "extends InterfaceBase" do
154
- metaclass = class << Regress::TestInterface; self; end
155
- assert_includes metaclass.ancestors, GirFFI::InterfaceBase
156
- end
185
+ it "has a working #static_method" do
186
+ rv = Regress::TestObj.static_method 623
187
+ assert_equal 623.0, rv
157
188
  end
158
189
 
159
- context "the Regress::TestObj class" do
160
- should "create an instance using #new_from_file" do
161
- o = Regress::TestObj.new_from_file("foo")
162
- assert_instance_of Regress::TestObj, o
190
+ describe "#static_method_callback" do
191
+ it "works when called with a Proc" do
192
+ a = 1
193
+ Regress::TestObj.static_method_callback Proc.new { a = 2 }
194
+ assert_equal 2, a
163
195
  end
164
196
 
165
- # TODO: Test that callback is called
166
- should "create an instance using #new_callback" do
167
- o = Regress::TestObj.new_callback Proc.new { }, nil, nil
168
- assert_instance_of Regress::TestObj, o
197
+ it "works when called with nil" do
198
+ assert_nothing_raised do
199
+ Regress::TestObj.static_method_callback nil
200
+ end
169
201
  end
202
+ end
170
203
 
171
- should "have a working #static_method" do
172
- rv = Regress::TestObj.static_method 623
173
- assert_equal 623.0, rv
204
+ describe "an instance" do
205
+ setup do
206
+ @o = Regress::TestObj.new_from_file("foo")
174
207
  end
175
208
 
176
- context "#static_method_callback" do
177
- should "work when called with a Proc" do
178
- a = 1
179
- Regress::TestObj.static_method_callback Proc.new { a = 2 }
180
- assert_equal 2, a
209
+ describe "its gtype" do
210
+ it "can be found through get_gtype and GObject.type_from_instance" do
211
+ gtype = Regress::TestObj.get_gtype
212
+ r = GObject.type_from_instance @o
213
+ assert_equal gtype, r
181
214
  end
215
+ end
182
216
 
183
- should "work when called with nil" do
184
- assert_nothing_raised do
185
- Regress::TestObj.static_method_callback nil
186
- end
217
+ describe "#get_property" do
218
+ it "gets the 'bare' property" do
219
+ obj = Regress::TestObj.new_from_file("bar")
220
+ @o.set_bare obj
221
+
222
+ obj2 = @o.get_property("bare")
223
+
224
+ assert_equal obj.to_ptr, obj2.to_ptr
225
+ assert_instance_of Regress::TestObj, obj2
187
226
  end
188
- end
189
227
 
190
- context "an instance" do
191
- setup do
192
- @o = Regress::TestObj.new_from_file("foo")
193
- end
228
+ it "gets the 'boxed' property" do
229
+ tb = Regress::TestBoxed.new_alternative_constructor1 75
230
+ @o.set_property "boxed", tb
194
231
 
195
- describe "its gtype" do
196
- it "can be found through get_gtype and GObject.type_from_instance" do
197
- gtype = Regress::TestObj.get_gtype
198
- r = GObject.type_from_instance @o
199
- assert_equal gtype, r
200
- end
232
+ tb2 = @o.get_property("boxed")
233
+
234
+ assert_instance_of Regress::TestBoxed, tb2
235
+ assert_equal 75, tb2.some_int8
201
236
  end
202
237
 
203
- describe "#get_property" do
204
- it "gets the 'bare' property" do
205
- obj = Regress::TestObj.new_from_file("bar")
206
- @o.set_bare obj
238
+ it "gets the 'hash-table' property" do
239
+ ht = GLib::HashTable.new :utf8, :gint8
240
+ ht.insert "foo", 34
241
+ ht.insert "bar", 83
207
242
 
208
- obj2 = @o.get_property("bare")
243
+ @o.set_property "hash-table", ht
209
244
 
210
- assert_equal obj.to_ptr, obj2.to_ptr
211
- assert_instance_of Regress::TestObj, obj2
212
- end
245
+ ht2 = @o.get_property "hash-table"
246
+ assert_equal({"foo" => 34, "bar" => 83}, ht2.to_hash)
247
+ end
213
248
 
214
- it "gets the 'boxed' property" do
215
- tb = Regress::TestBoxed.new_alternative_constructor1 75
216
- @o.set_property "boxed", tb
249
+ it "gets the 'float' property" do
250
+ @o.set_property "float", 3.14
251
+ assert_in_epsilon 3.14, @o.get_property("float")
252
+ end
217
253
 
218
- tb2 = @o.get_property("boxed")
254
+ it "gets the 'double' property" do
255
+ @o.set_property "double", 3.14
256
+ assert_in_epsilon 3.14, @o.get_property("double")
257
+ end
219
258
 
220
- assert_instance_of Regress::TestBoxed, tb2
221
- assert_equal 75, tb2.some_int8
222
- end
259
+ it "gets the 'int' property" do
260
+ @o.set_property "int", 42
261
+ assert_equal 42, @o.get_property("int")
262
+ end
223
263
 
224
- it "gets the 'hash-table' property" do
225
- ht = GLib::HashTable.new :utf8, :gint8
226
- ht.insert "foo", 34
227
- ht.insert "bar", 83
264
+ it "gets the 'list' property" do
265
+ lst = GLib::List.new(:utf8).append("foo").append("bar")
228
266
 
229
- @o.set_property "hash-table", ht
267
+ @o.set_property "list", lst
230
268
 
231
- ht2 = @o.get_property "hash-table"
232
- assert_equal({"foo" => 34, "bar" => 83}, ht2.to_hash)
233
- end
269
+ lst2 = @o.get_property "list"
270
+ assert_equal ["foo", "bar"], lst2.to_a
271
+ end
234
272
 
235
- it "gets the 'float' property" do
236
- @o.set_property "float", 3.14
237
- assert_in_epsilon 3.14, @o.get_property("float")
238
- end
273
+ it "gets the 'string' property" do
274
+ @o.set_property "string", "foobar"
275
+ assert_equal "foobar", @o.get_property("string")
276
+ end
277
+ end
239
278
 
240
- it "gets the 'double' property" do
241
- @o.set_property "double", 3.14
242
- assert_in_epsilon 3.14, @o.get_property("double")
243
- end
279
+ describe "#set_property" do
280
+ it "sets the 'bare' property" do
281
+ obj = Regress::TestObj.new_from_file("bar")
282
+ @o.set_property "bare", obj
283
+ assert_equal obj.to_ptr, @o.bare.to_ptr
284
+ end
244
285
 
245
- it "gets the 'int' property" do
246
- @o.set_property "int", 42
247
- assert_equal 42, @o.get_property("int")
248
- end
286
+ it "sets the 'boxed' property" do
287
+ tb = Regress::TestBoxed.new_alternative_constructor1 75
288
+ @o.set_property "boxed", tb
289
+ tb2 = @o.boxed
290
+ assert_equal 75, tb2.some_int8
291
+ end
249
292
 
250
- it "gets the 'list' property" do
251
- lst = GLib::List.new(:utf8).append("foo").append("bar")
293
+ it "sets the 'hash-table' property" do
294
+ @o.set_property("hash-table", {"foo" => 34, "bar" => 83})
252
295
 
253
- @o.set_property "list", lst
296
+ ht = @o.hash_table
297
+ ht.key_type = :utf8
298
+ ht.value_type = :gint32
254
299
 
255
- lst2 = @o.get_property "list"
256
- assert_equal ["foo", "bar"], lst2.to_a
257
- end
300
+ assert_equal({"foo" => 34, "bar" => 83}, ht.to_hash)
301
+ end
258
302
 
259
- it "gets the 'string' property" do
260
- @o.set_property "string", "foobar"
261
- assert_equal "foobar", @o.get_property("string")
262
- end
303
+ it "sets the 'float' property" do
304
+ @o.set_property "float", 3.14
305
+ assert_in_epsilon 3.14, get_field_value(@o, :some_float)
263
306
  end
264
307
 
265
- describe "#set_property" do
266
- it "sets the 'bare' property" do
267
- obj = Regress::TestObj.new_from_file("bar")
268
- @o.set_property "bare", obj
269
- assert_equal obj.to_ptr, @o.bare.to_ptr
270
- end
308
+ it "sets the 'double' property" do
309
+ @o.set_property "double", 3.14
310
+ assert_in_epsilon 3.14, get_field_value(@o, :some_double)
311
+ end
271
312
 
272
- it "sets the 'boxed' property" do
273
- tb = Regress::TestBoxed.new_alternative_constructor1 75
274
- @o.set_property "boxed", tb
275
- tb2 = @o.boxed
276
- assert_equal 75, tb2.some_int8
277
- end
313
+ it "sets the 'int' property" do
314
+ @o.set_property "int", 42
315
+ assert_equal 42, get_field_value(@o, :some_int8)
316
+ end
278
317
 
279
- it "sets the 'hash-table' property" do
280
- @o.set_property("hash-table", {"foo" => 34, "bar" => 83})
318
+ it "sets the 'list' property" do
319
+ @o.set_property "list", ["foo", "bar"]
320
+ assert_equal ["foo", "bar"],
321
+ GLib::List.wrap(:utf8, @o.list.to_ptr).to_a
322
+ end
281
323
 
282
- ht = @o.hash_table
283
- ht.key_type = :utf8
284
- ht.value_type = :gint32
324
+ it "sets the 'string' property" do
325
+ @o.set_property "string", "foobar"
326
+ assert_equal "foobar", @o.string
327
+ end
328
+ end
285
329
 
286
- assert_equal({"foo" => 34, "bar" => 83}, ht.to_hash)
287
- end
330
+ describe "its 'int' property" do
331
+ it "is set with #int=" do
332
+ @o.int = 41
333
+ assert_equal 41, @o.get_property("int")
334
+ end
288
335
 
289
- it "sets the 'float' property" do
290
- @o.set_property "float", 3.14
291
- assert_in_epsilon 3.14, @o.some_float
292
- end
336
+ it "is retrieved with #int" do
337
+ @o.set_property "int", 43
338
+ assert_equal 43, @o.int
339
+ end
340
+ end
293
341
 
294
- it "sets the 'double' property" do
295
- @o.set_property "double", 3.14
296
- assert_in_epsilon 3.14, @o.some_double
297
- end
342
+ it "has a reference count of 1" do
343
+ assert_equal 1, ref_count(@o)
344
+ end
298
345
 
299
- it "sets the 'int' property" do
300
- @o.set_property "int", 42
301
- assert_equal 42, @o.some_int8
302
- end
346
+ it "does not float" do
347
+ assert !is_floating?(@o)
348
+ end
303
349
 
304
- it "sets the 'list' property" do
305
- @o.set_property "list", ["foo", "bar"]
306
- assert_equal ["foo", "bar"],
307
- GLib::List.wrap(:utf8, @o.list.to_ptr).to_a
308
- end
350
+ it "has a working (virtual) #matrix method" do
351
+ rv = @o.matrix "bar"
352
+ assert_equal 42, rv
353
+ end
309
354
 
310
- it "sets the 'string' property" do
311
- @o.set_property "string", "foobar"
312
- assert_equal "foobar", @o.string
313
- end
314
- end
355
+ it "has a working #set_bare method" do
356
+ obj = Regress::TestObj.new_from_file("bar")
357
+ @o.set_bare obj
358
+ # TODO: What is the correct value to retrieve from the fields?
359
+ assert_equal obj.to_ptr, @o.bare.to_ptr
360
+ end
315
361
 
316
- should "have a reference count of 1" do
317
- assert_equal 1, ref_count(@o)
318
- end
319
-
320
- should "not float" do
321
- assert !is_floating?(@o)
322
- end
323
-
324
- should "have a working (virtual) #matrix method" do
325
- rv = @o.matrix "bar"
326
- assert_equal 42, rv
327
- end
328
-
329
- should "have a working #set_bare method" do
330
- obj = Regress::TestObj.new_from_file("bar")
331
- @o.set_bare obj
332
- # TODO: What is the correct value to retrieve from the fields?
333
- assert_equal obj.to_ptr, @o.bare.to_ptr
334
- end
335
-
336
- should "have a working #instance_method method" do
337
- rv = @o.instance_method
338
- assert_equal(-1, rv)
339
- end
340
-
341
- should "have a working #torture_signature_0 method" do
342
- y, z, q = @o.torture_signature_0(-21, "hello", 13)
343
- assert_equal [-21, 2 * -21, "hello".length + 13],
344
- [y, z, q]
345
- end
346
-
347
- context "its #torture_signature_1 method" do
348
- should "work for m even" do
349
- ret, y, z, q = @o.torture_signature_1(-21, "hello", 12)
350
- assert_equal [true, -21, 2 * -21, "hello".length + 12],
351
- [ret, y, z, q]
352
- end
353
-
354
- should "throw an exception for m odd" do
355
- assert_raises RuntimeError do
356
- @o.torture_signature_1(-21, "hello", 11)
357
- end
358
- end
359
- end
360
-
361
- should "have a working #instance_method_callback method" do
362
- a = 1
363
- @o.instance_method_callback Proc.new { a = 2 }
364
- assert_equal 2, a
365
- end
366
-
367
- should "not respond to #static_method" do
368
- assert_raises(NoMethodError) { @o.static_method 1 }
369
- end
370
- # TODO: Test instance's fields and properies.
362
+ it "has a working #instance_method method" do
363
+ rv = @o.instance_method
364
+ assert_equal(-1, rv)
371
365
  end
372
366
 
373
- describe "its 'test' signal" do
374
- it "properly passes its arguments" do
375
- a = b = nil
376
- o = Regress::TestSubObj.new
377
- GObject.signal_connect(o, "test", 2) { |i, d| a = d; b = i }
378
- GObject.signal_emit o, "test"
379
- # TODO: store o's identity somewhere so we can make o == b.
380
- assert_equal [2, o.to_ptr], [a, b.to_ptr]
381
- end
367
+ it "has a working #torture_signature_0 method" do
368
+ y, z, q = @o.torture_signature_0(-21, "hello", 13)
369
+ assert_equal [-21, 2 * -21, "hello".length + 13],
370
+ [y, z, q]
382
371
  end
383
372
 
384
- # TODO: Test other signals.
385
- end
373
+ describe "its #torture_signature_1 method" do
374
+ it "works for m even" do
375
+ ret, y, z, q = @o.torture_signature_1(-21, "hello", 12)
376
+ assert_equal [true, -21, 2 * -21, "hello".length + 12],
377
+ [ret, y, z, q]
378
+ end
386
379
 
387
- context "the Regress::TestSimpleBoxedA class" do
388
- should "create an instance using #new" do
389
- obj = Regress::TestSimpleBoxedA.new
390
- assert_instance_of Regress::TestSimpleBoxedA, obj
380
+ it "throws an exception for m odd" do
381
+ assert_raises RuntimeError do
382
+ @o.torture_signature_1(-21, "hello", 11)
383
+ end
384
+ end
391
385
  end
392
386
 
393
- context "an instance" do
394
- setup do
395
- @obj = Regress::TestSimpleBoxedA.new
396
- @obj.some_int = 4236
397
- @obj.some_int8 = 36
398
- @obj.some_double = 23.53
399
- @obj.some_enum = :value2
400
- end
401
-
402
- context "its equals method" do
403
- setup do
404
- @ob2 = Regress::TestSimpleBoxedA.new
405
- @ob2.some_int = 4236
406
- @ob2.some_int8 = 36
407
- @ob2.some_double = 23.53
408
- @ob2.some_enum = :value2
409
- end
410
-
411
- should "return true if values are the same" do
412
- assert_equal true, @obj.equals(@ob2)
413
- end
414
-
415
- should "return true if enum values differ" do
416
- @ob2.some_enum = :value3
417
- assert_equal true, @obj.equals(@ob2)
418
- end
419
-
420
- should "return false if other values differ" do
421
- @ob2.some_int = 1
422
- assert_equal false, @obj.equals(@ob2)
423
- end
424
- end
425
-
426
- context "its copy method" do
427
- setup do
428
- @ob2 = @obj.copy
429
- end
430
-
431
- should "return an instance of TestSimpleBoxedA" do
432
- assert_instance_of Regress::TestSimpleBoxedA, @ob2
433
- end
434
-
435
- should "copy fields" do
436
- assert_equal 4236, @ob2.some_int
437
- assert_equal 36, @ob2.some_int8
438
- assert_equal 23.53, @ob2.some_double
439
- assert_equal :value2, @ob2.some_enum
440
- end
441
-
442
- should "create a true copy" do
443
- @obj.some_int8 = 89
444
- assert_equal 36, @ob2.some_int8
445
- end
446
- end
387
+ it "has a working #instance_method_callback method" do
388
+ a = 1
389
+ @o.instance_method_callback Proc.new { a = 2 }
390
+ assert_equal 2, a
447
391
  end
448
- end
449
392
 
450
- context "the Regress::TestStructA class" do
451
- context "an instance" do
452
- should "have a working clone method" do
453
- a = Regress::TestStructA.new
454
- a.some_int = 2556
455
- a.some_int8 = -10
456
- a.some_double = 1.03455e20
457
- a.some_enum = :value2
458
-
459
- b = a.clone
460
-
461
- assert_equal 2556, b.some_int
462
- assert_equal(-10, b.some_int8)
463
- assert_equal 1.03455e20, b.some_double
464
- assert_equal :value2, b.some_enum
465
- end
393
+ it "does not respond to #static_method" do
394
+ assert_raises(NoMethodError) { @o.static_method 1 }
466
395
  end
396
+ # TODO: Test instance's fields and properies.
467
397
  end
468
398
 
469
- describe "TestStructB" do
470
- describe "an instance" do
471
- it "has a working method #clone" do
472
- a = Regress::TestStructB.new
473
- a.some_int8 = 42
474
- a.nested_a.some_int = 2556
475
- a.nested_a.some_int8 = -10
476
- a.nested_a.some_double = 1.03455e20
477
- a.nested_a.some_enum = :value2
478
-
479
- b = a.clone
480
-
481
- assert_equal 42, b.some_int8
482
- assert_equal 2556, b.nested_a.some_int
483
- assert_equal(-10, b.nested_a.some_int8)
484
- assert_equal 1.03455e20, b.nested_a.some_double
485
- assert_equal :value2, b.nested_a.some_enum
486
- end
399
+ describe "its 'test' signal" do
400
+ it "properly passes its arguments" do
401
+ a = b = nil
402
+ o = Regress::TestSubObj.new
403
+ GObject.signal_connect(o, "test", 2) { |i, d| a = d; b = i }
404
+ GObject.signal_emit o, "test"
405
+ # TODO: store o's identity somewhere so we can make o == b.
406
+ assert_equal [2, o.to_ptr], [a, b.to_ptr]
487
407
  end
488
408
  end
489
409
 
490
- describe "TestStructC" do
491
- it "needs to be tested"
410
+ # TODO: Test other signals.
411
+ end
412
+
413
+ describe Regress::TestSimpleBoxedA do
414
+ it "creates an instance using #new" do
415
+ obj = Regress::TestSimpleBoxedA.new
416
+ assert_instance_of Regress::TestSimpleBoxedA, obj
492
417
  end
493
418
 
494
- describe "TestSubObj" do
495
- it "is created with #new" do
496
- tso = Regress::TestSubObj.new
497
- assert_instance_of Regress::TestSubObj, tso
419
+ describe "an instance" do
420
+ setup do
421
+ @obj = Regress::TestSimpleBoxedA.new
422
+ @obj.some_int = 4236
423
+ @obj.some_int8 = 36
424
+ @obj.some_double = 23.53
425
+ @obj.some_enum = :value2
498
426
  end
499
427
 
500
- describe "an instance" do
501
- before do
502
- @tso = Regress::TestSubObj.new
428
+ describe "its equals method" do
429
+ setup do
430
+ @ob2 = Regress::TestSimpleBoxedA.new
431
+ @ob2.some_int = 4236
432
+ @ob2.some_int8 = 36
433
+ @ob2.some_double = 23.53
434
+ @ob2.some_enum = :value2
503
435
  end
504
436
 
505
- it "has a working method #instance_method" do
506
- res = @tso.instance_method
507
- assert_equal 0, res
437
+ it "returns true if values are the same" do
438
+ assert_equal true, @obj.equals(@ob2)
508
439
  end
509
440
 
510
- it "has a working method #unset_bare" do
511
- @tso.unset_bare
512
- pass
441
+ it "returns true if enum values differ" do
442
+ @ob2.some_enum = :value3
443
+ assert_equal true, @obj.equals(@ob2)
513
444
  end
514
445
 
515
- it "has a field parent_instance" do
516
- assert_instance_of Regress::TestObj, @tso.parent_instance
446
+ it "returns false if other values differ" do
447
+ @ob2.some_int = 1
448
+ assert_equal false, @obj.equals(@ob2)
517
449
  end
518
450
  end
519
- end
520
451
 
521
- context "the Regress::TestWi8021x class" do
522
- should "create an instance using #new" do
523
- o = Regress::TestWi8021x.new
524
- assert_instance_of Regress::TestWi8021x, o
525
- end
452
+ describe "its copy method" do
453
+ setup do
454
+ @ob2 = @obj.copy
455
+ end
456
+
457
+ it "returns an instance of TestSimpleBoxedA" do
458
+ assert_instance_of Regress::TestSimpleBoxedA, @ob2
459
+ end
460
+
461
+ it "copies fields" do
462
+ assert_equal 4236, @ob2.some_int
463
+ assert_equal 36, @ob2.some_int8
464
+ assert_equal 23.53, @ob2.some_double
465
+ assert_equal :value2, @ob2.some_enum
466
+ end
526
467
 
527
- should "have a working #static_method" do
528
- assert_equal(-84, Regress::TestWi8021x.static_method(-42))
468
+ it "creates a true copy" do
469
+ @obj.some_int8 = 89
470
+ assert_equal 36, @ob2.some_int8
471
+ end
529
472
  end
473
+ end
474
+ end
530
475
 
531
- context "an instance" do
532
- setup do
533
- @obj = Regress::TestWi8021x.new
534
- end
535
-
536
- it "sets its boolean field with #set_testbool" do
537
- @obj.set_testbool true
538
- assert_equal 1, @obj.testbool
539
- @obj.set_testbool false
540
- assert_equal 0, @obj.testbool
541
- end
542
-
543
- it "gets its boolean field with #get_testbool" do
544
- @obj.set_testbool false
545
- assert_equal false, @obj.get_testbool
546
- @obj.set_testbool true
547
- assert_equal true, @obj.get_testbool
548
- end
549
-
550
- it "gets its boolean field with #get_property" do
551
- @obj.set_testbool true
552
- val = @obj.get_property "testbool"
553
- assert_equal true, val
554
- end
476
+ describe Regress::TestStructA do
477
+ describe "an instance" do
478
+ it "has a working clone method" do
479
+ a = Regress::TestStructA.new
480
+ a.some_int = 2556
481
+ a.some_int8 = -10
482
+ a.some_double = 1.03455e20
483
+ a.some_enum = :value2
484
+
485
+ b = a.clone
486
+
487
+ assert_equal 2556, b.some_int
488
+ assert_equal(-10, b.some_int8)
489
+ assert_equal 1.03455e20, b.some_double
490
+ assert_equal :value2, b.some_enum
555
491
  end
556
492
  end
493
+ end
557
494
 
558
- it "has the constant UTF8_CONSTANT" do
559
- assert_equal "const ♥ utf8", Regress::UTF8_CONSTANT
495
+ describe Regress::TestStructB do
496
+ describe "an instance" do
497
+ it "has a working method #clone" do
498
+ a = Regress::TestStructB.new
499
+ a.some_int8 = 42
500
+ a.nested_a.some_int = 2556
501
+ a.nested_a.some_int8 = -10
502
+ a.nested_a.some_double = 1.03455e20
503
+ a.nested_a.some_enum = :value2
504
+
505
+ b = a.clone
506
+
507
+ assert_equal 42, b.some_int8
508
+ assert_equal 2556, b.nested_a.some_int
509
+ assert_equal(-10, b.nested_a.some_int8)
510
+ assert_equal 1.03455e20, b.nested_a.some_double
511
+ assert_equal :value2, b.nested_a.some_enum
512
+ end
560
513
  end
514
+ end
561
515
 
562
- it "has the function #set_abort_on_error" do
563
- Regress.set_abort_on_error false
564
- Regress.set_abort_on_error true
516
+ # TODO: Test the following classes.
517
+ # Regress::TestStructC
518
+ # Regress::TestStructD
519
+ # Regress::TestStructE
520
+ # Regress::TestStructFixedArray
521
+
522
+ describe Regress::TestSubObj do
523
+ it "is created with #new" do
524
+ tso = Regress::TestSubObj.new
525
+ assert_instance_of Regress::TestSubObj, tso
565
526
  end
566
527
 
567
- describe "#test_array_fixed_out_objects" do
528
+ describe "an instance" do
568
529
  before do
569
- @result = Regress.test_array_fixed_out_objects
530
+ @tso = Regress::TestSubObj.new
570
531
  end
571
532
 
572
- it "returns an array of two items" do
573
- assert_equal 2, @result.length
533
+ it "has a working method #instance_method" do
534
+ res = @tso.instance_method
535
+ assert_equal 0, res
574
536
  end
575
537
 
576
- it "returns an array TestObj objects" do
577
- @result.each {|o|
578
- assert_instance_of Regress::TestObj, o
579
- }
538
+ it "has a working method #unset_bare" do
539
+ @tso.unset_bare
540
+ pass
580
541
  end
581
542
 
582
- it "returns objects with the correct GType" do
583
- gtype = Regress::TestObj.get_gtype
584
- @result.each {|o|
585
- assert_equal gtype, GObject.type_from_instance(o)
586
- }
543
+ it "does not have a field parent_instance" do
544
+ assert_raises(NoMethodError) { @tso.parent_instance }
587
545
  end
588
546
  end
547
+ end
589
548
 
590
- describe "#test_array_fixed_size_int_in" do
591
- should "return the correct result" do
592
- assert_equal 5 + 4 + 3 + 2 + 1, Regress.test_array_fixed_size_int_in([5, 4, 3, 2, 1])
549
+ describe Regress::TestWi8021x do
550
+ it "creates an instance using #new" do
551
+ o = Regress::TestWi8021x.new
552
+ assert_instance_of Regress::TestWi8021x, o
553
+ end
554
+
555
+ it "has a working #static_method" do
556
+ assert_equal(-84, Regress::TestWi8021x.static_method(-42))
557
+ end
558
+
559
+ describe "an instance" do
560
+ setup do
561
+ @obj = Regress::TestWi8021x.new
593
562
  end
594
563
 
595
- should "raise an error when called with the wrong number of arguments" do
596
- assert_raises ArgumentError do
597
- Regress.test_array_fixed_size_int_in [2]
598
- end
564
+ it "sets its boolean field with #set_testbool" do
565
+ @obj.set_testbool true
566
+ assert_equal 1, get_field_value(@obj, :testbool)
567
+ @obj.set_testbool false
568
+ assert_equal 0, get_field_value(@obj, :testbool)
599
569
  end
600
- end
601
570
 
602
- should "have correct test_array_fixed_size_int_out" do
603
- assert_equal [0, 1, 2, 3, 4], Regress.test_array_fixed_size_int_out
604
- end
571
+ it "gets its boolean field with #get_testbool" do
572
+ @obj.set_testbool false
573
+ assert_equal false, @obj.get_testbool
574
+ @obj.set_testbool true
575
+ assert_equal true, @obj.get_testbool
576
+ end
605
577
 
606
- should "have correct test_array_fixed_size_int_return" do
607
- assert_equal [0, 1, 2, 3, 4], Regress.test_array_fixed_size_int_return
608
- end
578
+ it "gets its boolean field with #get_property" do
579
+ @obj.set_testbool true
580
+ val = @obj.get_property "testbool"
581
+ assert_equal true, val
582
+ end
609
583
 
610
- should "have correct test_array_gint16_in" do
611
- assert_equal 5 + 4 + 3, Regress.test_array_gint16_in([5, 4, 3])
612
- end
584
+ it "gets its boolean field with #testbool" do
585
+ @obj.set_testbool true
586
+ assert_equal true, @obj.testbool
587
+ @obj.set_testbool false
588
+ assert_equal false, @obj.testbool
589
+ end
613
590
 
614
- should "have correct test_array_gint32_in" do
615
- assert_equal 5 + 4 + 3, Regress.test_array_gint32_in([5, 4, 3])
591
+ it "sets its boolean field with #testbool=" do
592
+ @obj.testbool = true
593
+ assert_equal true, @obj.testbool
594
+ @obj.testbool = false
595
+ assert_equal false, @obj.testbool
596
+ end
616
597
  end
598
+ end
617
599
 
618
- should "have correct test_array_gint64_in" do
619
- assert_equal 5 + 4 + 3, Regress.test_array_gint64_in([5, 4, 3])
620
- end
600
+ it "has the constant UTF8_CONSTANT" do
601
+ assert_equal "const utf8", Regress::UTF8_CONSTANT
602
+ end
621
603
 
622
- should "have correct test_array_gint8_in" do
623
- assert_equal 5 + 4 + 3, Regress.test_array_gint8_in([5, 4, 3])
624
- end
604
+ it "has the function #set_abort_on_error" do
605
+ Regress.set_abort_on_error false
606
+ Regress.set_abort_on_error true
607
+ end
625
608
 
626
- should "have correct test_array_gtype_in" do
627
- t1 = GObject.type_from_name "gboolean"
628
- t2 = GObject.type_from_name "gint64"
629
- assert_equal "[gboolean,gint64,]", Regress.test_array_gtype_in([t1, t2])
609
+ describe "#test_array_fixed_out_objects" do
610
+ before do
611
+ begin
612
+ @result = Regress.test_array_fixed_out_objects
613
+ rescue NoMethodError
614
+ skip
615
+ end
630
616
  end
631
617
 
632
- should "have correct test_array_int_full_out" do
633
- assert_equal [0, 1, 2, 3, 4], Regress.test_array_int_full_out
618
+ it "returns an array of two items" do
619
+ assert_equal 2, @result.length
634
620
  end
635
621
 
636
- should "have correct test_array_int_in" do
637
- assert_equal 5 + 4 + 3, Regress.test_array_int_in([5, 4, 3])
622
+ it "returns an array TestObj objects" do
623
+ @result.each {|o|
624
+ assert_instance_of Regress::TestObj, o
625
+ }
638
626
  end
639
627
 
640
- should "have correct test_array_int_inout" do
641
- assert_equal [3, 4], Regress.test_array_int_inout([5, 2, 3])
628
+ it "returns objects with the correct GType" do
629
+ gtype = Regress::TestObj.get_gtype
630
+ @result.each {|o|
631
+ assert_equal gtype, GObject.type_from_instance(o)
632
+ }
642
633
  end
634
+ end
643
635
 
644
- should "have correct test_array_int_none_out" do
645
- assert_equal [1, 2, 3, 4, 5], Regress.test_array_int_none_out
636
+ describe "#test_array_fixed_size_int_in" do
637
+ it "returns the correct result" do
638
+ assert_equal 5 + 4 + 3 + 2 + 1, Regress.test_array_fixed_size_int_in([5, 4, 3, 2, 1])
646
639
  end
647
640
 
648
- should "have correct test_array_int_null_in" do
649
- assert_nothing_raised { Regress.test_array_int_null_in nil }
641
+ it "raises an error when called with the wrong number of arguments" do
642
+ assert_raises ArgumentError do
643
+ Regress.test_array_fixed_size_int_in [2]
644
+ end
650
645
  end
646
+ end
651
647
 
652
- should "have correct test_array_int_null_out" do
653
- assert_equal nil, Regress.test_array_int_null_out
654
- end
648
+ it "has correct test_array_fixed_size_int_out" do
649
+ assert_equal [0, 1, 2, 3, 4], Regress.test_array_fixed_size_int_out
650
+ end
655
651
 
656
- should "have correct test_array_int_out" do
657
- assert_equal [0, 1, 2, 3, 4], Regress.test_array_int_out
658
- end
652
+ it "has correct test_array_fixed_size_int_return" do
653
+ assert_equal [0, 1, 2, 3, 4], Regress.test_array_fixed_size_int_return
654
+ end
659
655
 
660
- should "have correct test_async_ready_callback" do
661
- a = 1
662
- main_loop = GLib::MainLoop.new nil, false
656
+ it "has correct test_array_gint16_in" do
657
+ assert_equal 5 + 4 + 3, Regress.test_array_gint16_in([5, 4, 3])
658
+ end
663
659
 
664
- Regress.test_async_ready_callback Proc.new {
665
- main_loop.quit
666
- a = 2
667
- }
660
+ it "has correct test_array_gint32_in" do
661
+ assert_equal 5 + 4 + 3, Regress.test_array_gint32_in([5, 4, 3])
662
+ end
668
663
 
669
- main_loop.run
664
+ it "has correct test_array_gint64_in" do
665
+ assert_equal 5 + 4 + 3, Regress.test_array_gint64_in([5, 4, 3])
666
+ end
670
667
 
671
- assert_equal 2, a
672
- end
668
+ it "has correct test_array_gint8_in" do
669
+ assert_equal 5 + 4 + 3, Regress.test_array_gint8_in([5, 4, 3])
670
+ end
673
671
 
674
- should "have correct test_boolean" do
675
- assert_equal false, Regress.test_boolean(false)
676
- assert_equal true, Regress.test_boolean(true)
677
- end
672
+ it "has correct test_array_gtype_in" do
673
+ t1 = GObject.type_from_name "gboolean"
674
+ t2 = GObject.type_from_name "gint64"
675
+ assert_equal "[gboolean,gint64,]", Regress.test_array_gtype_in([t1, t2])
676
+ end
678
677
 
679
- should "have correct test_boolean_false" do
680
- assert_equal false, Regress.test_boolean_false(false)
681
- end
678
+ it "has correct test_array_int_full_out" do
679
+ assert_equal [0, 1, 2, 3, 4], Regress.test_array_int_full_out
680
+ end
682
681
 
683
- should "have correct test_boolean_true" do
684
- assert_equal true, Regress.test_boolean_true(true)
685
- end
682
+ it "has correct test_array_int_in" do
683
+ assert_equal 5 + 4 + 3, Regress.test_array_int_in([5, 4, 3])
684
+ end
686
685
 
687
- it "has correct #test_cairo_context_full_return" do
688
- ct = Regress.test_cairo_context_full_return
689
- assert_instance_of Cairo::Context, ct
690
- end
686
+ it "has correct test_array_int_inout" do
687
+ assert_equal [3, 4], Regress.test_array_int_inout([5, 2, 3])
688
+ end
691
689
 
692
- it "has correct #test_cairo_context_none_in" do
693
- ct = Regress.test_cairo_context_full_return
694
- Regress.test_cairo_context_none_in ct
695
- end
690
+ it "has correct test_array_int_none_out" do
691
+ assert_equal [1, 2, 3, 4, 5], Regress.test_array_int_none_out
692
+ end
696
693
 
697
- it "has correct #test_cairo_surface_full_out" do
698
- cs = Regress.test_cairo_surface_full_out
699
- assert_instance_of Cairo::Surface, cs
700
- end
694
+ it "has correct test_array_int_null_in" do
695
+ assert_nothing_raised { Regress.test_array_int_null_in nil }
696
+ end
701
697
 
702
- it "has correct #test_cairo_surface_full_return" do
703
- cs = Regress.test_cairo_surface_full_return
704
- assert_instance_of Cairo::Surface, cs
705
- end
698
+ it "has correct test_array_int_null_out" do
699
+ assert_equal nil, Regress.test_array_int_null_out
700
+ end
706
701
 
707
- it "has correct #test_cairo_surface_none_in" do
708
- cs = Regress.test_cairo_surface_full_return
709
- Regress.test_cairo_surface_none_in cs
710
- end
702
+ it "has correct test_array_int_out" do
703
+ assert_equal [0, 1, 2, 3, 4], Regress.test_array_int_out
704
+ end
711
705
 
712
- it "has correct #test_cairo_surface_none_return" do
713
- cs = Regress.test_cairo_surface_none_return
714
- assert_instance_of Cairo::Surface, cs
715
- end
706
+ it "has correct test_async_ready_callback" do
707
+ # FIXME: Use GLib::MainLoop.new eventually.
708
+ main_loop = GLib.main_loop_new nil, false
716
709
 
717
- should "have correct test_callback" do
718
- result = Regress.test_callback Proc.new { 5 }
719
- assert_equal 5, result
720
- end
710
+ a = 1
711
+ Regress.test_async_ready_callback Proc.new {
712
+ main_loop.quit
713
+ a = 2
714
+ }
721
715
 
722
- should "have correct test_callback_async" do
723
- a = 1
724
- Regress.test_callback_async Proc.new {|b|
725
- a = 2
726
- b
727
- }, 44
728
- r = Regress.test_callback_thaw_async
729
- assert_equal 44, r
730
- assert_equal 2, a
731
- end
716
+ main_loop.run
732
717
 
733
- should "have correct test_callback_destroy_notify" do
734
- a = 1
735
- r1 = Regress.test_callback_destroy_notify Proc.new {|b|
736
- a = 2
737
- b
738
- }, 42, Proc.new { a = 3 }
739
- assert_equal 2, a
740
- assert_equal 42, r1
741
- r2 = Regress.test_callback_thaw_notifications
742
- assert_equal 3, a
743
- assert_equal 42, r2
744
- end
718
+ assert_equal 2, a
719
+ end
745
720
 
746
- describe "the #test_callback_user_data function" do
747
- should "return the callbacks return value" do
748
- result = Regress.test_callback_user_data Proc.new {|u| 5 }, nil
749
- assert_equal 5, result
750
- end
721
+ it "has correct test_boolean" do
722
+ assert_equal false, Regress.test_boolean(false)
723
+ assert_equal true, Regress.test_boolean(true)
724
+ end
751
725
 
752
- should "handle boolean user_data" do
753
- a = false
754
- Regress.test_callback_user_data Proc.new {|u|
755
- a = u
756
- 5
757
- }, true
758
- assert_equal true, a
759
- end
760
- end
726
+ it "has correct test_boolean_false" do
727
+ assert_equal false, Regress.test_boolean_false(false)
728
+ end
761
729
 
762
- should "have correct test_closure" do
763
- c = GObject::RubyClosure.new { 5235 }
764
- r = Regress.test_closure c
765
- assert_equal 5235, r
766
- end
730
+ it "has correct test_boolean_true" do
731
+ assert_equal true, Regress.test_boolean_true(true)
732
+ end
767
733
 
768
- should "have correct test_closure_one_arg" do
769
- c = GObject::RubyClosure.new { |a| a * 2 }
770
- r = Regress.test_closure_one_arg c, 2
771
- assert_equal 4, r
772
- end
734
+ it "has correct #test_cairo_context_full_return" do
735
+ ct = Regress.test_cairo_context_full_return
736
+ assert_instance_of Cairo::Context, ct
737
+ end
773
738
 
774
- it "has a correct #test_date_in_gvalue function" do
775
- r = Regress.test_date_in_gvalue
776
- date = r.ruby_value
777
- assert_equal [1984, :december, 5],
778
- [date.get_year, date.get_month, date.get_day]
779
- end
739
+ it "has correct #test_cairo_context_none_in" do
740
+ ct = Regress.test_cairo_context_full_return
741
+ Regress.test_cairo_context_none_in ct
742
+ end
780
743
 
781
- should "have correct test_double" do
782
- r = Regress.test_double 5435.32
783
- assert_equal 5435.32, r
784
- end
744
+ it "has correct #test_cairo_surface_full_out" do
745
+ cs = Regress.test_cairo_surface_full_out
746
+ assert_instance_of Cairo::Surface, cs
747
+ end
785
748
 
786
- should "have correct test_enum_param" do
787
- r = Regress.test_enum_param :value3
788
- assert_equal "value3", r
789
- end
749
+ it "has correct #test_cairo_surface_full_return" do
750
+ cs = Regress.test_cairo_surface_full_return
751
+ assert_instance_of Cairo::Surface, cs
752
+ end
753
+
754
+ it "has correct #test_cairo_surface_none_in" do
755
+ cs = Regress.test_cairo_surface_full_return
756
+ Regress.test_cairo_surface_none_in cs
757
+ end
758
+
759
+ it "has correct #test_cairo_surface_none_return" do
760
+ cs = Regress.test_cairo_surface_none_return
761
+ assert_instance_of Cairo::Surface, cs
762
+ end
763
+
764
+ it "has correct test_callback" do
765
+ result = Regress.test_callback Proc.new { 5 }
766
+ assert_equal 5, result
767
+ end
768
+
769
+ it "has correct test_callback_async" do
770
+ a = 1
771
+ Regress.test_callback_async Proc.new {|b|
772
+ a = 2
773
+ b
774
+ }, 44
775
+ r = Regress.test_callback_thaw_async
776
+ assert_equal 44, r
777
+ assert_equal 2, a
778
+ end
790
779
 
791
- # TODO: Find a way to test encoding issues.
792
- it "has correct #test_filename_return" do
793
- arr = Regress.test_filename_return
794
- assert_equal ["åäö", "/etc/fstab"], arr.to_a
780
+ it "has correct test_callback_destroy_notify" do
781
+ a = 1
782
+ r1 = Regress.test_callback_destroy_notify Proc.new {|b|
783
+ a = 2
784
+ b
785
+ }, 42, Proc.new { a = 3 }
786
+ assert_equal 2, a
787
+ assert_equal 42, r1
788
+ r2 = Regress.test_callback_thaw_notifications
789
+ assert_equal 3, a
790
+ assert_equal 42, r2
791
+ end
792
+
793
+ describe "the #test_callback_user_data function" do
794
+ it "returns the callbacks return value" do
795
+ result = Regress.test_callback_user_data Proc.new {|u| 5 }, nil
796
+ assert_equal 5, result
795
797
  end
796
798
 
797
- should "have correct test_float" do
798
- r = Regress.test_float 5435.32
799
- assert_in_delta 5435.32, r, 0.001
799
+ it "handles boolean user_data" do
800
+ a = false
801
+ Regress.test_callback_user_data Proc.new {|u|
802
+ a = u
803
+ 5
804
+ }, true
805
+ assert_equal true, a
800
806
  end
807
+ end
801
808
 
802
- describe "#test_garray_container_return" do
803
- before do
804
- @arr = Regress.test_garray_container_return
805
- end
809
+ it "has correct test_closure" do
810
+ c = GObject::RubyClosure.new { 5235 }
811
+ r = Regress.test_closure c
812
+ assert_equal 5235, r
813
+ end
806
814
 
807
- it "returns an instance of GLib::PtrArray" do
808
- @arr.must_be_instance_of GLib::PtrArray
809
- end
815
+ it "has correct test_closure_one_arg" do
816
+ c = GObject::RubyClosure.new { |a| a * 2 }
817
+ r = Regress.test_closure_one_arg c, 2
818
+ assert_equal 4, r
819
+ end
810
820
 
811
- it "returns the correct values" do
812
- @arr.len.must_be :==, 1
813
- ptr = @arr.pdata
814
- ptr2 = ptr.read_pointer
815
- ptr2.read_string.must_be :==, "regress"
816
- end
817
- end
821
+ it "has a correct #test_date_in_gvalue function" do
822
+ r = Regress.test_date_in_gvalue
823
+ date = r.ruby_value
824
+ skip unless date.respond_to? :get_year
825
+ assert_equal [1984, :december, 5],
826
+ [date.get_year, date.get_month, date.get_day]
827
+ end
818
828
 
819
- describe "#test_ghash_container_return" do
820
- before do
821
- @hash = Regress.test_ghash_container_return
822
- end
823
-
824
- it "returns an instance of GLib::HashTable" do
825
- @hash.must_be_instance_of GLib::HashTable
826
- end
829
+ it "has correct test_double" do
830
+ r = Regress.test_double 5435.32
831
+ assert_equal 5435.32, r
832
+ end
827
833
 
828
- it "returns the correct values" do
829
- @hash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
830
- "qux" => "quux"}
831
- end
832
- end
834
+ it "has correct test_enum_param" do
835
+ r = Regress.test_enum_param :value3
836
+ assert_equal "value3", r
837
+ end
833
838
 
834
- it "has correct #test_ghash_everything_return" do
835
- ghash = Regress.test_ghash_everything_return
836
- ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
837
- "qux" => "quux"}
838
- end
839
+ # TODO: Find a way to test encoding issues.
840
+ it "has correct #test_filename_return" do
841
+ arr = Regress.test_filename_return
842
+ assert_equal ["åäö", "/etc/fstab"], arr.to_a
843
+ end
839
844
 
840
- should "have correct test_ghash_nested_everything_return"
841
- should "have correct test_ghash_nested_everything_return2"
845
+ it "has correct test_float" do
846
+ r = Regress.test_float 5435.32
847
+ assert_in_delta 5435.32, r, 0.001
848
+ end
842
849
 
843
- it "has correct #test_ghash_nothing_in" do
844
- Regress.test_ghash_nothing_in({"foo" => "bar", "baz" => "bat",
845
- "qux" => "quux"})
850
+ describe "#test_garray_container_return" do
851
+ before do
852
+ skip unless get_introspection_data 'Regress', 'test_garray_container_return'
853
+ @arr = Regress.test_garray_container_return
846
854
  end
847
855
 
848
- it "has correct #test_ghash_nothing_in2" do
849
- Regress.test_ghash_nothing_in2({"foo" => "bar", "baz" => "bat",
850
- "qux" => "quux"})
856
+ it "returns an instance of GLib::PtrArray" do
857
+ @arr.must_be_instance_of GLib::PtrArray
851
858
  end
852
859
 
853
- it "has correct #test_ghash_nothing_return" do
854
- ghash = Regress.test_ghash_nothing_return
855
- ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
856
- "qux" => "quux"}
860
+ it "returns the correct values" do
861
+ @arr.len.must_be :==, 1
862
+ ptr = @arr.pdata
863
+ ptr2 = ptr.read_pointer
864
+ ptr2.read_string.must_be :==, "regress"
857
865
  end
866
+ end
858
867
 
859
- it "has correct #test_ghash_nothing_return2" do
860
- ghash = Regress.test_ghash_nothing_return2
861
- ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
862
- "qux" => "quux"}
868
+ describe "#test_ghash_container_return" do
869
+ before do
870
+ @hash = Regress.test_ghash_container_return
863
871
  end
864
872
 
865
- it "has correct #test_ghash_null_in" do
866
- Regress.test_ghash_null_in(nil)
873
+ it "returns an instance of GLib::HashTable" do
874
+ @hash.must_be_instance_of GLib::HashTable
867
875
  end
868
876
 
869
- it "has correct #test_ghash_null_out" do
870
- ghash = Regress.test_ghash_null_out
871
- ghash.must_be_nil
877
+ it "returns the correct values" do
878
+ @hash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
879
+ "qux" => "quux"}
872
880
  end
881
+ end
873
882
 
874
- it "has correct #test_ghash_null_return" do
875
- ghash = Regress.test_ghash_null_return
876
- ghash.must_be_nil
877
- end
883
+ it "has correct #test_ghash_everything_return" do
884
+ ghash = Regress.test_ghash_everything_return
885
+ ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
886
+ "qux" => "quux"}
887
+ end
878
888
 
879
- context "#test_glist_container_return" do
880
- setup do
881
- @list = Regress.test_glist_container_return
882
- end
889
+ it "has correct test_ghash_nested_everything_return"
890
+ it "has correct test_ghash_nested_everything_return2"
883
891
 
884
- should "return an instance of GLib::SList" do
885
- assert_instance_of GLib::List, @list
886
- end
892
+ it "has correct #test_ghash_nothing_in" do
893
+ Regress.test_ghash_nothing_in({"foo" => "bar", "baz" => "bat",
894
+ "qux" => "quux"})
895
+ end
887
896
 
888
- should "return the correct values" do
889
- assert_equal ["1", "2", "3"], @list.to_a
890
- end
891
- end
897
+ it "has correct #test_ghash_nothing_in2" do
898
+ Regress.test_ghash_nothing_in2({"foo" => "bar", "baz" => "bat",
899
+ "qux" => "quux"})
900
+ end
892
901
 
893
- should "have correct test_glist_everything_return" do
894
- list = Regress.test_glist_everything_return
895
- assert_equal ["1", "2", "3"], list.to_a
896
- end
902
+ it "has correct #test_ghash_nothing_return" do
903
+ ghash = Regress.test_ghash_nothing_return
904
+ ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
905
+ "qux" => "quux"}
906
+ end
897
907
 
898
- should "have correct test_glist_nothing_in" do
899
- assert_nothing_raised {
900
- Regress.test_glist_nothing_in ["1", "2", "3"]
901
- }
902
- end
908
+ it "has correct #test_ghash_nothing_return2" do
909
+ ghash = Regress.test_ghash_nothing_return2
910
+ ghash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
911
+ "qux" => "quux"}
912
+ end
903
913
 
904
- should "have correct test_glist_nothing_in2" do
905
- assert_nothing_raised {
906
- Regress.test_glist_nothing_in2 ["1", "2", "3"]
907
- }
908
- end
914
+ it "has correct #test_ghash_null_in" do
915
+ Regress.test_ghash_null_in(nil)
916
+ end
909
917
 
910
- should "have correct test_glist_nothing_return" do
911
- list = Regress.test_glist_nothing_return
912
- assert_equal ["1", "2", "3"], list.to_a
913
- end
918
+ it "has correct #test_ghash_null_out" do
919
+ ghash = Regress.test_ghash_null_out
920
+ ghash.must_be_nil
921
+ end
914
922
 
915
- should "have correct test_glist_nothing_return2" do
916
- list = Regress.test_glist_nothing_return2
917
- assert_equal ["1", "2", "3"], list.to_a
923
+ it "has correct #test_ghash_null_return" do
924
+ ghash = Regress.test_ghash_null_return
925
+ ghash.must_be_nil
926
+ end
927
+
928
+ describe "#test_glist_container_return" do
929
+ setup do
930
+ @list = Regress.test_glist_container_return
918
931
  end
919
932
 
920
- should "have correct test_glist_null_in" do
921
- assert_nothing_raised {
922
- Regress.test_glist_null_in nil
923
- }
933
+ it "returns an instance of GLib::SList" do
934
+ assert_instance_of GLib::List, @list
924
935
  end
925
936
 
926
- should "have correct test_glist_null_out" do
927
- result = Regress.test_glist_null_out
928
- assert_equal nil, result
937
+ it "returns the correct values" do
938
+ assert_equal ["1", "2", "3"], @list.to_a
929
939
  end
940
+ end
930
941
 
931
- context "#test_gslist_container_return" do
932
- setup do
933
- @slist = Regress.test_gslist_container_return
934
- end
942
+ it "has correct test_glist_everything_return" do
943
+ list = Regress.test_glist_everything_return
944
+ assert_equal ["1", "2", "3"], list.to_a
945
+ end
935
946
 
936
- should "return a GLib::SList object" do
937
- assert_instance_of GLib::SList, @slist
938
- end
947
+ it "has correct test_glist_nothing_in" do
948
+ assert_nothing_raised {
949
+ Regress.test_glist_nothing_in ["1", "2", "3"]
950
+ }
951
+ end
939
952
 
940
- should "return the correct values" do
941
- assert_equal ["1", "2", "3"], @slist.to_a
942
- end
943
- end
953
+ it "has correct test_glist_nothing_in2" do
954
+ assert_nothing_raised {
955
+ Regress.test_glist_nothing_in2 ["1", "2", "3"]
956
+ }
957
+ end
944
958
 
945
- should "have correct test_gslist_everything_return" do
946
- slist = Regress.test_gslist_everything_return
947
- assert_equal ["1", "2", "3"], slist.to_a
948
- end
959
+ it "has correct test_glist_nothing_return" do
960
+ list = Regress.test_glist_nothing_return
961
+ assert_equal ["1", "2", "3"], list.to_a
962
+ end
949
963
 
950
- should "have correct test_gslist_nothing_in" do
951
- assert_nothing_raised {
952
- Regress.test_gslist_nothing_in ["1", "2", "3"]
953
- }
954
- end
964
+ it "has correct test_glist_nothing_return2" do
965
+ list = Regress.test_glist_nothing_return2
966
+ assert_equal ["1", "2", "3"], list.to_a
967
+ end
955
968
 
956
- should "have correct test_gslist_nothing_in2" do
957
- assert_nothing_raised {
958
- Regress.test_gslist_nothing_in2 ["1", "2", "3"]
959
- }
960
- end
969
+ it "has correct test_glist_null_in" do
970
+ assert_nothing_raised {
971
+ Regress.test_glist_null_in nil
972
+ }
973
+ end
961
974
 
962
- should "have correct test_gslist_nothing_return" do
963
- slist = Regress.test_gslist_nothing_return
964
- assert_equal ["1", "2", "3"], slist.to_a
965
- end
975
+ it "has correct test_glist_null_out" do
976
+ result = Regress.test_glist_null_out
977
+ assert_equal nil, result
978
+ end
966
979
 
967
- should "have correct test_gslist_nothing_return2" do
968
- slist = Regress.test_gslist_nothing_return2
969
- assert_equal ["1", "2", "3"], slist.to_a
980
+ describe "#test_gslist_container_return" do
981
+ setup do
982
+ @slist = Regress.test_gslist_container_return
970
983
  end
971
984
 
972
- should "have correct test_gslist_null_in" do
973
- assert_nothing_raised {
974
- Regress.test_gslist_null_in nil
975
- }
985
+ it "returns a GLib::SList object" do
986
+ assert_instance_of GLib::SList, @slist
976
987
  end
977
988
 
978
- context "#test_gslist_null_out" do
979
- should "return nil" do
980
- result = Regress.test_gslist_null_out
981
- assert_equal nil, result
982
- end
989
+ it "returns the correct values" do
990
+ assert_equal ["1", "2", "3"], @slist.to_a
983
991
  end
992
+ end
984
993
 
985
- should "have correct test_gtype" do
986
- result = Regress.test_gtype 23
987
- assert_equal 23, result
988
- end
994
+ it "has correct test_gslist_everything_return" do
995
+ slist = Regress.test_gslist_everything_return
996
+ assert_equal ["1", "2", "3"], slist.to_a
997
+ end
989
998
 
990
- should "have correct test_int" do
991
- result = Regress.test_int 23
992
- assert_equal 23, result
993
- end
999
+ it "has correct test_gslist_nothing_in" do
1000
+ assert_nothing_raised {
1001
+ Regress.test_gslist_nothing_in ["1", "2", "3"]
1002
+ }
1003
+ end
994
1004
 
995
- should "have correct test_int16" do
996
- result = Regress.test_int16 23
997
- assert_equal 23, result
998
- end
1005
+ it "has correct test_gslist_nothing_in2" do
1006
+ assert_nothing_raised {
1007
+ Regress.test_gslist_nothing_in2 ["1", "2", "3"]
1008
+ }
1009
+ end
999
1010
 
1000
- should "have correct test_int32" do
1001
- result = Regress.test_int32 23
1002
- assert_equal 23, result
1003
- end
1011
+ it "has correct test_gslist_nothing_return" do
1012
+ slist = Regress.test_gslist_nothing_return
1013
+ assert_equal ["1", "2", "3"], slist.to_a
1014
+ end
1004
1015
 
1005
- should "have correct test_int64" do
1006
- result = Regress.test_int64 2300000000000
1007
- assert_equal 2300000000000, result
1008
- end
1016
+ it "has correct test_gslist_nothing_return2" do
1017
+ slist = Regress.test_gslist_nothing_return2
1018
+ assert_equal ["1", "2", "3"], slist.to_a
1019
+ end
1009
1020
 
1010
- should "have correct test_int8" do
1011
- result = Regress.test_int8 23
1012
- assert_equal 23, result
1013
- end
1021
+ it "has correct test_gslist_null_in" do
1022
+ assert_nothing_raised {
1023
+ Regress.test_gslist_null_in nil
1024
+ }
1025
+ end
1014
1026
 
1015
- should "have correct test_int_out_utf8" do
1016
- len = Regress.test_int_out_utf8 "How long?"
1017
- assert_equal 9, len
1027
+ describe "#test_gslist_null_out" do
1028
+ it "returns nil" do
1029
+ result = Regress.test_gslist_null_out
1030
+ assert_equal nil, result
1018
1031
  end
1032
+ end
1019
1033
 
1020
- should "have correct test_int_value_arg" do
1021
- gv = GObject::Value.new
1022
- gv.init GObject.type_from_name "gint"
1023
- gv.set_int 343
1024
- result = Regress.test_int_value_arg gv
1025
- assert_equal 343, result
1026
- end
1034
+ it "has correct test_gtype" do
1035
+ result = Regress.test_gtype 23
1036
+ assert_equal 23, result
1037
+ end
1027
1038
 
1028
- should "have correct test_long" do
1029
- result = Regress.test_long 2300000000000
1030
- assert_equal 2300000000000, result
1031
- end
1039
+ it "has correct test_int" do
1040
+ result = Regress.test_int 23
1041
+ assert_equal 23, result
1042
+ end
1032
1043
 
1033
- should "have correct test_multi_callback" do
1034
- a = 1
1035
- result = Regress.test_multi_callback Proc.new {
1036
- a += 1
1037
- 23
1038
- }
1039
- assert_equal 2 * 23, result
1040
- assert_equal 3, a
1041
- end
1044
+ it "has correct test_int16" do
1045
+ result = Regress.test_int16 23
1046
+ assert_equal 23, result
1047
+ end
1042
1048
 
1043
- should "have correct test_multi_double_args" do
1044
- one, two = Regress.test_multi_double_args 23.1
1045
- assert_equal 2 * 23.1, one
1046
- assert_equal 3 * 23.1, two
1047
- end
1049
+ it "has correct test_int32" do
1050
+ result = Regress.test_int32 23
1051
+ assert_equal 23, result
1052
+ end
1048
1053
 
1049
- should "have correct test_short" do
1050
- result = Regress.test_short 23
1051
- assert_equal 23, result
1052
- end
1054
+ it "has correct test_int64" do
1055
+ result = Regress.test_int64 2300000000000
1056
+ assert_equal 2300000000000, result
1057
+ end
1053
1058
 
1054
- should "have correct test_simple_boxed_a_const_return" do
1055
- result = Regress.test_simple_boxed_a_const_return
1056
- assert_equal [5, 6, 7.0], [result.some_int, result.some_int8, result.some_double]
1057
- end
1059
+ it "has correct test_int8" do
1060
+ result = Regress.test_int8 23
1061
+ assert_equal 23, result
1062
+ end
1058
1063
 
1059
- describe "the #test_simple_callback function" do
1060
- should "call the passed-in proc" do
1061
- a = 0
1062
- Regress.test_simple_callback Proc.new { a = 1 }
1063
- assert_equal 1, a
1064
- end
1064
+ it "has correct test_int_out_utf8" do
1065
+ len = Regress.test_int_out_utf8 "How long?"
1066
+ assert_equal 9, len
1067
+ end
1065
1068
 
1066
- # XXX: The scope data does not seem to be reliable enough.
1067
- if false
1068
- should "not store the proc in CALLBACKS" do
1069
- n = Regress::Lib::CALLBACKS.length
1070
- Regress.test_simple_callback Proc.new { }
1071
- assert_equal n, Regress::Lib::CALLBACKS.length
1072
- end
1073
- end
1074
- end
1069
+ it "has correct test_int_value_arg" do
1070
+ gv = GObject::Value.new
1071
+ gv.init GObject.type_from_name "gint"
1072
+ gv.set_int 343
1073
+ result = Regress.test_int_value_arg gv
1074
+ assert_equal 343, result
1075
+ end
1075
1076
 
1076
- should "have correct test_size" do
1077
- assert_equal 2354, Regress.test_size(2354)
1078
- end
1077
+ it "has correct test_long" do
1078
+ long_val = FFI.type_size(:long) == 8 ? 2_300_000_000_000 : 2_000_000_000
1079
+ result = Regress.test_long long_val
1080
+ assert_equal long_val, result
1081
+ end
1079
1082
 
1080
- should "have correct test_ssize" do
1081
- assert_equal(-2_000_000, Regress.test_ssize(-2_000_000))
1082
- end
1083
+ it "has correct test_multi_callback" do
1084
+ a = 1
1085
+ result = Regress.test_multi_callback Proc.new {
1086
+ a += 1
1087
+ 23
1088
+ }
1089
+ assert_equal 2 * 23, result
1090
+ assert_equal 3, a
1091
+ end
1083
1092
 
1084
- should "have correct test_strv_in" do
1085
- assert_equal true, Regress.test_strv_in(['1', '2', '3'])
1086
- end
1093
+ it "has correct test_multi_double_args" do
1094
+ one, two = Regress.test_multi_double_args 23.1
1095
+ assert_equal 2 * 23.1, one
1096
+ assert_equal 3 * 23.1, two
1097
+ end
1087
1098
 
1088
- it "has correct #test_strv_in_gvalue" do
1089
- gv = Regress.test_strv_in_gvalue
1090
- assert_equal ['one', 'two', 'three'], gv.ruby_value.to_a
1091
- end
1099
+ it "has correct test_short" do
1100
+ result = Regress.test_short 23
1101
+ assert_equal 23, result
1102
+ end
1092
1103
 
1093
- it "has correct #test_strv_out" do
1094
- arr = Regress.test_strv_out
1095
- assert_equal ["thanks", "for", "all", "the", "fish"], arr.to_a
1096
- end
1104
+ it "has correct test_simple_boxed_a_const_return" do
1105
+ result = Regress.test_simple_boxed_a_const_return
1106
+ assert_equal [5, 6, 7.0], [result.some_int, result.some_int8, result.some_double]
1107
+ end
1097
1108
 
1098
- it "has correct #test_strv_out_c" do
1099
- arr = Regress.test_strv_out_c
1100
- assert_equal ["thanks", "for", "all", "the", "fish"], arr.to_a
1109
+ describe "the #test_simple_callback function" do
1110
+ it "calls the passed-in proc" do
1111
+ a = 0
1112
+ Regress.test_simple_callback Proc.new { a = 1 }
1113
+ assert_equal 1, a
1101
1114
  end
1102
1115
 
1103
- it "has correct #test_strv_out_container" do
1104
- arr = Regress.test_strv_out_container
1105
- assert_equal ['1', '2', '3'], arr.to_a
1116
+ # XXX: The scope data does not seem to be reliable enough.
1117
+ if false
1118
+ it "does not store the proc in CALLBACKS" do
1119
+ n = Regress::Lib::CALLBACKS.length
1120
+ Regress.test_simple_callback Proc.new { }
1121
+ assert_equal n, Regress::Lib::CALLBACKS.length
1106
1122
  end
1107
-
1108
- it "has correct #test_strv_outarg" do
1109
- arr = Regress.test_strv_outarg
1110
- assert_equal ['1', '2', '3'], arr.to_a
1111
1123
  end
1124
+ end
1112
1125
 
1113
- should "have correct test_timet" do
1114
- # Time rounded to seconds.
1115
- t = Time.at(Time.now.to_i)
1116
- result = Regress.test_timet(t.to_i)
1117
- assert_equal t, Time.at(result)
1118
- end
1126
+ it "has correct test_size" do
1127
+ assert_equal 2354, Regress.test_size(2354)
1128
+ end
1119
1129
 
1120
- should "have correct test_torture_signature_0" do
1121
- y, z, q = Regress.test_torture_signature_0 86, "foo", 2
1122
- assert_equal [86, 2*86, 3+2], [y, z, q]
1123
- end
1130
+ it "has correct test_ssize" do
1131
+ assert_equal(-2_000_000, Regress.test_ssize(-2_000_000))
1132
+ end
1124
1133
 
1125
- context "its #test_torture_signature_1 method" do
1126
- should "work for m even" do
1127
- ret, y, z, q = Regress.test_torture_signature_1(-21, "hello", 12)
1128
- assert_equal [true, -21, 2 * -21, "hello".length + 12], [ret, y, z, q]
1129
- end
1134
+ it "has correct test_strv_in" do
1135
+ assert_equal true, Regress.test_strv_in(['1', '2', '3'])
1136
+ end
1130
1137
 
1131
- should "throw an exception for m odd" do
1132
- assert_raises RuntimeError do
1133
- Regress.test_torture_signature_1(-21, "hello", 11)
1134
- end
1135
- end
1136
- end
1137
-
1138
- should "have correct test_torture_signature_2" do
1139
- a = 1
1140
- y, z, q = Regress.test_torture_signature_2 244,
1141
- Proc.new {|u| a = u }, 2, Proc.new { a = 3 },
1142
- "foofoo", 31
1143
- assert_equal [244, 2*244, 6+31], [y, z, q]
1144
- assert_equal 3, a
1145
- end
1138
+ it "has correct #test_strv_in_gvalue" do
1139
+ gv = Regress.test_strv_in_gvalue
1140
+ assert_equal ['one', 'two', 'three'], gv.ruby_value.to_a
1141
+ end
1146
1142
 
1147
- should "have correct test_uint" do
1148
- assert_equal 31, Regress.test_uint(31)
1149
- end
1143
+ it "has correct #test_strv_out" do
1144
+ arr = Regress.test_strv_out
1145
+ assert_equal ["thanks", "for", "all", "the", "fish"], arr.to_a
1146
+ end
1150
1147
 
1151
- should "have correct test_uint16" do
1152
- assert_equal 31, Regress.test_uint16(31)
1153
- end
1148
+ it "has correct #test_strv_out_c" do
1149
+ arr = Regress.test_strv_out_c
1150
+ assert_equal ["thanks", "for", "all", "the", "fish"], arr.to_a
1151
+ end
1154
1152
 
1155
- should "have correct test_uint32" do
1156
- assert_equal 540000, Regress.test_uint32(540000)
1157
- end
1153
+ it "has correct #test_strv_out_container" do
1154
+ arr = Regress.test_strv_out_container
1155
+ assert_equal ['1', '2', '3'], arr.to_a
1156
+ end
1158
1157
 
1159
- should "have correct test_uint64" do
1160
- assert_equal 54_000_000_000_000, Regress.test_uint64(54_000_000_000_000)
1161
- end
1158
+ it "has correct #test_strv_outarg" do
1159
+ arr = Regress.test_strv_outarg
1160
+ assert_equal ['1', '2', '3'], arr.to_a
1161
+ end
1162
1162
 
1163
- should "have correct test_uint8" do
1164
- assert_equal 31, Regress.test_uint8(31)
1165
- end
1163
+ it "has correct test_timet" do
1164
+ # Time rounded to seconds.
1165
+ t = Time.at(Time.now.to_i)
1166
+ result = Regress.test_timet(t.to_i)
1167
+ assert_equal t, Time.at(result)
1168
+ end
1166
1169
 
1167
- should "have correct test_ulong" do
1168
- assert_equal 54_000_000_000_000, Regress.test_uint64(54_000_000_000_000)
1169
- end
1170
+ it "has correct test_torture_signature_0" do
1171
+ y, z, q = Regress.test_torture_signature_0 86, "foo", 2
1172
+ assert_equal [86, 2*86, 3+2], [y, z, q]
1173
+ end
1170
1174
 
1171
- it "has a correct #test_unichar" do
1172
- assert_equal 120, Regress.test_unichar(120)
1173
- assert_equal 540_000, Regress.test_unichar(540_000)
1175
+ describe "its #test_torture_signature_1 method" do
1176
+ it "works for m even" do
1177
+ ret, y, z, q = Regress.test_torture_signature_1(-21, "hello", 12)
1178
+ assert_equal [true, -21, 2 * -21, "hello".length + 12], [ret, y, z, q]
1174
1179
  end
1175
1180
 
1176
- it "has a correct #test_unsigned_enum_param" do
1177
- assert_equal "value1", Regress.test_unsigned_enum_param(:value1)
1178
- assert_equal "value2", Regress.test_unsigned_enum_param(:value2)
1181
+ it "throws an exception for m odd" do
1182
+ assert_raises RuntimeError do
1183
+ Regress.test_torture_signature_1(-21, "hello", 11)
1184
+ end
1179
1185
  end
1186
+ end
1187
+
1188
+ it "has correct test_torture_signature_2" do
1189
+ a = 1
1190
+ y, z, q = Regress.test_torture_signature_2 244,
1191
+ Proc.new {|u| a = u }, 2, Proc.new { a = 3 },
1192
+ "foofoo", 31
1193
+ assert_equal [244, 2*244, 6+31], [y, z, q]
1194
+ assert_equal 3, a
1195
+ end
1180
1196
 
1181
- should "have correct test_ushort" do
1182
- assert_equal 54_000_000, Regress.test_uint64(54_000_000)
1183
- end
1197
+ it "has correct test_uint" do
1198
+ assert_equal 31, Regress.test_uint(31)
1199
+ end
1184
1200
 
1185
- should "have correct test_utf8_const_in" do
1186
- assert_nothing_raised do
1187
- Regress.test_utf8_const_in("const \xe2\x99\xa5 utf8")
1188
- end
1189
- end
1201
+ it "has correct test_uint16" do
1202
+ assert_equal 31, Regress.test_uint16(31)
1203
+ end
1190
1204
 
1191
- should "have correct test_utf8_const_return" do
1192
- result = Regress.test_utf8_const_return
1193
- assert_equal "const \xe2\x99\xa5 utf8", result
1194
- end
1205
+ it "has correct test_uint32" do
1206
+ assert_equal 540000, Regress.test_uint32(540000)
1207
+ end
1195
1208
 
1196
- should "have correct test_utf8_inout" do
1197
- result = Regress.test_utf8_inout "const \xe2\x99\xa5 utf8"
1198
- assert_equal "nonconst \xe2\x99\xa5 utf8", result
1199
- end
1209
+ it "has correct test_uint64" do
1210
+ assert_equal 54_000_000_000_000, Regress.test_uint64(54_000_000_000_000)
1211
+ end
1200
1212
 
1201
- should "have correct test_utf8_nonconst_return" do
1202
- result = Regress.test_utf8_nonconst_return
1203
- assert_equal "nonconst \xe2\x99\xa5 utf8", result
1204
- end
1213
+ it "has correct test_uint8" do
1214
+ assert_equal 31, Regress.test_uint8(31)
1215
+ end
1205
1216
 
1206
- should "have correct test_utf8_null_in" do
1207
- assert_nothing_raised do
1208
- Regress.test_utf8_null_in nil
1209
- end
1210
- end
1217
+ it "has correct test_ulong" do
1218
+ assert_equal 54_000_000_000_000, Regress.test_uint64(54_000_000_000_000)
1219
+ end
1211
1220
 
1212
- should "have correct test_utf8_null_out" do
1213
- assert_equal nil, Regress.test_utf8_null_out
1214
- end
1221
+ it "has a correct #test_unichar" do
1222
+ assert_equal 120, Regress.test_unichar(120)
1223
+ assert_equal 540_000, Regress.test_unichar(540_000)
1224
+ end
1215
1225
 
1216
- should "have correct test_utf8_out" do
1217
- result = Regress.test_utf8_out
1218
- assert_equal "nonconst \xe2\x99\xa5 utf8", result
1219
- end
1226
+ it "has a correct #test_unsigned_enum_param" do
1227
+ assert_equal "value1", Regress.test_unsigned_enum_param(:value1)
1228
+ assert_equal "value2", Regress.test_unsigned_enum_param(:value2)
1229
+ end
1220
1230
 
1221
- should "have correct test_utf8_out_nonconst_return" do
1222
- r, out = Regress.test_utf8_out_nonconst_return
1223
- assert_equal ["first", "second"], [r, out]
1224
- end
1231
+ it "has correct test_ushort" do
1232
+ assert_equal 54_000_000, Regress.test_uint64(54_000_000)
1233
+ end
1225
1234
 
1226
- should "have correct test_utf8_out_out" do
1227
- out0, out1 = Regress.test_utf8_out_nonconst_return
1228
- assert_equal ["first", "second"], [out0, out1]
1235
+ it "has correct test_utf8_const_in" do
1236
+ assert_nothing_raised do
1237
+ Regress.test_utf8_const_in("const \xe2\x99\xa5 utf8")
1229
1238
  end
1239
+ end
1230
1240
 
1231
- should "have correct test_value_return" do
1232
- result = Regress.test_value_return 3423
1233
- assert_equal 3423, result.get_int
1234
- end
1241
+ it "has correct test_utf8_const_return" do
1242
+ result = Regress.test_utf8_const_return
1243
+ assert_equal "const \xe2\x99\xa5 utf8", result
1244
+ end
1235
1245
 
1236
- it "raises an appropriate NoMethodError when a function is not found" do
1237
- begin
1238
- Regress.this_method_does_not_exist
1239
- rescue => e
1240
- assert_equal "undefined method `this_method_does_not_exist' for Regress:Module", e.message
1241
- end
1246
+ it "has correct test_utf8_inout" do
1247
+ result = Regress.test_utf8_inout "const \xe2\x99\xa5 utf8"
1248
+ assert_equal "nonconst \xe2\x99\xa5 utf8", result
1249
+ end
1250
+
1251
+ it "has correct test_utf8_nonconst_return" do
1252
+ result = Regress.test_utf8_nonconst_return
1253
+ assert_equal "nonconst \xe2\x99\xa5 utf8", result
1254
+ end
1255
+
1256
+ it "has correct test_utf8_null_in" do
1257
+ assert_nothing_raised do
1258
+ Regress.test_utf8_null_in nil
1242
1259
  end
1243
1260
  end
1244
1261
 
1262
+ it "has correct test_utf8_null_out" do
1263
+ assert_equal nil, Regress.test_utf8_null_out
1264
+ end
1265
+
1266
+ it "has correct test_utf8_out" do
1267
+ result = Regress.test_utf8_out
1268
+ assert_equal "nonconst \xe2\x99\xa5 utf8", result
1269
+ end
1270
+
1271
+ it "has correct test_utf8_out_nonconst_return" do
1272
+ r, out = Regress.test_utf8_out_nonconst_return
1273
+ assert_equal ["first", "second"], [r, out]
1274
+ end
1275
+
1276
+ it "has correct test_utf8_out_out" do
1277
+ out0, out1 = Regress.test_utf8_out_nonconst_return
1278
+ assert_equal ["first", "second"], [out0, out1]
1279
+ end
1280
+
1281
+ it "has correct test_value_return" do
1282
+ result = Regress.test_value_return 3423
1283
+ assert_equal 3423, result.get_int
1284
+ end
1285
+
1286
+ it "raises an appropriate NoMethodError when a function is not found" do
1287
+ begin
1288
+ Regress.this_method_does_not_exist
1289
+ rescue => e
1290
+ assert_equal "undefined method `this_method_does_not_exist' for Regress:Module", e.message
1291
+ end
1292
+ end
1245
1293
  end