gir_ffi 0.15.3 → 0.15.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +15 -0
- data/README.md +5 -6
- 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/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 +0 -3
- data/lib/ffi-gobject/object.rb +77 -73
- data/lib/ffi-gobject/object_class.rb +1 -1
- data/lib/ffi-gobject/value.rb +107 -108
- data/lib/ffi-gobject_introspection/i_base_info.rb +20 -19
- data/lib/gir_ffi-base/gobject/lib.rb +4 -0
- data/lib/gir_ffi/array_element_convertor.rb +1 -2
- data/lib/gir_ffi/boxed_base.rb +1 -5
- data/lib/gir_ffi/builder.rb +1 -1
- data/lib/gir_ffi/builder_helper.rb +7 -4
- 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 +14 -12
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +4 -6
- data/lib/gir_ffi/builders/class_struct_builder.rb +24 -0
- data/lib/gir_ffi/builders/enum_builder.rb +3 -3
- 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/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 +16 -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 +5 -5
- 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 +3 -3
- 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/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 +86 -136
- 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 -123
- 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 -153
- data/test/gir_ffi/allocation_helper_test.rb +0 -36
- data/test/gir_ffi/arg_helper_test.rb +0 -146
- 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 -168
- data/test/gir_ffi/builders/argument_builder_test.rb +0 -691
- data/test/gir_ffi/builders/base_argument_builder_test.rb +0 -6
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +0 -130
- data/test/gir_ffi/builders/callback_builder_test.rb +0 -117
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +0 -84
- data/test/gir_ffi/builders/constant_builder_test.rb +0 -6
- data/test/gir_ffi/builders/constructor_builder_test.rb +0 -39
- data/test/gir_ffi/builders/enum_builder_test.rb +0 -23
- data/test/gir_ffi/builders/field_builder_test.rb +0 -140
- data/test/gir_ffi/builders/function_builder_test.rb +0 -570
- data/test/gir_ffi/builders/initializer_builder_test.rb +0 -56
- 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 -161
- data/test/gir_ffi/builders/registered_type_builder_test.rb +0 -54
- data/test/gir_ffi/builders/return_value_builder_test.rb +0 -444
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +0 -199
- data/test/gir_ffi/builders/struct_builder_test.rb +0 -96
- 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 -528
- data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +0 -107
- data/test/gir_ffi/builders/vfunc_builder_test.rb +0 -245
- data/test/gir_ffi/callback_base_test.rb +0 -22
- data/test/gir_ffi/class_base_test.rb +0 -171
- data/test/gir_ffi/core_test.rb +0 -99
- 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 -22
- 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 -22
- 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 -712
- 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 -67
- 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 -54
- data/test/integration/generated_everything_test.rb +0 -453
- data/test/integration/generated_gimarshallingtests_test.rb +0 -3109
- 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 -21
- 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 -4076
- 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 -45
- data/test/integration/method_lookup_test.rb +0 -34
- data/test/introspection_test_helper.rb +0 -94
- 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/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
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GLib::ByteArray do
|
6
|
-
it "can succesfully be created with GLib::ByteArray.new" do
|
7
|
-
ba = GLib::ByteArray.new
|
8
|
-
assert_instance_of GLib::ByteArray, ba
|
9
|
-
end
|
10
|
-
|
11
|
-
it "allows strings to be appended to it" do
|
12
|
-
ba = GLib::ByteArray.new
|
13
|
-
ba.append "abdc"
|
14
|
-
pass
|
15
|
-
end
|
16
|
-
|
17
|
-
it "has a working #to_string method" do
|
18
|
-
ba = GLib::ByteArray.new
|
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
|
27
|
-
end
|
28
|
-
end
|
data/test/ffi-glib/bytes_test.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GLib::Bytes do
|
6
|
-
it "can succesfully be created with GLib::Bytes.new" do
|
7
|
-
bytes = GLib::Bytes.new [1, 2, 3]
|
8
|
-
_(bytes).must_be_instance_of GLib::Bytes
|
9
|
-
end
|
10
|
-
|
11
|
-
it "has a working #get_size method" do
|
12
|
-
bytes = GLib::Bytes.new [1, 2, 3]
|
13
|
-
_(bytes.get_size).must_equal 3
|
14
|
-
end
|
15
|
-
|
16
|
-
it "has #size as an alias for #get_size" do
|
17
|
-
bytes = GLib::Bytes.new [1, 2, 3]
|
18
|
-
_(bytes.size).must_equal 3
|
19
|
-
end
|
20
|
-
|
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
|
27
|
-
a = []
|
28
|
-
bytes = GLib::Bytes.new [1, 2, 3]
|
29
|
-
bytes.each do |v|
|
30
|
-
a.unshift v
|
31
|
-
end
|
32
|
-
_(a).must_equal [3, 2, 1]
|
33
|
-
end
|
34
|
-
|
35
|
-
it "has a working #to_a method" do
|
36
|
-
bytes = GLib::Bytes.new [1, 2, 3]
|
37
|
-
_(bytes.to_a).must_equal [1, 2, 3]
|
38
|
-
end
|
39
|
-
|
40
|
-
describe ".from" do
|
41
|
-
it "creates a GLib::Bytes object form an array of small integers" do
|
42
|
-
bytes = GLib::Bytes.from [1, 2, 3]
|
43
|
-
_(bytes).must_be_instance_of GLib::Bytes
|
44
|
-
_(bytes.to_a).must_equal [1, 2, 3]
|
45
|
-
end
|
46
|
-
|
47
|
-
it "returns its argument if given a GLib::Bytes object" do
|
48
|
-
bytes = GLib::Bytes.new [1, 2, 3]
|
49
|
-
result = GLib::Bytes.from bytes
|
50
|
-
assert result.equal?(bytes)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "wraps its argument if given a pointer" do
|
54
|
-
bytes = GLib::Bytes.new [1, 2, 3]
|
55
|
-
ptr = bytes.to_ptr
|
56
|
-
result = GLib::Bytes.from ptr
|
57
|
-
_(result.to_a).must_equal [1, 2, 3]
|
58
|
-
_(result.to_ptr).must_equal ptr
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GObject::Closure do
|
6
|
-
describe ".new" do
|
7
|
-
it "updates the ref_count of the created object" do
|
8
|
-
# Tested on a subclass ...
|
9
|
-
c = GObject::RubyClosure.new {}
|
10
|
-
_(c.ref_count).must_equal 1
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#invoke" do
|
15
|
-
it "invokes the closure" do
|
16
|
-
a = 0
|
17
|
-
c = GObject::RubyClosure.new { a = 2 }
|
18
|
-
c2 = GObject::Closure.wrap(c.to_ptr)
|
19
|
-
c2.invoke nil, []
|
20
|
-
_(a).must_equal 2
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns the closure result" do
|
24
|
-
c = GObject::RubyClosure.new { 3 }
|
25
|
-
c2 = GObject::Closure.wrap(c.to_ptr)
|
26
|
-
result = c2.invoke GObject::Value.for_gtype(GObject::TYPE_INT), []
|
27
|
-
_(result).must_equal 3
|
28
|
-
end
|
29
|
-
|
30
|
-
it "passes arguments" do
|
31
|
-
a = 0
|
32
|
-
c = GObject::RubyClosure.new { |val| a = val }
|
33
|
-
c2 = GObject::Closure.wrap(c.to_ptr)
|
34
|
-
c2.invoke nil, [5]
|
35
|
-
_(a).must_equal 5
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GLib::DestroyNotify do
|
6
|
-
describe ".default" do
|
7
|
-
it "removes the passed-in key from the callback store" do
|
8
|
-
dummy_proc = "some-callback"
|
9
|
-
GirFFI::CallbackBase.store_callback dummy_proc
|
10
|
-
_(GirFFI::CallbackBase::CALLBACKS[dummy_proc.object_id]).wont_be_nil
|
11
|
-
|
12
|
-
user_data = GirFFI::ArgHelper.store dummy_proc
|
13
|
-
GLib::DestroyNotify.default.call user_data
|
14
|
-
|
15
|
-
_(GirFFI::CallbackBase::CALLBACKS[dummy_proc.object_id]).must_be_nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "gir_ffi_test_helper"
|
4
|
-
|
5
|
-
describe GLib::HashTable do
|
6
|
-
it "knows its key and value types" do
|
7
|
-
hsh = GLib::HashTable.new :gint32, :utf8
|
8
|
-
assert_equal :gint32, hsh.key_type
|
9
|
-
assert_equal :utf8, hsh.value_type
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "::from" do
|
13
|
-
it "creates a GHashTable from a Ruby hash" do
|
14
|
-
hsh = GLib::HashTable.from [:utf8, :gint32],
|
15
|
-
"foo" => 23, "bar" => 32
|
16
|
-
assert_equal({ "foo" => 23, "bar" => 32 }, hsh.to_hash)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "return its argument if given a GHashTable" do
|
20
|
-
hsh = GLib::HashTable.from [:utf8, :gint32], "foo" => 23, "bar" => 32
|
21
|
-
hsh2 = GLib::HashTable.from [:utf8, :gint32], hsh
|
22
|
-
assert hsh2.equal? hsh
|
23
|
-
end
|
24
|
-
|
25
|
-
it "wraps its argument if given a pointer" do
|
26
|
-
hsh = GLib::HashTable.from [:utf8, :gint32], "foo" => 23, "bar" => 32
|
27
|
-
pointer = hsh.to_ptr
|
28
|
-
assert_instance_of FFI::Pointer, pointer
|
29
|
-
hsh2 = GLib::HashTable.from [:utf8, :gint32], pointer
|
30
|
-
assert_instance_of GLib::HashTable, hsh2
|
31
|
-
refute hsh2.equal? hsh
|
32
|
-
_(hsh2.to_hash).must_equal hsh.to_hash
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "allows key-value pairs to be inserted" do
|
37
|
-
h = GLib::HashTable.new :utf8, :utf8
|
38
|
-
h.insert "foo", "bar"
|
39
|
-
_(h.to_hash).must_equal "foo" => "bar"
|
40
|
-
end
|
41
|
-
|
42
|
-
it "includes Enumerable" do
|
43
|
-
_(GLib::HashTable).must_include Enumerable
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "a HashTable provided by the system" do
|
47
|
-
before do
|
48
|
-
GirFFI.setup :Regress
|
49
|
-
@hash = Regress.test_ghash_container_return
|
50
|
-
end
|
51
|
-
|
52
|
-
it "has a working #each method" do
|
53
|
-
a = {}
|
54
|
-
@hash.each { |k, v| a[k] = v }
|
55
|
-
_(a).must_be :==,
|
56
|
-
"foo" => "bar",
|
57
|
-
"baz" => "bat",
|
58
|
-
"qux" => "quux"
|
59
|
-
end
|
60
|
-
|
61
|
-
it "has a working #to_hash method" do
|
62
|
-
_(@hash.to_hash).must_be :==,
|
63
|
-
"foo" => "bar",
|
64
|
-
"baz" => "bat",
|
65
|
-
"qux" => "quux"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|