1 |
# -*- Mode: Perl -*- |
#!/usr/bin/perl -w |
|
# database.t -- |
|
|
# ITIID : $ITI$ $Header $__Header$ |
|
|
# Author : Ulrich Pfeifer |
|
|
# Created On : Thu Aug 8 12:14:23 1996 |
|
|
# Last Modified By: Ulrich Pfeifer |
|
|
# Last Modified On: Sun Nov 22 18:44:30 1998 |
|
|
# Language : CPerl |
|
|
# Update Count : 80 |
|
|
# Status : Unknown, Use with caution! |
|
|
# |
|
|
# Copyright (c) 1996-1997, Ulrich Pfeifer |
|
|
# |
|
|
|
|
|
######################### We start with some black magic to print on failure. |
|
|
|
|
|
BEGIN { $| = 1; print "1..18\n"; } |
|
|
END {print "not ok 1\n" unless $loaded; |
|
|
system 'rm -rf test' if -d 'test'; |
|
|
} |
|
|
#use diagnostics; |
|
|
use WAIT::Database; |
|
|
$loaded = 1; |
|
|
print "ok 1\n"; |
|
|
|
|
|
######################### End of black magic. |
|
|
|
|
|
$test = 2; |
|
2 |
|
|
3 |
$db = create WAIT::Database name => 'test'; |
use strict; |
|
print ((defined $db)? "ok $test\n" : "not ok $test\n"); $test++; |
|
4 |
|
|
5 |
$tb = create_table $db name => 'sample', attr => ['docid', 'term']; |
use Test::More; |
6 |
print ((defined $tb)? "ok $test\n" : "not ok $test\n"); $test++; |
use blib; |
7 |
|
|
8 |
$tid = $tb->insert(docid => 1, term => IR); |
BEGIN { use_ok('WAIT::Database'); } |
9 |
print (($tid)? "ok $test\n" : "not ok $test\n"); $test++; |
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; |
$tb->sync; |
20 |
|
|
21 |
%tp = $tb->fetch($tid); |
ok(my %tp = $tb->fetch($tid), "fetch"); |
22 |
print (($tp{docid} == 1 and $tp{term} eq IR)? "ok $test\n" : "not ok $test\n"); $test++; |
ok(($tp{docid} == 1 and $tp{term} eq 'IR'), "fetch == IR"); |
23 |
|
|
24 |
$status = $tb->close; |
ok($tb->close, "tb->close"); |
|
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
|
25 |
|
|
26 |
$status = $db->close; |
ok($db->close, "db->close"); |
|
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
|
27 |
|
|
28 |
$db = WAIT::Database->open(name => 'test'); |
ok($db = WAIT::Database->open(name => 'test'), "open"); |
|
print ((defined $db)? "ok $test\n" : "not ok $test\n"); $test++; |
|
29 |
|
|
30 |
$tb = table $db name => 'sample'; |
ok($tb = $db->table(name => 'sample'), "table"); |
|
print ((defined $tb)? "ok $test\n" : "not ok $test\n"); $test++; |
|
31 |
|
|
32 |
$status = $tb->open; |
ok($tb->open, "open"); |
|
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
|
33 |
|
|
34 |
%tp = $tb->fetch($tid); |
ok(%tp = $tb->fetch($tid), "fetch"); |
35 |
print (($tp{docid} == 1 and $tp{term} eq IR)? "ok $test\n" : "not ok $test\n"); $test++; |
ok(($tp{docid} == 1 and $tp{term} eq 'IR'), "fetch == IR"); |
36 |
|
|
37 |
$status = $tb->delete(%tp); |
ok($tb->delete(%tp), "delete"); |
|
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
|
38 |
|
|
39 |
$status = $tb->delete_by_key($tid); |
ok($tb->delete_by_key($tid), "delete_by_key"); |
|
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
|
40 |
|
|
41 |
# can we reuse tid? |
# can we reuse tid? |
42 |
$ntid = $tb->insert(docid => 1, term => IR); |
ok(my $ntid = $tb->insert(docid => 1, term => 'IR'), "tid reuse"); |
|
print (($ntid == $tid)? "ok $test\n" : "not ok $test\n"); $test++; |
|
43 |
|
|
44 |
%tp = $tb->fetch($ntid); |
ok(%tp = $tb->fetch($ntid), "fetch"); |
45 |
print (($tp{docid} == 1 and $tp{term} eq IR)? "ok $test\n" : "not ok $test\n"); $test++; |
ok(($tp{docid} == 1 and $tp{term} eq 'IR'), "fetch == IR"); |
46 |
|
|
47 |
$status = $tb->close; |
ok($tb->close, "close"); |
|
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
|
48 |
|
|
|
# must have destroyed all handles here ! |
|
49 |
# clean up |
# clean up |
50 |
$status = $db->dispose; |
ok($db->dispose, "dispose"); |
51 |
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
ok(!defined $db, "undef db"); |
52 |
print ((!defined $db)? "ok $test\n" : "not ok $test\n"); $test++; |
ok(defined $tb,"defined tb"); |
53 |
|
|