4 use Test::More tests => 16;
5 BEGIN { use_ok('IndexData::Utils::PersistentCounter') };
7 my $file = "/tmp/id-u-pc-$$";
8 my $counter = new IndexData::Utils::PersistentCounter($file);
9 ok(!defined $counter, "can't open non-existent counter");
11 $counter = new IndexData::Utils::PersistentCounter("/x/$file", 1);
12 ok(!defined $counter, "can't create counter in silly place");
14 $counter = new IndexData::Utils::PersistentCounter($file, 1);
15 my $detail = defined $counter ? '' : ": $!@";
16 ok(defined $counter, "created new counter$detail");
18 foreach my $i (1..5) {
19 my $n = $counter->next();
20 ok(defined $n, "n is defined");
21 ok($n == $i, "n has correct value $i");
24 ### should test access from multiple processes
26 my $ok = $counter->delete();
27 ok($ok, "deleted counter file");
28 $counter = new IndexData::Utils::PersistentCounter($file);
29 ok(!defined $counter, "can't open deleted counter");