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; break;
case TALER_PQ_QF_RSA_PUBLIC_KEY: case TALER_PQ_QF_RSA_PUBLIC_KEY:
case TALER_PQ_QF_RSA_SIGNATURE: case TALER_PQ_QF_RSA_SIGNATURE:
case TALER_PQ_QF_TIME_ABSOLUTE:
len++; len++;
break; break;
default: default:
@ -67,6 +68,7 @@ TALER_PQ_exec_prepared (PGconn *db_conn,
GNUNET_assert (0); GNUNET_assert (0);
break; break;
} }
i++;
} }
/* new scope to allow stack allocation without alloca */ /* new scope to allow stack allocation without alloca */
@ -190,6 +192,7 @@ TALER_PQ_exec_prepared (PGconn *db_conn,
GNUNET_assert (0); GNUNET_assert (0);
break; break;
} }
i++;
} }
GNUNET_assert (off == len); GNUNET_assert (off == len);
res = PQexecPrepared (db_conn, res = PQexecPrepared (db_conn,
@ -200,7 +203,7 @@ TALER_PQ_exec_prepared (PGconn *db_conn,
param_formats, param_formats,
1); 1);
for (off = 0; off < soff; off++) for (off = 0; off < soff; off++)
GNUNET_free (scratch[soff]); GNUNET_free (scratch[off]);
return res; return res;
} }
} }

View File

@ -155,7 +155,7 @@ TALER_PQ_RESULT_SPEC_AMOUNT (const char *name,
struct TALER_Amount *amount) struct TALER_Amount *amount)
{ {
struct TALER_PQ_ResultSpec res = 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; return res;
} }

View File

@ -77,9 +77,9 @@ postgres_prepare (PGconn *db_conn)
",namount_val" ",namount_val"
",namount_frac" ",namount_frac"
",namount_curr" ",namount_curr"
"FROM test_pq" " FROM test_pq"
"ORDER BY abs_time DESC " " ORDER BY abs_time DESC "
"LIMIT 1;", " LIMIT 1;",
0, NULL); 0, NULL);
return GNUNET_OK; return GNUNET_OK;
#undef PREPARE #undef PREPARE
@ -108,47 +108,60 @@ run_queries (PGconn *conn)
struct TALER_Amount hamount2; struct TALER_Amount hamount2;
struct TALER_AmountNBO namount; struct TALER_AmountNBO namount;
struct TALER_AmountNBO namount2; 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; PGresult *result;
int ret; int ret;
struct GNUNET_CRYPTO_rsa_PrivateKey *priv;
// FIXME: init pub, sig char msg[] = "Hello";
result = TALER_PQ_exec_prepared (conn,
"test_insert", priv = GNUNET_CRYPTO_rsa_private_key_create (1024);
params_insert); pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv);
PQclear (result); sig = GNUNET_CRYPTO_rsa_sign (priv,
result = TALER_PQ_exec_prepared (conn, msg,
"test_select", sizeof (msg));
params_select); {
ret = TALER_PQ_extract_result (result, struct TALER_PQ_QueryParam params_insert[] = {
results_select, TALER_PQ_QUERY_PARAM_RSA_PUBLIC_KEY (pub),
0); TALER_PQ_QUERY_PARAM_RSA_SIGNATURE (sig),
// FIXME: cmp results! TALER_PQ_QUERY_PARAM_ABSOLUTE_TIME (abs_time),
TALER_PQ_cleanup_result (results_select); TALER_PQ_QUERY_PARAM_ABSOLUTE_TIME (forever),
PQclear (result); 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) if (GNUNET_OK != ret)
return 1; return 1;
@ -165,6 +178,9 @@ main(int argc,
int ret; int ret;
// FIXME: pass valid connect string for tests... // FIXME: pass valid connect string for tests...
GNUNET_log_setup ("test-pq",
"WARNING",
NULL);
conn = PQconnectdb ("postgres:///talercheck"); conn = PQconnectdb ("postgres:///talercheck");
if (CONNECTION_OK != PQstatus (conn)) if (CONNECTION_OK != PQstatus (conn))
{ {
@ -204,7 +220,6 @@ main(int argc,
postgres_prepare (conn)) postgres_prepare (conn))
{ {
GNUNET_break (0); GNUNET_break (0);
PQclear (result);
PQfinish (conn); PQfinish (conn);
return 1; return 1;
} }