Blame support/tst-test_compare_string.c

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