From 075945f611290f2b9db9a4ed6cf5433f2fd85785 Mon Sep 17 00:00:00 2001 From: "John (J5) Palmieri" Date: Thu, 14 Jul 2005 20:44:15 +0000 Subject: Checking in Rodrigo's patch along with my fixes to the patch 2005-07-14 John (J5) Palmieri * bus/activation.c: clean up all tabs to be 8 spaces (bus_activation_activate_service): make sure we clean up if activation fails * bus/dispatch.c: clean up all tabs to be 8 spaces (check_shell_fail_service_auto_start): New function tests to make sure we get fail properly when trying to auto start a service with a faulty command line (check_shell_service_success_auto_start): New function tests to make sure auto started services get the arguments on the command line * test/test-shell-service.c: Added service for testing auto-starting with command line arguments * test/data/valid-service-files/debug-shell-echo-fail.service.in, test/data/valid-service-files/debug-shell-echo-success.service.in: Added service files for testing auto-starting with command line arguments * */.cvsignore: added a bunch of generated files to various .cvsignore files 2005-07-14 Rodrigo Moya * dbus/dbus-shell.[ch]: copy/pasted code from GLib. * dbus/Makefile.am: added new files to build. * bus/activation.c (bus_activation_activate_service): support activation commands with parameters. * test/shell-test.c: added test program for the shell parsing code. --- test/shell-test.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 test/shell-test.c (limited to 'test/shell-test.c') diff --git a/test/shell-test.c b/test/shell-test.c new file mode 100644 index 00000000..46a387d7 --- /dev/null +++ b/test/shell-test.c @@ -0,0 +1,107 @@ +#include +#include +#define DBUS_COMPILATION +#include +#include +#include +#include +#include + +static dbus_bool_t +test_command_line (const char *arg1, ...) +{ + int i, original_argc, shell_argc; + char **shell_argv; + char **original_argv; + char *command_line, *tmp; + DBusString str; + DBusList *list = NULL, *node; + va_list var_args; + DBusError error; + + va_start (var_args, arg1); + _dbus_list_append (&list, arg1); + do + { + tmp = va_arg (var_args, char *); + if (!tmp) + break; + _dbus_list_append (&list, tmp); + } while (tmp); + va_end (var_args); + + original_argc = _dbus_list_get_length (&list); + original_argv = dbus_new (char *, original_argc); + _dbus_string_init (&str); + for (i = 0, node = _dbus_list_get_first_link (&list); i < original_argc && node; + i++, node = _dbus_list_get_next_link (&list, node)) + { + original_argv[i] = node->data; + if (i > 0) + _dbus_string_append_byte (&str, ' '); + _dbus_string_append (&str, original_argv[i]); + } + + _dbus_list_clear (&list); + command_line = _dbus_string_get_data (&str); + printf ("\n\nTesting command line '%s'\n", command_line); + + dbus_error_init (&error); + if (!_dbus_shell_parse_argv (command_line, &shell_argc, &shell_argv, &error)) + { + fprintf (stderr, "Error parsing command line: %s\n", error.message ? error.message : ""); + return FALSE; + } + else + { + if (shell_argc != original_argc) + { + printf ("Number of arguments returned (%d) don't match original (%d)\n", + shell_argc, original_argc); + return FALSE; + } + printf ("Number of arguments: %d\n", shell_argc); + for (i = 0; i < shell_argc; i++) + { + char *unquoted; + + unquoted = _dbus_shell_unquote (original_argv[i]); + if (strcmp (unquoted ? unquoted : "", + shell_argv[i] ? shell_argv[i] : "")) + { + printf ("Position %d, returned argument (%s) does not match original (%s)\n", + i, shell_argv[i], unquoted); + dbus_free (unquoted); + return FALSE; + } + dbus_free (unquoted); + if (shell_argv[i]) + printf ("Argument %d = %s\n", i, shell_argv[i]); + } + + dbus_free_string_array (shell_argv); + } + + _dbus_string_free (&str); + + return TRUE; +} + +int +main (int argc, char **argv) +{ + if (!test_command_line ("command", "-s", "--force-shutdown", "\"a string\"", "123", NULL) + || !test_command_line ("command", "-s", NULL) + || !test_command_line ("/opt/gnome/bin/service-start", NULL) + || !test_command_line ("grep", "-l", "-r", "-i", "'whatever'", "files*.c", NULL) + || !test_command_line ("/home/boston/johnp/devel-local/dbus/test/test-segfault", NULL) + || !test_command_line ("ls", "-l", "-a", "--colors", "/tmp", NULL) + || !test_command_line ("rsync-to-server", NULL) + || !test_command_line ("test-segfault", "--no-segfault", NULL) + || !test_command_line ("evolution", "mailto:pepe@cuco.com", NULL) + || !test_command_line ("run", "\"a \n multiline\"", NULL) + || test_command_line ("ls", "\"a wrong string'", NULL) /* invalid command line */ ) + return -1; + + return 0; +} -- cgit