diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-15 11:14:36 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-15 11:14:59 +0100 |
commit | f09c53eb6f8c540cc3bc3730f9e34be596ed3716 (patch) | |
tree | 524957bd395bfca32e006163d44601936bf2afda /src/util/test_program.c | |
parent | dc0d60c9c8a635221c0d656611f8f93e0256ed84 (diff) | |
download | gnunet-f09c53eb6f8c540cc3bc3730f9e34be596ed3716.tar.gz gnunet-f09c53eb6f8c540cc3bc3730f9e34be596ed3716.zip |
add way to mark options as mandatory, get tests to pass again
Diffstat (limited to 'src/util/test_program.c')
-rw-r--r-- | src/util/test_program.c | 129 |
1 files changed, 74 insertions, 55 deletions
diff --git a/src/util/test_program.c b/src/util/test_program.c index 669cee7bd..d206952af 100644 --- a/src/util/test_program.c +++ b/src/util/test_program.c | |||
@@ -24,37 +24,19 @@ | |||
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_util_lib.h" | 25 | #include "gnunet_util_lib.h" |
26 | 26 | ||
27 | static int setme1, setme2; | 27 | |
28 | 28 | static int setme1; | |
29 | static struct GNUNET_GETOPT_CommandLineOption options1[] = { | 29 | |
30 | {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1}, | 30 | static int setme2; |
31 | GNUNET_GETOPT_OPTION_END | 31 | |
32 | }; | ||
33 | |||
34 | static struct GNUNET_GETOPT_CommandLineOption options2[] = { | ||
35 | {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1}, | ||
36 | {'N', "number", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme2}, | ||
37 | GNUNET_GETOPT_OPTION_END | ||
38 | }; | ||
39 | |||
40 | static struct GNUNET_GETOPT_CommandLineOption options3[] = { | ||
41 | {'N', "number", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1}, | ||
42 | {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme2}, | ||
43 | GNUNET_GETOPT_OPTION_END | ||
44 | }; | ||
45 | |||
46 | static struct GNUNET_GETOPT_CommandLineOption options4[] = { | ||
47 | {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme1}, | ||
48 | {'n', "number", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme2}, | ||
49 | GNUNET_GETOPT_OPTION_END | ||
50 | }; | ||
51 | 32 | ||
52 | /** | 33 | /** |
53 | * Main function that will be run. | 34 | * Main function that will be run. |
54 | */ | 35 | */ |
55 | |||
56 | static void | 36 | static void |
57 | runner (void *cls, char *const *args, const char *cfgfile, | 37 | runner (void *cls, |
38 | char *const *args, | ||
39 | const char *cfgfile, | ||
58 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 40 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
59 | { | 41 | { |
60 | int *ok = cls; | 42 | int *ok = cls; |
@@ -62,21 +44,16 @@ runner (void *cls, char *const *args, const char *cfgfile, | |||
62 | GNUNET_assert (setme1 == 1); | 44 | GNUNET_assert (setme1 == 1); |
63 | GNUNET_assert (0 == strcmp (args[0], "extra")); | 45 | GNUNET_assert (0 == strcmp (args[0], "extra")); |
64 | GNUNET_assert (args[1] == NULL); | 46 | GNUNET_assert (args[1] == NULL); |
65 | GNUNET_assert (0 == strcmp (cfgfile, "test_program_data.conf")); | 47 | GNUNET_assert (NULL != strstr (cfgfile, "/test_program_data.conf")); |
66 | |||
67 | *ok = 0; | 48 | *ok = 0; |
68 | } | 49 | } |
69 | 50 | ||
70 | /** | 51 | |
71 | * Main method, starts scheduler with task1, | 52 | int |
72 | * checks that "ok" is correct at the end. | 53 | main (int argc, char *argv[]) |
73 | */ | ||
74 | static int | ||
75 | check () | ||
76 | { | 54 | { |
77 | int ok = 1; | 55 | int ok = 1; |
78 | 56 | char *const argvx[] = { | |
79 | char *const argv[] = { | ||
80 | "test_program", | 57 | "test_program", |
81 | "-c", | 58 | "-c", |
82 | "test_program_data.conf", | 59 | "test_program_data.conf", |
@@ -86,33 +63,75 @@ check () | |||
86 | "extra", | 63 | "extra", |
87 | NULL | 64 | NULL |
88 | }; | 65 | }; |
66 | struct GNUNET_GETOPT_CommandLineOption options1[] = { | ||
67 | GNUNET_GETOPT_OPTION_SET_ONE ('n', | ||
68 | "name", | ||
69 | "description", | ||
70 | &setme1), | ||
71 | GNUNET_GETOPT_OPTION_END | ||
72 | }; | ||
73 | struct GNUNET_GETOPT_CommandLineOption options2[] = { | ||
74 | GNUNET_GETOPT_OPTION_SET_ONE ('n', | ||
75 | "name", | ||
76 | "description", | ||
77 | &setme1), | ||
78 | GNUNET_GETOPT_OPTION_SET_ONE ('N', | ||
79 | "number", | ||
80 | "description", | ||
81 | &setme2), | ||
82 | GNUNET_GETOPT_OPTION_END | ||
83 | }; | ||
84 | struct GNUNET_GETOPT_CommandLineOption options3[] = { | ||
85 | GNUNET_GETOPT_OPTION_SET_ONE ('N', | ||
86 | "number", | ||
87 | "description", | ||
88 | &setme1), | ||
89 | GNUNET_GETOPT_OPTION_SET_ONE ('n', | ||
90 | "name", | ||
91 | "description", | ||
92 | &setme2), | ||
93 | GNUNET_GETOPT_OPTION_END | ||
94 | }; | ||
95 | struct GNUNET_GETOPT_CommandLineOption options4[] = { | ||
96 | GNUNET_GETOPT_OPTION_SET_ONE ('n', | ||
97 | "name", | ||
98 | "description", | ||
99 | &setme1), | ||
100 | GNUNET_GETOPT_OPTION_SET_ONE ('n', | ||
101 | "name", | ||
102 | "description", | ||
103 | &setme2), | ||
104 | GNUNET_GETOPT_OPTION_END | ||
105 | }; | ||
89 | 106 | ||
107 | |||
108 | GNUNET_log_setup ("test_program", | ||
109 | "WARNING", | ||
110 | NULL); | ||
90 | GNUNET_assert (GNUNET_OK == | 111 | GNUNET_assert (GNUNET_OK == |
91 | GNUNET_PROGRAM_run (7, argv, "test_program", "A test", | 112 | GNUNET_PROGRAM_run (7, argvx, |
92 | options1, &runner, &ok)); | 113 | "test_program", |
114 | "A test", | ||
115 | options1, | ||
116 | &runner, &ok)); | ||
93 | 117 | ||
94 | GNUNET_assert (GNUNET_OK == | 118 | GNUNET_assert (GNUNET_OK == |
95 | GNUNET_PROGRAM_run (7, argv, "test_program", "A test", | 119 | GNUNET_PROGRAM_run (7, argvx, |
96 | options2, &runner, &ok)); | 120 | "test_program", "A test", |
121 | options2, | ||
122 | &runner, &ok)); | ||
97 | GNUNET_assert (GNUNET_OK == | 123 | GNUNET_assert (GNUNET_OK == |
98 | GNUNET_PROGRAM_run (7, argv, "test_program", "A test", | 124 | GNUNET_PROGRAM_run (7, argvx, |
99 | options3, &runner, &ok)); | 125 | "test_program", "A test", |
126 | options3, | ||
127 | &runner, &ok)); | ||
100 | GNUNET_assert (GNUNET_OK == | 128 | GNUNET_assert (GNUNET_OK == |
101 | GNUNET_PROGRAM_run (7, argv, "test_program", "A test", | 129 | GNUNET_PROGRAM_run (7, argvx, |
102 | options4, &runner, &ok)); | 130 | "test_program", "A test", |
131 | options4, | ||
132 | &runner, &ok)); | ||
103 | 133 | ||
104 | return ok; | 134 | return ok; |
105 | } | 135 | } |
106 | 136 | ||
107 | int | ||
108 | main (int argc, char *argv[]) | ||
109 | { | ||
110 | int ret = 0; | ||
111 | |||
112 | GNUNET_log_setup ("test_program", "WARNING", NULL); | ||
113 | ret += check (); | ||
114 | |||
115 | return ret; | ||
116 | } | ||
117 | |||
118 | /* end of test_program.c */ | 137 | /* end of test_program.c */ |