Handle narrowing function sNaN test disabling based on argument format.
[glibc.git] / resolv / tst-ns_name_compress.c
blobc1262e0ec125239b39b07d563ce07afe04304329
1 /* Test ns_name_compress corner cases.
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 <resolv.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <support/check.h>
23 #include <support/support.h>
25 /* Check that we can process names which fit into the destination
26 buffer exactly. See bug 21359. */
27 static void
28 test_exact_fit (const char *name, size_t length)
30 unsigned char *buf = xmalloc (length + 1);
31 memset (buf, '$', length + 1);
32 enum { ptr_count = 5 };
33 const unsigned char *dnptrs[ptr_count] = { buf, };
34 int ret = ns_name_compress (name, buf, length,
35 dnptrs, dnptrs + ptr_count);
36 if (ret < 0)
38 support_record_failure ();
39 printf ("error: ns_name_compress for %s/%zu failed\n", name, length);
40 return;
42 if ((size_t) ret != length)
44 support_record_failure ();
45 printf ("error: ns_name_compress for %s/%zu result mismatch: %d\n",
46 name, length, ret);
48 if (buf[length] != '$')
50 support_record_failure ();
51 printf ("error: ns_name_compress for %s/%zu padding write\n",
52 name, length);
54 free (buf);
57 static int
58 do_test (void)
60 test_exact_fit ("abc", 5);
61 test_exact_fit ("abc.", 5);
63 char long_name[]
64 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."
65 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."
66 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."
67 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.";
68 TEST_VERIFY (strlen (long_name) == NS_MAXCDNAME - 1);
69 test_exact_fit (long_name, NS_MAXCDNAME);
70 long_name[sizeof (long_name) - 1] = '\0';
71 test_exact_fit (long_name, NS_MAXCDNAME);
73 return 0;
76 #include <support/test-driver.c>