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/my/test_my.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/my/test_my.c')
-rw-r--r-- | src/my/test_my.c | 366 |
1 files changed, 183 insertions, 183 deletions
diff --git a/src/my/test_my.c b/src/my/test_my.c index 556d2baa2..d9dcc71f9 100644 --- a/src/my/test_my.c +++ b/src/my/test_my.c | |||
@@ -11,12 +11,12 @@ | |||
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 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file my/test_my.c | 21 | * @file my/test_my.c |
22 | * @brief Tests for convenience MySQL database | 22 | * @brief Tests for convenience MySQL database |
@@ -30,23 +30,23 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Run actual test queries. | 33 | * Run actual test queries. |
34 | * | 34 | * |
35 | * @param contexte the current context of mysql | 35 | * @param contexte the current context of mysql |
36 | * @return 0 on succes | 36 | * @return 0 on succes |
37 | */ | 37 | */ |
38 | static int | 38 | static int |
39 | run_queries (struct GNUNET_MYSQL_Context *context) | 39 | run_queries(struct GNUNET_MYSQL_Context *context) |
40 | { | 40 | { |
41 | struct GNUNET_CRYPTO_RsaPublicKey *pub = NULL; | 41 | struct GNUNET_CRYPTO_RsaPublicKey *pub = NULL; |
42 | struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; | 42 | struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; |
43 | struct GNUNET_CRYPTO_RsaSignature *sig = NULL;; | 43 | struct GNUNET_CRYPTO_RsaSignature *sig = NULL;; |
44 | struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; | 44 | struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; |
45 | struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get (); | 45 | struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get(); |
46 | struct GNUNET_TIME_Absolute abs_time2; | 46 | struct GNUNET_TIME_Absolute abs_time2; |
47 | struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; | 47 | struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; |
48 | struct GNUNET_TIME_Absolute forever2; | 48 | struct GNUNET_TIME_Absolute forever2; |
49 | const struct GNUNET_TIME_AbsoluteNBO abs_time_nbo = GNUNET_TIME_absolute_hton (abs_time); | 49 | const struct GNUNET_TIME_AbsoluteNBO abs_time_nbo = GNUNET_TIME_absolute_hton(abs_time); |
50 | struct GNUNET_HashCode hc; | 50 | struct GNUNET_HashCode hc; |
51 | struct GNUNET_HashCode hc2; | 51 | struct GNUNET_HashCode hc2; |
52 | const char msg[] = "hello"; | 52 | const char msg[] = "hello"; |
@@ -71,163 +71,163 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
71 | struct GNUNET_CRYPTO_RsaPrivateKey *priv = NULL; | 71 | struct GNUNET_CRYPTO_RsaPrivateKey *priv = NULL; |
72 | struct GNUNET_HashCode hmsg; | 72 | struct GNUNET_HashCode hmsg; |
73 | 73 | ||
74 | priv = GNUNET_CRYPTO_rsa_private_key_create (1024); | 74 | priv = GNUNET_CRYPTO_rsa_private_key_create(1024); |
75 | pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); | 75 | pub = GNUNET_CRYPTO_rsa_private_key_get_public(priv); |
76 | memset (&hmsg, 42, sizeof(hmsg)); | 76 | memset(&hmsg, 42, sizeof(hmsg)); |
77 | sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, | 77 | sig = GNUNET_CRYPTO_rsa_sign_fdh(priv, |
78 | &hmsg); | 78 | &hmsg); |
79 | u16 = 16; | 79 | u16 = 16; |
80 | u32 = 32; | 80 | u32 = 32; |
81 | u64 = UINT64_MAX; | 81 | u64 = UINT64_MAX; |
82 | 82 | ||
83 | memset (&hc, 0, sizeof(hc)); | 83 | memset(&hc, 0, sizeof(hc)); |
84 | memset (&hc2, 0, sizeof(hc2)); | 84 | memset(&hc2, 0, sizeof(hc2)); |
85 | 85 | ||
86 | statements_handle_insert | 86 | statements_handle_insert |
87 | = GNUNET_MYSQL_statement_prepare (context, | 87 | = GNUNET_MYSQL_statement_prepare(context, |
88 | "INSERT INTO test_my2 (" | 88 | "INSERT INTO test_my2 (" |
89 | " pub" | 89 | " pub" |
90 | ",sig" | 90 | ",sig" |
91 | ",abs_time" | 91 | ",abs_time" |
92 | ",forever" | 92 | ",forever" |
93 | ",abs_time_nbo" | 93 | ",abs_time_nbo" |
94 | ",hash" | 94 | ",hash" |
95 | ",vsize" | 95 | ",vsize" |
96 | ",str" | 96 | ",str" |
97 | ",u16" | 97 | ",u16" |
98 | ",u32" | 98 | ",u32" |
99 | ",u64" | 99 | ",u64" |
100 | ") VALUES " | 100 | ") VALUES " |
101 | "( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); | 101 | "( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); |
102 | 102 | ||
103 | if (NULL == statements_handle_insert) | 103 | if (NULL == statements_handle_insert) |
104 | { | 104 | { |
105 | fprintf (stderr, "Failed to prepared statement INSERT\n"); | 105 | fprintf(stderr, "Failed to prepared statement INSERT\n"); |
106 | GNUNET_CRYPTO_rsa_signature_free (sig); | 106 | GNUNET_CRYPTO_rsa_signature_free(sig); |
107 | GNUNET_CRYPTO_rsa_private_key_free (priv); | 107 | GNUNET_CRYPTO_rsa_private_key_free(priv); |
108 | GNUNET_CRYPTO_rsa_public_key_free (pub); | 108 | GNUNET_CRYPTO_rsa_public_key_free(pub); |
109 | return 1; | 109 | return 1; |
110 | } | 110 | } |
111 | 111 | ||
112 | struct GNUNET_MY_QueryParam params_insert[] = { | 112 | struct GNUNET_MY_QueryParam params_insert[] = { |
113 | GNUNET_MY_query_param_rsa_public_key (pub), | 113 | GNUNET_MY_query_param_rsa_public_key(pub), |
114 | GNUNET_MY_query_param_rsa_signature (sig), | 114 | GNUNET_MY_query_param_rsa_signature(sig), |
115 | GNUNET_MY_query_param_absolute_time (&abs_time), | 115 | GNUNET_MY_query_param_absolute_time(&abs_time), |
116 | GNUNET_MY_query_param_absolute_time (&forever), | 116 | GNUNET_MY_query_param_absolute_time(&forever), |
117 | GNUNET_MY_query_param_absolute_time_nbo (&abs_time_nbo), | 117 | GNUNET_MY_query_param_absolute_time_nbo(&abs_time_nbo), |
118 | GNUNET_MY_query_param_auto_from_type (&hc), | 118 | GNUNET_MY_query_param_auto_from_type(&hc), |
119 | GNUNET_MY_query_param_fixed_size (msg, strlen (msg)), | 119 | GNUNET_MY_query_param_fixed_size(msg, strlen(msg)), |
120 | GNUNET_MY_query_param_string (msg3), | 120 | GNUNET_MY_query_param_string(msg3), |
121 | GNUNET_MY_query_param_uint16 (&u16), | 121 | GNUNET_MY_query_param_uint16(&u16), |
122 | GNUNET_MY_query_param_uint32 (&u32), | 122 | GNUNET_MY_query_param_uint32(&u32), |
123 | GNUNET_MY_query_param_uint64 (&u64), | 123 | GNUNET_MY_query_param_uint64(&u64), |
124 | GNUNET_MY_query_param_end | 124 | GNUNET_MY_query_param_end |
125 | }; | 125 | }; |
126 | 126 | ||
127 | if (GNUNET_OK != GNUNET_MY_exec_prepared(context, | 127 | if (GNUNET_OK != GNUNET_MY_exec_prepared(context, |
128 | statements_handle_insert, | 128 | statements_handle_insert, |
129 | params_insert)) | 129 | params_insert)) |
130 | { | 130 | { |
131 | fprintf (stderr, "Failed to execute prepared statement INSERT\n"); | 131 | fprintf(stderr, "Failed to execute prepared statement INSERT\n"); |
132 | GNUNET_CRYPTO_rsa_signature_free (sig); | 132 | GNUNET_CRYPTO_rsa_signature_free(sig); |
133 | GNUNET_CRYPTO_rsa_private_key_free (priv); | 133 | GNUNET_CRYPTO_rsa_private_key_free(priv); |
134 | GNUNET_CRYPTO_rsa_public_key_free (pub); | 134 | GNUNET_CRYPTO_rsa_public_key_free(pub); |
135 | return 1; | 135 | return 1; |
136 | } | 136 | } |
137 | 137 | ||
138 | statements_handle_select | 138 | statements_handle_select |
139 | = GNUNET_MYSQL_statement_prepare (context, | 139 | = GNUNET_MYSQL_statement_prepare(context, |
140 | "SELECT" | 140 | "SELECT" |
141 | " pub" | 141 | " pub" |
142 | ",sig" | 142 | ",sig" |
143 | ",abs_time" | 143 | ",abs_time" |
144 | ",forever" | 144 | ",forever" |
145 | ",hash" | 145 | ",hash" |
146 | ",vsize" | 146 | ",vsize" |
147 | ",str" | 147 | ",str" |
148 | ",u16" | 148 | ",u16" |
149 | ",u32" | 149 | ",u32" |
150 | ",u64" | 150 | ",u64" |
151 | " FROM test_my2"); | 151 | " FROM test_my2"); |
152 | 152 | ||
153 | if (NULL == statements_handle_select) | 153 | if (NULL == statements_handle_select) |
154 | { | 154 | { |
155 | fprintf(stderr, "Failed to prepared statement SELECT\n"); | 155 | fprintf(stderr, "Failed to prepared statement SELECT\n"); |
156 | GNUNET_CRYPTO_rsa_signature_free (sig); | 156 | GNUNET_CRYPTO_rsa_signature_free(sig); |
157 | GNUNET_CRYPTO_rsa_private_key_free (priv); | 157 | GNUNET_CRYPTO_rsa_private_key_free(priv); |
158 | GNUNET_CRYPTO_rsa_public_key_free (pub); | 158 | GNUNET_CRYPTO_rsa_public_key_free(pub); |
159 | return 1; | 159 | return 1; |
160 | } | 160 | } |
161 | 161 | ||
162 | struct GNUNET_MY_QueryParam params_select[] = { | 162 | struct GNUNET_MY_QueryParam params_select[] = { |
163 | GNUNET_MY_query_param_end | 163 | GNUNET_MY_query_param_end |
164 | }; | 164 | }; |
165 | 165 | ||
166 | if (GNUNET_OK != GNUNET_MY_exec_prepared (context, | 166 | if (GNUNET_OK != GNUNET_MY_exec_prepared(context, |
167 | statements_handle_select, | 167 | statements_handle_select, |
168 | params_select)) | 168 | params_select)) |
169 | { | 169 | { |
170 | fprintf (stderr, "Failed to execute prepared statement SELECT\n"); | 170 | fprintf(stderr, "Failed to execute prepared statement SELECT\n"); |
171 | GNUNET_CRYPTO_rsa_signature_free (sig); | 171 | GNUNET_CRYPTO_rsa_signature_free(sig); |
172 | GNUNET_CRYPTO_rsa_private_key_free (priv); | 172 | GNUNET_CRYPTO_rsa_private_key_free(priv); |
173 | GNUNET_CRYPTO_rsa_public_key_free (pub); | 173 | GNUNET_CRYPTO_rsa_public_key_free(pub); |
174 | return 1; | 174 | return 1; |
175 | } | 175 | } |
176 | 176 | ||
177 | struct GNUNET_MY_ResultSpec results_select[] = { | 177 | struct GNUNET_MY_ResultSpec results_select[] = { |
178 | GNUNET_MY_result_spec_rsa_public_key (&pub2), | 178 | GNUNET_MY_result_spec_rsa_public_key(&pub2), |
179 | GNUNET_MY_result_spec_rsa_signature (&sig2), | 179 | GNUNET_MY_result_spec_rsa_signature(&sig2), |
180 | GNUNET_MY_result_spec_absolute_time (&abs_time2), | 180 | GNUNET_MY_result_spec_absolute_time(&abs_time2), |
181 | GNUNET_MY_result_spec_absolute_time (&forever2), | 181 | GNUNET_MY_result_spec_absolute_time(&forever2), |
182 | GNUNET_MY_result_spec_auto_from_type (&hc2), | 182 | GNUNET_MY_result_spec_auto_from_type(&hc2), |
183 | GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), | 183 | GNUNET_MY_result_spec_variable_size(&msg2, &msg2_len), |
184 | GNUNET_MY_result_spec_string (&msg4), | 184 | GNUNET_MY_result_spec_string(&msg4), |
185 | GNUNET_MY_result_spec_uint16 (&u162), | 185 | GNUNET_MY_result_spec_uint16(&u162), |
186 | GNUNET_MY_result_spec_uint32 (&u322), | 186 | GNUNET_MY_result_spec_uint32(&u322), |
187 | GNUNET_MY_result_spec_uint64 (&u642), | 187 | GNUNET_MY_result_spec_uint64(&u642), |
188 | GNUNET_MY_result_spec_end | 188 | GNUNET_MY_result_spec_end |
189 | }; | 189 | }; |
190 | 190 | ||
191 | ret = GNUNET_MY_extract_result (statements_handle_select, | 191 | ret = GNUNET_MY_extract_result(statements_handle_select, |
192 | results_select); | 192 | results_select); |
193 | 193 | ||
194 | GNUNET_assert (GNUNET_YES == ret); | 194 | GNUNET_assert(GNUNET_YES == ret); |
195 | GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us); | 195 | GNUNET_break(abs_time.abs_value_us == abs_time2.abs_value_us); |
196 | GNUNET_break (forever.abs_value_us == forever2.abs_value_us); | 196 | GNUNET_break(forever.abs_value_us == forever2.abs_value_us); |
197 | GNUNET_break (0 == | 197 | GNUNET_break(0 == |
198 | memcmp (&hc, | 198 | memcmp(&hc, |
199 | &hc2, | 199 | &hc2, |
200 | sizeof (struct GNUNET_HashCode))); | 200 | sizeof(struct GNUNET_HashCode))); |
201 | 201 | ||
202 | GNUNET_assert (NULL != sig2); | 202 | GNUNET_assert(NULL != sig2); |
203 | GNUNET_assert (NULL != pub2); | 203 | GNUNET_assert(NULL != pub2); |
204 | GNUNET_break (0 == | 204 | GNUNET_break(0 == |
205 | GNUNET_CRYPTO_rsa_signature_cmp (sig, | 205 | GNUNET_CRYPTO_rsa_signature_cmp(sig, |
206 | sig2)); | 206 | sig2)); |
207 | GNUNET_break (0 == | 207 | GNUNET_break(0 == |
208 | GNUNET_CRYPTO_rsa_public_key_cmp (pub, | 208 | GNUNET_CRYPTO_rsa_public_key_cmp(pub, |
209 | pub2)); | 209 | pub2)); |
210 | 210 | ||
211 | GNUNET_break (strlen (msg) == msg2_len); | 211 | GNUNET_break(strlen(msg) == msg2_len); |
212 | GNUNET_break (0 == | 212 | GNUNET_break(0 == |
213 | strncmp (msg, | 213 | strncmp(msg, |
214 | msg2, | 214 | msg2, |
215 | msg2_len)); | 215 | msg2_len)); |
216 | 216 | ||
217 | GNUNET_break (strlen (msg3) == strlen(msg4)); | 217 | GNUNET_break(strlen(msg3) == strlen(msg4)); |
218 | GNUNET_break (0 == | 218 | GNUNET_break(0 == |
219 | strcmp (msg3, | 219 | strcmp(msg3, |
220 | msg4)); | 220 | msg4)); |
221 | 221 | ||
222 | GNUNET_break (16 == u162); | 222 | GNUNET_break(16 == u162); |
223 | GNUNET_break (32 == u322); | 223 | GNUNET_break(32 == u322); |
224 | GNUNET_break (UINT64_MAX == u642); | 224 | GNUNET_break(UINT64_MAX == u642); |
225 | 225 | ||
226 | GNUNET_MY_cleanup_result (results_select); | 226 | GNUNET_MY_cleanup_result(results_select); |
227 | 227 | ||
228 | GNUNET_CRYPTO_rsa_signature_free (sig); | 228 | GNUNET_CRYPTO_rsa_signature_free(sig); |
229 | GNUNET_CRYPTO_rsa_private_key_free (priv); | 229 | GNUNET_CRYPTO_rsa_private_key_free(priv); |
230 | GNUNET_CRYPTO_rsa_public_key_free (pub); | 230 | GNUNET_CRYPTO_rsa_public_key_free(pub); |
231 | 231 | ||
232 | if (GNUNET_OK != ret) | 232 | if (GNUNET_OK != ret) |
233 | return 1; | 233 | return 1; |
@@ -237,63 +237,63 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
237 | 237 | ||
238 | 238 | ||
239 | int | 239 | int |
240 | main (int argc, const char *const argv[]) | 240 | main(int argc, const char *const argv[]) |
241 | { | 241 | { |
242 | struct GNUNET_CONFIGURATION_Handle *config; | 242 | struct GNUNET_CONFIGURATION_Handle *config; |
243 | struct GNUNET_MYSQL_Context *context; | 243 | struct GNUNET_MYSQL_Context *context; |
244 | int ret; | 244 | int ret; |
245 | 245 | ||
246 | GNUNET_log_setup ("test-my", | 246 | GNUNET_log_setup("test-my", |
247 | "WARNING", | 247 | "WARNING", |
248 | NULL); | 248 | NULL); |
249 | 249 | ||
250 | config = GNUNET_CONFIGURATION_create (); | 250 | config = GNUNET_CONFIGURATION_create(); |
251 | if (GNUNET_OK != | 251 | if (GNUNET_OK != |
252 | GNUNET_CONFIGURATION_parse (config, "test_my.conf")) | 252 | GNUNET_CONFIGURATION_parse(config, "test_my.conf")) |
253 | { | 253 | { |
254 | fprintf (stderr, "Failed to parse configuaration\n"); | 254 | fprintf(stderr, "Failed to parse configuaration\n"); |
255 | return 1; | 255 | return 1; |
256 | } | 256 | } |
257 | 257 | ||
258 | context = GNUNET_MYSQL_context_create (config, | 258 | context = GNUNET_MYSQL_context_create(config, |
259 | "datastore-mysql"); | 259 | "datastore-mysql"); |
260 | if (NULL == context) | 260 | if (NULL == context) |
261 | { | 261 | { |
262 | fprintf(stderr, "Failed to connect to database\n"); | 262 | fprintf(stderr, "Failed to connect to database\n"); |
263 | return 77; | 263 | return 77; |
264 | } | 264 | } |
265 | 265 | ||
266 | (void) GNUNET_MYSQL_statement_run (context, | 266 | (void)GNUNET_MYSQL_statement_run(context, |
267 | "DROP TABLE test_my2;"); | 267 | "DROP TABLE test_my2;"); |
268 | 268 | ||
269 | if (GNUNET_OK != | 269 | if (GNUNET_OK != |
270 | GNUNET_MYSQL_statement_run (context, | 270 | GNUNET_MYSQL_statement_run(context, |
271 | "CREATE TABLE IF NOT EXISTS test_my2(" | 271 | "CREATE TABLE IF NOT EXISTS test_my2(" |
272 | " pub BLOB NOT NULL" | 272 | " pub BLOB NOT NULL" |
273 | ",sig BLOB NOT NULL" | 273 | ",sig BLOB NOT NULL" |
274 | ",abs_time BIGINT NOT NULL" | 274 | ",abs_time BIGINT NOT NULL" |
275 | ",forever BIGINT NOT NULL" | 275 | ",forever BIGINT NOT NULL" |
276 | ",abs_time_nbo BIGINT NOT NULL" | 276 | ",abs_time_nbo BIGINT NOT NULL" |
277 | ",hash BLOB NOT NULL CHECK(LENGTH(hash)=64)" | 277 | ",hash BLOB NOT NULL CHECK(LENGTH(hash)=64)" |
278 | ",vsize BLOB NOT NULL" | 278 | ",vsize BLOB NOT NULL" |
279 | ",str BLOB NOT NULL" | 279 | ",str BLOB NOT NULL" |
280 | ",u16 SMALLINT NOT NULL" | 280 | ",u16 SMALLINT NOT NULL" |
281 | ",u32 INT NOT NULL" | 281 | ",u32 INT NOT NULL" |
282 | ",u64 BIGINT NOT NULL" | 282 | ",u64 BIGINT NOT NULL" |
283 | ")")) | 283 | ")")) |
284 | { | 284 | { |
285 | fprintf (stderr, | 285 | fprintf(stderr, |
286 | "Failed to create table. Database likely not setup correctly.\n"); | 286 | "Failed to create table. Database likely not setup correctly.\n"); |
287 | GNUNET_MYSQL_statements_invalidate (context); | 287 | GNUNET_MYSQL_statements_invalidate(context); |
288 | GNUNET_MYSQL_context_destroy (context); | 288 | GNUNET_MYSQL_context_destroy(context); |
289 | 289 | ||
290 | return 77; | 290 | return 77; |
291 | } | 291 | } |
292 | 292 | ||
293 | ret = run_queries (context); | 293 | ret = run_queries(context); |
294 | 294 | ||
295 | GNUNET_MYSQL_context_destroy (context); | 295 | GNUNET_MYSQL_context_destroy(context); |
296 | GNUNET_free (config); | 296 | GNUNET_free(config); |
297 | 297 | ||
298 | return ret; | 298 | return ret; |
299 | } | 299 | } |