6 static const struct sgrp data[] =
8 { (char *) "one", (char *) "pwdone",
9 (char *[]) { (char *) "admoneone", (char *) "admonetwo",
10 (char *) "admonethree", NULL },
11 (char *[]) { (char *) "memoneone", (char *) "memonetwo",
12 (char *) "memonethree", NULL } },
13 { (char *) "two", (char *) "pwdtwo",
14 (char *[]) { (char *) "admtwoone", (char *) "admtwotwo", NULL },
15 (char *[]) { (char *) "memtwoone", (char *) "memtwotwo",
16 (char *) "memtwothree", NULL } },
17 { (char *) "three", (char *) "pwdthree",
18 (char *[]) { (char *) "admthreeone", (char *) "admthreetwo", NULL },
19 (char *[]) { (char *) "memthreeone", (char *) "memthreetwo", NULL } },
20 { (char *) "four", (char *) "pwdfour",
21 (char *[]) { (char *) "admfourone", (char *) "admfourtwo", NULL },
22 (char *[]) { NULL } },
23 { (char *) "five", (char *) "pwdfive",
25 (char *[]) { (char *) "memfiveone", (char *) "memfivetwo", NULL } },
27 #define ndata (sizeof (data) / sizeof (data[0]))
33 FILE *fp = tmpfile ();
36 puts ("cannot open temporary file");
40 for (size_t i = 0; i < ndata; ++i)
41 if (putsgent (&data[i], fp) != 0)
43 printf ("putsgent call %zu failed\n", i + 1);
52 while ((g = fgetsgent (fp)) != NULL)
55 if (strcmp (g->sg_namp, data[seen].sg_namp) != 0)
57 printf ("sg_namp of entry %d does not match: %s vs %s\n",
58 seen + 1, g->sg_namp, data[seen].sg_namp);
61 if (strcmp (g->sg_passwd, data[seen].sg_passwd) != 0)
63 printf ("sg_passwd of entry %d does not match: %s vs %s\n",
64 seen + 1, g->sg_passwd, data[seen].sg_passwd);
67 if (g->sg_adm == NULL)
69 printf ("sg_adm of entry %d is NULL\n", seen + 1);
75 char **sp1 = g->sg_adm;
76 char **sp2 = data[seen].sg_adm;
77 while (*sp1 != NULL && *sp2 != NULL)
79 if (strcmp (*sp1, *sp2) != 0)
81 printf ("sg_adm[%d] of entry %d does not match: %s vs %s\n",
82 i, seen + 1, *sp1, *sp2);
89 if (*sp1 == NULL && *sp2 != NULL)
91 printf ("sg_adm of entry %d has too few entries\n", seen + 1);
94 else if (*sp1 != NULL && *sp2 == NULL)
96 printf ("sg_adm of entry %d has too many entries\n", seen + 1);
100 if (g->sg_mem == NULL)
102 printf ("sg_mem of entry %d is NULL\n", seen + 1);
108 char **sp1 = g->sg_mem;
109 char **sp2 = data[seen].sg_mem;
110 while (*sp1 != NULL && *sp2 != NULL)
112 if (strcmp (*sp1, *sp2) != 0)
114 printf ("sg_mem[%d] of entry %d does not match: %s vs %s\n",
115 i, seen + 1, *sp1, *sp2);
122 if (*sp1 == NULL && *sp2 != NULL)
124 printf ("sg_mem of entry %d has too few entries\n", seen + 1);
127 else if (*sp1 != NULL && *sp2 == NULL)
129 printf ("sg_mem of entry %d has too many entries\n", seen + 1);
140 #define TEST_FUNCTION do_test ()
141 #include "../test-skeleton.c"