14 /* The next line prints a critical error and returns FALSE
15 ret = g_shell_parse_argv (NULL, NULL, NULL, NULL);
17 ret
= g_shell_parse_argv ("", NULL
, NULL
, NULL
);
19 return FAILED ("1. It should return FALSE");
21 ret
= g_shell_parse_argv ("hola", NULL
, NULL
, NULL
);
23 return FAILED ("2. It should return TRUE");
26 ret
= g_shell_parse_argv ("hola", &argc
, NULL
, NULL
);
28 return FAILED ("3. It should return TRUE");
30 return FAILED ("4. argc was %d", argc
);
33 ret
= g_shell_parse_argv ("hola bola", &argc
, NULL
, NULL
);
35 return FAILED ("5. It should return TRUE");
37 return FAILED ("6. argc was %d", argc
);
40 ret
= g_shell_parse_argv ("hola bola", &argc
, &argv
, NULL
);
42 return FAILED ("7. It should return TRUE");
44 return FAILED ("8. argc was %d", argc
);
45 if (strcmp (argv
[0], "hola"))
46 return FAILED ("9. argv[0] was %s", argv
[0]);
47 if (strcmp (argv
[1], "bola"))
48 return FAILED ("10. argv[1] was %s", argv
[1]);
54 ret
= g_shell_parse_argv ("hola 'bola'", &argc
, &argv
, &error
);
56 return FAILED ("11. It should return TRUE");
58 return FAILED ("12. argc was %d expected 2", argc
);
59 if (strcmp (argv
[0], "hola"))
60 return FAILED ("13. argv[0] was %s", argv
[0]);
61 if (strcmp (argv
[1], "bola"))
62 return FAILED ("14. argv[1] was %s", argv
[1]);
64 return FAILED ("15. error is not null");
71 ret
= g_shell_parse_argv ("hola '' 'bola'", &argc
, &argv
, &error
);
73 return FAILED ("16. It should return TRUE");
75 return FAILED ("17. argc was %d expected 3", argc
);
76 if (strcmp (argv
[0], "hola"))
77 return FAILED ("18. argv[0] was %s", argv
[0]);
78 if (strcmp (argv
[1], ""))
79 return FAILED ("19. argv[2] was %s", argv
[1]);
80 if (strcmp (argv
[2], "bola"))
81 return FAILED ("19. argv[2] was %s", argv
[2]);
83 return FAILED ("20. error is not null");
89 ret
= g_shell_parse_argv ("hola'' bola", &argc
, &argv
, &error
);
91 return FAILED ("21. It should return TRUE");
93 return FAILED ("22. argc was %d expected 2", argc
);
94 if (strcmp (argv
[0], "hola"))
95 return FAILED ("23. argv[0] was %s", argv
[0]);
96 if (strcmp (argv
[1], "bola"))
97 return FAILED ("24. argv[2] was %s", argv
[1]);
99 return FAILED ("25. error is not null");
115 ret
= g_shell_parse_argv ("hola \"bola\"", &argc
, &argv
, &error
);
117 return FAILED ("1. It should return TRUE");
119 return FAILED ("2. argc was %d expected 2", argc
);
120 if (strcmp (argv
[0], "hola"))
121 return FAILED ("3. argv[0] was %s", argv
[0]);
122 if (strcmp (argv
[1], "bola"))
123 return FAILED ("4. argv[1] was %s", argv
[1]);
125 return FAILED ("5. error is not null");
131 ret
= g_shell_parse_argv ("hola \"\" \"bola \"", &argc
, &argv
, &error
);
133 return FAILED ("6. It should return TRUE");
135 return FAILED ("7. argc was %d expected 3", argc
);
136 if (strcmp (argv
[0], "hola"))
137 return FAILED ("8. argv[0] was %s", argv
[0]);
138 if (strcmp (argv
[1], ""))
139 return FAILED ("9. argv[2] was %s", argv
[1]);
140 if (strcmp (argv
[2], "bola "))
141 return FAILED ("10. argv[2] was %s", argv
[2]);
143 return FAILED ("11. error is not null");
149 ret
= g_shell_parse_argv ("hola\n\t \"\t\" \"bola \"", &argc
, &argv
, &error
);
151 return FAILED ("10. It should return TRUE");
153 return FAILED ("11. argc was %d expected 3", argc
);
154 if (strcmp (argv
[0], "hola"))
155 return FAILED ("12. argv[0] was %s", argv
[0]);
156 if (strcmp (argv
[1], "\t"))
157 return FAILED ("13. argv[2] was %s", argv
[1]);
158 if (strcmp (argv
[2], "bola "))
159 return FAILED ("14. argv[2] was %s", argv
[2]);
161 return FAILED ("15. error is not null");
167 ret
= g_shell_parse_argv ("hola\n\t \\\n \"\t\" \"bola \"", &argc
, &argv
, &error
);
169 return FAILED ("16. It should return TRUE");
171 return FAILED ("17. argc was %d expected 3", argc
);
172 if (strcmp (argv
[0], "hola"))
173 return FAILED ("18. argv[0] was %s", argv
[0]);
174 if (strcmp (argv
[1], "\t"))
175 return FAILED ("19. argv[2] was %s", argv
[1]);
176 if (strcmp (argv
[2], "bola "))
177 return FAILED ("20. argv[2] was %s", argv
[2]);
179 return FAILED ("21. error is not null");
196 ret
= g_shell_parse_argv ("hola \"bola", &argc
, &argv
, &error
);
198 return FAILED ("1. It should return FALSE");
200 return FAILED ("2. argc was %d expected 0", argc
);
202 return FAILED ("3. argv[0] was %s", argv
[0]);
204 return FAILED ("4. error is null");
206 /* Text ended before matching quote was found for ". (The text was 'hola "bola') */
207 g_error_free (error
);
209 ret
= g_shell_parse_argv ("hola \\\"bola", &argc
, &argv
, &error
);
211 return FAILED ("5. It should return TRUE");
213 return FAILED ("6. argc was %d expected 2", argc
);
214 if (strcmp (argv
[0], "hola"))
215 return FAILED ("18. argv[0] was %s", argv
[0]);
216 if (strcmp (argv
[1], "\"bola"))
217 return FAILED ("18. argv[1] was %s", argv
[1]);
219 return FAILED ("8. error is not null");
224 ret
= g_shell_parse_argv ("hola \"\n\\'bola\"", &argc
, &argv
, &error
);
226 return FAILED ("9. It should return TRUE. %s", error
->message
);
228 return FAILED ("10. argc was %d expected 2", argc
);
229 if (strcmp (argv
[0], "hola"))
230 return FAILED ("11. argv[0] was %s", argv
[0]);
231 if (strcmp (argv
[1], "\n\\'bola"))
232 return FAILED ("12. argv[1] was %s", argv
[1]);
234 return FAILED ("13. error is not null");
242 // This was the 2.8 showstopper error
250 char *str
= "'/usr/bin/gnome-terminal' -e \"bash -c 'read -p \\\"Press any key to continue...\\\" -n1;'\"";
255 ret
= g_shell_parse_argv (str
, &argc
, &argv
, &error
);
257 return FAILED ("1. It should return TRUE");
259 return FAILED ("2. argc was %d expected 3", argc
);
261 return FAILED ("3. argv[0] was NULL");
263 return FAILED ("4. error was set");
265 if (strcmp (argv
[0], "/usr/bin/gnome-terminal"))
266 return FAILED ("5. Expected /usr/bin/gnome-terminal got %s", argv
[0]);
267 if (strcmp (argv
[1], "-e"))
268 return FAILED ("6. Expected -e, got: %s", argv
[1]);
269 if (strcmp (argv
[2], "bash -c 'read -p \"Press any key to continue...\" -n1;'"))
270 return FAILED ("7. Got unexpected result: %s\n", argv
[2]);
275 // This is https://bugzilla.novell.com/show_bug.cgi?id=655896
283 char *str
= "echo \"foo\",\"bar\"";
288 ret
= g_shell_parse_argv (str
, &argc
, &argv
, &error
);
290 return FAILED ("1. It should return TRUE");
292 return FAILED ("2. argc was %d expected 2", argc
);
294 return FAILED ("3. argv[0] was NULL");
296 return FAILED ("4. error was set");
298 if (strcmp (argv
[0], "echo"))
299 return FAILED ("5. Expected echo got %s", argv
[0]);
300 if (strcmp (argv
[1], "foo,bar"))
301 return FAILED ("6. Expected foo,bar, got: %s", argv
[1]);
309 if (strcmp (g_shell_quote ("foo"), "'foo'"))
310 return FAILED ("Should return 'foo'");
312 if (strcmp (g_shell_quote ("foo'bar"), "'foo'\\''bar'"))
313 return FAILED ("Should return 'foo'\\''bar'");
315 if (strcmp (g_shell_quote ("foo bar"), "'foo bar'"))
316 return FAILED ("Should return 'foo bar'");
320 static Test shell_tests
[] = {
321 {"test_shell_argv1", test_shell_argv1
},
322 {"test_shell_argv2", test_shell_argv2
},
323 {"test_shell_argv3", test_shell_argv3
},
324 {"test_shell_argv4", test_shell_argv4
},
325 {"test_shell_argv5", test_shell_argv5
},
326 {"g_shell_quote", test_quote
},
330 DEFINE_TEST_GROUP_INIT(shell_tests_init
, shell_tests
)