Mercurial > hg > th-libs
changeset 275:2799b2c3e64d
Merge.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 17 Feb 2016 17:17:00 +0200 |
parents | 7bea1d5ab944 (current diff) f875db8634b6 (diff) |
children | 56b0de9f9d44 |
files | |
diffstat | 1 files changed, 49 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/tests.c Wed Feb 17 15:38:33 2016 +0200 +++ b/tests.c Wed Feb 17 17:17:00 2016 +0200 @@ -1,4 +1,5 @@ #include "th_types.h" +#include "th_args.h" #include "th_util.h" #include "th_string.h" #include "th_crypto.h" @@ -13,6 +14,45 @@ char buf1[SET_BUF_SIZE+2], buf2[SET_BUF_SIZE+2]; +// Define option arguments +static const th_optarg_t arg_opts[] = +{ + { 0, '?', "help", "Show this help", OPT_NONE }, + { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, +}; + +static const int arg_nopts = sizeof(arg_opts) / sizeof(arg_opts[0]); + + +void arg_show_help(void) +{ + th_print_banner(stdout, th_prog_name, "[options]"); + th_args_help(stdout, arg_opts, arg_nopts, 0); +} + + +BOOL arg_handle_opt(const int optN, char *optArg, char *currArg) +{ + switch (optN) + { + case 0: + arg_show_help(); + exit(0); + break; + + case 1: + th_verbosityLevel++; + break; + + default: + THERR("Unknown option '%s'.\n", currArg); + return FALSE; + } + + return TRUE; +} + + void test_start_v(const char *fmt, va_list ap) { tests_total++; @@ -130,14 +170,11 @@ int main(int argc, char *argv[]) { - (void) argc; - (void) argv; - // // Initialization // th_init("th-test", "th-libs unit tests", "0.0.1", NULL, NULL); - th_verbosityLevel = 1; + th_verbosityLevel = 0; if (sizeof(char) != sizeof(unsigned char)) { @@ -148,6 +185,14 @@ tests_failed = tests_passed = tests_total = tests_set = 0; // + // Parse command line arguments + // + if (!th_args_process(argc, argv, arg_opts, arg_nopts, + arg_handle_opt, NULL, 0)) + return 0; + + + // // Test series #1 // tests_header("printf() function family");