1 /* Basic test for the TEST_COMPARE_STRING_WIDE macro.
2 Copyright (C) 2018-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/>. */
20 #include <support/check.h>
21 #include <support/capture_subprocess.h>
24 subprocess (void *closure
)
26 /* These tests should fail. They were chosen to cover differences
27 in length (with the same contents), single-bit mismatches, and
28 mismatching null pointers. */
29 TEST_COMPARE_STRING_WIDE (L
"", NULL
); /* Line 29. */
30 TEST_COMPARE_STRING_WIDE (L
"X", L
""); /* Line 30. */
31 TEST_COMPARE_STRING_WIDE (NULL
, L
"X"); /* Line 31. */
32 TEST_COMPARE_STRING_WIDE (L
"abcd", L
"abcD"); /* Line 32. */
33 TEST_COMPARE_STRING_WIDE (L
"abcd", NULL
); /* Line 33. */
34 TEST_COMPARE_STRING_WIDE (NULL
, L
"abcd"); /* Line 34. */
37 /* Same contents, different addresses. */
38 wchar_t buffer_abc_1
[] = L
"abc";
39 wchar_t buffer_abc_2
[] = L
"abc";
44 /* This should succeed. Even if the pointers and array contents are
45 different, zero-length inputs are not different. */
46 TEST_COMPARE_STRING_WIDE (NULL
, NULL
);
47 TEST_COMPARE_STRING_WIDE (L
"", L
"");
48 TEST_COMPARE_STRING_WIDE (buffer_abc_1
, buffer_abc_2
);
49 TEST_COMPARE_STRING_WIDE (buffer_abc_1
, L
"abc");
51 struct support_capture_subprocess proc
= support_capture_subprocess
54 /* Discard the reported error. */
55 support_record_failure_reset ();
57 puts ("info: *** subprocess output starts ***");
58 fputs (proc
.out
.buffer
, stdout
);
59 puts ("info: *** subprocess output ends ***");
62 (strcmp (proc
.out
.buffer
,
63 "tst-test_compare_string_wide.c:29: error: string comparison failed\n"
64 " left string: 0 wide characters\n"
65 " right string: NULL\n"
66 "tst-test_compare_string_wide.c:30: error: string comparison failed\n"
67 " left string: 1 wide characters\n"
68 " right string: 0 wide characters\n"
69 " left (evaluated from L\"X\"):\n"
72 "tst-test_compare_string_wide.c:31: error: string comparison failed\n"
73 " left string: NULL\n"
74 " right string: 1 wide characters\n"
75 " right (evaluated from L\"X\"):\n"
78 "tst-test_compare_string_wide.c:32: error: string comparison failed\n"
79 " string length: 4 wide characters\n"
80 " left (evaluated from L\"abcd\"):\n"
83 " right (evaluated from L\"abcD\"):\n"
86 "tst-test_compare_string_wide.c:33: error: string comparison failed\n"
87 " left string: 4 wide characters\n"
88 " right string: NULL\n"
89 " left (evaluated from L\"abcd\"):\n"
92 "tst-test_compare_string_wide.c:34: error: string comparison failed\n"
93 " left string: NULL\n"
94 " right string: 4 wide characters\n"
95 " right (evaluated from L\"abcd\"):\n"
100 /* Check that there is no output on standard error. */
101 support_capture_subprocess_check (&proc
, "TEST_COMPARE_STRING_WIDE",
107 #include <support/test-driver.c>