Add tests for counter.
[perl-indexdata-utils.git] / t / 02-IndexData-Utils-PersistentCounter.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 15;
5 BEGIN { use_ok('IndexData::Utils::PersistentCounter') };
6
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");
10
11 $counter = new IndexData::Utils::PersistentCounter("/x/$file", 1);
12 ok(!defined $counter, "can't create counter in silly place");
13
14 $counter = new IndexData::Utils::PersistentCounter($file, 1);
15 ok(defined $counter, "created new counter: $!");
16
17 foreach my $i (1..10) {
18     my $n = $counter->next();
19     is($n, $i);
20 }
21
22 ### should test access from multiple processes
23
24 $counter->delete();
25 $counter = new IndexData::Utils::PersistentCounter($file);
26 ok(!defined $counter, "can't open deleted counter");