Project

General

Profile

Bug #8446 ยป test_sdbm_many.rb

arton (Akio Tajima), 05/24/2013 11:22 PM

 
require 'test/unit'
require 'tmpdir'

require 'sdbm'

MAX_COUNT = 4011

class TestManyValues < Test::Unit::TestCase
def setup
@tmpdir = Dir.mktmpdir("tmptest_sdbm")
@prefix = "tmptest_sdbm_#{$$}"
@path = "#{@tmpdir}/#{@prefix}_"
@sdbm = SDBM.new(@path)
end
def teardown
@sdbm.close
ObjectSpace.each_object(SDBM) do |obj|
obj.close unless obj.closed?
end
FileUtils.remove_entry_secure @tmpdir
end
def test_many
val = '@' * 990
begin
@ix = 0
1.upto(MAX_COUNT) do |i|
@ix = i
key = i.to_s
@sdbm[key] = val + key
end
rescue
fail "can store only #{@ix}"
end
begin
1.upto(MAX_COUNT) do |i|
@ix = i
key = i.to_s
assert_equal(val + key, @sdbm[key])
end
rescue
fail "can restore only #{@ix}"
end
end
end
    (1-1/1)