summaryrefslogtreecommitdiffstats
path: root/spec/eet_spec.rb
blob: 848dc78c1f274da5340b82df7a01bee5d1c80c0d (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
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
require 'efl/eet'
#
describe EFL::EET do
    #
    include EFL
    #
    FP = '/tmp/_eet.cfg'
    #
    it "should init" do
        EET.init.should eql 1
        EET.init.should eql 2
        EET.init.should eql 3
    end
    #
    it "should shutdown" do
        EET.shutdown.should eql 2
        EET.shutdown.should eql 1
        EET.shutdown.should eql 0
    end
    #
    it "should clearcache" do
        EET.clearcache
        EET.clearcache
        EET.clearcache
    end
    #
    it "should open and close" do
        EET.init
        f = EET.open FP, EET::FILE_MODE_WRITE
        f.write 'fake', 'value'
        f.close
        EET.shutdown
    end
    it "should be able to get file access mode" do
        EET.init
        [ EET::FILE_MODE_READ, EET::FILE_MODE_WRITE, EET::FILE_MODE_READ_WRITE ].each do |m|
            EET.open FP, m do |f|
                f.mode_get.should eql m
            end
        end
        EET.shutdown
    end
    #
    it "should write" do
        EET.init
        f = EET.open FP, EET::FILE_MODE_WRITE
        f.write 'config', 'test key'
        f.close
        EET.shutdown
    end
    #
    it "should read" do
        EET.init
        f = EET.open FP, EET::FILE_MODE_READ
        f.read('config').should eql 'test key'
        f.close
        EET.shutdown
    end
    #
    it "should read/write" do
        EET.init
        f = EET.open FP, EET::FILE_MODE_READ_WRITE
        f.write 'configg', 'test key'
        f.read('configg').should eql 'test key'
        f.close
        EET.shutdown
    end
    #
    it "should write in block" do
        EET.init
        EET.open FP, EET::FILE_MODE_WRITE do |f|
            f.write 'config2', 'test--key'
        end
        EET.shutdown
    end
    #
    it "should read in block" do
        EET.init
        EET.open FP, EET::FILE_MODE_READ do |f|
            f.read('config2').should eql 'test--key'
        end
        EET.shutdown
    end
    #
    it "should read/write in block" do
        EET.init
        EET.open FP, EET::FILE_MODE_READ_WRITE do |f|
            f.write 'config22', 'test--key'
            f.read('config22').should eql 'test--key'
        end
        EET.shutdown
    end
end