pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pcmk__cmdline_preproc_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2020 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 Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
12 
13 #define LISTS_EQ(a, b) { \
14  g_assert_cmpint(g_strv_length((gchar **) (a)), ==, g_strv_length((gchar **) (b))); \
15  for (int i = 0; i < g_strv_length((a)); i++) { \
16  g_assert_cmpstr((a)[i], ==, (b)[i]); \
17  } \
18 }
19 
20 static void
21 empty_input(void) {
22  g_assert_null(pcmk__cmdline_preproc(NULL, ""));
23 }
24 
25 static void
26 no_specials(void) {
27  const char *argv[] = { "-a", "-b", "-c", "-d", NULL };
28  const gchar *expected[] = { "-a", "-b", "-c", "-d", NULL };
29 
30  gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
31  LISTS_EQ(processed, expected);
32  g_strfreev(processed);
33 
34  processed = pcmk__cmdline_preproc((char **) argv, "");
35  LISTS_EQ(processed, expected);
36  g_strfreev(processed);
37 }
38 
39 static void
40 single_dash(void) {
41  const char *argv[] = { "-", NULL };
42  const gchar *expected[] = { "-", NULL };
43 
44  gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
45  LISTS_EQ(processed, expected);
46  g_strfreev(processed);
47 }
48 
49 static void
50 double_dash(void) {
51  const char *argv[] = { "-a", "--", "-bc", NULL };
52  const gchar *expected[] = { "-a", "--", "-bc", NULL };
53 
54  gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
55  LISTS_EQ(processed, expected);
56  g_strfreev(processed);
57 }
58 
59 static void
60 special_args(void) {
61  const char *argv[] = { "-aX", "-Fval", NULL };
62  const gchar *expected[] = { "-a", "X", "-F", "val", NULL };
63 
64  gchar **processed = pcmk__cmdline_preproc((char **) argv, "aF");
65  LISTS_EQ(processed, expected);
66  g_strfreev(processed);
67 }
68 
69 static void
70 special_arg_at_end(void) {
71  const char *argv[] = { "-a", NULL };
72  const gchar *expected[] = { "-a", NULL };
73 
74  gchar **processed = pcmk__cmdline_preproc((char **) argv, "a");
75  LISTS_EQ(processed, expected);
76  g_strfreev(processed);
77 }
78 
79 static void
80 long_arg(void) {
81  const char *argv[] = { "--blah=foo", NULL };
82  const gchar *expected[] = { "--blah=foo", NULL };
83 
84  gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
85  LISTS_EQ(processed, expected);
86  g_strfreev(processed);
87 }
88 
89 int
90 main(int argc, char **argv)
91 {
92  g_test_init(&argc, &argv, NULL);
93 
94  g_test_add_func("/common/cmdline/preproc/empty_input", empty_input);
95  g_test_add_func("/common/cmdline/preproc/no_specials", no_specials);
96  g_test_add_func("/common/cmdline/preproc/single_dash", single_dash);
97  g_test_add_func("/common/cmdline/preproc/double_dash", double_dash);
98  g_test_add_func("/common/cmdline/preproc/special_args", special_args);
99  g_test_add_func("/common/cmdline/preproc/special_arg_at_end", special_arg_at_end);
100  g_test_add_func("/common/cmdline/preproc/long_arg", long_arg);
101  return g_test_run();
102 }
#define LISTS_EQ(a, b)
gchar ** pcmk__cmdline_preproc(char **argv, const char *special)
Definition: cmdline.c:145
int main(int argc, char **argv)