TeensyMud - 'A ruby mud server.'

Browse repository
back

test_sdbmstore.rb

# Code Generated by ZenTest v. 2.3.0

unless defined? $ZENTEST and $ZENTEST
require 'test/unit'
require 'flexmock'
require 'pp'
load 'mockengine.rb'
require 'utility/configuration'
require 'storage/sdbmstore'
require 'storage/properties'
require 'core/world'
require 'core/character'
require 'core/room'
end

class TestSdbmStore < Test::Unit::TestCase
configuration

def setup
$id = 0
@db = SdbmStore.new(options['dbfile'])
$db = @db
@r = Room.new("Here",0)
@o = GameObject.new("Thing",0)
@p = Character.new("Tyche", nil)
end

def teardown
@db.close
File.delete("#{options['dbfile']}.dir")
File.delete("#{options['dbfile']}.pag")
end

def test_delete
# pp @r, @o, @p
# pp @db
assert_equal(@r, @db.put(@r))
assert_equal(@o, @db.put(@o))
@db.delete(@r.id)
@db.delete(@o.id)
assert_equal(nil, @db.get(@r.id))
assert_equal(nil, @db.get(@o.id))
assert_equal(nil, @db.get(@p.id))
end

def test_close
assert_respond_to(@db, :close)
end

def test_log
assert_respond_to(@db, :log)
end

def test_makenoswap
assert(@db.makenoswap(@r.id))
end

def test_makeswap
assert(@db.makeswap(@r.id))
end

def test_get
# pp @r, @o, @p
assert_equal(@r, @db.put(@r))
assert_equal(@o, @db.put(@o))
assert_equal(@r.id, @db.get(@r.id).id)
assert_equal(@o.id, @db.get(@o.id).id)
assert_equal(nil, @db.get(@p.id))
end

def test_check
# pp @r, @o, @p
assert(!@db.check(@r.id))
end

def test_mark
# pp @r, @o, @p
assert(@db.mark(@r.id))
end

def test_getid
assert_equal(5,@db.getid)
end

def test_each
assert_equal(@r, @db.put(@r))
assert_equal(@o, @db.put(@o))
assert_equal(@p, @db.put(@p))
cnt = 0
@db.each {cnt += 1}
assert_equal(5,cnt)
end

def test_put
assert_equal(@r, @db.put(@r))
assert_equal(@o, @db.put(@o))
assert_equal(@p, @db.put(@p))
end

def test_save
assert(@db.save)
end

end