summaryrefslogtreecommitdiff
path: root/src/testing/test_testing_peerstartup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/test_testing_peerstartup.c')
-rw-r--r--src/testing/test_testing_peerstartup.c73
1 files changed, 36 insertions, 37 deletions
diff --git a/src/testing/test_testing_peerstartup.c b/src/testing/test_testing_peerstartup.c
index 241bc63a7..a03e6b596 100644
--- a/src/testing/test_testing_peerstartup.c
+++ b/src/testing/test_testing_peerstartup.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,8 +29,8 @@
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 * The status of the test 36 * The status of the test
@@ -40,8 +40,7 @@ int status;
40/** 40/**
41 * The testing context 41 * The testing context
42 */ 42 */
43struct TestingContext 43struct TestingContext {
44{
45 /** 44 /**
46 * The testing system 45 * The testing system
47 */ 46 */
@@ -65,21 +64,21 @@ struct TestingContext
65 * @param cls the testing context 64 * @param cls the testing context
66 */ 65 */
67static void 66static void
68do_shutdown (void *cls) 67do_shutdown(void *cls)
69{ 68{
70 struct TestingContext *test_ctx = cls; 69 struct TestingContext *test_ctx = cls;
71 70
72 GNUNET_assert (NULL != test_ctx); 71 GNUNET_assert(NULL != test_ctx);
73 if (NULL != test_ctx->peer) 72 if (NULL != test_ctx->peer)
74 { 73 {
75 (void) GNUNET_TESTING_peer_stop (test_ctx->peer); 74 (void)GNUNET_TESTING_peer_stop(test_ctx->peer);
76 GNUNET_TESTING_peer_destroy (test_ctx->peer); 75 GNUNET_TESTING_peer_destroy(test_ctx->peer);
77 } 76 }
78 if (NULL != test_ctx->cfg) 77 if (NULL != test_ctx->cfg)
79 GNUNET_CONFIGURATION_destroy (test_ctx->cfg); 78 GNUNET_CONFIGURATION_destroy(test_ctx->cfg);
80 if (NULL != test_ctx->system) 79 if (NULL != test_ctx->system)
81 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); 80 GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES);
82 GNUNET_free (test_ctx); 81 GNUNET_free(test_ctx);
83} 82}
84 83
85 84
@@ -87,42 +86,42 @@ do_shutdown (void *cls)
87 * Main point of test execution 86 * Main point of test execution
88 */ 87 */
89static void 88static void
90run (void *cls, char *const *args, const char *cfgfile, 89run(void *cls, char *const *args, const char *cfgfile,
91 const struct GNUNET_CONFIGURATION_Handle *cfg) 90 const struct GNUNET_CONFIGURATION_Handle *cfg)
92{ 91{
93 struct TestingContext *test_ctx; 92 struct TestingContext *test_ctx;
94 char *emsg; 93 char *emsg;
95 struct GNUNET_PeerIdentity id; 94 struct GNUNET_PeerIdentity id;
96 95
97 test_ctx = GNUNET_new (struct TestingContext); 96 test_ctx = GNUNET_new(struct TestingContext);
98 test_ctx->system = 97 test_ctx->system =
99 GNUNET_TESTING_system_create ("test-gnunet-testing", 98 GNUNET_TESTING_system_create("test-gnunet-testing",
100 "127.0.0.1", NULL, NULL); 99 "127.0.0.1", NULL, NULL);
101 emsg = NULL; 100 emsg = NULL;
102 if (NULL == test_ctx->system) 101 if (NULL == test_ctx->system)
103 goto end; 102 goto end;
104 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); 103 test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg);
105 test_ctx->peer = 104 test_ctx->peer =
106 GNUNET_TESTING_peer_configure (test_ctx->system, 105 GNUNET_TESTING_peer_configure(test_ctx->system,
107 test_ctx->cfg, 106 test_ctx->cfg,
108 0, &id, &emsg); 107 0, &id, &emsg);
109 if (NULL == test_ctx->peer) 108 if (NULL == test_ctx->peer)
110 { 109 {
111 if (NULL != emsg) 110 if (NULL != emsg)
112 printf ("Test failed upon error: %s", emsg); 111 printf("Test failed upon error: %s", emsg);
113 goto end; 112 goto end;
114 } 113 }
115 if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) 114 if (GNUNET_OK != GNUNET_TESTING_peer_start(test_ctx->peer))
116 goto end; 115 goto end;
117 status = GNUNET_OK; 116 status = GNUNET_OK;
118 117
119 end: 118end:
120 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); 119 GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx);
121 GNUNET_free_non_null (emsg); 120 GNUNET_free_non_null(emsg);
122} 121}
123 122
124 123
125int main (int argc, char *argv[]) 124int main(int argc, char *argv[])
126{ 125{
127 struct GNUNET_GETOPT_CommandLineOption options[] = { 126 struct GNUNET_GETOPT_CommandLineOption options[] = {
128 GNUNET_GETOPT_OPTION_END 127 GNUNET_GETOPT_OPTION_END
@@ -130,10 +129,10 @@ int main (int argc, char *argv[])
130 129
131 status = GNUNET_SYSERR; 130 status = GNUNET_SYSERR;
132 if (GNUNET_OK != 131 if (GNUNET_OK !=
133 GNUNET_PROGRAM_run (argc, argv, 132 GNUNET_PROGRAM_run(argc, argv,
134 "test_testing_peerstartup", 133 "test_testing_peerstartup",
135 "test case for peerstartup using new testing library", 134 "test case for peerstartup using new testing library",
136 options, &run, NULL)) 135 options, &run, NULL))
137 return 1; 136 return 1;
138 return (GNUNET_OK == status) ? 0 : 1; 137 return (GNUNET_OK == status) ? 0 : 1;
139} 138}