gir_ffi 0.15.1 → 0.15.6
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.
- checksums.yaml +4 -4
- data/Changelog.md +42 -0
- data/README.md +10 -10
- data/TODO.md +14 -35
- data/docs/Documentation.md +6 -0
- data/docs/Subclassing.md +38 -0
- data/lib/ffi-glib.rb +8 -3
- data/lib/ffi-glib/byte_array.rb +2 -1
- data/lib/ffi-glib/container_class_methods.rb +1 -3
- data/lib/ffi-glib/destroy_notify.rb +2 -2
- data/lib/ffi-glib/hash_table.rb +1 -2
- data/lib/ffi-glib/list.rb +11 -5
- data/lib/ffi-glib/list_methods.rb +12 -0
- data/lib/ffi-glib/s_list.rb +10 -4
- data/lib/ffi-gobject.rb +2 -5
- data/lib/ffi-gobject/object.rb +102 -92
- data/lib/ffi-gobject/object_class.rb +1 -1
- data/lib/ffi-gobject/ruby_closure.rb +1 -1
- data/lib/ffi-gobject/value.rb +108 -117
- data/lib/ffi-gobject_introspection/i_base_info.rb +35 -27
- data/lib/ffi-gobject_introspection/lib.rb +1 -1
- data/lib/gir_ffi-base/gobject/lib.rb +4 -0
- data/lib/gir_ffi/array_element_convertor.rb +2 -3
- data/lib/gir_ffi/boxed_base.rb +13 -11
- data/lib/gir_ffi/builder.rb +3 -4
- data/lib/gir_ffi/builder_helper.rb +10 -2
- data/lib/gir_ffi/builders/base_argument_builder.rb +2 -2
- data/lib/gir_ffi/builders/base_method_builder.rb +1 -1
- data/lib/gir_ffi/builders/base_type_builder.rb +1 -1
- data/lib/gir_ffi/builders/callback_argument_builder.rb +2 -0
- data/lib/gir_ffi/builders/callback_builder.rb +25 -11
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +4 -6
- data/lib/gir_ffi/builders/enum_builder.rb +9 -5
- data/lib/gir_ffi/builders/field_builder.rb +2 -1
- data/lib/gir_ffi/builders/function_builder.rb +1 -1
- data/lib/gir_ffi/builders/interface_builder.rb +3 -1
- data/lib/gir_ffi/builders/mapping_method_builder.rb +1 -1
- data/lib/gir_ffi/builders/marshalling_method_builder.rb +5 -2
- data/lib/gir_ffi/builders/method_template.rb +4 -4
- data/lib/gir_ffi/builders/module_builder.rb +4 -2
- data/lib/gir_ffi/builders/null_argument_builder.rb +0 -2
- data/lib/gir_ffi/builders/null_return_value_builder.rb +0 -2
- data/lib/gir_ffi/builders/object_builder.rb +18 -6
- data/lib/gir_ffi/builders/property_builder.rb +1 -2
- data/lib/gir_ffi/builders/signal_closure_builder.rb +3 -5
- data/lib/gir_ffi/builders/struct_builder.rb +34 -7
- data/lib/gir_ffi/builders/user_defined_builder.rb +8 -1
- data/lib/gir_ffi/builders/vfunc_argument_builder.rb +1 -1
- data/lib/gir_ffi/callback_base.rb +7 -8
- data/lib/gir_ffi/class_base.rb +1 -0
- data/lib/gir_ffi/core.rb +17 -2
- data/lib/gir_ffi/glib_error.rb +1 -2
- data/lib/gir_ffi/in_pointer.rb +7 -0
- data/lib/gir_ffi/object_base.rb +27 -0
- data/lib/gir_ffi/return_value_info.rb +1 -2
- data/lib/gir_ffi/struct_base.rb +1 -9
- data/lib/gir_ffi/struct_like_base.rb +9 -5
- data/lib/gir_ffi/type_map.rb +1 -0
- data/lib/gir_ffi/unintrospectable_type_info.rb +1 -1
- data/lib/gir_ffi/union_base.rb +1 -9
- data/lib/gir_ffi/user_defined_object_info.rb +3 -2
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi/vfunc_implementation.rb +1 -0
- metadata +106 -143
- data/Gemfile +0 -14
- data/Rakefile +0 -9
- data/tasks/test.rake +0 -204
- data/test/base_test_helper.rb +0 -70
- data/test/ffi-glib/array_test.rb +0 -203
- data/test/ffi-glib/byte_array_test.rb +0 -28
- data/test/ffi-glib/bytes_test.rb +0 -61
- data/test/ffi-glib/closure_test.rb +0 -38
- data/test/ffi-glib/destroy_notify_test.rb +0 -18
- data/test/ffi-glib/hash_table_test.rb +0 -68
- data/test/ffi-glib/list_test.rb +0 -86
- data/test/ffi-glib/main_loop_test.rb +0 -53
- data/test/ffi-glib/ptr_array_test.rb +0 -112
- data/test/ffi-glib/ruby_closure_test.rb +0 -62
- data/test/ffi-glib/s_list_test.rb +0 -76
- data/test/ffi-glib/strv_test.rb +0 -60
- data/test/ffi-glib/variant_test.rb +0 -12
- data/test/ffi-gobject/gobject_test.rb +0 -76
- data/test/ffi-gobject/object_class_test.rb +0 -31
- data/test/ffi-gobject/object_test.rb +0 -122
- data/test/ffi-gobject/param_spec_test.rb +0 -32
- data/test/ffi-gobject/value_test.rb +0 -390
- data/test/ffi-gobject_introspection/gobject_type_init_test.rb +0 -26
- data/test/ffi-gobject_introspection/i_base_info_test.rb +0 -52
- data/test/ffi-gobject_introspection/i_constant_info_test.rb +0 -29
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +0 -18
- data/test/ffi-gobject_introspection/i_function_info_test.rb +0 -6
- data/test/ffi-gobject_introspection/i_interface_info_test.rb +0 -23
- data/test/ffi-gobject_introspection/i_object_info_test.rb +0 -49
- data/test/ffi-gobject_introspection/i_property_info_test.rb +0 -47
- data/test/ffi-gobject_introspection/i_registered_type_info_test.rb +0 -27
- data/test/ffi-gobject_introspection/i_repository_test.rb +0 -81
- data/test/ffi-gobject_introspection/i_struct_info_test.rb +0 -23
- data/test/ffi-gobject_introspection/i_type_info_test.rb +0 -30
- data/test/ffi-gobject_introspection/i_union_info_test.rb +0 -17
- data/test/ffi-gobject_introspection/i_vfunc_info_test.rb +0 -41
- data/test/ffi-gobject_introspection/lib_test.rb +0 -13
- data/test/ffi-gobject_introspection/strv_test.rb +0 -46
- data/test/ffi-gobject_test.rb +0 -151
- data/test/gir_ffi/allocation_helper_test.rb +0 -36
- data/test/gir_ffi/arg_helper_test.rb +0 -139
- data/test/gir_ffi/boolean_test.rb +0 -43
- data/test/gir_ffi/boxed_base_test.rb +0 -65
- data/test/gir_ffi/builder_test.rb +0 -322
- data/test/gir_ffi/builders/argument_builder_test.rb +0 -651
- data/test/gir_ffi/builders/base_argument_builder_test.rb +0 -6
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +0 -126
- data/test/gir_ffi/builders/callback_builder_test.rb +0 -117
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +0 -81
- data/test/gir_ffi/builders/constant_builder_test.rb +0 -6
- data/test/gir_ffi/builders/constructor_builder_test.rb +0 -37
- data/test/gir_ffi/builders/enum_builder_test.rb +0 -23
- data/test/gir_ffi/builders/field_builder_test.rb +0 -134
- data/test/gir_ffi/builders/function_builder_test.rb +0 -550
- data/test/gir_ffi/builders/initializer_builder_test.rb +0 -54
- data/test/gir_ffi/builders/interface_builder_test.rb +0 -32
- data/test/gir_ffi/builders/module_builder_test.rb +0 -43
- data/test/gir_ffi/builders/object_builder_test.rb +0 -98
- data/test/gir_ffi/builders/property_builder_test.rb +0 -158
- data/test/gir_ffi/builders/registered_type_builder_test.rb +0 -54
- data/test/gir_ffi/builders/return_value_builder_test.rb +0 -433
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +0 -197
- data/test/gir_ffi/builders/struct_builder_test.rb +0 -93
- data/test/gir_ffi/builders/unintrospectable_boxed_builder_test.rb +0 -29
- data/test/gir_ffi/builders/unintrospectable_builder_test.rb +0 -84
- data/test/gir_ffi/builders/union_builder_test.rb +0 -28
- data/test/gir_ffi/builders/user_defined_builder_test.rb +0 -524
- data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +0 -101
- data/test/gir_ffi/builders/vfunc_builder_test.rb +0 -241
- data/test/gir_ffi/callback_base_test.rb +0 -22
- data/test/gir_ffi/class_base_test.rb +0 -166
- data/test/gir_ffi/core_test.rb +0 -98
- data/test/gir_ffi/enum_base_test.rb +0 -43
- data/test/gir_ffi/error_type_info_test.rb +0 -50
- data/test/gir_ffi/ffi_ext/pointer_test.rb +0 -20
- data/test/gir_ffi/g_type_test.rb +0 -31
- data/test/gir_ffi/in_pointer_test.rb +0 -203
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +0 -26
- data/test/gir_ffi/info_ext/i_callback_info_test.rb +0 -21
- data/test/gir_ffi/info_ext/i_field_info_test.rb +0 -37
- data/test/gir_ffi/info_ext/i_function_info_test.rb +0 -74
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +0 -32
- data/test/gir_ffi/info_ext/i_type_info_test.rb +0 -711
- data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +0 -19
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +0 -26
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +0 -26
- data/test/gir_ffi/interface_base_test.rb +0 -20
- data/test/gir_ffi/method_stubber_test.rb +0 -65
- data/test/gir_ffi/object_base_test.rb +0 -64
- data/test/gir_ffi/object_store_test.rb +0 -41
- data/test/gir_ffi/receiver_argument_info_test.rb +0 -33
- data/test/gir_ffi/sized_array_test.rb +0 -206
- data/test/gir_ffi/struct_base_test.rb +0 -23
- data/test/gir_ffi/struct_like_base_test.rb +0 -167
- data/test/gir_ffi/type_map_test.rb +0 -17
- data/test/gir_ffi/unintrospectable_type_info_test.rb +0 -121
- data/test/gir_ffi/union_base_test.rb +0 -23
- data/test/gir_ffi/user_defined_object_info_test.rb +0 -119
- data/test/gir_ffi/user_defined_property_info_test.rb +0 -39
- data/test/gir_ffi/variable_name_generator_test.rb +0 -18
- data/test/gir_ffi/version_test.rb +0 -9
- data/test/gir_ffi/zero_terminated_test.rb +0 -108
- data/test/gir_ffi_test_helper.rb +0 -84
- data/test/integration/callback_exceptions_test.rb +0 -59
- data/test/integration/derived_classes_test.rb +0 -53
- data/test/integration/generated_everything_test.rb +0 -452
- data/test/integration/generated_gimarshallingtests_test.rb +0 -3096
- data/test/integration/generated_gio_test.rb +0 -116
- data/test/integration/generated_glib_test.rb +0 -10
- data/test/integration/generated_gobject_test.rb +0 -124
- data/test/integration/generated_gst_test.rb +0 -38
- data/test/integration/generated_gtk_source_test.rb +0 -32
- data/test/integration/generated_gtop_test.rb +0 -22
- data/test/integration/generated_pango_ft2_test.rb +0 -17
- data/test/integration/generated_pango_test.rb +0 -24
- data/test/integration/generated_regress_test.rb +0 -4038
- data/test/integration/generated_secret_test.rb +0 -14
- data/test/integration/generated_utility_test.rb +0 -174
- data/test/integration/generated_warnlib_test.rb +0 -43
- data/test/integration/method_lookup_test.rb +0 -34
- data/test/introspection_test_helper.rb +0 -93
- data/test/lib/Makefile.am +0 -110
- data/test/lib/autogen.sh +0 -4
- data/test/lib/configure.ac +0 -34
- data/test/lib/m4/jhflags.m4 +0 -21
- data/test/minitest/stats_plugin.rb +0 -30
data/Gemfile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
# The gem's dependencies are specified in gir_ffi.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
gem "pry", "~> 0.12.0"
|
9
|
-
gem "ruby-prof", platform: :mri
|
10
|
-
gem "test-prof", platform: :mri
|
11
|
-
|
12
|
-
if ENV["CI"]
|
13
|
-
gem "coveralls", group: :development if ENV["TRAVIS_RUBY_VERSION"] == "2.4"
|
14
|
-
end
|
data/Rakefile
DELETED
data/tasks/test.rake
DELETED
@@ -1,204 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'cucumber/rake/task'
|
5
|
-
|
6
|
-
require 'rexml/document'
|
7
|
-
require 'rexml/streamlistener'
|
8
|
-
|
9
|
-
# Listener class used to process GIR xml data, for creating test stubs.
|
10
|
-
class Listener
|
11
|
-
include REXML::StreamListener
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
@inside_class = false
|
15
|
-
@stack = []
|
16
|
-
@skip_state = []
|
17
|
-
end
|
18
|
-
|
19
|
-
attr_accessor :result
|
20
|
-
attr_accessor :namespace
|
21
|
-
|
22
|
-
def tag_start(name, attrs)
|
23
|
-
@stack.push [name, attrs]
|
24
|
-
if @skip_state.last || skippable?(attrs)
|
25
|
-
@skip_state.push true
|
26
|
-
return
|
27
|
-
else
|
28
|
-
@skip_state.push false
|
29
|
-
end
|
30
|
-
|
31
|
-
obj_name = attrs['name']
|
32
|
-
case name
|
33
|
-
when 'constant'
|
34
|
-
result.puts " it 'has the constant #{obj_name}' do"
|
35
|
-
when 'record', 'class', 'enumeration', 'bitfield', 'interface', 'union'
|
36
|
-
result.puts " describe '#{namespace}::#{obj_name}' do"
|
37
|
-
@inside_class = name
|
38
|
-
when 'constructor'
|
39
|
-
result.puts " it 'creates an instance using ##{obj_name}' do"
|
40
|
-
when 'field'
|
41
|
-
if @inside_class != 'class'
|
42
|
-
if attrs['private'] == '1'
|
43
|
-
result.puts " it 'has a private field #{obj_name}' do"
|
44
|
-
elsif attrs['writable'] == '1'
|
45
|
-
result.puts " it 'has a writable field #{obj_name}' do"
|
46
|
-
else
|
47
|
-
result.puts " it 'has a read-only field #{obj_name}' do"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
when 'function', 'method'
|
51
|
-
spaces = @inside_class ? ' ' : ''
|
52
|
-
result.puts " #{spaces}it 'has a working #{name} ##{obj_name}' do"
|
53
|
-
when 'member'
|
54
|
-
result.puts " it 'has the member :#{obj_name}' do"
|
55
|
-
when 'namespace'
|
56
|
-
result.puts "describe #{obj_name} do"
|
57
|
-
when 'property'
|
58
|
-
accessor_name = obj_name.tr('-', '_')
|
59
|
-
result.puts " describe \"its '#{obj_name}' property\" do"
|
60
|
-
result.puts " it 'can be retrieved with #get_property' do"
|
61
|
-
result.puts ' end'
|
62
|
-
result.puts " it 'can be retrieved with ##{accessor_name}' do"
|
63
|
-
result.puts ' end'
|
64
|
-
if attrs['writable'] == '1'
|
65
|
-
result.puts " it 'can be set with #set_property' do"
|
66
|
-
result.puts ' end'
|
67
|
-
result.puts " it 'can be set with ##{accessor_name}=' do"
|
68
|
-
result.puts ' end'
|
69
|
-
end
|
70
|
-
when 'glib:signal'
|
71
|
-
result.puts " it \"handles the '#{obj_name}' signal\" do"
|
72
|
-
when 'type', 'alias', 'return-value', 'parameters',
|
73
|
-
'instance-parameter', 'parameter', 'doc', 'array',
|
74
|
-
'repository', 'include', 'package', 'source-position'
|
75
|
-
# Not printed"
|
76
|
-
else
|
77
|
-
puts "Skipping #{name}: #{attrs}"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def tag_end(name)
|
82
|
-
org_name, = *@stack.pop
|
83
|
-
skipping = @skip_state.pop
|
84
|
-
raise "Expected #{org_name}, got #{name}" if org_name != name
|
85
|
-
return if skipping
|
86
|
-
|
87
|
-
case name
|
88
|
-
when 'constant'
|
89
|
-
result.puts ' end'
|
90
|
-
when 'record', 'class', 'enumeration', 'bitfield',
|
91
|
-
'interface', 'union'
|
92
|
-
result.puts ' end'
|
93
|
-
@inside_class = false
|
94
|
-
when 'function', 'method'
|
95
|
-
if @inside_class
|
96
|
-
result.puts ' end'
|
97
|
-
else
|
98
|
-
result.puts ' end'
|
99
|
-
end
|
100
|
-
when 'constructor', 'member', 'property', 'glib:signal'
|
101
|
-
result.puts ' end'
|
102
|
-
when 'field'
|
103
|
-
result.puts ' end' if @inside_class != 'class'
|
104
|
-
when 'namespace'
|
105
|
-
result.puts 'end'
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def skippable?(attrs)
|
110
|
-
return true if attrs['disguised'] == '1'
|
111
|
-
return true if attrs['introspectable'] == '0'
|
112
|
-
return true if attrs['glib:is-gtype-struct-for']
|
113
|
-
|
114
|
-
false
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
namespace :test do
|
119
|
-
def define_test_task(name)
|
120
|
-
Rake::TestTask.new(name) do |t|
|
121
|
-
t.libs = ['lib']
|
122
|
-
t.ruby_opts += ['-w -Itest']
|
123
|
-
yield t
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
define_test_task(:base) do |t|
|
128
|
-
t.test_files = FileList['test/gir_ffi-base/**/*_test.rb']
|
129
|
-
end
|
130
|
-
|
131
|
-
define_test_task(:introspection) do |t|
|
132
|
-
t.test_files = FileList['test/ffi-gobject_introspection/**/*_test.rb']
|
133
|
-
end
|
134
|
-
|
135
|
-
define_test_task(:main) do |t|
|
136
|
-
t.test_files = FileList['test/gir_ffi/**/*_test.rb']
|
137
|
-
end
|
138
|
-
|
139
|
-
define_test_task(:overrides) do |t|
|
140
|
-
t.test_files = FileList['test/ffi-gobject_test.rb',
|
141
|
-
'test/ffi-glib/**/*_test.rb',
|
142
|
-
'test/ffi-gobject/**/*_test.rb']
|
143
|
-
end
|
144
|
-
|
145
|
-
define_test_task(:integration) do |t|
|
146
|
-
t.test_files = FileList['test/integration/**/*_test.rb']
|
147
|
-
end
|
148
|
-
|
149
|
-
desc 'Build test libraries and typelibs'
|
150
|
-
task lib: 'test/lib/Makefile' do
|
151
|
-
sh %(cd test/lib && make)
|
152
|
-
end
|
153
|
-
|
154
|
-
task introspection: :lib
|
155
|
-
task main: :lib
|
156
|
-
task overrides: :lib
|
157
|
-
task integration: :lib
|
158
|
-
|
159
|
-
desc 'Run the entire test suite as one with simplecov activated'
|
160
|
-
define_test_task(:all) do |t|
|
161
|
-
t.test_files = FileList['test/**/*_test.rb']
|
162
|
-
t.ruby_opts += ['-rbundler/setup -rsimplecov -w -Itest']
|
163
|
-
end
|
164
|
-
|
165
|
-
task all: :lib
|
166
|
-
|
167
|
-
desc 'Run all individual test suites separately'
|
168
|
-
task suites: [:base,
|
169
|
-
:introspection,
|
170
|
-
:main,
|
171
|
-
:overrides,
|
172
|
-
:integration]
|
173
|
-
|
174
|
-
def make_stub_file(libname)
|
175
|
-
file = File.new "test/lib/#{libname}-1.0.gir"
|
176
|
-
listener = Listener.new
|
177
|
-
listener.result = File.open("tmp/#{libname.downcase}_lines.rb", 'w')
|
178
|
-
listener.namespace = libname
|
179
|
-
REXML::Document.parse_stream file, listener
|
180
|
-
end
|
181
|
-
|
182
|
-
desc 'Create stubs for integration tests'
|
183
|
-
task stub: :lib do
|
184
|
-
make_stub_file 'Everything'
|
185
|
-
make_stub_file 'GIMarshallingTests'
|
186
|
-
make_stub_file 'Regress'
|
187
|
-
make_stub_file 'Utility'
|
188
|
-
make_stub_file 'WarnLib'
|
189
|
-
end
|
190
|
-
|
191
|
-
Cucumber::Rake::Task.new(:features) do |t|
|
192
|
-
t.cucumber_opts = 'features --format pretty'
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
file 'test/lib/Makefile' => 'test/lib/configure' do
|
197
|
-
sh %(cd test/lib && ./configure --enable-maintainer-mode)
|
198
|
-
end
|
199
|
-
|
200
|
-
file 'test/lib/configure' => ['test/lib/autogen.sh', 'test/lib/configure.ac'] do
|
201
|
-
sh %(cd test/lib && ./autogen.sh)
|
202
|
-
end
|
203
|
-
|
204
|
-
task test: 'test:all'
|
data/test/base_test_helper.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
old_verbose = $VERBOSE
|
4
|
-
$VERBOSE = false
|
5
|
-
begin
|
6
|
-
require "test-prof"
|
7
|
-
|
8
|
-
TestProf::RubyProf.configure do |config|
|
9
|
-
config.min_percent = 0.5
|
10
|
-
end
|
11
|
-
rescue LoadError
|
12
|
-
warn "test-prof not available"
|
13
|
-
end
|
14
|
-
$VERBOSE = old_verbose
|
15
|
-
|
16
|
-
if ENV["CI"]
|
17
|
-
begin
|
18
|
-
require "coveralls"
|
19
|
-
Coveralls.wear!
|
20
|
-
rescue LoadError
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
require "minitest/autorun"
|
26
|
-
require "rspec/mocks/minitest_integration"
|
27
|
-
|
28
|
-
Thread.abort_on_exception = true
|
29
|
-
|
30
|
-
module BaseTestExtensions
|
31
|
-
def assert_defines_singleton_method(klass, method, msg = nil)
|
32
|
-
method = method.to_sym
|
33
|
-
methods = klass.singleton_methods(false).map(&:to_sym)
|
34
|
-
msg = message(msg) do
|
35
|
-
"Expected #{mu_pp(klass)} to define singleton method #{mu_pp(method)}, " \
|
36
|
-
"but only found #{mu_pp(methods)}"
|
37
|
-
end
|
38
|
-
assert_includes methods, method, msg
|
39
|
-
end
|
40
|
-
|
41
|
-
def refute_defines_singleton_method(klass, method, msg = nil)
|
42
|
-
method = method.to_sym
|
43
|
-
methods = klass.singleton_methods(false).map(&:to_sym)
|
44
|
-
msg = message(msg) do
|
45
|
-
"Expected #{mu_pp(klass)} not to define singleton method #{mu_pp(method)}"
|
46
|
-
end
|
47
|
-
refute_includes methods, method, msg
|
48
|
-
end
|
49
|
-
|
50
|
-
def assert_defines_instance_method(klass, method, msg = nil)
|
51
|
-
method = method.to_sym
|
52
|
-
methods = klass.instance_methods(false).map(&:to_sym)
|
53
|
-
msg = message(msg) do
|
54
|
-
"Expected #{mu_pp(klass)} to define instance method #{mu_pp(method)}, " \
|
55
|
-
"but only found #{mu_pp(methods)}"
|
56
|
-
end
|
57
|
-
assert_includes methods, method, msg
|
58
|
-
end
|
59
|
-
|
60
|
-
def refute_defines_instance_method(klass, method, msg = nil)
|
61
|
-
method = method.to_sym
|
62
|
-
methods = klass.instance_methods(false).map(&:to_sym)
|
63
|
-
msg = message(msg) do
|
64
|
-
"Expected #{mu_pp(klass)} not to define instance method #{mu_pp(method)}"
|
65
|
-
end
|
66
|
-
refute_includes methods, method, msg
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
Minitest::Test.include BaseTestExtensions
|
data/test/ffi-glib/array_test.rb
DELETED
@@ -1,203 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GLib::Array do
|
6
|
-
it "knows its element type" do
|
7
|
-
arr = GLib::Array.new :gint32
|
8
|
-
assert_equal :gint32, arr.element_type
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#append_vals" do
|
12
|
-
before do
|
13
|
-
@arr = GLib::Array.new :gint32
|
14
|
-
@result = @arr.append_vals [1, 2, 3]
|
15
|
-
end
|
16
|
-
|
17
|
-
it "appends values" do
|
18
|
-
assert_equal 3, @arr.len
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns self" do
|
22
|
-
assert_equal @result, @arr
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "#each" do
|
27
|
-
before do
|
28
|
-
@arr = GLib::Array.new(:gint32).append_vals [1, 2, 3]
|
29
|
-
end
|
30
|
-
|
31
|
-
it "iterates over the values" do
|
32
|
-
a = []
|
33
|
-
@arr.each { |v| a << v }
|
34
|
-
|
35
|
-
assert_equal [1, 2, 3], a
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "::wrap" do
|
40
|
-
it "wraps a pointer, taking the element type as the first argument" do
|
41
|
-
arr = GLib::Array.new :gint32
|
42
|
-
arr.append_vals [1, 2, 3]
|
43
|
-
arr2 = GLib::Array.wrap :gint32, arr.to_ptr
|
44
|
-
assert_equal arr.to_a, arr2.to_a
|
45
|
-
end
|
46
|
-
|
47
|
-
it "warns the element sizes don't match" do
|
48
|
-
arr = GLib::Array.new :gint32
|
49
|
-
arr.append_vals [1, 2, 3]
|
50
|
-
_(proc { GLib::Array.wrap :gint8, arr.to_ptr }).must_output nil, /sizes do not match/
|
51
|
-
end
|
52
|
-
|
53
|
-
it "handles a struct as the element type" do
|
54
|
-
vals = [1, 2, 3].map { |i| GObject::EnumValue.new.tap { |ev| ev.value = i } }
|
55
|
-
arr = GLib::Array.new GObject::EnumValue
|
56
|
-
arr.append_vals vals
|
57
|
-
arr2 = GLib::Array.wrap GObject::EnumValue, arr.to_ptr
|
58
|
-
_(arr2.to_a).must_equal arr.to_a
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "includes Enumerable" do
|
63
|
-
_(GLib::Array).must_include Enumerable
|
64
|
-
end
|
65
|
-
|
66
|
-
it "has a working #to_a method" do
|
67
|
-
arr = GLib::Array.new :gint32
|
68
|
-
arr.append_vals [1, 2, 3]
|
69
|
-
assert_equal [1, 2, 3], arr.to_a
|
70
|
-
end
|
71
|
-
|
72
|
-
describe ".from" do
|
73
|
-
it "creates a GArray from an array of :gint32" do
|
74
|
-
arr = GLib::Array.from :gint32, [3, 2, 1]
|
75
|
-
_(arr).must_be_instance_of GLib::Array
|
76
|
-
_(arr.to_a).must_equal [3, 2, 1]
|
77
|
-
end
|
78
|
-
|
79
|
-
it "creates a GArray from an array of :gboolean" do
|
80
|
-
arr = GLib::Array.from :gboolean, [true, false, true]
|
81
|
-
_(arr).must_be_instance_of GLib::Array
|
82
|
-
_(arr.to_a).must_equal [true, false, true]
|
83
|
-
end
|
84
|
-
|
85
|
-
it "creates a GArray from an array of :utf8 values" do
|
86
|
-
arr = GLib::Array.from :utf8, %w(hello there)
|
87
|
-
_(arr).must_be_instance_of GLib::Array
|
88
|
-
_(arr.to_a).must_equal %w(hello there)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "creates a GArray from an array of struct values" do
|
92
|
-
values = [1, 2, 3].map do |val|
|
93
|
-
GObject::EnumValue.new.tap { |it| it.value = val }
|
94
|
-
end
|
95
|
-
arr = GLib::Array.from GObject::EnumValue, values
|
96
|
-
_(arr).must_be_instance_of GLib::Array
|
97
|
-
_(arr.to_a.map(&:value)).must_equal [1, 2, 3]
|
98
|
-
end
|
99
|
-
|
100
|
-
it "return its argument if given a GArray" do
|
101
|
-
arr = GLib::Array.new :gint32
|
102
|
-
arr.append_vals [3, 2, 1]
|
103
|
-
arr2 = GLib::Array.from :gint32, arr
|
104
|
-
assert arr2.equal? arr
|
105
|
-
end
|
106
|
-
|
107
|
-
it "wraps its argument if given a pointer" do
|
108
|
-
arr = GLib::Array.new :gint32
|
109
|
-
arr.append_vals [3, 2, 1]
|
110
|
-
pointer = arr.to_ptr
|
111
|
-
assert_instance_of FFI::Pointer, pointer
|
112
|
-
arr2 = GLib::Array.from :gint32, pointer
|
113
|
-
assert_instance_of GLib::Array, arr2
|
114
|
-
refute arr2.equal? arr
|
115
|
-
_(arr2.to_a).must_equal arr.to_a
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "#==" do
|
120
|
-
it "returns true when comparing to an array with the same elements" do
|
121
|
-
arr = GLib::Array.from :gint32, [1, 2, 3]
|
122
|
-
|
123
|
-
_(arr).must_be :==, [1, 2, 3]
|
124
|
-
end
|
125
|
-
|
126
|
-
it "returns false when comparing to an array with different elements" do
|
127
|
-
arr = GLib::Array.from :gint32, [1, 2, 3]
|
128
|
-
|
129
|
-
_(arr).wont_be :==, [1, 2]
|
130
|
-
end
|
131
|
-
|
132
|
-
it "returns true when comparing to a GArray with the same elements" do
|
133
|
-
arr = GLib::Array.from :gint32, [1, 2, 3]
|
134
|
-
other = GLib::Array.from :gint32, [1, 2, 3]
|
135
|
-
|
136
|
-
_(arr).must_be :==, other
|
137
|
-
end
|
138
|
-
|
139
|
-
it "returns false when comparing to a GArray with different elements" do
|
140
|
-
arr = GLib::Array.from :gint32, [1, 2, 3]
|
141
|
-
other = GLib::Array.from :gint32, [1, 2]
|
142
|
-
|
143
|
-
_(arr).wont_be :==, other
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "#index" do
|
148
|
-
it "returns the proper element for an array of :gint32" do
|
149
|
-
arr = GLib::Array.from :gint32, [1, 2, 3]
|
150
|
-
_(arr.index(2)).must_equal 3
|
151
|
-
end
|
152
|
-
|
153
|
-
it "returns the proper element for an array of :utf8" do
|
154
|
-
arr = GLib::Array.from :utf8, %w(a b c)
|
155
|
-
_(arr.index(1)).must_equal "b"
|
156
|
-
end
|
157
|
-
|
158
|
-
it "returns the proper element for an array of :gboolean" do
|
159
|
-
arr = GLib::Array.from :gboolean, [true, false, true]
|
160
|
-
_(arr.index(1)).must_equal false
|
161
|
-
end
|
162
|
-
|
163
|
-
it "returns the proper element for an array of struct" do
|
164
|
-
vals = [1, 2, 3].map { |i| GObject::EnumValue.new.tap { |ev| ev.value = i } }
|
165
|
-
arr = GLib::Array.from GObject::EnumValue, vals
|
166
|
-
_(arr.index(1).value).must_equal 2
|
167
|
-
end
|
168
|
-
|
169
|
-
it "raises an error if the index is out of bounds" do
|
170
|
-
arr = GLib::Array.from :gint32, [1, 2, 3]
|
171
|
-
_(proc { arr.index(16) }).must_raise IndexError
|
172
|
-
_(proc { arr.index(-1) }).must_raise IndexError
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "#reset_typespec" do
|
177
|
-
describe "when it needs to guess the type" do
|
178
|
-
it "guesses :uint8 for size 1" do
|
179
|
-
arr = GLib::Array.from :int8, [1, 2, 3]
|
180
|
-
arr.reset_typespec
|
181
|
-
_(arr.element_type).must_equal :uint8
|
182
|
-
end
|
183
|
-
|
184
|
-
it "guesses :uint16 for size 2" do
|
185
|
-
arr = GLib::Array.from :int16, [1, 2, 3]
|
186
|
-
arr.reset_typespec
|
187
|
-
_(arr.element_type).must_equal :uint16
|
188
|
-
end
|
189
|
-
|
190
|
-
it "guesses :uint32 for size 4" do
|
191
|
-
arr = GLib::Array.from :int32, [1, 2, 3]
|
192
|
-
arr.reset_typespec
|
193
|
-
_(arr.element_type).must_equal :uint32
|
194
|
-
end
|
195
|
-
|
196
|
-
it "guesses :uint64 for size 8" do
|
197
|
-
arr = GLib::Array.from :int64, [1, 2, 3]
|
198
|
-
arr.reset_typespec
|
199
|
-
_(arr.element_type).must_equal :uint64
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|