3 #define DBUS_COMPILATION
4 #include <dbus/dbus-internals.h>
5 #include <dbus/dbus-list.h>
6 #include <dbus/dbus-memory.h>
7 #include <dbus/dbus-shell.h>
8 #include <dbus/dbus-string.h>
11 test_command_line (const char *arg1, ...)
13 int i, original_argc, shell_argc;
16 char *command_line, *tmp;
18 DBusList *list = NULL, *node;
22 va_start (var_args, arg1);
23 _dbus_list_append (&list, arg1);
26 tmp = va_arg (var_args, char *);
29 _dbus_list_append (&list, tmp);
33 original_argc = _dbus_list_get_length (&list);
34 original_argv = dbus_new (char *, original_argc);
35 _dbus_string_init (&str);
36 for (i = 0, node = _dbus_list_get_first_link (&list); i < original_argc && node;
37 i++, node = _dbus_list_get_next_link (&list, node))
39 original_argv[i] = node->data;
41 _dbus_string_append_byte (&str, ' ');
42 _dbus_string_append (&str, original_argv[i]);
45 _dbus_list_clear (&list);
46 command_line = _dbus_string_get_data (&str);
47 printf ("\n\nTesting command line '%s'\n", command_line);
49 dbus_error_init (&error);
50 if (!_dbus_shell_parse_argv (command_line, &shell_argc, &shell_argv, &error))
52 fprintf (stderr, "Error parsing command line: %s\n", error.message ? error.message : "");
57 if (shell_argc != original_argc)
59 printf ("Number of arguments returned (%d) don't match original (%d)\n",
60 shell_argc, original_argc);
63 printf ("Number of arguments: %d\n", shell_argc);
64 for (i = 0; i < shell_argc; i++)
68 unquoted = _dbus_shell_unquote (original_argv[i]);
69 if (strcmp (unquoted ? unquoted : "",
70 shell_argv[i] ? shell_argv[i] : ""))
72 printf ("Position %d, returned argument (%s) does not match original (%s)\n",
73 i, shell_argv[i], unquoted);
79 printf ("Argument %d = %s\n", i, shell_argv[i]);
82 dbus_free_string_array (shell_argv);
85 _dbus_string_free (&str);
91 main (int argc, char **argv)
93 if (!test_command_line ("command", "-s", "--force-shutdown", "\"a string\"", "123", NULL)
94 || !test_command_line ("command", "-s", NULL)
95 || !test_command_line ("/opt/gnome/bin/service-start", NULL)
96 || !test_command_line ("grep", "-l", "-r", "-i", "'whatever'", "files*.c", NULL)
97 || !test_command_line ("/home/boston/johnp/devel-local/dbus/test/test-segfault", NULL)
98 || !test_command_line ("ls", "-l", "-a", "--colors", "/tmp", NULL)
99 || !test_command_line ("rsync-to-server", NULL)
100 || !test_command_line ("test-segfault", "--no-segfault", NULL)
101 || !test_command_line ("evolution", "mailto:pepe@cuco.com", NULL)
102 || !test_command_line ("run", "\"a \n multiline\"", NULL)
103 || test_command_line ("ls", "\"a wrong string'", NULL) /* invalid command line */ )