uk_UA: Add alternative month names (bug 10871).
[glibc.git] / nss / tst-field.c
blobb9b30ea54fc892e00cfe5aa22afff8bc878555b0
1 /* Test for invalid field handling in file-style NSS databases. [BZ #18724]
2 Copyright (C) 2015-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 /* This test needs to be statically linked because it access hidden
20 functions. */
22 #include <nss.h>
23 #include <stdbool.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include <support/support.h>
30 static bool errors;
32 static void
33 check (const char *what, bool expr)
35 if (!expr)
37 printf ("FAIL: %s\n", what);
38 errors = true;
42 #define CHECK(expr) check (#expr, (expr))
44 static void
45 check_rewrite (const char *input, const char *expected)
47 char *to_free;
48 const char *result = __nss_rewrite_field (input, &to_free);
49 CHECK (result != NULL);
50 if (result != NULL && strcmp (result, expected) != 0)
52 printf ("FAIL: rewrite \"%s\" -> \"%s\", expected \"%s\"\n",
53 input, result, expected);
54 errors = true;
56 free (to_free);
59 static int
60 do_test (void)
62 CHECK (__nss_valid_field (NULL));
63 CHECK (__nss_valid_field (""));
64 CHECK (__nss_valid_field ("+"));
65 CHECK (__nss_valid_field ("-"));
66 CHECK (__nss_valid_field (" "));
67 CHECK (__nss_valid_field ("abcdef"));
68 CHECK (__nss_valid_field ("abc def"));
69 CHECK (__nss_valid_field ("abc\tdef"));
70 CHECK (!__nss_valid_field ("abcdef:"));
71 CHECK (!__nss_valid_field ("abcde:f"));
72 CHECK (!__nss_valid_field (":abcdef"));
73 CHECK (!__nss_valid_field ("abcdef\n"));
74 CHECK (!__nss_valid_field ("\nabcdef"));
75 CHECK (!__nss_valid_field (":"));
76 CHECK (!__nss_valid_field ("\n"));
78 CHECK (__nss_valid_list_field (NULL));
79 CHECK (__nss_valid_list_field ((char *[]) {(char *) "good", NULL}));
80 CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g,ood", NULL}));
81 CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g\nood", NULL}));
82 CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g:ood", NULL}));
84 check_rewrite (NULL, "");
85 check_rewrite ("", "");
86 check_rewrite ("abc", "abc");
87 check_rewrite ("abc\n", "abc ");
88 check_rewrite ("abc:", "abc ");
89 check_rewrite ("\nabc", " abc");
90 check_rewrite (":abc", " abc");
91 check_rewrite (":", " ");
92 check_rewrite ("\n", " ");
93 check_rewrite ("a:b:c", "a b c");
94 check_rewrite ("a\nb\nc", "a b c");
95 check_rewrite ("a\nb:c", "a b c");
96 check_rewrite ("aa\nbb\ncc", "aa bb cc");
97 check_rewrite ("aa\nbb:cc", "aa bb cc");
99 return errors;
102 #include <support/test-driver.c>