gir_ffi 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +14 -0
- data/TODO.rdoc +23 -5
- data/lib/ffi-glib/array.rb +14 -15
- data/lib/ffi-glib/container_class_methods.rb +0 -1
- data/lib/ffi-glib/hash_table.rb +3 -4
- data/lib/ffi-glib/ptr_array.rb +12 -4
- data/lib/ffi-glib/sized_array.rb +27 -7
- data/lib/ffi-gobject.rb +14 -15
- data/lib/ffi-gobject/closure.rb +1 -1
- data/lib/ffi-gobject/object.rb +40 -15
- data/lib/ffi-gobject/ruby_closure.rb +0 -1
- data/lib/ffi-gobject/value.rb +45 -21
- data/lib/ffi-gobject_introspection/i_arg_info.rb +4 -0
- data/lib/ffi-gobject_introspection/i_base_info.rb +42 -2
- data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
- data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -4
- data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_object_info.rb +2 -0
- data/lib/ffi-gobject_introspection/i_repository.rb +2 -3
- data/lib/ffi-gobject_introspection/i_struct_info.rb +3 -8
- data/lib/ffi-gobject_introspection/lib.rb +3 -0
- data/lib/gir_ffi-base.rb +3 -1
- data/lib/gir_ffi-base/gir_ffi/struct.rb +27 -0
- data/lib/gir_ffi-base/glib/boolean.rb +13 -1
- data/lib/gir_ffi-base/gobject.rb +7 -0
- data/lib/gir_ffi-base/gobject/lib.rb +0 -2
- data/lib/gir_ffi.rb +1 -3
- data/lib/gir_ffi/arg_helper.rb +4 -85
- data/lib/gir_ffi/builder.rb +5 -5
- data/lib/gir_ffi/builder_helper.rb +7 -0
- data/lib/gir_ffi/builders/argument_builder.rb +132 -0
- data/lib/gir_ffi/{base_argument_builder.rb → builders/base_argument_builder.rb} +32 -41
- data/lib/gir_ffi/builders/base_type_builder.rb +47 -0
- data/lib/gir_ffi/builders/callback_builder.rb +38 -0
- data/lib/gir_ffi/builders/constant_builder.rb +18 -0
- data/lib/gir_ffi/builders/enum_builder.rb +62 -0
- data/lib/gir_ffi/builders/error_argument_builder.rb +18 -0
- data/lib/gir_ffi/builders/field_builder.rb +94 -0
- data/lib/gir_ffi/builders/function_builder.rb +123 -0
- data/lib/gir_ffi/builders/interface_builder.rb +29 -0
- data/lib/gir_ffi/builders/mapping_method_builder.rb +88 -0
- data/lib/gir_ffi/builders/module_builder.rb +124 -0
- data/lib/gir_ffi/{null_argument_builder.rb → builders/null_argument_builder.rb} +0 -0
- data/lib/gir_ffi/builders/null_builder.rb +11 -0
- data/lib/gir_ffi/builders/object_builder.rb +123 -0
- data/lib/gir_ffi/{builder/property.rb → builders/property_builder.rb} +0 -0
- data/lib/gir_ffi/builders/registered_type_builder.rb +50 -0
- data/lib/gir_ffi/builders/return_value_builder.rb +68 -0
- data/lib/gir_ffi/builders/signal_builder.rb +91 -0
- data/lib/gir_ffi/builders/struct_builder.rb +35 -0
- data/lib/gir_ffi/builders/type_builder.rb +40 -0
- data/lib/gir_ffi/builders/unintrospectable_builder.rb +35 -0
- data/lib/gir_ffi/builders/union_builder.rb +34 -0
- data/lib/gir_ffi/builders/user_defined_builder.rb +103 -0
- data/lib/gir_ffi/builders/with_layout.rb +55 -0
- data/lib/gir_ffi/builders/with_methods.rb +44 -0
- data/lib/gir_ffi/callback_base.rb +31 -0
- data/lib/gir_ffi/class_base.rb +16 -10
- data/lib/gir_ffi/enum_base.rb +8 -4
- data/lib/gir_ffi/ffi_ext/pointer.rb +19 -2
- data/lib/gir_ffi/in_out_pointer.rb +38 -39
- data/lib/gir_ffi/in_pointer.rb +33 -18
- data/lib/gir_ffi/info_ext.rb +0 -4
- data/lib/gir_ffi/info_ext/i_arg_info.rb +0 -18
- data/lib/gir_ffi/info_ext/i_callable_info.rb +2 -1
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +6 -8
- data/lib/gir_ffi/info_ext/i_signal_info.rb +6 -21
- data/lib/gir_ffi/info_ext/i_type_info.rb +54 -29
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -1
- data/lib/gir_ffi/interface_base.rb +1 -1
- data/lib/gir_ffi/module_base.rb +5 -1
- data/lib/gir_ffi/object_base.rb +5 -1
- data/lib/gir_ffi/setter_argument_info.rb +4 -0
- data/lib/gir_ffi/signal_base.rb +21 -0
- data/lib/gir_ffi/struct_base.rb +24 -0
- data/lib/gir_ffi/type_base.rb +11 -0
- data/lib/gir_ffi/type_map.rb +4 -2
- data/lib/gir_ffi/union_base.rb +24 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/tasks/test.rake +73 -7
- data/test/base_test_helper.rb +3 -19
- data/test/ffi-glib/array_test.rb +6 -0
- data/test/ffi-glib/ptr_array_test.rb +13 -0
- data/test/ffi-glib/ruby_closure_test.rb +7 -7
- data/test/ffi-glib/sized_array_test.rb +2 -2
- data/test/ffi-gobject/gobject_test.rb +3 -12
- data/test/ffi-gobject/object_test.rb +33 -2
- data/test/ffi-gobject/value_test.rb +114 -1
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +2 -2
- data/test/ffi-gobject_introspection/i_object_info_test.rb +3 -3
- data/test/ffi-gobject_introspection/i_repository_test.rb +26 -21
- data/test/ffi-gobject_test.rb +14 -14
- data/test/gir_ffi-base/glib/boolean_test.rb +6 -0
- data/test/gir_ffi/arg_helper_test.rb +2 -122
- data/test/gir_ffi/builder_test.rb +67 -204
- data/test/gir_ffi/{argument_builder_test.rb → builders/argument_builder_test.rb} +230 -108
- data/test/gir_ffi/builders/base_argument_builder_test.rb +5 -0
- data/test/gir_ffi/builders/callback_builder_test.rb +50 -0
- data/test/gir_ffi/builders/constant_builder_test.rb +4 -0
- data/test/gir_ffi/{builder/type/enum_test.rb → builders/enum_builder_test.rb} +2 -3
- data/test/gir_ffi/builders/field_builder_test.rb +94 -0
- data/test/gir_ffi/{function_builder_test.rb → builders/function_builder_test.rb} +43 -24
- data/test/gir_ffi/{builder/type/interface_test.rb → builders/interface_builder_test.rb} +2 -2
- data/test/gir_ffi/{builder/module_test.rb → builders/module_builder_test.rb} +12 -13
- data/test/gir_ffi/{builder/type/object_test.rb → builders/object_builder_test.rb} +9 -9
- data/test/gir_ffi/{return_value_builder_test.rb → builders/return_value_builder_test.rb} +94 -58
- data/test/gir_ffi/builders/signal_builder_test.rb +62 -0
- data/test/gir_ffi/{builder/type/struct_test.rb → builders/struct_builder_test.rb} +36 -19
- data/test/gir_ffi/{builder/type/unintrospectable_test.rb → builders/unintrospectable_builder_test.rb} +3 -3
- data/test/gir_ffi/builders/union_builder_test.rb +29 -0
- data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb} +2 -2
- data/test/gir_ffi/callback_base_test.rb +11 -0
- data/test/gir_ffi/class_base_test.rb +22 -22
- data/test/gir_ffi/ffi_ext/pointer_test.rb +18 -0
- data/test/gir_ffi/in_out_pointer_test.rb +0 -7
- data/test/gir_ffi/in_pointer_test.rb +27 -3
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +16 -44
- data/test/gir_ffi/info_ext/i_type_info_test.rb +315 -74
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +6 -0
- data/test/gir_ffi/interface_base_test.rb +3 -5
- data/test/gir_ffi/object_base_test.rb +10 -6
- data/test/gir_ffi/type_map_test.rb +2 -2
- data/test/gir_ffi/unintrospectable_type_info_test.rb +2 -2
- data/test/gir_ffi_test_helper.rb +12 -4
- data/test/integration/generated_gimarshallingtests_test.rb +436 -76
- data/test/integration/generated_gio_test.rb +5 -11
- data/test/integration/generated_gobject_test.rb +8 -0
- data/test/integration/generated_regress_test.rb +755 -309
- data/test/integration/generated_secret_test.rb +2 -1
- metadata +73 -72
- data/lib/ffi-gobject/ruby_style.rb +0 -23
- data/lib/gir_ffi/argument_builder.rb +0 -154
- data/lib/gir_ffi/builder/field.rb +0 -60
- data/lib/gir_ffi/builder/module.rb +0 -127
- data/lib/gir_ffi/builder/type.rb +0 -39
- data/lib/gir_ffi/builder/type/base.rb +0 -48
- data/lib/gir_ffi/builder/type/callback.rb +0 -30
- data/lib/gir_ffi/builder/type/constant.rb +0 -22
- data/lib/gir_ffi/builder/type/enum.rb +0 -66
- data/lib/gir_ffi/builder/type/interface.rb +0 -33
- data/lib/gir_ffi/builder/type/object.rb +0 -134
- data/lib/gir_ffi/builder/type/registered_type.rb +0 -62
- data/lib/gir_ffi/builder/type/struct.rb +0 -34
- data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -39
- data/lib/gir_ffi/builder/type/union.rb +0 -34
- data/lib/gir_ffi/builder/type/user_defined.rb +0 -107
- data/lib/gir_ffi/builder/type/with_layout.rb +0 -62
- data/lib/gir_ffi/builder/type/with_methods.rb +0 -64
- data/lib/gir_ffi/callback.rb +0 -72
- data/lib/gir_ffi/callback_helper.rb +0 -11
- data/lib/gir_ffi/error_argument_builder.rb +0 -17
- data/lib/gir_ffi/function_builder.rb +0 -112
- data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_object_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_struct_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_union_info.rb +0 -12
- data/lib/gir_ffi/return_value_builder.rb +0 -81
- data/test/ffi-gobject/ruby_style_test.rb +0 -38
- data/test/gir_ffi/base_argument_builder_test.rb +0 -13
- data/test/gir_ffi/builder/type/callback_test.rb +0 -6
- data/test/gir_ffi/builder/type/constant_test.rb +0 -4
- data/test/gir_ffi/builder/type/union_test.rb +0 -12
- data/test/gir_ffi/callback_helper_test.rb +0 -10
- data/test/gir_ffi/callback_test.rb +0 -49
- data/test/gir_ffi/info_ext/i_arg_info_test.rb +0 -39
- data/test/gir_ffi/info_ext/i_object_info_test.rb +0 -14
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'gir_ffi/base_argument_builder'
|
2
|
-
|
3
|
-
module GirFFI
|
4
|
-
# Implements argument processing for error handling arguments. These
|
5
|
-
# arguments are not part of the introspected signature, but their
|
6
|
-
# presence is indicated by the 'throws' attribute of the function.
|
7
|
-
class ErrorArgumentBuilder < BaseArgumentBuilder
|
8
|
-
def pre
|
9
|
-
[ "#{callarg} = FFI::MemoryPointer.new(:pointer).write_pointer nil" ]
|
10
|
-
end
|
11
|
-
|
12
|
-
def post
|
13
|
-
[ "GirFFI::ArgHelper.check_error(#{callarg})" ]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'gir_ffi/argument_builder'
|
2
|
-
require 'gir_ffi/return_value_builder'
|
3
|
-
require 'gir_ffi/error_argument_builder'
|
4
|
-
require 'gir_ffi/null_argument_builder'
|
5
|
-
require 'gir_ffi/variable_name_generator'
|
6
|
-
|
7
|
-
module GirFFI
|
8
|
-
# Implements the creation of a Ruby function definition out of a GIR
|
9
|
-
# IFunctionInfo.
|
10
|
-
class FunctionBuilder
|
11
|
-
def initialize info, libmodule
|
12
|
-
@info = info
|
13
|
-
@libmodule = libmodule
|
14
|
-
end
|
15
|
-
|
16
|
-
def generate
|
17
|
-
vargen = GirFFI::VariableNameGenerator.new
|
18
|
-
@argument_builders = @info.args.map {|arg| ArgumentBuilder.new vargen, arg }
|
19
|
-
@return_value_builder = ReturnValueBuilder.new(vargen, @info.return_type,
|
20
|
-
@info.constructor?)
|
21
|
-
|
22
|
-
link_array_length_arguments
|
23
|
-
setup_error_argument vargen
|
24
|
-
return filled_out_template
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def link_array_length_arguments
|
30
|
-
alldata = @argument_builders.dup << @return_value_builder
|
31
|
-
|
32
|
-
alldata.each {|data|
|
33
|
-
idx = data.type_info.array_length
|
34
|
-
if idx > -1
|
35
|
-
other_data = @argument_builders[idx]
|
36
|
-
data.length_arg = other_data
|
37
|
-
other_data.array_arg = data
|
38
|
-
end
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
def setup_error_argument vargen
|
43
|
-
klass = @info.throws? ? ErrorArgumentBuilder : NullArgumentBuilder
|
44
|
-
@errarg = klass.new vargen, nil, nil, :error
|
45
|
-
end
|
46
|
-
|
47
|
-
def filled_out_template
|
48
|
-
meta = @info.method? ? '' : "self."
|
49
|
-
|
50
|
-
code = "def #{meta}#{@info.safe_name} #{method_arguments.join(', ')}\n"
|
51
|
-
code << method_body
|
52
|
-
code << "\nend\n"
|
53
|
-
end
|
54
|
-
|
55
|
-
def method_body
|
56
|
-
lines = preparation << function_call << post_processing << cleanup
|
57
|
-
lines << "return #{return_values.join(', ')}" if has_return_values?
|
58
|
-
lines.flatten.join("\n").indent
|
59
|
-
end
|
60
|
-
|
61
|
-
def function_call
|
62
|
-
"#{capture}#{@libmodule}.#{@info.symbol} #{function_call_arguments.join(', ')}"
|
63
|
-
end
|
64
|
-
|
65
|
-
def method_arguments
|
66
|
-
@argument_builders.map(&:inarg).compact
|
67
|
-
end
|
68
|
-
|
69
|
-
def function_call_arguments
|
70
|
-
ca = @argument_builders.map(&:callarg)
|
71
|
-
ca << @errarg.callarg
|
72
|
-
ca.unshift "self" if @info.method?
|
73
|
-
ca.compact
|
74
|
-
end
|
75
|
-
|
76
|
-
def preparation
|
77
|
-
pr = @argument_builders.map(&:pre)
|
78
|
-
pr << @errarg.pre
|
79
|
-
pr.flatten
|
80
|
-
end
|
81
|
-
|
82
|
-
def capture
|
83
|
-
if (cv = @return_value_builder.cvar)
|
84
|
-
"#{cv} = "
|
85
|
-
else
|
86
|
-
""
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def post_processing
|
91
|
-
# FIXME: Sorting knows too much about internals of ArgumentBuilder.
|
92
|
-
args = @argument_builders.sort_by {|arg| arg.type_info.array_length}
|
93
|
-
args << @return_value_builder
|
94
|
-
args.unshift @errarg
|
95
|
-
|
96
|
-
args.map {|arg| arg.post}
|
97
|
-
end
|
98
|
-
|
99
|
-
def cleanup
|
100
|
-
@argument_builders.map {|item| item.cleanup}
|
101
|
-
end
|
102
|
-
|
103
|
-
def return_values
|
104
|
-
@return_values ||= ([@return_value_builder.retval] +
|
105
|
-
@argument_builders.map(&:retval)).compact
|
106
|
-
end
|
107
|
-
|
108
|
-
def has_return_values?
|
109
|
-
!return_values.empty?
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'gir_ffi/base_argument_builder'
|
2
|
-
|
3
|
-
module GirFFI
|
4
|
-
# Implements building post-processing statements for return values.
|
5
|
-
class ReturnValueBuilder < BaseArgumentBuilder
|
6
|
-
def initialize var_gen, type_info, is_constructor
|
7
|
-
super var_gen, nil, type_info, :return
|
8
|
-
@is_constructor = is_constructor
|
9
|
-
end
|
10
|
-
|
11
|
-
def post
|
12
|
-
if has_conversion?
|
13
|
-
[ "#{retname} = #{post_conversion}" ]
|
14
|
-
else
|
15
|
-
[]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def inarg
|
20
|
-
nil
|
21
|
-
end
|
22
|
-
|
23
|
-
# TODO: Rename
|
24
|
-
def cvar
|
25
|
-
callarg unless is_void_return_value?
|
26
|
-
end
|
27
|
-
|
28
|
-
def retval
|
29
|
-
if has_conversion?
|
30
|
-
super
|
31
|
-
elsif is_void_return_value?
|
32
|
-
nil
|
33
|
-
else
|
34
|
-
callarg
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def post_conversion
|
41
|
-
raw = cvar
|
42
|
-
|
43
|
-
if needs_constructor_wrap?
|
44
|
-
"self.constructor_wrap(#{raw})"
|
45
|
-
elsif needs_wrapping?
|
46
|
-
"#{argument_class_name}.wrap(#{conversion_arguments raw})"
|
47
|
-
else
|
48
|
-
case specialized_type_tag
|
49
|
-
when :utf8
|
50
|
-
# TODO: Re-use methods in InOutPointer for this conversion
|
51
|
-
"GirFFI::ArgHelper.ptr_to_utf8(#{raw})"
|
52
|
-
when :c
|
53
|
-
"GLib::SizedArray.wrap(#{subtype_tag_or_class_name}, #{array_size}, #{raw})"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def retname
|
59
|
-
@retname ||= @var_gen.new_var
|
60
|
-
end
|
61
|
-
|
62
|
-
def has_conversion?
|
63
|
-
needs_wrapping? || [ :utf8, :c ].include?(specialized_type_tag)
|
64
|
-
end
|
65
|
-
|
66
|
-
# TODO: Merge with ArgumentBuilder#needs_outgoing_parameter_conversion?
|
67
|
-
def needs_wrapping?
|
68
|
-
[ :array, :byte_array, :error, :ghash, :glist, :gslist, :interface,
|
69
|
-
:object, :ptr_array, :struct, :strv, :union, :zero_terminated
|
70
|
-
].include?(specialized_type_tag)
|
71
|
-
end
|
72
|
-
|
73
|
-
def needs_constructor_wrap?
|
74
|
-
@is_constructor && [ :interface, :object ].include?(specialized_type_tag)
|
75
|
-
end
|
76
|
-
|
77
|
-
def is_void_return_value?
|
78
|
-
specialized_type_tag == :void && !type_info.pointer?
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'gir_ffi_test_helper'
|
2
|
-
|
3
|
-
require 'ffi-gobject/ruby_style'
|
4
|
-
|
5
|
-
describe GObject::RubyStyle do
|
6
|
-
class RubyStyleTest
|
7
|
-
include GObject::RubyStyle
|
8
|
-
def get_x
|
9
|
-
@x
|
10
|
-
end
|
11
|
-
def set_x(val)
|
12
|
-
@x = val
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
subject { RubyStyleTest.new }
|
17
|
-
|
18
|
-
it 'reads x by calling get_x' do
|
19
|
-
subject.set_x(1)
|
20
|
-
assert_equal 1, subject.x
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'writes x by calling set_x' do
|
24
|
-
subject.x = 2
|
25
|
-
assert_equal 2, subject.x
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'delegates signal_connect to GObject' do
|
29
|
-
mock(GObject).signal_connect(subject, 'some-event')
|
30
|
-
subject.signal_connect('some-event') do
|
31
|
-
nothing
|
32
|
-
end
|
33
|
-
|
34
|
-
RR.verify
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'gir_ffi_test_helper'
|
2
|
-
|
3
|
-
describe GirFFI::BaseArgumentBuilder do
|
4
|
-
describe "#subtype_tag_or_class_name" do
|
5
|
-
it "delegates to the type" do
|
6
|
-
mock(info = Object.new).subtype_tag_or_class_name { 'foo' }
|
7
|
-
|
8
|
-
builder = GirFFI::BaseArgumentBuilder.new nil, 'bar', info, :direction
|
9
|
-
assert_equal "foo", builder.subtype_tag_or_class_name
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'gir_ffi_test_helper'
|
2
|
-
|
3
|
-
describe GirFFI::Builder::Type::Union do
|
4
|
-
before do
|
5
|
-
@cbuilder = GirFFI::Builder::Type::Union.new get_introspection_data('GObject', 'TypeCValue')
|
6
|
-
end
|
7
|
-
|
8
|
-
it "returns false looking for a method that doesn't exist" do
|
9
|
-
assert_equal false, @cbuilder.setup_instance_method('blub')
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'gir_ffi_test_helper'
|
2
|
-
|
3
|
-
describe GirFFI::CallbackHelper do
|
4
|
-
describe ".store_callback" do
|
5
|
-
it "stores the passed in proc in GirFFI::CallbackHelper::CALLBACKS" do
|
6
|
-
GirFFI::CallbackHelper.store_callback "some-callback"
|
7
|
-
GirFFI::CallbackHelper::CALLBACKS.last.must_equal "some-callback"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'gir_ffi_test_helper'
|
2
|
-
|
3
|
-
describe GirFFI::Callback do
|
4
|
-
describe "::map_single_callback_arg" do
|
5
|
-
it "maps a :struct type by building the type and wrapping the argument in it" do
|
6
|
-
cinfo = get_introspection_data 'GObject', 'ClosureMarshal'
|
7
|
-
ainfo = cinfo.args[0]
|
8
|
-
ifinfo = ainfo.argument_type.interface
|
9
|
-
|
10
|
-
assert_equal :struct, ifinfo.info_type
|
11
|
-
|
12
|
-
struct_class = Class.new
|
13
|
-
mock(GirFFI::Builder).build_class(ifinfo) { struct_class }
|
14
|
-
mock(struct_class).wrap("dummy") { "good-result" }
|
15
|
-
|
16
|
-
r = GirFFI::Callback.map_single_callback_arg "dummy", ainfo.argument_type
|
17
|
-
|
18
|
-
assert_equal "good-result", r
|
19
|
-
end
|
20
|
-
|
21
|
-
it "maps an :interface type by calling #to_object on the argument" do
|
22
|
-
cinfo = get_introspection_data 'Gtk', 'CellLayoutDataFunc'
|
23
|
-
ainfo = cinfo.args[0]
|
24
|
-
ifinfo = ainfo.argument_type.interface
|
25
|
-
|
26
|
-
assert_equal :interface, ifinfo.info_type
|
27
|
-
|
28
|
-
mock(ptr = Object.new).to_object { "good-result" }
|
29
|
-
|
30
|
-
r = GirFFI::Callback.map_single_callback_arg ptr, ainfo.argument_type
|
31
|
-
|
32
|
-
assert_equal "good-result", r
|
33
|
-
end
|
34
|
-
|
35
|
-
it "maps an :object type by calling #to_object on the argument" do
|
36
|
-
cinfo = get_introspection_data 'Gtk', 'CellLayoutDataFunc'
|
37
|
-
ainfo = cinfo.args[1]
|
38
|
-
ifinfo = ainfo.argument_type.interface
|
39
|
-
|
40
|
-
assert_equal :object, ifinfo.info_type
|
41
|
-
|
42
|
-
mock(ptr = Object.new).to_object { "good-result" }
|
43
|
-
|
44
|
-
r = GirFFI::Callback.map_single_callback_arg ptr, ainfo.argument_type
|
45
|
-
|
46
|
-
assert_equal "good-result", r
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'gir_ffi_test_helper'
|
2
|
-
|
3
|
-
describe GirFFI::InfoExt::IArgInfo do
|
4
|
-
let(:klass) { Class.new do
|
5
|
-
include GirFFI::InfoExt::IArgInfo
|
6
|
-
end }
|
7
|
-
let(:arg_info) { klass.new }
|
8
|
-
|
9
|
-
describe "#cast_signal_argument" do
|
10
|
-
describe "with info for an enum" do
|
11
|
-
before do
|
12
|
-
enuminfo = get_introspection_data 'GLib', 'DateMonth'
|
13
|
-
stub(type_info = Object.new).interface { enuminfo }
|
14
|
-
stub(type_info).tag { :interface }
|
15
|
-
stub(arg_info).argument_type { type_info }
|
16
|
-
end
|
17
|
-
|
18
|
-
it "casts an integer to its enum symbol" do
|
19
|
-
res = arg_info.cast_signal_argument 7
|
20
|
-
assert_equal :july, res
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "with info for an interface" do
|
25
|
-
before do
|
26
|
-
ifaceinfo = get_introspection_data 'Regress', 'TestInterface'
|
27
|
-
stub(type_info = Object.new).interface { ifaceinfo }
|
28
|
-
stub(type_info).tag { :interface }
|
29
|
-
stub(arg_info).argument_type { type_info }
|
30
|
-
end
|
31
|
-
|
32
|
-
it "casts the argument by calling #to_object on it" do
|
33
|
-
mock(ptr = Object.new).to_object { "good-result" }
|
34
|
-
res = arg_info.cast_signal_argument ptr
|
35
|
-
res.must_equal "good-result"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|