style changes in tests

This commit is contained in:
Markus Teich 2016-08-09 12:27:44 +02:00
parent fbc3e92e59
commit f55d10d5f6
2 changed files with 45 additions and 44 deletions

4
test.h
View File

@ -27,7 +27,7 @@
int tests_run = 0;
int ret = 0;
#define check(cond, message) do { if (!(cond)) { fputs (message, stderr); fputc ('\n', stderr); return 0; } } while (0)
#define run(test) do { if (!test ()) { ret = 1; } } while (0)
#define CHECK(cond, message) do { if (!(cond)) { fputs (message, stderr); fputc ('\n', stderr); return 0; } } while (0)
#define RUN(test) do { if (!test ()) { ret = 1; } } while (0)
#endif // ifndef _BRANDT_TEST_H

View File

@ -34,7 +34,7 @@ static uint16_t bidders;
static uint16_t prizes;
static struct BRANDT_Auction *ad;
int
static int
test_smc_2d_array ()
{
gcry_mpi_point_t **array;
@ -43,18 +43,18 @@ test_smc_2d_array ()
uint16_t i, j;
array = smc_init2 (size1, size2);
check (array, "memory allocation failed");
CHECK (array, "memory allocation failed");
for (i = 0; i < size1; i++)
for (j = 0; j < size2; j++)
check (array[i][j], "point has not been initialized");
CHECK (array[i][j], "point has not been initialized");
smc_free2 (array, size1, size2);
return 1;
}
int
static int
test_smc_3d_array ()
{
gcry_mpi_point_t ***array;
@ -64,19 +64,19 @@ test_smc_3d_array ()
uint16_t i, j, k;
array = smc_init3 (size1, size2, size3);
check (array, "memory allocation failed");
CHECK (array, "memory allocation failed");
for (i = 0; i < size1; i++)
for (j = 0; j < size2; j++)
for (k = 0; k < size3; k++)
check (array[i][j][k], "point has not been initialized");
CHECK (array[i][j][k], "point has not been initialized");
smc_free3 (array, size1, size2, size3);
return 1;
}
int
static int
test_serialization ()
{
gcry_mpi_point_t oldp = gcry_mpi_point_new (0);
@ -94,12 +94,12 @@ test_serialization ()
ec_point_parse (newp, &serp);
mpi_parse (newi, &seri);
check (!ec_point_cmp (oldp, newp), "serialization changed point");
check (!gcry_mpi_cmp (oldi, newi), "serialization changed mpi");
CHECK (!ec_point_cmp (oldp, newp), "serialization changed point");
CHECK (!gcry_mpi_cmp (oldi, newi), "serialization changed mpi");
mpi_serialize (&seri, GCRYMPI_CONST_ONE);
mpi_parse (newi, &seri);
check (!gcry_mpi_cmp (GCRYMPI_CONST_ONE, newi), "serializing mpi 1 fail");
CHECK (!gcry_mpi_cmp (GCRYMPI_CONST_ONE, newi), "serializing mpi 1 fail");
gcry_mpi_point_release (oldp);
gcry_mpi_point_release (newp);
@ -109,7 +109,7 @@ test_serialization ()
}
int
static int
test_smc_zkp_dl ()
{
struct proof_dl proof;
@ -119,8 +119,8 @@ test_smc_zkp_dl ()
ec_skey_create (x);
smc_zkp_dl (v, x, &proof);
check (gcry_mpi_ec_curve_point (v, ec_ctx), "not on curve");
check (!smc_zkp_dl_check (v, &proof), "zkp dl wrong");
CHECK (gcry_mpi_ec_curve_point (v, ec_ctx), "not on curve");
CHECK (!smc_zkp_dl_check (v, &proof), "zkp dl wrong");
gcry_mpi_release (x);
gcry_mpi_point_release (v);
@ -128,7 +128,7 @@ test_smc_zkp_dl ()
}
int
static int
test_smc_zkp_2dle ()
{
struct proof_2dle proof;
@ -142,11 +142,11 @@ test_smc_zkp_2dle ()
ec_keypair_create (g2, x);
smc_zkp_2dle (v, w, g1, g2, x, &proof);
check (gcry_mpi_ec_curve_point (g1, ec_ctx), "not on curve");
check (gcry_mpi_ec_curve_point (g2, ec_ctx), "not on curve");
check (gcry_mpi_ec_curve_point (v, ec_ctx), "not on curve");
check (gcry_mpi_ec_curve_point (w, ec_ctx), "not on curve");
check (!smc_zkp_2dle_check (v, w, g1, g2, &proof), "zkp 2dle wrong");
CHECK (gcry_mpi_ec_curve_point (g1, ec_ctx), "not on curve");
CHECK (gcry_mpi_ec_curve_point (g2, ec_ctx), "not on curve");
CHECK (gcry_mpi_ec_curve_point (v, ec_ctx), "not on curve");
CHECK (gcry_mpi_ec_curve_point (w, ec_ctx), "not on curve");
CHECK (!smc_zkp_2dle_check (v, w, g1, g2, &proof), "zkp 2dle wrong");
gcry_mpi_release (x);
gcry_mpi_point_release (g1);
@ -157,7 +157,7 @@ test_smc_zkp_2dle ()
}
int
static int
test_smc_zkp_0og ()
{
struct proof_0og proof;
@ -170,9 +170,9 @@ test_smc_zkp_0og ()
ec_keypair_create (y, NULL);
smc_zkp_0og (tests_run % 2, y, NULL, alpha, beta, &proof);
check (gcry_mpi_ec_curve_point (alpha, ec_ctx), "not on curve");
check (gcry_mpi_ec_curve_point (beta, ec_ctx), "not on curve");
check (!smc_zkp_0og_check (y, alpha, beta, &proof), "zkp 0og is wrong");
CHECK (gcry_mpi_ec_curve_point (alpha, ec_ctx), "not on curve");
CHECK (gcry_mpi_ec_curve_point (beta, ec_ctx), "not on curve");
CHECK (!smc_zkp_0og_check (y, alpha, beta, &proof), "zkp 0og is wrong");
gcry_mpi_point_release (y);
gcry_mpi_point_release (alpha);
@ -198,12 +198,13 @@ test_setup_auction_data ()
return 1;
}
/*
*/
#define ROUND(type, oc, index) do { \
for (uint16_t i = 0; i < bidders; i++) \
{ \
bufs[i] = handler_out[type][oc][index] (&ad[i], &lens[i]); \
check (bufs[i], "failed to gen keyshare"); \
CHECK (bufs[i], "failed to gen keyshare"); \
} \
\
for (uint16_t i = 0; i < bidders; i++) \
@ -212,7 +213,7 @@ test_setup_auction_data ()
{ \
if (s == i) \
continue; \
check (handler_in[type][oc][index] (&ad[i], bufs[s], lens[s], s), \
CHECK (handler_in[type][oc][index] (&ad[i], bufs[s], lens[s], s), \
"failed checking keyshare"); \
} \
} \
@ -222,7 +223,7 @@ test_setup_auction_data ()
} while (0)
int
static int
test_private_first_price ()
{
unsigned char *bufs[bidders];
@ -239,17 +240,17 @@ test_private_first_price ()
{
if (-1 != fp_priv_determine_outcome (&ad[i]))
{
check (-1 == winner, "multiple winners detected");
CHECK (-1 == winner, "multiple winners detected");
winner = i;
}
}
check (-1 != winner, "no winner detected");
CHECK (-1 != winner, "no winner detected");
fputs ("good: one winner detected", stderr);
return 1;
}
int
static int
test_public_first_price ()
{
unsigned char *bufs[bidders];
@ -270,10 +271,10 @@ test_public_first_price ()
price = fp_pub_determine_outcome (&ad[i], &winner);
if (-1 == pret)
pret = price;
check (price == pret, "different prices detected");
CHECK (price == pret, "different prices detected");
if (-1 == wret)
wret = winner;
check (winner == wret, "different winners detected");
CHECK (winner == wret, "different winners detected");
}
fputs ("good: same winner detected", stderr);
return 1;
@ -316,22 +317,22 @@ main (int argc, char *argv[])
BRANDT_init (edc);
/* tests that need to run only once */
run (test_smc_2d_array);
run (test_smc_3d_array);
run (test_serialization);
RUN (test_smc_2d_array);
RUN (test_smc_3d_array);
RUN (test_serialization);
for (tests_run = 0; tests_run < repeat; tests_run++)
{
run (test_smc_zkp_dl);
run (test_smc_zkp_2dle);
run (test_smc_zkp_0og);
RUN (test_smc_zkp_dl);
RUN (test_smc_zkp_2dle);
RUN (test_smc_zkp_0og);
}
run (test_setup_auction_data);
run (test_private_first_price);
RUN (test_setup_auction_data);
RUN (test_private_first_price);
cleanup_auction_data ();
run (test_setup_auction_data);
run (test_public_first_price);
RUN (test_setup_auction_data);
RUN (test_public_first_price);
cleanup_auction_data ();
GNUNET_CRYPTO_ecc_dlog_release (edc);