localedata: Convert day names in nn_NO locale to UTF-8
[glibc.git] / nss / tst-sgetsgent.c
blob0370c10fd0630b42a2b273808a63f9b97d07ac11
1 /* Test large input for sgetsgent (bug 30151).
2 Copyright (C) 2023 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 <https://www.gnu.org/licenses/>. */
19 #include <gshadow.h>
20 #include <stddef.h>
21 #include <support/check.h>
22 #include <support/support.h>
23 #include <support/xmemstream.h>
24 #include <stdlib.h>
26 static int
27 do_test (void)
29 /* Create a shadow group with 1000 members. */
30 struct xmemstream mem;
31 xopen_memstream (&mem);
32 const char *passwd = "k+zD0nucwfxAo3sw1NXUj6K5vt5M16+X0TVGdE1uFvq5R8V7efJ";
33 fprintf (mem.out, "group-name:%s::m0", passwd);
34 for (int i = 1; i < 1000; ++i)
35 fprintf (mem.out, ",m%d", i);
36 xfclose_memstream (&mem);
38 /* Call sgetsgent. */
39 char *input = mem.buffer;
40 struct sgrp *e = sgetsgent (input);
41 TEST_VERIFY_EXIT (e != NULL);
42 TEST_COMPARE_STRING (e->sg_namp, "group-name");
43 TEST_COMPARE_STRING (e->sg_passwd, passwd);
44 /* No administrators. */
45 TEST_COMPARE_STRING (e->sg_adm[0], NULL);
46 /* Check the members list. */
47 for (int i = 0; i < 1000; ++i)
49 char *member = xasprintf ("m%d", i);
50 TEST_COMPARE_STRING (e->sg_mem[i], member);
51 free (member);
53 TEST_COMPARE_STRING (e->sg_mem[1000], NULL);
55 /* Check that putsgent brings back the input string. */
56 xopen_memstream (&mem);
57 TEST_COMPARE (putsgent (e, mem.out), 0);
58 xfclose_memstream (&mem);
59 /* Compare without the trailing '\n' that putsgent added. */
60 TEST_COMPARE (mem.buffer[mem.length - 1], '\n');
61 mem.buffer[mem.length - 1] = '\0';
62 TEST_COMPARE_STRING (mem.buffer, input);
64 free (mem.buffer);
65 free (input);
66 return 0;
69 #include <support/test-driver.c>