1 /* Basic test for the TEST_COMPARE_STRING 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 ("", NULL
); /* Line 29. */
30 TEST_COMPARE_STRING ("X", ""); /* Line 30. */
31 TEST_COMPARE_STRING (NULL
, "X"); /* Line 31. */
32 TEST_COMPARE_STRING ("abcd", "abcD"); /* Line 32. */
33 TEST_COMPARE_STRING ("abcd", NULL
); /* Line 33. */
34 TEST_COMPARE_STRING (NULL
, "abcd"); /* Line 34. */
37 /* Same contents, different addresses. */
38 char buffer_abc_1
[] = "abc";
39 char buffer_abc_2
[] = "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 (NULL
, NULL
);
47 TEST_COMPARE_STRING ("", "");
48 TEST_COMPARE_STRING (buffer_abc_1
, buffer_abc_2
);
49 TEST_COMPARE_STRING (buffer_abc_1
, "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.c:29: error: string comparison failed\n"
64 " left string: 0 bytes\n"
65 " right string: NULL\n"
66 "tst-test_compare_string.c:30: error: string comparison failed\n"
67 " left string: 1 bytes\n"
68 " right string: 0 bytes\n"
69 " left (evaluated from \"X\"):\n"
72 "tst-test_compare_string.c:31: error: string comparison failed\n"
73 " left string: NULL\n"
74 " right string: 1 bytes\n"
75 " right (evaluated from \"X\"):\n"
78 "tst-test_compare_string.c:32: error: string comparison failed\n"
79 " string length: 4 bytes\n"
80 " left (evaluated from \"abcd\"):\n"
83 " right (evaluated from \"abcD\"):\n"
86 "tst-test_compare_string.c:33: error: string comparison failed\n"
87 " left string: 4 bytes\n"
88 " right string: NULL\n"
89 " left (evaluated from \"abcd\"):\n"
92 "tst-test_compare_string.c:34: error: string comparison failed\n"
93 " left string: NULL\n"
94 " right string: 4 bytes\n"
95 " right (evaluated from \"abcd\"):\n"
100 /* Check that there is no output on standard error. */
101 support_capture_subprocess_check (&proc
, "TEST_COMPARE_STRING",
107 #include <support/test-driver.c>