31
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <stdio.h>
|
|
19 |
#include <stdlib.h>
|
|
20 |
#define DBUS_COMPILATION
|
|
21 |
#ifndef __SYMBIAN32__
|
|
22 |
#include <dbus/dbus-internals.h>
|
|
23 |
#include <dbus/dbus-list.h>
|
|
24 |
#include <dbus/dbus-shell.h>
|
|
25 |
#include <dbus/dbus-string.h>
|
|
26 |
#include <dbus/dbus-sysdeps.h>
|
|
27 |
#else
|
|
28 |
#include "dbus-internals.h"
|
|
29 |
#include "dbus-list.h"
|
|
30 |
#include "dbus-shell.h"
|
|
31 |
#include "dbus-string.h"
|
|
32 |
#include "dbus-sysdeps.h"
|
|
33 |
#endif //__SYMBAIN32__
|
|
34 |
#include <dbus/dbus-memory.h>
|
|
35 |
|
|
36 |
#define LOG_FILE "c:\\logs\\shell_test_log1.txt"
|
|
37 |
#include "std_log_result.h"
|
|
38 |
#define LOG_FILENAME_LINE __FILE__, __LINE__
|
|
39 |
|
|
40 |
void create_xml(int result)
|
|
41 |
{
|
|
42 |
if(result)
|
|
43 |
assert_failed = 1;
|
|
44 |
|
|
45 |
testResultXml("shell_test");
|
|
46 |
close_log_file();
|
|
47 |
}
|
|
48 |
|
|
49 |
|
|
50 |
static dbus_bool_t
|
|
51 |
test_command_line (const char *arg1, ...)
|
|
52 |
{
|
|
53 |
int i, original_argc, shell_argc;
|
|
54 |
char **shell_argv;
|
|
55 |
char **original_argv;
|
|
56 |
char *command_line, *tmp;
|
|
57 |
DBusString str;
|
|
58 |
DBusList *list = NULL, *node;
|
|
59 |
va_list var_args;
|
|
60 |
DBusError error;
|
|
61 |
|
|
62 |
va_start (var_args, arg1);
|
|
63 |
_dbus_list_append (&list, (char *)arg1);
|
|
64 |
do
|
|
65 |
{
|
|
66 |
tmp = va_arg (var_args, char *);
|
|
67 |
if (!tmp)
|
|
68 |
break;
|
|
69 |
_dbus_list_append (&list, tmp);
|
|
70 |
} while (tmp);
|
|
71 |
va_end (var_args);
|
|
72 |
|
|
73 |
original_argc = _dbus_list_get_length (&list);
|
|
74 |
original_argv = dbus_new (char *, original_argc);
|
|
75 |
_dbus_string_init (&str);
|
|
76 |
for (i = 0, node = _dbus_list_get_first_link (&list); i < original_argc && node;
|
|
77 |
i++, node = _dbus_list_get_next_link (&list, node))
|
|
78 |
{
|
|
79 |
original_argv[i] = node->data;
|
|
80 |
if (i > 0)
|
|
81 |
_dbus_string_append_byte (&str, ' ');
|
|
82 |
_dbus_string_append (&str, original_argv[i]);
|
|
83 |
}
|
|
84 |
|
|
85 |
_dbus_list_clear (&list);
|
|
86 |
command_line = _dbus_string_get_data (&str);
|
|
87 |
printf ("\n\nTesting command line '%s'\n", command_line);
|
|
88 |
std_log(LOG_FILENAME_LINE, "\n\nTesting command line '%s'\n", command_line);
|
|
89 |
|
|
90 |
dbus_error_init (&error);
|
|
91 |
if (!_dbus_shell_parse_argv (command_line, &shell_argc, &shell_argv, &error))
|
|
92 |
{
|
|
93 |
fprintf (stderr, "Error parsing command line: %s\n", error.message ? error.message : "");
|
|
94 |
std_log(LOG_FILENAME_LINE, "Error parsing command line: %s\n", error.message ? error.message : "");
|
|
95 |
return FALSE;
|
|
96 |
}
|
|
97 |
else
|
|
98 |
{
|
|
99 |
if (shell_argc != original_argc)
|
|
100 |
{
|
|
101 |
printf ("Number of arguments returned (%d) don't match original (%d)\n",
|
|
102 |
shell_argc, original_argc);
|
|
103 |
std_log(LOG_FILENAME_LINE, "Number of arguments returned (%d) don't match original (%d)\n",
|
|
104 |
shell_argc, original_argc);
|
|
105 |
return FALSE;
|
|
106 |
}
|
|
107 |
printf ("Number of arguments: %d\n", shell_argc);
|
|
108 |
std_log(LOG_FILENAME_LINE, "Number of arguments: %d\n", shell_argc);
|
|
109 |
for (i = 0; i < shell_argc; i++)
|
|
110 |
{
|
|
111 |
char *unquoted;
|
|
112 |
|
|
113 |
unquoted = _dbus_shell_unquote (original_argv[i]);
|
|
114 |
if (strcmp (unquoted ? unquoted : "",
|
|
115 |
shell_argv[i] ? shell_argv[i] : ""))
|
|
116 |
{
|
|
117 |
printf ("Position %d, returned argument (%s) does not match original (%s)\n",
|
|
118 |
i, shell_argv[i], unquoted);
|
|
119 |
std_log(LOG_FILENAME_LINE, "Position %d, returned argument (%s) does not match original (%s)\n",
|
|
120 |
i, shell_argv[i], unquoted);
|
|
121 |
dbus_free (unquoted);
|
|
122 |
return FALSE;
|
|
123 |
}
|
|
124 |
dbus_free (unquoted);
|
|
125 |
if (shell_argv[i])
|
|
126 |
{
|
|
127 |
printf ("Argument %d = %s\n", i, shell_argv[i]);
|
|
128 |
std_log(LOG_FILENAME_LINE, "Argument %d = %s\n", i, shell_argv[i]);
|
|
129 |
}
|
|
130 |
}
|
|
131 |
|
|
132 |
dbus_free_string_array (shell_argv);
|
|
133 |
}
|
|
134 |
|
|
135 |
_dbus_string_free (&str);
|
|
136 |
|
|
137 |
return TRUE;
|
|
138 |
}
|
|
139 |
|
|
140 |
int
|
|
141 |
main ()
|
|
142 |
{
|
|
143 |
if (!test_command_line ("command", "-s", "--force-shutdown", "\"a string\"", "123", NULL)
|
|
144 |
|| !test_command_line ("command", "-s", NULL)
|
|
145 |
|| !test_command_line ("/opt/gnome/bin/service-start", NULL)
|
|
146 |
|| !test_command_line ("grep", "-l", "-r", "-i", "'whatever'", "files*.c", NULL)
|
|
147 |
|| !test_command_line ("/home/boston/johnp/devel-local/dbus/test/test-segfault", NULL)
|
|
148 |
|| !test_command_line ("ls", "-l", "-a", "--colors", _dbus_get_tmpdir(), NULL)
|
|
149 |
|| !test_command_line ("rsync-to-server", NULL)
|
|
150 |
|| !test_command_line ("test-segfault", "--no-segfault", NULL)
|
|
151 |
|| !test_command_line ("evolution", "mailto:pepe@cuco.com", NULL)
|
|
152 |
|| !test_command_line ("run", "\"a \n multiline\"", NULL)
|
|
153 |
|| test_command_line ("ls", "\"a wrong string'", NULL) /* invalid command line */ )
|
|
154 |
{
|
|
155 |
create_xml(1);
|
|
156 |
return -1;
|
|
157 |
}
|
|
158 |
|
|
159 |
std_log(LOG_FILENAME_LINE, "Test Successful.");
|
|
160 |
create_xml(0);
|
|
161 |
return 0;
|
|
162 |
}
|