blob: a0a408936b6c75fbd247be5097074e2b6a9afdb5 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <mcheck.h>
2#include <nl_types.h>
3#include <stdio.h>
4#include <string.h>
5
6
7static const char *msgs[] =
8{
9#define INPUT(str)
10#define OUTPUT(str) str,
11#include <intl/msgs.h>
12};
13#define nmsgs (sizeof (msgs) / sizeof (msgs[0]))
14
15#define ROUNDS 5
16
17static int
18do_test (void)
19{
20 int rnd;
21 int result = 0;
22
23 mtrace ();
24
25 /* We do this a few times to stress the memory handling. */
26 for (rnd = 0; rnd < ROUNDS; ++rnd)
27 {
28 nl_catd cd = catopen ("libc", 0);
29 size_t cnt;
30
31 if (cd == (nl_catd) -1)
32 {
33 printf ("cannot load catalog: %m\n");
34 result = 1;
35 break;
36 }
37
38 /* Go through all the messages and compare the result. */
39 for (cnt = 0; cnt < nmsgs; ++cnt)
40 {
41 char *trans;
42
43 trans = catgets (cd, 1, 1 + cnt,
44 "+#+# if this comes backs it's an error");
45
46 if (trans == NULL)
47 {
48 printf ("catgets return NULL for %zd\n", cnt);
49 result = 1;
50 }
51 else if (strcmp (trans, msgs[cnt]) != 0 && msgs[cnt][0] != '\0')
52 {
53 printf ("expected \"%s\", got \"%s\"\n", msgs[cnt], trans);
54 result = 1;
55 }
56 }
57
58 if (catclose (cd) != 0)
59 {
60 printf ("catclose failed: %m\n");
61 result = 1;
62 }
63 }
64
65 return result;
66}
67
68#define TEST_FUNCTION do_test ()
69#include "../test-skeleton.c"