gir_ffi 0.5.2 → 0.6.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 (78) hide show
  1. data/History.txt +5 -0
  2. data/lib/ffi-glib/array.rb +2 -3
  3. data/lib/ffi-glib/container_class_methods.rb +3 -4
  4. data/lib/ffi-glib/hash_table.rb +7 -3
  5. data/lib/ffi-glib/list_methods.rb +1 -1
  6. data/lib/ffi-glib/sized_array.rb +66 -0
  7. data/lib/ffi-glib/strv.rb +1 -1
  8. data/lib/ffi-glib.rb +5 -4
  9. data/lib/ffi-gobject/object.rb +2 -3
  10. data/lib/ffi-gobject/ruby_closure.rb +3 -2
  11. data/lib/ffi-gobject/value.rb +26 -14
  12. data/lib/ffi-gobject.rb +8 -5
  13. data/lib/ffi-gobject_introspection/g_error.rb +1 -0
  14. data/lib/ffi-gobject_introspection/i_base_info.rb +3 -2
  15. data/lib/ffi-gobject_introspection/i_union_info.rb +21 -8
  16. data/lib/ffi-gobject_introspection/lib.rb +1 -0
  17. data/lib/gir_ffi/argument_builder.rb +8 -20
  18. data/lib/gir_ffi/base_argument_builder.rb +13 -30
  19. data/lib/gir_ffi/builder/module.rb +3 -9
  20. data/lib/gir_ffi/builder/type/base.rb +2 -0
  21. data/lib/gir_ffi/builder/type/callback.rb +2 -2
  22. data/lib/gir_ffi/builder/type/enum.rb +1 -0
  23. data/lib/gir_ffi/builder/type/object.rb +13 -3
  24. data/lib/gir_ffi/builder/type/registered_type.rb +1 -1
  25. data/lib/gir_ffi/builder/type/struct.rb +18 -3
  26. data/lib/gir_ffi/builder/type/unintrospectable.rb +5 -45
  27. data/lib/gir_ffi/builder/type/user_defined.rb +3 -15
  28. data/lib/gir_ffi/builder/type.rb +5 -5
  29. data/lib/gir_ffi/builder.rb +5 -80
  30. data/lib/gir_ffi/callback.rb +65 -2
  31. data/lib/gir_ffi/callback_helper.rb +0 -56
  32. data/lib/gir_ffi/class_base.rb +2 -2
  33. data/lib/gir_ffi/in_out_pointer.rb +7 -28
  34. data/lib/gir_ffi/in_pointer.rb +12 -19
  35. data/lib/gir_ffi/info_ext/i_arg_info.rb +5 -0
  36. data/lib/gir_ffi/info_ext/i_callable_info.rb +16 -0
  37. data/lib/gir_ffi/info_ext/i_function_info.rb +15 -0
  38. data/lib/gir_ffi/info_ext/i_signal_info.rb +17 -10
  39. data/lib/gir_ffi/info_ext/i_type_info.rb +63 -39
  40. data/lib/gir_ffi/info_ext.rb +5 -3
  41. data/lib/gir_ffi/null_argument_builder.rb +1 -1
  42. data/lib/gir_ffi/return_value_builder.rb +24 -16
  43. data/lib/gir_ffi/unintrospectable_type_info.rb +41 -0
  44. data/lib/gir_ffi/user_defined_property_info.rb +15 -0
  45. data/lib/gir_ffi/user_defined_type_info.rb +25 -0
  46. data/lib/gir_ffi/version.rb +1 -1
  47. data/lib/gir_ffi-base.rb +3 -0
  48. data/lib/gir_ffi.rb +2 -1
  49. data/test/ffi-glib/sized_array_test.rb +87 -0
  50. data/test/ffi-gobject_introspection/i_base_info_test.rb +4 -5
  51. data/test/gir_ffi/argument_builder_test.rb +26 -55
  52. data/test/gir_ffi/builder/type/unintrospectable_test.rb +3 -19
  53. data/test/gir_ffi/builder/type/user_defined_test.rb +16 -21
  54. data/test/gir_ffi/builder_test.rb +31 -53
  55. data/test/gir_ffi/callback_helper_test.rb +0 -47
  56. data/test/gir_ffi/callback_test.rb +49 -0
  57. data/test/gir_ffi/function_builder_test.rb +8 -8
  58. data/test/gir_ffi/in_out_pointer_test.rb +2 -53
  59. data/test/gir_ffi/in_pointer_test.rb +0 -13
  60. data/test/gir_ffi/info_ext/i_callable_info_test.rb +32 -0
  61. data/test/gir_ffi/info_ext/i_function_info_test.rb +61 -0
  62. data/test/gir_ffi/info_ext/i_signal_info_test.rb +7 -0
  63. data/test/gir_ffi/info_ext/i_type_info_test.rb +158 -77
  64. data/test/gir_ffi/return_value_builder_test.rb +2 -2
  65. data/test/gir_ffi/unintrospectable_type_info_test.rb +95 -0
  66. data/test/gir_ffi/user_defined_property_info_test.rb +19 -0
  67. data/test/gir_ffi/user_defined_type_info_test.rb +34 -0
  68. data/test/integration/generated_gimarshallingtests_test.rb +10 -10
  69. data/test/integration/generated_regress_test.rb +10 -10
  70. metadata +24 -15
  71. data/lib/gir_ffi/builder/type/struct_based.rb +0 -31
  72. data/lib/gir_ffi/user_defined/i_base_info.rb +0 -7
  73. data/lib/gir_ffi/user_defined/i_object_info.rb +0 -13
  74. data/lib/gir_ffi/user_defined/i_property_info.rb +0 -9
  75. data/lib/gir_ffi/user_defined/i_registered_type_info.rb +0 -10
  76. data/test/gir_ffi/user_defined/i_object_info_test.rb +0 -18
  77. data/test/gir_ffi/user_defined/i_property_info_test.rb +0 -14
  78. data/test/gir_ffi/user_defined/i_registered_type_info_test.rb +0 -10
@@ -27,45 +27,6 @@ describe GirFFI::InOutPointer do
27
27
  end
28
28
  end
29
29
 
30
- describe "an instance created with .from_array" do
31
- before do
32
- @result = GirFFI::InOutPointer.from_array :gint32, [24, 13]
33
- end
34
-
35
- it "holds a pointer to a non-null pointer" do
36
- ptr = @result.read_pointer
37
- refute ptr.null?
38
- end
39
-
40
- it "holds a pointer to a pointer to the correct input values" do
41
- ptr = @result.read_pointer
42
- assert_equal [24, 13], [ptr.get_int(0), ptr.get_int(4)]
43
- end
44
-
45
- it "is an instance of GirFFI::InPointer" do
46
- assert_instance_of GirFFI::InOutPointer, @result
47
- end
48
- end
49
-
50
- describe ".from_array" do
51
- it "returns nil when passed nil" do
52
- result = GirFFI::InOutPointer.from_array :gint32, nil
53
- assert_nil result
54
- end
55
- end
56
-
57
- describe "an instance created with .from_array :utf8" do
58
- before do
59
- @result = GirFFI::InOutPointer.from_array :utf8, ["foo", "bar", "baz"]
60
- end
61
-
62
- it "returns a pointer to an array of pointers to strings" do
63
- ptr = @result.read_pointer
64
- ary = ptr.read_array_of_pointer(3)
65
- assert_equal ["foo", "bar", "baz"], ary.map {|p| p.read_string}
66
- end
67
- end
68
-
69
30
  describe "in instance created with .for" do
70
31
  before do
71
32
  @result = GirFFI::InOutPointer.for :gint32
@@ -109,21 +70,9 @@ describe GirFFI::InOutPointer do
109
70
  end
110
71
 
111
72
  describe "for :utf8 values" do
112
- it "returns the held value" do
73
+ it "returns a pointer to the held value" do
113
74
  ptr = GirFFI::InOutPointer.from :utf8, "Some value"
114
- assert_equal "Some value", ptr.to_value
115
- end
116
- end
117
- end
118
-
119
- describe "#to_sized_array_value" do
120
- describe "for an array of :gint32" do
121
- before do
122
- @ptr = GirFFI::InOutPointer.from_array :gint32, [1, 2, 3]
123
- end
124
-
125
- it "returns an array of integers with the correct values" do
126
- assert_equal [1, 2, 3], @ptr.to_sized_array_value(3)
75
+ assert_equal "Some value", ptr.to_value.read_string
127
76
  end
128
77
  end
129
78
  end
@@ -13,24 +13,11 @@ describe GirFFI::InPointer do
13
13
  GirFFI::InPointer.from_array :GType, [2]
14
14
  end
15
15
 
16
- it "handles type tag :interface_pointer" do
17
- GirFFI::InPointer.from_array :interface_pointer, []
18
- end
19
-
20
16
  it "handles enum types" do
21
17
  e = FFI::Enum.new [:foo, :bar, :baz]
22
18
  ptr = GirFFI::InPointer.from_array e, [:bar, :foo, :baz]
23
19
  ptr.read_array_of_int32(3).must_equal [1, 0, 2]
24
20
  end
25
-
26
- it "handles typed pointers" do
27
- p1 = GirFFI::InPointer.from :gint32, 42
28
- p2 = GirFFI::InPointer.from :gint32, 24
29
-
30
- ptr = GirFFI::InPointer.from_array [:pointer, :uint32], [p1, p2]
31
-
32
- ptr.read_array_of_pointer(2).must_equal [p1, p2]
33
- end
34
21
  end
35
22
 
36
23
  describe "an instance created with .from_array :gint32" do
@@ -0,0 +1,32 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GirFFI::InfoExt::ICallableInfo do
4
+ let(:testclass) { Class.new do
5
+ include GirFFI::InfoExt::ICallableInfo
6
+ end }
7
+ let(:callable_info) { testclass.new }
8
+
9
+ describe "#argument_ffi_types" do
10
+ describe "for a simple callable with several arguments" do
11
+ before do
12
+ stub(arg_info1 = Object.new).to_ffitype { :type1 }
13
+ stub(arg_info2 = Object.new).to_ffitype { :type2 }
14
+ stub(callable_info).args { [arg_info1, arg_info2] }
15
+ end
16
+
17
+ it "returns the ffi types of the arguments" do
18
+ callable_info.argument_ffi_types.must_equal [:type1, :type2]
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "#return_ffi_type" do
24
+ it "returns the ffi type of the return type" do
25
+ stub(return_type_info = Object.new).to_ffitype { :some_type }
26
+ stub(callable_info).return_type { return_type_info }
27
+
28
+ callable_info.return_ffi_type.must_equal :some_type
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,61 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GirFFI::InfoExt::IFunctionInfo do
4
+ let(:testclass) { Class.new do
5
+ include GirFFI::InfoExt::ICallableInfo
6
+ include GirFFI::InfoExt::IFunctionInfo
7
+ end }
8
+ let(:function_info) { testclass.new }
9
+
10
+ describe "#argument_ffi_types" do
11
+ before do
12
+ stub(arg_info1 = Object.new).to_ffitype { :type1 }
13
+ stub(arg_info2 = Object.new).to_ffitype { :type2 }
14
+ stub(function_info).args { [arg_info1, arg_info2] }
15
+ end
16
+
17
+ describe "for a simple function with several arguments" do
18
+ before do
19
+ stub(function_info).method? { false }
20
+ stub(function_info).throws? { false }
21
+ end
22
+
23
+ it "returns the ffi types of the arguments" do
24
+ function_info.argument_ffi_types.must_equal [:type1, :type2]
25
+ end
26
+ end
27
+
28
+ describe "for a throwing function with several arguments" do
29
+ before do
30
+ stub(function_info).method? { false }
31
+ stub(function_info).throws? { true }
32
+ end
33
+
34
+ it "appends :pointer to represent the error argument" do
35
+ function_info.argument_ffi_types.must_equal [:type1, :type2, :pointer]
36
+ end
37
+ end
38
+
39
+ describe "for a method with several arguments" do
40
+ before do
41
+ stub(function_info).method? { true }
42
+ stub(function_info).throws? { false }
43
+ end
44
+
45
+ it "prepends :pointer to represent the method reciever" do
46
+ function_info.argument_ffi_types.must_equal [:pointer, :type1, :type2]
47
+ end
48
+ end
49
+
50
+ describe "for a throwing method with several arguments" do
51
+ before do
52
+ stub(function_info).method? { true }
53
+ stub(function_info).throws? { true }
54
+ end
55
+
56
+ it "adds :pointer for both the reciever and the error argument" do
57
+ function_info.argument_ffi_types.must_equal [:pointer, :type1, :type2, :pointer]
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,7 +1,13 @@
1
1
  require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GirFFI::InfoExt::ISignalInfo do
4
+ let(:testclass) { Class.new do
5
+ include GirFFI::InfoExt::ISignalInfo
6
+ end }
7
+ let(:signal_info) { testclass.new }
8
+
4
9
  describe "#cast_back_signal_arguments" do
10
+ # TODO: Move to integration tests
5
11
  it "correctly casts back pointers for the test-with-static-scope-arg signal" do
6
12
  o = Regress::TestSubObj.new
7
13
  b = Regress::TestSimpleBoxedA.new
@@ -22,6 +28,7 @@ describe GirFFI::InfoExt::ISignalInfo do
22
28
  end
23
29
 
24
30
  describe "#signal_arguments_to_gvalue_array" do
31
+ # TODO: Move to integration tests
25
32
  describe "the result of wrapping test-with-static-scope-arg" do
26
33
  setup do
27
34
  o = Regress::TestSubObj.new
@@ -11,12 +11,12 @@ describe GirFFI::InfoExt::ITypeInfo do
11
11
 
12
12
  describe "#layout_specification_type" do
13
13
  it "returns an array with elements subtype and size for type :array" do
14
- mock(elmtype_info).layout_specification_type { :foo }
15
-
14
+ mock(type_info).pointer? { false }
15
+ stub(type_info).tag { :array }
16
16
  mock(type_info).array_fixed_size { 2 }
17
- mock(type_info).param_type(0) { elmtype_info }
18
17
 
19
- mock(GirFFI::Builder).itypeinfo_to_ffitype(type_info) { :array }
18
+ mock(elmtype_info).layout_specification_type { :foo }
19
+ mock(type_info).param_type(0) { elmtype_info }
20
20
 
21
21
  result = type_info.layout_specification_type
22
22
  assert_equal [:foo, 2], result
@@ -26,6 +26,7 @@ describe GirFFI::InfoExt::ITypeInfo do
26
26
  describe "#element_type" do
27
27
  it "returns the element type for lists" do
28
28
  mock(elmtype_info).tag { :foo }
29
+ mock(elmtype_info).pointer? { false }
29
30
 
30
31
  mock(type_info).tag {:glist}
31
32
  mock(type_info).param_type(0) { elmtype_info }
@@ -36,7 +37,9 @@ describe GirFFI::InfoExt::ITypeInfo do
36
37
 
37
38
  it "returns the key and value types for ghashes" do
38
39
  mock(keytype_info).tag { :foo }
40
+ mock(keytype_info).pointer? { false }
39
41
  mock(valtype_info).tag { :bar }
42
+ mock(valtype_info).pointer? { false }
40
43
 
41
44
  mock(type_info).tag {:ghash}
42
45
  mock(type_info).param_type(0) { keytype_info }
@@ -53,138 +56,216 @@ describe GirFFI::InfoExt::ITypeInfo do
53
56
  result.must_be_nil
54
57
  end
55
58
 
56
- it "returns :gpointer if the element type is a pointer with tag :void" do
57
- stub(elm_type = Object.new).tag { :void }
58
- stub(elm_type).pointer? { true }
59
+ it "returns [:pointer, :void] if the element type is a pointer with tag :void" do
60
+ stub(elmtype_info).tag_or_class { [:pointer, :void] }
59
61
 
60
62
  mock(type_info).tag {:glist}
61
- mock(type_info).param_type(0) { elm_type }
63
+ mock(type_info).param_type(0) { elmtype_info }
62
64
 
63
- assert_equal :gpointer, type_info.element_type
65
+ assert_equal [:pointer, :void], type_info.element_type
64
66
  end
65
67
  end
66
68
 
67
- describe "#type_specification" do
69
+ describe "#flattened_tag" do
68
70
  describe "for a simple type" do
69
71
  it "returns the type tag" do
70
72
  stub(type_info).tag { :uint32 }
71
73
 
72
- type_info.type_specification.must_equal ":uint32"
74
+ type_info.flattened_tag.must_equal :uint32
73
75
  end
74
76
  end
75
77
 
76
- describe "for a zero-terminated utf8 array" do
77
- it "returns the pair [:strv, :utf8]" do
78
- stub(elmtype_info).tag { :utf8 }
79
- stub(elmtype_info).pointer? { true }
80
-
78
+ context "for a zero-terminated array" do
79
+ before do
81
80
  stub(type_info).tag { :array }
82
81
  stub(type_info).param_type(0) { elmtype_info }
83
82
  stub(type_info).zero_terminated? { true }
84
- stub(type_info).array_type { :c }
83
+ end
84
+
85
+ context "of utf8" do
86
+ it "returns :strv" do
87
+ stub(elmtype_info).tag { :utf8 }
88
+ stub(elmtype_info).pointer? { true }
85
89
 
86
- type_info.type_specification.must_equal "[:strv, :utf8]"
90
+ type_info.flattened_tag.must_equal :strv
91
+ end
92
+ end
93
+
94
+ context "of filename" do
95
+ it "returns :strv" do
96
+ stub(elmtype_info).tag { :filename }
97
+ stub(elmtype_info).pointer? { true }
98
+
99
+ type_info.flattened_tag.must_equal :strv
100
+ end
101
+ end
102
+
103
+ context "of another type" do
104
+ it "returns :zero_terminated" do
105
+ stub(elmtype_info).tag { :foo }
106
+ stub(elmtype_info).pointer? { false }
107
+
108
+ type_info.flattened_tag.must_equal :zero_terminated
109
+ end
87
110
  end
88
111
  end
89
112
 
90
- describe "for a zero-terminated filename array" do
91
- it "returns the pair [:strv, :filename]" do
92
- stub(elmtype_info).tag { :filename }
93
- stub(elmtype_info).pointer? { true }
113
+ describe "for a fixed length c-like array" do
114
+ it "returns :c" do
115
+ mock(type_info).tag { :array }
116
+ mock(type_info).zero_terminated? { false }
117
+ mock(type_info).array_type { :c }
94
118
 
95
- stub(type_info).tag { :array }
96
- stub(type_info).param_type(0) { elmtype_info }
97
- stub(type_info).zero_terminated? { true }
98
- stub(type_info).array_type { :c }
119
+ type_info.flattened_tag.must_equal :c
120
+ end
121
+ end
122
+
123
+ end
124
+
125
+ describe "#subtype_tag_or_class_name" do
126
+ describe "without a parameter" do
127
+ it "returns the result of calling #tag_or_class_name on the first param_type" do
128
+ mock(elmtype_info).tag_or_class_name { ":foo" }
99
129
 
100
- type_info.type_specification.must_equal "[:strv, :filename]"
130
+ mock(type_info).param_type(0) { elmtype_info }
131
+
132
+ type_info.subtype_tag_or_class_name.must_equal ":foo"
101
133
  end
102
134
  end
135
+ end
103
136
 
104
- describe "for a zero-terminated array" do
105
- it "returns the pair [:zero_terminated, element_type]" do
106
- stub(elmtype_info).tag { :foo }
107
- stub(elmtype_info).pointer? { false }
137
+ describe "#subtype_tag_or_class" do
138
+ describe "without a parameter" do
139
+ it "returns the result of calling #tag_or_class on the first param_type" do
140
+ mock(elmtype_info).tag_or_class { :foo }
108
141
 
109
- stub(type_info).tag { :array }
110
- stub(type_info).param_type(0) { elmtype_info }
111
- stub(type_info).zero_terminated? { true }
112
- stub(type_info).array_type { :c }
142
+ mock(type_info).param_type(0) { elmtype_info }
113
143
 
114
- type_info.type_specification.must_equal "[:zero_terminated, :foo]"
144
+ type_info.subtype_tag_or_class.must_equal :foo
115
145
  end
116
146
  end
147
+ end
117
148
 
118
- describe "for a fixed length c-like array of type :foo" do
119
- it "returns the pair [:c, :foo]" do
120
- mock(elmtype_info).tag { :foo }
121
- mock(elmtype_info).pointer? { false }
149
+ describe "#tag_or_class_name" do
150
+ describe "for the simple type :foo" do
151
+ it "returns the string ':foo'" do
152
+ mock(type_info).tag { :foo }
153
+ mock(type_info).pointer? { false }
122
154
 
123
- mock(type_info).tag { :array }
124
- stub(type_info).param_type(0) { elmtype_info }
125
- stub(type_info).zero_terminated? { false }
126
- stub(type_info).array_type { :c }
155
+ assert_equal ":foo", type_info.tag_or_class_name
156
+ end
157
+ end
158
+
159
+ describe "for :utf8" do
160
+ it "returns the string ':utf8'" do
161
+ mock(type_info).tag { :utf8 }
162
+ mock(type_info).pointer? { true }
163
+
164
+ assert_equal ":utf8", type_info.tag_or_class_name
165
+ end
166
+ end
127
167
 
128
- type_info.type_specification.must_equal "[:c, :foo]"
168
+ describe "for an interface class" do
169
+ it "returns the interface's full class name" do
170
+ mock(type_info).tag { :interface }
171
+ mock(type_info).interface_type_name { "-full-type-name-" }
172
+ mock(type_info).pointer? { false }
173
+
174
+ assert_equal "-full-type-name-", type_info.tag_or_class_name
129
175
  end
130
176
  end
131
177
 
178
+ describe "for a pointer to simple type :foo" do
179
+ it "returns the string '[:pointer, :foo]'" do
180
+ mock(type_info).tag { :foo }
181
+ mock(type_info).pointer? { true }
182
+
183
+ assert_equal "[:pointer, :foo]", type_info.tag_or_class_name
184
+ end
185
+ end
132
186
  end
133
187
 
134
- describe "#subtype_tag_or_class_name" do
188
+ describe "#tag_or_class" do
135
189
  describe "for a simple type" do
136
- it "returns the string ':void'" do
137
- mock(subtype = Object.new).tag { :void }
138
- mock(subtype).pointer? { false }
139
-
140
- mock(info = testclass.new).param_type(0) { subtype }
190
+ it "returns the type's tag" do
191
+ mock(type_info).tag { :foo }
192
+ mock(type_info).pointer? { false }
141
193
 
142
- assert_equal ":void", info.subtype_tag_or_class_name
194
+ type_info.tag_or_class.must_equal :foo
143
195
  end
144
196
  end
145
197
 
146
- describe "for an array of simple type :foo" do
147
- it "returns the string ':foo'" do
148
- mock(subtype = Object.new).tag { :foo }
149
- mock(subtype).pointer? { false }
198
+ describe "for utf8 strings" do
199
+ it "returns the tag :utf8" do
200
+ mock(type_info).tag { :utf8 }
201
+ mock(type_info).pointer? { true }
202
+
203
+ type_info.tag_or_class.must_equal :utf8
204
+ end
205
+ end
150
206
 
151
- mock(info = testclass.new).param_type(0) { subtype }
207
+ describe "for filename strings" do
208
+ it "returns the tag :filename" do
209
+ mock(type_info).tag { :filename }
210
+ mock(type_info).pointer? { true }
152
211
 
153
- assert_equal ":foo", info.subtype_tag_or_class_name
212
+ type_info.tag_or_class.must_equal :filename
154
213
  end
155
214
  end
156
215
 
157
- describe "for an array of :utf8" do
158
- it "returns the string ':utf8'" do
159
- mock(subtype = Object.new).tag { :utf8 }
160
- mock(subtype).pointer? { true }
216
+ describe "for an interface class" do
217
+ it "returns the class built from the interface" do
218
+ interface_info = Object.new
219
+ interface = Object.new
220
+
221
+ mock(type_info).tag { :interface }
222
+ mock(type_info).interface { interface_info }
223
+ mock(type_info).pointer? { false }
161
224
 
162
- mock(info = testclass.new).param_type(0) { subtype }
225
+ mock(GirFFI::Builder).build_class(interface_info) { interface }
163
226
 
164
- assert_equal ":utf8", info.subtype_tag_or_class_name
227
+ type_info.tag_or_class.must_equal interface
165
228
  end
166
229
  end
167
230
 
168
- describe "for an array of an interface class" do
169
- it "returns the interface's full class name" do
170
- mock(subtype = Object.new).tag { :interface }
171
- mock(subtype).interface_type_name { "-full-type-name-" }
172
- mock(subtype).pointer? { false }
231
+ describe "for a pointer to simple type :foo" do
232
+ it "returns [:pointer, :foo]" do
233
+ mock(type_info).tag { :foo }
234
+ mock(type_info).pointer? { true }
235
+
236
+ type_info.tag_or_class.must_equal [:pointer, :foo]
237
+ end
238
+ end
173
239
 
174
- mock(info = testclass.new).param_type(0) { subtype }
240
+ describe "for a pointer to :void" do
241
+ it "returns [:pointer, :void]" do
242
+ stub(type_info).tag { :void }
243
+ stub(type_info).pointer? { true }
175
244
 
176
- assert_equal "-full-type-name-", info.subtype_tag_or_class_name
245
+ type_info.tag_or_class.must_equal [:pointer, :void]
177
246
  end
178
247
  end
248
+ end
179
249
 
180
- describe "for an array of pointer to simple type :foo" do
181
- it "returns the string '[:pointer, :foo]'" do
182
- mock(subtype = Object.new).tag { :foo }
183
- mock(subtype).pointer? { true }
250
+ describe "#to_callback_ffitype" do
251
+ let(:iface) { Object.new }
252
+ describe "for an :interface argument" do
253
+ before do
254
+ stub(type_info).interface { iface }
255
+ stub(type_info).tag { :interface }
256
+ stub(type_info).pointer? { false }
257
+ end
258
+
259
+ it "correctly maps a :union argument to :pointer" do
260
+ stub(iface).info_type { :union }
261
+
262
+ type_info.to_callback_ffitype.must_equal :pointer
263
+ end
184
264
 
185
- mock(info = testclass.new).param_type(0) { subtype }
265
+ it "correctly maps a :flags argument to :int32" do
266
+ stub(iface).info_type { :flags }
186
267
 
187
- assert_equal "[:pointer, :foo]", info.subtype_tag_or_class_name
268
+ type_info.to_callback_ffitype.must_equal :int32
188
269
  end
189
270
  end
190
271
  end
@@ -270,7 +270,7 @@ describe GirFFI::ReturnValueBuilder do
270
270
 
271
271
  it "converts the result in #post" do
272
272
  builder.callarg.must_equal "_v1"
273
- builder.post.must_equal [ "_v2 = GirFFI::ArgHelper.ptr_to_typed_array :foo, _v1, 3" ]
273
+ builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:foo, 3, _v1)" ]
274
274
  end
275
275
 
276
276
  it "returns the wrapped result" do
@@ -292,7 +292,7 @@ describe GirFFI::ReturnValueBuilder do
292
292
 
293
293
  it "converts the result in #post" do
294
294
  builder.callarg.must_equal "_v1"
295
- builder.post.must_equal [ "_v2 = GirFFI::ArgHelper.ptr_to_typed_array :foo, _v1, bar" ]
295
+ builder.post.must_equal [ "_v2 = GLib::SizedArray.wrap(:foo, bar, _v1)" ]
296
296
  end
297
297
 
298
298
  it "returns the wrapped result" do
@@ -0,0 +1,95 @@
1
+ require 'gir_ffi_test_helper'
2
+ require 'gir_ffi/unintrospectable_type_info'
3
+
4
+ describe GirFFI::UnintrospectableTypeInfo do
5
+ describe "#info_type" do
6
+ it "returns :unintrospectable" do
7
+ info = GirFFI::UnintrospectableTypeInfo.new :some_type
8
+ info.info_type.must_equal :unintrospectable
9
+ end
10
+ end
11
+
12
+ describe "#parent" do
13
+ it "finds the parent's info by gtype" do
14
+ gobject = Object.new
15
+ gir = Object.new
16
+
17
+ mock(gobject).type_parent(:some_type) { :foo }
18
+ mock(gir).find_by_gtype(:foo) { :foo_info }
19
+
20
+ info = GirFFI::UnintrospectableTypeInfo.new(:some_type, gir, gobject)
21
+
22
+ info.parent.must_equal :foo_info
23
+ end
24
+ end
25
+
26
+ describe "#interfaces" do
27
+ it "finds interface infos by gtype" do
28
+ gobject = Object.new
29
+ gir = Object.new
30
+
31
+ mock(gobject).type_interfaces(:some_type) { [:foo, :bar ] }
32
+ mock(gir).find_by_gtype(:foo) { :foo_info }
33
+ mock(gir).find_by_gtype(:bar) { :bar_info }
34
+
35
+ info = GirFFI::UnintrospectableTypeInfo.new(:some_type, gir, gobject)
36
+
37
+ info.interfaces.must_equal [:foo_info, :bar_info]
38
+ end
39
+
40
+ it "skips interfaces that have no introspection data" do
41
+ gobject = Object.new
42
+ gir = Object.new
43
+
44
+ mock(gobject).type_interfaces(:some_type) { [:foo, :bar ] }
45
+ mock(gir).find_by_gtype(:foo) { :foo_info }
46
+ mock(gir).find_by_gtype(:bar) { nil }
47
+
48
+ info = GirFFI::UnintrospectableTypeInfo.new(:some_type, gir, gobject)
49
+
50
+ info.interfaces.must_equal [:foo_info]
51
+ end
52
+ end
53
+
54
+ describe "#g_type" do
55
+ it "returns the passed-in gtype" do
56
+ info = GirFFI::UnintrospectableTypeInfo.new(:some_type)
57
+ info.g_type.must_equal :some_type
58
+ end
59
+ end
60
+
61
+ describe "#fields" do
62
+ it "returns an empty array" do
63
+ info = GirFFI::UnintrospectableTypeInfo.new(:some_type)
64
+ info.fields.must_equal []
65
+ end
66
+ end
67
+
68
+ describe "#namespace" do
69
+ it "returns the parent class' namespace" do
70
+ gobject = Object.new
71
+ gir = Object.new
72
+ parent_info = Object.new
73
+
74
+ mock(gobject).type_parent(:some_type) { :foo }
75
+ mock(gir).find_by_gtype(:foo) { parent_info }
76
+ mock(parent_info).namespace { 'FooNamespace' }
77
+
78
+ info = GirFFI::UnintrospectableTypeInfo.new(:some_type, gir, gobject)
79
+
80
+ info.namespace.must_equal 'FooNamespace'
81
+ end
82
+ end
83
+
84
+ describe "#safe_name" do
85
+ it "finds the class name by gtype" do
86
+ gobject = Object.new
87
+
88
+ mock(gobject).type_name(:some_type) { 'GSomeType' }
89
+
90
+ info = GirFFI::UnintrospectableTypeInfo.new(:some_type, nil, gobject)
91
+
92
+ info.safe_name.must_equal 'GSomeType'
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,19 @@
1
+ require 'gir_ffi_test_helper'
2
+ require 'gir_ffi/user_defined_property_info'
3
+
4
+ describe GirFFI::UserDefinedPropertyInfo do
5
+ describe "#param_spec" do
6
+ it "returns the passed in parameter specification" do
7
+ info = GirFFI::UserDefinedPropertyInfo.new :some_param_spec
8
+ info.param_spec.must_equal :some_param_spec
9
+ end
10
+ end
11
+
12
+ describe "#name" do
13
+ it "returns the name retrieved from the parameter specification" do
14
+ mock(param_spec = Object.new).get_name { :property_name }
15
+ info = GirFFI::UserDefinedPropertyInfo.new param_spec
16
+ info.name.must_equal :property_name
17
+ end
18
+ end
19
+ end