From 0ed32396a0fd63625ea94c4da86c2df3829acc72 Mon Sep 17 00:00:00 2001 From: Jérémy Zurcher Date: Fri, 29 Apr 2011 14:45:08 +0200 Subject: update efl/eina* and specs --- spec/eina/eina_hash_spec.rb | 186 -------------------------------------------- spec/eina/eina_list_spec.rb | 100 ------------------------ spec/eina_hash_spec.rb | 186 ++++++++++++++++++++++++++++++++++++++++++++ spec/eina_list_spec.rb | 101 ++++++++++++++++++++++++ 4 files changed, 287 insertions(+), 286 deletions(-) delete mode 100644 spec/eina/eina_hash_spec.rb delete mode 100644 spec/eina/eina_list_spec.rb create mode 100644 spec/eina_hash_spec.rb create mode 100644 spec/eina_list_spec.rb (limited to 'spec') diff --git a/spec/eina/eina_hash_spec.rb b/spec/eina/eina_hash_spec.rb deleted file mode 100644 index 3cd5504..0000000 --- a/spec/eina/eina_hash_spec.rb +++ /dev/null @@ -1,186 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- -# -require 'efl/eina/eina_hash' -# -describe Efl::Eina::EinaHash do - # - before(:all) { - EinaHash = Efl::Eina::EinaHash - Efl::Eina.init.should eql 1 - @d0 = ::FFI::MemoryPointer.from_string "D0" - @d1 = ::FFI::MemoryPointer.from_string "D1" - @d2 = ::FFI::MemoryPointer.from_string "D2" - @d3 = ::FFI::MemoryPointer.from_string "D3" - } - after(:all) { - Efl::Eina.shutdown.should eql 0 - } - # - it "should append prepend and fetch" do - h = EinaHash.new - h.add 'k2', @d2 - h.add 'k1', @d1 - h['k3']=@d3 - h['k0']=@d0 - h['k0'].read_string.should eql "D0" - h['k1'].read_string.should eql "D1" - h['k2'].read_string.should eql "D2" - h['k3'].read_string.should eql "D3" - cpt=0 - h.each { |k,v| - cpt+=1 - v.read_string.empty?.should be_false - } - cpt.should eql 4 - h.free - end - # - it "should be able to convert into ruby Hash from NULL pointer" do - h = Hash.from_eina_hash ::FFI::Pointer::NULL - h.empty?.should be_true - h.is_a?(Hash).should be_true - end - # - it "should be able to convert into ruby Hash from empty EinaHash" do - h = Hash.from_eina_hash EinaHash.new - h.empty?.should be_true - h.is_a?(Hash).should be_true - end - # - it "should be able to convert into ruby Hash from empty EinaHash pointer" do - h = Hash.from_eina_hash EinaHash.new.ptr - h.empty?.should be_true - h.is_a?(Hash).should be_true - end - # - it "should be able to convert into ruby Hash from non empty EinaHash" do - h = EinaHash.new - d0 = ::FFI::MemoryPointer.from_string "D0" - d1 = ::FFI::MemoryPointer.from_string "D1" - d2 = ::FFI::MemoryPointer.from_string "D2" - d3 = ::FFI::MemoryPointer.from_string "D3" - h.add 'k2', d2 - h.add 'k1', d1 - h['k3']=d3 - h["k0"]=d0 - h["k0"].read_string.should eql "D0" - h['k1'].read_string.should eql "D1" - h['k2'].read_string.should eql "D2" - h['k3'].read_string.should eql "D3" - cpt=0 - h.each { |k,v| - cpt+=1 - v.read_string.empty?.should be_false - true - } - cpt.should eql 4 - rh = Hash.from_eina_hash h - rh.length.should eql 4 - rh2 = {} - rh.each { |k,v| - rh2[k.read_string]=v.read_string - true - } - rh2['k0'].should eql 'D0' - rh2['k1'].should eql 'D1' - rh2['k2'].should eql 'D2' - rh2['k3'].should eql 'D3' - h.free - end - # - it "should be able to convert into ruby Hash from non empty EinaHash pointer" do - h = EinaHash.new - d0 = ::FFI::MemoryPointer.from_string "D0" - d1 = ::FFI::MemoryPointer.from_string "D1" - d2 = ::FFI::MemoryPointer.from_string "D2" - d3 = ::FFI::MemoryPointer.from_string "D3" - h.add 'k2', d2 - h.add 'k1', d1 - h['k3']=d3 - h['k0']=d0 - h['k0'].read_string.should eql "D0" - h['k1'].read_string.should eql "D1" - h['k2'].read_string.should eql "D2" - h['k3'].read_string.should eql "D3" - rh = Hash.from_eina_hash h.ptr - rh.length.should eql 4 - h.free - end - # - it "should be able to convert into ruby Hash from non empty EinaHash pointer, with key from string" do - h = EinaHash.new - d0 = ::FFI::MemoryPointer.from_string "D0" - d1 = ::FFI::MemoryPointer.from_string "D1" - d2 = ::FFI::MemoryPointer.from_string "D2" - d3 = ::FFI::MemoryPointer.from_string "D3" - h.add 'k2', d2 - h.add 'k1', d1 - h['k3']=d3 - h['k0']=d0 - h['k0'].read_string.should eql "D0" - h['k1'].read_string.should eql "D1" - h['k2'].read_string.should eql "D2" - h['k3'].read_string.should eql "D3" - rh = h.to_h_conv - rh.length.should eql 4 - rh['k0'].read_string.should eql "D0" - rh['k1'].read_string.should eql "D1" - rh['k2'].read_string.should eql "D2" - rh['k3'].read_string.should eql "D3" - h.free - end - # - it "should be able to convert into ruby Hash from non empty EinaHash pointer, with key from string block" do - h = EinaHash.new - d0 = ::FFI::MemoryPointer.from_string "D0" - d1 = ::FFI::MemoryPointer.from_string "D1" - d2 = ::FFI::MemoryPointer.from_string "D2" - d3 = ::FFI::MemoryPointer.from_string "D3" - h.add 'k2', d2 - h.add 'k1', d1 - h['k3']=d3 - h['k0']=d0 - h['k0'].read_string.should eql "D0" - h['k1'].read_string.should eql "D1" - h['k2'].read_string.should eql "D2" - h['k3'].read_string.should eql "D3" - cpt=0 - rh = h.to_h_conv { |k| cpt+=1; k.read_string } - cpt.should eql 4 - rh.length.should eql 4 - rh['k0'].read_string.should eql "D0" - rh['k1'].read_string.should eql "D1" - rh['k2'].read_string.should eql "D2" - rh['k3'].read_string.should eql "D3" - h.free - end - # - it "should be able to build from ruby Hash" do - rh = {} - k0 = ::FFI::MemoryPointer.from_string "0" - k1 = ::FFI::MemoryPointer.from_string "1" - k2 = ::FFI::MemoryPointer.from_string "2" - k3 = ::FFI::MemoryPointer.from_string "3" - d0 = ::FFI::MemoryPointer.from_string "D0" - d1 = ::FFI::MemoryPointer.from_string "D1" - d2 = ::FFI::MemoryPointer.from_string "D2" - d3 = ::FFI::MemoryPointer.from_string "D3" - rh[k0]=d0 - rh[k1]=d1 - rh[k2]=d2 - rh[k3]=d3 - h = EinaHash.new rh - h[k0].read_string.should eql "D0" - h[k1].read_string.should eql "D1" - h[k2].read_string.should eql "D2" - h[k3].read_string.should eql "D3" - h.free - end - # - it "alternate constructor should work" do - cstr_cnt = 0 - h = EinaHash.new { cstr_cnt+=1; Efl::FFI.eina_hash_string_superfast_new ::FFI::Pointer::NULL } - cstr_cnt.should eql 1 - end -end diff --git a/spec/eina/eina_list_spec.rb b/spec/eina/eina_list_spec.rb deleted file mode 100644 index 2522256..0000000 --- a/spec/eina/eina_list_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- -# -require 'efl/eina/eina_list' -# -describe Efl::Eina::EinaList do - # - before(:all) { - EinaList = Efl::Eina::EinaList - Efl::Eina.init.should eql 1 - } - after(:all) { - Efl::Eina.shutdown.should eql 0 - } - # - it "should append prepend and fetch" do - l = EinaList.new - d1 = ::FFI::MemoryPointer.from_string "D0" - d2 = ::FFI::MemoryPointer.from_string "D1" - d3 = ::FFI::MemoryPointer.from_string "D2" - d4 = ::FFI::MemoryPointer.from_string "D3" - l.append d3 - l.prepend d2 - l << d4 - l.unshift d1 - 0.upto 3 do |i| - l.nth(i).read_string.should eql "D#{i}" - end - l.each { |p| p.read_string.empty?.should be_false } - l.free - end - # - it "should be able to convert into ruby Array from NULL pointer" do - ary = Array.from_eina_list ::FFI::Pointer::NULL - ary.empty?.should be_true - ary.is_a?(Array).should be_true - end - # - it "should be able to convert into ruby Array from empty EinaList" do - ary = Array.from_eina_list EinaList.new - ary.empty?.should be_true - ary.is_a?(Array).should be_true - end - # - it "should be able to convert into ruby Array from empty EinaList pointer" do - ary = Array.from_eina_list EinaList.new.ptr - ary.empty?.should be_true - ary.is_a?(Array).should be_true - end - # - it "should be able to convert into ruby Array from non empty EinaList" do - l = EinaList.new - d1 = ::FFI::MemoryPointer.from_string "D0" - d2 = ::FFI::MemoryPointer.from_string "D1" - d3 = ::FFI::MemoryPointer.from_string "D2" - d4 = ::FFI::MemoryPointer.from_string "D3" - l.append d3 - l.prepend d2 - l << d4 - l.unshift d1 - ary = Array.from_eina_list l - ary.length.should eql 4 - 0.upto 3 do |i| - ary[i].read_string.should eql "D#{i}" - end - l.free - end - # - it "should be able to convert into ruby Array from non empty EinaList pointer" do - l = EinaList.new - d1 = ::FFI::MemoryPointer.from_string "D0" - d2 = ::FFI::MemoryPointer.from_string "D1" - d3 = ::FFI::MemoryPointer.from_string "D2" - d4 = ::FFI::MemoryPointer.from_string "D3" - l.append d3 - l.prepend d2 - l << d4 - l.unshift d1 - ary = Array.from_eina_list l.ptr - ary.length.should eql 4 - 0.upto 3 do |i| - ary[i].read_string.should eql "D#{i}" - end - l.free - end - # - it "should be able to build from ruby Array" do - a = [] - a << ::FFI::MemoryPointer.from_string("D0") - a << ::FFI::MemoryPointer.from_string("D1") - a << ::FFI::MemoryPointer.from_string("D2") - a << ::FFI::MemoryPointer.from_string("D3") - l = EinaList.new a - 0.upto 3 do |i| - l.nth(i).read_string.should eql "D#{i}" - end - l.free - end - # -end diff --git a/spec/eina_hash_spec.rb b/spec/eina_hash_spec.rb new file mode 100644 index 0000000..5efc062 --- /dev/null +++ b/spec/eina_hash_spec.rb @@ -0,0 +1,186 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +require 'efl/eina_hash' +# +describe Efl::EinaHash do + # + before(:all) { + REinaHash = Efl::EinaHash::REinaHash + Efl::Eina.init.should eql 1 + @d0 = FFI::MemoryPointer.from_string "D0" + @d1 = FFI::MemoryPointer.from_string "D1" + @d2 = FFI::MemoryPointer.from_string "D2" + @d3 = FFI::MemoryPointer.from_string "D3" + } + after(:all) { + Efl::Eina.shutdown.should eql 0 + } + # + it "should append prepend and fetch" do + h = REinaHash.new + h.add 'k2', @d2 + h.add 'k1', @d1 + h['k3']=@d3 + h['k0']=@d0 + h['k0'].read_string.should eql "D0" + h['k1'].read_string.should eql "D1" + h['k2'].read_string.should eql "D2" + h['k3'].read_string.should eql "D3" + cpt=0 + h.each { |k,v| + cpt+=1 + v.read_string.empty?.should be_false + } + cpt.should eql 4 + h.free + end + # + it "should be able to convert into ruby Hash from NULL pointer" do + h = Hash.from_eina_hash FFI::Pointer::NULL + h.empty?.should be_true + h.is_a?(Hash).should be_true + end + # + it "should be able to convert into ruby Hash from empty REinaHash" do + h = Hash.from_eina_hash REinaHash.new + h.empty?.should be_true + h.is_a?(Hash).should be_true + end + # + it "should be able to convert into ruby Hash from empty REinaHash pointer" do + h = Hash.from_eina_hash REinaHash.new.to_ptr + h.empty?.should be_true + h.is_a?(Hash).should be_true + end + # + it "should be able to convert into ruby Hash from non empty REinaHash" do + h = REinaHash.new + d0 = FFI::MemoryPointer.from_string "D0" + d1 = FFI::MemoryPointer.from_string "D1" + d2 = FFI::MemoryPointer.from_string "D2" + d3 = FFI::MemoryPointer.from_string "D3" + h.add 'k2', d2 + h.add 'k1', d1 + h['k3']=d3 + h["k0"]=d0 + h["k0"].read_string.should eql "D0" + h['k1'].read_string.should eql "D1" + h['k2'].read_string.should eql "D2" + h['k3'].read_string.should eql "D3" + cpt=0 + h.each { |k,v| + cpt+=1 + v.read_string.empty?.should be_false + true + } + cpt.should eql 4 + rh = Hash.from_eina_hash h + rh.length.should eql 4 + rh2 = {} + rh.each { |k,v| + rh2[k.read_string]=v.read_string + true + } + rh2['k0'].should eql 'D0' + rh2['k1'].should eql 'D1' + rh2['k2'].should eql 'D2' + rh2['k3'].should eql 'D3' + h.free + end + # + it "should be able to convert into ruby Hash from non empty REinaHash pointer" do + h = REinaHash.new + d0 = FFI::MemoryPointer.from_string "D0" + d1 = FFI::MemoryPointer.from_string "D1" + d2 = FFI::MemoryPointer.from_string "D2" + d3 = FFI::MemoryPointer.from_string "D3" + h.add 'k2', d2 + h.add 'k1', d1 + h['k3']=d3 + h['k0']=d0 + h['k0'].read_string.should eql "D0" + h['k1'].read_string.should eql "D1" + h['k2'].read_string.should eql "D2" + h['k3'].read_string.should eql "D3" + rh = Hash.from_eina_hash h.to_ptr + rh.length.should eql 4 + h.free + end + # + it "should be able to convert into ruby Hash from non empty REinaHash pointer, with key from string" do + h = REinaHash.new + d0 = FFI::MemoryPointer.from_string "D0" + d1 = FFI::MemoryPointer.from_string "D1" + d2 = FFI::MemoryPointer.from_string "D2" + d3 = FFI::MemoryPointer.from_string "D3" + h.add 'k2', d2 + h.add 'k1', d1 + h['k3']=d3 + h['k0']=d0 + h['k0'].read_string.should eql "D0" + h['k1'].read_string.should eql "D1" + h['k2'].read_string.should eql "D2" + h['k3'].read_string.should eql "D3" + rh = h.to_h_conv + rh.length.should eql 4 + rh['k0'].read_string.should eql "D0" + rh['k1'].read_string.should eql "D1" + rh['k2'].read_string.should eql "D2" + rh['k3'].read_string.should eql "D3" + h.free + end + # + it "should be able to convert into ruby Hash from non empty REinaHash pointer, with key from string block" do + h = REinaHash.new + d0 = FFI::MemoryPointer.from_string "D0" + d1 = FFI::MemoryPointer.from_string "D1" + d2 = FFI::MemoryPointer.from_string "D2" + d3 = FFI::MemoryPointer.from_string "D3" + h.add 'k2', d2 + h.add 'k1', d1 + h['k3']=d3 + h['k0']=d0 + h['k0'].read_string.should eql "D0" + h['k1'].read_string.should eql "D1" + h['k2'].read_string.should eql "D2" + h['k3'].read_string.should eql "D3" + cpt=0 + rh = h.to_h_conv { |k| cpt+=1; k.read_string } + cpt.should eql 4 + rh.length.should eql 4 + rh['k0'].read_string.should eql "D0" + rh['k1'].read_string.should eql "D1" + rh['k2'].read_string.should eql "D2" + rh['k3'].read_string.should eql "D3" + h.free + end + # + it "should be able to build from ruby Hash" do + rh = {} + k0 = FFI::MemoryPointer.from_string "0" + k1 = FFI::MemoryPointer.from_string "1" + k2 = FFI::MemoryPointer.from_string "2" + k3 = FFI::MemoryPointer.from_string "3" + d0 = FFI::MemoryPointer.from_string "D0" + d1 = FFI::MemoryPointer.from_string "D1" + d2 = FFI::MemoryPointer.from_string "D2" + d3 = FFI::MemoryPointer.from_string "D3" + rh[k0]=d0 + rh[k1]=d1 + rh[k2]=d2 + rh[k3]=d3 + h = REinaHash.new rh + h[k0].read_string.should eql "D0" + h[k1].read_string.should eql "D1" + h[k2].read_string.should eql "D2" + h[k3].read_string.should eql "D3" + h.free + end + # + it "alternate constructor should work" do + cstr_cnt = 0 + h = REinaHash.new { cstr_cnt+=1; Efl::EinaHash.eina_hash_string_superfast_new FFI::Pointer::NULL } + cstr_cnt.should eql 1 + end +end diff --git a/spec/eina_list_spec.rb b/spec/eina_list_spec.rb new file mode 100644 index 0000000..74f89c5 --- /dev/null +++ b/spec/eina_list_spec.rb @@ -0,0 +1,101 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +require 'efl/eina' +require 'efl/eina_list' +# +describe Efl::EinaList do + # + before(:all) { + REinaList = Efl::EinaList::REinaList + Efl::Eina.init.should eql 1 + } + after(:all) { + Efl::Eina.shutdown.should eql 0 + } + # + it "should append prepend and fetch" do + l = REinaList.new + d1 = ::FFI::MemoryPointer.from_string "D0" + d2 = ::FFI::MemoryPointer.from_string "D1" + d3 = ::FFI::MemoryPointer.from_string "D2" + d4 = ::FFI::MemoryPointer.from_string "D3" + l.append d3 + l.prepend d2 + l << d4 + l.unshift d1 + 0.upto 3 do |i| + l.nth(i).read_string.should eql "D#{i}" + end + l.each { |p| p.read_string.empty?.should be_false } + l.free + end + # + it "should be able to convert into ruby Array from NULL pointer" do + ary = Array.from_eina_list ::FFI::Pointer::NULL + ary.empty?.should be_true + ary.is_a?(Array).should be_true + end + # + it "should be able to convert into ruby Array from empty REinaList" do + ary = Array.from_eina_list REinaList.new + ary.empty?.should be_true + ary.is_a?(Array).should be_true + end + # + it "should be able to convert into ruby Array from empty REinaList pointer" do + ary = Array.from_eina_list REinaList.new.to_ptr + ary.empty?.should be_true + ary.is_a?(Array).should be_true + end + # + it "should be able to convert into ruby Array from non empty REinaList" do + l = REinaList.new + d1 = ::FFI::MemoryPointer.from_string "D0" + d2 = ::FFI::MemoryPointer.from_string "D1" + d3 = ::FFI::MemoryPointer.from_string "D2" + d4 = ::FFI::MemoryPointer.from_string "D3" + l.append d3 + l.prepend d2 + l << d4 + l.unshift d1 + ary = Array.from_eina_list l + ary.length.should eql 4 + 0.upto 3 do |i| + ary[i].read_string.should eql "D#{i}" + end + l.free + end + # + it "should be able to convert into ruby Array from non empty REinaList pointer" do + l = REinaList.new + d1 = ::FFI::MemoryPointer.from_string "D0" + d2 = ::FFI::MemoryPointer.from_string "D1" + d3 = ::FFI::MemoryPointer.from_string "D2" + d4 = ::FFI::MemoryPointer.from_string "D3" + l.append d3 + l.prepend d2 + l << d4 + l.unshift d1 + ary = Array.from_eina_list l.to_ptr + ary.length.should eql 4 + 0.upto 3 do |i| + ary[i].read_string.should eql "D#{i}" + end + l.free + end + # + it "should be able to build from ruby Array" do + a = [] + a << ::FFI::MemoryPointer.from_string("D0") + a << ::FFI::MemoryPointer.from_string("D1") + a << ::FFI::MemoryPointer.from_string("D2") + a << ::FFI::MemoryPointer.from_string("D3") + l = REinaList.new a + 0.upto 3 do |i| + l.nth(i).read_string.should eql "D#{i}" + end + l.free + end + # +end -- cgit v1.2.3