gir_ffi 0.6.7 → 0.7.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 (136) hide show
  1. checksums.yaml +7 -0
  2. data/{History.txt → Changelog.md} +93 -61
  3. data/{DESIGN.rdoc → DESIGN.md} +7 -7
  4. data/README.md +5 -7
  5. data/TODO.md +90 -0
  6. data/lib/ffi-glib.rb +0 -1
  7. data/lib/ffi-glib/array.rb +13 -29
  8. data/lib/ffi-glib/array_methods.rb +13 -0
  9. data/lib/ffi-glib/container_class_methods.rb +6 -1
  10. data/lib/ffi-glib/hash_table.rb +3 -2
  11. data/lib/ffi-glib/list.rb +3 -17
  12. data/lib/ffi-glib/list_methods.rb +22 -3
  13. data/lib/ffi-glib/ptr_array.rb +19 -19
  14. data/lib/ffi-glib/s_list.rb +3 -17
  15. data/lib/ffi-gobject.rb +10 -17
  16. data/lib/ffi-gobject/object.rb +19 -9
  17. data/lib/ffi-gobject/object_class.rb +14 -0
  18. data/lib/ffi-gobject/ruby_closure.rb +4 -5
  19. data/lib/ffi-gobject/value.rb +7 -5
  20. data/lib/ffi-gobject_introspection/i_vfunc_info.rb +1 -1
  21. data/lib/gir_ffi-base.rb +0 -2
  22. data/lib/gir_ffi-base/gobject.rb +1 -0
  23. data/lib/gir_ffi-base/gobject/lib.rb +1 -1
  24. data/lib/gir_ffi.rb +2 -0
  25. data/lib/gir_ffi/arg_helper.rb +18 -8
  26. data/lib/gir_ffi/builders/argument_builder.rb +62 -55
  27. data/lib/gir_ffi/builders/base_argument_builder.rb +52 -106
  28. data/lib/gir_ffi/builders/base_type_builder.rb +3 -3
  29. data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +34 -0
  30. data/lib/gir_ffi/builders/callback_argument_builder.rb +73 -0
  31. data/lib/gir_ffi/builders/callback_builder.rb +19 -9
  32. data/lib/gir_ffi/builders/callback_return_value_builder.rb +54 -0
  33. data/lib/gir_ffi/builders/closure_convertor.rb +9 -0
  34. data/lib/gir_ffi/builders/closure_to_pointer_convertor.rb +9 -0
  35. data/lib/gir_ffi/builders/constructor_result_convertor.rb +9 -0
  36. data/lib/gir_ffi/builders/enum_builder.rb +16 -16
  37. data/lib/gir_ffi/builders/field_builder.rb +36 -15
  38. data/lib/gir_ffi/builders/function_builder.rb +32 -27
  39. data/lib/gir_ffi/builders/interface_builder.rb +14 -4
  40. data/lib/gir_ffi/builders/mapping_method_builder.rb +95 -43
  41. data/lib/gir_ffi/builders/module_builder.rb +22 -35
  42. data/lib/gir_ffi/builders/null_convertor.rb +9 -0
  43. data/lib/gir_ffi/builders/object_builder.rb +11 -14
  44. data/lib/gir_ffi/builders/property_builder.rb +107 -9
  45. data/lib/gir_ffi/builders/registered_type_builder.rb +2 -2
  46. data/lib/gir_ffi/builders/return_value_builder.rb +42 -33
  47. data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +15 -0
  48. data/lib/gir_ffi/builders/signal_builder.rb +18 -58
  49. data/lib/gir_ffi/builders/struct_builder.rb +1 -2
  50. data/lib/gir_ffi/builders/type_builder.rb +1 -0
  51. data/lib/gir_ffi/builders/unintrospectable_builder.rb +4 -4
  52. data/lib/gir_ffi/builders/user_defined_builder.rb +151 -26
  53. data/lib/gir_ffi/builders/vfunc_builder.rb +57 -0
  54. data/lib/gir_ffi/builders/with_layout.rb +10 -8
  55. data/lib/gir_ffi/builders/with_methods.rb +1 -1
  56. data/lib/gir_ffi/callback_base.rb +42 -8
  57. data/lib/gir_ffi/class_base.rb +1 -2
  58. data/lib/gir_ffi/enum_base.rb +26 -4
  59. data/lib/gir_ffi/error_argument_info.rb +21 -0
  60. data/lib/gir_ffi/{setter_argument_info.rb → field_argument_info.rb} +2 -1
  61. data/lib/gir_ffi/g_type.rb +25 -0
  62. data/lib/gir_ffi/in_out_pointer.rb +3 -14
  63. data/lib/gir_ffi/in_pointer.rb +20 -21
  64. data/lib/gir_ffi/info_ext.rb +2 -0
  65. data/lib/gir_ffi/info_ext/i_callable_info.rb +0 -9
  66. data/lib/gir_ffi/info_ext/i_callback_info.rb +17 -0
  67. data/lib/gir_ffi/info_ext/i_function_info.rb +4 -0
  68. data/lib/gir_ffi/info_ext/i_property_info.rb +4 -0
  69. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +1 -0
  70. data/lib/gir_ffi/info_ext/i_signal_info.rb +14 -16
  71. data/lib/gir_ffi/info_ext/i_type_info.rb +72 -34
  72. data/lib/gir_ffi/info_ext/i_vfunc_info.rb +12 -0
  73. data/lib/gir_ffi/info_ext/safe_constant_name.rb +3 -2
  74. data/lib/gir_ffi/interface_base.rb +8 -3
  75. data/lib/gir_ffi/module_base.rb +3 -5
  76. data/lib/gir_ffi/object_base.rb +8 -0
  77. data/lib/gir_ffi/receiver_argument_info.rb +21 -0
  78. data/lib/gir_ffi/receiver_type_info.rb +27 -0
  79. data/lib/gir_ffi/return_value_info.rb +23 -0
  80. data/lib/gir_ffi/signal_base.rb +1 -1
  81. data/lib/{ffi-glib → gir_ffi}/sized_array.rb +10 -6
  82. data/lib/gir_ffi/struct_base.rb +10 -9
  83. data/lib/gir_ffi/type_base.rb +1 -0
  84. data/lib/gir_ffi/type_map.rb +3 -0
  85. data/lib/gir_ffi/unintrospectable_type_info.rb +4 -1
  86. data/lib/gir_ffi/union_base.rb +4 -21
  87. data/lib/gir_ffi/user_data_argument_info.rb +21 -0
  88. data/lib/gir_ffi/user_data_type_info.rb +17 -0
  89. data/lib/gir_ffi/user_defined_type_info.rb +18 -4
  90. data/lib/gir_ffi/version.rb +1 -1
  91. data/lib/gir_ffi/vfunc_base.rb +8 -0
  92. data/lib/gir_ffi/vfunc_implementation.rb +11 -0
  93. data/lib/gir_ffi/zero_terminated.rb +18 -24
  94. data/test/base_test_helper.rb +2 -3
  95. data/test/ffi-glib/array_test.rb +3 -3
  96. data/test/ffi-glib/ruby_closure_test.rb +3 -3
  97. data/test/ffi-gobject/value_test.rb +15 -1
  98. data/test/ffi-gobject_test.rb +2 -1
  99. data/test/gir_ffi/arg_helper_test.rb +21 -2
  100. data/test/gir_ffi/builders/argument_builder_test.rb +213 -287
  101. data/test/gir_ffi/builders/base_argument_builder_test.rb +1 -1
  102. data/test/gir_ffi/builders/callback_builder_test.rb +26 -8
  103. data/test/gir_ffi/builders/field_builder_test.rb +18 -3
  104. data/test/gir_ffi/builders/function_builder_test.rb +30 -12
  105. data/test/gir_ffi/builders/interface_builder_test.rb +9 -0
  106. data/test/gir_ffi/builders/module_builder_test.rb +0 -39
  107. data/test/gir_ffi/builders/object_builder_test.rb +27 -27
  108. data/test/gir_ffi/builders/property_builder_test.rb +110 -0
  109. data/test/gir_ffi/builders/return_value_builder_test.rb +168 -200
  110. data/test/gir_ffi/builders/signal_builder_test.rb +58 -14
  111. data/test/gir_ffi/builders/struct_builder_test.rb +2 -41
  112. data/test/gir_ffi/builders/user_defined_builder_test.rb +88 -20
  113. data/test/gir_ffi/builders/vfunc_builder_test.rb +44 -0
  114. data/test/gir_ffi/g_type_test.rb +29 -0
  115. data/test/gir_ffi/in_pointer_test.rb +28 -9
  116. data/test/gir_ffi/info_ext/i_callable_info_test.rb +0 -9
  117. data/test/gir_ffi/info_ext/i_callback_info_test.rb +19 -0
  118. data/test/gir_ffi/info_ext/i_function_info_test.rb +9 -0
  119. data/test/gir_ffi/info_ext/i_signal_info_test.rb +8 -11
  120. data/test/gir_ffi/info_ext/i_type_info_test.rb +140 -16
  121. data/test/gir_ffi/interface_base_test.rb +9 -3
  122. data/test/gir_ffi/object_base_test.rb +1 -2
  123. data/test/{ffi-glib → gir_ffi}/sized_array_test.rb +28 -28
  124. data/test/gir_ffi/type_map_test.rb +1 -1
  125. data/test/gir_ffi/user_defined_type_info_test.rb +36 -4
  126. data/test/gir_ffi_test.rb +5 -5
  127. data/test/gir_ffi_test_helper.rb +4 -0
  128. data/test/integration/generated_gimarshallingtests_test.rb +163 -59
  129. data/test/integration/generated_gobject_test.rb +21 -8
  130. data/test/integration/generated_pango_test.rb +2 -2
  131. data/test/integration/generated_regress_test.rb +361 -101
  132. data/test/lib/autogen.sh +5 -1
  133. metadata +51 -35
  134. data/TODO.rdoc +0 -63
  135. data/lib/gir_ffi-base/gir_ffi/library.rb +0 -17
  136. data/lib/gir_ffi-base/gir_ffi/struct.rb +0 -27
@@ -58,4 +58,13 @@ describe GirFFI::InfoExt::IFunctionInfo do
58
58
  end
59
59
  end
60
60
  end
61
+
62
+ describe "#return_ffi_type" do
63
+ it "returns the ffi type of the return type" do
64
+ stub(return_type_info = Object.new).to_ffitype { :some_type }
65
+ stub(function_info).return_type { return_type_info }
66
+
67
+ function_info.return_ffi_type.must_equal :some_type
68
+ end
69
+ end
61
70
  end
@@ -1,5 +1,7 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
+ GirFFI.setup :Regress
4
+
3
5
  describe GirFFI::InfoExt::ISignalInfo do
4
6
  let(:klass) { Class.new do
5
7
  include GirFFI::InfoExt::ICallableInfo
@@ -7,31 +9,26 @@ describe GirFFI::InfoExt::ISignalInfo do
7
9
  end }
8
10
  let(:signal_info) { klass.new }
9
11
 
10
- describe "#signal_arguments_to_gvalue_array" do
12
+ describe "#arguments_to_gvalues" do
11
13
  let(:object) { Regress::TestSubObj.new }
12
14
  let(:boxed) { Regress::TestSimpleBoxedA.const_return }
13
15
  let(:signal_info) { Regress::TestSubObj.find_signal "test-with-static-scope-arg" }
14
- let(:result) { signal_info.signal_arguments_to_gvalue_array(object, boxed) }
15
-
16
- it "wraps its arguments in a GObject::ValueArray" do
17
- result.must_be_instance_of GObject::ValueArray
18
- result.n_values.must_equal 2
19
- end
16
+ let(:result) { signal_info.arguments_to_gvalues(object, [boxed]) }
20
17
 
21
18
  it "correctly wraps :object" do
22
- result.get_nth(0).get_value.must_equal object
19
+ result[0].get_value.must_equal object
23
20
  end
24
21
 
25
22
  it "correctly wraps :struct" do
26
- result_boxed = result.get_nth(1).get_value
23
+ result_boxed = result[1].get_value
27
24
  result_boxed.some_int8.must_equal boxed.some_int8
28
25
  result_boxed.some_int.must_equal boxed.some_int
29
26
  end
30
27
  end
31
28
 
32
29
  describe "#return_ffi_type" do
33
- # FIXME: This is needed because callbacks are limited in the accepted
34
- # types. This should be fixed in FFI.
30
+ # NOTE: This is needed because FFI callbacks are limited in the
31
+ # accepted types.
35
32
  it "returns :bool for the :gboolean type" do
36
33
  stub(return_type_info = Object.new).to_ffitype { GLib::Boolean }
37
34
  stub(signal_info).return_type { return_type_info }
@@ -13,6 +13,9 @@ describe GirFFI::InfoExt::ITypeInfo do
13
13
 
14
14
  let(:callback_type_info) {
15
15
  get_introspection_data('Regress', 'test_callback').args[0].argument_type }
16
+ let(:ghash_type_info) {
17
+ get_introspection_data('Regress',
18
+ 'test_ghash_nested_everything_return').return_type }
16
19
 
17
20
  describe "#to_ffitype" do
18
21
  it "returns an array with elements subtype and size for type :array" do
@@ -150,18 +153,6 @@ describe GirFFI::InfoExt::ITypeInfo do
150
153
  end
151
154
  end
152
155
 
153
- describe "#subtype_tag_or_class" do
154
- describe "without a parameter" do
155
- it "returns the result of calling #tag_or_class on the first param_type" do
156
- mock(elmtype_info).tag_or_class { :foo }
157
-
158
- mock(type_info).param_type(0) { elmtype_info }
159
-
160
- type_info.subtype_tag_or_class.must_equal :foo
161
- end
162
- end
163
- end
164
-
165
156
  describe "#tag_or_class" do
166
157
  describe "for a simple type" do
167
158
  it "returns the type's tag" do
@@ -210,10 +201,10 @@ describe GirFFI::InfoExt::ITypeInfo do
210
201
  end
211
202
 
212
203
  describe "when the interface type is :object" do
213
- it "returns an array with elements :pointer and built interface class" do
204
+ it "returns the built interface class" do
214
205
  stub(iface_info).info_type { :object }
215
206
 
216
- type_info.tag_or_class.must_equal [:pointer, interface]
207
+ type_info.tag_or_class.must_equal interface
217
208
  end
218
209
  end
219
210
 
@@ -228,8 +219,8 @@ describe GirFFI::InfoExt::ITypeInfo do
228
219
  end
229
220
 
230
221
  describe "for a callback" do
231
- it "returns :callback" do
232
- callback_type_info.tag_or_class.must_equal :callback
222
+ it "returns the callback's wrapper class" do
223
+ callback_type_info.tag_or_class.must_equal Regress::TestCallback
233
224
  end
234
225
  end
235
226
 
@@ -250,6 +241,17 @@ describe GirFFI::InfoExt::ITypeInfo do
250
241
  type_info.tag_or_class.must_equal [:pointer, :void]
251
242
  end
252
243
  end
244
+
245
+ describe "for a complex nested hash type" do
246
+ it "returns a representeation of the nested structure" do
247
+ ghash_type_info.tag_or_class.must_equal(
248
+ [ :pointer,
249
+ [ :ghash,
250
+ :utf8,
251
+ [ :pointer,
252
+ [ :ghash, :utf8, :utf8 ] ] ] ])
253
+ end
254
+ end
253
255
  end
254
256
 
255
257
  describe "#to_callback_ffitype" do
@@ -564,4 +566,126 @@ describe GirFFI::InfoExt::ITypeInfo do
564
566
  end
565
567
  end
566
568
  end
569
+
570
+ describe "#g_type" do
571
+ before do
572
+ stub(type_info).tag { tag }
573
+ stub(type_info).pointer? { pointer? }
574
+ end
575
+
576
+ describe "for :void" do
577
+ let(:tag) { :void }
578
+ let(:pointer?) { false }
579
+
580
+ it "equals the none type" do
581
+ GObject.type_name(type_info.g_type).must_equal "void"
582
+ end
583
+ end
584
+
585
+ describe "for :gboolean" do
586
+ let(:tag) { :gboolean }
587
+ let(:pointer?) { false }
588
+
589
+ it "equals the gboolean type" do
590
+ GObject.type_name(type_info.g_type).must_equal "gboolean"
591
+ end
592
+ end
593
+
594
+ describe "for :gint32" do
595
+ let(:tag) { :gint32 }
596
+ let(:pointer?) { false }
597
+
598
+ it "equals the gint type" do
599
+ GObject.type_name(type_info.g_type).must_equal "gint"
600
+ end
601
+ end
602
+
603
+ describe "for :gint64" do
604
+ let(:tag) { :gint64 }
605
+ let(:pointer?) { false }
606
+
607
+ it "equals the gint64 type" do
608
+ GObject.type_name(type_info.g_type).must_equal "gint64"
609
+ end
610
+ end
611
+
612
+ describe "for :guint64" do
613
+ let(:tag) { :guint64 }
614
+ let(:pointer?) { false }
615
+
616
+ it "equals the guint64 type" do
617
+ GObject.type_name(type_info.g_type).must_equal "guint64"
618
+ end
619
+ end
620
+
621
+ describe "for pointer to :utf8" do
622
+ let(:tag) { :utf8 }
623
+ let(:pointer?) { true }
624
+
625
+ it "equals the gchararray type" do
626
+ GObject.type_name(type_info.g_type).must_equal "gchararray"
627
+ end
628
+ end
629
+
630
+ describe "for pointer to :ghash" do
631
+ let(:tag) { :ghash }
632
+ let(:pointer?) { true }
633
+
634
+ it "equals the GHashTable type" do
635
+ GObject.type_name(type_info.g_type).must_equal "GHashTable"
636
+ end
637
+ end
638
+
639
+ describe "for arrays" do
640
+ let(:tag) { :array }
641
+ let(:pointer?) { true }
642
+
643
+ describe "for pointer to GArray" do
644
+ before do
645
+ stub(type_info).zero_terminated? { false }
646
+ stub(type_info).array_type { :array }
647
+ end
648
+
649
+ it "equals the GArray type" do
650
+ GObject.type_name(type_info.g_type).must_equal "GArray"
651
+ end
652
+ end
653
+
654
+ describe "for a C array" do
655
+ before do
656
+ stub(type_info).zero_terminated? { false }
657
+ stub(type_info).array_type { :c }
658
+ end
659
+
660
+ it "equals the gpointer type" do
661
+ GObject.type_name(type_info.g_type).must_equal "gpointer"
662
+ end
663
+ end
664
+
665
+ describe "for a zero-terminated array" do
666
+ before do
667
+ stub(type_info).param_type(0) { elmtype_info }
668
+ stub(type_info).zero_terminated? { true }
669
+ end
670
+
671
+ describe "of utf8" do
672
+ it "equals the GStrv type" do
673
+ stub(elmtype_info).tag { :utf8 }
674
+ stub(elmtype_info).pointer? { true }
675
+
676
+ GObject.type_name(type_info.g_type).must_equal "GStrv"
677
+ end
678
+ end
679
+
680
+ describe "of filename" do
681
+ it "equals the GStrv type" do
682
+ stub(elmtype_info).tag { :filename }
683
+ stub(elmtype_info).pointer? { true }
684
+
685
+ GObject.type_name(type_info.g_type).must_equal "GStrv"
686
+ end
687
+ end
688
+ end
689
+ end
690
+ end
567
691
  end
@@ -1,12 +1,18 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GirFFI::InterfaceBase do
4
+ let(:interface) { Module.new { extend GirFFI::InterfaceBase } }
5
+
4
6
  describe "#wrap" do
5
7
  it "delegates conversion to the wrapped pointer" do
6
- mod = Module.new { extend GirFFI::InterfaceBase }
7
8
  mock(ptr = Object.new).to_object { "good-result" }
8
- mod.wrap(ptr).must_equal "good-result"
9
+ interface.wrap(ptr).must_equal "good-result"
9
10
  end
10
11
  end
11
- end
12
12
 
13
+ describe ".to_ffitype" do
14
+ it "returns :pointer" do
15
+ interface.to_ffitype.must_equal :pointer
16
+ end
17
+ end
18
+ end
@@ -2,6 +2,7 @@ require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GirFFI::ObjectBase do
4
4
  let(:derived_class) { Class.new GirFFI::ObjectBase }
5
+
5
6
  describe ".wrap" do
6
7
  it "delegates conversion to the wrapped pointer" do
7
8
  mock(ptr = Object.new).to_object { "good-result" }
@@ -15,5 +16,3 @@ describe GirFFI::ObjectBase do
15
16
  end
16
17
  end
17
18
  end
18
-
19
-
@@ -1,11 +1,11 @@
1
- require 'base_test_helper'
1
+ require 'gir_ffi_test_helper'
2
2
 
3
- describe GLib::SizedArray do
3
+ describe GirFFI::SizedArray do
4
4
  describe "::wrap" do
5
- it "takes a type, size and pointer and returns a GLib::SizedArray wrapping them" do
5
+ it "takes a type, size and pointer and returns a GirFFI::SizedArray wrapping them" do
6
6
  mock(ptr = Object.new).null? { false }
7
- sarr = GLib::SizedArray.wrap :gint32, 3, ptr
8
- assert_instance_of GLib::SizedArray, sarr
7
+ sarr = GirFFI::SizedArray.wrap :gint32, 3, ptr
8
+ assert_instance_of GirFFI::SizedArray, sarr
9
9
  assert_equal ptr, sarr.to_ptr
10
10
  assert_equal 3, sarr.size
11
11
  assert_equal :gint32, sarr.element_type
@@ -13,7 +13,7 @@ describe GLib::SizedArray do
13
13
 
14
14
  it "returns nil if the wrapped pointer is null" do
15
15
  mock(ptr = Object.new).null? { true }
16
- sarr = GLib::SizedArray.wrap :gint32, 3, ptr
16
+ sarr = GirFFI::SizedArray.wrap :gint32, 3, ptr
17
17
  sarr.must_be_nil
18
18
  end
19
19
  end
@@ -26,7 +26,7 @@ describe GLib::SizedArray do
26
26
  block = FFI::MemoryPointer.new(:pointer, ptrs.length)
27
27
  block.write_array_of_pointer ptrs
28
28
 
29
- sarr = GLib::SizedArray.new :utf8, 3, block
29
+ sarr = GirFFI::SizedArray.new :utf8, 3, block
30
30
  arr = []
31
31
  sarr.each do |str|
32
32
  arr << str
@@ -37,44 +37,44 @@ describe GLib::SizedArray do
37
37
 
38
38
  describe "::from" do
39
39
  describe "from a Ruby array" do
40
- it "creates a GLib::SizedArray with the same elements" do
41
- arr = GLib::SizedArray.from :gint32, 3, [3, 2, 1]
42
- arr.must_be_instance_of GLib::SizedArray
40
+ it "creates a GirFFI::SizedArray with the same elements" do
41
+ arr = GirFFI::SizedArray.from :gint32, 3, [3, 2, 1]
42
+ arr.must_be_instance_of GirFFI::SizedArray
43
43
  assert_equal [3, 2, 1], arr.to_a
44
44
  end
45
45
 
46
46
  it "raises an error if the array has the wrong number of elements" do
47
- lambda { GLib::SizedArray.from :gint32, 4, [3, 2, 1] }.must_raise ArgumentError
47
+ lambda { GirFFI::SizedArray.from :gint32, 4, [3, 2, 1] }.must_raise ArgumentError
48
48
  end
49
49
 
50
50
  it "uses the array's size if passed -1 as the size" do
51
- arr = GLib::SizedArray.from :gint32, -1, [3, 2, 1]
51
+ arr = GirFFI::SizedArray.from :gint32, -1, [3, 2, 1]
52
52
  arr.size.must_equal 3
53
53
  end
54
54
  end
55
55
 
56
- describe "from a GLib::SizedArray" do
56
+ describe "from a GirFFI::SizedArray" do
57
57
  it "return its argument" do
58
- arr = GLib::SizedArray.from :gint32, 3, [3, 2, 1]
59
- arr2 = GLib::SizedArray.from :gint32, 3, arr
58
+ arr = GirFFI::SizedArray.from :gint32, 3, [3, 2, 1]
59
+ arr2 = GirFFI::SizedArray.from :gint32, 3, arr
60
60
  assert_equal arr, arr2
61
61
  end
62
62
 
63
63
  it "raises an error if the argument has the wrong number of elements" do
64
- arr = GLib::SizedArray.from :gint32, 3, [3, 2, 1]
65
- lambda { GLib::SizedArray.from :gint32, 4, arr }.must_raise ArgumentError
64
+ arr = GirFFI::SizedArray.from :gint32, 3, [3, 2, 1]
65
+ lambda { GirFFI::SizedArray.from :gint32, 4, arr }.must_raise ArgumentError
66
66
  end
67
67
  end
68
68
 
69
69
  it "returns nil when passed nil" do
70
- arr = GLib::SizedArray.from :gint32, 0, nil
70
+ arr = GirFFI::SizedArray.from :gint32, 0, nil
71
71
  arr.must_be_nil
72
72
  end
73
73
 
74
74
  it "wraps its argument if given a pointer" do
75
- arr = GLib::SizedArray.from :gint32, 3, [3, 2, 1]
76
- arr2 = GLib::SizedArray.from :gint32, 3, arr.to_ptr
77
- assert_instance_of GLib::SizedArray, arr2
75
+ arr = GirFFI::SizedArray.from :gint32, 3, [3, 2, 1]
76
+ arr2 = GirFFI::SizedArray.from :gint32, 3, arr.to_ptr
77
+ assert_instance_of GirFFI::SizedArray, arr2
78
78
  refute arr2.equal? arr
79
79
  arr2.to_ptr.must_equal arr.to_ptr
80
80
  end
@@ -82,33 +82,33 @@ describe GLib::SizedArray do
82
82
 
83
83
  describe "#==" do
84
84
  it "returns true when comparing to an array with the same elements" do
85
- sized = GLib::SizedArray.from :int32, 3, [1, 2, 3]
85
+ sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
86
86
 
87
87
  sized.must_be :==, [1, 2, 3]
88
88
  end
89
89
 
90
90
  it "returns false when comparing to an array with different elements" do
91
- sized = GLib::SizedArray.from :int32, 3, [1, 2, 3]
91
+ sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
92
92
 
93
93
  sized.wont_be :==, [1, 2]
94
94
  end
95
95
 
96
96
  it "returns true when comparing to a sized array with the same elements" do
97
- sized = GLib::SizedArray.from :int32, 3, [1, 2, 3]
98
- other = GLib::SizedArray.from :int32, 3, [1, 2, 3]
97
+ sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
98
+ other = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
99
99
 
100
100
  sized.must_be :==, other
101
101
  end
102
102
 
103
103
  it "returns false when comparing to a sized array with different elements" do
104
- sized = GLib::SizedArray.from :int32, 3, [1, 2, 3]
105
- other = GLib::SizedArray.from :int32, 2, [1, 2]
104
+ sized = GirFFI::SizedArray.from :int32, 3, [1, 2, 3]
105
+ other = GirFFI::SizedArray.from :int32, 2, [1, 2]
106
106
 
107
107
  sized.wont_be :==, other
108
108
  end
109
109
  end
110
110
 
111
111
  it "includes Enumerable" do
112
- GLib::SizedArray.must_include Enumerable
112
+ GirFFI::SizedArray.must_include Enumerable
113
113
  end
114
114
  end
@@ -4,7 +4,7 @@ describe GirFFI::TypeMap do
4
4
  describe ".type_specification_to_ffitype" do
5
5
  it "returns the nested FFI::Enum for an Enum module" do
6
6
  GirFFI::TypeMap.type_specification_to_ffitype(GLib::DateMonth).
7
- must_equal GLib::DateMonth::Enum
7
+ must_equal GLib::DateMonth
8
8
  end
9
9
 
10
10
  it "returns the class itself for a Struct class" do
@@ -19,16 +19,48 @@ describe GirFFI::UserDefinedTypeInfo do
19
19
  end
20
20
  end
21
21
 
22
+ describe "#install_vfunc_implementation" do
23
+ let(:info) { GirFFI::UserDefinedTypeInfo.new :some_class }
24
+ let(:implementation) { Object.new }
25
+
26
+ it "adds to the list of vfunc implementations" do
27
+ info.vfunc_implementations.must_equal []
28
+ info.install_vfunc_implementation :foo, implementation
29
+ info.vfunc_implementations.map(&:name).must_equal [:foo]
30
+ end
31
+
32
+ it "stores the passed-in implementation in the implementation object" do
33
+ info.install_vfunc_implementation :foo, implementation
34
+ impl = info.vfunc_implementations.first
35
+ impl.implementation.must_equal implementation
36
+ end
37
+ end
38
+
22
39
  describe "#initialize" do
23
- it "takes a block that is evaluated in the context of the instance" do
40
+ it "yields the new object to the block passed" do
24
41
  mock(foo_spec = Object.new).get_name { :foo }
25
42
  mock(bar_spec = Object.new).get_name { :bar }
26
43
 
27
- info = GirFFI::UserDefinedTypeInfo.new :some_class do
28
- install_property foo_spec
29
- install_property bar_spec
44
+ info = GirFFI::UserDefinedTypeInfo.new :some_class do |inf|
45
+ inf.install_property foo_spec
46
+ inf.install_property bar_spec
30
47
  end
31
48
  info.properties.map(&:name).must_equal [:foo, :bar]
32
49
  end
33
50
  end
51
+
52
+ describe "#g_name" do
53
+ it "returns the described class' name by default" do
54
+ mock(klass = Object.new).name { "foo" }
55
+ info = GirFFI::UserDefinedTypeInfo.new klass
56
+ info.g_name.must_equal "foo"
57
+ end
58
+
59
+ it "returns the the name set by #g_name= if present" do
60
+ stub(klass = Object.new).name { "foo" }
61
+ info = GirFFI::UserDefinedTypeInfo.new klass
62
+ info.g_name = "bar"
63
+ info.g_name.must_equal "bar"
64
+ end
65
+ end
34
66
  end