diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-15 09:53:31 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-15 09:53:31 +0200 |
commit | 6b9ccc4ca0a5cb35c6cc76a8d5247ac914561d64 (patch) | |
tree | 9fc3b9ae2f2cd16e405bb953e390381953ded447 | |
parent | 3ac86568b0223ab3dfca83b497208dc0f2261fdd (diff) |
fixing misc. minor bugs, towards getting testcases to work
-rw-r--r-- | src/pq/db_pq.c | 5 | ||||
-rw-r--r-- | src/pq/pq_helper.c | 2 | ||||
-rw-r--r-- | src/pq/test_pq.c | 101 |
3 files changed, 63 insertions, 45 deletions
diff --git a/src/pq/db_pq.c b/src/pq/db_pq.c index 72a9370ed..42ce3fa71 100644 --- a/src/pq/db_pq.c +++ b/src/pq/db_pq.c @@ -60,6 +60,7 @@ TALER_PQ_exec_prepared (PGconn *db_conn, break; case TALER_PQ_QF_RSA_PUBLIC_KEY: case TALER_PQ_QF_RSA_SIGNATURE: + case TALER_PQ_QF_TIME_ABSOLUTE: len++; break; default: @@ -67,6 +68,7 @@ TALER_PQ_exec_prepared (PGconn *db_conn, GNUNET_assert (0); break; } + i++; } /* new scope to allow stack allocation without alloca */ @@ -190,6 +192,7 @@ TALER_PQ_exec_prepared (PGconn *db_conn, GNUNET_assert (0); break; } + i++; } GNUNET_assert (off == len); res = PQexecPrepared (db_conn, @@ -200,7 +203,7 @@ TALER_PQ_exec_prepared (PGconn *db_conn, param_formats, 1); for (off = 0; off < soff; off++) - GNUNET_free (scratch[soff]); + GNUNET_free (scratch[off]); return res; } } diff --git a/src/pq/pq_helper.c b/src/pq/pq_helper.c index b172a94bf..183bd43f2 100644 --- a/src/pq/pq_helper.c +++ b/src/pq/pq_helper.c @@ -155,7 +155,7 @@ TALER_PQ_RESULT_SPEC_AMOUNT (const char *name, struct TALER_Amount *amount) { struct TALER_PQ_ResultSpec res = - {TALER_PQ_RF_AMOUNT, (void *) (&amount), sizeof (amount), (name), NULL }; + {TALER_PQ_RF_AMOUNT, (void *) (&amount), sizeof (*amount), (name), NULL }; return res; } diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c index 2133182d0..1672cc54c 100644 --- a/src/pq/test_pq.c +++ b/src/pq/test_pq.c @@ -77,9 +77,9 @@ postgres_prepare (PGconn *db_conn) ",namount_val" ",namount_frac" ",namount_curr" - "FROM test_pq" - "ORDER BY abs_time DESC " - "LIMIT 1;", + " FROM test_pq" + " ORDER BY abs_time DESC " + " LIMIT 1;", 0, NULL); return GNUNET_OK; #undef PREPARE @@ -108,47 +108,60 @@ run_queries (PGconn *conn) struct TALER_Amount hamount2; struct TALER_AmountNBO namount; struct TALER_AmountNBO namount2; - struct TALER_PQ_QueryParam params_insert[] = { - TALER_PQ_QUERY_PARAM_RSA_PUBLIC_KEY (pub), - TALER_PQ_QUERY_PARAM_RSA_SIGNATURE (sig), - TALER_PQ_QUERY_PARAM_ABSOLUTE_TIME (abs_time), - TALER_PQ_QUERY_PARAM_ABSOLUTE_TIME (forever), - TALER_PQ_QUERY_PARAM_PTR (&hc), - TALER_PQ_QUERY_PARAM_AMOUNT (&hamount), - TALER_PQ_QUERY_PARAM_AMOUNT_NBO (&namount), - TALER_PQ_QUERY_PARAM_END - }; - struct TALER_PQ_QueryParam params_select[] = { - TALER_PQ_QUERY_PARAM_END - }; - struct TALER_PQ_ResultSpec results_select[] = { - TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY ("pub", &pub2), - TALER_PQ_RESULT_SPEC_RSA_SIGNATURE ("sig", &sig2), - TALER_PQ_RESULT_SPEC_ABSOLUTE_TIME ("abs_time", &abs_time2), - TALER_PQ_RESULT_SPEC_ABSOLUTE_TIME ("forever", &forever2), - TALER_PQ_RESULT_SPEC ("hash", &hc2), - TALER_PQ_RESULT_SPEC_AMOUNT ("hamount", &hamount2), - TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("namount", &namount2), - TALER_PQ_RESULT_SPEC_END - }; PGresult *result; int ret; - - // FIXME: init pub, sig - result = TALER_PQ_exec_prepared (conn, - "test_insert", - params_insert); - PQclear (result); - result = TALER_PQ_exec_prepared (conn, - "test_select", - params_select); - ret = TALER_PQ_extract_result (result, - results_select, - 0); - // FIXME: cmp results! - TALER_PQ_cleanup_result (results_select); - PQclear (result); - + struct GNUNET_CRYPTO_rsa_PrivateKey *priv; + char msg[] = "Hello"; + + priv = GNUNET_CRYPTO_rsa_private_key_create (1024); + pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); + sig = GNUNET_CRYPTO_rsa_sign (priv, + msg, + sizeof (msg)); + { + struct TALER_PQ_QueryParam params_insert[] = { + TALER_PQ_QUERY_PARAM_RSA_PUBLIC_KEY (pub), + TALER_PQ_QUERY_PARAM_RSA_SIGNATURE (sig), + TALER_PQ_QUERY_PARAM_ABSOLUTE_TIME (abs_time), + TALER_PQ_QUERY_PARAM_ABSOLUTE_TIME (forever), + TALER_PQ_QUERY_PARAM_PTR (&hc), + TALER_PQ_QUERY_PARAM_AMOUNT (&hamount), + TALER_PQ_QUERY_PARAM_AMOUNT_NBO (&namount), + TALER_PQ_QUERY_PARAM_END + }; + struct TALER_PQ_QueryParam params_select[] = { + TALER_PQ_QUERY_PARAM_END + }; + struct TALER_PQ_ResultSpec results_select[] = { + TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY ("pub", &pub2), + TALER_PQ_RESULT_SPEC_RSA_SIGNATURE ("sig", &sig2), + TALER_PQ_RESULT_SPEC_ABSOLUTE_TIME ("abs_time", &abs_time2), + TALER_PQ_RESULT_SPEC_ABSOLUTE_TIME ("forever", &forever2), + TALER_PQ_RESULT_SPEC ("hash", &hc2), + TALER_PQ_RESULT_SPEC_AMOUNT ("hamount", &hamount2), + TALER_PQ_RESULT_SPEC_AMOUNT_NBO ("namount", &namount2), + TALER_PQ_RESULT_SPEC_END + }; + + + result = TALER_PQ_exec_prepared (conn, + "test_insert", + params_insert); + PQclear (result); + result = TALER_PQ_exec_prepared (conn, + "test_select", + params_select); + ret = TALER_PQ_extract_result (result, + results_select, + 0); + // FIXME: cmp results! + + TALER_PQ_cleanup_result (results_select); + PQclear (result); + } + GNUNET_CRYPTO_rsa_signature_free (sig); + GNUNET_CRYPTO_rsa_private_key_free (priv); + GNUNET_CRYPTO_rsa_public_key_free (pub); if (GNUNET_OK != ret) return 1; @@ -165,6 +178,9 @@ main(int argc, int ret; // FIXME: pass valid connect string for tests... + GNUNET_log_setup ("test-pq", + "WARNING", + NULL); conn = PQconnectdb ("postgres:///talercheck"); if (CONNECTION_OK != PQstatus (conn)) { @@ -204,7 +220,6 @@ main(int argc, postgres_prepare (conn)) { GNUNET_break (0); - PQclear (result); PQfinish (conn); return 1; } |