gir_ffi 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/DESIGN.rdoc +54 -0
- data/History.txt +3 -0
- data/README.rdoc +59 -0
- data/Rakefile +21 -0
- data/TODO.rdoc +40 -0
- data/examples/01_empty_window.rb +15 -0
- data/examples/02_hello_world.rb +30 -0
- data/examples/03_upgraded_hello_world.rb +45 -0
- data/examples/demo_ffi_inherited_layout.rb +21 -0
- data/examples/demo_ffi_nested_struct.rb +17 -0
- data/examples/demo_ffi_safe_inherited_layout.rb +43 -0
- data/examples/hard_coded.rb +144 -0
- data/lib/gir_ffi.rb +47 -0
- data/lib/gir_ffi/allocation_helper.rb +12 -0
- data/lib/gir_ffi/arg_helper.rb +77 -0
- data/lib/gir_ffi/base.rb +23 -0
- data/lib/gir_ffi/builder.rb +159 -0
- data/lib/gir_ffi/builder_helper.rb +32 -0
- data/lib/gir_ffi/class_base.rb +11 -0
- data/lib/gir_ffi/class_builder.rb +116 -0
- data/lib/gir_ffi/constructor_definition_builder.rb +20 -0
- data/lib/gir_ffi/function_definition_builder.rb +148 -0
- data/lib/gir_ffi/g_error.rb +8 -0
- data/lib/gir_ffi/g_type.rb +14 -0
- data/lib/gir_ffi/i_arg_info.rb +16 -0
- data/lib/gir_ffi/i_base_info.rb +45 -0
- data/lib/gir_ffi/i_callable_info.rb +18 -0
- data/lib/gir_ffi/i_callback_info.rb +7 -0
- data/lib/gir_ffi/i_constant_info.rb +6 -0
- data/lib/gir_ffi/i_enum_info.rb +13 -0
- data/lib/gir_ffi/i_field_info.rb +10 -0
- data/lib/gir_ffi/i_flags_info.rb +5 -0
- data/lib/gir_ffi/i_function_info.rb +16 -0
- data/lib/gir_ffi/i_interface_info.rb +7 -0
- data/lib/gir_ffi/i_object_info.rb +50 -0
- data/lib/gir_ffi/i_property_info.rb +7 -0
- data/lib/gir_ffi/i_registered_type_info.rb +8 -0
- data/lib/gir_ffi/i_repository.rb +108 -0
- data/lib/gir_ffi/i_signal_info.rb +7 -0
- data/lib/gir_ffi/i_struct_info.rb +22 -0
- data/lib/gir_ffi/i_type_info.rb +25 -0
- data/lib/gir_ffi/i_union_info.rb +7 -0
- data/lib/gir_ffi/i_value_info.rb +8 -0
- data/lib/gir_ffi/i_vfunc_info.rb +7 -0
- data/lib/gir_ffi/lib.rb +174 -0
- data/lib/gir_ffi/lib_c.rb +11 -0
- data/lib/gir_ffi/method_missing_definition_builder.rb +62 -0
- data/lib/gir_ffi/module_builder.rb +66 -0
- data/lib/gir_ffi/overrides/gtk.rb +12 -0
- data/lib/gir_ffi/version.rb +4 -0
- data/tasks/bones.rake +87 -0
- data/tasks/notes.rake +134 -0
- data/tasks/post_load.rake +25 -0
- data/tasks/setup.rb +138 -0
- data/tasks/test.rake +22 -0
- data/test/arg_helper_test.rb +112 -0
- data/test/builder_test.rb +328 -0
- data/test/constructor_definition_builder_test.rb +19 -0
- data/test/function_definition_builder_test.rb +60 -0
- data/test/g_type_test.rb +22 -0
- data/test/girffi_test.rb +11 -0
- data/test/gtk_overrides_test.rb +22 -0
- data/test/i_repository_test.rb +54 -0
- data/test/test_helper.rb +39 -0
- metadata +174 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
|
+
require 'gir_ffi/builder'
|
3
|
+
|
4
|
+
class ConstructorDefinitionBuilderTest < Test::Unit::TestCase
|
5
|
+
context "The ConstructorDefinitionBuilder" do
|
6
|
+
should "build correct definition of Gtk::Window#new" do
|
7
|
+
go = get_method_introspection_data 'Gtk', 'Window', 'new'
|
8
|
+
cbuilder = GirFFI::ConstructorDefinitionBuilder.new go, Lib
|
9
|
+
code = cbuilder.generate
|
10
|
+
|
11
|
+
expected =
|
12
|
+
"def new type
|
13
|
+
_real_new Lib.gtk_window_new(type)
|
14
|
+
end"
|
15
|
+
|
16
|
+
assert_equal cws(expected), cws(code)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
|
+
require 'gir_ffi/builder'
|
3
|
+
require 'gir_ffi/function_definition_builder'
|
4
|
+
|
5
|
+
class FunctionDefinitionBuilderTest < Test::Unit::TestCase
|
6
|
+
context "The FunctionDefinition builder" do
|
7
|
+
should "build correct definition of Gtk.init" do
|
8
|
+
go = get_function_introspection_data 'Gtk', 'init'
|
9
|
+
fbuilder = GirFFI::FunctionDefinitionBuilder.new go, Lib
|
10
|
+
code = fbuilder.generate
|
11
|
+
|
12
|
+
expected = "
|
13
|
+
def init argc, argv
|
14
|
+
_v1 = GirFFI::ArgHelper.int_to_inoutptr argc
|
15
|
+
_v3 = GirFFI::ArgHelper.string_array_to_inoutptr argv
|
16
|
+
Lib.gtk_init _v1, _v3
|
17
|
+
_v2 = GirFFI::ArgHelper.outptr_to_int _v1
|
18
|
+
_v4 = GirFFI::ArgHelper.outptr_to_string_array _v3, argv.nil? ? 0 : argv.size
|
19
|
+
return _v2, _v4
|
20
|
+
end
|
21
|
+
"
|
22
|
+
|
23
|
+
assert_equal cws(expected), cws(code)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "build correct definition of Gtk::Widget.show" do
|
27
|
+
go = get_method_introspection_data 'Gtk', 'Widget', 'show'
|
28
|
+
fbuilder = GirFFI::FunctionDefinitionBuilder.new go, Lib
|
29
|
+
code = fbuilder.generate
|
30
|
+
|
31
|
+
expected = "
|
32
|
+
def show
|
33
|
+
Lib.gtk_widget_show self
|
34
|
+
end
|
35
|
+
"
|
36
|
+
|
37
|
+
assert_equal cws(expected), cws(code)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "build correct definition of GObject.signal_connect_data" do
|
41
|
+
go = get_function_introspection_data 'GObject', 'signal_connect_data'
|
42
|
+
fbuilder = GirFFI::FunctionDefinitionBuilder.new go, Lib
|
43
|
+
code = fbuilder.generate
|
44
|
+
|
45
|
+
expected =
|
46
|
+
"def signal_connect_data instance, detailed_signal, c_handler, data, destroy_data, connect_flags
|
47
|
+
_v2 = GirFFI::ArgHelper.object_to_inptr instance
|
48
|
+
_v3 = GirFFI::ArgHelper.mapped_callback_args c_handler
|
49
|
+
Lib::CALLBACKS << _v3
|
50
|
+
_v4 = GirFFI::ArgHelper.object_to_inptr data
|
51
|
+
_v5 = GirFFI::ArgHelper.mapped_callback_args destroy_data
|
52
|
+
Lib::CALLBACKS << _v5
|
53
|
+
_v1 = Lib.g_signal_connect_data _v2, detailed_signal, _v3, _v4, _v5, connect_flags
|
54
|
+
return _v1
|
55
|
+
end"
|
56
|
+
|
57
|
+
assert_equal cws(expected), cws(code)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/test/g_type_test.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
|
+
require 'gir_ffi/g_type'
|
3
|
+
|
4
|
+
class HelperGTypeTest < Test::Unit::TestCase
|
5
|
+
context "The GType module" do
|
6
|
+
should "have init as a public method" do
|
7
|
+
assert GirFFI::GType.respond_to?('init')
|
8
|
+
end
|
9
|
+
|
10
|
+
should "not have g_type_init as a public method" do
|
11
|
+
assert GirFFI::GType.respond_to?('g_type_init') == false
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
context "the init method" do
|
16
|
+
should "not raise an error" do
|
17
|
+
assert_nothing_raised do
|
18
|
+
GirFFI::GType.init
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/test/girffi_test.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
|
+
require 'gir_ffi'
|
3
|
+
GirFFI.setup :Gtk
|
4
|
+
|
5
|
+
class GtkOverridesTest < Test::Unit::TestCase
|
6
|
+
context "The Gtk.init function" do
|
7
|
+
should "not take any arguments" do
|
8
|
+
assert_raises(ArgumentError) { Gtk.init 1, ["foo"] }
|
9
|
+
assert_nothing_raised { Gtk.init }
|
10
|
+
end
|
11
|
+
# FIXME: The following test doesn't actually work.
|
12
|
+
# In practice however, the Gtk.init function does exactly this.
|
13
|
+
if false
|
14
|
+
should "process ARGV, removing Gtk+ options" do
|
15
|
+
ARGV.replace ["foo", "--g-fatal-warnings"]
|
16
|
+
Gtk.init
|
17
|
+
assert_same_elements ["foo"], ARGV
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
|
+
require 'gir_ffi/i_repository'
|
3
|
+
|
4
|
+
module GirFFI
|
5
|
+
class IRepositoryTest < Test::Unit::TestCase
|
6
|
+
context "An IRepository object" do
|
7
|
+
should "not be created by calling new()" do
|
8
|
+
assert_raise NoMethodError do
|
9
|
+
IRepository.new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be created by calling default()" do
|
14
|
+
gir = IRepository.default
|
15
|
+
assert_kind_of IRepository, gir
|
16
|
+
end
|
17
|
+
|
18
|
+
should "be a singleton" do
|
19
|
+
gir = IRepository.default
|
20
|
+
gir2 = IRepository.default
|
21
|
+
assert_equal gir, gir2
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "The namespace method" do
|
26
|
+
should "raise an error if the namespace doesn't exist" do
|
27
|
+
assert_raise RuntimeError do
|
28
|
+
IRepository.default.require 'VeryUnlikelyGObjectNamespaceName', nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
should "allow version to be nil" do
|
33
|
+
assert_nothing_raised do
|
34
|
+
IRepository.default.require 'Gtk', nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "Enumerating the infos" do
|
40
|
+
setup do
|
41
|
+
@gir = IRepository.default
|
42
|
+
@gir.require 'Gtk', nil
|
43
|
+
end
|
44
|
+
|
45
|
+
should "yield more than one object" do
|
46
|
+
assert_operator @gir.n_infos('Gtk'), :>, 0
|
47
|
+
end
|
48
|
+
|
49
|
+
should "yield IBaseInfo objects" do
|
50
|
+
assert_kind_of IBaseInfo, @gir.info('Gtk', 0)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'shoulda'
|
2
|
+
require 'ffi'
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
# Since the tests will call Gtk+ functions, Gtk+ must be initialized.
|
6
|
+
module DummyGtk
|
7
|
+
module Lib
|
8
|
+
extend FFI::Library
|
9
|
+
|
10
|
+
ffi_lib "gtk-x11-2.0"
|
11
|
+
attach_function :gtk_init, [:pointer, :pointer], :void
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.init
|
15
|
+
Lib.gtk_init nil, nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
DummyGtk.init
|
20
|
+
|
21
|
+
# Need a dummy module for some tests.
|
22
|
+
module Lib
|
23
|
+
end
|
24
|
+
|
25
|
+
class Test::Unit::TestCase
|
26
|
+
def cws code
|
27
|
+
code.gsub(/(^\s*|\s*$)/, "")
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_function_introspection_data namespace, function
|
31
|
+
GirFFI::IRepository.default.require namespace, nil
|
32
|
+
GirFFI::Builder.send :function_introspection_data, namespace, function
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_method_introspection_data namespace, klass, function
|
36
|
+
GirFFI::IRepository.default.require namespace, nil
|
37
|
+
GirFFI::Builder.send :method_introspection_data, namespace, klass, function
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gir_ffi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matijs van Zuijlen
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-25 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: ffi
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 6
|
33
|
+
- 3
|
34
|
+
version: 0.6.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: shoulda
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 37
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 11
|
49
|
+
- 3
|
50
|
+
version: 2.11.3
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Ruby-FFI-based binding of the GObject Introspection Repository
|
54
|
+
email:
|
55
|
+
- matijs@matijs.net
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files:
|
61
|
+
- DESIGN.rdoc
|
62
|
+
- History.txt
|
63
|
+
- README.rdoc
|
64
|
+
- TODO.rdoc
|
65
|
+
files:
|
66
|
+
- lib/gir_ffi.rb
|
67
|
+
- lib/gir_ffi/lib_c.rb
|
68
|
+
- lib/gir_ffi/builder_helper.rb
|
69
|
+
- lib/gir_ffi/i_field_info.rb
|
70
|
+
- lib/gir_ffi/i_flags_info.rb
|
71
|
+
- lib/gir_ffi/g_error.rb
|
72
|
+
- lib/gir_ffi/i_object_info.rb
|
73
|
+
- lib/gir_ffi/builder.rb
|
74
|
+
- lib/gir_ffi/constructor_definition_builder.rb
|
75
|
+
- lib/gir_ffi/i_enum_info.rb
|
76
|
+
- lib/gir_ffi/base.rb
|
77
|
+
- lib/gir_ffi/i_value_info.rb
|
78
|
+
- lib/gir_ffi/i_signal_info.rb
|
79
|
+
- lib/gir_ffi/g_type.rb
|
80
|
+
- lib/gir_ffi/i_callback_info.rb
|
81
|
+
- lib/gir_ffi/lib.rb
|
82
|
+
- lib/gir_ffi/i_property_info.rb
|
83
|
+
- lib/gir_ffi/i_registered_type_info.rb
|
84
|
+
- lib/gir_ffi/i_repository.rb
|
85
|
+
- lib/gir_ffi/i_vfunc_info.rb
|
86
|
+
- lib/gir_ffi/i_constant_info.rb
|
87
|
+
- lib/gir_ffi/class_base.rb
|
88
|
+
- lib/gir_ffi/i_struct_info.rb
|
89
|
+
- lib/gir_ffi/i_callable_info.rb
|
90
|
+
- lib/gir_ffi/function_definition_builder.rb
|
91
|
+
- lib/gir_ffi/i_function_info.rb
|
92
|
+
- lib/gir_ffi/version.rb
|
93
|
+
- lib/gir_ffi/overrides/gtk.rb
|
94
|
+
- lib/gir_ffi/allocation_helper.rb
|
95
|
+
- lib/gir_ffi/i_base_info.rb
|
96
|
+
- lib/gir_ffi/module_builder.rb
|
97
|
+
- lib/gir_ffi/method_missing_definition_builder.rb
|
98
|
+
- lib/gir_ffi/arg_helper.rb
|
99
|
+
- lib/gir_ffi/i_union_info.rb
|
100
|
+
- lib/gir_ffi/class_builder.rb
|
101
|
+
- lib/gir_ffi/i_interface_info.rb
|
102
|
+
- lib/gir_ffi/i_arg_info.rb
|
103
|
+
- lib/gir_ffi/i_type_info.rb
|
104
|
+
- test/i_repository_test.rb
|
105
|
+
- test/g_type_test.rb
|
106
|
+
- test/function_definition_builder_test.rb
|
107
|
+
- test/arg_helper_test.rb
|
108
|
+
- test/test_helper.rb
|
109
|
+
- test/girffi_test.rb
|
110
|
+
- test/constructor_definition_builder_test.rb
|
111
|
+
- test/builder_test.rb
|
112
|
+
- test/gtk_overrides_test.rb
|
113
|
+
- tasks/bones.rake
|
114
|
+
- tasks/test.rake
|
115
|
+
- tasks/post_load.rake
|
116
|
+
- tasks/setup.rb
|
117
|
+
- tasks/notes.rake
|
118
|
+
- examples/demo_ffi_safe_inherited_layout.rb
|
119
|
+
- examples/demo_ffi_nested_struct.rb
|
120
|
+
- examples/demo_ffi_inherited_layout.rb
|
121
|
+
- examples/hard_coded.rb
|
122
|
+
- examples/03_upgraded_hello_world.rb
|
123
|
+
- examples/02_hello_world.rb
|
124
|
+
- examples/01_empty_window.rb
|
125
|
+
- TODO.rdoc
|
126
|
+
- DESIGN.rdoc
|
127
|
+
- README.rdoc
|
128
|
+
- History.txt
|
129
|
+
- Rakefile
|
130
|
+
has_rdoc: true
|
131
|
+
homepage: http://www.github.com/mvz/ruby-gir-ffi
|
132
|
+
licenses: []
|
133
|
+
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options:
|
136
|
+
- --main
|
137
|
+
- README.rdoc
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 3
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
version: "0"
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
hash: 3
|
155
|
+
segments:
|
156
|
+
- 0
|
157
|
+
version: "0"
|
158
|
+
requirements: []
|
159
|
+
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 1.3.7
|
162
|
+
signing_key:
|
163
|
+
specification_version: 3
|
164
|
+
summary: Ruby-FFI-based binding of the GObject Introspection Repository
|
165
|
+
test_files:
|
166
|
+
- test/arg_helper_test.rb
|
167
|
+
- test/builder_test.rb
|
168
|
+
- test/constructor_definition_builder_test.rb
|
169
|
+
- test/function_definition_builder_test.rb
|
170
|
+
- test/g_type_test.rb
|
171
|
+
- test/girffi_test.rb
|
172
|
+
- test/gtk_overrides_test.rb
|
173
|
+
- test/i_repository_test.rb
|
174
|
+
- test/test_helper.rb
|