Update contrib.
1 /* Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
4 #define DBUS_COMPILATION
6 #include <dbus/dbus-internals.h>
7 #include <dbus/dbus-list.h>
8 #include <dbus/dbus-shell.h>
9 #include <dbus/dbus-string.h>
10 #include <dbus/dbus-sysdeps.h>
12 #include "dbus-internals.h"
13 #include "dbus-list.h"
14 #include "dbus-shell.h"
15 #include "dbus-string.h"
16 #include "dbus-sysdeps.h"
17 #endif //__SYMBAIN32__
18 #include <dbus/dbus-memory.h>
20 #define LOG_FILE "c:\\logs\\shell_test_log1.txt"
21 #include "std_log_result.h"
22 #define LOG_FILENAME_LINE __FILE__, __LINE__
24 void create_xml(int result)
29 testResultXml("shell_test");
35 test_command_line (const char *arg1, ...)
37 int i, original_argc, shell_argc;
40 char *command_line, *tmp;
42 DBusList *list = NULL, *node;
46 va_start (var_args, arg1);
47 _dbus_list_append (&list, (char *)arg1);
50 tmp = va_arg (var_args, char *);
53 _dbus_list_append (&list, tmp);
57 original_argc = _dbus_list_get_length (&list);
58 original_argv = dbus_new (char *, original_argc);
59 _dbus_string_init (&str);
60 for (i = 0, node = _dbus_list_get_first_link (&list); i < original_argc && node;
61 i++, node = _dbus_list_get_next_link (&list, node))
63 original_argv[i] = node->data;
65 _dbus_string_append_byte (&str, ' ');
66 _dbus_string_append (&str, original_argv[i]);
69 _dbus_list_clear (&list);
70 command_line = _dbus_string_get_data (&str);
71 printf ("\n\nTesting command line '%s'\n", command_line);
72 std_log(LOG_FILENAME_LINE, "\n\nTesting command line '%s'\n", command_line);
74 dbus_error_init (&error);
75 if (!_dbus_shell_parse_argv (command_line, &shell_argc, &shell_argv, &error))
77 fprintf (stderr, "Error parsing command line: %s\n", error.message ? error.message : "");
78 std_log(LOG_FILENAME_LINE, "Error parsing command line: %s\n", error.message ? error.message : "");
83 if (shell_argc != original_argc)
85 printf ("Number of arguments returned (%d) don't match original (%d)\n",
86 shell_argc, original_argc);
87 std_log(LOG_FILENAME_LINE, "Number of arguments returned (%d) don't match original (%d)\n",
88 shell_argc, original_argc);
91 printf ("Number of arguments: %d\n", shell_argc);
92 std_log(LOG_FILENAME_LINE, "Number of arguments: %d\n", shell_argc);
93 for (i = 0; i < shell_argc; i++)
97 unquoted = _dbus_shell_unquote (original_argv[i]);
98 if (strcmp (unquoted ? unquoted : "",
99 shell_argv[i] ? shell_argv[i] : ""))
101 printf ("Position %d, returned argument (%s) does not match original (%s)\n",
102 i, shell_argv[i], unquoted);
103 std_log(LOG_FILENAME_LINE, "Position %d, returned argument (%s) does not match original (%s)\n",
104 i, shell_argv[i], unquoted);
105 dbus_free (unquoted);
108 dbus_free (unquoted);
111 printf ("Argument %d = %s\n", i, shell_argv[i]);
112 std_log(LOG_FILENAME_LINE, "Argument %d = %s\n", i, shell_argv[i]);
116 dbus_free_string_array (shell_argv);
119 _dbus_string_free (&str);
127 if (!test_command_line ("command", "-s", "--force-shutdown", "\"a string\"", "123", NULL)
128 || !test_command_line ("command", "-s", NULL)
129 || !test_command_line ("/opt/gnome/bin/service-start", NULL)
130 || !test_command_line ("grep", "-l", "-r", "-i", "'whatever'", "files*.c", NULL)
131 || !test_command_line ("/home/boston/johnp/devel-local/dbus/test/test-segfault", NULL)
132 || !test_command_line ("ls", "-l", "-a", "--colors", _dbus_get_tmpdir(), NULL)
133 || !test_command_line ("rsync-to-server", NULL)
134 || !test_command_line ("test-segfault", "--no-segfault", NULL)
135 || !test_command_line ("evolution", "mailto:pepe@cuco.com", NULL)
136 || !test_command_line ("run", "\"a \n multiline\"", NULL)
137 || test_command_line ("ls", "\"a wrong string'", NULL) /* invalid command line */ )
143 std_log(LOG_FILENAME_LINE, "Test Successful.");