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");
232 if (strcmp (g_shell_quote ("foo"), "'foo'"))
233 return FAILED ("Should return 'foo'");
235 if (strcmp (g_shell_quote ("foo'bar"), "'foo'\\''bar'"))
236 return FAILED ("Should return 'foo'\\''bar'");
238 if (strcmp (g_shell_quote ("foo bar"), "'foo bar'"))
239 return FAILED ("Should return 'foo bar'");
243 static Test shell_tests
[] = {
244 {"g_shell_parse_argv1", test_shell_argv1
},
245 {"g_shell_parse_argv2", test_shell_argv2
},
246 {"g_shell_parse_argv3", test_shell_argv3
},
247 {"g_shell_quote", test_quote
},
251 DEFINE_TEST_GROUP_INIT(shell_tests_init
, shell_tests
)