This source file includes following definitions.
- empty_input
- no_spaces
- spaces_no_quote
- spaces_with_quote
1
2
3
4
5
6
7
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) {
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))