1# Before `make install' is performed this script should be runnable with
2# `make test'. After `make install' it should work as `perl test.pl'
3
4######################### We start with some black magic to print on failure.
5
6# Change 1..1 below to 1..last_test_to_print .
7# (It may become useful if the test is moved to ./t subdirectory.)
8
9BEGIN { $| = 1; print "1..7\n"; }
10END {print "not ok 1\n" unless $loaded;}
11
12my @gencat = qw(
13	gencat
14	/bin/gencat /usr/bin/gencat /usr/sbin/gencat /sbin/gencat
15	/etc/gencat /usr/etc/gencat /usr/local/bin/gencat
16);
17
18use Locale::Msgcat;
19$loaded = 1;
20print "ok 1\n";
21
22## Generate the catalog
23if (MakeCat() != 0) {
24   print "not ok 2\n";
25   exit 0;
26}
27print "ok 2\n";
28
29unless ($a = new Locale::Msgcat) {
30   print "not ok 2\n";
31   exit 0;
32}
33print "ok 2\n";
34
35unless ($a->catopen("./sample.cat", 1)) {
36   print "not ok 3\n";
37   exit 0;
38}
39print "ok 3\n";
40
41print "not " if ($a->catgets(1, 1, "test") ne "Hi there ?");
42print "ok 4\n";
43print "not " if ($a->catgets(2, 1, "test") ne "It's raining.");
44print "ok 5\n";
45print "not " if ($a->catgets(2, 2, "test") ne "test");
46print "ok 6\n";
47print "not " unless ($a->catclose());
48print "ok 7\n";
49
50unlink("sample.cat");
51exit 0;
52
53## Makes the message catalog
54sub MakeCat {
55   my $i;
56
57   while ($i = shift(@gencat)) {
58      return 0 if (system("$i sample.cat sample.msg") == 0);
59   }
60   return 1;
61}
62