1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ofdbus/dbus/tsrc/testapps/dbus_test_cases/shell-test.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,146 @@
1.4 +/* Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
1.5 +#include <stdio.h>
1.6 +#include <stdlib.h>
1.7 +#define DBUS_COMPILATION
1.8 +#ifndef __SYMBIAN32__
1.9 +#include <dbus/dbus-internals.h>
1.10 +#include <dbus/dbus-list.h>
1.11 +#include <dbus/dbus-shell.h>
1.12 +#include <dbus/dbus-string.h>
1.13 +#include <dbus/dbus-sysdeps.h>
1.14 +#else
1.15 +#include "dbus-internals.h"
1.16 +#include "dbus-list.h"
1.17 +#include "dbus-shell.h"
1.18 +#include "dbus-string.h"
1.19 +#include "dbus-sysdeps.h"
1.20 +#endif //__SYMBAIN32__
1.21 +#include <dbus/dbus-memory.h>
1.22 +
1.23 +#define LOG_FILE "c:\\logs\\shell_test_log1.txt"
1.24 +#include "std_log_result.h"
1.25 +#define LOG_FILENAME_LINE __FILE__, __LINE__
1.26 +
1.27 +void create_xml(int result)
1.28 + {
1.29 + if(result)
1.30 + assert_failed = 1;
1.31 +
1.32 + testResultXml("shell_test");
1.33 + close_log_file();
1.34 + }
1.35 +
1.36 +
1.37 +static dbus_bool_t
1.38 +test_command_line (const char *arg1, ...)
1.39 +{
1.40 + int i, original_argc, shell_argc;
1.41 + char **shell_argv;
1.42 + char **original_argv;
1.43 + char *command_line, *tmp;
1.44 + DBusString str;
1.45 + DBusList *list = NULL, *node;
1.46 + va_list var_args;
1.47 + DBusError error;
1.48 +
1.49 + va_start (var_args, arg1);
1.50 + _dbus_list_append (&list, (char *)arg1);
1.51 + do
1.52 + {
1.53 + tmp = va_arg (var_args, char *);
1.54 + if (!tmp)
1.55 + break;
1.56 + _dbus_list_append (&list, tmp);
1.57 + } while (tmp);
1.58 + va_end (var_args);
1.59 +
1.60 + original_argc = _dbus_list_get_length (&list);
1.61 + original_argv = dbus_new (char *, original_argc);
1.62 + _dbus_string_init (&str);
1.63 + for (i = 0, node = _dbus_list_get_first_link (&list); i < original_argc && node;
1.64 + i++, node = _dbus_list_get_next_link (&list, node))
1.65 + {
1.66 + original_argv[i] = node->data;
1.67 + if (i > 0)
1.68 + _dbus_string_append_byte (&str, ' ');
1.69 + _dbus_string_append (&str, original_argv[i]);
1.70 + }
1.71 +
1.72 + _dbus_list_clear (&list);
1.73 + command_line = _dbus_string_get_data (&str);
1.74 + printf ("\n\nTesting command line '%s'\n", command_line);
1.75 + std_log(LOG_FILENAME_LINE, "\n\nTesting command line '%s'\n", command_line);
1.76 +
1.77 + dbus_error_init (&error);
1.78 + if (!_dbus_shell_parse_argv (command_line, &shell_argc, &shell_argv, &error))
1.79 + {
1.80 + fprintf (stderr, "Error parsing command line: %s\n", error.message ? error.message : "");
1.81 + std_log(LOG_FILENAME_LINE, "Error parsing command line: %s\n", error.message ? error.message : "");
1.82 + return FALSE;
1.83 + }
1.84 + else
1.85 + {
1.86 + if (shell_argc != original_argc)
1.87 + {
1.88 + printf ("Number of arguments returned (%d) don't match original (%d)\n",
1.89 + shell_argc, original_argc);
1.90 + std_log(LOG_FILENAME_LINE, "Number of arguments returned (%d) don't match original (%d)\n",
1.91 + shell_argc, original_argc);
1.92 + return FALSE;
1.93 + }
1.94 + printf ("Number of arguments: %d\n", shell_argc);
1.95 + std_log(LOG_FILENAME_LINE, "Number of arguments: %d\n", shell_argc);
1.96 + for (i = 0; i < shell_argc; i++)
1.97 + {
1.98 + char *unquoted;
1.99 +
1.100 + unquoted = _dbus_shell_unquote (original_argv[i]);
1.101 + if (strcmp (unquoted ? unquoted : "",
1.102 + shell_argv[i] ? shell_argv[i] : ""))
1.103 + {
1.104 + printf ("Position %d, returned argument (%s) does not match original (%s)\n",
1.105 + i, shell_argv[i], unquoted);
1.106 + std_log(LOG_FILENAME_LINE, "Position %d, returned argument (%s) does not match original (%s)\n",
1.107 + i, shell_argv[i], unquoted);
1.108 + dbus_free (unquoted);
1.109 + return FALSE;
1.110 + }
1.111 + dbus_free (unquoted);
1.112 + if (shell_argv[i])
1.113 + {
1.114 + printf ("Argument %d = %s\n", i, shell_argv[i]);
1.115 + std_log(LOG_FILENAME_LINE, "Argument %d = %s\n", i, shell_argv[i]);
1.116 + }
1.117 + }
1.118 +
1.119 + dbus_free_string_array (shell_argv);
1.120 + }
1.121 +
1.122 + _dbus_string_free (&str);
1.123 +
1.124 + return TRUE;
1.125 +}
1.126 +
1.127 +int
1.128 +main ()
1.129 +{
1.130 + if (!test_command_line ("command", "-s", "--force-shutdown", "\"a string\"", "123", NULL)
1.131 + || !test_command_line ("command", "-s", NULL)
1.132 + || !test_command_line ("/opt/gnome/bin/service-start", NULL)
1.133 + || !test_command_line ("grep", "-l", "-r", "-i", "'whatever'", "files*.c", NULL)
1.134 + || !test_command_line ("/home/boston/johnp/devel-local/dbus/test/test-segfault", NULL)
1.135 + || !test_command_line ("ls", "-l", "-a", "--colors", _dbus_get_tmpdir(), NULL)
1.136 + || !test_command_line ("rsync-to-server", NULL)
1.137 + || !test_command_line ("test-segfault", "--no-segfault", NULL)
1.138 + || !test_command_line ("evolution", "mailto:pepe@cuco.com", NULL)
1.139 + || !test_command_line ("run", "\"a \n multiline\"", NULL)
1.140 + || test_command_line ("ls", "\"a wrong string'", NULL) /* invalid command line */ )
1.141 + {
1.142 + create_xml(1);
1.143 + return -1;
1.144 + }
1.145 +
1.146 + std_log(LOG_FILENAME_LINE, "Test Successful.");
1.147 + create_xml(0);
1.148 + return 0;
1.149 +}