1/* Test IDNA name classification.
2 Copyright (C) 2018-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19#include <inet/net-internal.h>
20#include <locale.h>
21#include <stdio.h>
22#include <support/check.h>
23
24static void
25locale_insensitive_tests (void)
26{
27 TEST_COMPARE (__idna_name_classify (""), idna_name_ascii);
28 TEST_COMPARE (__idna_name_classify ("abc"), idna_name_ascii);
29 TEST_COMPARE (__idna_name_classify (".."), idna_name_ascii);
30 TEST_COMPARE (__idna_name_classify ("\001abc\177"), idna_name_ascii);
31 TEST_COMPARE (__idna_name_classify ("\\065bc"), idna_name_ascii);
32}
33
34static int
35do_test (void)
36{
37 puts (s: "info: C locale tests");
38 locale_insensitive_tests ();
39 TEST_COMPARE (__idna_name_classify ("abc\200def"),
40 idna_name_encoding_error);
41 TEST_COMPARE (__idna_name_classify ("abc\200\\def"),
42 idna_name_encoding_error);
43 TEST_COMPARE (__idna_name_classify ("abc\377def"),
44 idna_name_encoding_error);
45
46 puts (s: "info: en_US.ISO-8859-1 locale tests");
47 if (setlocale (LC_CTYPE, "en_US.ISO-8859-1") == 0)
48 FAIL_EXIT1 ("setlocale for en_US.ISO-8859-1: %m\n");
49 locale_insensitive_tests ();
50 TEST_COMPARE (__idna_name_classify ("abc\200def"), idna_name_nonascii);
51 TEST_COMPARE (__idna_name_classify ("abc\377def"), idna_name_nonascii);
52 TEST_COMPARE (__idna_name_classify ("abc\\\200def"),
53 idna_name_nonascii_backslash);
54 TEST_COMPARE (__idna_name_classify ("abc\200\\def"),
55 idna_name_nonascii_backslash);
56
57 puts (s: "info: en_US.UTF-8 locale tests");
58 if (setlocale (LC_CTYPE, "en_US.UTF-8") == 0)
59 FAIL_EXIT1 ("setlocale for en_US.UTF-8: %m\n");
60 locale_insensitive_tests ();
61 TEST_COMPARE (__idna_name_classify ("abc\xc3\x9f""def"), idna_name_nonascii);
62 TEST_COMPARE (__idna_name_classify ("abc\\\xc3\x9f""def"),
63 idna_name_nonascii_backslash);
64 TEST_COMPARE (__idna_name_classify ("abc\xc3\x9f\\def"),
65 idna_name_nonascii_backslash);
66 TEST_COMPARE (__idna_name_classify ("abc\200def"), idna_name_encoding_error);
67 TEST_COMPARE (__idna_name_classify ("abc\xc3""def"), idna_name_encoding_error);
68 TEST_COMPARE (__idna_name_classify ("abc\xc3"), idna_name_encoding_error);
69
70 return 0;
71}
72
73#include <support/test-driver.c>
74

source code of glibc/inet/tst-idna_name_classify.c