Blame support/tst-support_quote_string.c

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