gir_ffi 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/History.txt +7 -0
  2. data/{README.rdoc → README.md} +31 -25
  3. data/Rakefile +1 -1
  4. data/TODO.rdoc +1 -1
  5. data/lib/ffi-glib.rb +5 -5
  6. data/lib/ffi-glib/container_class_methods.rb +1 -2
  7. data/lib/ffi-glib/list_methods.rb +16 -6
  8. data/lib/ffi-gobject.rb +4 -7
  9. data/lib/ffi-gobject/helper.rb +6 -6
  10. data/lib/ffi-gobject/object.rb +4 -4
  11. data/lib/ffi-gobject_introspection.rb +0 -1
  12. data/lib/ffi-gobject_introspection/g_error.rb +15 -5
  13. data/lib/ffi-gobject_introspection/i_base_info.rb +7 -4
  14. data/lib/ffi-gobject_introspection/i_function_info.rb +3 -1
  15. data/lib/ffi-gobject_introspection/i_repository.rb +8 -15
  16. data/lib/ffi-gobject_introspection/i_struct_info.rb +5 -10
  17. data/lib/gir_ffi-base.rb +2 -0
  18. data/lib/gir_ffi-base/glib/strv.rb +43 -0
  19. data/lib/{ffi-gobject_introspection/gobject_lib.rb → gir_ffi-base/gobject/lib.rb} +4 -2
  20. data/lib/gir_ffi/arg_helper.rb +4 -2
  21. data/lib/gir_ffi/builder.rb +1 -7
  22. data/lib/gir_ffi/builder/argument.rb +34 -108
  23. data/lib/gir_ffi/builder/argument/base.rb +26 -20
  24. data/lib/gir_ffi/builder/type/object.rb +14 -2
  25. data/lib/gir_ffi/builder/type/registered_type.rb +1 -11
  26. data/lib/gir_ffi/class_base.rb +21 -26
  27. data/lib/gir_ffi/in_pointer.rb +11 -5
  28. data/lib/gir_ffi/info_ext/i_type_info.rb +26 -0
  29. data/lib/gir_ffi/interface_base.rb +10 -0
  30. data/lib/gir_ffi/module_base.rb +14 -4
  31. data/lib/gir_ffi/object_base.rb +39 -0
  32. data/lib/gir_ffi/type_map.rb +1 -3
  33. data/lib/gir_ffi/version.rb +1 -1
  34. data/tasks/test.rake +33 -44
  35. data/test/{test_helper.rb → base_test_helper.rb} +2 -11
  36. data/test/ffi-glib/array_test.rb +1 -1
  37. data/test/ffi-glib/byte_array_test.rb +1 -1
  38. data/test/ffi-glib/hash_table_test.rb +30 -1
  39. data/test/ffi-glib/list_test.rb +1 -1
  40. data/test/ffi-glib/ptr_array_test.rb +1 -1
  41. data/test/ffi-glib/ruby_closure_test.rb +54 -0
  42. data/test/ffi-glib/s_list_test.rb +1 -1
  43. data/test/ffi-gobject/gobject_test.rb +1 -1
  44. data/test/ffi-gobject/helper_test.rb +103 -0
  45. data/test/ffi-gobject/object_class_test.rb +1 -1
  46. data/test/ffi-gobject/object_test.rb +1 -1
  47. data/test/ffi-gobject/ruby_style_test.rb +1 -1
  48. data/test/ffi-gobject/value_test.rb +1 -1
  49. data/test/ffi-gobject_introspection/i_base_info_test.rb +1 -1
  50. data/test/ffi-gobject_introspection/i_constant_info_test.rb +1 -1
  51. data/test/ffi-gobject_introspection/i_function_info_test.rb +1 -1
  52. data/test/ffi-gobject_introspection/i_object_info_test.rb +1 -1
  53. data/test/ffi-gobject_introspection/i_repository_test.rb +1 -1
  54. data/test/ffi-gobject_introspection/lib_test.rb +1 -1
  55. data/test/ffi-gobject_test.rb +120 -0
  56. data/test/{ffi-glib → gir_ffi-base/glib}/strv_test.rb +8 -5
  57. data/test/{unit → gir_ffi}/arg_helper_test.rb +2 -2
  58. data/test/{unit/argument_builder_test.rb → gir_ffi/builder/argument/base_test.rb} +1 -13
  59. data/test/{unit/function_builder_test.rb → gir_ffi/builder/function_test.rb} +2 -2
  60. data/test/{unit/module_builder_test.rb → gir_ffi/builder/module_test.rb} +1 -1
  61. data/test/{unit/callback_builder_test.rb → gir_ffi/builder/type/callback_test.rb} +1 -1
  62. data/test/{unit/constant_builder_test.rb → gir_ffi/builder/type/constant_test.rb} +1 -1
  63. data/test/{unit/enum_builder_test.rb → gir_ffi/builder/type/enum_test.rb} +1 -1
  64. data/test/{unit/interface_builder_test.rb → gir_ffi/builder/type/interface_test.rb} +1 -4
  65. data/test/{unit/object_type_builder_test.rb → gir_ffi/builder/type/object_test.rb} +21 -2
  66. data/test/{unit/struct_builder_test.rb → gir_ffi/builder/type/struct_test.rb} +1 -1
  67. data/test/{unit/unintrospectable_type_builder_test.rb → gir_ffi/builder/type/unintrospectable_test.rb} +1 -1
  68. data/test/{unit/union_builder_test.rb → gir_ffi/builder/type/union_test.rb} +9 -3
  69. data/test/{unit/user_defined_type_builder_test.rb → gir_ffi/builder/type/user_defined_test.rb} +4 -2
  70. data/test/gir_ffi/builder_test.rb +398 -0
  71. data/test/{unit → gir_ffi}/callback_helper_test.rb +1 -1
  72. data/test/{unit → gir_ffi}/class_base_test.rb +1 -1
  73. data/test/{unit → gir_ffi}/in_out_pointer_test.rb +1 -1
  74. data/test/{unit → gir_ffi}/in_pointer_test.rb +24 -3
  75. data/test/{unit → gir_ffi/info_ext}/i_field_info_test.rb +1 -1
  76. data/test/gir_ffi/info_ext/i_type_info_test.rb +71 -0
  77. data/test/{unit/user_defined_object_info_test.rb → gir_ffi/user_defined/i_object_info_test.rb} +1 -1
  78. data/test/{unit/user_defined_property_info_test.rb → gir_ffi/user_defined/i_property_info_test.rb} +1 -1
  79. data/test/{unit/user_defined_registered_type_info_test.rb → gir_ffi/user_defined/i_registered_type_info_test.rb} +1 -1
  80. data/test/{unit → gir_ffi}/variable_name_generator_test.rb +1 -1
  81. data/test/{unit/gir_ffi_test.rb → gir_ffi_test.rb} +24 -4
  82. data/test/gir_ffi_test_helper.rb +1 -1
  83. data/test/integration/derived_classes_test.rb +1 -1
  84. data/test/integration/generated_gimarshallingtests_test.rb +1 -1
  85. data/test/integration/generated_gio_test.rb +1 -1
  86. data/test/integration/generated_gobject_test.rb +1 -1
  87. data/test/integration/generated_regress_test.rb +2 -3
  88. data/test/integration/method_lookup_test.rb +1 -1
  89. data/test/integration/pretty_print_test.rb +1 -1
  90. data/test/introspection_test_helper.rb +11 -0
  91. metadata +71 -77
  92. data/lib/ffi-glib/strv.rb +0 -31
  93. data/test/builder_test.rb +0 -264
  94. data/test/ffi-glib/glib_overrides_test.rb +0 -38
  95. data/test/ffi-gobject/g_object_overrides_test.rb +0 -274
  96. data/test/girffi_test.rb +0 -27
  97. data/test/integration/generated_pango_test.rb +0 -20
  98. data/test/type_builder_test.rb +0 -36
  99. data/test/unit/builder_test.rb +0 -143
  100. data/test/unit/hash_table_element_type_provider_test.rb +0 -16
  101. data/test/unit/i_type_info_test.rb +0 -23
  102. data/test/unit/list_element_type_provider_test.rb +0 -13
@@ -5,19 +5,25 @@ module GirFFI
5
5
  class InPointer < FFI::Pointer
6
6
  def self.from_array type, ary
7
7
  return nil if ary.nil?
8
- return from_utf8_array ary if type == :utf8
9
- return from_interface_pointer_array ary if type == :interface_pointer
10
-
11
- return from_basic_type_array type, ary
8
+ case type
9
+ when :utf8, :filename
10
+ from_utf8_array ary
11
+ when :interface_pointer
12
+ from_interface_pointer_array ary
13
+ else
14
+ from_basic_type_array type, ary
15
+ end
12
16
  end
13
17
 
14
18
  def self.from type, val
15
19
  return nil if val.nil?
16
20
  case type
17
- when :utf8
21
+ when :utf8, :filename
18
22
  from_utf8 val
19
23
  when :gint32, :gint8
20
24
  self.new val
25
+ when :void
26
+ ArgHelper.object_to_inptr val
21
27
  else
22
28
  raise NotImplementedError
23
29
  end
@@ -23,6 +23,32 @@ module GirFFI
23
23
  ffitype
24
24
  end
25
25
  end
26
+
27
+ def subtype_tag index
28
+ st = param_type(index)
29
+ tag = st.tag
30
+ case tag
31
+ when :interface
32
+ return :interface_pointer if st.pointer?
33
+ return :interface
34
+ when :void
35
+ return :gpointer if st.pointer?
36
+ return :void
37
+ else
38
+ return tag
39
+ end
40
+ end
41
+
42
+ def element_type
43
+ case tag
44
+ when :glist, :gslist, :array
45
+ subtype_tag 0
46
+ when :ghash
47
+ [subtype_tag(0), subtype_tag(1)]
48
+ else
49
+ nil
50
+ end
51
+ end
26
52
  end
27
53
  end
28
54
  end
@@ -1,10 +1,20 @@
1
1
  module GirFFI
2
2
  module InterfaceBase
3
+ # @deprecated Compatibility function. Remove in version 0.5.0.
3
4
  def _builder
5
+ gir_ffi_builder
6
+ end
7
+
8
+ def gir_ffi_builder
4
9
  self.const_get :GIR_FFI_BUILDER
5
10
  end
6
11
 
12
+ # @deprecated Compatibility function. Remove in version 0.5.0.
7
13
  def _setup_instance_method name
14
+ setup_instance_method name
15
+ end
16
+
17
+ def setup_instance_method name
8
18
  _builder.setup_instance_method name
9
19
  end
10
20
  end
@@ -1,27 +1,37 @@
1
1
  module GirFFI
2
2
  module ModuleBase
3
3
  def method_missing method, *arguments, &block
4
- result = _setup_method method.to_s
4
+ result = setup_method method.to_s
5
5
  return super unless result
6
6
  self.send method, *arguments, &block
7
7
  end
8
8
 
9
9
  def const_missing classname
10
- klass = _builder.build_namespaced_class classname.to_s
10
+ klass = load_class classname
11
11
  return super if klass.nil?
12
12
  klass
13
13
  end
14
14
 
15
15
  def load_class classname
16
- _builder.build_namespaced_class classname.to_s
16
+ gir_ffi_builder.build_namespaced_class classname.to_s
17
17
  end
18
18
 
19
+ # @deprecated Compatibility function. Remove in version 0.5.0.
19
20
  def _builder
21
+ gir_ffi_builder
22
+ end
23
+
24
+ def gir_ffi_builder
20
25
  self.const_get :GIR_FFI_BUILDER
21
26
  end
22
27
 
28
+ # @deprecated Compatibility function. Remove in version 0.5.0.
23
29
  def _setup_method name
24
- _builder.setup_method name
30
+ setup_method name
31
+ end
32
+
33
+ def setup_method name
34
+ gir_ffi_builder.setup_method name
25
35
  end
26
36
  end
27
37
  end
@@ -0,0 +1,39 @@
1
+ module GirFFI
2
+ # Base class for all generated classes of type :object.
3
+ class ObjectBase < ClassBase
4
+ #
5
+ # Wraps a pointer retrieved from a constructor method. Here,
6
+ # it is simply defined as a wrapper around wrap, but, e.g., InitiallyUnowned
7
+ # overrides it to sink the floating object.
8
+ #
9
+ # @param ptr Pointer to the object's C structure
10
+ #
11
+ # @return An object of the current class wrapping the pointer
12
+ #
13
+ def self.constructor_wrap ptr
14
+ wrap ptr
15
+ end
16
+
17
+ #
18
+ # Find property info for the named property.
19
+ #
20
+ # @param name The property's name
21
+ #
22
+ # @return [GObjectIntrospection::IPropertyInfo] The property's info
23
+ #
24
+ def self.find_property name
25
+ gir_ffi_builder.find_property name
26
+ end
27
+
28
+ #
29
+ # Find signal info for the named signal.
30
+ #
31
+ # @param name The signal's name
32
+ #
33
+ # @return [GObjectIntrospection::ISignalInfo] The signal's info
34
+ #
35
+ def self.find_signal name
36
+ gir_ffi_builder.find_signal name
37
+ end
38
+ end
39
+ end
@@ -4,9 +4,7 @@ module GirFFI
4
4
  gtype_type = "uint#{sz}".to_sym
5
5
 
6
6
  TAG_TYPE_MAP = {
7
- #FIXME: Pick one: GType or gtype.
8
- :GType => :size_t,
9
- :gtype => gtype_type,
7
+ :GType => gtype_type,
10
8
  :gboolean => :bool,
11
9
  :gunichar => :uint32,
12
10
  :gint8 => :int8,
@@ -1,4 +1,4 @@
1
1
  module GirFFI
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
4
4
 
@@ -1,47 +1,35 @@
1
1
  require 'rake/testtask'
2
2
 
3
3
  namespace :test do
4
-
5
- Rake::TestTask.new(:integration) do |t|
6
- t.libs = ['lib']
7
- t.test_files = FileList['test/integration/*_test.rb']
8
- t.ruby_opts += ["-w"]
9
- end
10
-
11
- Rake::TestTask.new(:run) do |t|
12
- t.libs = ['lib']
13
- t.test_files = FileList['test/*_test.rb']
14
- t.ruby_opts += ["-w"]
4
+ def define_test_task name
5
+ Rake::TestTask.new(name) do |t|
6
+ t.libs = ['lib']
7
+ t.ruby_opts += ["-w -Itest"]
8
+ yield t
9
+ end
15
10
  end
16
11
 
17
- Rake::TestTask.new(:unit) do |t|
18
- t.libs = ['lib']
19
- t.test_files = FileList['test/unit/*_test.rb']
20
- t.ruby_opts += ["-w"]
12
+ define_test_task(:base) do |t|
13
+ t.test_files = FileList['test/gir_ffi-base/**/*_test.rb']
21
14
  end
22
15
 
23
- Rake::TestTask.new(:gobjectintrospection) do |t|
24
- t.libs = ['lib']
25
- t.test_files = FileList['test/ffi-gobject_introspection/*_test.rb']
26
- t.ruby_opts += ["-w"]
16
+ define_test_task(:introspection) do |t|
17
+ t.test_files = FileList['test/ffi-gobject_introspection/**/*_test.rb']
27
18
  end
28
19
 
29
- Rake::TestTask.new(:glib) do |t|
30
- t.libs = ['lib']
31
- t.test_files = FileList['test/ffi-glib/*_test.rb']
32
- t.ruby_opts += ["-w"]
20
+ define_test_task(:main) do |t|
21
+ t.test_files = FileList['test/gir_ffi_test.rb',
22
+ 'test/gir_ffi/**/*_test.rb']
33
23
  end
34
24
 
35
- Rake::TestTask.new(:gobject) do |t|
36
- t.libs = ['lib']
37
- t.test_files = FileList['test/ffi-gobject/*_test.rb']
38
- t.ruby_opts += ["-w"]
25
+ define_test_task(:overrides) do |t|
26
+ t.test_files = FileList['test/ffi-gobject_test.rb',
27
+ 'test/ffi-glib/**/*_test.rb',
28
+ 'test/ffi-gobject/**/*_test.rb']
39
29
  end
40
30
 
41
- Rake::TestTask.new(:gtk) do |t|
42
- t.libs = ['lib']
43
- t.test_files = FileList['test/ffi-gtk/*_test.rb']
44
- t.ruby_opts += ["-w"]
31
+ define_test_task(:integration) do |t|
32
+ t.test_files = FileList['test/integration/**/*_test.rb']
45
33
  end
46
34
 
47
35
  desc 'Build Regress test library and typelib'
@@ -49,17 +37,23 @@ namespace :test do
49
37
  sh %{cd test/lib && make}
50
38
  end
51
39
 
52
- task :run => :lib
53
- task :unit => :lib
54
- task :glib => :lib
55
- task :gobject => :lib
40
+ task :main => :lib
41
+ task :overrides => :lib
56
42
  task :integration => :lib
57
43
 
58
- desc 'Run rcov for the entire test suite'
59
- task :coverage => :lib do
60
- rm_f "coverage"
61
- system "rcov", "-Ilib", "--exclude", "\.gem\/,\/gems\/", *FileList['test/**/*_test.rb']
44
+ desc 'Run the entire test suite as one'
45
+ define_test_task(:all) do |t|
46
+ t.test_files = FileList['test/**/*_test.rb']
62
47
  end
48
+
49
+ task :all => :lib
50
+
51
+ desc 'Run all individual test suites separately'
52
+ task :suites => [:base,
53
+ :introspection,
54
+ :main,
55
+ :overrides,
56
+ :integration]
63
57
  end
64
58
 
65
59
  file "test/lib/Makefile" => "test/lib/configure" do
@@ -69,8 +63,3 @@ end
69
63
  file "test/lib/configure" do
70
64
  sh %{cd test/lib && NOCONFIGURE=1 ./autogen.sh}
71
65
  end
72
-
73
- desc 'Run unit an integration tests'
74
- task :test => ['test:gobjectintrospection',
75
- 'test:unit', 'test:run', 'test:glib', 'test:gobject', 'test:gtk',
76
- 'test:integration']
@@ -12,23 +12,12 @@ end
12
12
  require 'minitest/spec'
13
13
  require 'minitest/autorun'
14
14
  require 'rr'
15
- require 'ffi'
16
15
 
17
16
  Thread.abort_on_exception = true
18
17
 
19
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
20
-
21
- require 'ffi-gobject_introspection'
22
-
23
18
  class MiniTest::Unit::TestCase
24
19
  include RR::Adapters::TestUnit
25
20
 
26
- def get_introspection_data namespace, name
27
- gir = GObjectIntrospection::IRepository.default
28
- gir.require namespace, nil
29
- gir.find_by_name namespace, name
30
- end
31
-
32
21
  def assert_nothing_raised
33
22
  yield
34
23
  assert true
@@ -85,3 +74,5 @@ class MiniTest::Spec
85
74
  alias :context :describe
86
75
  end
87
76
  end
77
+
78
+ require 'gir_ffi-base'
@@ -1,4 +1,4 @@
1
- require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
1
+ require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GLib::Array do
4
4
  it "knows its element type" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
1
+ require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GLib::ByteArray do
4
4
  it "can succesfully be created with Glib::ByteArray.new" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
1
+ require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GLib::HashTable do
4
4
  it "knows its key and value types" do
@@ -30,5 +30,34 @@ describe GLib::HashTable do
30
30
  assert_equal hsh.to_hash, hsh2.to_hash
31
31
  end
32
32
  end
33
+
34
+ it "allows key-value pairs to be inserted" do
35
+ h = GLib::HashTable.new :utf8, :utf8
36
+ h.insert "foo", "bar"
37
+ h.to_hash.must_equal "foo" => "bar"
38
+ end
39
+
40
+ it "includes Enumerable" do
41
+ GLib::HashTable.must_include Enumerable
42
+ end
43
+
44
+ describe "a HashTable provided by the system" do
45
+ before do
46
+ GirFFI.setup :Regress
47
+ @hash = Regress.test_ghash_container_return
48
+ end
49
+
50
+ it "has a working #each method" do
51
+ a = {}
52
+ @hash.each {|k, v| a[k] = v}
53
+ a.must_be :==, {"foo" => "bar", "baz" => "bat",
54
+ "qux" => "quux"}
55
+ end
56
+
57
+ it "has a working #to_hash method" do
58
+ @hash.to_hash.must_be :==, {"foo" => "bar", "baz" => "bat",
59
+ "qux" => "quux"}
60
+ end
61
+ end
33
62
  end
34
63
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
1
+ require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GLib::List do
4
4
  it "knows its element type" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))
1
+ require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GLib::PtrArray do
4
4
  it "knows its element type" do
@@ -0,0 +1,54 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GObject::RubyClosure do
4
+ should "have a constructor with a mandatory block argument" do
5
+ assert_raises ArgumentError do
6
+ GObject::RubyClosure.new
7
+ end
8
+ end
9
+
10
+ should "be a kind of Closure" do
11
+ c = GObject::RubyClosure.new {}
12
+ assert_kind_of GObject::Closure, c
13
+ end
14
+
15
+ should "be able to retrieve its block from its struct" do
16
+ a = 0
17
+ c = GObject::RubyClosure.new { a = 2 }
18
+ c2 = GObject::RubyClosure.wrap(c.to_ptr)
19
+ c2.block.call
20
+ assert_equal 2, a
21
+ end
22
+
23
+ describe "its #marshaller singleton method" do
24
+ should "invoke its closure argument's block" do
25
+ a = 0
26
+ c = GObject::RubyClosure.new { a = 2 }
27
+ GObject::RubyClosure.marshaller(c, nil, 0, nil, nil, nil)
28
+ assert_equal 2, a
29
+ end
30
+
31
+ should "work when its closure argument is a GObject::Closure" do
32
+ a = 0
33
+ c = GObject::RubyClosure.new { a = 2 }
34
+ c2 = GObject::Closure.wrap(c.to_ptr)
35
+ GObject::RubyClosure.marshaller(c2, nil, 0, nil, nil, nil)
36
+ assert_equal 2, a
37
+ end
38
+
39
+ should "store the closure's return value in the proper gvalue" do
40
+ c = GObject::RubyClosure.new { 2 }
41
+ gv = GObject::Value.new
42
+ GObject::RubyClosure.marshaller(c, gv, 0, nil, nil, nil)
43
+ assert_equal 2, gv.ruby_value
44
+ end
45
+ end
46
+
47
+ should "have GObject::Closure#invoke call its block" do
48
+ a = 0
49
+ c = GObject::RubyClosure.new { a = 2 }
50
+ c2 = GObject::Closure.wrap(c.to_ptr)
51
+ c2.invoke nil, nil, nil
52
+ assert_equal 2, a
53
+ end
54
+ end