gir_ffi 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/DESIGN.rdoc +9 -0
  2. data/History.txt +11 -0
  3. data/TODO.rdoc +6 -9
  4. data/examples/01_empty_window.rb +1 -1
  5. data/examples/02_hello_world.rb +4 -4
  6. data/examples/03_upgraded_hello_world.rb +7 -8
  7. data/lib/gir_ffi.rb +0 -4
  8. data/lib/gir_ffi/arg_helper.rb +27 -2
  9. data/lib/gir_ffi/builder.rb +13 -86
  10. data/lib/gir_ffi/builder_helper.rb +2 -15
  11. data/lib/gir_ffi/class_base.rb +51 -0
  12. data/lib/gir_ffi/class_builder.rb +178 -52
  13. data/lib/gir_ffi/function_definition_builder.rb +46 -9
  14. data/lib/gir_ffi/g_object.rb +37 -0
  15. data/lib/gir_ffi/i_arg_info.rb +27 -9
  16. data/lib/gir_ffi/i_base_info.rb +12 -4
  17. data/lib/gir_ffi/i_callable_info.rb +15 -5
  18. data/lib/gir_ffi/i_enum_info.rb +9 -3
  19. data/lib/gir_ffi/i_field_info.rb +12 -4
  20. data/lib/gir_ffi/i_function_info.rb +24 -8
  21. data/lib/gir_ffi/i_object_info.rb +63 -21
  22. data/lib/gir_ffi/i_registered_type_info.rb +11 -0
  23. data/lib/gir_ffi/i_repository.rb +2 -2
  24. data/lib/gir_ffi/i_signal_info.rb +1 -1
  25. data/lib/gir_ffi/i_struct_info.rb +24 -8
  26. data/lib/gir_ffi/i_type_info.rb +24 -8
  27. data/lib/gir_ffi/i_union_info.rb +15 -0
  28. data/lib/gir_ffi/i_value_info.rb +3 -1
  29. data/lib/gir_ffi/i_vfunc_info.rb +12 -1
  30. data/lib/gir_ffi/lib.rb +23 -1
  31. data/lib/gir_ffi/lib_c.rb +1 -1
  32. data/lib/gir_ffi/module_base.rb +19 -0
  33. data/lib/gir_ffi/module_builder.rb +67 -20
  34. data/lib/gir_ffi/overrides/gobject.rb +174 -0
  35. data/lib/gir_ffi/overrides/gtk.rb +26 -9
  36. data/test/builder_test.rb +57 -37
  37. data/test/{base_test.rb → class_base_test.rb} +3 -3
  38. data/test/class_builder_test.rb +48 -6
  39. data/test/everything_test.rb +285 -36
  40. data/test/function_definition_builder_test.rb +11 -9
  41. data/test/g_object_test.rb +22 -0
  42. data/test/gobject_overrides_test.rb +216 -0
  43. data/test/i_object_info_test.rb +21 -0
  44. data/test/module_builder_test.rb +54 -0
  45. data/test/test_helper.rb +6 -4
  46. metadata +18 -14
  47. data/lib/gir_ffi/base.rb +0 -25
  48. data/lib/gir_ffi/constructor_definition_builder.rb +0 -20
  49. data/lib/gir_ffi/g_type.rb +0 -14
  50. data/lib/gir_ffi/method_missing_definition_builder.rb +0 -59
  51. data/test/constructor_definition_builder_test.rb +0 -19
  52. data/test/g_type_test.rb +0 -22
@@ -0,0 +1,22 @@
1
+ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
+ require 'gir_ffi/g_object'
3
+
4
+ class GObjectTest < Test::Unit::TestCase
5
+ context "The GirFFI::GObject helper module" do
6
+ should "have type_init as a public method" do
7
+ assert GirFFI::GObject.respond_to?('type_init')
8
+ end
9
+
10
+ should "not have g_type_init as a public method" do
11
+ assert GirFFI::GObject.respond_to?('g_type_init') == false
12
+ end
13
+
14
+ end
15
+ context "the type_init method" do
16
+ should "not raise an error" do
17
+ assert_nothing_raised do
18
+ GirFFI::GObject.type_init
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,216 @@
1
+ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
+ require 'gir_ffi'
3
+
4
+ class GObjectOverridesTest < Test::Unit::TestCase
5
+ context "The GObject module with overridden functions" do
6
+ setup do
7
+ GirFFI.setup :GObject
8
+ GirFFI.setup :Everything
9
+ GirFFI.setup :Gio
10
+ end
11
+
12
+ context "the wrap_in_g_value function" do
13
+ should "wrap a boolean false" do
14
+ gv = GObject.wrap_in_g_value false
15
+ assert_instance_of GObject::Value, gv
16
+ assert_equal false, gv.get_boolean
17
+ end
18
+
19
+ should "wrap a boolean true" do
20
+ gv = GObject.wrap_in_g_value true
21
+ assert_instance_of GObject::Value, gv
22
+ assert_equal true, gv.get_boolean
23
+ end
24
+ end
25
+
26
+ context "the unwrap_g_value function" do
27
+ should "unwrap a boolean false" do
28
+ gv = GObject.wrap_in_g_value false
29
+ result = GObject.unwrap_g_value gv
30
+ assert_equal false, result
31
+ end
32
+
33
+ should "unwrap a boolean true" do
34
+ gv = GObject.wrap_in_g_value true
35
+ result = GObject.unwrap_g_value gv
36
+ assert_equal true, result
37
+ end
38
+ end
39
+
40
+ context "the signal_emit function" do
41
+ should "emit a signal" do
42
+ a = 1
43
+ o = Everything::TestSubObj.new
44
+ GObject.signal_connect_data o, "test", Proc.new { a = 2 }, nil, nil, 0
45
+ GObject.signal_emit o, "test"
46
+ assert_equal 2, a
47
+ end
48
+
49
+ should "handle return values" do
50
+ s = Gio::SocketService.new
51
+
52
+ argtypes = [:pointer, :pointer, :pointer, :pointer]
53
+ callback = FFI::Function.new(:bool, argtypes) { |a,b,c,d| true }
54
+ GObject.signal_connect_data s, "incoming", callback, nil, nil, 0
55
+ rv = GObject.signal_emit s, "incoming"
56
+ assert_equal true, rv.get_boolean
57
+ end
58
+
59
+ should "pass in extra arguments" do
60
+ o = Everything::TestSubObj.new
61
+ sb = Everything::TestSimpleBoxedA.new
62
+ sb[:some_int8] = 31
63
+ sb[:some_double] = 2.42
64
+ sb[:some_enum] = :value2
65
+ b2 = nil
66
+
67
+ argtypes = [:pointer, :pointer, :pointer]
68
+ callback = FFI::Function.new(:void, argtypes) do |a,b,c|
69
+ b2 = b
70
+ end
71
+ GObject.signal_connect_data o, "test-with-static-scope-arg", callback, nil, nil, 0
72
+ GObject.signal_emit o, "test-with-static-scope-arg", sb
73
+
74
+ sb2 = Everything::TestSimpleBoxedA.new b2
75
+ assert sb.equals(sb2)
76
+ end
77
+ end
78
+
79
+ context "the signal_connect function" do
80
+ should "install a signal handler" do
81
+ a = 1
82
+ o = Everything::TestSubObj.new
83
+ GObject.signal_connect(o, "test") { a = 2 }
84
+ GObject.signal_emit o, "test"
85
+ assert_equal 2, a
86
+ end
87
+
88
+ should "pass user data to handler" do
89
+ a = 1
90
+ o = Everything::TestSubObj.new
91
+ GObject.signal_connect(o, "test", 2) { |i, d| a = d }
92
+ GObject.signal_emit o, "test"
93
+ assert_equal 2, a
94
+ end
95
+
96
+ should "pass object to handler" do
97
+ o = Everything::TestSubObj.new
98
+ o2 = nil
99
+ GObject.signal_connect(o, "test") { |i, d| o2 = i }
100
+ GObject.signal_emit o, "test"
101
+ assert_instance_of Everything::TestSubObj, o2
102
+ assert_equal o.to_ptr, o2.to_ptr
103
+ end
104
+
105
+ should "not allow connecting an invalid signal" do
106
+ o = Everything::TestSubObj.new
107
+ assert_raises RuntimeError do
108
+ GObject.signal_connect(o, "not-really-a-signal") {}
109
+ end
110
+ end
111
+
112
+ should "handle return values" do
113
+ s = Gio::SocketService.new
114
+ GObject.signal_connect(s, "incoming") { true }
115
+ rv = GObject.signal_emit s, "incoming"
116
+ assert_equal true, rv.get_boolean
117
+ end
118
+
119
+ context "connecting a signal with extra arguments" do
120
+ setup do
121
+ @a = nil
122
+ @b = 2
123
+
124
+ o = Everything::TestSubObj.new
125
+ sb = Everything::TestSimpleBoxedA.new
126
+
127
+ GObject.signal_connect(o, "test-with-static-scope-arg", 2) { |i, object, d|
128
+ @a = d
129
+ @b = object
130
+ }
131
+ GObject.signal_emit o, "test-with-static-scope-arg"
132
+ end
133
+
134
+ should "move the user data argument" do
135
+ assert_equal 2, @a
136
+ end
137
+
138
+ should "pass on the extra arguments" do
139
+ assert_instance_of Everything::TestSimpleBoxedA, @b
140
+ end
141
+ end
142
+
143
+ end
144
+
145
+ context "The GObject overrides Helper module" do
146
+ context "#signal_arguments_to_gvalue_array" do
147
+ context "the result of wrapping test-with-static-scope-arg" do
148
+ setup do
149
+ o = Everything::TestSubObj.new
150
+ b = Everything::TestSimpleBoxedA.new
151
+
152
+ @gva =
153
+ GirFFI::Overrides::GObject::Helper.signal_arguments_to_gvalue_array(
154
+ "test-with-static-scope-arg", o, b)
155
+ end
156
+
157
+ should "be a GObject::ValueArray" do
158
+ assert_instance_of GObject::ValueArray, @gva
159
+ end
160
+
161
+ should "contain two values" do
162
+ assert_equal 2, @gva[:n_values]
163
+ end
164
+
165
+ should "have a first value with GType for TestSubObj" do
166
+ assert_equal Everything::TestSubObj.get_gtype, (@gva.get_nth 0)[:g_type]
167
+ end
168
+
169
+ should "have a second value with GType for TestSimpleBoxedA" do
170
+ assert_equal Everything::TestSimpleBoxedA.get_gtype, (@gva.get_nth 1)[:g_type]
171
+ end
172
+ end
173
+ end
174
+
175
+ context "#cast_back_signal_arguments" do
176
+ context "the result of casting pointers for the test-with-static-scope-arg signal" do
177
+ setup do
178
+ sig_name = "test-with-static-scope-arg"
179
+ o = Everything::TestSubObj.new
180
+ b = Everything::TestSimpleBoxedA.new
181
+ ud = GirFFI::ArgHelper.object_to_inptr "Hello!"
182
+ sig = o.class.gir_ffi_builder.find_signal sig_name
183
+
184
+ @gva =
185
+ GirFFI::Overrides::GObject::Helper.cast_back_signal_arguments(
186
+ sig, o.class, o.to_ptr, b.to_ptr, ud)
187
+ end
188
+
189
+ should "have three elements" do
190
+ assert_equal 3, @gva.length
191
+ end
192
+
193
+ context "its first value" do
194
+ should "be a TestSubObj" do
195
+ assert_instance_of Everything::TestSubObj, @gva[0]
196
+ end
197
+ end
198
+
199
+ context "its second value" do
200
+ should "be a TestSimpleBoxedA" do
201
+ assert_instance_of Everything::TestSimpleBoxedA, @gva[1]
202
+ end
203
+ end
204
+
205
+ context "its third value" do
206
+ should "be a 'Hello!'" do
207
+ assert_equal "Hello!", @gva[2]
208
+ end
209
+ end
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
215
+
216
+
@@ -0,0 +1,21 @@
1
+ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
+ require 'gir_ffi'
3
+
4
+ module GirFFI
5
+ class IObjectInfoTest < Test::Unit::TestCase
6
+ context "An IObjectInfo object" do
7
+
8
+ setup do
9
+ gir = IRepository.default
10
+ gir.require 'Everything', nil
11
+ @info = gir.find_by_name 'Everything', 'TestObj'
12
+ end
13
+
14
+ should "find a vfunc by name" do
15
+ assert_not_nil @info.find_vfunc("matrix")
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+
@@ -0,0 +1,54 @@
1
+ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
+ require 'gir_ffi'
3
+
4
+ class ModuleBuilderTest < Test::Unit::TestCase
5
+ context "The ModuleBuilder" do
6
+ context "for Gtk" do
7
+ setup do
8
+ @mbuilder = GirFFI::ModuleBuilder.new('Gtk')
9
+ end
10
+
11
+ context "looking at Gtk.main" do
12
+ setup do
13
+ @go = get_function_introspection_data 'Gtk', 'main'
14
+ end
15
+
16
+ should "build correct definition of Gtk.main" do
17
+ code = @mbuilder.send :function_definition, @go, Lib
18
+ expected = "def main\n::Lib.gtk_main\nend"
19
+ assert_equal cws(expected), cws(code)
20
+ end
21
+ end
22
+
23
+ context "looking at Gtk.init" do
24
+ setup do
25
+ @go = get_function_introspection_data 'Gtk', 'init'
26
+ end
27
+
28
+ should "delegate definition to FunctionDefinitionBuilder" do
29
+ code = @mbuilder.send :function_definition, @go, Lib
30
+ expected = GirFFI::FunctionDefinitionBuilder.new(@go, Lib).generate
31
+ assert_equal cws(expected), cws(code)
32
+ end
33
+ end
34
+ end
35
+
36
+ context "for GObject" do
37
+ setup do
38
+ @mbuilder = GirFFI::ModuleBuilder.new('GObject')
39
+ end
40
+
41
+ context "looking at GObject.signal_connect_data" do
42
+ setup do
43
+ @go = get_function_introspection_data 'GObject', 'signal_connect_data'
44
+ end
45
+
46
+ should "delegate definition to FunctionDefinitionBuilder" do
47
+ code = @mbuilder.send :function_definition, @go, Lib
48
+ expected = GirFFI::FunctionDefinitionBuilder.new(@go, Lib).generate
49
+ assert_equal cws(expected), cws(code)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
data/test/test_helper.rb CHANGED
@@ -30,13 +30,15 @@ class Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  def get_function_introspection_data namespace, function
33
- GirFFI::IRepository.default.require namespace, nil
34
- GirFFI::Builder.send :function_introspection_data, namespace, function
33
+ gir = GirFFI::IRepository.default
34
+ gir.require namespace, nil
35
+ gir.find_by_name namespace, function
35
36
  end
36
37
 
37
38
  def get_method_introspection_data namespace, klass, function
38
- GirFFI::IRepository.default.require namespace, nil
39
- GirFFI::Builder.send :method_introspection_data, namespace, klass, function
39
+ gir = GirFFI::IRepository.default
40
+ gir.require namespace, nil
41
+ gir.find_by_name(namespace, klass).find_method function
40
42
  end
41
43
 
42
44
  def cleanup_module name
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matijs van Zuijlen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-19 00:00:00 +01:00
18
+ date: 2010-12-14 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -87,12 +87,10 @@ files:
87
87
  - lib/gir_ffi/g_error.rb
88
88
  - lib/gir_ffi/i_object_info.rb
89
89
  - lib/gir_ffi/builder.rb
90
- - lib/gir_ffi/constructor_definition_builder.rb
91
90
  - lib/gir_ffi/i_enum_info.rb
92
- - lib/gir_ffi/base.rb
93
91
  - lib/gir_ffi/i_value_info.rb
92
+ - lib/gir_ffi/module_base.rb
94
93
  - lib/gir_ffi/i_signal_info.rb
95
- - lib/gir_ffi/g_type.rb
96
94
  - lib/gir_ffi/i_callback_info.rb
97
95
  - lib/gir_ffi/lib.rb
98
96
  - lib/gir_ffi/i_property_info.rb
@@ -100,6 +98,7 @@ files:
100
98
  - lib/gir_ffi/i_repository.rb
101
99
  - lib/gir_ffi/i_vfunc_info.rb
102
100
  - lib/gir_ffi/i_constant_info.rb
101
+ - lib/gir_ffi/class_base.rb
103
102
  - lib/gir_ffi/i_struct_info.rb
104
103
  - lib/gir_ffi/i_callable_info.rb
105
104
  - lib/gir_ffi/function_definition_builder.rb
@@ -107,25 +106,28 @@ files:
107
106
  - lib/gir_ffi/i_error_domain_info.rb
108
107
  - lib/gir_ffi/version.rb
109
108
  - lib/gir_ffi/overrides/gtk.rb
109
+ - lib/gir_ffi/overrides/gobject.rb
110
110
  - lib/gir_ffi/allocation_helper.rb
111
111
  - lib/gir_ffi/i_base_info.rb
112
112
  - lib/gir_ffi/module_builder.rb
113
- - lib/gir_ffi/method_missing_definition_builder.rb
114
113
  - lib/gir_ffi/arg_helper.rb
114
+ - lib/gir_ffi/g_object.rb
115
115
  - lib/gir_ffi/i_union_info.rb
116
116
  - lib/gir_ffi/class_builder.rb
117
117
  - lib/gir_ffi/i_interface_info.rb
118
118
  - lib/gir_ffi/i_arg_info.rb
119
119
  - lib/gir_ffi/i_type_info.rb
120
120
  - test/i_repository_test.rb
121
- - test/g_type_test.rb
122
121
  - test/function_definition_builder_test.rb
122
+ - test/g_object_test.rb
123
123
  - test/arg_helper_test.rb
124
+ - test/gobject_overrides_test.rb
125
+ - test/class_base_test.rb
124
126
  - test/test_helper.rb
125
127
  - test/class_builder_test.rb
126
128
  - test/girffi_test.rb
127
- - test/constructor_definition_builder_test.rb
128
- - test/base_test.rb
129
+ - test/module_builder_test.rb
130
+ - test/i_object_info_test.rb
129
131
  - test/everything_test.rb
130
132
  - test/builder_test.rb
131
133
  - test/gtk_overrides_test.rb
@@ -183,14 +185,16 @@ specification_version: 3
183
185
  summary: Ruby-FFI-based binding of the GObject Introspection Repository
184
186
  test_files:
185
187
  - test/arg_helper_test.rb
186
- - test/base_test.rb
187
188
  - test/builder_test.rb
189
+ - test/class_base_test.rb
188
190
  - test/class_builder_test.rb
189
- - test/constructor_definition_builder_test.rb
190
191
  - test/everything_test.rb
191
192
  - test/function_definition_builder_test.rb
192
- - test/g_type_test.rb
193
+ - test/g_object_test.rb
193
194
  - test/girffi_test.rb
195
+ - test/gobject_overrides_test.rb
194
196
  - test/gtk_overrides_test.rb
197
+ - test/i_object_info_test.rb
195
198
  - test/i_repository_test.rb
199
+ - test/module_builder_test.rb
196
200
  - test/test_helper.rb
data/lib/gir_ffi/base.rb DELETED
@@ -1,25 +0,0 @@
1
- require 'forwardable'
2
- module GirFFI
3
- # Base class for all generated classes. Contains code for dealing with
4
- # the generated Struct classes.
5
- class Base
6
- extend Forwardable
7
- def_delegators :@struct, :[], :[]=, :to_ptr
8
-
9
- def initialize(*args)
10
- @struct = ffi_structure.new(*args)
11
- end
12
-
13
- def ffi_structure
14
- self.class.ffi_structure
15
- end
16
-
17
- class << self
18
- def ffi_structure
19
- self.const_get(:Struct)
20
- end
21
- alias_method :_real_new, :new
22
- undef new
23
- end
24
- end
25
- end