diff options
Diffstat (limited to 'src/testing/test_testing_peerstartup2.c')
-rw-r--r-- | src/testing/test_testing_peerstartup2.c | 138 |
1 files changed, 70 insertions, 68 deletions
diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c index 80a3b719a..316a55951 100644 --- a/src/testing/test_testing_peerstartup2.c +++ b/src/testing/test_testing_peerstartup2.c | |||
@@ -30,18 +30,18 @@ | |||
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,7 +52,8 @@ int status; | |||
52 | /** | 52 | /** |
53 | * The testing context | 53 | * The testing context |
54 | */ | 54 | */ |
55 | struct TestingContext { | 55 | struct TestingContext |
56 | { | ||
56 | /** | 57 | /** |
57 | * The testing system | 58 | * The testing system |
58 | */ | 59 | */ |
@@ -71,7 +72,8 @@ struct TestingContext { | |||
71 | /** | 72 | /** |
72 | * State | 73 | * State |
73 | */ | 74 | */ |
74 | enum { | 75 | enum |
76 | { | ||
75 | PEER_INIT, | 77 | PEER_INIT, |
76 | 78 | ||
77 | PEER_STARTED, | 79 | PEER_STARTED, |
@@ -82,17 +84,17 @@ struct TestingContext { | |||
82 | 84 | ||
83 | 85 | ||
84 | static void | 86 | static void |
85 | do_shutdown2(void *cls) | 87 | do_shutdown2 (void *cls) |
86 | { | 88 | { |
87 | struct TestingContext *test_ctx = cls; | 89 | struct TestingContext *test_ctx = cls; |
88 | 90 | ||
89 | if (NULL != test_ctx->peer) | 91 | if (NULL != test_ctx->peer) |
90 | GNUNET_TESTING_peer_destroy(test_ctx->peer); | 92 | GNUNET_TESTING_peer_destroy (test_ctx->peer); |
91 | if (NULL != test_ctx->cfg) | 93 | if (NULL != test_ctx->cfg) |
92 | GNUNET_CONFIGURATION_destroy(test_ctx->cfg); | 94 | GNUNET_CONFIGURATION_destroy (test_ctx->cfg); |
93 | if (NULL != test_ctx->system) | 95 | if (NULL != test_ctx->system) |
94 | GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES); | 96 | GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); |
95 | GNUNET_free(test_ctx); | 97 | GNUNET_free (test_ctx); |
96 | } | 98 | } |
97 | 99 | ||
98 | 100 | ||
@@ -102,29 +104,29 @@ do_shutdown2(void *cls) | |||
102 | * @param cls the testing context | 104 | * @param cls the testing context |
103 | */ | 105 | */ |
104 | static void | 106 | static void |
105 | do_shutdown(void *cls); | 107 | do_shutdown (void *cls); |
106 | 108 | ||
107 | 109 | ||
108 | static void | 110 | static void |
109 | peer_status_cb(void *cls, struct GNUNET_TESTING_Peer *peer, int success) | 111 | peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) |
110 | { | 112 | { |
111 | struct TestingContext *test_ctx = cls; | 113 | struct TestingContext *test_ctx = cls; |
112 | 114 | ||
113 | switch (test_ctx->state) | 115 | switch (test_ctx->state) |
114 | { | 116 | { |
115 | case PEER_INIT: | 117 | case PEER_INIT: |
116 | FAIL_TEST(0); | 118 | FAIL_TEST (0); |
117 | break; | 119 | break; |
118 | 120 | ||
119 | case PEER_STARTED: | 121 | case PEER_STARTED: |
120 | FAIL_TEST(GNUNET_YES == success); | 122 | FAIL_TEST (GNUNET_YES == success); |
121 | test_ctx->state = PEER_STOPPED; | 123 | test_ctx->state = PEER_STOPPED; |
122 | GNUNET_SCHEDULER_add_now(&do_shutdown2, cls); | 124 | GNUNET_SCHEDULER_add_now (&do_shutdown2, cls); |
123 | break; | 125 | break; |
124 | 126 | ||
125 | case PEER_STOPPED: | 127 | case PEER_STOPPED: |
126 | FAIL_TEST(0); | 128 | FAIL_TEST (0); |
127 | } | 129 | } |
128 | } | 130 | } |
129 | 131 | ||
130 | 132 | ||
@@ -134,20 +136,20 @@ peer_status_cb(void *cls, struct GNUNET_TESTING_Peer *peer, int success) | |||
134 | * @param cls the testing context | 136 | * @param cls the testing context |
135 | */ | 137 | */ |
136 | static void | 138 | static void |
137 | do_shutdown(void *cls) | 139 | do_shutdown (void *cls) |
138 | { | 140 | { |
139 | struct TestingContext *test_ctx = cls; | 141 | struct TestingContext *test_ctx = cls; |
140 | 142 | ||
141 | GNUNET_assert(NULL != test_ctx); | 143 | GNUNET_assert (NULL != test_ctx); |
142 | if (NULL != test_ctx->peer) | 144 | if (NULL != test_ctx->peer) |
143 | { | 145 | { |
144 | FAIL_TEST(GNUNET_OK == | 146 | FAIL_TEST (GNUNET_OK == |
145 | GNUNET_TESTING_peer_stop_async(test_ctx->peer, | 147 | GNUNET_TESTING_peer_stop_async (test_ctx->peer, |
146 | &peer_status_cb, | 148 | &peer_status_cb, |
147 | test_ctx)); | 149 | test_ctx)); |
148 | } | 150 | } |
149 | else | 151 | else |
150 | do_shutdown2(test_ctx); | 152 | do_shutdown2 (test_ctx); |
151 | } | 153 | } |
152 | 154 | ||
153 | 155 | ||
@@ -155,51 +157,51 @@ do_shutdown(void *cls) | |||
155 | * Main point of test execution | 157 | * Main point of test execution |
156 | */ | 158 | */ |
157 | static void | 159 | static void |
158 | run(void *cls, char *const *args, const char *cfgfile, | 160 | run (void *cls, char *const *args, const char *cfgfile, |
159 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 161 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
160 | { | 162 | { |
161 | struct TestingContext *test_ctx; | 163 | struct TestingContext *test_ctx; |
162 | char *emsg; | 164 | char *emsg; |
163 | struct GNUNET_PeerIdentity id; | 165 | struct GNUNET_PeerIdentity id; |
164 | 166 | ||
165 | test_ctx = GNUNET_new(struct TestingContext); | 167 | test_ctx = GNUNET_new (struct TestingContext); |
166 | test_ctx->system = | 168 | test_ctx->system = |
167 | GNUNET_TESTING_system_create("test-gnunet-testing", | 169 | GNUNET_TESTING_system_create ("test-gnunet-testing", |
168 | "127.0.0.1", NULL, NULL); | 170 | "127.0.0.1", NULL, NULL); |
169 | emsg = NULL; | 171 | emsg = NULL; |
170 | if (NULL == test_ctx->system) | 172 | if (NULL == test_ctx->system) |
171 | goto end; | 173 | goto end; |
172 | test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg); | 174 | test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); |
173 | test_ctx->peer = | 175 | test_ctx->peer = |
174 | GNUNET_TESTING_peer_configure(test_ctx->system, | 176 | GNUNET_TESTING_peer_configure (test_ctx->system, |
175 | test_ctx->cfg, | 177 | test_ctx->cfg, |
176 | 0, &id, &emsg); | 178 | 0, &id, &emsg); |
177 | if (NULL == test_ctx->peer) | 179 | if (NULL == test_ctx->peer) |
178 | { | 180 | { |
179 | if (NULL != emsg) | 181 | if (NULL != emsg) |
180 | printf("Test failed upon error: %s", emsg); | 182 | printf ("Test failed upon error: %s", emsg); |
181 | goto end; | 183 | goto end; |
182 | } | 184 | } |
183 | if (GNUNET_OK != GNUNET_TESTING_peer_start(test_ctx->peer)) | 185 | if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) |
184 | goto end; | 186 | goto end; |
185 | test_ctx->state = PEER_STARTED; | 187 | test_ctx->state = PEER_STARTED; |
186 | FAIL_TEST(GNUNET_OK == | 188 | FAIL_TEST (GNUNET_OK == |
187 | GNUNET_TESTING_peer_stop_async(test_ctx->peer, | 189 | GNUNET_TESTING_peer_stop_async (test_ctx->peer, |
188 | &peer_status_cb, | 190 | &peer_status_cb, |
189 | test_ctx)); | 191 | test_ctx)); |
190 | GNUNET_TESTING_peer_stop_async_cancel(test_ctx->peer); | 192 | GNUNET_TESTING_peer_stop_async_cancel (test_ctx->peer); |
191 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | 193 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
192 | &do_shutdown, test_ctx); | 194 | &do_shutdown, test_ctx); |
193 | return; | 195 | return; |
194 | 196 | ||
195 | end: | 197 | end: |
196 | FAIL_TEST(0); | 198 | FAIL_TEST (0); |
197 | GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx); | 199 | GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); |
198 | GNUNET_free_non_null(emsg); | 200 | GNUNET_free_non_null (emsg); |
199 | } | 201 | } |
200 | 202 | ||
201 | 203 | ||
202 | int main(int argc, char *argv[]) | 204 | int main (int argc, char *argv[]) |
203 | { | 205 | { |
204 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 206 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
205 | GNUNET_GETOPT_OPTION_END | 207 | GNUNET_GETOPT_OPTION_END |
@@ -207,10 +209,10 @@ int main(int argc, char *argv[]) | |||
207 | 209 | ||
208 | status = GNUNET_OK; | 210 | status = GNUNET_OK; |
209 | if (GNUNET_OK != | 211 | if (GNUNET_OK != |
210 | GNUNET_PROGRAM_run(argc, argv, | 212 | GNUNET_PROGRAM_run (argc, argv, |
211 | "test_testing_new_peerstartup", | 213 | "test_testing_new_peerstartup", |
212 | "test case for peerstartup using new testing library", | 214 | "test case for peerstartup using new testing library", |
213 | options, &run, NULL)) | 215 | options, &run, NULL)) |
214 | return 1; | 216 | return 1; |
215 | return (GNUNET_OK == status) ? 0 : 1; | 217 | return (GNUNET_OK == status) ? 0 : 1; |
216 | } | 218 | } |