1 |
# -*- Mode: Perl -*- |
2 |
# database.t -- |
3 |
# ITIID : $ITI$ $Header $__Header$ |
4 |
# Author : Ulrich Pfeifer |
5 |
# Created On : Thu Aug 8 12:14:23 1996 |
6 |
# Last Modified By: Ulrich Pfeifer |
7 |
# Last Modified On: Sun Nov 22 18:44:30 1998 |
8 |
# Language : CPerl |
9 |
# Update Count : 80 |
10 |
# Status : Unknown, Use with caution! |
11 |
# |
12 |
# Copyright (c) 1996-1997, Ulrich Pfeifer |
13 |
# |
14 |
|
15 |
######################### We start with some black magic to print on failure. |
16 |
|
17 |
BEGIN { $| = 1; print "1..18\n"; } |
18 |
END {print "not ok 1\n" unless $loaded; |
19 |
system 'rm -rf test' if -d 'test'; |
20 |
} |
21 |
#use diagnostics; |
22 |
use WAIT::Database; |
23 |
$loaded = 1; |
24 |
print "ok 1\n"; |
25 |
|
26 |
######################### End of black magic. |
27 |
|
28 |
$test = 2; |
29 |
|
30 |
$db = create WAIT::Database name => 'test'; |
31 |
print ((defined $db)? "ok $test\n" : "not ok $test\n"); $test++; |
32 |
|
33 |
$tb = create_table $db name => 'sample', attr => ['docid', 'term']; |
34 |
print ((defined $tb)? "ok $test\n" : "not ok $test\n"); $test++; |
35 |
|
36 |
$tid = $tb->insert(docid => 1, term => IR); |
37 |
print (($tid)? "ok $test\n" : "not ok $test\n"); $test++; |
38 |
|
39 |
$tb->sync; |
40 |
|
41 |
%tp = $tb->fetch($tid); |
42 |
print (($tp{docid} == 1 and $tp{term} eq IR)? "ok $test\n" : "not ok $test\n"); $test++; |
43 |
|
44 |
$status = $tb->close; |
45 |
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
46 |
|
47 |
$status = $db->close; |
48 |
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
49 |
|
50 |
$db = WAIT::Database->open(name => 'test'); |
51 |
print ((defined $db)? "ok $test\n" : "not ok $test\n"); $test++; |
52 |
|
53 |
$tb = table $db name => 'sample'; |
54 |
print ((defined $tb)? "ok $test\n" : "not ok $test\n"); $test++; |
55 |
|
56 |
$status = $tb->open; |
57 |
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
58 |
|
59 |
%tp = $tb->fetch($tid); |
60 |
print (($tp{docid} == 1 and $tp{term} eq IR)? "ok $test\n" : "not ok $test\n"); $test++; |
61 |
|
62 |
$status = $tb->delete(%tp); |
63 |
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
64 |
|
65 |
$status = $tb->delete_by_key($tid); |
66 |
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
67 |
|
68 |
# can we reuse tid? |
69 |
$ntid = $tb->insert(docid => 1, term => IR); |
70 |
print (($ntid == $tid)? "ok $test\n" : "not ok $test\n"); $test++; |
71 |
|
72 |
%tp = $tb->fetch($ntid); |
73 |
print (($tp{docid} == 1 and $tp{term} eq IR)? "ok $test\n" : "not ok $test\n"); $test++; |
74 |
|
75 |
$status = $tb->close; |
76 |
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
77 |
|
78 |
# must have destroyed all handles here ! |
79 |
# clean up |
80 |
$status = $db->dispose; |
81 |
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
82 |
print ((!defined $db)? "ok $test\n" : "not ok $test\n"); $test++; |
83 |
|