|
Packit Service |
9448d4 |
/* Test the support_quote_string function.
|
|
Packit Service |
9448d4 |
Copyright (C) 2018 Free Software Foundation, Inc.
|
|
Packit Service |
9448d4 |
This file is part of the GNU C Library.
|
|
Packit Service |
9448d4 |
|
|
Packit Service |
9448d4 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
9448d4 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
9448d4 |
License as published by the Free Software Foundation; either
|
|
Packit Service |
9448d4 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
9448d4 |
|
|
Packit Service |
9448d4 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
9448d4 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
9448d4 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
9448d4 |
Lesser General Public License for more details.
|
|
Packit Service |
9448d4 |
|
|
Packit Service |
9448d4 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
9448d4 |
License along with the GNU C Library; if not, see
|
|
Packit Service |
9448d4 |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
9448d4 |
|
|
Packit Service |
9448d4 |
#include <support/check.h>
|
|
Packit Service |
9448d4 |
#include <support/support.h>
|
|
Packit Service |
9448d4 |
#include <string.h>
|
|
Packit Service |
9448d4 |
#include <stdlib.h>
|
|
Packit Service |
9448d4 |
|
|
Packit Service |
9448d4 |
static int
|
|
Packit Service |
9448d4 |
do_test (void)
|
|
Packit Service |
9448d4 |
{
|
|
Packit Service |
9448d4 |
char *p = support_quote_string ("");
|
|
Packit Service |
9448d4 |
TEST_COMPARE (strlen (p), 0);
|
|
Packit Service |
9448d4 |
free (p);
|
|
Packit Service |
9448d4 |
p = support_quote_string ("X");
|
|
Packit Service |
9448d4 |
TEST_COMPARE (strlen (p), 1);
|
|
Packit Service |
9448d4 |
TEST_COMPARE (p[0], 'X');
|
|
Packit Service |
9448d4 |
free (p);
|
|
Packit Service |
9448d4 |
|
|
Packit Service |
9448d4 |
/* Check escaping of backslash-escaped characters, and lack of
|
|
Packit Service |
9448d4 |
escaping for other shell meta-characters. */
|
|
Packit Service |
9448d4 |
p = support_quote_string ("$()*?`@[]{}~\'\"X");
|
|
Packit Service |
9448d4 |
TEST_COMPARE (strcmp (p, "$()*?`@[]{}~\\'\\\"X"), 0);
|
|
Packit Service |
9448d4 |
free (p);
|
|
Packit Service |
9448d4 |
|
|
Packit Service |
9448d4 |
/* Check lack of escaping for letters and digits. */
|
|
Packit Service |
9448d4 |
#define LETTERS_AND_DIGTS \
|
|
Packit Service |
9448d4 |
"abcdefghijklmnopqrstuvwxyz" \
|
|
Packit Service |
9448d4 |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
|
|
Packit Service |
9448d4 |
"0123456789"
|
|
Packit Service |
9448d4 |
p = support_quote_string (LETTERS_AND_DIGTS "@");
|
|
Packit Service |
9448d4 |
TEST_COMPARE (strcmp (p, LETTERS_AND_DIGTS "@"), 0);
|
|
Packit Service |
9448d4 |
free (p);
|
|
Packit Service |
9448d4 |
|
|
Packit Service |
9448d4 |
/* Check escaping of control characters and other non-printable
|
|
Packit Service |
9448d4 |
characters. */
|
|
Packit Service |
9448d4 |
p = support_quote_string ("\r\n\t\a\b\f\v\1\177\200\377@");
|
|
Packit Service |
9448d4 |
TEST_COMPARE (strcmp (p, "\\r\\n\\t\\a\\b\\f\\v\\001"
|
|
Packit Service |
9448d4 |
"\\177\\200\\377@"), 0);
|
|
Packit Service |
9448d4 |
free (p);
|
|
Packit Service |
9448d4 |
|
|
Packit Service |
9448d4 |
return 0;
|
|
Packit Service |
9448d4 |
}
|
|
Packit Service |
9448d4 |
|
|
Packit Service |
9448d4 |
#include <support/test-driver.c>
|