|
Packit Service |
6b2d43 |
/* Check two strings for equality.
|
|
Packit Service |
6b2d43 |
Copyright (C) 2018 Free Software Foundation, Inc.
|
|
Packit Service |
6b2d43 |
This file is part of the GNU C Library.
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
6b2d43 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
6b2d43 |
License as published by the Free Software Foundation; either
|
|
Packit Service |
6b2d43 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
6b2d43 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
6b2d43 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
6b2d43 |
Lesser General Public License for more details.
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
6b2d43 |
License along with the GNU C Library; if not, see
|
|
Packit Service |
6b2d43 |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
#include <stdio.h>
|
|
Packit Service |
6b2d43 |
#include <stdlib.h>
|
|
Packit Service |
6b2d43 |
#include <string.h>
|
|
Packit Service |
6b2d43 |
#include <support/check.h>
|
|
Packit Service |
6b2d43 |
#include <support/support.h>
|
|
Packit Service |
6b2d43 |
#include <support/xmemstream.h>
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
static void
|
|
Packit Service |
6b2d43 |
report_length (const char *what, const char *str, size_t length)
|
|
Packit Service |
6b2d43 |
{
|
|
Packit Service |
6b2d43 |
if (str == NULL)
|
|
Packit Service |
6b2d43 |
printf (" %s string: NULL\n", what);
|
|
Packit Service |
6b2d43 |
else
|
|
Packit Service |
6b2d43 |
printf (" %s string: %zu bytes\n", what, length);
|
|
Packit Service |
6b2d43 |
}
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
static void
|
|
Packit Service |
6b2d43 |
report_string (const char *what, const unsigned char *blob,
|
|
Packit Service |
6b2d43 |
size_t length, const char *expr)
|
|
Packit Service |
6b2d43 |
{
|
|
Packit Service |
6b2d43 |
if (length > 0)
|
|
Packit Service |
6b2d43 |
{
|
|
Packit Service |
6b2d43 |
printf (" %s (evaluated from %s):\n", what, expr);
|
|
Packit Service |
6b2d43 |
char *quoted = support_quote_blob (blob, length);
|
|
Packit Service |
6b2d43 |
printf (" \"%s\"\n", quoted);
|
|
Packit Service |
6b2d43 |
free (quoted);
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
fputs (" ", stdout);
|
|
Packit Service |
6b2d43 |
for (size_t i = 0; i < length; ++i)
|
|
Packit Service |
6b2d43 |
printf (" %02X", blob[i]);
|
|
Packit Service |
6b2d43 |
putc ('\n', stdout);
|
|
Packit Service |
6b2d43 |
}
|
|
Packit Service |
6b2d43 |
}
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
static size_t
|
|
Packit Service |
6b2d43 |
string_length_or_zero (const char *str)
|
|
Packit Service |
6b2d43 |
{
|
|
Packit Service |
6b2d43 |
if (str == NULL)
|
|
Packit Service |
6b2d43 |
return 0;
|
|
Packit Service |
6b2d43 |
else
|
|
Packit Service |
6b2d43 |
return strlen (str);
|
|
Packit Service |
6b2d43 |
}
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
void
|
|
Packit Service |
6b2d43 |
support_test_compare_string (const char *left, const char *right,
|
|
Packit Service |
6b2d43 |
const char *file, int line,
|
|
Packit Service |
6b2d43 |
const char *left_expr, const char *right_expr)
|
|
Packit Service |
6b2d43 |
{
|
|
Packit Service |
6b2d43 |
/* Two null pointers are accepted. */
|
|
Packit Service |
6b2d43 |
if (left == NULL && right == NULL)
|
|
Packit Service |
6b2d43 |
return;
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
size_t left_length = string_length_or_zero (left);
|
|
Packit Service |
6b2d43 |
size_t right_length = string_length_or_zero (right);
|
|
Packit Service |
6b2d43 |
|
|
Packit Service |
6b2d43 |
if (left_length != right_length || left == NULL || right == NULL
|
|
Packit Service |
6b2d43 |
|| memcmp (left, right, left_length) != 0)
|
|
Packit Service |
6b2d43 |
{
|
|
Packit Service |
6b2d43 |
support_record_failure ();
|
|
Packit Service |
6b2d43 |
printf ("%s:%d: error: blob comparison failed\n", file, line);
|
|
Packit Service |
6b2d43 |
if (left_length == right_length && right != NULL && left != NULL)
|
|
Packit Service |
6b2d43 |
printf (" string length: %zu bytes\n", left_length);
|
|
Packit Service |
6b2d43 |
else
|
|
Packit Service |
6b2d43 |
{
|
|
Packit Service |
6b2d43 |
report_length ("left", left, left_length);
|
|
Packit Service |
6b2d43 |
report_length ("right", right, right_length);
|
|
Packit Service |
6b2d43 |
}
|
|
Packit Service |
6b2d43 |
report_string ("left", (const unsigned char *) left,
|
|
Packit Service |
6b2d43 |
left_length, left_expr);
|
|
Packit Service |
6b2d43 |
report_string ("right", (const unsigned char *) right,
|
|
Packit Service |
6b2d43 |
right_length, right_expr);
|
|
Packit Service |
6b2d43 |
}
|
|
Packit Service |
6b2d43 |
}
|