2004-04-15 05:39:39 -04:00
|
|
|
require 'test/unit/testsuite'
|
|
|
|
require 'test/unit/testcase'
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'gdbm'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
|
|
|
|
if defined? GDBM
|
|
|
|
require 'tmpdir'
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
class TestGDBM < Test::Unit::TestCase
|
|
|
|
TMPROOT = "#{Dir.tmpdir}/ruby-gdbm.#{$$}"
|
|
|
|
|
|
|
|
def setup
|
|
|
|
Dir.mkdir TMPROOT
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
FileUtils.rm_rf TMPROOT if File.directory?(TMPROOT)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_open
|
|
|
|
GDBM.open("#{TMPROOT}/a.dbm") {}
|
|
|
|
v = GDBM.open("#{TMPROOT}/a.dbm", nil, GDBM::READER) {|d|
|
|
|
|
assert_raises(GDBMError) { d["k"] = "v" }
|
|
|
|
true
|
|
|
|
}
|
|
|
|
assert(v)
|
|
|
|
end
|
2004-05-07 05:39:12 -04:00
|
|
|
|
|
|
|
def test_freeze
|
|
|
|
GDBM.open("#{TMPROOT}/a.dbm") {|d|
|
|
|
|
d.freeze
|
|
|
|
assert_raises(TypeError) { d["k"] = "v" }
|
|
|
|
}
|
|
|
|
end
|
2004-04-15 05:39:39 -04:00
|
|
|
end
|
|
|
|
end
|