/[webpac2]/trunk/t/4-db.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/t/4-db.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations)
Sun Jul 24 15:03:11 2005 UTC (18 years, 8 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1870 byte(s)
re-worked logging, added no_log option to disable logging

1 #!/usr/bin/perl -w
2
3 use Test::More tests => 25;
4 use Test::Exception;
5 use Cwd qw/abs_path/;
6 use blib;
7 use File::Temp qw/tempdir/;
8 use strict;
9
10 BEGIN {
11 use_ok( 'WebPAC::DB' );
12 }
13
14 ok(my $abs_path = abs_path($0), "abs_path");
15 $abs_path =~ s#/[^/]*$#/#;
16 diag "abs_path: $abs_path";
17
18 my $db;
19 my $debug = 1;
20
21 diag "NULL DB";
22
23 ok($db = new WebPAC::DB( debug => $debug, no_log => 1, ), "new");
24
25 ok(! $db->path, "path");
26
27 ok(! $db->load_ds(), 'load_ds');
28 ok(! $db->load_ds({ '000' => '000' }), 'load_ds');
29
30 ok(! $db->save_ds(), "save_ds");
31 ok(! $db->save_ds({ '000' => '000' }), 'save_ds');
32
33 undef $db;
34
35 ok(my $path = tempdir( CLEANUP => 1 ), "path");
36
37 diag "DB path: $path";
38
39 ok($db = new WebPAC::DB( path => $path, debug => $debug, no_log => 1 ), "new");
40
41 cmp_ok($db->{'path'}, 'eq', $path, "path");
42
43 ok(! $db->path(''), "path - disable caching");
44
45 cmp_ok($db->{'path'}, '==', undef, "no path");
46
47 ok($db->path( $path ), "path($path)");
48
49 cmp_ok($db->{'path'}, 'eq', $path, "path");
50
51 ok(! $db->load_ds(), 'load_ds');
52 ok(! $db->load_ds({ '000' => '000' }), 'load_ds');
53
54 ok(! $db->save_ds(), "save_ds");
55
56 my @ds = [ {
57 'name' => 'Izvor: ',
58 'tag' => 'Source',
59 'display' => [ 'foo' ]
60 }, {
61 'name' => 'ID',
62 'tag' => 'IDths',
63 'swish' => [ 'bar' ],
64 'lookup_key' => [ 'bar' ]
65 }, {
66 'filename' => [ 'out/thes/001.html' ],
67 'name' => 'filename',
68 'tag' => 'filename'
69 },
70 ];
71
72 ok(! $db->save_ds(), "empty save_ds");
73 throws_ok { $db->save_ds( foo => 1 ) } qr/ds/, "save_ds - ds";
74 throws_ok { $db->save_ds( ds => \@ds ) } qr/current_filename/, "save_ds - current_filename";
75 throws_ok { $db->save_ds( ds => \@ds, 'current_filename' => 'foo' ) } qr/headline/, "save_ds - headline";
76
77 ok($db->save_ds( ds => \@ds, 'current_filename' => 'foo', 'headline' => 'bar' ), "save_ds");
78
79 ok(my @ds2 = $db->load_ds({ '000' => '000' }), "load_ds");
80
81 is_deeply(\@ds, \@ds2, "loaded data");
82
83 undef $db;
84

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26