diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-05-28 08:00:14 -0700 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-05-28 08:00:14 -0700 |
commit | e7023612eff5ab8f1be3aaff1b26896962aab139 (patch) | |
tree | dc3da7b71abefaac1fd7767a09e507f22b2dfec2 /test | |
parent | a3c9fb08136d6a3875b8e400ef4b4137357d6b4a (diff) |
Add a test of cmdline usage strings - and make them saner
Diffstat (limited to 'test')
-rw-r--r-- | test/core/support/cmdline_test.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/core/support/cmdline_test.c b/test/core/support/cmdline_test.c index a7767ace5e..26153b192c 100644 --- a/test/core/support/cmdline_test.c +++ b/test/core/support/cmdline_test.c @@ -35,6 +35,7 @@ #include <string.h> +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/useful.h> #include "test/core/util/test_config.h" @@ -272,6 +273,27 @@ static void test_many(void) { gpr_cmdline_destroy(cl); } +static void test_usage(void) { + gpr_cmdline *cl; + char *usage; + + char *str = NULL; + int x = 0; + int flag = 2; + + cl = gpr_cmdline_create(NULL); + gpr_cmdline_add_string(cl, "str", NULL, &str); + gpr_cmdline_add_int(cl, "x", NULL, &x); + gpr_cmdline_add_flag(cl, "flag", NULL, &flag); + + usage = gpr_cmdline_usage_string(cl, "test"); + GPR_ASSERT(0 == strcmp(usage, + "Usage: test [--str=string] [--x=int] [--flag|--no-flag]\n")); + gpr_free(usage); + + gpr_cmdline_destroy(cl); +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); test_simple_int(); @@ -289,5 +311,6 @@ int main(int argc, char **argv) { test_flag_val_true(); test_flag_val_false(); test_many(); + test_usage(); return 0; } |