summaryrefslogtreecommitdiffstats
path: root/spec/eina_list_spec.rb
blob: 66e65c8542220e9c5fa098ec62bb16f569850c49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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 == 1
    }
    after(:all) {
        Efl::Eina.shutdown.should == 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 == "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 == 4
        0.upto 3 do |i|
            ary[i].read_string.should == "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 == 4
        0.upto 3 do |i|
            ary[i].read_string.should == "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 == "D#{i}"
        end
        l.free
    end
    #
end