root/lib/common/tests/cmdline/pcmk__quote_cmdline_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. empty_input
  2. no_spaces
  3. spaces_no_quote
  4. spaces_with_quote

   1 /*
   2  * Copyright 2022 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/common/unittest_internal.h>
  13 #include <crm/common/cmdline_internal.h>
  14 
  15 #include <glib.h>
  16 
  17 static void
  18 empty_input(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  19     assert_null(pcmk__quote_cmdline(NULL));
  20 }
  21 
  22 static void
  23 no_spaces(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  24     const char *argv[] = { "crm_resource", "-r", "rsc1", "--meta", "-p", "comment", "-v", "hello", "--output-as=xml", NULL };
  25     const gchar *expected = "crm_resource -r rsc1 --meta -p comment -v hello --output-as=xml";
  26 
  27     gchar *processed = pcmk__quote_cmdline((gchar **) argv);
  28     assert_string_equal(processed, expected);
  29     g_free(processed);
  30 }
  31 
  32 static void
  33 spaces_no_quote(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  34     const char *argv[] = { "crm_resource", "-r", "rsc1", "--meta", "-p", "comment", "-v", "hello world", "--output-as=xml", NULL };
  35     const gchar *expected = "crm_resource -r rsc1 --meta -p comment -v 'hello world' --output-as=xml";
  36 
  37     gchar *processed = pcmk__quote_cmdline((gchar **) argv);
  38     assert_string_equal(processed, expected);
  39     g_free(processed);
  40 }
  41 
  42 static void
  43 spaces_with_quote(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  44     const char *argv[] = { "crm_resource", "-r", "rsc1", "--meta", "-p", "comment", "-v", "here's johnny", "--output-as=xml", NULL };
  45     const gchar *expected = "crm_resource -r rsc1 --meta -p comment -v 'here\\\'s johnny' --output-as=xml";
  46 
  47     gchar *processed = pcmk__quote_cmdline((gchar **) argv);
  48     assert_string_equal(processed, expected);
  49     g_free(processed);
  50 }
  51 
  52 PCMK__UNIT_TEST(NULL, NULL,
  53                 cmocka_unit_test(empty_input),
  54                 cmocka_unit_test(no_spaces),
  55                 cmocka_unit_test(spaces_no_quote),
  56                 cmocka_unit_test(spaces_with_quote))

/* [previous][next][first][last][top][bottom][index][help] */