Fix testing.
[perl-indexdata-utils.git] / t / 02-IndexData-Utils-PersistentCounter.t
index 491bc7d..a7752d6 100644 (file)
@@ -1,5 +1,29 @@
 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More tests => 16;
 BEGIN { use_ok('IndexData::Utils::PersistentCounter') };
+
+my $file = "/tmp/id-u-pc-$$";
+my $counter = new IndexData::Utils::PersistentCounter($file);
+ok(!defined $counter, "can't open non-existent counter");
+
+$counter = new IndexData::Utils::PersistentCounter("/x/$file", 1);
+ok(!defined $counter, "can't create counter in silly place");
+
+$counter = new IndexData::Utils::PersistentCounter($file, 1);
+my $detail = defined $counter ? '' : ": $!@";
+ok(defined $counter, "created new counter$detail");
+
+foreach my $i (1..5) {
+    my $n = $counter->next();
+    ok(defined $n, "n is defined");
+    ok($n == $i, "n has correct value $i");
+}
+
+### should test access from multiple processes
+
+my $ok = $counter->delete();
+ok($ok, "deleted counter file");
+$counter = new IndexData::Utils::PersistentCounter($file);
+ok(!defined $counter, "can't open deleted counter");