diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-15 14:16:10 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-15 14:16:10 +0200 |
commit | 6c774a1f032e2e09ab5e22a58a1979acc2c3430b (patch) | |
tree | c3a9079fcebe189e4e225b0f9c7d92766d37b694 /src | |
parent | 6b9ccc4ca0a5cb35c6cc76a8d5247ac914561d64 (diff) |
completing test-case implementation:
Diffstat (limited to 'src')
-rw-r--r-- | src/pq/db_pq.c | 4 | ||||
-rw-r--r-- | src/pq/pq_helper.c | 2 | ||||
-rw-r--r-- | src/pq/test_pq.c | 61 |
3 files changed, 61 insertions, 6 deletions
diff --git a/src/pq/db_pq.c b/src/pq/db_pq.c index 42ce3fa71..220ce9f94 100644 --- a/src/pq/db_pq.c +++ b/src/pq/db_pq.c @@ -113,7 +113,7 @@ TALER_PQ_exec_prepared (PGconn *db_conn, param_formats[off] = 1; off++; param_values[off] = (void *) amount->currency; - param_lengths[off] = strlen (amount->currency) + 1; + param_lengths[off] = strlen (amount->currency); param_formats[off] = 1; off++; } @@ -136,7 +136,7 @@ TALER_PQ_exec_prepared (PGconn *db_conn, param_formats[off] = 1; off++; param_values[off] = (void *) amount->currency; - param_lengths[off] = strlen (amount->currency) + 1; + param_lengths[off] = strlen (amount->currency); param_formats[off] = 1; off++; } diff --git a/src/pq/pq_helper.c b/src/pq/pq_helper.c index 183bd43f2..5baab5a1c 100644 --- a/src/pq/pq_helper.c +++ b/src/pq/pq_helper.c @@ -138,7 +138,7 @@ TALER_PQ_RESULT_SPEC_AMOUNT_NBO (const char *name, struct TALER_AmountNBO *amount) { struct TALER_PQ_ResultSpec res = - {TALER_PQ_RF_AMOUNT_NBO, (void *) (&amount), sizeof (amount), (name), NULL }; + {TALER_PQ_RF_AMOUNT_NBO, (void *) (&amount), sizeof (*amount), (name), NULL }; return res; } diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c index 1672cc54c..dfae86125 100644 --- a/src/pq/test_pq.c +++ b/src/pq/test_pq.c @@ -118,6 +118,12 @@ run_queries (PGconn *conn) sig = GNUNET_CRYPTO_rsa_sign (priv, msg, sizeof (msg)); + TALER_string_to_amount ("EUR:5.5", + &hamount); + TALER_amount_hton (&namount, + &hamount); + TALER_string_to_amount ("EUR:4.4", + &hamount); { struct TALER_PQ_QueryParam params_insert[] = { TALER_PQ_QUERY_PARAM_RSA_PUBLIC_KEY (pub), @@ -143,19 +149,68 @@ run_queries (PGconn *conn) TALER_PQ_RESULT_SPEC_END }; - + fprintf (stderr, + "Inserting\n"); result = TALER_PQ_exec_prepared (conn, "test_insert", params_insert); + if (PGRES_COMMAND_OK != PQresultStatus (result)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Database failure: %s\n", + PQresultErrorMessage (result)); + PQclear (result); + GNUNET_CRYPTO_rsa_signature_free (sig); + GNUNET_CRYPTO_rsa_private_key_free (priv); + GNUNET_CRYPTO_rsa_public_key_free (pub); + return 1; + } + PQclear (result); + fprintf (stderr, + "Selecting\n"); result = TALER_PQ_exec_prepared (conn, "test_select", params_select); + if (1 != + PQntuples (result)) + { + GNUNET_break (0); + PQclear (result); + GNUNET_CRYPTO_rsa_signature_free (sig); + GNUNET_CRYPTO_rsa_private_key_free (priv); + GNUNET_CRYPTO_rsa_public_key_free (pub); + return 1; + } ret = TALER_PQ_extract_result (result, results_select, 0); - // FIXME: cmp results! - + GNUNET_break (GNUNET_YES == ret); + fprintf (stderr, + "Verifying\n"); + GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us); + GNUNET_break (forever.abs_value_us == forever2.abs_value_us); + GNUNET_break (0 == + memcmp (&hc, + &hc2, + sizeof (struct GNUNET_HashCode))); + GNUNET_break (0 == + TALER_amount_cmp (&hamount, + &hamount2)); + TALER_string_to_amount ("EUR:5.5", + &hamount); + TALER_amount_ntoh (&hamount2, + &namount2); + GNUNET_break (0 == + TALER_amount_cmp (&hamount, + &hamount2)); + GNUNET_break (0 == + GNUNET_CRYPTO_rsa_signature_cmp (sig, + sig2)); + GNUNET_break (0 == + GNUNET_CRYPTO_rsa_public_key_cmp (pub, + pub2)); + TALER_PQ_cleanup_result (results_select); PQclear (result); } |