gir_ffi 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/History.txt +11 -0
  2. data/TODO.rdoc +5 -0
  3. data/examples/01_empty_window.rb +0 -1
  4. data/examples/02_hello_world.rb +0 -1
  5. data/examples/03_upgraded_hello_world.rb +0 -1
  6. data/examples/04_webkit.rb +0 -1
  7. data/lib/gir_ffi/arg_helper.rb +231 -94
  8. data/lib/gir_ffi/builder/argument.rb +372 -46
  9. data/lib/gir_ffi/builder/module.rb +25 -10
  10. data/lib/gir_ffi/builder/type/constant.rb +39 -0
  11. data/lib/gir_ffi/builder/type/enum.rb +15 -5
  12. data/lib/gir_ffi/builder/type/registered_type.rb +25 -6
  13. data/lib/gir_ffi/builder/type/struct.rb +1 -9
  14. data/lib/gir_ffi/builder/type/union.rb +5 -0
  15. data/lib/gir_ffi/builder/type.rb +13 -14
  16. data/lib/gir_ffi/builder.rb +7 -4
  17. data/lib/gir_ffi/builder_helper.rb +4 -3
  18. data/lib/gir_ffi/i_base_info.rb +4 -0
  19. data/lib/gir_ffi/i_constant_info.rb +9 -0
  20. data/lib/gir_ffi/i_registered_type_info.rb +0 -1
  21. data/lib/gir_ffi/i_repository.rb +8 -2
  22. data/lib/gir_ffi/i_type_info.rb +7 -0
  23. data/lib/gir_ffi/lib.rb +41 -3
  24. data/lib/gir_ffi/overrides/glib.rb +188 -4
  25. data/lib/gir_ffi/overrides/gobject.rb +16 -5
  26. data/tasks/test.rake +1 -1
  27. data/test/arg_helper_test.rb +5 -5
  28. data/test/builder_test.rb +64 -41
  29. data/test/class_base_test.rb +1 -1
  30. data/test/function_definition_builder_test.rb +24 -2
  31. data/test/g_object_overrides_test.rb +1 -3
  32. data/test/g_object_test.rb +1 -1
  33. data/test/generated_gimarshallingtests_test.rb +1677 -0
  34. data/test/generated_gio_test.rb +1 -1
  35. data/test/generated_gtk_test.rb +31 -2
  36. data/test/generated_regress_test.rb +278 -54
  37. data/test/girffi_test.rb +20 -5
  38. data/test/glib_overrides_test.rb +81 -0
  39. data/test/gtk_overrides_test.rb +2 -3
  40. data/test/i_object_info_test.rb +1 -1
  41. data/test/i_repository_test.rb +3 -4
  42. data/test/lib/Makefile.am +18 -2
  43. data/test/module_builder_test.rb +1 -1
  44. data/test/test_helper.rb +88 -5
  45. data/test/type_builder_test.rb +7 -10
  46. metadata +16 -13
data/test/builder_test.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
- class BuilderTest < Test::Unit::TestCase
3
+ class BuilderTest < MiniTest::Spec
4
4
  context "The GirFFI::Builder module" do
5
5
  setup do
6
6
  @gir = GirFFI::IRepository.default
7
7
  end
8
8
 
9
9
  context "building GObject::Object" do
10
- setup do
11
- cleanup_module :GObject
12
- GirFFI::Builder.build_class @gir.find_by_name('GObject', 'Object')
10
+ before do
11
+ save_module :GObject
12
+ GirFFI::Builder.build_class get_function_introspection_data('GObject', 'Object')
13
13
  end
14
14
 
15
15
  should "create a Lib module in the parent namespace ready to attach functions from gobject-2.0" do
@@ -23,16 +23,20 @@ class BuilderTest < Test::Unit::TestCase
23
23
 
24
24
  should "not replace existing classes" do
25
25
  oldclass = GObject::Object
26
- GirFFI::Builder.build_class @gir.find_by_name('GObject', 'Object')
26
+ GirFFI::Builder.build_class get_function_introspection_data('GObject', 'Object')
27
27
  assert_equal oldclass, GObject::Object
28
28
  end
29
+
30
+ after do
31
+ restore_module :GObject
32
+ end
29
33
  end
30
34
 
31
35
  context "building Gtk::Window" do
32
- setup do
33
- cleanup_module :Gtk
34
- cleanup_module :GObject
35
- GirFFI::Builder.build_class @gir.find_by_name('Gtk', 'Window')
36
+ before do
37
+ save_module :Gtk
38
+ save_module :GObject
39
+ GirFFI::Builder.build_class get_function_introspection_data('Gtk', 'Window')
36
40
  end
37
41
 
38
42
  should "build Gtk namespace" do
@@ -66,22 +70,16 @@ class BuilderTest < Test::Unit::TestCase
66
70
  should "result in Gtk::Window.new to succeed" do
67
71
  assert_nothing_raised {Gtk::Window.new(:toplevel)}
68
72
  end
69
- end
70
73
 
71
- context "built Gtk::Widget" do
72
- setup do
73
- cleanup_module :Gtk
74
- GirFFI::Builder.build_class @gir.find_by_name('Gtk', 'Widget')
75
- end
76
-
77
- should "not have regular #new as a constructor" do
78
- assert_raises(NoMethodError) { Gtk::Widget.new }
74
+ after do
75
+ restore_module :Gtk
76
+ restore_module :GObject
79
77
  end
80
78
  end
81
79
 
82
80
  context "building Gtk" do
83
- setup do
84
- cleanup_module :Gtk
81
+ before do
82
+ save_module :Gtk
85
83
  GirFFI::Builder.build_module 'Gtk'
86
84
  end
87
85
 
@@ -106,6 +104,10 @@ class BuilderTest < Test::Unit::TestCase
106
104
  GirFFI::Builder.build_module 'Gtk'
107
105
  assert_equal oldmodule, Gtk::Lib
108
106
  end
107
+
108
+ after do
109
+ restore_module :Gtk
110
+ end
109
111
  end
110
112
 
111
113
  context "looking at Gtk.main" do
@@ -159,10 +161,10 @@ class BuilderTest < Test::Unit::TestCase
159
161
  end
160
162
 
161
163
  context "looking at Regress.test_callback_destroy_notify" do
162
- setup do
163
- cleanup_module :GLib
164
- cleanup_module :GObject
165
- cleanup_module :Regress
164
+ before do
165
+ save_module :GLib
166
+ save_module :GObject
167
+ save_module :Regress
166
168
  GirFFI::Builder.build_module 'GLib'
167
169
  GirFFI::Builder.build_module 'GObject'
168
170
  GirFFI::Builder.build_module 'Regress'
@@ -190,16 +192,21 @@ class BuilderTest < Test::Unit::TestCase
190
192
  should "define ffi enum type ConnectFlags" do
191
193
  assert_equal({:after => 1, :swapped => 2}, GObject::ConnectFlags.to_h)
192
194
  end
195
+
196
+ after do
197
+ restore_module :Regress
198
+ restore_module :GObject
199
+ restore_module :GLib
200
+ end
193
201
  end
194
202
 
195
203
  context "building Regress::TestStructA" do
196
204
  setup do
197
- @fieldnames = [:some_int, :some_int8, :some_double, :some_enum]
198
- GirFFI::Builder.build_class @gir.find_by_name('Regress', 'TestStructA')
205
+ GirFFI::Builder.build_class get_function_introspection_data('Regress', 'TestStructA')
199
206
  end
200
207
 
201
208
  should "set up the correct struct members" do
202
- assert_equal @fieldnames,
209
+ assert_equal [:some_int, :some_int8, :some_double, :some_enum],
203
210
  Regress::TestStructA::Struct.members
204
211
  end
205
212
 
@@ -212,13 +219,13 @@ class BuilderTest < Test::Unit::TestCase
212
219
  should "set up struct members with the correct types" do
213
220
  tags = [:int, :int8, :double, Regress::TestEnum]
214
221
  assert_equal tags.map {|t| FFI.find_type t},
215
- @fieldnames.map {|f| Regress::TestStructA::Struct.layout[f].type}
222
+ Regress::TestStructA::Struct.layout.fields.map {|f| f.type}
216
223
  end
217
224
  end
218
225
 
219
226
  context "building GObject::TypeCValue" do
220
227
  setup do
221
- GirFFI::Builder.build_class @gir.find_by_name('GObject', 'TypeCValue')
228
+ GirFFI::Builder.build_class get_function_introspection_data('GObject', 'TypeCValue')
222
229
  end
223
230
 
224
231
  should "set up the correct union members" do
@@ -238,7 +245,7 @@ class BuilderTest < Test::Unit::TestCase
238
245
 
239
246
  context "building GObject::ValueArray" do
240
247
  should "use provided constructor if present" do
241
- GirFFI::Builder.build_class @gir.find_by_name('GObject', 'ValueArray')
248
+ GirFFI::Builder.build_class get_function_introspection_data('GObject', 'ValueArray')
242
249
  assert_nothing_raised {
243
250
  GObject::ValueArray.new 2
244
251
  }
@@ -247,7 +254,7 @@ class BuilderTest < Test::Unit::TestCase
247
254
 
248
255
  context "building Regress::TestBoxed" do
249
256
  setup do
250
- GirFFI::Builder.build_class @gir.find_by_name('Regress', 'TestBoxed')
257
+ GirFFI::Builder.build_class get_function_introspection_data('Regress', 'TestBoxed')
251
258
  end
252
259
 
253
260
  should "set up #wrap" do
@@ -260,8 +267,8 @@ class BuilderTest < Test::Unit::TestCase
260
267
  end
261
268
 
262
269
  context "built Regress module" do
263
- setup do
264
- cleanup_module :Regress
270
+ before do
271
+ save_module :Regress
265
272
  GirFFI::Builder.build_module 'Regress'
266
273
  end
267
274
 
@@ -279,12 +286,16 @@ class BuilderTest < Test::Unit::TestCase
279
286
  should "know its own module builder" do
280
287
  assert GirFFI::Builder::Module === Regress.gir_ffi_builder
281
288
  end
289
+
290
+ after do
291
+ restore_module :Regress
292
+ end
282
293
  end
283
294
 
284
295
  context "built Regress::TestObj" do
285
- setup do
286
- cleanup_module :Regress
287
- GirFFI::Builder.build_class @gir.find_by_name('Regress', 'TestObj')
296
+ before do
297
+ save_module :Regress
298
+ GirFFI::Builder.build_class get_function_introspection_data('Regress', 'TestObj')
288
299
  end
289
300
 
290
301
  should "make autocreated instance method available to all instances" do
@@ -319,12 +330,16 @@ class BuilderTest < Test::Unit::TestCase
319
330
  GirFFI::Builder.send(:ffi_function_argument_types, info)
320
331
  end
321
332
  end
333
+
334
+ after do
335
+ restore_module :Regress
336
+ end
322
337
  end
323
338
 
324
339
  context "built Regress::TestSubObj" do
325
- setup do
326
- cleanup_module :Regress
327
- GirFFI::Builder.build_class @gir.find_by_name('Regress', 'TestSubObj')
340
+ before do
341
+ save_module :Regress
342
+ GirFFI::Builder.build_class get_function_introspection_data('Regress', 'TestSubObj')
328
343
  end
329
344
 
330
345
  should "autocreate parent class' set_bare inside the parent class" do
@@ -346,11 +361,15 @@ class BuilderTest < Test::Unit::TestCase
346
361
  subobj = Regress::TestSubObj.new
347
362
  assert_equal 0, subobj.instance_method
348
363
  end
364
+
365
+ after do
366
+ restore_module :Regress
367
+ end
349
368
  end
350
369
 
351
370
  context "built Gio::ThreadedSocketService" do
352
- setup do
353
- cleanup_module :Gio
371
+ before do
372
+ save_module :Gio
354
373
  GirFFI::Builder.build_module 'Gio'
355
374
  end
356
375
 
@@ -363,6 +382,10 @@ class BuilderTest < Test::Unit::TestCase
363
382
  assert_nothing_raised { Gio::ThreadedSocketService.new 2 }
364
383
  end
365
384
  end
385
+
386
+ after do
387
+ restore_module :Gio
388
+ end
366
389
  end
367
390
  end
368
391
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
- class ClassBaseTest < Test::Unit::TestCase
3
+ class ClassBaseTest < MiniTest::Spec
4
4
  context "A class derived from GirFFI::Base" do
5
5
  # TODO: See if we can test some part of Base again.
6
6
  should "pass" do
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
- class FunctionDefinitionBuilderTest < Test::Unit::TestCase
3
+ class FunctionDefinitionBuilderTest < MiniTest::Spec
4
4
  context "The Builder::Function class" do
5
5
  should "build correct definition of Gtk.init" do
6
6
  go = get_function_introspection_data 'Gtk', 'init'
@@ -68,7 +68,7 @@ class FunctionDefinitionBuilderTest < Test::Unit::TestCase
68
68
  _v4 = FFI::MemoryPointer.new(:pointer).write_pointer nil
69
69
  _v2 = ::Lib.regress_test_obj_new_from_file _v1, _v4
70
70
  GirFFI::ArgHelper.check_error(_v4)
71
- _v3 = ::Regress::TestObj.constructor_wrap(_v2)
71
+ _v3 = self.constructor_wrap(_v2)
72
72
  return _v3
73
73
  end"
74
74
 
@@ -111,5 +111,27 @@ class FunctionDefinitionBuilderTest < Test::Unit::TestCase
111
111
 
112
112
  assert_equal cws(expected), cws(code)
113
113
  end
114
+
115
+ it "builds the correct definition of GIMarshallingTests::Object#method_array_inout" do
116
+ go = get_method_introspection_data 'GIMarshallingTests', 'Object', 'method_array_inout'
117
+ fbuilder = GirFFI::Builder::Function.new go, Lib
118
+ code = fbuilder.generate
119
+
120
+ expected =
121
+ "def method_array_inout ints
122
+ _v1 = GirFFI::ArgHelper.gint32_array_to_inoutptr ints
123
+ length = ints.length
124
+ _v3 = GirFFI::ArgHelper.gint32_to_inoutptr length
125
+ ::Lib.gi_marshalling_tests_object_method_array_inout self, _v1, _v3
126
+ _v4 = GirFFI::ArgHelper.outptr_to_gint32 _v3
127
+ GirFFI::ArgHelper.cleanup_ptr _v3
128
+ _v2 = GirFFI::ArgHelper.outptr_to_gint32_array _v1, _v4
129
+ GirFFI::ArgHelper.cleanup_ptr _v1
130
+ return _v2
131
+ end"
132
+
133
+ assert_equal cws(expected), cws(code)
134
+ end
135
+
114
136
  end
115
137
  end
@@ -1,11 +1,9 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
- class GObjectOverridesTest < Test::Unit::TestCase
3
+ class GObjectOverridesTest < MiniTest::Spec
4
4
  context "In the GObject module with overridden functions" do
5
5
  setup do
6
- GirFFI.setup :GObject
7
6
  GirFFI.setup :Regress
8
- GirFFI.setup :Gio
9
7
  end
10
8
 
11
9
  context "the Value class" do
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
2
 
3
- class GObjectTest < Test::Unit::TestCase
3
+ class GObjectTest < MiniTest::Spec
4
4
  context "The GirFFI::GObject helper module" do
5
5
  should "have type_init as a public method" do
6
6
  assert GirFFI::GObject.respond_to?('type_init')