gir_ffi 0.6.7 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,10 +1,6 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
- describe "The generated GObject module" do
4
- before do
5
- GirFFI.setup :GObject
6
- end
7
-
3
+ describe GObject do
8
4
  describe "#type_interfaces" do
9
5
  it "works, showing that returning an array of GType works" do
10
6
  klass = GObject::TypeModule
@@ -13,7 +9,24 @@ describe "The generated GObject module" do
13
9
  end
14
10
  end
15
11
 
16
- describe "the TypePlugin interface" do
12
+ describe GObject::TypeInfo do
13
+ let(:instance) { GObject::TypeInfo.new }
14
+ it "has a working field setter for class_init" do
15
+ instance.class_init = proc do |object_class, data|
16
+ end
17
+ end
18
+
19
+ it "has a working field getter for class_init" do
20
+ instance.class_init.must_be_nil
21
+ instance.class_init = proc do |object_class, data|
22
+ end
23
+ result = instance.class_init
24
+ result.wont_be_nil
25
+ result.must_be_instance_of FFI::Function
26
+ end
27
+ end
28
+
29
+ describe GObject::TypePlugin do
17
30
  it "is implemented as a module" do
18
31
  mod = GObject::TypePlugin
19
32
  assert_instance_of Module, mod
@@ -21,14 +34,14 @@ describe "The generated GObject module" do
21
34
  end
22
35
  end
23
36
 
24
- describe "the TypeModule class" do
37
+ describe GObject::TypeModule do
25
38
  it "has the GObject::TypePlugin module as an ancestor" do
26
39
  klass = GObject::TypeModule
27
40
  assert_includes klass.ancestors, GObject::TypePlugin
28
41
  end
29
42
  end
30
43
 
31
- describe "the ValueArray struct class" do
44
+ describe GObject::ValueArray do
32
45
  it "uses the constructor provided by GObject" do
33
46
  instance = GObject::ValueArray.new 16
34
47
  instance.n_prealloced.must_equal 16
@@ -10,11 +10,11 @@ describe Pango do
10
10
  lang = Pango::Language.from_string 'ja'
11
11
  result = lang.get_scripts
12
12
 
13
- if GLib::SizedArray === result
13
+ if GirFFI::SizedArray === result
14
14
  scripts = result
15
15
  else
16
16
  ptr, size = *result
17
- scripts = GLib::SizedArray.new Pango::Script, size, ptr
17
+ scripts = GirFFI::SizedArray.new Pango::Script, size, ptr
18
18
  end
19
19
 
20
20
  scripts.must_be :==, [:han, :katakana, :hiragana]
@@ -3,17 +3,12 @@ require 'gir_ffi_test_helper'
3
3
 
4
4
  GirFFI.setup :Regress
5
5
 
6
- def get_field_value obj, field
7
- struct = obj.instance_variable_get :@struct
8
- struct[field]
9
- end
10
-
11
6
  # Tests generated methods and functions in the Regress namespace.
12
7
  describe Regress do
13
8
  describe Regress::Lib do
14
- it "extends GirFFI::Library" do
9
+ it "extends FFI::Library" do
15
10
  class << Regress::Lib
16
- self.must_be :include?, GirFFI::Library
11
+ self.must_be :include?, FFI::Library
17
12
  end
18
13
  end
19
14
  end
@@ -90,8 +85,7 @@ describe Regress do
90
85
  end
91
86
 
92
87
  it "has a writable field attributes" do
93
- skip "This does not work yet"
94
- instance.attributes
88
+ skip "Introspection data cannot deal with type of this field yet"
95
89
  end
96
90
 
97
91
  it "has a writable field dummy2" do
@@ -101,6 +95,27 @@ describe Regress do
101
95
  end
102
96
  end
103
97
 
98
+ describe "Regress::LikeXklConfigItem" do
99
+ before do
100
+ skip unless get_introspection_data 'Regress', 'LikeXklConfigItem'
101
+ end
102
+
103
+ let(:instance) { Regress::LikeXklConfigItem.new }
104
+ let(:name_array) { "foo".bytes.to_a + [0] * 29 }
105
+
106
+ it "has a writable field name" do
107
+ # TODO: Should an array of gint8 be more string-like?
108
+ instance.name.to_a.must_equal [0] * 32
109
+ instance.name = name_array
110
+ instance.name.to_a.must_equal name_array
111
+ end
112
+
113
+ it "has a working method #set_name" do
114
+ instance.set_name "foo"
115
+ instance.name.to_a.must_equal name_array
116
+ end
117
+ end
118
+
104
119
  it "has the constant MAXUINT64" do
105
120
  skip unless get_introspection_data 'Regress', 'MAXUINT64'
106
121
  Regress::MAXUINT64.must_equal 0xffff_ffff_ffff_ffff
@@ -431,7 +446,7 @@ describe Regress do
431
446
  GObject::Object
432
447
  end
433
448
 
434
- it "cannot be instanciated" do
449
+ it "cannot be instantiated" do
435
450
  proc { Regress::TestFundamentalObject.new }.must_raise NoMethodError
436
451
  end
437
452
 
@@ -575,9 +590,9 @@ describe Regress do
575
590
  end
576
591
 
577
592
  it "has a working method #emit_sig_with_int64" do
578
- skip "This does not work yet"
593
+ skip "FFI doesn't seem to convert the returned :int64 properly yet"
579
594
  instance.signal_connect "sig-with-int64-prop" do |obj, i, ud|
580
- int
595
+ i
581
596
  end
582
597
  instance.emit_sig_with_int64
583
598
  end
@@ -593,7 +608,7 @@ describe Regress do
593
608
  end
594
609
 
595
610
  it "has a working method #emit_sig_with_uint64" do
596
- skip "This does not work yet"
611
+ skip "FFI doesn't seem to convert the returned :int64 properly yet"
597
612
  instance.signal_connect "sig-with-uint64-prop" do |obj, i, ud|
598
613
  i
599
614
  end
@@ -693,7 +708,7 @@ describe Regress do
693
708
 
694
709
  describe "its 'bare' property" do
695
710
  it "can be retrieved with #get_property" do
696
- instance.get_property("bare").must_be_nil
711
+ instance.get_property("bare").get_value.must_be_nil
697
712
  end
698
713
 
699
714
  it "can be retrieved with #bare" do
@@ -703,7 +718,7 @@ describe Regress do
703
718
  it "can be set with #set_property" do
704
719
  obj = Regress::TestObj.new_from_file("bar")
705
720
  instance.set_property "bare", obj
706
- instance.get_property("bare").must_equal obj
721
+ instance.get_property("bare").get_value.must_equal obj
707
722
  end
708
723
 
709
724
  it "can be set with #bare=" do
@@ -711,13 +726,13 @@ describe Regress do
711
726
  instance.bare = obj
712
727
 
713
728
  instance.bare.must_equal obj
714
- instance.get_property("bare").must_equal obj
729
+ instance.get_property("bare").get_value.must_equal obj
715
730
  end
716
731
  end
717
732
 
718
733
  describe "its 'boxed' property" do
719
734
  it "can be retrieved with #get_property" do
720
- instance.get_property("boxed").must_be_nil
735
+ instance.get_property("boxed").get_value.must_be_nil
721
736
  end
722
737
 
723
738
  it "can be retrieved with #boxed" do
@@ -727,20 +742,20 @@ describe Regress do
727
742
  it "can be set with #set_property" do
728
743
  tb = Regress::TestBoxed.new_alternative_constructor1 75
729
744
  instance.set_property "boxed", tb
730
- instance.get_property("boxed").some_int8.must_equal 75
745
+ instance.get_property("boxed").get_value.some_int8.must_equal 75
731
746
  end
732
747
 
733
748
  it "can be set with #boxed=" do
734
749
  tb = Regress::TestBoxed.new_alternative_constructor1 75
735
750
  instance.boxed = tb
736
751
  instance.boxed.some_int8.must_equal tb.some_int8
737
- instance.get_property("boxed").some_int8.must_equal tb.some_int8
752
+ instance.get_property("boxed").get_value.some_int8.must_equal tb.some_int8
738
753
  end
739
754
  end
740
755
 
741
756
  describe "its 'double' property" do
742
757
  it "can be retrieved with #get_property" do
743
- instance.get_property("double").must_equal 0.0
758
+ instance.get_property("double").get_value.must_equal 0.0
744
759
  end
745
760
 
746
761
  it "can be retrieved with #double" do
@@ -749,19 +764,19 @@ describe Regress do
749
764
 
750
765
  it "can be set with #set_property" do
751
766
  instance.set_property "double", 3.14
752
- instance.get_property("double").must_equal 3.14
767
+ instance.get_property("double").get_value.must_equal 3.14
753
768
  end
754
769
 
755
770
  it "can be set with #double=" do
756
771
  instance.double = 3.14
757
772
  instance.double.must_equal 3.14
758
- instance.get_property("double").must_equal 3.14
773
+ instance.get_property("double").get_value.must_equal 3.14
759
774
  end
760
775
  end
761
776
 
762
777
  describe "its 'float' property" do
763
778
  it "can be retrieved with #get_property" do
764
- instance.get_property("float").must_equal 0.0
779
+ instance.get_property("float").get_value.must_equal 0.0
765
780
  end
766
781
 
767
782
  it "can be retrieved with #float" do
@@ -770,13 +785,13 @@ describe Regress do
770
785
 
771
786
  it "can be set with #set_property" do
772
787
  instance.set_property "float", 3.14
773
- instance.get_property("float").must_be_close_to 3.14
788
+ instance.get_property("float").get_value.must_be_close_to 3.14
774
789
  end
775
790
 
776
791
  it "can be set with #float=" do
777
792
  instance.float = 3.14
778
793
  instance.float.must_be_close_to 3.14
779
- instance.get_property("float").must_be_close_to 3.14
794
+ instance.get_property("float").get_value.must_be_close_to 3.14
780
795
  end
781
796
  end
782
797
 
@@ -786,7 +801,7 @@ describe Regress do
786
801
  end
787
802
 
788
803
  it "can be retrieved with #get_property" do
789
- instance.get_property("gtype").must_equal 0
804
+ instance.get_property("gtype").get_value.must_equal 0
790
805
  end
791
806
 
792
807
  it "can be retrieved with #gtype" do
@@ -795,69 +810,63 @@ describe Regress do
795
810
 
796
811
  it "can be set with #set_property" do
797
812
  instance.set_property "gtype", GObject::TYPE_INT64
798
- instance.get_property("gtype").must_equal GObject::TYPE_INT64
813
+ instance.get_property("gtype").get_value.must_equal GObject::TYPE_INT64
799
814
  end
800
815
 
801
816
  it "can be set with #gtype=" do
802
817
  instance.gtype = GObject::TYPE_STRING
803
818
  instance.gtype.must_equal GObject::TYPE_STRING
804
- instance.get_property("gtype").must_equal GObject::TYPE_STRING
819
+ instance.get_property("gtype").get_value.must_equal GObject::TYPE_STRING
805
820
  end
806
821
  end
807
822
 
808
823
  describe "its 'hash-table' property" do
809
824
  it "can be retrieved with #get_property" do
810
- instance.get_property("hash-table").must_be_nil
825
+ instance.get_property("hash-table").get_value.must_be_nil
811
826
  end
812
827
 
813
828
  it "can be retrieved with #hash_table" do
814
829
  instance.hash_table.must_be_nil
815
830
  end
816
831
 
817
- it "can be set with #set_property" do
818
- instance.set_property "hash-table", {"foo" => 34, "bar" => 83}
819
- instance.get_property("hash-table").to_hash.must_equal({"foo" => 34,
820
- "bar" => 83})
832
+ it "can be set with #set_property_extended" do
833
+ instance.set_property_extended "hash-table", {"foo" => -4, "bar" => 83}
834
+ instance.hash_table.to_hash.must_equal({"foo" => -4, "bar" => 83})
821
835
  end
822
836
 
823
837
  it "can be set with #hash_table=" do
824
- instance.set_property "hash-table", {"foo" => 34, "bar" => 83}
825
- instance.hash_table.to_hash.must_equal({"foo" => 34, "bar" => 83})
826
- instance.get_property("hash-table").to_hash.must_equal({"foo" => 34,
827
- "bar" => 83})
838
+ instance.hash_table = {"foo" => -4, "bar" => 83}
839
+ instance.hash_table.to_hash.must_equal({"foo" => -4, "bar" => 83})
840
+ instance.get_property_extended("hash-table").to_hash.must_equal({"foo" => -4,
841
+ "bar" => 83})
828
842
  end
829
843
  end
830
844
 
831
845
  describe "its 'hash-table-old' property" do
832
846
  it "can be retrieved with #get_property" do
833
- instance.get_property("hash-table-old").must_be_nil
847
+ instance.get_property("hash-table-old").get_value.must_be_nil
834
848
  end
835
849
 
836
850
  it "can be retrieved with #hash_table_old" do
837
851
  instance.hash_table_old.must_be_nil
838
852
  end
839
853
 
840
- it "can be set with #set_property" do
841
- instance.set_property "hash-table-old", {"foo" => 34,
842
- "bar" => 83}
843
-
844
- instance.get_property("hash-table-old").to_hash.must_equal({"foo" => 34,
845
- "bar" => 83})
854
+ it "can be set with #set_property_extended" do
855
+ instance.set_property_extended "hash-table-old", {"foo" => 34, "bar" => -3}
856
+ instance.hash_table_old.to_hash.must_equal({"foo" => 34, "bar" => -3})
846
857
  end
847
858
 
848
859
  it "can be set with #hash_table_old=" do
849
- instance.set_property "hash-table-old", {"foo" => 34,
850
- "bar" => 83}
851
-
852
- instance.hash_table_old.to_hash.must_equal({"foo" => 34, "bar" => 83})
853
- instance.get_property("hash-table-old").to_hash.must_equal({"foo" => 34,
854
- "bar" => 83})
860
+ instance.hash_table_old = {"foo" => 34, "bar" => -3}
861
+ instance.hash_table_old.to_hash.must_equal({"foo" => 34, "bar" => -3})
862
+ instance.get_property_extended("hash-table-old").to_hash.must_equal({"foo" => 34,
863
+ "bar" => -3})
855
864
  end
856
865
  end
857
866
 
858
867
  describe "its 'int' property" do
859
868
  it "can be retrieved with #get_property" do
860
- assert_equal 0, instance.get_property("int")
869
+ assert_equal 0, instance.get_property("int").get_value
861
870
  end
862
871
 
863
872
  it "can be retrieved with #int" do
@@ -866,61 +875,61 @@ describe Regress do
866
875
 
867
876
  it "can be set with #set_property" do
868
877
  instance.set_property "int", 42
869
- assert_equal 42, instance.get_property("int")
878
+ assert_equal 42, instance.get_property("int").get_value
870
879
  end
871
880
 
872
881
  it "can be set with #int=" do
873
882
  instance.int = 41
874
- assert_equal 41, instance.get_property("int")
883
+ assert_equal 41, instance.get_property("int").get_value
875
884
  assert_equal 41, instance.int
876
885
  end
877
886
  end
878
887
 
879
888
  describe "its 'list' property" do
880
- it "can be retrieved with #get_property" do
881
- instance.get_property("list").must_be_nil
889
+ it "can be retrieved with #get_property_extended" do
890
+ instance.get_property_extended("list").must_be_nil
882
891
  end
883
892
 
884
893
  it "can be retrieved with #list" do
885
894
  instance.list.must_be_nil
886
895
  end
887
896
 
888
- it "can be set with #set_property" do
889
- instance.set_property "list", ["foo", "bar"]
890
- instance.get_property("list").must_be :==, ["foo", "bar"]
897
+ it "can be set with #set_property_extended" do
898
+ instance.set_property_extended "list", ["foo", "bar"]
899
+ instance.list.to_a.must_equal ["foo", "bar"]
891
900
  end
892
901
 
893
902
  it "can be set with #list=" do
894
903
  instance.list = ["foo", "bar"]
895
- instance.list.must_be :==, ["foo", "bar"]
896
- instance.get_property("list").must_be :==, ["foo", "bar"]
904
+ instance.list.to_a.must_equal ["foo", "bar"]
905
+ instance.get_property_extended("list").must_be :==, ["foo", "bar"]
897
906
  end
898
907
  end
899
908
 
900
909
  describe "its 'list-old' property" do
901
910
  it "can be retrieved with #get_property" do
902
- instance.get_property("list-old").must_be_nil
911
+ instance.get_property_extended("list-old").must_be_nil
903
912
  end
904
913
 
905
914
  it "can be retrieved with #list_old" do
906
915
  instance.list_old.must_be_nil
907
916
  end
908
917
 
909
- it "can be set with #set_property" do
910
- instance.set_property "list-old", ["foo", "bar"]
911
- instance.get_property("list-old").must_be :==, ["foo", "bar"]
918
+ it "can be set with #set_property_extended" do
919
+ instance.set_property_extended "list-old", ["foo", "bar"]
920
+ instance.list_old.must_be :==, ["foo", "bar"]
912
921
  end
913
922
 
914
923
  it "can be set with #list_old=" do
915
924
  instance.list_old = ["foo", "bar"]
916
925
  instance.list_old.must_be :==, ["foo", "bar"]
917
- instance.get_property("list-old").must_be :==, ["foo", "bar"]
926
+ instance.get_property_extended("list-old").must_be :==, ["foo", "bar"]
918
927
  end
919
928
  end
920
929
 
921
930
  describe "its 'string' property" do
922
931
  it "can be retrieved with #get_property" do
923
- assert_nil instance.get_property("string")
932
+ assert_nil instance.get_property("string").get_value
924
933
  end
925
934
 
926
935
  it "can be retrieved with #string" do
@@ -929,13 +938,13 @@ describe Regress do
929
938
 
930
939
  it "can be set with #set_property" do
931
940
  instance.set_property "string", "foobar"
932
- assert_equal "foobar", instance.get_property("string")
941
+ assert_equal "foobar", instance.get_property("string").get_value
933
942
  end
934
943
 
935
944
  it "can be set with #string=" do
936
945
  instance.string = "foobar"
937
946
  assert_equal "foobar", instance.string
938
- assert_equal "foobar", instance.get_property("string")
947
+ assert_equal "foobar", instance.get_property("string").get_value
939
948
  end
940
949
  end
941
950
 
@@ -961,38 +970,130 @@ describe Regress do
961
970
  end
962
971
 
963
972
  it "handles the 'sig-with-array-len-prop' signal" do
964
- skip
973
+ skip unless get_signal_introspection_data "Regress", "TestObj", "sig-with-array-len-prop"
974
+
975
+ a = nil
976
+
977
+ GObject.signal_connect(instance, "sig-with-array-len-prop") do |obj, arr, user_data|
978
+ a = arr
979
+ end
980
+
981
+ arr = GirFFI::InPointer.from_array(:uint, [1, 2, 3])
982
+ GObject.signal_emit instance, "sig-with-array-len-prop", arr, 3
983
+
984
+ a.to_a.must_equal [1, 2, 3]
965
985
  end
966
986
 
967
987
  it "handles the 'sig-with-array-prop' signal" do
968
988
  a = nil
969
989
  GObject.signal_connect(instance, "sig-with-array-prop") {|_, arr, _| a = arr }
970
- # TODO: Automatically convert arguments to signal_emit.
971
990
  GObject.signal_emit instance, "sig-with-array-prop",
972
991
  GLib::Array.from(:uint, [1, 2, 3])
973
992
  a.to_a.must_equal [1, 2, 3]
974
993
  end
975
994
 
976
995
  it "handles the 'sig-with-foreign-struct' signal" do
977
- skip
996
+ skip unless get_signal_introspection_data "Regress", "TestObj", "sig-with-foreign-struct"
997
+
998
+ a = nil
999
+ instance.signal_connect "sig-with-foreign-struct" do |obj, ct|
1000
+ a = ct
1001
+ end
1002
+
1003
+ cairo_context = Regress.test_cairo_context_full_return
1004
+
1005
+ GObject.signal_emit instance, "sig-with-foreign-struct", cairo_context
1006
+
1007
+ a.must_be_instance_of Cairo::Context
1008
+ a.must_equal cairo_context
978
1009
  end
1010
+
979
1011
  it "handles the 'sig-with-hash-prop' signal" do
980
- skip
1012
+ a = nil
1013
+
1014
+ GObject.signal_connect(instance, "sig-with-hash-prop") do |_, ghash, _|
1015
+ a = ghash.to_hash
1016
+ end
1017
+
1018
+ g_hash_table = GLib::HashTable.from([:utf8, GObject::Value],
1019
+ {"foo" => GObject::Value.from("bar")})
1020
+
1021
+ GObject.signal_emit instance, "sig-with-hash-prop", g_hash_table
1022
+
1023
+ a["foo"].must_be_instance_of GObject::Value
1024
+ a["foo"].get_value.must_equal "bar"
981
1025
  end
1026
+
982
1027
  it "handles the 'sig-with-int64-prop' signal" do
983
- skip
1028
+ skip unless get_signal_introspection_data "Regress", "TestObj", "sig-with-int64-prop"
1029
+
1030
+ a = nil
1031
+
1032
+ GObject.signal_connect(instance, "sig-with-int64-prop") do |obj, int64, user_data|
1033
+ a = int64
1034
+ end
1035
+
1036
+ GObject.signal_emit instance, "sig-with-int64-prop", 0x7fffffffffffffff
1037
+
1038
+ a.must_equal 0x7fffffffffffffff
984
1039
  end
1040
+
985
1041
  it "handles the 'sig-with-intarray-ret' signal" do
986
- skip
1042
+ skip unless get_signal_introspection_data "Regress", "TestObj", "sig-with-intarray-ret"
1043
+
1044
+ a = nil
1045
+
1046
+ GObject.signal_connect(instance, "sig-with-intarray-ret") do |_, i, _|
1047
+ a = i
1048
+ [3, 2, 1]
1049
+ end
1050
+
1051
+ result = GObject.signal_emit instance, "sig-with-intarray-ret", 3
1052
+
1053
+ a.must_equal 3
1054
+
1055
+ # We would expect result to contain the int array, but regress.c uses the
1056
+ # wrong marshalling function
1057
+ result.get_value.must_be_nil
987
1058
  end
1059
+
988
1060
  it "handles the 'sig-with-obj' signal" do
989
- skip
1061
+ a = nil
1062
+
1063
+ GObject.signal_connect(instance, "sig-with-obj") do |_, obj, _|
1064
+ a = obj
1065
+ end
1066
+
1067
+ object = Regress::TestObj.constructor
1068
+ GObject.signal_emit instance, "sig-with-obj", object
1069
+
1070
+ a.must_equal object
990
1071
  end
1072
+
991
1073
  it "handles the 'sig-with-strv' signal" do
992
- skip
1074
+ a = nil
1075
+
1076
+ GObject.signal_connect(instance, "sig-with-strv") do |_, strs, _|
1077
+ a = strs
1078
+ end
1079
+
1080
+ GObject.signal_emit instance, "sig-with-strv", GLib::Strv.from(["foo", "bar"])
1081
+
1082
+ a.to_a.must_equal ["foo", "bar"]
993
1083
  end
1084
+
994
1085
  it "handles the 'sig-with-uint64-prop' signal" do
995
- skip
1086
+ skip unless get_signal_introspection_data "Regress", "TestObj", "sig-with-uint64-prop"
1087
+
1088
+ a = nil
1089
+
1090
+ GObject.signal_connect(instance, "sig-with-uint64-prop") do |_, uint64, _|
1091
+ a = uint64
1092
+ end
1093
+
1094
+ GObject.signal_emit instance, "sig-with-uint64-prop", 0xffffffffffffffff
1095
+
1096
+ a.must_equal 0xffffffffffffffff
996
1097
  end
997
1098
 
998
1099
  it "handles the 'test' signal" do
@@ -1002,8 +1103,19 @@ describe Regress do
1002
1103
  GObject.signal_emit o, "test"
1003
1104
  assert_equal [2, o], [a, b]
1004
1105
  end
1106
+
1005
1107
  it "handles the 'test-with-static-scope-arg' signal" do
1006
- skip
1108
+ a = nil
1109
+
1110
+ GObject.signal_connect(instance, "test-with-static-scope-arg") do |_, obj, _|
1111
+ a = obj
1112
+ end
1113
+
1114
+ arg = Regress::TestSimpleBoxedA.new
1115
+ arg.some_int = 12345
1116
+ GObject.signal_emit instance, "test-with-static-scope-arg", arg
1117
+
1118
+ a.some_int.must_equal 12345
1007
1119
  end
1008
1120
  end
1009
1121
 
@@ -1096,6 +1208,30 @@ describe Regress do
1096
1208
 
1097
1209
  let(:instance) { Regress::TestSimpleBoxedA.new }
1098
1210
 
1211
+ it "has a writable field some_int" do
1212
+ instance.some_int.must_equal 0
1213
+ instance.some_int = 42
1214
+ instance.some_int.must_equal 42
1215
+ end
1216
+
1217
+ it "has a writable field some_int8" do
1218
+ instance.some_int8.must_equal 0
1219
+ instance.some_int8 = 42
1220
+ instance.some_int8.must_equal 42
1221
+ end
1222
+
1223
+ it "has a writable field some_double" do
1224
+ instance.some_double.must_equal 0.0
1225
+ instance.some_double = 42.0
1226
+ instance.some_double.must_equal 42.0
1227
+ end
1228
+
1229
+ it "has a writable field some_enum" do
1230
+ instance.some_enum.must_equal :value1
1231
+ instance.some_enum = :value4
1232
+ instance.some_enum.must_equal :value4
1233
+ end
1234
+
1099
1235
  it "has a working method #copy" do
1100
1236
  instance.some_int = 4236
1101
1237
 
@@ -1273,6 +1409,20 @@ describe Regress do
1273
1409
  instance.field = o
1274
1410
  instance.field.must_equal o
1275
1411
  end
1412
+
1413
+ it "has a writable field list" do
1414
+ instance.list.must_be_nil
1415
+ o = Regress::TestSubObj.new
1416
+ instance.list = [o]
1417
+ instance.list.must_be :==, [o]
1418
+ end
1419
+
1420
+ it "has a writable field garray" do
1421
+ instance.garray.must_be_nil
1422
+ o = Regress::TestSubObj.new
1423
+ instance.garray = [o]
1424
+ instance.garray.must_be :==, [o]
1425
+ end
1276
1426
  end
1277
1427
 
1278
1428
  describe "Regress::TestStructE" do
@@ -1364,7 +1514,7 @@ describe Regress do
1364
1514
  it "has a writable field data1" do
1365
1515
  instance.data1.must_be :null?
1366
1516
  instance.data1 = GirFFI::InOutPointer.from(:gint32, 42)
1367
- instance.data1.read_int32.must_equal 42
1517
+ instance.data1.read_int.must_equal 42
1368
1518
  end
1369
1519
 
1370
1520
  it "has a writable field data2" do
@@ -1458,7 +1608,7 @@ describe Regress do
1458
1608
 
1459
1609
  describe "its 'testbool' property" do
1460
1610
  it "can be retrieved with #get_property" do
1461
- instance.get_property("testbool").must_equal true
1611
+ instance.get_property("testbool").get_value.must_equal true
1462
1612
  end
1463
1613
 
1464
1614
  it "can be retrieved with #testbool" do
@@ -1468,23 +1618,23 @@ describe Regress do
1468
1618
  it "can be set with #set_property" do
1469
1619
  instance.set_property "testbool", true
1470
1620
  instance.get_testbool.must_equal true
1471
- instance.get_property("testbool").must_equal true
1621
+ instance.get_property("testbool").get_value.must_equal true
1472
1622
 
1473
1623
  instance.set_property "testbool", false
1474
1624
  instance.get_testbool.must_equal false
1475
- instance.get_property("testbool").must_equal false
1625
+ instance.get_property("testbool").get_value.must_equal false
1476
1626
  end
1477
1627
 
1478
1628
  it "can be set with #testbool=" do
1479
1629
  instance.testbool = true
1480
1630
  instance.testbool.must_equal true
1481
1631
  instance.get_testbool.must_equal true
1482
- instance.get_property("testbool").must_equal true
1632
+ instance.get_property("testbool").get_value.must_equal true
1483
1633
 
1484
1634
  instance.testbool = false
1485
1635
  instance.testbool.must_equal false
1486
1636
  instance.get_testbool.must_equal false
1487
- instance.get_property("testbool").must_equal false
1637
+ instance.get_property("testbool").get_value.must_equal false
1488
1638
  end
1489
1639
  end
1490
1640
  end
@@ -1511,13 +1661,19 @@ describe Regress do
1511
1661
  end
1512
1662
 
1513
1663
  it "has a working function #global_get_flags_out" do
1514
- skip
1664
+ result = Regress.global_get_flags_out
1665
+ result.must_equal Regress::TestFlags[:flag1] | Regress::TestFlags[:flag3]
1515
1666
  end
1667
+
1516
1668
  it "has a working function #has_parameter_named_attrs" do
1517
- skip
1669
+ skip unless get_introspection_data 'Regress', 'has_parameter_named_attrs'
1670
+ Regress.has_parameter_named_attrs 42, [23] * 32
1671
+ pass
1518
1672
  end
1673
+
1519
1674
  it "has a working function #introspectable_via_alias" do
1520
- skip
1675
+ Regress.introspectable_via_alias []
1676
+ pass
1521
1677
  end
1522
1678
 
1523
1679
  it "has a working function #set_abort_on_error" do
@@ -1527,10 +1683,28 @@ describe Regress do
1527
1683
  end
1528
1684
 
1529
1685
  it "has a working function #test_abc_error_quark" do
1530
- skip
1686
+ skip unless get_introspection_data 'Regress', 'test_abc_error_quark'
1687
+
1688
+ quark = Regress.test_abc_error_quark
1689
+ GLib.quark_to_string(quark).must_equal "regress-test-abc-error"
1531
1690
  end
1691
+
1532
1692
  it "has a working function #test_array_callback" do
1533
- skip
1693
+ a = nil
1694
+ b = nil
1695
+ c = 95
1696
+
1697
+ callback = lambda do |one, two|
1698
+ a = one
1699
+ b = two
1700
+ c
1701
+ end
1702
+
1703
+ result = Regress.test_array_callback callback
1704
+
1705
+ result.must_equal 2 * c
1706
+ a.to_a.must_equal [-1, 0, 1, 2]
1707
+ b.to_a.must_equal ["one", "two", "three"]
1534
1708
  end
1535
1709
 
1536
1710
  it "has a working function #test_array_fixed_out_objects" do
@@ -1703,13 +1877,52 @@ describe Regress do
1703
1877
  end
1704
1878
 
1705
1879
  it "has a working function #test_callback_destroy_notify_no_user_data" do
1706
- skip
1880
+ skip unless get_introspection_data 'Regress', 'test_callback_destroy_notify_no_user_data'
1881
+
1882
+ callback_times_called = 0
1883
+ notify_times_called = 0
1884
+ b = :not_nil
1885
+
1886
+ callback = Proc.new {|user_data|
1887
+ callback_times_called += 1
1888
+ b = user_data
1889
+ callback_times_called * 5
1890
+ }
1891
+
1892
+ notify = Proc.new { notify_times_called += 1 }
1893
+
1894
+ result = Regress.test_callback_destroy_notify_no_user_data callback, notify
1895
+
1896
+ callback_times_called.must_equal 1
1897
+ notify_times_called.must_equal 0
1898
+ result.must_equal 5
1899
+ b.must_be_nil
1900
+
1901
+ result = Regress.test_callback_thaw_notifications
1902
+
1903
+ callback_times_called.must_equal 2
1904
+ notify_times_called.must_equal 1
1905
+ result.must_equal 10
1906
+ b.must_be_nil
1707
1907
  end
1908
+
1708
1909
  it "has a working function #test_callback_thaw_async" do
1709
- skip
1910
+ invoked = []
1911
+ Regress.test_callback_async Proc.new { invoked << 1; 1 }, nil
1912
+ Regress.test_callback_async Proc.new { invoked << 2; 2 }, nil
1913
+ Regress.test_callback_async Proc.new { invoked << 3; 3 }, nil
1914
+ result = Regress.test_callback_thaw_async
1915
+ invoked.must_equal [3, 2, 1]
1916
+ result.must_equal 1
1710
1917
  end
1918
+
1711
1919
  it "has a working function #test_callback_thaw_notifications" do
1712
- skip
1920
+ invoked = false
1921
+ Regress.test_callback_destroy_notify Proc.new { 42 }, nil, nil
1922
+ Regress.test_callback_destroy_notify Proc.new { 24 }, nil, Proc.new { invoked = true }
1923
+ result = Regress.test_callback_thaw_notifications
1924
+ result.must_equal 66
1925
+ invoked.must_equal true
1713
1926
  end
1714
1927
 
1715
1928
  it "has a working function #test_callback_user_data" do
@@ -1746,7 +1959,21 @@ describe Regress do
1746
1959
  end
1747
1960
 
1748
1961
  it "has a working function #test_closure_variant" do
1749
- skip
1962
+ skip "This causes a core dump on some systems"
1963
+ arg = GLib::Variant.new_string "foo"
1964
+ closure = GObject::RubyClosure.new do |variant|
1965
+ str = variant.get_string
1966
+ if str == "foo"
1967
+ GLib::Variant.new_int32 40
1968
+ else
1969
+ GLib::Variant.new_string "bar"
1970
+ end
1971
+ end
1972
+
1973
+ # TODO: Convert proc to RubyClosure automatically
1974
+ result = Regress.test_closure_variant closure, arg
1975
+
1976
+ result.get_int32.must_equal 40
1750
1977
  end
1751
1978
 
1752
1979
  it "has a working function #test_date_in_gvalue" do
@@ -1758,7 +1985,9 @@ describe Regress do
1758
1985
  end
1759
1986
 
1760
1987
  it "has a working function #test_def_error_quark" do
1761
- skip
1988
+ skip unless get_introspection_data 'Regress', 'test_def_error_quark'
1989
+ quark = Regress.test_def_error_quark
1990
+ GLib.quark_to_string(quark).must_equal "regress-test-def-error"
1762
1991
  end
1763
1992
 
1764
1993
  it "has a working function #test_double" do
@@ -1772,7 +2001,9 @@ describe Regress do
1772
2001
  end
1773
2002
 
1774
2003
  it "has a working function #test_error_quark" do
1775
- skip
2004
+ skip unless get_introspection_data 'Regress', 'test_error_quark'
2005
+ quark = Regress.test_error_quark
2006
+ GLib.quark_to_string(quark).must_equal "regress-test-error"
1776
2007
  end
1777
2008
 
1778
2009
  it "has a working function #test_filename_return" do
@@ -1796,10 +2027,14 @@ describe Regress do
1796
2027
  end
1797
2028
 
1798
2029
  it "has a working function #test_garray_full_return" do
1799
- skip
2030
+ result = Regress.test_garray_full_return
2031
+ result.to_a.must_equal ["regress"]
1800
2032
  end
2033
+
1801
2034
  it "has a working function #test_gerror_callback" do
1802
- skip
2035
+ result = nil
2036
+ Regress.test_gerror_callback Proc.new {|err| result = err.message }
2037
+ result.must_equal "regression test error"
1803
2038
  end
1804
2039
 
1805
2040
  it "has a working function #test_ghash_container_return" do
@@ -1818,16 +2053,41 @@ describe Regress do
1818
2053
  end
1819
2054
 
1820
2055
  it "has a working function #test_ghash_gvalue_in" do
1821
- skip
2056
+ skip unless get_introspection_data 'Regress', 'test_ghash_gvalue_in'
2057
+ skip unless get_introspection_data 'Regress', 'test_ghash_gvalue_return'
2058
+ hash_table = Regress.test_ghash_gvalue_return
2059
+ Regress.test_ghash_gvalue_in hash_table
1822
2060
  end
2061
+
1823
2062
  it "has a working function #test_ghash_gvalue_return" do
1824
- skip
2063
+ skip unless get_introspection_data 'Regress', 'test_ghash_gvalue_return'
2064
+ result = Regress.test_ghash_gvalue_return
2065
+ hash = result.to_hash
2066
+ hash["integer"].get_value.must_equal 12
2067
+ hash["boolean"].get_value.must_equal true
2068
+ hash["string"].get_value.must_equal "some text"
2069
+ hash["strings"].get_value.to_a.must_equal ["first", "second", "third"]
2070
+ hash["flags"].get_value.must_equal Regress::TestFlags[:flag1] | Regress::TestFlags[:flag3]
2071
+ hash["enum"].get_value.must_equal :value2
2072
+ hash.keys.sort.must_equal ["boolean", "enum", "flags", "integer", "string", "strings"]
1825
2073
  end
2074
+
1826
2075
  it "has a working function #test_ghash_nested_everything_return" do
1827
- skip
2076
+ result = Regress.test_ghash_nested_everything_return
2077
+ hash = result.to_hash
2078
+ hash.keys.must_equal ["wibble"]
2079
+ hash["wibble"].to_hash.must_equal({"foo" => "bar",
2080
+ "baz" => "bat",
2081
+ "qux" => "quux"})
1828
2082
  end
2083
+
1829
2084
  it "has a working function #test_ghash_nested_everything_return2" do
1830
- skip
2085
+ result = Regress.test_ghash_nested_everything_return2
2086
+ hash = result.to_hash
2087
+ hash.keys.must_equal ["wibble"]
2088
+ hash["wibble"].to_hash.must_equal({"foo" => "bar",
2089
+ "baz" => "bat",
2090
+ "qux" => "quux"})
1831
2091
  end
1832
2092
 
1833
2093
  it "has a working function #test_ghash_nothing_in" do