diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/peerstore/test_plugin_peerstore.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/peerstore/test_plugin_peerstore.c')
-rw-r--r-- | src/peerstore/test_plugin_peerstore.c | 205 |
1 files changed, 102 insertions, 103 deletions
diff --git a/src/peerstore/test_plugin_peerstore.c b/src/peerstore/test_plugin_peerstore.c index 24b5723ff..0664659a4 100644 --- a/src/peerstore/test_plugin_peerstore.c +++ b/src/peerstore/test_plugin_peerstore.c | |||
@@ -16,7 +16,7 @@ | |||
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 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /* | 20 | /* |
21 | * @file namestore/test_plugin_namestore.c | 21 | * @file namestore/test_plugin_namestore.c |
22 | * @brief Test for the namestore plugins | 22 | * @brief Test for the namestore plugins |
@@ -48,17 +48,17 @@ static struct GNUNET_PeerIdentity p1; | |||
48 | * @param api api to unload | 48 | * @param api api to unload |
49 | */ | 49 | */ |
50 | static void | 50 | static void |
51 | unload_plugin (struct GNUNET_PEERSTORE_PluginFunctions *api) | 51 | unload_plugin(struct GNUNET_PEERSTORE_PluginFunctions *api) |
52 | { | 52 | { |
53 | char *libname; | 53 | char *libname; |
54 | 54 | ||
55 | GNUNET_asprintf (&libname, | 55 | GNUNET_asprintf(&libname, |
56 | "libgnunet_plugin_peer_%s", | 56 | "libgnunet_plugin_peer_%s", |
57 | plugin_name); | 57 | plugin_name); |
58 | GNUNET_break (NULL == | 58 | GNUNET_break(NULL == |
59 | GNUNET_PLUGIN_unload (libname, | 59 | GNUNET_PLUGIN_unload(libname, |
60 | api)); | 60 | api)); |
61 | GNUNET_free (libname); | 61 | GNUNET_free(libname); |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
@@ -69,124 +69,123 @@ unload_plugin (struct GNUNET_PEERSTORE_PluginFunctions *api) | |||
69 | * @return NULL on error | 69 | * @return NULL on error |
70 | */ | 70 | */ |
71 | static struct GNUNET_PEERSTORE_PluginFunctions * | 71 | static struct GNUNET_PEERSTORE_PluginFunctions * |
72 | load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | 72 | load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg) |
73 | { | 73 | { |
74 | struct GNUNET_PEERSTORE_PluginFunctions *ret; | 74 | struct GNUNET_PEERSTORE_PluginFunctions *ret; |
75 | char *libname; | 75 | char *libname; |
76 | 76 | ||
77 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 77 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
78 | _("Loading `%s' peer plugin\n"), | 78 | _("Loading `%s' peer plugin\n"), |
79 | plugin_name); | ||
80 | GNUNET_asprintf (&libname, | ||
81 | "libgnunet_plugin_peerstore_%s", | ||
82 | plugin_name); | ||
83 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, | ||
84 | (void*) cfg))) | ||
85 | { | ||
86 | fprintf (stderr, | ||
87 | "Failed to load plugin `%s'!\n", | ||
88 | plugin_name); | 79 | plugin_name); |
89 | GNUNET_free (libname); | 80 | GNUNET_asprintf(&libname, |
90 | return NULL; | 81 | "libgnunet_plugin_peerstore_%s", |
91 | } | 82 | plugin_name); |
92 | GNUNET_free (libname); | 83 | if (NULL == (ret = GNUNET_PLUGIN_load(libname, |
84 | (void*)cfg))) | ||
85 | { | ||
86 | fprintf(stderr, | ||
87 | "Failed to load plugin `%s'!\n", | ||
88 | plugin_name); | ||
89 | GNUNET_free(libname); | ||
90 | return NULL; | ||
91 | } | ||
92 | GNUNET_free(libname); | ||
93 | return ret; | 93 | return ret; |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | static void | 97 | static void |
98 | test_record (void *cls, | 98 | test_record(void *cls, |
99 | const struct GNUNET_PEERSTORE_Record *record, | 99 | const struct GNUNET_PEERSTORE_Record *record, |
100 | const char *error) | 100 | const char *error) |
101 | { | 101 | { |
102 | const struct GNUNET_PeerIdentity *id = cls; | 102 | const struct GNUNET_PeerIdentity *id = cls; |
103 | const char* testval = "test_val"; | 103 | const char* testval = "test_val"; |
104 | 104 | ||
105 | if (NULL == record) | 105 | if (NULL == record) |
106 | { | 106 | { |
107 | unload_plugin (psp); | 107 | unload_plugin(psp); |
108 | return; | 108 | return; |
109 | } | 109 | } |
110 | GNUNET_assert (0 == memcmp (&record->peer, | 110 | GNUNET_assert(0 == memcmp(&record->peer, |
111 | id, | 111 | id, |
112 | sizeof (struct GNUNET_PeerIdentity))); | 112 | sizeof(struct GNUNET_PeerIdentity))); |
113 | GNUNET_assert (0 == strcmp ("subsys", | 113 | GNUNET_assert(0 == strcmp("subsys", |
114 | record->sub_system)); | 114 | record->sub_system)); |
115 | GNUNET_assert (0 == strcmp ("key", | 115 | GNUNET_assert(0 == strcmp("key", |
116 | record->key)); | 116 | record->key)); |
117 | GNUNET_assert (0 == memcmp (testval, | 117 | GNUNET_assert(0 == memcmp(testval, |
118 | record->value, | 118 | record->value, |
119 | strlen (testval))); | 119 | strlen(testval))); |
120 | ok = 0; | 120 | ok = 0; |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | static void | 124 | static void |
125 | get_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, | 125 | get_record(struct GNUNET_PEERSTORE_PluginFunctions *psp, |
126 | const struct GNUNET_PeerIdentity *identity) | 126 | const struct GNUNET_PeerIdentity *identity) |
127 | { | 127 | { |
128 | GNUNET_assert (GNUNET_OK == | 128 | GNUNET_assert(GNUNET_OK == |
129 | psp->iterate_records (psp->cls, | 129 | psp->iterate_records(psp->cls, |
130 | "subsys", | 130 | "subsys", |
131 | identity, | 131 | identity, |
132 | "key", | 132 | "key", |
133 | &test_record, | 133 | &test_record, |
134 | (void*)identity)); | 134 | (void*)identity)); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | static void | 138 | static void |
139 | store_cont (void *cls, | 139 | store_cont(void *cls, |
140 | int status) | 140 | int status) |
141 | { | 141 | { |
142 | GNUNET_assert (GNUNET_OK == status); | 142 | GNUNET_assert(GNUNET_OK == status); |
143 | get_record (psp, | 143 | get_record(psp, |
144 | &p1); | 144 | &p1); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | static void | 148 | static void |
149 | put_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, | 149 | put_record(struct GNUNET_PEERSTORE_PluginFunctions *psp, |
150 | const struct GNUNET_PeerIdentity *identity) | 150 | const struct GNUNET_PeerIdentity *identity) |
151 | { | 151 | { |
152 | GNUNET_assert (GNUNET_OK == | 152 | GNUNET_assert(GNUNET_OK == |
153 | psp->store_record (psp->cls, | 153 | psp->store_record(psp->cls, |
154 | "subsys", | 154 | "subsys", |
155 | identity, | 155 | identity, |
156 | "key", | 156 | "key", |
157 | "test_value", | 157 | "test_value", |
158 | strlen ("test_value"), | 158 | strlen("test_value"), |
159 | GNUNET_TIME_absolute_get (), | 159 | GNUNET_TIME_absolute_get(), |
160 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 160 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
161 | &store_cont, | 161 | &store_cont, |
162 | NULL)); | 162 | NULL)); |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | static void | 166 | static void |
167 | run (void *cls, | 167 | run(void *cls, |
168 | char *const *args, | 168 | char *const *args, |
169 | const char *cfgfile, | 169 | const char *cfgfile, |
170 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 170 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
171 | { | 171 | { |
172 | |||
173 | ok = 1; | 172 | ok = 1; |
174 | psp = load_plugin (cfg); | 173 | psp = load_plugin(cfg); |
175 | if (NULL == psp) | 174 | if (NULL == psp) |
176 | { | 175 | { |
177 | fprintf (stderr, | 176 | fprintf(stderr, |
178 | "%s", | 177 | "%s", |
179 | "Failed to initialize peerstore. Database likely not setup, skipping test.\n"); | 178 | "Failed to initialize peerstore. Database likely not setup, skipping test.\n"); |
180 | return; | 179 | return; |
181 | } | 180 | } |
182 | memset (&p1, 1, sizeof (p1)); | 181 | memset(&p1, 1, sizeof(p1)); |
183 | put_record (psp, | 182 | put_record(psp, |
184 | &p1); | 183 | &p1); |
185 | } | 184 | } |
186 | 185 | ||
187 | 186 | ||
188 | int | 187 | int |
189 | main (int argc, char *argv[]) | 188 | main(int argc, char *argv[]) |
190 | { | 189 | { |
191 | char cfg_name[PATH_MAX]; | 190 | char cfg_name[PATH_MAX]; |
192 | char *const xargv[] = { | 191 | char *const xargv[] = { |
@@ -199,25 +198,25 @@ main (int argc, char *argv[]) | |||
199 | GNUNET_GETOPT_OPTION_END | 198 | GNUNET_GETOPT_OPTION_END |
200 | }; | 199 | }; |
201 | 200 | ||
202 | GNUNET_log_setup ("test-plugin-peerstore", | 201 | GNUNET_log_setup("test-plugin-peerstore", |
203 | "WARNING", | 202 | "WARNING", |
204 | NULL); | 203 | NULL); |
205 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 204 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); |
206 | GNUNET_snprintf (cfg_name, | 205 | GNUNET_snprintf(cfg_name, |
207 | sizeof (cfg_name), | 206 | sizeof(cfg_name), |
208 | "test_plugin_peerstore_%s.conf", | 207 | "test_plugin_peerstore_%s.conf", |
209 | plugin_name); | 208 | plugin_name); |
210 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, | 209 | GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, |
211 | xargv, | 210 | xargv, |
212 | "test-plugin-peerstore", | 211 | "test-plugin-peerstore", |
213 | "nohelp", | 212 | "nohelp", |
214 | options, | 213 | options, |
215 | &run, | 214 | &run, |
216 | NULL); | 215 | NULL); |
217 | if (ok != 0) | 216 | if (ok != 0) |
218 | fprintf (stderr, | 217 | fprintf(stderr, |
219 | "Missed some testcases: %d\n", | 218 | "Missed some testcases: %d\n", |
220 | ok); | 219 | ok); |
221 | return ok; | 220 | return ok; |
222 | } | 221 | } |
223 | 222 | ||