gir_ffi 0.14.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +21 -0
- data/Gemfile +6 -4
- data/README.md +4 -4
- data/Rakefile +5 -5
- data/lib/ffi-glib/array.rb +14 -4
- data/lib/ffi-glib/byte_array.rb +7 -2
- data/lib/ffi-glib/container_class_methods.rb +1 -1
- data/lib/ffi-glib/error.rb +1 -1
- data/lib/ffi-glib/hash_table.rb +3 -3
- data/lib/ffi-glib/list.rb +1 -1
- data/lib/ffi-glib/list_methods.rb +1 -1
- data/lib/ffi-glib/main_loop.rb +3 -3
- data/lib/ffi-glib/ptr_array.rb +30 -8
- data/lib/ffi-glib/s_list.rb +1 -1
- data/lib/ffi-glib/variant.rb +1 -1
- data/lib/ffi-glib.rb +16 -16
- data/lib/ffi-gobject/object.rb +23 -32
- data/lib/ffi-gobject/param_spec.rb +1 -1
- data/lib/ffi-gobject/ruby_closure.rb +2 -2
- data/lib/ffi-gobject/value.rb +37 -28
- data/lib/ffi-gobject.rb +13 -13
- data/lib/ffi-gobject_introspection/gobject_type_init.rb +2 -2
- data/lib/ffi-gobject_introspection/i_arg_info.rb +2 -2
- data/lib/ffi-gobject_introspection/i_base_info.rb +27 -17
- data/lib/ffi-gobject_introspection/i_callable_info.rb +4 -4
- data/lib/ffi-gobject_introspection/i_constant_info.rb +2 -2
- data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_field_info.rb +1 -1
- data/lib/ffi-gobject_introspection/i_function_info.rb +1 -1
- data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -1
- data/lib/ffi-gobject_introspection/i_object_info.rb +2 -2
- data/lib/ffi-gobject_introspection/i_property_info.rb +2 -2
- data/lib/ffi-gobject_introspection/i_repository.rb +9 -6
- data/lib/ffi-gobject_introspection/i_struct_info.rb +2 -1
- data/lib/ffi-gobject_introspection/i_type_info.rb +13 -7
- data/lib/ffi-gobject_introspection/i_unresolved_info.rb +1 -1
- data/lib/ffi-gobject_introspection/i_vfunc_info.rb +1 -1
- data/lib/ffi-gobject_introspection/lib.rb +30 -19
- data/lib/ffi-gobject_introspection/strv.rb +1 -1
- data/lib/ffi-gobject_introspection.rb +20 -20
- data/lib/gir_ffi/allocation_helper.rb +1 -1
- data/lib/gir_ffi/arg_helper.rb +4 -4
- data/lib/gir_ffi/{in_out_pointer.rb → array_element_convertor.rb} +16 -23
- data/lib/gir_ffi/boolean.rb +1 -1
- data/lib/gir_ffi/boxed_base.rb +1 -1
- data/lib/gir_ffi/builder.rb +18 -10
- data/lib/gir_ffi/builders/argument_builder.rb +17 -17
- data/lib/gir_ffi/builders/base_argument_builder.rb +1 -0
- data/lib/gir_ffi/builders/base_method_builder.rb +7 -7
- data/lib/gir_ffi/builders/base_return_value_builder.rb +1 -1
- data/lib/gir_ffi/builders/base_type_builder.rb +1 -1
- data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +5 -5
- data/lib/gir_ffi/builders/callback_argument_builder.rb +8 -8
- data/lib/gir_ffi/builders/callback_builder.rb +3 -3
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +2 -2
- data/lib/gir_ffi/builders/closure_argument_builder.rb +1 -1
- data/lib/gir_ffi/builders/closure_return_value_builder.rb +1 -1
- data/lib/gir_ffi/builders/constant_builder.rb +1 -1
- data/lib/gir_ffi/builders/constructor_builder.rb +9 -9
- data/lib/gir_ffi/builders/enum_builder.rb +2 -2
- data/lib/gir_ffi/builders/field_builder.rb +16 -15
- data/lib/gir_ffi/builders/flags_builder.rb +2 -2
- data/lib/gir_ffi/builders/full_c_to_ruby_convertor.rb +1 -1
- data/lib/gir_ffi/builders/function_builder.rb +11 -5
- data/lib/gir_ffi/builders/initializer_builder.rb +3 -3
- data/lib/gir_ffi/builders/initializer_return_value_builder.rb +2 -2
- data/lib/gir_ffi/builders/interface_builder.rb +2 -2
- data/lib/gir_ffi/builders/mapping_method_builder.rb +9 -9
- data/lib/gir_ffi/builders/marshalling_method_builder.rb +7 -7
- data/lib/gir_ffi/builders/method_template.rb +1 -1
- data/lib/gir_ffi/builders/module_builder.rb +4 -6
- data/lib/gir_ffi/builders/object_builder.rb +6 -6
- data/lib/gir_ffi/builders/property_argument_builder.rb +1 -1
- data/lib/gir_ffi/builders/property_builder.rb +13 -12
- data/lib/gir_ffi/builders/property_return_value_builder.rb +1 -1
- data/lib/gir_ffi/builders/registered_type_builder.rb +14 -5
- data/lib/gir_ffi/builders/return_value_builder.rb +4 -4
- data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +6 -6
- data/lib/gir_ffi/builders/signal_closure_builder.rb +2 -2
- data/lib/gir_ffi/builders/struct_builder.rb +4 -4
- data/lib/gir_ffi/builders/struct_like.rb +1 -1
- data/lib/gir_ffi/builders/type_builder.rb +12 -12
- data/lib/gir_ffi/builders/unintrospectable_boxed_builder.rb +2 -2
- data/lib/gir_ffi/builders/unintrospectable_builder.rb +2 -2
- data/lib/gir_ffi/builders/union_builder.rb +4 -4
- data/lib/gir_ffi/builders/user_defined_builder.rb +2 -2
- data/lib/gir_ffi/builders/vfunc_argument_builder.rb +1 -1
- data/lib/gir_ffi/builders/vfunc_builder.rb +6 -6
- data/lib/gir_ffi/builders/with_layout.rb +2 -2
- data/lib/gir_ffi/callback_base.rb +1 -1
- data/lib/gir_ffi/class_base.rb +5 -5
- data/lib/gir_ffi/core.rb +19 -20
- data/lib/gir_ffi/enum_base.rb +1 -1
- data/lib/gir_ffi/enum_like_base.rb +2 -2
- data/lib/gir_ffi/error_argument_info.rb +2 -2
- data/lib/gir_ffi/error_type_info.rb +1 -1
- data/lib/gir_ffi/ffi_ext/pointer.rb +1 -1
- data/lib/gir_ffi/ffi_ext.rb +1 -1
- data/lib/gir_ffi/flags_base.rb +1 -1
- data/lib/gir_ffi/in_pointer.rb +10 -0
- data/lib/gir_ffi/info_ext/full_type_name.rb +3 -3
- data/lib/gir_ffi/info_ext/i_arg_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_callable_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_callback_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_field_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_function_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_property_info.rb +2 -2
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +4 -5
- data/lib/gir_ffi/info_ext/i_signal_info.rb +7 -3
- data/lib/gir_ffi/info_ext/i_type_info.rb +48 -26
- data/lib/gir_ffi/info_ext/i_unresolved_info.rb +1 -1
- data/lib/gir_ffi/info_ext/i_value_info.rb +2 -2
- data/lib/gir_ffi/info_ext/i_vfunc_info.rb +2 -2
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -8
- data/lib/gir_ffi/info_ext/safe_function_name.rb +2 -2
- data/lib/gir_ffi/info_ext.rb +15 -15
- data/lib/gir_ffi/interface_base.rb +3 -3
- data/lib/gir_ffi/lib_c.rb +1 -1
- data/lib/gir_ffi/method_stubber.rb +1 -1
- data/lib/gir_ffi/module_base.rb +1 -1
- data/lib/gir_ffi/object_base.rb +3 -4
- data/lib/gir_ffi/receiver_argument_info.rb +1 -1
- data/lib/gir_ffi/receiver_type_info.rb +2 -2
- data/lib/gir_ffi/registered_type_base.rb +1 -1
- data/lib/gir_ffi/sized_array.rb +4 -2
- data/lib/gir_ffi/struct.rb +1 -1
- data/lib/gir_ffi/struct_base.rb +1 -1
- data/lib/gir_ffi/type_map.rb +2 -23
- data/lib/gir_ffi/unintrospectable_boxed_info.rb +2 -2
- data/lib/gir_ffi/unintrospectable_type_info.rb +1 -1
- data/lib/gir_ffi/union.rb +1 -1
- data/lib/gir_ffi/union_base.rb +1 -1
- data/lib/gir_ffi/user_defined_object_info.rb +6 -2
- data/lib/gir_ffi/user_defined_property_info.rb +33 -33
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi-base/gobject/lib.rb +3 -2
- data/lib/gir_ffi-base/gobject.rb +26 -25
- data/lib/gir_ffi-base.rb +1 -1
- data/lib/gir_ffi.rb +3 -3
- data/tasks/test.rake +3 -2
- data/test/base_test_helper.rb +16 -9
- data/test/ffi-glib/array_test.rb +71 -56
- data/test/ffi-glib/byte_array_test.rb +13 -7
- data/test/ffi-glib/bytes_test.rb +24 -19
- data/test/ffi-glib/closure_test.rb +11 -11
- data/test/ffi-glib/destroy_notify_test.rb +6 -6
- data/test/ffi-glib/hash_table_test.rb +27 -27
- data/test/ffi-glib/list_test.rb +22 -22
- data/test/ffi-glib/main_loop_test.rb +12 -12
- data/test/ffi-glib/ptr_array_test.rb +39 -39
- data/test/ffi-glib/ruby_closure_test.rb +10 -10
- data/test/ffi-glib/s_list_test.rb +20 -20
- data/test/ffi-glib/strv_test.rb +19 -19
- data/test/ffi-glib/variant_test.rb +5 -5
- data/test/ffi-gobject/gobject_test.rb +48 -44
- data/test/ffi-gobject/object_class_test.rb +8 -8
- data/test/ffi-gobject/object_test.rb +49 -67
- data/test/ffi-gobject/param_spec_test.rb +12 -12
- data/test/ffi-gobject/value_test.rb +145 -125
- data/test/ffi-gobject_introspection/gobject_type_init_test.rb +8 -8
- data/test/ffi-gobject_introspection/i_base_info_test.rb +15 -16
- data/test/ffi-gobject_introspection/i_constant_info_test.rb +9 -13
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +7 -7
- data/test/ffi-gobject_introspection/i_function_info_test.rb +1 -1
- data/test/ffi-gobject_introspection/i_interface_info_test.rb +10 -10
- data/test/ffi-gobject_introspection/i_object_info_test.rb +23 -23
- data/test/ffi-gobject_introspection/i_property_info_test.rb +19 -19
- data/test/ffi-gobject_introspection/i_registered_type_info_test.rb +10 -10
- data/test/ffi-gobject_introspection/i_repository_test.rb +31 -31
- data/test/ffi-gobject_introspection/i_struct_info_test.rb +10 -10
- data/test/ffi-gobject_introspection/i_type_info_test.rb +12 -15
- data/test/ffi-gobject_introspection/i_union_info_test.rb +7 -7
- data/test/ffi-gobject_introspection/i_vfunc_info_test.rb +16 -16
- data/test/ffi-gobject_introspection/lib_test.rb +3 -3
- data/test/ffi-gobject_introspection/strv_test.rb +9 -9
- data/test/ffi-gobject_test.rb +44 -44
- data/test/gir_ffi/allocation_helper_test.rb +13 -13
- data/test/gir_ffi/arg_helper_test.rb +63 -64
- data/test/gir_ffi/boolean_test.rb +20 -20
- data/test/gir_ffi/boxed_base_test.rb +18 -18
- data/test/gir_ffi/builder_test.rb +115 -93
- data/test/gir_ffi/builders/argument_builder_test.rb +280 -286
- data/test/gir_ffi/builders/base_argument_builder_test.rb +1 -1
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +53 -56
- data/test/gir_ffi/builders/callback_builder_test.rb +71 -72
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +36 -40
- data/test/gir_ffi/builders/constant_builder_test.rb +1 -1
- data/test/gir_ffi/builders/constructor_builder_test.rb +10 -10
- data/test/gir_ffi/builders/enum_builder_test.rb +10 -10
- data/test/gir_ffi/builders/field_builder_test.rb +42 -42
- data/test/gir_ffi/builders/function_builder_test.rb +236 -224
- data/test/gir_ffi/builders/initializer_builder_test.rb +14 -14
- data/test/gir_ffi/builders/interface_builder_test.rb +9 -9
- data/test/gir_ffi/builders/module_builder_test.rb +18 -18
- data/test/gir_ffi/builders/object_builder_test.rb +38 -38
- data/test/gir_ffi/builders/property_builder_test.rb +91 -94
- data/test/gir_ffi/builders/registered_type_builder_test.rb +35 -11
- data/test/gir_ffi/builders/return_value_builder_test.rb +215 -222
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +122 -113
- data/test/gir_ffi/builders/struct_builder_test.rb +32 -32
- data/test/gir_ffi/builders/unintrospectable_boxed_builder_test.rb +8 -14
- data/test/gir_ffi/builders/unintrospectable_builder_test.rb +23 -23
- data/test/gir_ffi/builders/union_builder_test.rb +12 -15
- data/test/gir_ffi/builders/user_defined_builder_test.rb +147 -147
- data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +40 -40
- data/test/gir_ffi/builders/vfunc_builder_test.rb +145 -157
- data/test/gir_ffi/callback_base_test.rb +9 -9
- data/test/gir_ffi/class_base_test.rb +49 -51
- data/test/gir_ffi/core_test.rb +32 -32
- data/test/gir_ffi/enum_base_test.rb +19 -19
- data/test/gir_ffi/error_type_info_test.rb +23 -23
- data/test/gir_ffi/ffi_ext/pointer_test.rb +5 -5
- data/test/gir_ffi/g_type_test.rb +11 -11
- data/test/gir_ffi/in_pointer_test.rb +70 -50
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +5 -5
- data/test/gir_ffi/info_ext/i_callback_info_test.rb +4 -4
- data/test/gir_ffi/info_ext/i_field_info_test.rb +6 -6
- data/test/gir_ffi/info_ext/i_function_info_test.rb +17 -17
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +8 -8
- data/test/gir_ffi/info_ext/i_type_info_test.rb +229 -215
- data/test/gir_ffi/info_ext/i_unresolved_info_test.rb +4 -4
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +8 -8
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +8 -8
- data/test/gir_ffi/interface_base_test.rb +8 -8
- data/test/gir_ffi/method_stubber_test.rb +19 -19
- data/test/gir_ffi/object_base_test.rb +19 -19
- data/test/gir_ffi/object_store_test.rb +13 -13
- data/test/gir_ffi/receiver_argument_info_test.rb +15 -15
- data/test/gir_ffi/sized_array_test.rb +68 -68
- data/test/gir_ffi/struct_base_test.rb +8 -8
- data/test/gir_ffi/struct_like_base_test.rb +64 -64
- data/test/gir_ffi/type_map_test.rb +6 -6
- data/test/gir_ffi/unintrospectable_type_info_test.rb +33 -33
- data/test/gir_ffi/union_base_test.rb +8 -8
- data/test/gir_ffi/user_defined_object_info_test.rb +34 -34
- data/test/gir_ffi/user_defined_property_info_test.rb +16 -16
- data/test/gir_ffi/variable_name_generator_test.rb +8 -8
- data/test/gir_ffi/version_test.rb +4 -4
- data/test/gir_ffi/zero_terminated_test.rb +34 -34
- data/test/gir_ffi_test_helper.rb +3 -3
- data/test/integration/callback_exceptions_test.rb +17 -21
- data/test/integration/derived_classes_test.rb +13 -13
- data/test/integration/generated_everything_test.rb +224 -224
- data/test/integration/generated_gimarshallingtests_test.rb +1118 -1017
- data/test/integration/generated_gio_test.rb +36 -36
- data/test/integration/generated_glib_test.rb +4 -6
- data/test/integration/generated_gobject_test.rb +43 -35
- data/test/integration/generated_gst_test.rb +16 -16
- data/test/integration/generated_gtk_source_test.rb +22 -17
- data/test/integration/generated_gtop_test.rb +8 -15
- data/test/integration/generated_pango_ft2_test.rb +2 -2
- data/test/integration/generated_pango_test.rb +4 -4
- data/test/integration/generated_regress_test.rb +1809 -1621
- data/test/integration/generated_secret_test.rb +8 -11
- data/test/integration/generated_utility_test.rb +81 -81
- data/test/integration/generated_warnlib_test.rb +13 -19
- data/test/integration/method_lookup_test.rb +6 -6
- data/test/introspection_test_helper.rb +48 -7
- data/test/minitest/stats_plugin.rb +1 -1
- metadata +11 -28
- data/lib/ffi-glib/array_methods.rb +0 -16
- data/test/gir_ffi/in_out_pointer_test.rb +0 -56
data/tasks/test.rake
CHANGED
@@ -71,7 +71,7 @@ class Listener
|
|
71
71
|
result.puts " it \"handles the '#{obj_name}' signal\" do"
|
72
72
|
when 'type', 'alias', 'return-value', 'parameters',
|
73
73
|
'instance-parameter', 'parameter', 'doc', 'array',
|
74
|
-
'repository', 'include', 'package'
|
74
|
+
'repository', 'include', 'package', 'source-position'
|
75
75
|
# Not printed"
|
76
76
|
else
|
77
77
|
puts "Skipping #{name}: #{attrs}"
|
@@ -156,9 +156,10 @@ namespace :test do
|
|
156
156
|
task overrides: :lib
|
157
157
|
task integration: :lib
|
158
158
|
|
159
|
-
desc 'Run the entire test suite as one'
|
159
|
+
desc 'Run the entire test suite as one with simplecov activated'
|
160
160
|
define_test_task(:all) do |t|
|
161
161
|
t.test_files = FileList['test/**/*_test.rb']
|
162
|
+
t.ruby_opts += ['-rbundler/setup -rsimplecov -w -Itest']
|
162
163
|
end
|
163
164
|
|
164
165
|
task all: :lib
|
data/test/base_test_helper.rb
CHANGED
@@ -1,22 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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"
|
7
13
|
end
|
14
|
+
$VERBOSE = old_verbose
|
8
15
|
|
9
|
-
if ENV[
|
16
|
+
if ENV["CI"]
|
10
17
|
begin
|
11
|
-
require
|
18
|
+
require "coveralls"
|
12
19
|
Coveralls.wear!
|
13
20
|
rescue LoadError
|
14
21
|
nil
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
18
|
-
require
|
19
|
-
require
|
25
|
+
require "minitest/autorun"
|
26
|
+
require "rspec/mocks/minitest_integration"
|
20
27
|
|
21
28
|
Thread.abort_on_exception = true
|
22
29
|
|
@@ -60,4 +67,4 @@ module BaseTestExtensions
|
|
60
67
|
end
|
61
68
|
end
|
62
69
|
|
63
|
-
Minitest::Test.
|
70
|
+
Minitest::Test.include BaseTestExtensions
|
data/test/ffi-glib/array_test.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GLib::Array do
|
6
|
-
it
|
6
|
+
it "knows its element type" do
|
7
7
|
arr = GLib::Array.new :gint32
|
8
8
|
assert_equal :gint32, arr.element_type
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe "#append_vals" do
|
12
12
|
before do
|
13
13
|
@arr = GLib::Array.new :gint32
|
14
14
|
@result = @arr.append_vals [1, 2, 3]
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it "appends values" do
|
18
18
|
assert_equal 3, @arr.len
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it "returns self" do
|
22
22
|
assert_equal @result, @arr
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
26
|
+
describe "#each" do
|
27
27
|
before do
|
28
28
|
@arr = GLib::Array.new(:gint32).append_vals [1, 2, 3]
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it "iterates over the values" do
|
32
32
|
a = []
|
33
33
|
@arr.each { |v| a << v }
|
34
34
|
|
@@ -36,8 +36,8 @@ describe GLib::Array do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
describe
|
40
|
-
it
|
39
|
+
describe "::wrap" do
|
40
|
+
it "wraps a pointer, taking the element type as the first argument" do
|
41
41
|
arr = GLib::Array.new :gint32
|
42
42
|
arr.append_vals [1, 2, 3]
|
43
43
|
arr2 = GLib::Array.wrap :gint32, arr.to_ptr
|
@@ -47,49 +47,64 @@ describe GLib::Array do
|
|
47
47
|
it "warns the element sizes don't match" do
|
48
48
|
arr = GLib::Array.new :gint32
|
49
49
|
arr.append_vals [1, 2, 3]
|
50
|
-
proc { GLib::Array.wrap :gint8, arr.to_ptr }.must_output nil, /sizes do not match/
|
50
|
+
_(proc { GLib::Array.wrap :gint8, arr.to_ptr }).must_output nil, /sizes do not match/
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it "handles a struct as the element type" do
|
54
54
|
vals = [1, 2, 3].map { |i| GObject::EnumValue.new.tap { |ev| ev.value = i } }
|
55
55
|
arr = GLib::Array.new GObject::EnumValue
|
56
56
|
arr.append_vals vals
|
57
57
|
arr2 = GLib::Array.wrap GObject::EnumValue, arr.to_ptr
|
58
|
-
arr2.to_a.must_equal arr.to_a
|
58
|
+
_(arr2.to_a).must_equal arr.to_a
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
63
|
-
GLib::Array.must_include Enumerable
|
62
|
+
it "includes Enumerable" do
|
63
|
+
_(GLib::Array).must_include Enumerable
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
66
|
+
it "has a working #to_a method" do
|
67
67
|
arr = GLib::Array.new :gint32
|
68
68
|
arr.append_vals [1, 2, 3]
|
69
69
|
assert_equal [1, 2, 3], arr.to_a
|
70
70
|
end
|
71
71
|
|
72
|
-
describe
|
73
|
-
it
|
72
|
+
describe ".from" do
|
73
|
+
it "creates a GArray from an array of :gint32" do
|
74
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]
|
75
|
+
_(arr).must_be_instance_of GLib::Array
|
76
|
+
_(arr.to_a).must_equal [3, 2, 1]
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
79
|
+
it "creates a GArray from an array of :gboolean" do
|
80
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]
|
81
|
+
_(arr).must_be_instance_of GLib::Array
|
82
|
+
_(arr.to_a).must_equal [true, false, true]
|
83
83
|
end
|
84
84
|
|
85
|
-
it
|
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
|
86
101
|
arr = GLib::Array.new :gint32
|
87
102
|
arr.append_vals [3, 2, 1]
|
88
103
|
arr2 = GLib::Array.from :gint32, arr
|
89
104
|
assert arr2.equal? arr
|
90
105
|
end
|
91
106
|
|
92
|
-
it
|
107
|
+
it "wraps its argument if given a pointer" do
|
93
108
|
arr = GLib::Array.new :gint32
|
94
109
|
arr.append_vals [3, 2, 1]
|
95
110
|
pointer = arr.to_ptr
|
@@ -97,91 +112,91 @@ describe GLib::Array do
|
|
97
112
|
arr2 = GLib::Array.from :gint32, pointer
|
98
113
|
assert_instance_of GLib::Array, arr2
|
99
114
|
refute arr2.equal? arr
|
100
|
-
arr2.to_a.must_equal arr.to_a
|
115
|
+
_(arr2.to_a).must_equal arr.to_a
|
101
116
|
end
|
102
117
|
end
|
103
118
|
|
104
|
-
describe
|
105
|
-
it
|
119
|
+
describe "#==" do
|
120
|
+
it "returns true when comparing to an array with the same elements" do
|
106
121
|
arr = GLib::Array.from :gint32, [1, 2, 3]
|
107
122
|
|
108
|
-
arr.must_be :==, [1, 2, 3]
|
123
|
+
_(arr).must_be :==, [1, 2, 3]
|
109
124
|
end
|
110
125
|
|
111
|
-
it
|
126
|
+
it "returns false when comparing to an array with different elements" do
|
112
127
|
arr = GLib::Array.from :gint32, [1, 2, 3]
|
113
128
|
|
114
|
-
arr.wont_be :==, [1, 2]
|
129
|
+
_(arr).wont_be :==, [1, 2]
|
115
130
|
end
|
116
131
|
|
117
|
-
it
|
132
|
+
it "returns true when comparing to a GArray with the same elements" do
|
118
133
|
arr = GLib::Array.from :gint32, [1, 2, 3]
|
119
134
|
other = GLib::Array.from :gint32, [1, 2, 3]
|
120
135
|
|
121
|
-
arr.must_be :==, other
|
136
|
+
_(arr).must_be :==, other
|
122
137
|
end
|
123
138
|
|
124
|
-
it
|
139
|
+
it "returns false when comparing to a GArray with different elements" do
|
125
140
|
arr = GLib::Array.from :gint32, [1, 2, 3]
|
126
141
|
other = GLib::Array.from :gint32, [1, 2]
|
127
142
|
|
128
|
-
arr.wont_be :==, other
|
143
|
+
_(arr).wont_be :==, other
|
129
144
|
end
|
130
145
|
end
|
131
146
|
|
132
|
-
describe
|
133
|
-
it
|
147
|
+
describe "#index" do
|
148
|
+
it "returns the proper element for an array of :gint32" do
|
134
149
|
arr = GLib::Array.from :gint32, [1, 2, 3]
|
135
|
-
arr.index(2).must_equal 3
|
150
|
+
_(arr.index(2)).must_equal 3
|
136
151
|
end
|
137
152
|
|
138
|
-
it
|
153
|
+
it "returns the proper element for an array of :utf8" do
|
139
154
|
arr = GLib::Array.from :utf8, %w(a b c)
|
140
|
-
arr.index(1).must_equal
|
155
|
+
_(arr.index(1)).must_equal "b"
|
141
156
|
end
|
142
157
|
|
143
|
-
it
|
158
|
+
it "returns the proper element for an array of :gboolean" do
|
144
159
|
arr = GLib::Array.from :gboolean, [true, false, true]
|
145
|
-
arr.index(1).must_equal false
|
160
|
+
_(arr.index(1)).must_equal false
|
146
161
|
end
|
147
162
|
|
148
|
-
it
|
163
|
+
it "returns the proper element for an array of struct" do
|
149
164
|
vals = [1, 2, 3].map { |i| GObject::EnumValue.new.tap { |ev| ev.value = i } }
|
150
165
|
arr = GLib::Array.from GObject::EnumValue, vals
|
151
|
-
arr.index(1).value.must_equal 2
|
166
|
+
_(arr.index(1).value).must_equal 2
|
152
167
|
end
|
153
168
|
|
154
|
-
it
|
169
|
+
it "raises an error if the index is out of bounds" do
|
155
170
|
arr = GLib::Array.from :gint32, [1, 2, 3]
|
156
|
-
proc { arr.index(16) }.must_raise IndexError
|
157
|
-
proc { arr.index(-1) }.must_raise IndexError
|
171
|
+
_(proc { arr.index(16) }).must_raise IndexError
|
172
|
+
_(proc { arr.index(-1) }).must_raise IndexError
|
158
173
|
end
|
159
174
|
end
|
160
175
|
|
161
|
-
describe
|
162
|
-
describe
|
163
|
-
it
|
176
|
+
describe "#reset_typespec" do
|
177
|
+
describe "when it needs to guess the type" do
|
178
|
+
it "guesses :uint8 for size 1" do
|
164
179
|
arr = GLib::Array.from :int8, [1, 2, 3]
|
165
180
|
arr.reset_typespec
|
166
|
-
arr.element_type.must_equal :uint8
|
181
|
+
_(arr.element_type).must_equal :uint8
|
167
182
|
end
|
168
183
|
|
169
|
-
it
|
184
|
+
it "guesses :uint16 for size 2" do
|
170
185
|
arr = GLib::Array.from :int16, [1, 2, 3]
|
171
186
|
arr.reset_typespec
|
172
|
-
arr.element_type.must_equal :uint16
|
187
|
+
_(arr.element_type).must_equal :uint16
|
173
188
|
end
|
174
189
|
|
175
|
-
it
|
190
|
+
it "guesses :uint32 for size 4" do
|
176
191
|
arr = GLib::Array.from :int32, [1, 2, 3]
|
177
192
|
arr.reset_typespec
|
178
|
-
arr.element_type.must_equal :uint32
|
193
|
+
_(arr.element_type).must_equal :uint32
|
179
194
|
end
|
180
195
|
|
181
|
-
it
|
196
|
+
it "guesses :uint64 for size 8" do
|
182
197
|
arr = GLib::Array.from :int64, [1, 2, 3]
|
183
198
|
arr.reset_typespec
|
184
|
-
arr.element_type.must_equal :uint64
|
199
|
+
_(arr.element_type).must_equal :uint64
|
185
200
|
end
|
186
201
|
end
|
187
202
|
end
|
@@ -1,22 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GLib::ByteArray do
|
6
|
-
it
|
6
|
+
it "can succesfully be created with GLib::ByteArray.new" do
|
7
7
|
ba = GLib::ByteArray.new
|
8
8
|
assert_instance_of GLib::ByteArray, ba
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it "allows strings to be appended to it" do
|
12
12
|
ba = GLib::ByteArray.new
|
13
|
-
ba.append
|
13
|
+
ba.append "abdc"
|
14
14
|
pass
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it "has a working #to_string method" do
|
18
18
|
ba = GLib::ByteArray.new
|
19
|
-
ba = ba.append
|
20
|
-
assert_equal
|
19
|
+
ba = ba.append "abdc"
|
20
|
+
assert_equal "abdc", ba.to_string
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can be created from a string" do
|
24
|
+
str = "cdba"
|
25
|
+
ba = GLib::ByteArray.from str
|
26
|
+
_(ba.to_string).must_equal str
|
21
27
|
end
|
22
28
|
end
|
data/test/ffi-glib/bytes_test.rb
CHANGED
@@ -1,56 +1,61 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GLib::Bytes do
|
6
|
-
it
|
6
|
+
it "can succesfully be created with GLib::Bytes.new" do
|
7
7
|
bytes = GLib::Bytes.new [1, 2, 3]
|
8
|
-
bytes.must_be_instance_of GLib::Bytes
|
8
|
+
_(bytes).must_be_instance_of GLib::Bytes
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it "has a working #get_size method" do
|
12
12
|
bytes = GLib::Bytes.new [1, 2, 3]
|
13
|
-
bytes.get_size.must_equal 3
|
13
|
+
_(bytes.get_size).must_equal 3
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it "has #size as an alias for #get_size" do
|
17
17
|
bytes = GLib::Bytes.new [1, 2, 3]
|
18
|
-
bytes.
|
18
|
+
_(bytes.size).must_equal 3
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it "has a working #get_data method" do
|
22
|
+
bytes = GLib::Bytes.new [1, 2, 3]
|
23
|
+
_(bytes.get_data.to_a).must_equal [1, 2, 3]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has a working #each method" do
|
22
27
|
a = []
|
23
28
|
bytes = GLib::Bytes.new [1, 2, 3]
|
24
29
|
bytes.each do |v|
|
25
30
|
a.unshift v
|
26
31
|
end
|
27
|
-
a.must_equal [3, 2, 1]
|
32
|
+
_(a).must_equal [3, 2, 1]
|
28
33
|
end
|
29
34
|
|
30
|
-
it
|
35
|
+
it "has a working #to_a method" do
|
31
36
|
bytes = GLib::Bytes.new [1, 2, 3]
|
32
|
-
bytes.to_a.must_equal [1, 2, 3]
|
37
|
+
_(bytes.to_a).must_equal [1, 2, 3]
|
33
38
|
end
|
34
39
|
|
35
|
-
describe
|
36
|
-
it
|
40
|
+
describe ".from" do
|
41
|
+
it "creates a GLib::Bytes object form an array of small integers" do
|
37
42
|
bytes = GLib::Bytes.from [1, 2, 3]
|
38
|
-
bytes.must_be_instance_of GLib::Bytes
|
39
|
-
bytes.to_a.must_equal [1, 2, 3]
|
43
|
+
_(bytes).must_be_instance_of GLib::Bytes
|
44
|
+
_(bytes.to_a).must_equal [1, 2, 3]
|
40
45
|
end
|
41
46
|
|
42
|
-
it
|
47
|
+
it "returns its argument if given a GLib::Bytes object" do
|
43
48
|
bytes = GLib::Bytes.new [1, 2, 3]
|
44
49
|
result = GLib::Bytes.from bytes
|
45
50
|
assert result.equal?(bytes)
|
46
51
|
end
|
47
52
|
|
48
|
-
it
|
53
|
+
it "wraps its argument if given a pointer" do
|
49
54
|
bytes = GLib::Bytes.new [1, 2, 3]
|
50
55
|
ptr = bytes.to_ptr
|
51
56
|
result = GLib::Bytes.from ptr
|
52
|
-
result.to_a.must_equal [1, 2, 3]
|
53
|
-
result.to_ptr.must_equal ptr
|
57
|
+
_(result.to_a).must_equal [1, 2, 3]
|
58
|
+
_(result.to_ptr).must_equal ptr
|
54
59
|
end
|
55
60
|
end
|
56
61
|
end
|
@@ -1,38 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "gir_ffi_test_helper"
|
4
4
|
|
5
5
|
describe GObject::Closure do
|
6
|
-
describe
|
7
|
-
it
|
6
|
+
describe ".new" do
|
7
|
+
it "updates the ref_count of the created object" do
|
8
8
|
# Tested on a subclass ...
|
9
9
|
c = GObject::RubyClosure.new {}
|
10
|
-
c.ref_count.must_equal 1
|
10
|
+
_(c.ref_count).must_equal 1
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
15
|
-
it
|
14
|
+
describe "#invoke" do
|
15
|
+
it "invokes the closure" do
|
16
16
|
a = 0
|
17
17
|
c = GObject::RubyClosure.new { a = 2 }
|
18
18
|
c2 = GObject::Closure.wrap(c.to_ptr)
|
19
19
|
c2.invoke nil, []
|
20
|
-
a.must_equal 2
|
20
|
+
_(a).must_equal 2
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it "returns the closure result" do
|
24
24
|
c = GObject::RubyClosure.new { 3 }
|
25
25
|
c2 = GObject::Closure.wrap(c.to_ptr)
|
26
26
|
result = c2.invoke GObject::Value.for_gtype(GObject::TYPE_INT), []
|
27
|
-
result.must_equal 3
|
27
|
+
_(result).must_equal 3
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it "passes arguments" do
|
31
31
|
a = 0
|
32
32
|
c = GObject::RubyClosure.new { |val| a = val }
|
33
33
|
c2 = GObject::Closure.wrap(c.to_ptr)
|
34
34
|
c2.invoke nil, [5]
|
35
|
-
a.must_equal 5
|
35
|
+
_(a).must_equal 5
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|