diff options
Diffstat (limited to 'src/sq/test_sq.c')
-rw-r--r-- | src/sq/test_sq.c | 340 |
1 files changed, 170 insertions, 170 deletions
diff --git a/src/sq/test_sq.c b/src/sq/test_sq.c index 4c81bd5c3..e5187b55a 100644 --- a/src/sq/test_sq.c +++ b/src/sq/test_sq.c | |||
@@ -36,23 +36,23 @@ | |||
36 | * @return 0 on success | 36 | * @return 0 on success |
37 | */ | 37 | */ |
38 | static int | 38 | static int |
39 | sq_prepare(sqlite3 *dbh, | 39 | sq_prepare (sqlite3 *dbh, |
40 | const char *zSql, | 40 | const char *zSql, |
41 | sqlite3_stmt **ppStmt) | 41 | sqlite3_stmt **ppStmt) |
42 | { | 42 | { |
43 | char *dummy; | 43 | char *dummy; |
44 | int result; | 44 | int result; |
45 | 45 | ||
46 | result = sqlite3_prepare_v2(dbh, | 46 | result = sqlite3_prepare_v2 (dbh, |
47 | zSql, | 47 | zSql, |
48 | strlen(zSql), | 48 | strlen (zSql), |
49 | ppStmt, | 49 | ppStmt, |
50 | (const char **)&dummy); | 50 | (const char **) &dummy); |
51 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 51 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
52 | "Prepared `%s' / %p: %d\n", | 52 | "Prepared `%s' / %p: %d\n", |
53 | zSql, | 53 | zSql, |
54 | *ppStmt, | 54 | *ppStmt, |
55 | result); | 55 | result); |
56 | return result; | 56 | return result; |
57 | } | 57 | } |
58 | 58 | ||
@@ -63,13 +63,13 @@ sq_prepare(sqlite3 *dbh, | |||
63 | * @return 0 on success | 63 | * @return 0 on success |
64 | */ | 64 | */ |
65 | static int | 65 | static int |
66 | run_queries(sqlite3 *dbh) | 66 | run_queries (sqlite3 *dbh) |
67 | { | 67 | { |
68 | struct GNUNET_CRYPTO_RsaPublicKey *pub; | 68 | struct GNUNET_CRYPTO_RsaPublicKey *pub; |
69 | struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; | 69 | struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; |
70 | struct GNUNET_CRYPTO_RsaSignature *sig; | 70 | struct GNUNET_CRYPTO_RsaSignature *sig; |
71 | struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; | 71 | struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; |
72 | struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get(); | 72 | struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get (); |
73 | struct GNUNET_TIME_Absolute abs_time2; | 73 | struct GNUNET_TIME_Absolute abs_time2; |
74 | struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; | 74 | struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; |
75 | struct GNUNET_TIME_Absolute forever2; | 75 | struct GNUNET_TIME_Absolute forever2; |
@@ -88,199 +88,199 @@ run_queries(sqlite3 *dbh) | |||
88 | uint64_t u64; | 88 | uint64_t u64; |
89 | uint64_t u642; | 89 | uint64_t u642; |
90 | 90 | ||
91 | priv = GNUNET_CRYPTO_rsa_private_key_create(1024); | 91 | priv = GNUNET_CRYPTO_rsa_private_key_create (1024); |
92 | pub = GNUNET_CRYPTO_rsa_private_key_get_public(priv); | 92 | pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); |
93 | memset(&hmsg, 42, sizeof(hmsg)); | 93 | memset (&hmsg, 42, sizeof(hmsg)); |
94 | sig = GNUNET_CRYPTO_rsa_sign_fdh(priv, | 94 | sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, |
95 | &hmsg); | 95 | &hmsg); |
96 | u16 = 16; | 96 | u16 = 16; |
97 | u32 = 32; | 97 | u32 = 32; |
98 | u64 = 64; | 98 | u64 = 64; |
99 | /* FIXME: test GNUNET_SQ_result_spec_variable_size */ | 99 | /* FIXME: test GNUNET_SQ_result_spec_variable_size */ |
100 | 100 | ||
101 | sq_prepare(dbh, | 101 | sq_prepare (dbh, |
102 | "INSERT INTO test_sq (" | 102 | "INSERT INTO test_sq (" |
103 | " pub" | 103 | " pub" |
104 | ",sig" | 104 | ",sig" |
105 | ",abs_time" | 105 | ",abs_time" |
106 | ",forever" | 106 | ",forever" |
107 | ",hash" | 107 | ",hash" |
108 | ",vsize" | 108 | ",vsize" |
109 | ",u16" | 109 | ",u16" |
110 | ",u32" | 110 | ",u32" |
111 | ",u64" | 111 | ",u64" |
112 | ") VALUES " | 112 | ") VALUES " |
113 | "($1, $2, $3, $4, $5, $6," | 113 | "($1, $2, $3, $4, $5, $6," |
114 | "$7, $8, $9);", | 114 | "$7, $8, $9);", |
115 | &stmt); | 115 | &stmt); |
116 | { | 116 | { |
117 | struct GNUNET_SQ_QueryParam params_insert[] = { | 117 | struct GNUNET_SQ_QueryParam params_insert[] = { |
118 | GNUNET_SQ_query_param_rsa_public_key(pub), | 118 | GNUNET_SQ_query_param_rsa_public_key (pub), |
119 | GNUNET_SQ_query_param_rsa_signature(sig), | 119 | GNUNET_SQ_query_param_rsa_signature (sig), |
120 | GNUNET_SQ_query_param_absolute_time(&abs_time), | 120 | GNUNET_SQ_query_param_absolute_time (&abs_time), |
121 | GNUNET_SQ_query_param_absolute_time(&forever), | 121 | GNUNET_SQ_query_param_absolute_time (&forever), |
122 | GNUNET_SQ_query_param_auto_from_type(&hc), | 122 | GNUNET_SQ_query_param_auto_from_type (&hc), |
123 | GNUNET_SQ_query_param_fixed_size(msg, strlen(msg)), | 123 | GNUNET_SQ_query_param_fixed_size (msg, strlen (msg)), |
124 | GNUNET_SQ_query_param_uint16(&u16), | 124 | GNUNET_SQ_query_param_uint16 (&u16), |
125 | GNUNET_SQ_query_param_uint32(&u32), | 125 | GNUNET_SQ_query_param_uint32 (&u32), |
126 | GNUNET_SQ_query_param_uint64(&u64), | 126 | GNUNET_SQ_query_param_uint64 (&u64), |
127 | GNUNET_SQ_query_param_end | 127 | GNUNET_SQ_query_param_end |
128 | }; | 128 | }; |
129 | 129 | ||
130 | GNUNET_assert(GNUNET_OK == | 130 | GNUNET_assert (GNUNET_OK == |
131 | GNUNET_SQ_bind(stmt, | 131 | GNUNET_SQ_bind (stmt, |
132 | params_insert)); | 132 | params_insert)); |
133 | if (SQLITE_DONE != | 133 | if (SQLITE_DONE != |
134 | sqlite3_step(stmt)) | 134 | sqlite3_step (stmt)) |
135 | { | 135 | { |
136 | GNUNET_CRYPTO_rsa_signature_free(sig); | 136 | GNUNET_CRYPTO_rsa_signature_free (sig); |
137 | GNUNET_CRYPTO_rsa_private_key_free(priv); | 137 | GNUNET_CRYPTO_rsa_private_key_free (priv); |
138 | GNUNET_CRYPTO_rsa_public_key_free(pub); | 138 | GNUNET_CRYPTO_rsa_public_key_free (pub); |
139 | return 1; | 139 | return 1; |
140 | } | 140 | } |
141 | } | 141 | } |
142 | sqlite3_finalize(stmt); | 142 | sqlite3_finalize (stmt); |
143 | 143 | ||
144 | sq_prepare(dbh, | 144 | sq_prepare (dbh, |
145 | "SELECT" | 145 | "SELECT" |
146 | " pub" | 146 | " pub" |
147 | ",sig" | 147 | ",sig" |
148 | ",abs_time" | 148 | ",abs_time" |
149 | ",forever" | 149 | ",forever" |
150 | ",hash" | 150 | ",hash" |
151 | ",vsize" | 151 | ",vsize" |
152 | ",u16" | 152 | ",u16" |
153 | ",u32" | 153 | ",u32" |
154 | ",u64" | 154 | ",u64" |
155 | " FROM test_sq" | 155 | " FROM test_sq" |
156 | " ORDER BY abs_time DESC " | 156 | " ORDER BY abs_time DESC " |
157 | " LIMIT 1;", | 157 | " LIMIT 1;", |
158 | &stmt); | 158 | &stmt); |
159 | { | 159 | { |
160 | struct GNUNET_SQ_QueryParam params_select[] = { | 160 | struct GNUNET_SQ_QueryParam params_select[] = { |
161 | GNUNET_SQ_query_param_end | 161 | GNUNET_SQ_query_param_end |
162 | }; | 162 | }; |
163 | struct GNUNET_SQ_ResultSpec results_select[] = { | 163 | struct GNUNET_SQ_ResultSpec results_select[] = { |
164 | GNUNET_SQ_result_spec_rsa_public_key(&pub2), | 164 | GNUNET_SQ_result_spec_rsa_public_key (&pub2), |
165 | GNUNET_SQ_result_spec_rsa_signature(&sig2), | 165 | GNUNET_SQ_result_spec_rsa_signature (&sig2), |
166 | GNUNET_SQ_result_spec_absolute_time(&abs_time2), | 166 | GNUNET_SQ_result_spec_absolute_time (&abs_time2), |
167 | GNUNET_SQ_result_spec_absolute_time(&forever2), | 167 | GNUNET_SQ_result_spec_absolute_time (&forever2), |
168 | GNUNET_SQ_result_spec_auto_from_type(&hc2), | 168 | GNUNET_SQ_result_spec_auto_from_type (&hc2), |
169 | GNUNET_SQ_result_spec_variable_size(&msg2, &msg2_len), | 169 | GNUNET_SQ_result_spec_variable_size (&msg2, &msg2_len), |
170 | GNUNET_SQ_result_spec_uint16(&u162), | 170 | GNUNET_SQ_result_spec_uint16 (&u162), |
171 | GNUNET_SQ_result_spec_uint32(&u322), | 171 | GNUNET_SQ_result_spec_uint32 (&u322), |
172 | GNUNET_SQ_result_spec_uint64(&u642), | 172 | GNUNET_SQ_result_spec_uint64 (&u642), |
173 | GNUNET_SQ_result_spec_end | 173 | GNUNET_SQ_result_spec_end |
174 | }; | 174 | }; |
175 | 175 | ||
176 | GNUNET_assert(GNUNET_OK == | 176 | GNUNET_assert (GNUNET_OK == |
177 | GNUNET_SQ_bind(stmt, | 177 | GNUNET_SQ_bind (stmt, |
178 | params_select)); | 178 | params_select)); |
179 | if (SQLITE_ROW != | 179 | if (SQLITE_ROW != |
180 | sqlite3_step(stmt)) | 180 | sqlite3_step (stmt)) |
181 | { | 181 | { |
182 | GNUNET_break(0); | 182 | GNUNET_break (0); |
183 | sqlite3_finalize(stmt); | 183 | sqlite3_finalize (stmt); |
184 | GNUNET_CRYPTO_rsa_signature_free(sig); | 184 | GNUNET_CRYPTO_rsa_signature_free (sig); |
185 | GNUNET_CRYPTO_rsa_private_key_free(priv); | 185 | GNUNET_CRYPTO_rsa_private_key_free (priv); |
186 | GNUNET_CRYPTO_rsa_public_key_free(pub); | 186 | GNUNET_CRYPTO_rsa_public_key_free (pub); |
187 | return 1; | 187 | return 1; |
188 | } | 188 | } |
189 | GNUNET_assert(GNUNET_OK == | 189 | GNUNET_assert (GNUNET_OK == |
190 | GNUNET_SQ_extract_result(stmt, | 190 | GNUNET_SQ_extract_result (stmt, |
191 | results_select)); | 191 | results_select)); |
192 | GNUNET_break(abs_time.abs_value_us == abs_time2.abs_value_us); | 192 | GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us); |
193 | GNUNET_break(forever.abs_value_us == forever2.abs_value_us); | 193 | GNUNET_break (forever.abs_value_us == forever2.abs_value_us); |
194 | GNUNET_break(0 == | 194 | GNUNET_break (0 == |
195 | GNUNET_memcmp(&hc, | 195 | GNUNET_memcmp (&hc, |
196 | &hc2)); | 196 | &hc2)); |
197 | GNUNET_break(0 == | 197 | GNUNET_break (0 == |
198 | GNUNET_CRYPTO_rsa_signature_cmp(sig, | 198 | GNUNET_CRYPTO_rsa_signature_cmp (sig, |
199 | sig2)); | 199 | sig2)); |
200 | GNUNET_break(0 == | 200 | GNUNET_break (0 == |
201 | GNUNET_CRYPTO_rsa_public_key_cmp(pub, | 201 | GNUNET_CRYPTO_rsa_public_key_cmp (pub, |
202 | pub2)); | 202 | pub2)); |
203 | GNUNET_break(strlen(msg) == msg2_len); | 203 | GNUNET_break (strlen (msg) == msg2_len); |
204 | GNUNET_break(0 == | 204 | GNUNET_break (0 == |
205 | strncmp(msg, | 205 | strncmp (msg, |
206 | msg2, | 206 | msg2, |
207 | msg2_len)); | 207 | msg2_len)); |
208 | GNUNET_break(16 == u162); | 208 | GNUNET_break (16 == u162); |
209 | GNUNET_break(32 == u322); | 209 | GNUNET_break (32 == u322); |
210 | GNUNET_break(64 == u642); | 210 | GNUNET_break (64 == u642); |
211 | GNUNET_SQ_cleanup_result(results_select); | 211 | GNUNET_SQ_cleanup_result (results_select); |
212 | } | 212 | } |
213 | sqlite3_finalize(stmt); | 213 | sqlite3_finalize (stmt); |
214 | 214 | ||
215 | GNUNET_CRYPTO_rsa_signature_free(sig); | 215 | GNUNET_CRYPTO_rsa_signature_free (sig); |
216 | GNUNET_CRYPTO_rsa_private_key_free(priv); | 216 | GNUNET_CRYPTO_rsa_private_key_free (priv); |
217 | GNUNET_CRYPTO_rsa_public_key_free(pub); | 217 | GNUNET_CRYPTO_rsa_public_key_free (pub); |
218 | return 0; | 218 | return 0; |
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
222 | int | 222 | int |
223 | main(int argc, | 223 | main (int argc, |
224 | const char *const argv[]) | 224 | const char *const argv[]) |
225 | { | 225 | { |
226 | sqlite3 *dbh; | 226 | sqlite3 *dbh; |
227 | int ret; | 227 | int ret; |
228 | 228 | ||
229 | GNUNET_log_setup("test-sq", | 229 | GNUNET_log_setup ("test-sq", |
230 | "WARNING", | 230 | "WARNING", |
231 | NULL); | 231 | NULL); |
232 | if (SQLITE_OK != | 232 | if (SQLITE_OK != |
233 | sqlite3_open("test.db", | 233 | sqlite3_open ("test.db", |
234 | &dbh)) | 234 | &dbh)) |
235 | { | 235 | { |
236 | fprintf(stderr, | 236 | fprintf (stderr, |
237 | "Cannot run test, sqlite3 initialization failed\n"); | 237 | "Cannot run test, sqlite3 initialization failed\n"); |
238 | GNUNET_break(0); | 238 | GNUNET_break (0); |
239 | return 77; /* Signal test was skipped... */ | 239 | return 77; /* Signal test was skipped... */ |
240 | } | 240 | } |
241 | 241 | ||
242 | if (SQLITE_OK != | 242 | if (SQLITE_OK != |
243 | sqlite3_exec(dbh, | 243 | sqlite3_exec (dbh, |
244 | "CREATE TEMPORARY TABLE IF NOT EXISTS test_sq (" | 244 | "CREATE TEMPORARY TABLE IF NOT EXISTS test_sq (" |
245 | " pub BYTEA NOT NULL" | 245 | " pub BYTEA NOT NULL" |
246 | ",sig BYTEA NOT NULL" | 246 | ",sig BYTEA NOT NULL" |
247 | ",abs_time INT8 NOT NULL" | 247 | ",abs_time INT8 NOT NULL" |
248 | ",forever INT8 NOT NULL" | 248 | ",forever INT8 NOT NULL" |
249 | ",hash BYTEA NOT NULL" | 249 | ",hash BYTEA NOT NULL" |
250 | ",vsize VARCHAR NOT NULL" | 250 | ",vsize VARCHAR NOT NULL" |
251 | ",u16 INT2 NOT NULL" | 251 | ",u16 INT2 NOT NULL" |
252 | ",u32 INT4 NOT NULL" | 252 | ",u32 INT4 NOT NULL" |
253 | ",u64 INT8 NOT NULL" | 253 | ",u64 INT8 NOT NULL" |
254 | ")", | 254 | ")", |
255 | NULL, NULL, NULL)) | 255 | NULL, NULL, NULL)) |
256 | { | 256 | { |
257 | fprintf(stderr, | 257 | fprintf (stderr, |
258 | "Failed to create table\n"); | 258 | "Failed to create table\n"); |
259 | GNUNET_break(SQLITE_OK == | 259 | GNUNET_break (SQLITE_OK == |
260 | sqlite3_close(dbh)); | 260 | sqlite3_close (dbh)); |
261 | if (0 != unlink("test.db")) | 261 | if (0 != unlink ("test.db")) |
262 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, | 262 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
263 | "unlink", | 263 | "unlink", |
264 | "test.db"); | 264 | "test.db"); |
265 | return 1; | 265 | return 1; |
266 | } | 266 | } |
267 | 267 | ||
268 | ret = run_queries(dbh); | 268 | ret = run_queries (dbh); |
269 | if (SQLITE_OK != | 269 | if (SQLITE_OK != |
270 | sqlite3_exec(dbh, | 270 | sqlite3_exec (dbh, |
271 | "DROP TABLE test_sq", | 271 | "DROP TABLE test_sq", |
272 | NULL, NULL, NULL)) | 272 | NULL, NULL, NULL)) |
273 | { | 273 | { |
274 | fprintf(stderr, | 274 | fprintf (stderr, |
275 | "Failed to drop table\n"); | 275 | "Failed to drop table\n"); |
276 | ret = 1; | 276 | ret = 1; |
277 | } | 277 | } |
278 | GNUNET_break(SQLITE_OK == | 278 | GNUNET_break (SQLITE_OK == |
279 | sqlite3_close(dbh)); | 279 | sqlite3_close (dbh)); |
280 | if (0 != unlink("test.db")) | 280 | if (0 != unlink ("test.db")) |
281 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, | 281 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
282 | "unlink", | 282 | "unlink", |
283 | "test.db"); | 283 | "test.db"); |
284 | return ret; | 284 | return ret; |
285 | } | 285 | } |
286 | 286 | ||