From e811376a95174f0a99aa42f7e9d75dc16843780f Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Tue, 19 Mar 2019 15:20:59 +0000 Subject: [PATCH] Do the test more properly --- test/crypto_kem/functest.c | 14 ++++++++++---- test/crypto_sign/functest.c | 16 +++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/test/crypto_kem/functest.c b/test/crypto_kem/functest.c index a2721e86..74cef3f6 100644 --- a/test/crypto_kem/functest.c +++ b/test/crypto_kem/functest.c @@ -50,8 +50,15 @@ static int check_canary(const uint8_t *d) { return -1; \ } -#define DEFER(x) x -#define NAMESPACE_CHECK DEFER(NAMESPACE(API_H)) +// https://stackoverflow.com/a/55243651/248065 +#define MY_TRUTHY_VALUE_X 1 +#define CAT(x,y) CAT_(x,y) +#define CAT_(x,y) x##y +#define HAS_NAMESPACE(x) CAT(CAT(MY_TRUTHY_VALUE_,CAT(PQCLEAN_NAMESPACE,CAT(_,x))),X) + +#if !HAS_NAMESPACE(API_H) +#error "namespace not properly defined for header guard" +#endif static int test_keys(void) { /* @@ -200,9 +207,8 @@ static int test_invalid_ciphertext(void) { } int main(void) { - // these two will trigger compiler errors + // Check if CRYPTO_ALGNAME is printable puts(CRYPTO_ALGNAME); - NAMESPACE_CHECK; int result = 0; result += test_keys(); diff --git a/test/crypto_sign/functest.c b/test/crypto_sign/functest.c index 2eaf8f5c..57e9e0da 100644 --- a/test/crypto_sign/functest.c +++ b/test/crypto_sign/functest.c @@ -51,8 +51,16 @@ static int check_canary(const uint8_t *d) { return -1; \ } -#define DEFER(x) x -#define NAMESPACE_CHECK DEFER(NAMESPACE(API_H)) +// https://stackoverflow.com/a/55243651/248065 +#define MY_TRUTHY_VALUE_X 1 +#define CAT(x,y) CAT_(x,y) +#define CAT_(x,y) x##y +#define HAS_NAMESPACE(x) CAT(CAT(MY_TRUTHY_VALUE_,CAT(PQCLEAN_NAMESPACE,CAT(_,x))),X) + +#if !HAS_NAMESPACE(API_H) +#error "namespace not properly defined for header guard" +#endif + static int test_sign(void) { /* @@ -163,10 +171,8 @@ static int test_wrong_pk(void) { } int main(void) { - // these two will generate compile errors + // check if CRYPTO_ALGNAME is printable puts(CRYPTO_ALGNAME); - NAMESPACE_CHECK; - int result = 0; result += test_sign(); result += test_wrong_pk();