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