|
1 /* Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/ |
|
2 #include <stdio.h> |
|
3 #include <stdlib.h> |
|
4 #define DBUS_COMPILATION |
|
5 #ifndef __SYMBIAN32__ |
|
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> |
|
11 #else |
|
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> |
|
19 |
|
20 #define LOG_FILE "c:\\logs\\shell_test_log1.txt" |
|
21 #include "std_log_result.h" |
|
22 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
23 |
|
24 void create_xml(int result) |
|
25 { |
|
26 if(result) |
|
27 assert_failed = 1; |
|
28 |
|
29 testResultXml("shell_test"); |
|
30 close_log_file(); |
|
31 } |
|
32 |
|
33 |
|
34 static dbus_bool_t |
|
35 test_command_line (const char *arg1, ...) |
|
36 { |
|
37 int i, original_argc, shell_argc; |
|
38 char **shell_argv; |
|
39 char **original_argv; |
|
40 char *command_line, *tmp; |
|
41 DBusString str; |
|
42 DBusList *list = NULL, *node; |
|
43 va_list var_args; |
|
44 DBusError error; |
|
45 |
|
46 va_start (var_args, arg1); |
|
47 _dbus_list_append (&list, (char *)arg1); |
|
48 do |
|
49 { |
|
50 tmp = va_arg (var_args, char *); |
|
51 if (!tmp) |
|
52 break; |
|
53 _dbus_list_append (&list, tmp); |
|
54 } while (tmp); |
|
55 va_end (var_args); |
|
56 |
|
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)) |
|
62 { |
|
63 original_argv[i] = node->data; |
|
64 if (i > 0) |
|
65 _dbus_string_append_byte (&str, ' '); |
|
66 _dbus_string_append (&str, original_argv[i]); |
|
67 } |
|
68 |
|
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); |
|
73 |
|
74 dbus_error_init (&error); |
|
75 if (!_dbus_shell_parse_argv (command_line, &shell_argc, &shell_argv, &error)) |
|
76 { |
|
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 : ""); |
|
79 return FALSE; |
|
80 } |
|
81 else |
|
82 { |
|
83 if (shell_argc != original_argc) |
|
84 { |
|
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); |
|
89 return FALSE; |
|
90 } |
|
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++) |
|
94 { |
|
95 char *unquoted; |
|
96 |
|
97 unquoted = _dbus_shell_unquote (original_argv[i]); |
|
98 if (strcmp (unquoted ? unquoted : "", |
|
99 shell_argv[i] ? shell_argv[i] : "")) |
|
100 { |
|
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); |
|
106 return FALSE; |
|
107 } |
|
108 dbus_free (unquoted); |
|
109 if (shell_argv[i]) |
|
110 { |
|
111 printf ("Argument %d = %s\n", i, shell_argv[i]); |
|
112 std_log(LOG_FILENAME_LINE, "Argument %d = %s\n", i, shell_argv[i]); |
|
113 } |
|
114 } |
|
115 |
|
116 dbus_free_string_array (shell_argv); |
|
117 } |
|
118 |
|
119 _dbus_string_free (&str); |
|
120 |
|
121 return TRUE; |
|
122 } |
|
123 |
|
124 int |
|
125 main () |
|
126 { |
|
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 */ ) |
|
138 { |
|
139 create_xml(1); |
|
140 return -1; |
|
141 } |
|
142 |
|
143 std_log(LOG_FILENAME_LINE, "Test Successful."); |
|
144 create_xml(0); |
|
145 return 0; |
|
146 } |