1 /* Test for invalid field handling in file-style NSS databases. [BZ #18724]
2 Copyright (C) 2015-2016 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
31 check (const char *what
, bool expr
)
35 printf ("FAIL: %s\n", what
);
40 #define CHECK(expr) check (#expr, (expr))
43 check_rewrite (const char *input
, const char *expected
)
46 const char *result
= __nss_rewrite_field (input
, &to_free
);
47 CHECK (result
!= NULL
);
48 if (result
!= NULL
&& strcmp (result
, expected
) != 0)
50 printf ("FAIL: rewrite \"%s\" -> \"%s\", expected \"%s\"\n",
51 input
, result
, expected
);
60 CHECK (__nss_valid_field (NULL
));
61 CHECK (__nss_valid_field (""));
62 CHECK (__nss_valid_field ("+"));
63 CHECK (__nss_valid_field ("-"));
64 CHECK (__nss_valid_field (" "));
65 CHECK (__nss_valid_field ("abcdef"));
66 CHECK (__nss_valid_field ("abc def"));
67 CHECK (__nss_valid_field ("abc\tdef"));
68 CHECK (!__nss_valid_field ("abcdef:"));
69 CHECK (!__nss_valid_field ("abcde:f"));
70 CHECK (!__nss_valid_field (":abcdef"));
71 CHECK (!__nss_valid_field ("abcdef\n"));
72 CHECK (!__nss_valid_field ("\nabcdef"));
73 CHECK (!__nss_valid_field (":"));
74 CHECK (!__nss_valid_field ("\n"));
76 CHECK (__nss_valid_list_field (NULL
));
77 CHECK (__nss_valid_list_field ((char *[]) {(char *) "good", NULL
}));
78 CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g,ood", NULL
}));
79 CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g\nood", NULL
}));
80 CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g:ood", NULL
}));
82 check_rewrite (NULL
, "");
83 check_rewrite ("", "");
84 check_rewrite ("abc", "abc");
85 check_rewrite ("abc\n", "abc ");
86 check_rewrite ("abc:", "abc ");
87 check_rewrite ("\nabc", " abc");
88 check_rewrite (":abc", " abc");
89 check_rewrite (":", " ");
90 check_rewrite ("\n", " ");
91 check_rewrite ("a:b:c", "a b c");
92 check_rewrite ("a\nb\nc", "a b c");
93 check_rewrite ("a\nb:c", "a b c");
94 check_rewrite ("aa\nbb\ncc", "aa bb cc");
95 check_rewrite ("aa\nbb:cc", "aa bb cc");
100 #define TEST_FUNCTION do_test ()
101 #include "../test-skeleton.c"