TeensyMud - 'A ruby mud server.'

Browse repository
back

test_yamlstore.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/yamlstore'
require 'storage/properties'
require 'core/world'
require 'core/character'
require 'core/room'
require 'core/script'
end

class TestYamlStore < Test::Unit::TestCase
configuration

def setup
$id = 0
@db = YamlStore.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']}.yaml")
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_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_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

def test_stats
assert_equal(@r, @db.put(@r))
assert_equal(@o, @db.put(@o))
assert_equal(@p, @db.put(@p))
stats=<<EOH
[COLOR Cyan]
---* Database Statistics *---
Rooms - 2
Objects - 1
Scripts - 0
Accounts - 0
Characters - 1
Total Objects - 4
Highest OID in use - 4
---* *---
[/COLOR]
EOH
assert_equal(stats,@db.stats)
end

end