4 #define DBUS_COMPILATION
5 #include <dbus/dbus-internals.h>
6 #include <dbus/dbus-list.h>
7 #include <dbus/dbus-memory.h>
8 #include <dbus/dbus-shell.h>
9 #include <dbus/dbus-string.h>
10 #include <dbus/dbus-sysdeps.h>
13 test_command_line (const char *arg1, ...)
15 int i, original_argc, shell_argc;
18 char *command_line, *tmp;
20 DBusList *list = NULL, *node;
24 va_start (var_args, arg1);
25 _dbus_list_append (&list, (char *)arg1);
28 tmp = va_arg (var_args, char *);
31 _dbus_list_append (&list, tmp);
35 original_argc = _dbus_list_get_length (&list);
36 original_argv = dbus_new (char *, original_argc);
37 _dbus_string_init (&str);
38 for (i = 0, node = _dbus_list_get_first_link (&list); i < original_argc && node;
39 i++, node = _dbus_list_get_next_link (&list, node))
41 original_argv[i] = node->data;
43 _dbus_string_append_byte (&str, ' ');
44 _dbus_string_append (&str, original_argv[i]);
47 _dbus_list_clear (&list);
48 command_line = _dbus_string_get_data (&str);
49 printf ("\n\nTesting command line '%s'\n", command_line);
51 dbus_error_init (&error);
52 if (!_dbus_shell_parse_argv (command_line, &shell_argc, &shell_argv, &error))
54 fprintf (stderr, "Error parsing command line: %s\n", error.message ? error.message : "");
59 if (shell_argc != original_argc)
61 printf ("Number of arguments returned (%d) don't match original (%d)\n",
62 shell_argc, original_argc);
65 printf ("Number of arguments: %d\n", shell_argc);
66 for (i = 0; i < shell_argc; i++)
70 unquoted = _dbus_shell_unquote (original_argv[i]);
71 if (strcmp (unquoted ? unquoted : "",
72 shell_argv[i] ? shell_argv[i] : ""))
74 printf ("Position %d, returned argument (%s) does not match original (%s)\n",
75 i, shell_argv[i], unquoted);
81 printf ("Argument %d = %s\n", i, shell_argv[i]);
84 dbus_free_string_array (shell_argv);
87 _dbus_string_free (&str);
93 main (int argc, char **argv)
95 if (!test_command_line ("command", "-s", "--force-shutdown", "\"a string\"", "123", NULL)
96 || !test_command_line ("command", "-s", NULL)
97 || !test_command_line ("/opt/gnome/bin/service-start", NULL)
98 || !test_command_line ("grep", "-l", "-r", "-i", "'whatever'", "files*.c", NULL)
99 || !test_command_line ("/home/boston/johnp/devel-local/dbus/test/test-segfault", NULL)
100 || !test_command_line ("ls", "-l", "-a", "--colors", _dbus_get_tmpdir(), NULL)
101 || !test_command_line ("rsync-to-server", NULL)
102 || !test_command_line ("test-segfault", "--no-segfault", NULL)
103 || !test_command_line ("evolution", "mailto:pepe@cuco.com", NULL)
104 || !test_command_line ("run", "\"a \n multiline\"", NULL)
105 || test_command_line ("ls", "\"a wrong string'", NULL) /* invalid command line */ )