/* 9 */ "foo \\\" la la la",
/* 10 */ "foo \\ foo woo woo\\ ",
/* 11 */ "foo \"yada yada \\$\\\"\"",
+ /* 12 */ "foo \"c:\\\\\"",
NULL
};
static const gchar *result9[] = { "foo", "\"", "la", "la", "la", NULL };
static const gchar *result10[] = { "foo", " foo", "woo", "woo ", NULL };
static const gchar *result11[] = { "foo", "yada yada $\"", NULL };
+static const gchar *result12[] = { "foo", "c:\\", NULL };
static const TestResult
correct_results[] =
{ G_N_ELEMENTS (result8) - 1, result8 },
{ G_N_ELEMENTS (result9) - 1, result9 },
{ G_N_ELEMENTS (result10) - 1, result10 },
- { G_N_ELEMENTS (result11) - 1, result11 }
+ { G_N_ELEMENTS (result11) - 1, result11 },
+ { G_N_ELEMENTS (result12) - 1, result12 }
};
static void
{
gint i;
- printf ("\nCommand line was: '%s'\n", cmdline);
+ fprintf (stderr, "Command line was: '%s'\n", cmdline);
- printf ("Expected result (%d args):\n", result->argc);
+ fprintf (stderr, "Expected result (%d args):\n", result->argc);
i = 0;
while (result->argv[i])
{
- printf (" %3d '%s'\n", i, result->argv[i]);
-
+ fprintf (stderr, " %3d '%s'\n", i, result->argv[i]);
++i;
}
- printf ("Actual result (%d args):\n", argc);
+ fprintf (stderr, "Actual result (%d args):\n", argc);
i = 0;
while (argv[i])
{
- printf (" %3d '%s'\n", i, argv[i]);
-
+ fprintf (stderr, " %3d '%s'\n", i, argv[i]);
++i;
}
}
fprintf (stderr, "argv didn't get NULL-terminated\n");
exit (1);
}
+ g_strfreev (argv);
}
static void
i = 0;
while (test_command_lines[i])
{
- printf ("g_shell_parse_argv() test %d - ", i);
do_argv_test (test_command_lines[i], &correct_results[i]);
- printf ("ok (%s)\n", test_command_lines[i]);
-
++i;
}
}
char *result,
const char *expected)
{
- gboolean match;
-
- if (expected == NULL)
- match = result == NULL;
- else
- match = result != NULL && strcmp (result, expected) == 0;
-
- if (!match)
- {
- if (!any_test_failed)
- fprintf (stderr, "\n");
-
- fprintf (stderr, "FAIL: check failed in %s, line %d\n", file_name, line_number);
- fprintf (stderr, " evaluated: %s\n", expression);
- fprintf (stderr, " expected: %s\n", expected == NULL ? "NULL" : expected);
- fprintf (stderr, " got: %s\n", result == NULL ? "NULL" : result);
-
- any_test_failed = TRUE;
- }
-
- g_free (result);
+ gboolean match;
+
+ if (expected == NULL)
+ match = result == NULL;
+ else
+ match = result != NULL && strcmp (result, expected) == 0;
+
+ if (!match)
+ {
+ if (!any_test_failed)
+ fprintf (stderr, "\n");
+
+ fprintf (stderr, "FAIL: check failed in %s, line %d\n", file_name, line_number);
+ fprintf (stderr, " evaluated: %s\n", expression);
+ fprintf (stderr, " expected: %s\n", expected == NULL ? "NULL" : expected);
+ fprintf (stderr, " got: %s\n", result == NULL ? "NULL" : result);
+
+ any_test_failed = TRUE;
+ }
+
+ g_free (result);
}
static char *
if (error == NULL)
return result;
- /* Leaks the error, which is no big deal. */
+ /* Leaks the error, which is no big deal and easy to fix if we
+ * decide it matters.
+ */
if (error->domain != G_SHELL_ERROR)
return g_strdup ("error in domain other than G_SHELL_ERROR");
CHECK_STRING_RESULT (test_shell_unquote ("\\\n"), "");
CHECK_STRING_RESULT (test_shell_unquote ("'\\''"), "G_SHELL_ERROR_BAD_QUOTING");
+
+#if defined (_MSC_VER) && (_MSC_VER <= 1200)
+ /* using \x22 instead of \" to work around a msvc 5.0, 6.0 compiler bug */
+ CHECK_STRING_RESULT (test_shell_unquote ("\x22\\\x22\""), "\"");
+#else
CHECK_STRING_RESULT (test_shell_unquote ("\"\\\"\""), "\"");
+#endif
CHECK_STRING_RESULT (test_shell_unquote ("\""), "G_SHELL_ERROR_BAD_QUOTING");
CHECK_STRING_RESULT (test_shell_unquote ("'"), "G_SHELL_ERROR_BAD_QUOTING");
- CHECK_STRING_RESULT (test_shell_unquote ("\"\\\\\""), "\\");
- CHECK_STRING_RESULT (test_shell_unquote ("\"\\`\""), "`");
- CHECK_STRING_RESULT (test_shell_unquote ("\"\\$\""), "$");
- CHECK_STRING_RESULT (test_shell_unquote ("\"\\\n\""), "\n");
+ CHECK_STRING_RESULT (test_shell_unquote ("\x22\\\\\""), "\\");
+ CHECK_STRING_RESULT (test_shell_unquote ("\x22\\`\""), "`");
+ CHECK_STRING_RESULT (test_shell_unquote ("\x22\\$\""), "$");
+ CHECK_STRING_RESULT (test_shell_unquote ("\x22\\\n\""), "\n");
CHECK_STRING_RESULT (test_shell_unquote ("\"\\'\""), "\\'");
- CHECK_STRING_RESULT (test_shell_unquote ("\"\\\r\""), "\\\r");
- CHECK_STRING_RESULT (test_shell_unquote ("\"\\n\""), "\\n");
+ CHECK_STRING_RESULT (test_shell_unquote ("\x22\\\r\""), "\\\r");
+ CHECK_STRING_RESULT (test_shell_unquote ("\x22\\n\""), "\\n");
return any_test_failed ? 1 : 0;
}