gir_ffi 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.6.1 / 2013-06-09
2
+
3
+ * Handle SizedArray containing enums
4
+
1
5
  == 0.6.0 / 2013-06-07
2
6
 
3
7
  * Support Rubinius
@@ -26,11 +26,14 @@ module GirFFI
26
26
  end
27
27
 
28
28
  def self.ptr_to_typed_array type, ptr, size
29
- if type.is_a? Class
29
+ case type
30
+ when Class
30
31
  ptr_to_interface_array type, ptr, size
31
- elsif type.is_a? Array
32
+ when Array
32
33
  ptr_to_interface_pointer_array type[1], ptr, size
33
- elsif type == :utf8
34
+ when FFI::Enum
35
+ ptr_to_enum_array type, ptr, size
36
+ when :utf8
34
37
  ptr_to_utf8_array ptr, size
35
38
  else
36
39
  self.send "ptr_to_#{type}_array", ptr, size
@@ -73,6 +76,10 @@ module GirFFI
73
76
  end
74
77
  end
75
78
 
79
+ def self.ptr_to_enum_array enum, ptr, size
80
+ ptr_to_gint32_array(ptr, size).map {|val| enum[val] }
81
+ end
82
+
76
83
  if RUBY_VERSION < "1.9"
77
84
  def self.ptr_to_utf8 ptr
78
85
  ptr.null? ? nil : ptr.read_string
@@ -1,3 +1,3 @@
1
1
  module GirFFI
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -7,13 +7,12 @@ if RUBY_VERSION >= "1.9"
7
7
  SimpleCov.start
8
8
  end
9
9
 
10
- require 'minitest/spec'
11
10
  require 'minitest/autorun'
12
11
  require 'rr'
13
12
 
14
13
  Thread.abort_on_exception = true
15
14
 
16
- class MiniTest::Unit::TestCase
15
+ class Minitest::Test
17
16
  include RR::Adapters::TestUnit
18
17
 
19
18
  def assert_nothing_raised
@@ -64,7 +63,7 @@ class MiniTest::Unit::TestCase
64
63
  end
65
64
  end
66
65
 
67
- class MiniTest::Spec
66
+ class Minitest::Spec
68
67
  class << self
69
68
  alias :setup :before
70
69
  alias :teardown :after
@@ -1,20 +1,15 @@
1
1
  require 'introspection_test_helper'
2
2
 
3
- module GirFFI
4
- class IObjectInfoTest < MiniTest::Spec
5
- context "An IObjectInfo object" do
6
-
7
- setup do
8
- gir = GObjectIntrospection::IRepository.default
9
- gir.require 'GObject', nil
10
- @info = gir.find_by_name 'GObject', 'Object'
11
- end
12
-
13
- should "find a vfunc by name" do
14
- assert_not_nil @info.find_vfunc("finalize")
15
- end
3
+ describe GObjectIntrospection::IObjectInfo do
4
+ describe "#find_vfunc" do
5
+ setup do
6
+ gir = GObjectIntrospection::IRepository.default
7
+ gir.require 'GObject', nil
8
+ @info = gir.find_by_name 'GObject', 'Object'
16
9
  end
17
10
 
11
+ should "find a vfunc by name" do
12
+ assert_not_nil @info.find_vfunc("finalize")
13
+ end
18
14
  end
19
15
  end
20
-
@@ -51,6 +51,27 @@ describe GirFFI::ArgHelper do
51
51
  end
52
52
  end
53
53
 
54
+ describe "for pointers to arrays of enums" do
55
+ let(:enum) { FFI::Enum.new([:foo, 1, :bar, 2]) }
56
+ it "returns an empty array when passed a null pointer" do
57
+ result = GirFFI::ArgHelper.ptr_to_typed_array enum, FFI::Pointer.new(0), 0
58
+ result.must_equal []
59
+ end
60
+
61
+ it "returns an empty array when passed nil" do
62
+ result = GirFFI::ArgHelper.ptr_to_typed_array enum, nil, 0
63
+ result.must_equal []
64
+ end
65
+
66
+ it "returns an array of symbols when passed a pointer to ints" do
67
+ block = FFI::MemoryPointer.new(:int32, 2)
68
+ block.write_array_of_int32 [1, 2]
69
+ result = GirFFI::ArgHelper.ptr_to_typed_array enum, block, 2
70
+ result.must_equal [:foo, :bar]
71
+ end
72
+
73
+ end
74
+
54
75
  describe "for pointers to arrays of base types" do
55
76
  it "returns an empty array when passed a null pointer" do
56
77
  result = GirFFI::ArgHelper.ptr_to_typed_array :gint32, FFI::Pointer.new(0), 0
@@ -33,7 +33,7 @@ class Sequence
33
33
  end
34
34
  end
35
35
 
36
- class MiniTest::Unit::TestCase
36
+ class Minitest::Test
37
37
  def cws code
38
38
  code.gsub(/(^\s*|\s*$)/, "")
39
39
  end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ require 'gir_ffi_test_helper'
3
+
4
+ require 'gir_ffi'
5
+
6
+ GirFFI.setup :Pango
7
+
8
+ # Tests generated methods and functions in the Pango namespace.
9
+ describe Pango do
10
+ describe Pango::Language do
11
+ it "has a working method get_scripts" do
12
+ lang = Pango::Language.from_string 'ja'
13
+ result = lang.get_scripts
14
+
15
+ if GLib::SizedArray === result
16
+ scripts = result
17
+ else
18
+ ptr, size = *result
19
+ scripts = GLib::SizedArray.new Pango::Script, size, ptr
20
+ end
21
+
22
+ scripts.to_a.must_equal [:han, :katakana, :hiragana]
23
+ end
24
+ end
25
+ end
@@ -2,7 +2,7 @@ require 'base_test_helper'
2
2
 
3
3
  require 'ffi-gobject_introspection'
4
4
 
5
- class MiniTest::Unit::TestCase
5
+ class Minitest::Test
6
6
  def get_introspection_data namespace, name
7
7
  gir = GObjectIntrospection::IRepository.default
8
8
  gir.require namespace, nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-08 00:00:00.000000000 Z
12
+ date: 2013-06-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '4.3'
53
+ version: '5.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '4.3'
61
+ version: '5.0'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rr
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -216,6 +216,7 @@ files:
216
216
  - test/integration/method_lookup_test.rb
217
217
  - test/integration/generated_gimarshallingtests_test.rb
218
218
  - test/integration/generated_gio_test.rb
219
+ - test/integration/generated_pango_test.rb
219
220
  - test/integration/generated_gobject_test.rb
220
221
  - test/gir_ffi/builder/type/user_defined_test.rb
221
222
  - test/gir_ffi/builder/type/enum_test.rb
@@ -382,6 +383,7 @@ test_files:
382
383
  - test/integration/generated_gimarshallingtests_test.rb
383
384
  - test/integration/generated_gio_test.rb
384
385
  - test/integration/generated_gobject_test.rb
386
+ - test/integration/generated_pango_test.rb
385
387
  - test/integration/generated_regress_test.rb
386
388
  - test/integration/method_lookup_test.rb
387
389
  - test/introspection_test_helper.rb