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
|
|
|
|
|
2004-05-16 08:03:23 -04:00
|
|
|
def test_reader_open
|
2004-04-15 05:39:39 -04:00
|
|
|
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
|
|
|
|
2004-05-16 08:03:23 -04:00
|
|
|
def test_newdb_open
|
|
|
|
GDBM.open("#{TMPROOT}/a.dbm") {|dbm|
|
|
|
|
dbm["k"] = "v"
|
|
|
|
}
|
|
|
|
v = GDBM.open("#{TMPROOT}/a.dbm", nil, GDBM::NEWDB) {|d|
|
|
|
|
assert_equal(0, d.length)
|
|
|
|
assert_nil(d["k"])
|
|
|
|
true
|
|
|
|
}
|
|
|
|
assert(v)
|
|
|
|
end
|
|
|
|
|
2004-05-07 05:39:12 -04:00
|
|
|
def test_freeze
|
|
|
|
GDBM.open("#{TMPROOT}/a.dbm") {|d|
|
|
|
|
d.freeze
|
2004-11-18 03:11:12 -05:00
|
|
|
assert_raises(RuntimeError) { d["k"] = "v" }
|
2004-05-07 05:39:12 -04:00
|
|
|
}
|
|
|
|
end
|
2004-04-15 05:39:39 -04:00
|
|
|
end
|
|
|
|
end
|