5
class TC_DhelpDB < Test::Unit::TestCase
9
FileUtils.rm_r TMP_DIR if File.exists? TMP_DIR
10
FileUtils.mkdir_p TMP_DIR
11
@db = Dhelp::Database.open(BDB::CREATE|BDB::TRUNCATE, {}, 0644,
12
File.join(TMP_DIR, 'dhelpbase'))
16
@db.write(Dhelp::ItemData.new(:file => 'foofile',
19
:descrip => 'Description for foo'))
20
assert_equal(1, @db.keys.size, "Number of keys")
24
fooItem = Dhelp::ItemData.new(:file => 'foofile',
27
:descrip => 'Description for foo')
28
almostFooItem = Dhelp::ItemData.new(:file => 'anotherfile',
31
:descrip => 'Description for foo')
32
barItem = Dhelp::ItemData.new(:file => 'barfile',
35
:descrip => 'Description for bar')
36
fooItemWithAltDesc = Dhelp::ItemData.new(:file => 'foofile',
39
:descrip => 'Alternative description')
42
assert_equal(2, @db.keys.size, "Number of keys")
43
ret = @db.del(almostFooItem)
44
assert_equal(nil, ret, "Deleting nothing")
45
assert_equal(2, @db.keys.size, "Number of keys after deleting nothing")
46
ret = @db.del(fooItem)
47
assert_not_nil(ret, "Really deleting one key")
48
assert_equal(1, @db.keys.size, "Number of keys after really deleting")
49
# Add it again, check it's deleted with the same key, but different
52
assert_equal(2, @db.keys.size, "Number of keys after really deleting")
53
ret = @db.del(fooItemWithAltDesc)
54
assert_not_nil(ret, "Deleting same key, different data")
55
assert_equal(1, @db.keys.size, "Number of keys after really deleting")
59
testCategories = %w(cat1 cat2 supercat supercow powers)
61
testCategories.each_with_index do |cat, i|
62
# A couple of items for each category
65
@db.write(Dhelp::ItemData.new(:file => "#{cat}#{j}",
67
:name => "File #{j} for cat #{cat}",
68
:descrip => "Long description for #{cat}/#{j}"))
71
assert_equal(numberEntries, @db.size, "Files in categories inserted")
73
# Check that every category has the correct files
74
@db.each_category do |cat, itemList|
75
# If the category is in index n, then it has n+1 items
76
size = testCategories.index(cat) + 1
77
assert_equal(size, itemList.size, "Number of categories in #{cat}")
83
FileUtils.rm_rf TMP_DIR