aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-01-13 18:34:04 +0100
committerAris Adamantiadis <aris@0xbadc0de.be>2011-01-13 18:34:04 +0100
commit2917e71aadae004f3a353c3de0672d7534e1a2bf (patch)
treede254390ede76ba980bb0a39a4f2abb42a69ee67 /tests
parent551b87b65b209255e60fbcaf146c43f2188ddc39 (diff)
downloadlibssh-2917e71aadae004f3a353c3de0672d7534e1a2bf.tar.gz
libssh-2917e71aadae004f3a353c3de0672d7534e1a2bf.tar.xz
libssh-2917e71aadae004f3a353c3de0672d7534e1a2bf.zip
Replaced argp support for platforms that support it
Argp is really useful, but it's not mandatory.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt5
-rw-r--r--tests/cmdline.c67
-rw-r--r--tests/torture.c9
-rw-r--r--tests/torture.h9
4 files changed, 86 insertions, 4 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d5227b70..e6205616 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,5 +1,7 @@
project(tests C)
+find_package(Argp)
+
set(TORTURE_LIBRARY torture)
include_directories(
@@ -14,13 +16,14 @@ include_directories(
)
# create test library
-add_library(${TORTURE_LIBRARY} STATIC torture.c)
+add_library(${TORTURE_LIBRARY} STATIC cmdline.c torture.c)
target_link_libraries(${TORTURE_LIBRARY}
${CMOCKERY_LIBRARY}
${LIBSSH_STATIC_LIBRARY}
${LIBSSH_LINK_LIBRARIES}
${LIBSSH_THREADS_STATIC_LIBRARY}
${LIBSSH_THREADS_LINK_LIBRARIES}
+ ${ARGP_LIBRARIES}
)
set(TEST_TARGET_LIBRARIES
diff --git a/tests/cmdline.c b/tests/cmdline.c
new file mode 100644
index 00000000..9619fd2a
--- /dev/null
+++ b/tests/cmdline.c
@@ -0,0 +1,67 @@
+#include "config.h"
+#include "torture.h"
+
+#ifdef HAVE_ARGP_H
+#include <argp.h>
+
+const char *argp_program_version = "libssh test 0.2";
+const char *argp_program_bug_address = "<csync-devel@csync.org>";
+
+static char **cmdline;
+
+/* Program documentation. */
+static char doc[] = "libssh test test";
+
+/* The options we understand. */
+static struct argp_option options[] = {
+ {
+ .name = "verbose",
+ .key = 'v',
+ .arg = NULL,
+ .flags = 0,
+ .doc = "Make libssh test more verbose",
+ .group = 0
+ },
+ {NULL, 0, NULL, 0, NULL, 0}
+};
+
+/* Parse a single option. */
+static error_t parse_opt (int key, char *arg, struct argp_state *state) {
+ /* Get the input argument from argp_parse, which we
+ * know is a pointer to our arguments structure.
+ */
+ struct argument_s *arguments = state->input;
+
+ /* arg is currently not used */
+ (void) arg;
+
+ switch (key) {
+ case 'v':
+ arguments->verbose++;
+ break;
+ case ARGP_KEY_ARG:
+ /* End processing here. */
+ cmdline = &state->argv [state->next - 1];
+ state->next = state->argc;
+ break;
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
+ return 0;
+}
+
+/* Our argp parser. */
+/* static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; */
+static struct argp argp = {options, parse_opt, NULL, doc, NULL, NULL, NULL};
+#endif /* HAVE_ARGP_H */
+
+void torture_cmdline_parse(int argc, char **argv, struct argument_s *arguments) {
+ /*
+ * Parse our arguments; every option seen by parse_opt will
+ * be reflected in arguments.
+ */
+#ifdef HAVE_ARGP_H
+ argp_parse(&argp, argc, argv, 0, 0, arguments);
+#endif /* HAVE_ARGP_H */
+}
diff --git a/tests/torture.c b/tests/torture.c
index 1bd7b159..62f52efa 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -9,8 +9,11 @@ int torture_libssh_verbosity(void){
}
int main(int argc, char **argv) {
- (void) argc;
- (void) argv;
+ struct argument_s arguments;
- return torture_run_tests();
+ arguments.verbose=0;
+ torture_cmdline_parse(argc, argv, &arguments);
+ verbosity=arguments.verbose;
+
+ return torture_run_tests();
}
diff --git a/tests/torture.h b/tests/torture.h
index 271fdd20..3aa73112 100644
--- a/tests/torture.h
+++ b/tests/torture.h
@@ -12,6 +12,15 @@
#include <setjmp.h>
#include <google/cmockery.h>
+
+/* Used by main to communicate with parse_opt. */
+struct argument_s {
+ char *args[2];
+ int verbose;
+};
+
+void torture_cmdline_parse(int argc, char **argv, struct argument_s *arguments);
+
/*
* Returns the verbosity level asked by user
*/