Stats tests

This commit is contained in:
mattbauer 2008-12-28 23:43:02 -06:00
parent 418880baa1
commit 09ee9704e4
3 changed files with 19 additions and 7 deletions

View file

@ -1,17 +1,16 @@
require 'fileutils'
require 'test_helper' require 'test_helper'
class DbTest < Test::Unit::TestCase class DbTest < Test::Unit::TestCase
def setup def setup
FileUtils::mkdir File.join(File.dirname(__FILE__), 'tmp') mkdir File.join(File.dirname(__FILE__), 'tmp')
@db = Bdb::Db.new @db = Bdb::Db.new
@db.open(nil, File.join(File.dirname(__FILE__), 'tmp', 'test.db'), nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0) @db.open(nil, File.join(File.dirname(__FILE__), 'tmp', 'test.db'), nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
end end
def teardown def teardown
assert(@db.close(0)) if @db assert(@db.close(0)) if @db
FileUtils::rm_rf File.join('test', 'tmp') rm_rf File.join(File.dirname(__FILE__), 'tmp')
end end
def test_put_and_get def test_put_and_get

View file

@ -1,10 +1,22 @@
require 'test_helper' require 'test_helper'
class DbTest < Test::Unit::TestCase class DbStat < Test::Unit::TestCase
def setup
mkdir File.join(File.dirname(__FILE__), 'tmp')
end
def teardown
rm_rf File.join(File.dirname(__FILE__), 'tmp')
end
# rb_define_method(cDbStat,"[]",stat_aref,1);
def test_stat def test_stat
@db = Bdb::Db.new
@db.open(nil, File.join(File.dirname(__FILE__), 'tmp', 'test.db'), nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
@db.put(nil, 'key', 'data', 0)
stats = @db.stat(nil, 0)
assert_equal 1, stats['bt_nkeys']
@db.close(0)
end end
end end

View file

@ -1,6 +1,7 @@
require "test/unit" require "test/unit"
require 'fileutils'
require "bdb" require "bdb"
class Test::Unit::TestCase class Test::Unit::TestCase
include FileUtils
end end