ffi-efl 0.0.2 → 0.0.3

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.
Files changed (43) hide show
  1. data/Changelog +13 -1
  2. data/README.rdoc +24 -14
  3. data/lib/efl/ecore.rb +7 -7
  4. data/lib/efl/ecore_evas.rb +78 -0
  5. data/lib/efl/ecore_getopt.rb +28 -29
  6. data/lib/efl/ecore_input.rb +14 -0
  7. data/lib/efl/edje.rb +47 -1
  8. data/lib/efl/eet.rb +18 -25
  9. data/lib/efl/eina.rb +14 -0
  10. data/lib/efl/eina_hash.rb +84 -0
  11. data/lib/efl/eina_list.rb +77 -0
  12. data/lib/efl/elementary.rb +22 -9
  13. data/lib/efl/evas.rb +67 -25
  14. data/lib/efl/{ecore/ecore-ffi.rb → ffi/ecore.rb} +8 -5
  15. data/lib/efl/{ecore/ecore_evas-ffi.rb → ffi/ecore_evas.rb} +10 -7
  16. data/lib/efl/{ecore/ecore_getopt-ffi.rb → ffi/ecore_getopt.rb} +8 -5
  17. data/lib/efl/{ecore/ecore_input-ffi.rb → ffi/ecore_input.rb} +9 -6
  18. data/lib/efl/{edje/edje-ffi.rb → ffi/edje.rb} +10 -7
  19. data/lib/efl/{eet/eet-ffi.rb → ffi/eet.rb} +8 -5
  20. data/lib/efl/ffi/eina.rb +48 -0
  21. data/lib/efl/ffi/eina_hash.rb +111 -0
  22. data/lib/efl/ffi/eina_list.rb +108 -0
  23. data/lib/efl/{eina/eina_types-ffi.rb → ffi/eina_types.rb} +8 -5
  24. data/lib/efl/{elementary/elementary-ffi.rb → ffi/elementary.rb} +16 -9
  25. data/lib/efl/{evas/evas-ffi.rb → ffi/evas.rb} +153 -150
  26. data/lib/efl/ffi.rb +81 -38
  27. data/lib/efl.rb +9 -4
  28. data/spec/ecore_evas_spec.rb +24 -0
  29. data/spec/ecore_getopt_spec.rb +1 -2
  30. data/spec/ecore_input_spec.rb +24 -0
  31. data/spec/ecore_spec.rb +2 -3
  32. data/spec/edje_spec.rb +1 -1
  33. data/spec/eet_spec.rb +68 -69
  34. data/spec/eina_hash_spec.rb +180 -0
  35. data/spec/eina_list_spec.rb +101 -0
  36. data/spec/eina_spec.rb +20 -0
  37. data/spec/evas_spec.rb +288 -40
  38. data/tasks/ffi.rake +1 -1
  39. data/test/test_edje.rb +141 -0
  40. data/test/test_elm_win.rb +25 -28
  41. data/test/test_elm_win_class.rb +7 -7
  42. data/test/test_evas.rb +106 -0
  43. metadata +30 -17
data/lib/efl/ffi.rb CHANGED
@@ -5,9 +5,7 @@ require 'ffi'
5
5
  #
6
6
  module Efl
7
7
  #
8
- module API
9
- #
10
- extend FFI::Library
8
+ module FFIHelper
11
9
  #
12
10
  def attach_fcts fcts
13
11
  fcts.each do |func|
@@ -18,53 +16,98 @@ module Efl
18
16
  end
19
17
  end
20
18
  end
21
- module_function :attach_fcts
22
19
  #
23
- typedef :pointer, :char_p
24
- typedef :pointer, :short_p
25
- typedef :pointer, :int_p
26
- typedef :pointer, :long_p
27
- typedef :pointer, :float_p
28
- typedef :pointer, :double_p
29
- typedef :pointer, :uchar_p
30
- typedef :pointer, :ushort_p
31
- typedef :pointer, :uint_p
32
- typedef :pointer, :ulong_p
33
- typedef :pointer, :ufloat_p
34
- typedef :pointer, :udouble_p
35
- typedef :pointer, :void_p
36
- typedef :pointer, :string_array
37
- typedef :pointer, :string_array_p
20
+ def ffi_typedefs
21
+ @ffi_typedefs
22
+ end
38
23
  #
39
- typedef :pointer, :eina_list_p
40
- typedef :pointer, :eina_iterator_p
41
- typedef :pointer, :eina_accessor_p
42
- typedef :pointer, :evas_p
43
- typedef :pointer, :evas_object_p
24
+ def steal_ffitype mod, sym
25
+ typedef mod.ffi_typedefs[sym], sym
26
+ end
27
+ #
28
+ def self.extended mod
29
+ #
30
+ mod.extend FFI::Library
31
+ #
32
+ mod.typedef :pointer, :char_p
33
+ mod.typedef :pointer, :short_p
34
+ mod.typedef :pointer, :int_p
35
+ mod.typedef :pointer, :long_p
36
+ mod.typedef :pointer, :float_p
37
+ mod.typedef :pointer, :double_p
38
+ mod.typedef :pointer, :uchar_p
39
+ mod.typedef :pointer, :ushort_p
40
+ mod.typedef :pointer, :uint_p
41
+ mod.typedef :pointer, :ulong_p
42
+ mod.typedef :pointer, :ufloat_p
43
+ mod.typedef :pointer, :udouble_p
44
+ mod.typedef :pointer, :void_p
45
+ mod.typedef :pointer, :string_array
46
+ mod.typedef :pointer, :string_array_p
47
+ mod.typedef :uint_p, :uintptr_t
48
+ #
49
+ mod.typedef :bool, :eina_bool
50
+ mod.typedef :pointer, :eina_bool_p
51
+ mod.typedef :pointer, :eina_list_p
52
+ mod.typedef :pointer, :eina_hash_p
53
+ mod.typedef :pointer, :eina_iterator_p
54
+ mod.typedef :pointer, :eina_accessor_p
55
+ mod.typedef :pointer, :evas_p
56
+ mod.typedef :pointer, :evas_object_p
57
+ mod.typedef :pointer, :evas_object_pp
58
+ mod.typedef :pointer, :ecore_getopt_p
59
+ mod.typedef :pointer, :ecore_getopt_desc_p
60
+ mod.typedef :pointer, :ecore_getopt_value_p
61
+ #
62
+ mod.callback :eina_compare_cb, [ :void_p, :void_p ], :int
63
+ mod.callback :eina_each_cb, [ :void_p, :void_p, :void_p ], :eina_bool
64
+ mod.callback :eina_free_cb, [ :void_p ], :void
65
+ #
66
+ end
44
67
  #
45
68
  end
46
69
  #
47
- module Helper
48
- def self.included m
49
- m.class_eval "def ptr; @ptr; end"
50
- m.class_eval "def self.func_prefixes; @func_prefixes; end"
51
- m.class_eval "def self.inherited sub; sub.class_eval 'def self.func_prefixes; superclass.func_prefixes; end'; end"
70
+ module ClassHelper
71
+ def to_ptr; @ptr; end
72
+ def === o; @ptr === o.to_ptr; end
73
+ def address; @ptr.address; end
74
+ def self.included kls
75
+ # create class instance @proxy_list
76
+ kls.class_eval "@proxy_list ||=[]"
77
+ # access and prepend *args to @proxy_list
78
+ kls.class_eval "def self.proxy_list *args; @proxy_list.unshift *args unless args.empty?; @proxy_list; end"
79
+ # on inheritance, copy ancestor's @proxy_list
80
+ kls.class_eval <<-EOF
81
+ def self.inherited sub
82
+ sub.class_eval '@proxy_list = []'
83
+ sub.proxy_list *self.proxy_list
84
+ end
85
+ EOF
52
86
  end
53
87
  def method_missing m, *args, &block
54
- self.class.func_prefixes.each do |p|
55
- sym = p+m.to_s
56
- if Efl::API.respond_to? sym
57
- self.class.class_eval "def #{m} *args, &block; r=Efl::API.#{sym}(@ptr,*args); yield r if block_given?; r; end"
88
+ if m =~/^(.*)=$/
89
+ m_s = $1+'_set'
90
+ args_s = '*args[0]'
91
+ elsif m =~/^(.*)\?$/
92
+ m_s = $1+'_get'
93
+ args_s = '*args'
94
+ else
95
+ m_s = m.to_s
96
+ args_s = '*args'
97
+ end
98
+ self.class.proxy_list.each do |mod,p|
99
+ sym = p+m_s
100
+ if mod.respond_to? sym
101
+ self.class.class_eval "def #{m} *args, &block; r=#{mod.name}.#{sym}(@ptr,#{args_s}); yield r if block_given?; r; end"
102
+ return self.send m, *args, &block
103
+ elsif mod.respond_to? m
104
+ self.class.class_eval "def #{m} *args, &block; r=#{mod.name}.#{m}(@ptr,#{args_s}); yield r if block_given?; r; end"
58
105
  return self.send m, *args, &block
59
106
  end
60
107
  end
61
- r = Efl::API.send m, @ptr, *args
62
- self.class.class_eval "def #{m} *args, &block; r=Efl::API.#{m}(@ptr,*args); yield r if block_given?; r; end"
63
- r
108
+ raise NameError.new "#{self.class} is unable to resolve #{m} within #{self.class.proxy_list.inspect}"
64
109
  end
65
110
  end
66
111
  end
67
112
  #
68
- require 'efl/eina/eina_types-ffi'
69
- #
70
113
  # EOF
data/lib/efl.rb CHANGED
@@ -4,14 +4,19 @@
4
4
  #
5
5
  module Efl
6
6
  #
7
- VERSION = '0.0.2'
7
+ VERSION = '0.0.3'
8
8
  #
9
- autoload :Eet, './lib/efl/eet.rb'
10
- autoload :Evas, './lib/efl/evas.rb'
11
- autoload :Ecore, './lib/efl/ecore.rb'
9
+ autoload :EcoreEvas, './lib/efl/ecore_evas.rb'
12
10
  autoload :EcoreGetopt, './lib/efl/ecore_getopt.rb'
11
+ autoload :EcoreInput, './lib/efl/ecore_input.rb'
12
+ autoload :Ecore, './lib/efl/ecore.rb'
13
13
  autoload :Edje, './lib/efl/edje.rb'
14
+ autoload :Eet, './lib/efl/eet.rb'
15
+ autoload :EinHash, './lib/efl/eina_hash.rb'
16
+ autoload :EinaList, './lib/efl/eina_list.rb'
17
+ autoload :Eina, './lib/efl/eina.rb'
14
18
  autoload :Elm, './lib/efl/elementary.rb'
19
+ autoload :Evas, './lib/efl/evas.rb'
15
20
  end
16
21
  #
17
22
  # EOF
@@ -0,0 +1,24 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: UTF-8 -*-
3
+ #
4
+ require 'efl/ecore_evas'
5
+ #
6
+ describe Efl::EcoreEvas do
7
+ #
8
+ before(:all) do
9
+ EcoreEvas = Efl::EcoreEvas
10
+ end
11
+ #
12
+ it "should init" do
13
+ EcoreEvas.init.should eql 1
14
+ EcoreEvas.init.should eql 2
15
+ EcoreEvas.init.should eql 3
16
+ end
17
+ #
18
+ it "should shutdown" do
19
+ EcoreEvas.shutdown.should eql 2
20
+ EcoreEvas.shutdown.should eql 1
21
+ EcoreEvas.shutdown.should eql 0
22
+ end
23
+ #
24
+ end
@@ -1,7 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
  # -*- coding: UTF-8 -*-
3
3
  #
4
- require 'efl/ecore'
5
4
  require 'efl/ecore_getopt'
6
5
  #
7
6
  describe Efl::EcoreGetopt do
@@ -9,7 +8,7 @@ describe Efl::EcoreGetopt do
9
8
  before(:all) do
10
9
  Efl::Ecore.init
11
10
  #
12
- @p = Efl::EcoreGetopt::Parser.new :prog =>"Prog", :usage => "Usage", :version => "0.0.0", :copyright => "less", :license => "MIT", :description => "description", :strict => 1
11
+ @p = Efl::EcoreGetopt::REcoreGetopt.new :prog =>"Prog", :usage => "Usage", :version => "0.0.0", :copyright => "less", :license => "MIT", :description => "description", :strict => 1
13
12
  @callback = Proc.new do |parser, desc, string, data, value|
14
13
  parser.address.should eql @p.to_ptr.address
15
14
  string.should eql "my_data"
@@ -0,0 +1,24 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: UTF-8 -*-
3
+ #
4
+ require 'efl/ecore_input'
5
+ #
6
+ describe Efl::EcoreInput do
7
+ #
8
+ before(:all) do
9
+ EcoreInput = Efl::EcoreInput
10
+ end
11
+ #
12
+ it "should init" do
13
+ EcoreInput.init.should eql 1
14
+ EcoreInput.init.should eql 2
15
+ EcoreInput.init.should eql 3
16
+ end
17
+ #
18
+ it "should shutdown" do
19
+ EcoreInput.shutdown.should eql 2
20
+ EcoreInput.shutdown.should eql 1
21
+ EcoreInput.shutdown.should eql 0
22
+ end
23
+ #
24
+ end
data/spec/ecore_spec.rb CHANGED
@@ -4,10 +4,9 @@
4
4
  require 'efl/ecore'
5
5
  #
6
6
  describe Efl::Ecore do
7
- #
8
- include Efl
9
7
  #
10
8
  before(:all) do
9
+ Ecore = Efl::Ecore
11
10
  USER_SIGNAL_CB = Proc.new do |data, type, event|
12
11
  data.read_string.should eql "ok"
13
12
  type.should eql Ecore::EVENT_SIGNAL_USER
@@ -51,7 +50,7 @@ describe Efl::Ecore do
51
50
  bytes.should eql 12
52
51
  end
53
52
  Ecore.init
54
- pipe = Ecore::EcorePipe.new cb, data
53
+ pipe = Ecore::REcorePipe.new cb, data
55
54
  pipe.write("hello world").should be_true
56
55
  Ecore.main_loop_iterate
57
56
  pipe.read_close
data/spec/edje_spec.rb CHANGED
@@ -5,7 +5,7 @@ require 'efl/edje'
5
5
  #
6
6
  describe Efl::Edje do
7
7
  #
8
- include Efl
8
+ before(:all) { Edje = Efl::Edje }
9
9
  #
10
10
  it "should init" do
11
11
  Edje.init.should eql 1
data/spec/eet_spec.rb CHANGED
@@ -5,7 +5,10 @@ require 'efl/eet'
5
5
  #
6
6
  describe Efl::Eet do
7
7
  #
8
- include Efl
8
+ before(:all) {
9
+ Eet = Efl::Eet
10
+ REetFile = Efl::Eet::REetFile
11
+ }
9
12
  #
10
13
  FP = '/tmp/_eet.cfg'
11
14
  #
@@ -28,80 +31,76 @@ describe Efl::Eet do
28
31
  end
29
32
  #
30
33
  it "should have good enums" do
31
- Efl::API.enum_type(:eet_file_mode)[:eet_file_mode_invalid].should eql -1
32
- Efl::API.enum_type(:eet_file_mode)[:eet_file_mode_read].should eql 0
33
- Efl::API.enum_type(:eet_file_mode)[:eet_file_mode_write].should eql 1
34
- Efl::API.enum_type(:eet_file_mode)[:eet_file_mode_read_write].should eql 2
34
+ Eet.enum_type(:eet_file_mode)[:eet_file_mode_invalid].should eql -1
35
+ Eet.enum_type(:eet_file_mode)[:eet_file_mode_read].should eql 0
36
+ Eet.enum_type(:eet_file_mode)[:eet_file_mode_write].should eql 1
37
+ Eet.enum_type(:eet_file_mode)[:eet_file_mode_read_write].should eql 2
35
38
  end
36
39
  #
37
- it "should open and close" do
38
- Eet.init
39
- f = Eet.open FP, Efl::API.enum_type(:eet_file_mode)[:eet_file_mode_write]
40
- f.write 'fake', 'value'
41
- f.close
42
- Eet.shutdown
43
- end
44
- #
45
- it "should be able to get file access mode" do
46
- Eet.init
47
- Efl::API.enum_type(:eet_file_mode).symbols.each do |m|
48
- next if m==:eet_file_mode_invalid
49
- Eet.open FP, Efl::API.enum_type(:eet_file_mode)[m] do |f|
50
- f.mode_get.should eql m
40
+ describe Efl::Eet::REetFile do
41
+ before(:each) { Eet.init }
42
+ after(:each) { Eet.shutdown }
43
+ #
44
+ it "should open and close" do
45
+ f = REetFile.open FP, Eet.enum_type(:eet_file_mode)[:eet_file_mode_write]
46
+ f.write 'fake', 'value'
47
+ f.close
48
+ end
49
+ #
50
+ it "should be able to get file access mode" do
51
+ Eet.enum_type(:eet_file_mode).symbols.each do |m|
52
+ next if m==:eet_file_mode_invalid
53
+ REetFile.open FP, Eet.enum_type(:eet_file_mode)[m] do |f|
54
+ f.mode_get.should eql m
55
+ end
51
56
  end
52
57
  end
53
- Eet.shutdown
54
- end
55
- #
56
- it "should write" do
57
- Eet.init
58
- f = Eet.open FP, :eet_file_mode_write
59
- f.mode_get.should eql :eet_file_mode_write
60
- f.write 'config', 'test key'
61
- f.close
62
- Eet.shutdown
63
- end
64
- #
65
- it "should read" do
66
- Eet.init
67
- f = Eet.open FP, :eet_file_mode_read
68
- f.mode_get.should eql :eet_file_mode_read
69
- f.read('config').should eql 'test key'
70
- f.close
71
- Eet.shutdown
72
- end
73
- #
74
- it "should read/write" do
75
- Eet.init
76
- f = Eet.open FP, :eet_file_mode_read_write
77
- f.write 'configg', 'test key'
78
- f.read('configg').should eql 'test key'
79
- f.close
80
- Eet.shutdown
81
- end
82
- #
83
- it "should write in block" do
84
- Eet.init
85
- Eet.open FP, :eet_file_mode_write do |f|
86
- f.write 'config2', 'test--key'
58
+ #
59
+ it "should write" do
60
+ f = REetFile.open FP, :eet_file_mode_write
61
+ f.mode_get.should eql :eet_file_mode_write
62
+ f.write 'config', 'test key'
63
+ f.close
87
64
  end
88
- Eet.shutdown
89
- end
90
- #
91
- it "should read in block" do
92
- Eet.init
93
- Eet.open FP, :eet_file_mode_read do |f|
94
- f.read('config2').should eql 'test--key'
65
+ #
66
+ it "default mode should be read" do
67
+ f = REetFile.open FP
68
+ f.mode_get.should eql :eet_file_mode_read
69
+ f.close
95
70
  end
96
- Eet.shutdown
97
- end
98
- #
99
- it "should read/write in block" do
100
- Eet.init
101
- Eet.open FP, :eet_file_mode_read_write do |f|
102
- f.write 'config22', 'test--key'
103
- f.read('config22').should eql 'test--key'
71
+ #
72
+ it "should read" do
73
+ f = REetFile.open FP, :eet_file_mode_read
74
+ f.mode_get.should eql :eet_file_mode_read
75
+ f.read('config').should eql 'test key'
76
+ f.close
77
+ end
78
+ #
79
+ it "should read/write" do
80
+ f = REetFile.open FP, :eet_file_mode_read_write
81
+ f.write 'configg', 'test key'
82
+ f.read('configg').should eql 'test key'
83
+ f.close
84
+ end
85
+ #
86
+ it "should write in block" do
87
+ REetFile.open FP, :eet_file_mode_write do |f|
88
+ f.write 'config2', 'test--key'
89
+ end
90
+ end
91
+ #
92
+ it "should read in block" do
93
+ REetFile.open FP, :eet_file_mode_read do |f|
94
+ f.read('config2').should eql 'test--key'
95
+ end
96
+ end
97
+ #
98
+ it "should read/write in block" do
99
+ REetFile.open FP, :eet_file_mode_read_write do |f|
100
+ f.write 'config22', 'test--key'
101
+ f.read('config22').should eql 'test--key'
102
+ end
104
103
  end
105
- Eet.shutdown
104
+ #
106
105
  end
107
106
  end
@@ -0,0 +1,180 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: UTF-8 -*-
3
+ #
4
+ require 'efl/eina_hash'
5
+ #
6
+ describe Efl::EinaHash do
7
+ #
8
+ before(:all) {
9
+ REinaHash = Efl::EinaHash::REinaHash
10
+ Efl::Eina.init.should eql 1
11
+ @d0 = FFI::MemoryPointer.from_string "D0"
12
+ @d1 = FFI::MemoryPointer.from_string "D1"
13
+ @d2 = FFI::MemoryPointer.from_string "D2"
14
+ @d3 = FFI::MemoryPointer.from_string "D3"
15
+ }
16
+ after(:all) {
17
+ Efl::Eina.shutdown.should eql 0
18
+ }
19
+ #
20
+ it "should append prepend and fetch" do
21
+ h = REinaHash.new
22
+ h.add 'k2', @d2
23
+ h.add 'k1', @d1
24
+ h['k3']=@d3
25
+ h['k0']=@d0
26
+ h['k0'].read_string.should eql "D0"
27
+ h['k1'].read_string.should eql "D1"
28
+ h['k2'].read_string.should eql "D2"
29
+ h['k3'].read_string.should eql "D3"
30
+ cpt=0
31
+ h.each { |k,v|
32
+ cpt+=1
33
+ v.read_string.empty?.should be_false
34
+ }
35
+ cpt.should eql 4
36
+ end
37
+ #
38
+ it "should be able to convert into ruby Hash from NULL pointer" do
39
+ h = Hash.from_eina_hash FFI::Pointer::NULL
40
+ h.empty?.should be_true
41
+ h.is_a?(Hash).should be_true
42
+ end
43
+ #
44
+ it "should be able to convert into ruby Hash from empty REinaHash" do
45
+ h = Hash.from_eina_hash REinaHash.new
46
+ h.empty?.should be_true
47
+ h.is_a?(Hash).should be_true
48
+ end
49
+ #
50
+ it "should be able to convert into ruby Hash from empty REinaHash pointer" do
51
+ h = Hash.from_eina_hash REinaHash.new.to_ptr
52
+ h.empty?.should be_true
53
+ h.is_a?(Hash).should be_true
54
+ end
55
+ #
56
+ it "should be able to convert into ruby Hash from non empty REinaHash" do
57
+ h = REinaHash.new
58
+ d0 = FFI::MemoryPointer.from_string "D0"
59
+ d1 = FFI::MemoryPointer.from_string "D1"
60
+ d2 = FFI::MemoryPointer.from_string "D2"
61
+ d3 = FFI::MemoryPointer.from_string "D3"
62
+ h.add 'k2', d2
63
+ h.add 'k1', d1
64
+ h['k3']=d3
65
+ h["k0"]=d0
66
+ h["k0"].read_string.should eql "D0"
67
+ h['k1'].read_string.should eql "D1"
68
+ h['k2'].read_string.should eql "D2"
69
+ h['k3'].read_string.should eql "D3"
70
+ cpt=0
71
+ h.each { |k,v|
72
+ cpt+=1
73
+ v.read_string.empty?.should be_false
74
+ true
75
+ }
76
+ cpt.should eql 4
77
+ rh = Hash.from_eina_hash h
78
+ rh.length.should eql 4
79
+ rh2 = {}
80
+ rh.each { |k,v|
81
+ rh2[k.read_string]=v.read_string
82
+ true
83
+ }
84
+ rh2['k0'].should eql 'D0'
85
+ rh2['k1'].should eql 'D1'
86
+ rh2['k2'].should eql 'D2'
87
+ rh2['k3'].should eql 'D3'
88
+ end
89
+ #
90
+ it "should be able to convert into ruby Hash from non empty REinaHash pointer" do
91
+ h = REinaHash.new
92
+ d0 = FFI::MemoryPointer.from_string "D0"
93
+ d1 = FFI::MemoryPointer.from_string "D1"
94
+ d2 = FFI::MemoryPointer.from_string "D2"
95
+ d3 = FFI::MemoryPointer.from_string "D3"
96
+ h.add 'k2', d2
97
+ h.add 'k1', d1
98
+ h['k3']=d3
99
+ h['k0']=d0
100
+ h['k0'].read_string.should eql "D0"
101
+ h['k1'].read_string.should eql "D1"
102
+ h['k2'].read_string.should eql "D2"
103
+ h['k3'].read_string.should eql "D3"
104
+ rh = Hash.from_eina_hash h.to_ptr
105
+ rh.length.should eql 4
106
+ end
107
+ #
108
+ it "should be able to convert into ruby Hash from non empty REinaHash pointer, with key from string" do
109
+ h = REinaHash.new
110
+ d0 = FFI::MemoryPointer.from_string "D0"
111
+ d1 = FFI::MemoryPointer.from_string "D1"
112
+ d2 = FFI::MemoryPointer.from_string "D2"
113
+ d3 = FFI::MemoryPointer.from_string "D3"
114
+ h.add 'k2', d2
115
+ h.add 'k1', d1
116
+ h['k3']=d3
117
+ h['k0']=d0
118
+ h['k0'].read_string.should eql "D0"
119
+ h['k1'].read_string.should eql "D1"
120
+ h['k2'].read_string.should eql "D2"
121
+ h['k3'].read_string.should eql "D3"
122
+ rh = h.to_h_conv
123
+ rh.length.should eql 4
124
+ rh['k0'].read_string.should eql "D0"
125
+ rh['k1'].read_string.should eql "D1"
126
+ rh['k2'].read_string.should eql "D2"
127
+ rh['k3'].read_string.should eql "D3"
128
+ end
129
+ #
130
+ it "should be able to convert into ruby Hash from non empty REinaHash pointer, with key from string block" do
131
+ h = REinaHash.new
132
+ d0 = FFI::MemoryPointer.from_string "D0"
133
+ d1 = FFI::MemoryPointer.from_string "D1"
134
+ d2 = FFI::MemoryPointer.from_string "D2"
135
+ d3 = FFI::MemoryPointer.from_string "D3"
136
+ h.add 'k2', d2
137
+ h.add 'k1', d1
138
+ h['k3']=d3
139
+ h['k0']=d0
140
+ h['k0'].read_string.should eql "D0"
141
+ h['k1'].read_string.should eql "D1"
142
+ h['k2'].read_string.should eql "D2"
143
+ h['k3'].read_string.should eql "D3"
144
+ cpt=0
145
+ rh = h.to_h_conv { |k| cpt+=1; k.read_string }
146
+ cpt.should eql 4
147
+ rh.length.should eql 4
148
+ rh['k0'].read_string.should eql "D0"
149
+ rh['k1'].read_string.should eql "D1"
150
+ rh['k2'].read_string.should eql "D2"
151
+ rh['k3'].read_string.should eql "D3"
152
+ end
153
+ #
154
+ it "should be able to build from ruby Hash" do
155
+ rh = {}
156
+ k0 = FFI::MemoryPointer.from_string "0"
157
+ k1 = FFI::MemoryPointer.from_string "1"
158
+ k2 = FFI::MemoryPointer.from_string "2"
159
+ k3 = FFI::MemoryPointer.from_string "3"
160
+ d0 = FFI::MemoryPointer.from_string "D0"
161
+ d1 = FFI::MemoryPointer.from_string "D1"
162
+ d2 = FFI::MemoryPointer.from_string "D2"
163
+ d3 = FFI::MemoryPointer.from_string "D3"
164
+ rh[k0]=d0
165
+ rh[k1]=d1
166
+ rh[k2]=d2
167
+ rh[k3]=d3
168
+ h = REinaHash.new rh
169
+ h[k0].read_string.should eql "D0"
170
+ h[k1].read_string.should eql "D1"
171
+ h[k2].read_string.should eql "D2"
172
+ h[k3].read_string.should eql "D3"
173
+ end
174
+ #
175
+ it "alternate constructor should work" do
176
+ cstr_cnt = 0
177
+ h = REinaHash.new { cstr_cnt+=1; Efl::EinaHash.eina_hash_string_superfast_new FFI::Pointer::NULL }
178
+ cstr_cnt.should eql 1
179
+ end
180
+ end