|
Packit |
b0207b |
/* Basic test for the TEST_COMPARE_STRING macro.
|
|
Packit |
b0207b |
Copyright (C) 2018 Free Software Foundation, Inc.
|
|
Packit |
b0207b |
This file is part of the GNU C Library.
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
b0207b |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
b0207b |
License as published by the Free Software Foundation; either
|
|
Packit |
b0207b |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
b0207b |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
b0207b |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
b0207b |
Lesser General Public License for more details.
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
b0207b |
License along with the GNU C Library; if not, see
|
|
Packit |
b0207b |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
#include <string.h>
|
|
Packit |
b0207b |
#include <support/check.h>
|
|
Packit |
b0207b |
#include <support/capture_subprocess.h>
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
static void
|
|
Packit |
b0207b |
subprocess (void *closure)
|
|
Packit |
b0207b |
{
|
|
Packit |
b0207b |
/* These tests should fail. They were chosen to cover differences
|
|
Packit |
b0207b |
in length (with the same contents), single-bit mismatches, and
|
|
Packit |
b0207b |
mismatching null pointers. */
|
|
Packit |
b0207b |
TEST_COMPARE_STRING ("", NULL); /* Line 29. */
|
|
Packit |
b0207b |
TEST_COMPARE_STRING ("X", ""); /* Line 30. */
|
|
Packit |
b0207b |
TEST_COMPARE_STRING (NULL, "X"); /* Line 31. */
|
|
Packit |
b0207b |
TEST_COMPARE_STRING ("abcd", "abcD"); /* Line 32. */
|
|
Packit |
b0207b |
TEST_COMPARE_STRING ("abcd", NULL); /* Line 33. */
|
|
Packit |
b0207b |
TEST_COMPARE_STRING (NULL, "abcd"); /* Line 34. */
|
|
Packit |
b0207b |
}
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
/* Same contents, different addresses. */
|
|
Packit |
b0207b |
char buffer_abc_1[] = "abc";
|
|
Packit |
b0207b |
char buffer_abc_2[] = "abc";
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
static int
|
|
Packit |
b0207b |
do_test (void)
|
|
Packit |
b0207b |
{
|
|
Packit |
b0207b |
/* This should succeed. Even if the pointers and array contents are
|
|
Packit |
b0207b |
different, zero-length inputs are not different. */
|
|
Packit |
b0207b |
TEST_COMPARE_STRING (NULL, NULL);
|
|
Packit |
b0207b |
TEST_COMPARE_STRING ("", "");
|
|
Packit |
b0207b |
TEST_COMPARE_STRING (buffer_abc_1, buffer_abc_2);
|
|
Packit |
b0207b |
TEST_COMPARE_STRING (buffer_abc_1, "abc");
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
struct support_capture_subprocess proc = support_capture_subprocess
|
|
Packit |
b0207b |
(&subprocess, NULL);
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
/* Discard the reported error. */
|
|
Packit |
b0207b |
support_record_failure_reset ();
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
puts ("info: *** subprocess output starts ***");
|
|
Packit |
b0207b |
fputs (proc.out.buffer, stdout);
|
|
Packit |
b0207b |
puts ("info: *** subprocess output ends ***");
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
TEST_VERIFY
|
|
Packit |
b0207b |
(strcmp (proc.out.buffer,
|
|
Packit |
b0207b |
"tst-test_compare_string.c:29: error: blob comparison failed\n"
|
|
Packit |
b0207b |
" left string: 0 bytes\n"
|
|
Packit |
b0207b |
" right string: NULL\n"
|
|
Packit |
b0207b |
"tst-test_compare_string.c:30: error: blob comparison failed\n"
|
|
Packit |
b0207b |
" left string: 1 bytes\n"
|
|
Packit |
b0207b |
" right string: 0 bytes\n"
|
|
Packit |
b0207b |
" left (evaluated from \"X\"):\n"
|
|
Packit |
b0207b |
" \"X\"\n"
|
|
Packit |
b0207b |
" 58\n"
|
|
Packit |
b0207b |
"tst-test_compare_string.c:31: error: blob comparison failed\n"
|
|
Packit |
b0207b |
" left string: NULL\n"
|
|
Packit |
b0207b |
" right string: 1 bytes\n"
|
|
Packit |
b0207b |
" right (evaluated from \"X\"):\n"
|
|
Packit |
b0207b |
" \"X\"\n"
|
|
Packit |
b0207b |
" 58\n"
|
|
Packit |
b0207b |
"tst-test_compare_string.c:32: error: blob comparison failed\n"
|
|
Packit |
b0207b |
" string length: 4 bytes\n"
|
|
Packit |
b0207b |
" left (evaluated from \"abcd\"):\n"
|
|
Packit |
b0207b |
" \"abcd\"\n"
|
|
Packit |
b0207b |
" 61 62 63 64\n"
|
|
Packit |
b0207b |
" right (evaluated from \"abcD\"):\n"
|
|
Packit |
b0207b |
" \"abcD\"\n"
|
|
Packit |
b0207b |
" 61 62 63 44\n"
|
|
Packit |
b0207b |
"tst-test_compare_string.c:33: error: blob comparison failed\n"
|
|
Packit |
b0207b |
" left string: 4 bytes\n"
|
|
Packit |
b0207b |
" right string: NULL\n"
|
|
Packit |
b0207b |
" left (evaluated from \"abcd\"):\n"
|
|
Packit |
b0207b |
" \"abcd\"\n"
|
|
Packit |
b0207b |
" 61 62 63 64\n"
|
|
Packit |
b0207b |
"tst-test_compare_string.c:34: error: blob comparison failed\n"
|
|
Packit |
b0207b |
" left string: NULL\n"
|
|
Packit |
b0207b |
" right string: 4 bytes\n"
|
|
Packit |
b0207b |
" right (evaluated from \"abcd\"):\n"
|
|
Packit |
b0207b |
" \"abcd\"\n"
|
|
Packit |
b0207b |
" 61 62 63 64\n"
|
|
Packit |
b0207b |
) == 0);
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
/* Check that there is no output on standard error. */
|
|
Packit |
b0207b |
support_capture_subprocess_check (&proc, "TEST_COMPARE_STRING",
|
|
Packit |
b0207b |
0, sc_allow_stdout);
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
return 0;
|
|
Packit |
b0207b |
}
|
|
Packit |
b0207b |
|
|
Packit |
b0207b |
#include <support/test-driver.c>
|