fixing misc. minor bugs, towards getting testcases to work

This commit is contained in:
Christian Grothoff 2015-05-15 09:53:31 +02:00
parent 3ac86568b0
commit 6b9ccc4ca0
3 changed files with 63 additions and 45 deletions

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
struct GNUNET_CRYPTO_rsa_PrivateKey *priv;
char msg[] = "Hello";
// 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);
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;
}