diff options
Diffstat (limited to 'src/testing/test_testing_peerstartup2.c')
-rw-r--r-- | src/testing/test_testing_peerstartup2.c | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c index a077ddcc2..80a3b719a 100644 --- a/src/testing/test_testing_peerstartup2.c +++ b/src/testing/test_testing_peerstartup2.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -29,19 +29,19 @@ | |||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_testing_lib.h" | 30 | #include "gnunet_testing_lib.h" |
31 | 31 | ||
32 | #define LOG(kind,...) \ | 32 | #define LOG(kind, ...) \ |
33 | GNUNET_log (kind, __VA_ARGS__) | 33 | GNUNET_log(kind, __VA_ARGS__) |
34 | 34 | ||
35 | 35 | ||
36 | #define FAIL_TEST(cond) \ | 36 | #define FAIL_TEST(cond) \ |
37 | do { \ | 37 | do { \ |
38 | if (!(cond)) { \ | 38 | if (!(cond)) { \ |
39 | GNUNET_break (0); \ | 39 | GNUNET_break(0); \ |
40 | if (GNUNET_OK == status) { \ | 40 | if (GNUNET_OK == status) { \ |
41 | status = GNUNET_SYSERR; \ | 41 | status = GNUNET_SYSERR; \ |
42 | } \ | 42 | } \ |
43 | } \ | 43 | } \ |
44 | } while (0) \ | 44 | } while (0) \ |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
@@ -52,8 +52,7 @@ int status; | |||
52 | /** | 52 | /** |
53 | * The testing context | 53 | * The testing context |
54 | */ | 54 | */ |
55 | struct TestingContext | 55 | struct TestingContext { |
56 | { | ||
57 | /** | 56 | /** |
58 | * The testing system | 57 | * The testing system |
59 | */ | 58 | */ |
@@ -83,18 +82,17 @@ struct TestingContext | |||
83 | 82 | ||
84 | 83 | ||
85 | static void | 84 | static void |
86 | do_shutdown2 (void *cls) | 85 | do_shutdown2(void *cls) |
87 | { | 86 | { |
88 | struct TestingContext *test_ctx = cls; | 87 | struct TestingContext *test_ctx = cls; |
89 | 88 | ||
90 | if (NULL != test_ctx->peer) | 89 | if (NULL != test_ctx->peer) |
91 | GNUNET_TESTING_peer_destroy (test_ctx->peer); | 90 | GNUNET_TESTING_peer_destroy(test_ctx->peer); |
92 | if (NULL != test_ctx->cfg) | 91 | if (NULL != test_ctx->cfg) |
93 | GNUNET_CONFIGURATION_destroy (test_ctx->cfg); | 92 | GNUNET_CONFIGURATION_destroy(test_ctx->cfg); |
94 | if (NULL != test_ctx->system) | 93 | if (NULL != test_ctx->system) |
95 | GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); | 94 | GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES); |
96 | GNUNET_free (test_ctx); | 95 | GNUNET_free(test_ctx); |
97 | |||
98 | } | 96 | } |
99 | 97 | ||
100 | 98 | ||
@@ -104,27 +102,29 @@ do_shutdown2 (void *cls) | |||
104 | * @param cls the testing context | 102 | * @param cls the testing context |
105 | */ | 103 | */ |
106 | static void | 104 | static void |
107 | do_shutdown (void *cls); | 105 | do_shutdown(void *cls); |
108 | 106 | ||
109 | 107 | ||
110 | static void | 108 | static void |
111 | peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) | 109 | peer_status_cb(void *cls, struct GNUNET_TESTING_Peer *peer, int success) |
112 | { | 110 | { |
113 | struct TestingContext *test_ctx = cls; | 111 | struct TestingContext *test_ctx = cls; |
114 | 112 | ||
115 | switch (test_ctx->state) | 113 | switch (test_ctx->state) |
116 | { | 114 | { |
117 | case PEER_INIT: | 115 | case PEER_INIT: |
118 | FAIL_TEST (0); | 116 | FAIL_TEST(0); |
119 | break; | 117 | break; |
120 | case PEER_STARTED: | 118 | |
121 | FAIL_TEST (GNUNET_YES == success); | 119 | case PEER_STARTED: |
122 | test_ctx->state = PEER_STOPPED; | 120 | FAIL_TEST(GNUNET_YES == success); |
123 | GNUNET_SCHEDULER_add_now (&do_shutdown2, cls); | 121 | test_ctx->state = PEER_STOPPED; |
124 | break; | 122 | GNUNET_SCHEDULER_add_now(&do_shutdown2, cls); |
125 | case PEER_STOPPED: | 123 | break; |
126 | FAIL_TEST (0); | 124 | |
127 | } | 125 | case PEER_STOPPED: |
126 | FAIL_TEST(0); | ||
127 | } | ||
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
@@ -134,20 +134,20 @@ peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) | |||
134 | * @param cls the testing context | 134 | * @param cls the testing context |
135 | */ | 135 | */ |
136 | static void | 136 | static void |
137 | do_shutdown (void *cls) | 137 | do_shutdown(void *cls) |
138 | { | 138 | { |
139 | struct TestingContext *test_ctx = cls; | 139 | struct TestingContext *test_ctx = cls; |
140 | 140 | ||
141 | GNUNET_assert (NULL != test_ctx); | 141 | GNUNET_assert(NULL != test_ctx); |
142 | if (NULL != test_ctx->peer) | 142 | if (NULL != test_ctx->peer) |
143 | { | 143 | { |
144 | FAIL_TEST (GNUNET_OK == | 144 | FAIL_TEST(GNUNET_OK == |
145 | GNUNET_TESTING_peer_stop_async (test_ctx->peer, | 145 | GNUNET_TESTING_peer_stop_async(test_ctx->peer, |
146 | &peer_status_cb, | 146 | &peer_status_cb, |
147 | test_ctx)); | 147 | test_ctx)); |
148 | } | 148 | } |
149 | else | 149 | else |
150 | do_shutdown2 (test_ctx); | 150 | do_shutdown2(test_ctx); |
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
@@ -155,51 +155,51 @@ do_shutdown (void *cls) | |||
155 | * Main point of test execution | 155 | * Main point of test execution |
156 | */ | 156 | */ |
157 | static void | 157 | static void |
158 | run (void *cls, char *const *args, const char *cfgfile, | 158 | run(void *cls, char *const *args, const char *cfgfile, |
159 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 159 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
160 | { | 160 | { |
161 | struct TestingContext *test_ctx; | 161 | struct TestingContext *test_ctx; |
162 | char *emsg; | 162 | char *emsg; |
163 | struct GNUNET_PeerIdentity id; | 163 | struct GNUNET_PeerIdentity id; |
164 | 164 | ||
165 | test_ctx = GNUNET_new (struct TestingContext); | 165 | test_ctx = GNUNET_new(struct TestingContext); |
166 | test_ctx->system = | 166 | test_ctx->system = |
167 | GNUNET_TESTING_system_create ("test-gnunet-testing", | 167 | GNUNET_TESTING_system_create("test-gnunet-testing", |
168 | "127.0.0.1", NULL, NULL); | 168 | "127.0.0.1", NULL, NULL); |
169 | emsg = NULL; | 169 | emsg = NULL; |
170 | if (NULL == test_ctx->system) | 170 | if (NULL == test_ctx->system) |
171 | goto end; | 171 | goto end; |
172 | test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); | 172 | test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg); |
173 | test_ctx->peer = | 173 | test_ctx->peer = |
174 | GNUNET_TESTING_peer_configure (test_ctx->system, | 174 | GNUNET_TESTING_peer_configure(test_ctx->system, |
175 | test_ctx->cfg, | 175 | test_ctx->cfg, |
176 | 0, &id, &emsg); | 176 | 0, &id, &emsg); |
177 | if (NULL == test_ctx->peer) | 177 | if (NULL == test_ctx->peer) |
178 | { | 178 | { |
179 | if (NULL != emsg) | 179 | if (NULL != emsg) |
180 | printf ("Test failed upon error: %s", emsg); | 180 | printf("Test failed upon error: %s", emsg); |
181 | goto end; | 181 | goto end; |
182 | } | 182 | } |
183 | if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) | 183 | if (GNUNET_OK != GNUNET_TESTING_peer_start(test_ctx->peer)) |
184 | goto end; | 184 | goto end; |
185 | test_ctx->state = PEER_STARTED; | 185 | test_ctx->state = PEER_STARTED; |
186 | FAIL_TEST (GNUNET_OK == | 186 | FAIL_TEST(GNUNET_OK == |
187 | GNUNET_TESTING_peer_stop_async (test_ctx->peer, | 187 | GNUNET_TESTING_peer_stop_async(test_ctx->peer, |
188 | &peer_status_cb, | 188 | &peer_status_cb, |
189 | test_ctx)); | 189 | test_ctx)); |
190 | GNUNET_TESTING_peer_stop_async_cancel (test_ctx->peer); | 190 | GNUNET_TESTING_peer_stop_async_cancel(test_ctx->peer); |
191 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 191 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
192 | &do_shutdown, test_ctx); | 192 | &do_shutdown, test_ctx); |
193 | return; | 193 | return; |
194 | 194 | ||
195 | end: | 195 | end: |
196 | FAIL_TEST (0); | 196 | FAIL_TEST(0); |
197 | GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); | 197 | GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx); |
198 | GNUNET_free_non_null (emsg); | 198 | GNUNET_free_non_null(emsg); |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | int main (int argc, char *argv[]) | 202 | int main(int argc, char *argv[]) |
203 | { | 203 | { |
204 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 204 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
205 | GNUNET_GETOPT_OPTION_END | 205 | GNUNET_GETOPT_OPTION_END |
@@ -207,10 +207,10 @@ int main (int argc, char *argv[]) | |||
207 | 207 | ||
208 | status = GNUNET_OK; | 208 | status = GNUNET_OK; |
209 | if (GNUNET_OK != | 209 | if (GNUNET_OK != |
210 | GNUNET_PROGRAM_run (argc, argv, | 210 | GNUNET_PROGRAM_run(argc, argv, |
211 | "test_testing_new_peerstartup", | 211 | "test_testing_new_peerstartup", |
212 | "test case for peerstartup using new testing library", | 212 | "test case for peerstartup using new testing library", |
213 | options, &run, NULL)) | 213 | options, &run, NULL)) |
214 | return 1; | 214 | return 1; |
215 | return (GNUNET_OK == status) ? 0 : 1; | 215 | return (GNUNET_OK == status) ? 0 : 1; |
216 | } | 216 | } |