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,5 +1,5 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
- describe GirFFI::BaseArgumentBuilder do
3
+ describe GirFFI::Builders::BaseArgumentBuilder do
4
4
  end
5
5
 
@@ -8,10 +8,12 @@ describe GirFFI::Builders::CallbackBuilder do
8
8
  let(:callback_info) { get_introspection_data "Regress", "TestCallbackFull" }
9
9
  it "returns a valid mapping method" do
10
10
  expected = <<-CODE.reset_indentation
11
- def self.call_with_argument_mapping(_proc, _v1, _v2, _v3)
12
- _v4 = _v3.to_utf8
13
- _v5 = _proc.call(_v1, _v2, _v4)
14
- return _v5
11
+ def self.call_with_argument_mapping(_proc, foo, bar, path)
12
+ _v1 = foo
13
+ _v2 = bar
14
+ _v3 = path.to_utf8
15
+ _v4 = _proc.call(_v1, _v2, _v3)
16
+ return _v4
15
17
  end
16
18
  CODE
17
19
 
@@ -36,10 +38,26 @@ describe GirFFI::Builders::CallbackBuilder do
36
38
  let(:callback_info) { get_introspection_data "Regress", "TestCallbackUserData" }
37
39
  it "returns a valid mapping method" do
38
40
  expected = <<-CODE.reset_indentation
39
- def self.call_with_argument_mapping(_proc, _v1)
40
- _v2 = GirFFI::ArgHelper::OBJECT_STORE[_v1.address]
41
- _v3 = _proc.call(_v2)
42
- return _v3
41
+ def self.call_with_argument_mapping(_proc, user_data)
42
+ _v1 = GirFFI::ArgHelper::OBJECT_STORE[user_data.address]
43
+ _v2 = _proc.call(_v1)
44
+ return _v2
45
+ end
46
+ CODE
47
+
48
+ builder.mapping_method_definition.must_equal expected
49
+ end
50
+ end
51
+
52
+ describe "for a callback with one out argument" do
53
+ let(:callback_info) { get_introspection_data("GIMarshallingTests",
54
+ "CallbackOneOutParameter") }
55
+ it "returns a valid mapping method" do
56
+ expected = <<-CODE.reset_indentation
57
+ def self.call_with_argument_mapping(_proc, a)
58
+ _v1 = GirFFI::InOutPointer.new(:gfloat, a)
59
+ _v2 = _proc.call()
60
+ _v1.set_value _v2
43
61
  end
44
62
  CODE
45
63
 
@@ -39,7 +39,7 @@ describe GirFFI::Builders::FieldBuilder do
39
39
  _v1 = @struct.to_ptr + #{field_info.offset}
40
40
  _v2 = GirFFI::InOutPointer.new(Regress::TestSimpleBoxedA, _v1)
41
41
  _v3 = _v2.to_value
42
- _v4 = ::Regress::TestSimpleBoxedA.wrap(_v3)
42
+ _v4 = Regress::TestSimpleBoxedA.wrap(_v3)
43
43
  _v4
44
44
  end
45
45
  CODE
@@ -71,7 +71,7 @@ describe GirFFI::Builders::FieldBuilder do
71
71
  _v1 = @struct.to_ptr + #{field_info.offset}
72
72
  _v2 = GirFFI::InOutPointer.new(:c, _v1)
73
73
  _v3 = _v2.to_value
74
- _v4 = GLib::SizedArray.wrap(Regress::TestStructE__some_union__union, 2, _v3)
74
+ _v4 = GirFFI::SizedArray.wrap(Regress::TestStructE__some_union__union, 2, _v3)
75
75
  _v4
76
76
  end
77
77
  CODE
@@ -84,7 +84,22 @@ describe GirFFI::Builders::FieldBuilder do
84
84
  _v1 = @struct.to_ptr + #{field_info.offset}
85
85
  _v2 = GirFFI::InOutPointer.new(:c, _v1)
86
86
  GirFFI::ArgHelper.check_fixed_array_size 2, value, \"value\"
87
- _v3 = GLib::SizedArray.from(Regress::TestStructE__some_union__union, 2, value)
87
+ _v3 = GirFFI::SizedArray.from(Regress::TestStructE__some_union__union, 2, value)
88
+ _v2.set_value _v3
89
+ end
90
+ CODE
91
+ instance.setter_def.must_equal expected
92
+ end
93
+ end
94
+
95
+ describe "for a field of type :callback" do
96
+ let(:field_info) { get_field_introspection_data "GObject", "TypeInfo", "class_init" }
97
+ it "creates the right setter method" do
98
+ expected = <<-CODE.reset_indentation
99
+ def class_init= value
100
+ _v1 = @struct.to_ptr + #{field_info.offset}
101
+ _v2 = GirFFI::InOutPointer.new(GObject::ClassInitFunc, _v1)
102
+ _v3 = GObject::ClassInitFunc.from(value)
88
103
  _v2.set_value _v3
89
104
  end
90
105
  CODE
@@ -11,7 +11,7 @@ describe GirFFI::Builders::FunctionBuilder do
11
11
  def self.test_array_fixed_out_objects
12
12
  _v1 = GirFFI::InOutPointer.for [:pointer, :c]
13
13
  Regress::Lib.regress_test_array_fixed_out_objects _v1
14
- _v2 = GLib::SizedArray.wrap([:pointer, Regress::TestObj], 2, _v1.to_value)
14
+ _v2 = GirFFI::SizedArray.wrap([:pointer, Regress::TestObj], 2, _v1.to_value)
15
15
  return _v2
16
16
  end
17
17
  CODE
@@ -28,7 +28,7 @@ describe GirFFI::Builders::FunctionBuilder do
28
28
  def self.test_array_gint16_in ints
29
29
  n_ints = ints.nil? ? 0 : ints.length
30
30
  _v1 = n_ints
31
- _v2 = GLib::SizedArray.from(:gint16, -1, ints)
31
+ _v2 = GirFFI::SizedArray.from(:gint16, -1, ints)
32
32
  _v3 = Regress::Lib.regress_test_array_gint16_in _v1, _v2
33
33
  return _v3
34
34
  end
@@ -44,9 +44,9 @@ describe GirFFI::Builders::FunctionBuilder do
44
44
 
45
45
  expected = <<-CODE
46
46
  def self.test_callback_destroy_notify callback, user_data, notify
47
- _v1 = ::Regress::TestCallbackUserData.from(callback)
48
- _v2 = GirFFI::InPointer.from(:void, user_data)
49
- _v3 = ::GLib::DestroyNotify.from(notify)
47
+ _v1 = Regress::TestCallbackUserData.from(callback)
48
+ _v2 = GirFFI::InPointer.from_closure_data(user_data)
49
+ _v3 = GLib::DestroyNotify.from(notify)
50
50
  _v4 = Regress::Lib.regress_test_callback_destroy_notify _v1, _v2, _v3
51
51
  return _v4
52
52
  end
@@ -81,7 +81,7 @@ describe GirFFI::Builders::FunctionBuilder do
81
81
 
82
82
  expected = <<-CODE
83
83
  def self.gvalue_in value
84
- _v1 = ::GObject::Value.from(value)
84
+ _v1 = GObject::Value.from(value)
85
85
  GIMarshallingTests::Lib.gi_marshalling_tests_gvalue_in _v1
86
86
  end
87
87
  CODE
@@ -96,7 +96,7 @@ describe GirFFI::Builders::FunctionBuilder do
96
96
 
97
97
  expected = <<-CODE
98
98
  def self.test_array_int_null_in arr
99
- _v1 = GLib::SizedArray.from(:gint32, -1, arr)
99
+ _v1 = GirFFI::SizedArray.from(:gint32, -1, arr)
100
100
  len = arr.nil? ? 0 : arr.length
101
101
  _v2 = len
102
102
  Regress::Lib.regress_test_array_int_null_in _v1, _v2
@@ -117,7 +117,7 @@ describe GirFFI::Builders::FunctionBuilder do
117
117
  _v2 = GirFFI::InOutPointer.for :gint32
118
118
  Regress::Lib.regress_test_array_int_null_out _v1, _v2
119
119
  _v3 = _v2.to_value
120
- _v4 = GLib::SizedArray.wrap(:gint32, _v3, _v1.to_value)
120
+ _v4 = GirFFI::SizedArray.wrap(:gint32, _v3, _v1.to_value)
121
121
  return _v4
122
122
  end
123
123
  CODE
@@ -132,12 +132,14 @@ describe GirFFI::Builders::FunctionBuilder do
132
132
 
133
133
  expected = <<-CODE
134
134
  def method_array_inout ints
135
- _v1 = GirFFI::InOutPointer.from [:pointer, :c], GLib::SizedArray.from(:gint32, -1, ints)
135
+ _v1 = GirFFI::InOutPointer.for [:pointer, :c]
136
+ _v1.set_value GirFFI::SizedArray.from(:gint32, -1, ints)
136
137
  length = ints.nil? ? 0 : ints.length
137
- _v2 = GirFFI::InOutPointer.from :gint32, length
138
+ _v2 = GirFFI::InOutPointer.for :gint32
139
+ _v2.set_value length
138
140
  GIMarshallingTests::Lib.gi_marshalling_tests_object_method_array_inout self, _v1, _v2
139
141
  _v3 = _v2.to_value
140
- _v4 = GLib::SizedArray.wrap(:gint32, _v3, _v1.to_value)
142
+ _v4 = GirFFI::SizedArray.wrap(:gint32, _v3, _v1.to_value)
141
143
  return _v4
142
144
  end
143
145
  CODE
@@ -169,7 +171,7 @@ describe GirFFI::Builders::FunctionBuilder do
169
171
  it "builds a correct definition" do
170
172
  code.must_equal <<-CODE.reset_indentation
171
173
  def get_strv
172
- _v1 = nil
174
+ _v1 = GirFFI::InOutPointer.for :guint64
173
175
  _v2 = GLib::Lib.g_variant_get_strv self, _v1
174
176
  _v3 = GLib::Strv.wrap(_v2)
175
177
  return _v3
@@ -177,5 +179,21 @@ describe GirFFI::Builders::FunctionBuilder do
177
179
  CODE
178
180
  end
179
181
  end
182
+
183
+ describe "for Regress.has_parameter_named_attrs" do
184
+ let(:function_info) {get_introspection_data 'Regress', 'has_parameter_named_attrs' }
185
+
186
+ it "builds a correct definition" do
187
+ skip unless function_info
188
+ code.must_equal <<-CODE.reset_indentation
189
+ def self.has_parameter_named_attrs foo, attributes
190
+ _v1 = foo
191
+ GirFFI::ArgHelper.check_fixed_array_size 32, attributes, \"attributes\"
192
+ _v2 = GirFFI::SizedArray.from([:pointer, :guint32], 32, attributes)
193
+ Regress::Lib.regress_has_parameter_named_attrs _v1, _v2
194
+ end
195
+ CODE
196
+ end
197
+ end
180
198
  end
181
199
  end
@@ -1,6 +1,9 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GirFFI::Builders::InterfaceBuilder do
4
+ let(:interface_builder) { GirFFI::Builders::InterfaceBuilder.new(
5
+ get_introspection_data('Regress', 'TestInterface')) }
6
+
4
7
  describe "#build_class" do
5
8
  before do
6
9
  info = get_introspection_data 'GObject', 'TypePlugin'
@@ -16,4 +19,10 @@ describe GirFFI::Builders::InterfaceBuilder do
16
19
  assert_defines_instance_method @iface, :complete_interface_info
17
20
  end
18
21
  end
22
+
23
+ describe "#interface_struct" do
24
+ it "returns the interface struct type" do
25
+ interface_builder.interface_struct.must_equal Regress::TestInterfaceIface
26
+ end
27
+ end
19
28
  end
@@ -1,45 +1,6 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GirFFI::Builders::ModuleBuilder do
4
- describe "#function_definition" do
5
- it "delegates to GirFFI::Builders::FunctionBuilder#generate" do
6
- builder = GirFFI::Builders::ModuleBuilder.new "Foo"
7
-
8
- mock(fb = Object.new).generate { "function body" }
9
- mock(GirFFI::Builders::FunctionBuilder).new("info") { fb }
10
-
11
- result = builder.send :function_definition, "info"
12
-
13
- assert_equal "function body", result
14
- end
15
- end
16
-
17
- describe "#sub_builder" do
18
- describe "for a :function argument" do
19
- it "creates a GirFFI::Builders::FunctionBuilder object" do
20
- builder = GirFFI::Builders::ModuleBuilder.new "Foo"
21
-
22
- stub(info = Object.new).info_type { :function }
23
-
24
- result = builder.send :sub_builder, info
25
- assert_instance_of GirFFI::Builders::FunctionBuilder, result
26
- end
27
- end
28
-
29
- describe "for an :object argument" do
30
- it "creates a GirFFI::Builders::ObjectBuilder object" do
31
- builder = GirFFI::Builders::ModuleBuilder.new "Foo"
32
-
33
- stub(info = Object.new).info_type { :object }
34
- stub(info).namespace { "Foo" }
35
- stub(info).safe_name { "FooClass" }
36
-
37
- result = builder.send :sub_builder, info
38
- assert_instance_of GirFFI::Builders::ObjectBuilder, result
39
- end
40
- end
41
- end
42
-
43
4
  describe "#build_namespaced_class" do
44
5
  it "raises a clear error if the named class does not exist" do
45
6
  gir = GObjectIntrospection::IRepository.default
@@ -1,61 +1,61 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GirFFI::Builders::ObjectBuilder do
4
+ let(:obj_builder) { GirFFI::Builders::ObjectBuilder.new(
5
+ get_introspection_data('Regress', 'TestObj')) }
6
+ let(:sub_obj_builder) { GirFFI::Builders::ObjectBuilder.new(
7
+ get_introspection_data('Regress', 'TestSubObj')) }
8
+
4
9
  describe '#find_signal' do
5
10
  it 'finds the signal "test" for TestObj' do
6
- builder = GirFFI::Builders::ObjectBuilder.new get_introspection_data('Regress', 'TestObj')
7
- sig = builder.find_signal 'test'
8
- assert_equal 'test', sig.name
11
+ sig = obj_builder.find_signal 'test'
12
+ sig.name.must_equal 'test'
9
13
  end
10
14
 
11
15
  it 'finds the signal "test" for TestSubObj' do
12
- builder = GirFFI::Builders::ObjectBuilder.new get_introspection_data('Regress', 'TestSubObj')
13
- sig = builder.find_signal 'test'
14
- assert_equal 'test', sig.name
16
+ sig = sub_obj_builder.find_signal 'test'
17
+ sig.name.must_equal 'test'
15
18
  end
16
19
 
17
20
  it 'finds the signal "changed" for Gtk::Entry' do
18
21
  builder = GirFFI::Builders::ObjectBuilder.new get_introspection_data('Gtk', 'Entry')
19
22
  sig = builder.find_signal 'changed'
20
- assert_equal 'changed', sig.name
23
+ sig.name.must_equal 'changed'
21
24
  end
22
25
  end
23
26
 
24
27
  describe "#find_property" do
25
28
  it "finds a property specified on the class itself" do
26
- builder = GirFFI::Builders::ObjectBuilder.new(
27
- get_introspection_data('Regress', 'TestObj'))
28
- prop = builder.find_property("int")
29
- assert_equal "int", prop.name
29
+ prop = obj_builder.find_property("int")
30
+ prop.name.must_equal "int"
30
31
  end
31
32
 
32
33
  it "finds a property specified on the parent class" do
33
- builder = GirFFI::Builders::ObjectBuilder.new(
34
- get_introspection_data('Regress', 'TestSubObj'))
35
- prop = builder.find_property("int")
36
- assert_equal "int", prop.name
34
+ prop = sub_obj_builder.find_property("int")
35
+ prop.name.must_equal "int"
37
36
  end
38
37
 
39
38
  it "raises an error if the property is not found" do
40
- builder = GirFFI::Builders::ObjectBuilder.new(
41
- get_introspection_data('Regress', 'TestSubObj'))
42
- assert_raises RuntimeError do
43
- builder.find_property("this-property-does-not-exist")
44
- end
39
+ proc {
40
+ sub_obj_builder.find_property("this-property-does-not-exist")
41
+ }.must_raise RuntimeError
45
42
  end
46
43
  end
47
44
 
48
45
  describe "#function_definition" do
49
- before do
50
- @cbuilder = GirFFI::Builders::ObjectBuilder.new get_introspection_data('Regress', 'TestObj')
51
- @go = get_method_introspection_data 'Regress', 'TestObj', 'instance_method'
52
- end
46
+ let(:method_info) {
47
+ get_method_introspection_data 'Regress', 'TestObj', 'instance_method' }
53
48
 
54
49
  it "delegates definition to FunctionBuilder" do
55
- code = @cbuilder.send :function_definition, @go
56
- expected = GirFFI::Builders::FunctionBuilder.new(@go).generate
57
- assert_equal cws(expected), cws(code)
50
+ code = obj_builder.send :function_definition, method_info
51
+ expected = GirFFI::Builders::FunctionBuilder.new(method_info).generate
52
+ code.must_equal expected
58
53
  end
54
+ end
59
55
 
56
+ describe "#object_class_struct" do
57
+ it "returns the class struct type" do
58
+ obj_builder.object_class_struct.must_equal Regress::TestObjClass
59
+ end
60
60
  end
61
61
  end
@@ -0,0 +1,110 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GirFFI::Builders::PropertyBuilder do
4
+ let(:builder) { GirFFI::Builders::PropertyBuilder.new property_info }
5
+
6
+ describe "for a property of type :glist" do
7
+ let(:property_info) { get_property_introspection_data("Regress", "TestObj", "list") }
8
+ it "generates the correct getter definition" do
9
+ expected = <<-CODE.reset_indentation
10
+ def list
11
+ _v1 = get_property("list").get_value_plain
12
+ _v2 = GLib::List.wrap(:utf8, _v1)
13
+ _v2
14
+ end
15
+ CODE
16
+
17
+ builder.getter_def.must_equal expected
18
+ end
19
+
20
+ it "generates the correct setter definition" do
21
+ expected = <<-CODE.reset_indentation
22
+ def list= value
23
+ _v1 = GLib::List.from(:utf8, value)
24
+ set_property("list", _v1)
25
+ end
26
+ CODE
27
+
28
+ builder.setter_def.must_equal expected
29
+ end
30
+ end
31
+
32
+ describe "for a property of type :ghash" do
33
+ let(:property_info) { get_property_introspection_data("Regress", "TestObj", "hash-table") }
34
+ it "generates the correct getter definition" do
35
+ expected = <<-CODE.reset_indentation
36
+ def hash_table
37
+ _v1 = get_property("hash-table").get_value_plain
38
+ _v2 = GLib::HashTable.wrap([:utf8, :gint8], _v1)
39
+ _v2
40
+ end
41
+ CODE
42
+
43
+ builder.getter_def.must_equal expected
44
+ end
45
+
46
+ it "generates the correct setter definition" do
47
+ expected = <<-CODE.reset_indentation
48
+ def hash_table= value
49
+ _v1 = GLib::HashTable.from([:utf8, :gint8], value)
50
+ set_property("hash-table", _v1)
51
+ end
52
+ CODE
53
+
54
+ builder.setter_def.must_equal expected
55
+ end
56
+ end
57
+
58
+ describe "for a property of type :strv" do
59
+ let(:property_info) { get_property_introspection_data("GIMarshallingTests",
60
+ "PropertiesObject",
61
+ "some-strv") }
62
+ before do
63
+ skip unless property_info
64
+ end
65
+
66
+ it "generates the correct getter definition" do
67
+ expected = <<-CODE.reset_indentation
68
+ def some_strv
69
+ get_property("some-strv").get_value
70
+ end
71
+ CODE
72
+
73
+ builder.getter_def.must_equal expected
74
+ end
75
+
76
+ it "generates the correct setter definition" do
77
+ expected = <<-CODE.reset_indentation
78
+ def some_strv= value
79
+ _v1 = GLib::Strv.from(value)
80
+ set_property("some-strv", _v1)
81
+ end
82
+ CODE
83
+
84
+ builder.setter_def.must_equal expected
85
+ end
86
+ end
87
+
88
+ describe "for a property of type :utf8" do
89
+ let(:property_info) { get_property_introspection_data("Regress", "TestObj", "string") }
90
+ it "generates the correct getter definition" do
91
+ expected = <<-CODE.reset_indentation
92
+ def string
93
+ get_property("string").get_value
94
+ end
95
+ CODE
96
+
97
+ builder.getter_def.must_equal expected
98
+ end
99
+
100
+ it "generates the correct setter definition" do
101
+ expected = <<-CODE.reset_indentation
102
+ def string= value
103
+ set_property("string", value)
104
+ end
105
+ CODE
106
+
107
+ builder.setter_def.must_equal expected
108
+ end
109
+ end
110
+ end