11/*
2- * Copyright 2020-2023 the Pacemaker project contributors
2+ * Copyright 2020-2026 the Pacemaker project contributors
33 *
44 * The version control history for this file may have further details.
55 *
1414#include <glib.h>
1515#include <stdint.h>
1616
17+ // @COMPAT Consider replacing with g_strv_equal() when we require GLib 2.60
1718#define LISTS_EQ (a , b ) { \
18- assert_int_equal(g_strv_length((gchar **) (a)), g_strv_length((gchar **) (b))); \
19+ assert_int_equal(g_strv_length((char **) (a)), \
20+ g_strv_length((char **) (b))); \
1921 for (int i = 0; i < g_strv_length((a)); i++) { \
2022 assert_string_equal((a)[i], (b)[i]); \
2123 } \
@@ -27,9 +29,10 @@ empty_input(void **state) {
2729}
2830
2931static void
30- no_specials (void * * state ) {
32+ no_specials (void * * state )
33+ {
3134 const char * argv [] = { "crm_mon" , "-a" , "-b" , "-c" , "-d" , "-1" , NULL };
32- const gchar * expected [] = { "crm_mon" , "-a" , "-b" , "-c" , "-d" , "-1" , NULL };
35+ const char * expected [] = { "crm_mon" , "-a" , "-b" , "-c" , "-d" , "-1" , NULL };
3336
3437 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , NULL );
3538 LISTS_EQ (processed , expected );
@@ -41,109 +44,124 @@ no_specials(void **state) {
4144}
4245
4346static void
44- single_dash (void * * state ) {
47+ single_dash (void * * state )
48+ {
4549 const char * argv [] = { "crm_mon" , "-" , NULL };
46- const gchar * expected [] = { "crm_mon" , "-" , NULL };
50+ const char * expected [] = { "crm_mon" , "-" , NULL };
4751
4852 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , NULL );
4953 LISTS_EQ (processed , expected );
5054 g_strfreev (processed );
5155}
5256
5357static void
54- double_dash (void * * state ) {
58+ double_dash (void * * state )
59+ {
5560 const char * argv [] = { "crm_mon" , "-a" , "--" , "-bc" , NULL };
56- const gchar * expected [] = { "crm_mon" , "-a" , "--" , "-bc" , NULL };
61+ const char * expected [] = { "crm_mon" , "-a" , "--" , "-bc" , NULL };
5762
5863 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , NULL );
5964 LISTS_EQ (processed , expected );
6065 g_strfreev (processed );
6166}
6267
6368static void
64- special_args (void * * state ) {
69+ special_args (void * * state )
70+ {
6571 const char * argv [] = { "crm_mon" , "-aX" , "-Fval" , NULL };
66- const gchar * expected [] = { "crm_mon" , "-a" , "X" , "-F" , "val" , NULL };
72+ const char * expected [] = { "crm_mon" , "-a" , "X" , "-F" , "val" , NULL };
6773
6874 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , "aF" );
6975 LISTS_EQ (processed , expected );
7076 g_strfreev (processed );
7177}
7278
7379static void
74- special_arg_at_end (void * * state ) {
80+ special_arg_at_end (void * * state )
81+ {
7582 const char * argv [] = { "crm_mon" , "-a" , NULL };
76- const gchar * expected [] = { "crm_mon" , "-a" , NULL };
83+ const char * expected [] = { "crm_mon" , "-a" , NULL };
7784
7885 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , "a" );
7986 LISTS_EQ (processed , expected );
8087 g_strfreev (processed );
8188}
8289
8390static void
84- long_arg (void * * state ) {
91+ long_arg (void * * state )
92+ {
8593 const char * argv [] = { "crm_mon" , "--blah=foo" , NULL };
86- const gchar * expected [] = { "crm_mon" , "--blah=foo" , NULL };
94+ const char * expected [] = { "crm_mon" , "--blah=foo" , NULL };
8795
8896 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , NULL );
8997 LISTS_EQ (processed , expected );
9098 g_strfreev (processed );
9199}
92100
93101static void
94- negative_score (void * * state ) {
102+ negative_score (void * * state )
103+ {
95104 const char * argv [] = { "crm_mon" , "-v" , "-1000" , NULL };
96- const gchar * expected [] = { "crm_mon" , "-v" , "-1000" , NULL };
105+ const char * expected [] = { "crm_mon" , "-v" , "-1000" , NULL };
97106
98107 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , "v" );
99108 LISTS_EQ (processed , expected );
100109 g_strfreev (processed );
101110}
102111
103112static void
104- negative_score_2 (void * * state ) {
113+ negative_score_2 (void * * state )
114+ {
105115 const char * argv [] = { "crm_mon" , "-1i3" , NULL };
106- const gchar * expected [] = { "crm_mon" , "-1" , "-i" , "-3" , NULL };
116+ const char * expected [] = { "crm_mon" , "-1" , "-i" , "-3" , NULL };
107117
108118 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , NULL );
109119 LISTS_EQ (processed , expected );
110120 g_strfreev (processed );
111121}
112122
113123static void
114- negative_score_3 (void * * state ) {
124+ negative_score_3 (void * * state )
125+ {
115126 const char * argv [] = { "crm_attribute" , "-p" , "-v" , "-INFINITY" , NULL };
116- const gchar * expected [] = { "crm_attribute" , "-p" , "-v" , "-INFINITY" , NULL };
127+ const char * expected [] = { "crm_attribute" , "-p" , "-v" , "-INFINITY" , NULL };
117128
118129 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , "pv" );
119130 LISTS_EQ (processed , expected );
120131 g_strfreev (processed );
121132}
122133
123134static void
124- string_arg_with_dash (void * * state ) {
125- const char * argv [] = { "crm_mon" , "-n" , "crm_mon_options" , "-v" , "--opt1 --opt2" , NULL };
126- const gchar * expected [] = { "crm_mon" , "-n" , "crm_mon_options" , "-v" , "--opt1 --opt2" , NULL };
135+ string_arg_with_dash (void * * state )
136+ {
137+ const char * argv [] = { "crm_mon" , "-n" , "crm_mon_options" , "-v" ,
138+ "--opt1 --opt2" , NULL };
139+ const char * expected [] = { "crm_mon" , "-n" , "crm_mon_options" , "-v" ,
140+ "--opt1 --opt2" , NULL };
127141
128142 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , "v" );
129143 LISTS_EQ (processed , expected );
130144 g_strfreev (processed );
131145}
132146
133147static void
134- string_arg_with_dash_2 (void * * state ) {
135- const char * argv [] = { "crm_mon" , "-n" , "crm_mon_options" , "-v" , "-1i3" , NULL };
136- const gchar * expected [] = { "crm_mon" , "-n" , "crm_mon_options" , "-v" , "-1i3" , NULL };
148+ string_arg_with_dash_2 (void * * state )
149+ {
150+ const char * argv [] = { "crm_mon" , "-n" , "crm_mon_options" , "-v" , "-1i3" ,
151+ NULL };
152+ const char * expected [] = { "crm_mon" , "-n" , "crm_mon_options" , "-v" , "-1i3" ,
153+ NULL };
137154
138155 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , "v" );
139156 LISTS_EQ (processed , expected );
140157 g_strfreev (processed );
141158}
142159
143160static void
144- string_arg_with_dash_3 (void * * state ) {
161+ string_arg_with_dash_3 (void * * state )
162+ {
145163 const char * argv [] = { "crm_mon" , "-abc" , "-1i3" , NULL };
146- const gchar * expected [] = { "crm_mon" , "-a" , "-b" , "-c" , "-1i3" , NULL };
164+ const char * expected [] = { "crm_mon" , "-a" , "-b" , "-c" , "-1i3" , NULL };
147165
148166 gchar * * processed = pcmk__cmdline_preproc ((char * * ) argv , "c" );
149167 LISTS_EQ (processed , expected );
0 commit comments