From 749a159c13bfa9989e57a6d9f6668e03f7f99a14 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 10 Jan 2014 02:17:22 +0100 Subject: [PATCH 1/5] Rename shell-test to test-shell to match common test application naming scheme. --- cmake/test/CMakeLists.txt | 6 +-- test/.gitignore | 2 +- test/Makefile.am | 6 +-- test/shell-test.c | 109 --------------------------------------------- test/test-shell.c | 109 +++++++++++++++++++++++++++++++++++++++++++++ 5 Dateien geändert, 116 Zeilen hinzugefügt(+), 116 Zeilen entfernt(-) delete mode 100644 test/shell-test.c create mode 100644 test/test-shell.c diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt index 327b092..eccb01c 100644 --- a/cmake/test/CMakeLists.txt +++ b/cmake/test/CMakeLists.txt @@ -27,8 +27,8 @@ set (test-shell-service_SOURCES ${CMAKE_SOURCE_DIR}/../test/test-shell-service.c ) -set (shell-test_SOURCES - ${CMAKE_SOURCE_DIR}/../test/shell-test.c +set (test-shell_SOURCES + ${CMAKE_SOURCE_DIR}/../test/test-shell.c ) set (spawn-test_SOURCES @@ -49,7 +49,7 @@ set (test-sleep-forever_SOURCES add_helper_executable(test-service ${test-service_SOURCES} dbus-testutils) add_helper_executable(test-names ${test-names_SOURCES} dbus-testutils) -add_test_executable(shell-test ${shell-test_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +add_test_executable(test-shell ${test-shell_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) add_test_executable(test-printf ${CMAKE_SOURCE_DIR}/../test/internals/printf.c dbus-testutils) add_helper_executable(test-shell-service ${test-shell-service_SOURCES} dbus-testutils) add_helper_executable(spawn-test ${spawn-test_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) diff --git a/test/.gitignore b/test/.gitignore index 1337de6..814a35c 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -21,7 +21,7 @@ test-segfault test-service test-sleep-forever decode-gcov -shell-test +test-shell test-shell-service test-names test-loopback diff --git a/test/Makefile.am b/test/Makefile.am index 09b9456..06d06e3 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -100,8 +100,8 @@ test_names_LDADD = libdbus-testutils-internal.la ## break_loader_LDADD = $(top_builddir)/dbus/libdbus-internal.la test_shell_service_CPPFLAGS = $(static_cppflags) test_shell_service_LDADD = libdbus-testutils-internal.la -shell_test_CPPFLAGS = $(static_cppflags) -shell_test_LDADD = libdbus-testutils-internal.la +test_shell_CPPFLAGS = $(static_cppflags) +test_shell_LDADD = libdbus-testutils-internal.la spawn_test_CPPFLAGS = $(static_cppflags) spawn_test_LDADD = $(top_builddir)/dbus/libdbus-internal.la @@ -124,7 +124,7 @@ testexecdir = $(libdir)/dbus-1.0/test testexec_PROGRAMS = installable_tests = \ - shell-test \ + test-shell \ test-printf \ $(NULL) installable_manual_tests = \ diff --git a/test/shell-test.c b/test/shell-test.c deleted file mode 100644 index d1dc5b5..0000000 --- a/test/shell-test.c +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include -#include - -#include -#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, (char *)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", _dbus_get_tmpdir(), 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; -} diff --git a/test/test-shell.c b/test/test-shell.c new file mode 100644 index 0000000..d1dc5b5 --- /dev/null +++ b/test/test-shell.c @@ -0,0 +1,109 @@ +#include +#include +#include + +#include +#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, (char *)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", _dbus_get_tmpdir(), 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; +} -- 1.7.10.4