gir_ffi 0.11.4 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/Changelog.md +6 -0
  3. data/Gemfile +1 -6
  4. data/README.md +3 -3
  5. data/Rakefile +2 -0
  6. data/lib/ffi-glib.rb +0 -1
  7. data/lib/ffi-glib/array_methods.rb +1 -1
  8. data/lib/ffi-glib/container_class_methods.rb +1 -1
  9. data/lib/ffi-glib/main_loop.rb +1 -3
  10. data/lib/ffi-gobject/ruby_closure.rb +1 -1
  11. data/lib/ffi-gobject/value.rb +2 -6
  12. data/lib/ffi-gobject_introspection/i_base_info.rb +2 -2
  13. data/lib/gir_ffi/arg_helper.rb +1 -3
  14. data/lib/gir_ffi/builders/argument_builder.rb +3 -5
  15. data/lib/gir_ffi/builders/callback_argument_builder.rb +1 -1
  16. data/lib/gir_ffi/builders/enum_builder.rb +1 -1
  17. data/lib/gir_ffi/builders/initializer_return_value_builder.rb +1 -3
  18. data/lib/gir_ffi/builders/object_builder.rb +4 -4
  19. data/lib/gir_ffi/builders/return_value_builder.rb +1 -1
  20. data/lib/gir_ffi/builders/struct_builder.rb +1 -3
  21. data/lib/gir_ffi/builders/unintrospectable_builder.rb +1 -1
  22. data/lib/gir_ffi/class_base.rb +2 -6
  23. data/lib/gir_ffi/enum_like_base.rb +1 -3
  24. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +1 -1
  25. data/lib/gir_ffi/info_ext/i_type_info.rb +1 -1
  26. data/lib/gir_ffi/info_ext/i_vfunc_info.rb +1 -1
  27. data/lib/gir_ffi/interface_base.rb +1 -3
  28. data/lib/gir_ffi/object_base.rb +1 -1
  29. data/lib/gir_ffi/struct_like_base.rb +6 -3
  30. data/lib/gir_ffi/unintrospectable_boxed_info.rb +1 -1
  31. data/lib/gir_ffi/version.rb +1 -1
  32. data/test/base_test_helper.rb +9 -10
  33. data/test/ffi-gobject/object_test.rb +1 -3
  34. data/test/ffi-gobject/value_test.rb +1 -3
  35. data/test/ffi-gobject_introspection/i_base_info_test.rb +1 -3
  36. data/test/ffi-gobject_introspection/i_repository_test.rb +2 -0
  37. data/test/gir_ffi/arg_helper_test.rb +4 -4
  38. data/test/gir_ffi/boxed_base_test.rb +1 -3
  39. data/test/gir_ffi/builder_test.rb +1 -1
  40. data/test/gir_ffi/builders/field_builder_test.rb +3 -3
  41. data/test/gir_ffi/builders/registered_type_builder_test.rb +1 -3
  42. data/test/gir_ffi/builders/unintrospectable_boxed_builder_test.rb +5 -5
  43. data/test/gir_ffi/builders/unintrospectable_builder_test.rb +2 -2
  44. data/test/gir_ffi/builders/user_defined_builder_test.rb +78 -78
  45. data/test/gir_ffi/class_base_test.rb +7 -7
  46. data/test/gir_ffi/ffi_ext/pointer_test.rb +2 -2
  47. data/test/gir_ffi/info_ext/i_callable_info_test.rb +2 -2
  48. data/test/gir_ffi/info_ext/i_callback_info_test.rb +2 -2
  49. data/test/gir_ffi/info_ext/i_field_info_test.rb +2 -2
  50. data/test/gir_ffi/info_ext/i_function_info_test.rb +2 -2
  51. data/test/gir_ffi/info_ext/i_signal_info_test.rb +2 -2
  52. data/test/gir_ffi/info_ext/i_type_info_test.rb +5 -5
  53. data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +2 -2
  54. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +2 -2
  55. data/test/gir_ffi/info_ext/safe_function_name_test.rb +2 -2
  56. data/test/gir_ffi/method_stubber_test.rb +2 -1
  57. data/test/gir_ffi/struct_like_base_test.rb +22 -22
  58. data/test/gir_ffi/user_defined_object_info_test.rb +11 -11
  59. data/test/gir_ffi_test_helper.rb +1 -3
  60. data/test/integration/generated_glib_test.rb +0 -6
  61. data/test/integration/generated_gobject_test.rb +1 -1
  62. data/test/integration/generated_regress_test.rb +4 -3
  63. data/test/minitest/stats_plugin.rb +3 -1
  64. metadata +27 -15
  65. data/lib/ffi-glib/iconv.rb +0 -15
  66. data/test/ffi-glib/iconv_test.rb +0 -19
@@ -1,19 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rubygems' if RUBY_PLATFORM == 'java'
4
-
5
- begin
6
- require 'simplecov'
7
- SimpleCov.start do
8
- track_files 'lib/**/*.rb'
9
- add_filter '/test/'
10
- end
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ track_files 'lib/**/*.rb'
6
+ add_filter '/test/'
7
+ end
11
8
 
12
- if ENV['CI']
9
+ if ENV['CI']
10
+ begin
13
11
  require 'coveralls'
14
12
  Coveralls.wear!
13
+ rescue LoadError
14
+ nil
15
15
  end
16
- rescue LoadError
17
16
  end
18
17
 
19
18
  require 'minitest/autorun'
@@ -121,9 +121,7 @@ describe GObject::Object do
121
121
 
122
122
  describe 'upon garbage collection' do
123
123
  it 'lowers the reference count' do
124
- if jruby? || rubinius?
125
- skip 'cannot be reliably tested on JRuby and Rubinius'
126
- end
124
+ skip 'cannot be reliably tested on JRuby and Rubinius' if jruby? || rubinius?
127
125
 
128
126
  ptr = GObject::Object.new.to_ptr
129
127
  ref_count(ptr).must_equal 1
@@ -349,9 +349,7 @@ describe GObject::Value do
349
349
 
350
350
  describe 'upon garbage collection' do
351
351
  it 'restores the underlying GValue to its pristine state' do
352
- if jruby? || rubinius?
353
- skip 'cannot be reliably tested on JRuby and Rubinius'
354
- end
352
+ skip 'cannot be reliably tested on JRuby and Rubinius' if jruby? || rubinius?
355
353
 
356
354
  value = GObject::Value.from 42
357
355
 
@@ -33,9 +33,7 @@ describe GObjectIntrospection::IBaseInfo do
33
33
 
34
34
  describe 'upon garbage collection' do
35
35
  it 'calls g_base_info_unref' do
36
- if jruby? || rubinius?
37
- skip 'cannot be reliably tested on JRuby and Rubinius'
38
- end
36
+ skip 'cannot be reliably tested on JRuby and Rubinius' if jruby? || rubinius?
39
37
 
40
38
  expect(ptr = Object.new).to receive(:null?).and_return false
41
39
  expect(lib = Object.new).to receive(:g_base_info_unref).with(ptr).and_return nil
@@ -62,11 +62,13 @@ describe GObjectIntrospection::IRepository do
62
62
 
63
63
  describe '#dependencies' do
64
64
  it 'returns a list of dependencies of the given namespace' do
65
+ gir.require 'GObject', '2.0'
65
66
  result = gir.dependencies('GObject')
66
67
  result.must_equal ['GLib-2.0']
67
68
  end
68
69
 
69
70
  it 'passes its struct pointer to the c function just in case' do
71
+ gir.require 'GObject', '2.0'
70
72
  ptr = gir.instance_variable_get(:@gobj)
71
73
  allow(GObjectIntrospection::Lib).to receive(:g_irepository_get_dependencies).
72
74
  and_call_original
@@ -69,25 +69,25 @@ describe GirFFI::ArgHelper do
69
69
  describe 'when passing a broken typespec' do
70
70
  it 'raises on unknown symbol' do
71
71
  ptr = FFI::Pointer.new(0xffffffff)
72
- exception = -> { GirFFI::ArgHelper.cast_from_pointer(:foo, ptr) }.must_raise
72
+ exception = -> { GirFFI::ArgHelper.cast_from_pointer(:foo, ptr) }.must_raise RuntimeError
73
73
  exception.message.must_equal "Don't know how to cast foo"
74
74
  end
75
75
 
76
76
  it 'raises on unexpected main type for complex type' do
77
77
  ptr = FFI::Pointer.new(0xffffffff)
78
- exception = -> { GirFFI::ArgHelper.cast_from_pointer([:utf8], ptr) }.must_raise
78
+ exception = -> { GirFFI::ArgHelper.cast_from_pointer([:utf8], ptr) }.must_raise RuntimeError
79
79
  exception.message.must_equal "Don't know how to cast [:utf8]"
80
80
  end
81
81
 
82
82
  it 'raises on unexpected sub type for complex type' do
83
83
  ptr = FFI::Pointer.new(0xffffffff)
84
- exception = -> { GirFFI::ArgHelper.cast_from_pointer([:pointer, :utf8], ptr) }.must_raise
84
+ exception = -> { GirFFI::ArgHelper.cast_from_pointer([:pointer, :utf8], ptr) }.must_raise RuntimeError
85
85
  exception.message.must_equal "Don't know how to cast [:pointer, :utf8]"
86
86
  end
87
87
 
88
88
  it 'raises on unexpected container type for complex type' do
89
89
  ptr = FFI::Pointer.new(0xffffffff)
90
- exception = -> { GirFFI::ArgHelper.cast_from_pointer([:pointer, [:gint32]], ptr) }.must_raise
90
+ exception = -> { GirFFI::ArgHelper.cast_from_pointer([:pointer, [:gint32]], ptr) }.must_raise RuntimeError
91
91
  exception.message.must_equal "Don't know how to cast [:pointer, [:gint32]]"
92
92
  end
93
93
  end
@@ -38,9 +38,7 @@ describe GirFFI::BoxedBase do
38
38
 
39
39
  describe 'upon garbage collection' do
40
40
  it 'frees and disowns the underlying struct if it is owned' do
41
- if jruby? || rubinius?
42
- skip 'cannot be reliably tested on JRuby and Rubinius'
43
- end
41
+ skip 'cannot be reliably tested on JRuby and Rubinius' if jruby? || rubinius?
44
42
 
45
43
  allow(GObject).to receive(:boxed_free)
46
44
  gtype = GIMarshallingTests::BoxedStruct.gtype
@@ -18,7 +18,7 @@ describe GirFFI::Builder do
18
18
 
19
19
  describe '.build_module' do
20
20
  it 'refuses to build existing modules defined elsewhere' do
21
- result = -> { GirFFI::Builder.build_module('Array') }.must_raise
21
+ result = -> { GirFFI::Builder.build_module('Array') }.must_raise RuntimeError
22
22
  result.message.must_equal 'The module Array was already defined elsewhere'
23
23
  end
24
24
 
@@ -3,8 +3,8 @@
3
3
  require 'gir_ffi_test_helper'
4
4
 
5
5
  describe GirFFI::Builders::FieldBuilder do
6
- let(:klass) { 'dummy' }
7
- let(:instance) { GirFFI::Builders::FieldBuilder.new field_info, klass }
6
+ let(:target_class) { 'dummy' }
7
+ let(:instance) { GirFFI::Builders::FieldBuilder.new field_info, target_class }
8
8
 
9
9
  describe 'for a field of type :gint8 with an offset' do
10
10
  let(:field_info) { get_field_introspection_data 'Regress', 'TestSimpleBoxedA', 'some_int8' }
@@ -117,7 +117,7 @@ describe GirFFI::Builders::FieldBuilder do
117
117
  let(:n_params_field_info) { get_field_introspection_data 'GObject', 'SignalQuery', 'n_params' }
118
118
 
119
119
  it 'creates the right getter method' do
120
- skip if field_info.field_type.array_length < 0
120
+ skip if field_info.field_type.array_length.negative?
121
121
  expected = <<-CODE.reset_indentation
122
122
  def param_types
123
123
  _v1 = @struct.to_ptr + #{n_params_field_info.offset}
@@ -24,9 +24,7 @@ describe GirFFI::Builders::RegisteredTypeBuilder do
24
24
  end
25
25
 
26
26
  it 'returns the name of the generated method if different from the info name' do
27
- builder = GLib::IConv.gir_ffi_builder
28
- result = builder.setup_instance_method ''
29
- result.must_equal '_'
27
+ skip 'Need some way to test this now that GLib::IConv is gone'
30
28
  end
31
29
  end
32
30
  end
@@ -10,7 +10,7 @@ describe GirFFI::Builders::UnintrospectableBoxedBuilder do
10
10
  let(:gtype) { property.value_type }
11
11
  let(:info) { GirFFI::UnintrospectableBoxedInfo.new(gtype) }
12
12
  let(:bldr) { GirFFI::Builders::UnintrospectableBoxedBuilder.new(info) }
13
- let(:klass) { bldr.build_class }
13
+ let(:boxed_class) { bldr.build_class }
14
14
 
15
15
  before do
16
16
  skip unless get_property_introspection_data('GIMarshallingTests',
@@ -19,17 +19,17 @@ describe GirFFI::Builders::UnintrospectableBoxedBuilder do
19
19
  end
20
20
 
21
21
  it 'builds a class' do
22
- klass.must_be_instance_of Class
22
+ boxed_class.must_be_instance_of Class
23
23
  end
24
24
 
25
25
  it 'builds a class derived from GirFFI::BoxedBase' do
26
- klass.ancestors.must_include GirFFI::BoxedBase
26
+ boxed_class.ancestors.must_include GirFFI::BoxedBase
27
27
  end
28
28
 
29
29
  it 'returns the same class when built again' do
30
30
  other_bldr = GirFFI::Builders::UnintrospectableBoxedBuilder.new(info)
31
- other_klass = other_bldr.build_class
31
+ other_class = other_bldr.build_class
32
32
 
33
- other_klass.must_equal klass
33
+ other_class.must_equal boxed_class
34
34
  end
35
35
  end
@@ -55,8 +55,8 @@ describe GirFFI::Builders::UnintrospectableBuilder do
55
55
 
56
56
  describe 'building the GstFakeSink type' do
57
57
  let(:instance) { Gst::ElementFactory.make('fakesink', 'sink') }
58
- let(:klass) { instance.class }
59
- let(:builder) { klass.gir_ffi_builder }
58
+ let(:sink_class) { instance.class }
59
+ let(:builder) { sink_class.gir_ffi_builder }
60
60
 
61
61
  before do
62
62
  Gst.init []
@@ -6,12 +6,12 @@ GirFFI.setup :GIMarshallingTests
6
6
  GirFFI.setup :Regress
7
7
 
8
8
  describe GirFFI::Builders::UserDefinedBuilder do
9
- let(:base_klass) { GIMarshallingTests::Object }
10
- let(:klass) do
11
- Object.const_set("DerivedClass#{Sequence.next}", Class.new(base_klass))
9
+ let(:base_class) { GIMarshallingTests::Object }
10
+ let(:derived_class) do
11
+ Object.const_set("DerivedClass#{Sequence.next}", Class.new(base_class))
12
12
  end
13
13
  let(:builder) { GirFFI::Builders::UserDefinedBuilder.new info }
14
- let(:info) { GirFFI::UserDefinedObjectInfo.new klass }
14
+ let(:info) { GirFFI::UserDefinedObjectInfo.new derived_class }
15
15
 
16
16
  describe '#build_class' do
17
17
  before do
@@ -20,7 +20,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
20
20
 
21
21
  describe 'with type info containing one integer property' do
22
22
  let(:info) do
23
- GirFFI::UserDefinedObjectInfo.new klass do |it|
23
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
24
24
  it.install_property GObject.param_spec_int('foo-bar', 'foo bar',
25
25
  'The Foo Bar Property',
26
26
  10, 20, 15,
@@ -29,41 +29,41 @@ describe GirFFI::Builders::UserDefinedBuilder do
29
29
  end
30
30
 
31
31
  it 'registers a type that is bigger than the parent' do
32
- gtype = klass.gtype
32
+ gtype = derived_class.gtype
33
33
  q = GObject.type_query gtype
34
34
  q.instance_size.must_be :>, GIMarshallingTests::Object::Struct.size
35
35
  end
36
36
 
37
37
  it "gives the type's Struct fields for the parent and the property" do
38
- klass::Struct.members.must_equal [:parent, :foo_bar]
38
+ derived_class::Struct.members.must_equal [:parent, :foo_bar]
39
39
  end
40
40
 
41
41
  it 'creates accessor functions for the property' do
42
- obj = klass.new
42
+ obj = derived_class.new
43
43
  obj.foo_bar = 13
44
44
  obj.foo_bar.must_equal 13
45
45
  end
46
46
 
47
47
  it 'makes the property retrievable using #get_property' do
48
- obj = klass.new
48
+ obj = derived_class.new
49
49
  obj.foo_bar = 13
50
50
  obj.get_property('foo-bar').must_equal 13
51
51
  end
52
52
 
53
53
  it 'makes the property settable using #set_property' do
54
- obj = klass.new
54
+ obj = derived_class.new
55
55
  obj.set_property('foo-bar', 20)
56
56
  obj.foo_bar.must_equal 20
57
57
  end
58
58
 
59
59
  it 'keeps parent properties accessible through their accessors' do
60
- obj = klass.new
60
+ obj = derived_class.new
61
61
  obj.int = 24
62
62
  obj.int.must_equal 24
63
63
  end
64
64
 
65
65
  it 'keeps parent properties accessible through get_property and set_property' do
66
- obj = klass.new
66
+ obj = derived_class.new
67
67
  obj.set_property('int', 24)
68
68
  obj.get_property('int').must_equal 24
69
69
  end
@@ -71,7 +71,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
71
71
 
72
72
  describe 'with type info containing properties of several different types' do
73
73
  let(:info) do
74
- GirFFI::UserDefinedObjectInfo.new klass do |it|
74
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
75
75
  it.install_property GObject.param_spec_string('string-prop', 'string property',
76
76
  'The String Property',
77
77
  'this is the default value',
@@ -88,27 +88,27 @@ describe GirFFI::Builders::UserDefinedBuilder do
88
88
  end
89
89
 
90
90
  it 'registers a type of the proper size' do
91
- expected_size = klass::Struct.size
92
- gtype = klass.gtype
91
+ expected_size = derived_class::Struct.size
92
+ gtype = derived_class.gtype
93
93
  q = GObject.type_query gtype
94
94
  q.instance_size.must_equal expected_size
95
95
  end
96
96
 
97
97
  it "gives the type's Struct fields for the parent and the properties with the correct offsets" do
98
- offsets = klass::Struct.offsets
99
- alignment = klass::Struct.alignment
98
+ offsets = derived_class::Struct.offsets
99
+ alignment = derived_class::Struct.alignment
100
100
  alignment.must_equal 8 # TODO: Fix tests for platforms where this fails.
101
101
  offsets.must_equal [[:parent, 0], [:string_prop, 32], [:int_prop, 40], [:long_prop, 48]]
102
102
  end
103
103
 
104
104
  it 'creates accessor functions for the string property' do
105
- obj = klass.new
105
+ obj = derived_class.new
106
106
  obj.string_prop = 'hello!'
107
107
  obj.string_prop.must_equal 'hello!'
108
108
  end
109
109
 
110
110
  it 'creates accessor functions for the integer property' do
111
- obj = klass.new
111
+ obj = derived_class.new
112
112
  obj.int_prop = 13
113
113
  obj.int_prop.must_equal 13
114
114
  end
@@ -117,7 +117,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
117
117
  describe 'with a boxed property' do
118
118
  let(:boxed_gtype) { GIMarshallingTests::BoxedStruct.gtype }
119
119
  let(:info) do
120
- GirFFI::UserDefinedObjectInfo.new klass do |it|
120
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
121
121
  it.install_property GObject.param_spec_boxed('boxed-prop', 'boxed property',
122
122
  'The Boxed Property',
123
123
  boxed_gtype,
@@ -126,18 +126,18 @@ describe GirFFI::Builders::UserDefinedBuilder do
126
126
  end
127
127
 
128
128
  it 'registers a type of the proper size' do
129
- expected_size = klass::Struct.size
130
- gtype = klass.gtype
129
+ expected_size = derived_class::Struct.size
130
+ gtype = derived_class.gtype
131
131
  q = GObject.type_query gtype
132
132
  q.instance_size.must_equal expected_size
133
133
  end
134
134
 
135
135
  it "gives the type's Struct fields for the parent and the property" do
136
- klass::Struct.members.must_equal [:parent, :boxed_prop]
136
+ derived_class::Struct.members.must_equal [:parent, :boxed_prop]
137
137
  end
138
138
 
139
139
  it 'creates accessor functions for the property' do
140
- obj = klass.new
140
+ obj = derived_class.new
141
141
  boxed = GIMarshallingTests::BoxedStruct.new
142
142
  boxed.long_ = 423
143
143
  obj.boxed_prop = boxed
@@ -148,7 +148,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
148
148
  describe 'with an object property' do
149
149
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
150
150
  let(:info) do
151
- GirFFI::UserDefinedObjectInfo.new klass do |it|
151
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
152
152
  it.install_property GObject.param_spec_object('object-prop', 'object property',
153
153
  'The Object Property',
154
154
  object_gtype,
@@ -157,18 +157,18 @@ describe GirFFI::Builders::UserDefinedBuilder do
157
157
  end
158
158
 
159
159
  it 'registers a type of the proper size' do
160
- expected_size = klass::Struct.size
161
- gtype = klass.gtype
160
+ expected_size = derived_class::Struct.size
161
+ gtype = derived_class.gtype
162
162
  q = GObject.type_query gtype
163
163
  q.instance_size.must_equal expected_size
164
164
  end
165
165
 
166
166
  it "gives the type's Struct fields for the parent and the property" do
167
- klass::Struct.members.must_equal [:parent, :object_prop]
167
+ derived_class::Struct.members.must_equal [:parent, :object_prop]
168
168
  end
169
169
 
170
170
  it 'creates accessor functions for the property' do
171
- obj = klass.new
171
+ obj = derived_class.new
172
172
  object = GIMarshallingTests::Object.new 42
173
173
  object.int = 423
174
174
  obj.object_prop = object
@@ -176,20 +176,20 @@ describe GirFFI::Builders::UserDefinedBuilder do
176
176
  end
177
177
 
178
178
  it 'allows clearing the property throught the setter method' do
179
- obj = klass.new
179
+ obj = derived_class.new
180
180
  obj.object_prop = nil
181
181
  obj.object_prop.must_be_nil
182
182
  end
183
183
 
184
184
  it 'handles reference counting correctly when using the accessor' do
185
- obj = klass.new
185
+ obj = derived_class.new
186
186
  object = GIMarshallingTests::Object.new 42
187
187
  obj.object_prop = object
188
188
  object.ref_count.must_equal 2
189
189
  end
190
190
 
191
191
  it 'handles reference counting correctly when using the set_property method' do
192
- obj = klass.new
192
+ obj = derived_class.new
193
193
  object = GIMarshallingTests::Object.new 42
194
194
  object.ref_count.must_equal 1
195
195
  obj.set_property('object_prop', object)
@@ -200,7 +200,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
200
200
  describe 'with a boolean property' do
201
201
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
202
202
  let(:info) do
203
- GirFFI::UserDefinedObjectInfo.new klass do |it|
203
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
204
204
  it.install_property GObject.param_spec_boolean('the-prop', 'the property',
205
205
  'The Property',
206
206
  true,
@@ -209,7 +209,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
209
209
  end
210
210
 
211
211
  it 'creates accessor functions for the property' do
212
- obj = klass.new
212
+ obj = derived_class.new
213
213
  obj.the_prop = true
214
214
  obj.the_prop.must_equal true
215
215
  end
@@ -218,7 +218,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
218
218
  describe 'with a char property' do
219
219
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
220
220
  let(:info) do
221
- GirFFI::UserDefinedObjectInfo.new klass do |it|
221
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
222
222
  it.install_property GObject.param_spec_char('the-prop', 'the property',
223
223
  'The Property',
224
224
  -20, 100, 15,
@@ -227,7 +227,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
227
227
  end
228
228
 
229
229
  it 'creates accessor functions for the property' do
230
- obj = klass.new
230
+ obj = derived_class.new
231
231
  obj.the_prop = -13
232
232
  obj.the_prop.must_equal(-13)
233
233
  end
@@ -236,7 +236,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
236
236
  describe 'with a uchar property' do
237
237
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
238
238
  let(:info) do
239
- GirFFI::UserDefinedObjectInfo.new klass do |it|
239
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
240
240
  it.install_property GObject.param_spec_uchar('the-prop', 'the property',
241
241
  'The Property',
242
242
  10, 100, 15,
@@ -245,7 +245,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
245
245
  end
246
246
 
247
247
  it 'creates accessor functions for the property' do
248
- obj = klass.new
248
+ obj = derived_class.new
249
249
  obj.the_prop = 13
250
250
  obj.the_prop.must_equal 13
251
251
  end
@@ -254,7 +254,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
254
254
  describe 'with a uint property' do
255
255
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
256
256
  let(:info) do
257
- GirFFI::UserDefinedObjectInfo.new klass do |it|
257
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
258
258
  it.install_property GObject.param_spec_uint('the-prop', 'the property',
259
259
  'The Property',
260
260
  10, 100, 15,
@@ -263,7 +263,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
263
263
  end
264
264
 
265
265
  it 'creates accessor functions for the property' do
266
- obj = klass.new
266
+ obj = derived_class.new
267
267
  obj.the_prop = 423
268
268
  obj.the_prop.must_equal 423
269
269
  end
@@ -272,7 +272,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
272
272
  describe 'with a ulong property' do
273
273
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
274
274
  let(:info) do
275
- GirFFI::UserDefinedObjectInfo.new klass do |it|
275
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
276
276
  it.install_property GObject.param_spec_ulong('the-prop', 'the property',
277
277
  'The Property',
278
278
  10, 100, 15,
@@ -281,7 +281,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
281
281
  end
282
282
 
283
283
  it 'creates accessor functions for the property' do
284
- obj = klass.new
284
+ obj = derived_class.new
285
285
  obj.the_prop = 423_432
286
286
  obj.the_prop.must_equal 423_432
287
287
  end
@@ -290,7 +290,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
290
290
  describe 'with a int64 property' do
291
291
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
292
292
  let(:info) do
293
- GirFFI::UserDefinedObjectInfo.new klass do |it|
293
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
294
294
  it.install_property GObject.param_spec_int64('the-prop', 'the property',
295
295
  'The Property',
296
296
  10, 100, 15,
@@ -299,7 +299,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
299
299
  end
300
300
 
301
301
  it 'creates accessor functions for the property' do
302
- obj = klass.new
302
+ obj = derived_class.new
303
303
  obj.the_prop = -423_432
304
304
  obj.the_prop.must_equal(-423_432)
305
305
  end
@@ -308,7 +308,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
308
308
  describe 'with a uint64 property' do
309
309
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
310
310
  let(:info) do
311
- GirFFI::UserDefinedObjectInfo.new klass do |it|
311
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
312
312
  it.install_property GObject.param_spec_uint64('the-prop', 'the property',
313
313
  'The Property',
314
314
  10, 100, 15,
@@ -317,7 +317,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
317
317
  end
318
318
 
319
319
  it 'creates accessor functions for the property' do
320
- obj = klass.new
320
+ obj = derived_class.new
321
321
  obj.the_prop = 423_432
322
322
  obj.the_prop.must_equal 423_432
323
323
  end
@@ -326,7 +326,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
326
326
  describe 'with a float property' do
327
327
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
328
328
  let(:info) do
329
- GirFFI::UserDefinedObjectInfo.new klass do |it|
329
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
330
330
  it.install_property GObject.param_spec_float('the-prop', 'the property',
331
331
  'The Property',
332
332
  10.0, 100.0, 15.0,
@@ -335,7 +335,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
335
335
  end
336
336
 
337
337
  it 'creates accessor functions for the property' do
338
- obj = klass.new
338
+ obj = derived_class.new
339
339
  obj.the_prop = 42.23
340
340
  obj.the_prop.must_be_within_epsilon 42.23
341
341
  end
@@ -344,7 +344,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
344
344
  describe 'with a double property' do
345
345
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
346
346
  let(:info) do
347
- GirFFI::UserDefinedObjectInfo.new klass do |it|
347
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
348
348
  it.install_property GObject.param_spec_double('the-prop', 'the property',
349
349
  'The Property',
350
350
  10.0, 100.0, 15.0,
@@ -353,7 +353,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
353
353
  end
354
354
 
355
355
  it 'creates accessor functions for the property' do
356
- obj = klass.new
356
+ obj = derived_class.new
357
357
  obj.the_prop = 42.23
358
358
  obj.the_prop.must_equal 42.23
359
359
  end
@@ -362,7 +362,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
362
362
  describe 'with an enum property' do
363
363
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
364
364
  let(:info) do
365
- GirFFI::UserDefinedObjectInfo.new klass do |it|
365
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
366
366
  prop = GObject.param_spec_enum('the-prop', 'the property',
367
367
  'The Property',
368
368
  GIMarshallingTests::GEnum.gtype, 0,
@@ -372,7 +372,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
372
372
  end
373
373
 
374
374
  it 'creates accessor functions for the property' do
375
- obj = klass.new
375
+ obj = derived_class.new
376
376
  obj.the_prop = :value2
377
377
  obj.the_prop.must_equal :value2
378
378
  end
@@ -381,7 +381,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
381
381
  describe 'with a flags property' do
382
382
  let(:object_gtype) { GIMarshallingTests::Object.gtype }
383
383
  let(:info) do
384
- GirFFI::UserDefinedObjectInfo.new klass do |it|
384
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
385
385
  prop = GObject.param_spec_flags('the-prop', 'the property',
386
386
  'The Property',
387
387
  GIMarshallingTests::Flags.gtype, 0,
@@ -391,7 +391,7 @@ describe GirFFI::Builders::UserDefinedBuilder do
391
391
  end
392
392
 
393
393
  it 'creates accessor functions for the property' do
394
- obj = klass.new
394
+ obj = derived_class.new
395
395
  obj.the_prop = { value2: true }
396
396
  obj.the_prop.must_equal value2: true
397
397
  end
@@ -402,11 +402,11 @@ describe GirFFI::Builders::UserDefinedBuilder do
402
402
  let(:parent_size) do
403
403
  GObject.type_query(parent_class.gtype).instance_size
404
404
  end
405
- let(:klass) do
405
+ let(:derived_class) do
406
406
  Object.const_set("DerivedClass#{Sequence.next}", Class.new(parent_class))
407
407
  end
408
408
  let(:info) do
409
- GirFFI::UserDefinedObjectInfo.new klass do |it|
409
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
410
410
  it.install_property GObject.param_spec_int('int-prop', 'integer property',
411
411
  'Integer Property',
412
412
  10, 20, 15,
@@ -415,33 +415,33 @@ describe GirFFI::Builders::UserDefinedBuilder do
415
415
  end
416
416
 
417
417
  it 'registers a type that is bigger than the parent' do
418
- klass_size = GObject.type_query(klass.gtype).instance_size
419
- klass_size.must_be :>, parent_size
418
+ class_size = GObject.type_query(derived_class.gtype).instance_size
419
+ class_size.must_be :>, parent_size
420
420
  end
421
421
 
422
422
  it 'leaves enough space in derived struct layout' do
423
- struct_size = klass::Struct.size
423
+ struct_size = derived_class::Struct.size
424
424
  struct_size.must_be :>, parent_size
425
425
  end
426
426
  end
427
427
 
428
428
  describe 'with type info containing an overridden g_name' do
429
429
  let(:info) do
430
- GirFFI::UserDefinedObjectInfo.new klass do |it|
430
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
431
431
  it.g_name = "OtherName#{Sequence.next}"
432
432
  end
433
433
  end
434
434
 
435
435
  it 'registers a type under the overridden name' do
436
- registered_name = GObject.type_name(klass.gtype)
436
+ registered_name = GObject.type_name(derived_class.gtype)
437
437
  registered_name.must_equal info.g_name
438
- registered_name.wont_equal klass.name
438
+ registered_name.wont_equal derived_class.name
439
439
  end
440
440
  end
441
441
 
442
442
  describe 'with type info containing a vfunc' do
443
443
  let(:info) do
444
- GirFFI::UserDefinedObjectInfo.new klass do |it|
444
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
445
445
  it.install_vfunc_implementation :method_int8_in, proc { |instance, in_|
446
446
  instance.int = in_
447
447
  }
@@ -449,22 +449,22 @@ describe GirFFI::Builders::UserDefinedBuilder do
449
449
  end
450
450
 
451
451
  it 'allows the vfunc to be called through its invoker' do
452
- obj = klass.new
452
+ obj = derived_class.new
453
453
  obj.method_int8_in 12
454
454
  obj.int.must_equal 12
455
455
  end
456
456
  end
457
457
 
458
458
  describe 'when using a default vfunc implementation' do
459
- let(:base_klass) { Regress::TestObj }
459
+ let(:base_class) { Regress::TestObj }
460
460
  let(:info) do
461
- GirFFI::UserDefinedObjectInfo.new klass do |it|
461
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
462
462
  it.install_vfunc_implementation :matrix
463
463
  end
464
464
  end
465
465
 
466
466
  before do
467
- klass.class_eval do
467
+ derived_class.class_eval do
468
468
  def matrix(_arg)
469
469
  44
470
470
  end
@@ -472,15 +472,15 @@ describe GirFFI::Builders::UserDefinedBuilder do
472
472
  end
473
473
 
474
474
  it 'allows the vfunc to be called through its invoker' do
475
- obj = klass.new
475
+ obj = derived_class.new
476
476
  obj.do_matrix('bar').must_equal 44
477
477
  end
478
478
  end
479
479
 
480
480
  describe 'with type info containing a vfunc from an included Interface' do
481
481
  let(:info) do
482
- klass.class_eval { include GIMarshallingTests::Interface }
483
- GirFFI::UserDefinedObjectInfo.new klass do |it|
482
+ derived_class.class_eval { include GIMarshallingTests::Interface }
483
+ GirFFI::UserDefinedObjectInfo.new derived_class do |it|
484
484
  it.install_vfunc_implementation :test_int8_in,
485
485
  proc { |instance, in_| instance.int = in_ }
486
486
  end
@@ -488,30 +488,30 @@ describe GirFFI::Builders::UserDefinedBuilder do
488
488
 
489
489
  it 'marks the type as conforming to the included Interface' do
490
490
  iface_gtype = GIMarshallingTests::Interface.gtype
491
- GObject.type_interfaces(klass.gtype).to_a.must_equal [iface_gtype]
491
+ GObject.type_interfaces(derived_class.gtype).to_a.must_equal [iface_gtype]
492
492
  end
493
493
 
494
494
  it 'allows the vfunc to be called through its invoker' do
495
- obj = klass.new
495
+ obj = derived_class.new
496
496
  obj.test_int8_in 12
497
497
  obj.int.must_equal 12
498
498
  end
499
499
  end
500
500
 
501
501
  it 'keeps the gtype for an already registered class' do
502
- gtype = klass.gtype
502
+ gtype = derived_class.gtype
503
503
  other_builder = GirFFI::Builders::UserDefinedBuilder.new info
504
- other_klass = other_builder.build_class
505
- other_klass.gtype.must_equal gtype
504
+ other_class = other_builder.build_class
505
+ other_class.gtype.must_equal gtype
506
506
  end
507
507
 
508
508
  it 'creates a class with a new GType' do
509
- klass.gtype.wont_equal GIMarshallingTests::Object.gtype
509
+ derived_class.gtype.wont_equal GIMarshallingTests::Object.gtype
510
510
  end
511
511
 
512
512
  it 'makes the registered class return objects with the correct GType' do
513
- obj = klass.new
514
- GObject.type_from_instance(obj).must_equal klass.gtype
513
+ obj = derived_class.new
514
+ GObject.type_from_instance(obj).must_equal derived_class.gtype
515
515
  end
516
516
  end
517
517