Remove powerpc, sparc fdim inlines (bug 22987).
[glibc.git] / nss / tst-nss-test3.c
blobd9d708ae7b3877563832c12803a8515a4dd318fa
1 /* Test error checking for group entries.
2 Copyright (C) 2017-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <nss.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
24 #include <support/support.h>
26 #include "nss_test.h"
28 /* The names here are arbitrary, but the *lengths* of the arrays is
29 not, and groups 6 and 7 test for partial matches. */
31 static const char *group_2[] = {
32 "foo", "bar", NULL
35 static const char *group_3[] = {
36 "tom", "dick", "harry", NULL
39 static const char *group_4[] = {
40 "alpha", "beta", "gamma", "fred", NULL
43 static const char *group_6[] = {
44 "larry", "curly", "moe", NULL
47 static const char *group_7[] = {
48 "larry", "curly", "darryl", NULL
51 static const char *group_14[] = {
52 "huey", "dewey", "louis", NULL
55 /* Note that we're intentionally causing mis-matches here; the purpose
56 of this test case is to test each error check and make sure they
57 detect the errors they check for, and to ensure that the harness
58 can process all the error cases properly (i.e. a NULL gr_name
59 field). We check for the correct number of mismatches at the
60 end. */
62 /* This is the data we're giving the service. */
63 static struct group group_table_data[] = {
64 GRP(4), /* match */
65 GRP_N(8, "name6", group_6), /* wrong gid */
66 GRP_N(14, NULL, group_14), /* missing name */
67 GRP(14), /* unexpected name */
68 GRP_N(7, "name7_wrong", group_7), /* wrong name */
69 { .gr_name = (char *)"name5", .gr_passwd = (char *)"wilma", .gr_gid = 5, .gr_mem = NULL }, /* unexpected passwd */
70 { .gr_name = (char *)"name5", .gr_passwd = NULL, .gr_gid = 5, .gr_mem = NULL }, /* missing passwd */
71 { .gr_name = (char *)"name5", .gr_passwd = (char *)"wilma", .gr_gid = 5, .gr_mem = NULL }, /* wrong passwd */
72 GRP_N(3, "name3a", NULL), /* missing member list */
73 GRP_N(3, "name3b", group_3), /* unexpected member list */
74 GRP_N(3, "name3c", group_3), /* wrong/short member list */
75 GRP_N(3, "name3d", group_4), /* wrong/long member list */
76 GRP_LAST ()
79 /* This is the data we compare against. */
80 static struct group group_table[] = {
81 GRP(4),
82 GRP(6),
83 GRP(14),
84 GRP_N(14, NULL, group_14),
85 GRP(7),
86 { .gr_name = (char *)"name5", .gr_passwd = NULL, .gr_gid = 5, .gr_mem = NULL },
87 { .gr_name = (char *)"name5", .gr_passwd = (char *)"fred", .gr_gid = 5, .gr_mem = NULL },
88 { .gr_name = (char *)"name5", .gr_passwd = (char *)"fred", .gr_gid = 5, .gr_mem = NULL },
89 GRP_N(3, "name3a", group_3),
90 GRP_N(3, "name3b", NULL),
91 GRP_N(3, "name3c", group_4),
92 GRP_N(3, "name3d", group_3),
93 GRP(2),
94 GRP_LAST ()
97 void
98 _nss_test1_init_hook(test_tables *t)
100 t->grp_table = group_table_data;
103 static int
104 do_test (void)
106 int retval = 0;
107 int i;
108 struct group *g = NULL;
110 __nss_configure_lookup ("group", "test1");
112 setgrent ();
114 i = 0;
115 for (g = getgrent () ;
116 g != NULL && ! GRP_ISLAST(&group_table[i]);
117 ++i, g = getgrent ())
119 retval += compare_groups (i, g, & group_table[i]);
122 endgrent ();
124 if (g)
126 printf ("FAIL: [?] group entry %u.%s unexpected\n", g->gr_gid, g->gr_name);
127 ++retval;
129 if (group_table[i].gr_name || group_table[i].gr_gid)
131 printf ("FAIL: [%d] group entry %u.%s missing\n", i,
132 group_table[i].gr_gid, group_table[i].gr_name);
133 ++retval;
136 #define EXPECTED 18
137 if (retval == EXPECTED)
139 if (retval > 0)
140 printf ("PASS: Found %d expected errors\n", retval);
141 return 0;
143 else
145 printf ("FAIL: Found %d errors, expected %d\n", retval, EXPECTED);
146 return 1;
150 #include <support/test-driver.c>