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", 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", 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");
102 ret
= g_shell_parse_argv ("hola \"bola\"", &argc
, &argv
, &error
);
104 return FAILED ("1. It should return TRUE");
106 return FAILED ("2. argc was %d", argc
);
107 if (strcmp (argv
[0], "hola"))
108 return FAILED ("3. argv[0] was %s", argv
[0]);
109 if (strcmp (argv
[1], "bola"))
110 return FAILED ("4. argv[1] was %s", argv
[1]);
112 return FAILED ("5. error is not null");
118 ret
= g_shell_parse_argv ("hola \"\" \"bola \"", &argc
, &argv
, &error
);
120 return FAILED ("6. It should return TRUE");
122 return FAILED ("7. argc was %d", argc
);
123 if (strcmp (argv
[0], "hola"))
124 return FAILED ("8. argv[0] was %s", argv
[0]);
125 if (strcmp (argv
[1], ""))
126 return FAILED ("9. argv[2] was %s", argv
[1]);
127 if (strcmp (argv
[2], "bola "))
128 return FAILED ("10. argv[2] was %s", argv
[2]);
130 return FAILED ("11. error is not null");
136 ret
= g_shell_parse_argv ("hola\n\t \"\t\" \"bola \"", &argc
, &argv
, &error
);
138 return FAILED ("10. It should return TRUE");
140 return FAILED ("11. argc was %d", argc
);
141 if (strcmp (argv
[0], "hola"))
142 return FAILED ("12. argv[0] was %s", argv
[0]);
143 if (strcmp (argv
[1], "\t"))
144 return FAILED ("13. argv[2] was %s", argv
[1]);
145 if (strcmp (argv
[2], "bola "))
146 return FAILED ("14. argv[2] was %s", argv
[2]);
148 return FAILED ("15. error is not null");
154 ret
= g_shell_parse_argv ("hola\n\t \\\n \"\t\" \"bola \"", &argc
, &argv
, &error
);
156 return FAILED ("16. It should return TRUE");
158 return FAILED ("17. argc was %d", argc
);
159 if (strcmp (argv
[0], "hola"))
160 return FAILED ("18. argv[0] was %s", argv
[0]);
161 if (strcmp (argv
[1], "\t"))
162 return FAILED ("19. argv[2] was %s", argv
[1]);
163 if (strcmp (argv
[2], "bola "))
164 return FAILED ("20. argv[2] was %s", argv
[2]);
166 return FAILED ("21. error is not null");
183 ret
= g_shell_parse_argv ("hola \"bola", &argc
, &argv
, &error
);
185 return FAILED ("1. It should return FALSE");
187 return FAILED ("2. argc was %d", argc
);
189 return FAILED ("3. argv[0] was %s", argv
[0]);
191 return FAILED ("4. error is null");
193 /* Text ended before matching quote was found for ". (The text was 'hola "bola') */
194 g_error_free (error
);
196 ret
= g_shell_parse_argv ("hola \\\"bola", &argc
, &argv
, &error
);
198 return FAILED ("5. It should return TRUE");
200 return FAILED ("6. argc was %d", argc
);
201 if (strcmp (argv
[0], "hola"))
202 return FAILED ("18. argv[0] was %s", argv
[0]);
203 if (strcmp (argv
[1], "\"bola"))
204 return FAILED ("18. argv[1] was %s", argv
[1]);
206 return FAILED ("8. error is not null");
211 ret
= g_shell_parse_argv ("hola \"\n\\'bola\"", &argc
, &argv
, &error
);
213 return FAILED ("9. It should return TRUE. %s", error
->message
);
215 return FAILED ("10. argc was %d", argc
);
216 if (strcmp (argv
[0], "hola"))
217 return FAILED ("11. argv[0] was %s", argv
[0]);
218 if (strcmp (argv
[1], "\n\\'bola"))
219 return FAILED ("12. argv[1] was %s", argv
[1]);
221 return FAILED ("13. error is not null");
229 // This was the 2.8 showstopper error
237 char *str
= "'/usr/bin/gnome-terminal' -e \"bash -c 'read -p \\\"Press any key to continue...\\\" -n1;'\"";
242 ret
= g_shell_parse_argv (str
, &argc
, &argv
, &error
);
244 return FAILED ("1. It should return TRUE");
246 return FAILED ("2. argc was %d", argc
);
248 return FAILED ("3. argv[0] was NULL");
250 return FAILED ("4. error was set");
252 if (strcmp (argv
[0], "/usr/bin/gnome-terminal"))
253 return FAILED ("5. Expected /usr/bin/gnome-terminal got %s", argv
[0]);
254 if (strcmp (argv
[1], "-e"))
255 return FAILED ("6. Expected -e, got: %s", argv
[1]);
256 if (strcmp (argv
[2], "bash -c 'read -p \"Press any key to continue...\" -n1;'"))
257 return FAILED ("7. Got unexpected result: %s\n", argv
[2]);
265 if (strcmp (g_shell_quote ("foo"), "'foo'"))
266 return FAILED ("Should return 'foo'");
268 if (strcmp (g_shell_quote ("foo'bar"), "'foo'\\''bar'"))
269 return FAILED ("Should return 'foo'\\''bar'");
271 if (strcmp (g_shell_quote ("foo bar"), "'foo bar'"))
272 return FAILED ("Should return 'foo bar'");
276 static Test shell_tests
[] = {
277 {"g_shell_parse_argv1", test_shell_argv1
},
278 {"g_shell_parse_argv2", test_shell_argv2
},
279 {"g_shell_parse_argv3", test_shell_argv3
},
280 {"g_shell_parse_argv4", test_shell_argv4
},
281 {"g_shell_quote", test_quote
},
285 DEFINE_TEST_GROUP_INIT(shell_tests_init
, shell_tests
)