pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk__quote_cmdline_test.c
Go to the documentation of this file.
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 
14 
15 #include <glib.h>
16 
17 static void
18 empty_input(void **state) {
19  assert_null(pcmk__quote_cmdline(NULL));
20 }
21 
22 static void
23 no_spaces(void **state) {
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) {
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) {
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))
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
gchar * pcmk__quote_cmdline(gchar **argv)
Definition: cmdline.c:163