aboutsummaryrefslogtreecommitdiff
path: root/catgets/tst-catgets.c
blob: fdaa8349496b54e70fe8b2ade1ef9801bdedbf91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <mcheck.h>
#include <nl_types.h>
#include <stdio.h>
#include <string.h>


static const char *msgs[] =
{
#define INPUT(str)
#define OUTPUT(str) str,
#include <intl/msgs.h>
};
#define nmsgs (sizeof (msgs) / sizeof (msgs[0]))

#define ROUNDS 5

int
main (void)
{
  int rnd;
  int result = 0;

  mtrace ();

  /* We do this a few times to stress the memory handling.  */
  for (rnd = 0; rnd < ROUNDS; ++rnd)
    {
      nl_catd cd = catopen ("libc", 0);
      size_t cnt;

      if (cd == (nl_catd) -1)
	{
	  printf ("cannot load catalog: %m\n");
	  result = 1;
	  break;
	}

      /* Go through all the messages and compare the result.  */
      for (cnt = 0; cnt < nmsgs; ++cnt)
	{
	  char *trans;

	  trans = catgets (cd, 1, 1 + cnt,
			   "+#+# if this comes backs it's an error");

	  if (trans == NULL)
	    {
	      printf ("catgets return NULL for %zd\n", cnt);
	      result = 1;
	    }
	  else if (strcmp (trans, msgs[cnt]) != 0 && msgs[cnt][0] != '\0')
	    {
	      printf ("expected \"%s\", got \"%s\"\n", msgs[cnt], trans);
	      result = 1;
	    }
	}

      if (catclose (cd) != 0)
	{
	  printf ("catclose failed: %m\n");
	  result = 1;
	}
    }

  return result;
}