1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use strict; |
4 |
|
5 |
use Test::More; |
6 |
use blib; |
7 |
|
8 |
BEGIN { use_ok('WAIT::Database'); } |
9 |
END { system 'rm -rf test' if -d 'test'; } |
10 |
|
11 |
plan tests => 21; |
12 |
|
13 |
ok(my $db = WAIT::Database->create(name => 'test'), "create"); |
14 |
|
15 |
ok(my $tb = $db->create_table(name => 'sample', attr => ['docid', 'term']), "create_table"); |
16 |
|
17 |
ok(my $tid = $tb->insert(docid => 1, term => 'IR'), "insert IR"); |
18 |
|
19 |
$tb->sync; |
20 |
|
21 |
ok(my %tp = $tb->fetch($tid), "fetch"); |
22 |
ok(($tp{docid} == 1 and $tp{term} eq 'IR'), "fetch == IR"); |
23 |
|
24 |
ok($tb->close, "tb->close"); |
25 |
|
26 |
ok($db->close, "db->close"); |
27 |
|
28 |
ok($db = WAIT::Database->open(name => 'test'), "open"); |
29 |
|
30 |
ok($tb = $db->table(name => 'sample'), "table"); |
31 |
|
32 |
ok($tb->open, "open"); |
33 |
|
34 |
ok(%tp = $tb->fetch($tid), "fetch"); |
35 |
ok(($tp{docid} == 1 and $tp{term} eq 'IR'), "fetch == IR"); |
36 |
|
37 |
ok($tb->delete(%tp), "delete"); |
38 |
|
39 |
ok($tb->delete_by_key($tid), "delete_by_key"); |
40 |
|
41 |
# can we reuse tid? |
42 |
ok(my $ntid = $tb->insert(docid => 1, term => 'IR'), "tid reuse"); |
43 |
|
44 |
ok(%tp = $tb->fetch($ntid), "fetch"); |
45 |
ok(($tp{docid} == 1 and $tp{term} eq 'IR'), "fetch == IR"); |
46 |
|
47 |
ok($tb->close, "close"); |
48 |
|
49 |
# clean up |
50 |
ok($db->dispose, "dispose"); |
51 |
ok(!defined $db, "undef db"); |
52 |
ok(defined $tb,"defined tb"); |
53 |
|