summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy.zurcher@heraeus.com>2011-04-19 16:33:28 +0200
committerJérémy Zurcher <jeremy.zurcher@heraeus.com>2011-04-19 16:33:28 +0200
commitdc7e8bff7e751fe97149f41fecbe5216dbc9c890 (patch)
tree861691937b51c107e44d6b2f2c32ba3ac634a4bc
parent04bbea78a76910eec93d7e113e2b3803384db7ff (diff)
downloadffi-efl-dc7e8bff7e751fe97149f41fecbe5216dbc9c890.zip
ffi-efl-dc7e8bff7e751fe97149f41fecbe5216dbc9c890.tar.gz
update eet lib and specs
-rw-r--r--lib/e17/eet.rb17
-rw-r--r--spec/eet_spec.rb91
2 files changed, 54 insertions, 54 deletions
diff --git a/lib/e17/eet.rb b/lib/e17/eet.rb
index 324afee..753588f 100644
--- a/lib/e17/eet.rb
+++ b/lib/e17/eet.rb
@@ -1,8 +1,7 @@
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
-require 'e17/eet/eet-defs'
-require 'e17/eet/eet-funcs'
+require 'e17/eet/eet-ffi'
#
module E17
module Eet
@@ -11,12 +10,12 @@ module E17
#
def open path, mode=FILE_MODE_READ, &blk
if blk
- f = eet_open path, mode
+ f = E17::API.eet_open path, mode
raise Exception.new "Unable to open file #{path}" if f.nil?
yield EetFile.new f
- eet_close f
+ E17::API.eet_close f
else
- f = eet_open path, mode
+ f = E17::API.eet_open path, mode
return EetFile.new f unless f.nil?
end
end
@@ -30,21 +29,21 @@ module E17
private :initialize
#
def close
- Eet.eet_close @ptr
+ E17::API.eet_close @ptr
@ptr=nil
end
#
def mode_get
- Eet.eet_mode_get @ptr
+ E17::API.eet_mode_get @ptr
end
#
def write key, data, compress=false
- Eet.eet_write @ptr, key, FFI::MemoryPointer.from_string(data), data.bytesize, ( compress ? 1 : 0 )
+ E17::API.eet_write @ptr, key, FFI::MemoryPointer.from_string(data), data.bytesize, ( compress ? 1 : 0 )
end
#
def read key
ptr = FFI::MemoryPointer.new(:int)
- data = Eet.eet_read @ptr, key, ptr
+ data = E17::API.eet_read @ptr, key, ptr
s = ptr.read_int
ptr.free
return nil if s==0
diff --git a/spec/eet_spec.rb b/spec/eet_spec.rb
index 0ba0c40..d45e07c 100644
--- a/spec/eet_spec.rb
+++ b/spec/eet_spec.rb
@@ -28,24 +28,25 @@ describe E17::Eet do
end
#
it "should have good enums" do
- Eet.enum_type(:eet_file_mode)[:invalid].should eql -1
- Eet.enum_type(:eet_file_mode)[:read].should eql 0
- Eet.enum_type(:eet_file_mode)[:write].should eql 1
- Eet.enum_type(:eet_file_mode)[:read_write].should eql 2
+ E17::API.enum_type(:eet_file_mode)[:eet_file_mode_invalid].should eql -1
+ E17::API.enum_type(:eet_file_mode)[:eet_file_mode_read].should eql 0
+ E17::API.enum_type(:eet_file_mode)[:eet_file_mode_write].should eql 1
+ E17::API.enum_type(:eet_file_mode)[:eet_file_mode_read_write].should eql 2
end
#
it "should open and close" do
Eet.init
- f = Eet.open FP, Eet.enum_type(:eet_file_mode)[:write]
+ f = Eet.open FP, E17::API.enum_type(:eet_file_mode)[: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.enum_type(:eet_file_mode).symbols.each do |m|
- next if m==:invalid
- Eet.open FP, Eet.enum_type(:eet_file_mode)[m] do |f|
+ E17::API.enum_type(:eet_file_mode).symbols.each do |m|
+ next if m==:eet_file_mode_invalid
+ Eet.open FP, E17::API.enum_type(:eet_file_mode)[m] do |f|
f.mode_get.should eql m
end
end
@@ -54,8 +55,8 @@ describe E17::Eet do
#
it "should write" do
Eet.init
- f = Eet.open FP, :write
- f.mode_get.should eql :write
+ f = Eet.open FP, :eet_file_mode_write
+ f.mode_get.should eql :eet_file_mode_write
f.write 'config', 'test key'
f.close
Eet.shutdown
@@ -63,44 +64,44 @@ describe E17::Eet do
#
it "should read" do
Eet.init
- f = Eet.open FP, :read
- f.mode_get.should eql :read
+ f = Eet.open FP, :eet_file_mode_read
+ f.mode_get.should eql :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, :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, :write do |f|
-# f.write 'config2', 'test--key'
-# end
-# Eet.shutdown
-# end
-# #
-# it "should read in block" do
-# Eet.init
-# Eet.open FP, :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, :read_write do |f|
-# f.write 'config22', 'test--key'
-# f.read('config22').should eql 'test--key'
-# end
-# 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