From 3a73ab675a19e2ea29b4cb1385db0188ce4997f8 Mon Sep 17 00:00:00 2001 From: Mattias Andrée <maandree@kth.se> Date: Sat, 24 Aug 2024 11:26:42 +0200 Subject: Make algorithms optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée <maandree@kth.se> --- common.h | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'common.h') diff --git a/common.h b/common.h index 3d0972c..f41ef53 100644 --- a/common.h +++ b/common.h @@ -160,17 +160,17 @@ run_tests(const char *name, enum libhashsum_algorithm algorithm, size_t hash_siz *p = '\0'; } if (testcases[i].input_repeat == 1) - printf("[\033[1;%s\033[m] %s(\"%s\"%s) = %s\n", - caseok ? "32mPASS" : "31mFAIL", name, input, bitstr, hexsum); + fprintf(stderr, "[\033[1;%s\033[m] %s(\"%s\"%s) = %s\n", + caseok ? "32mPASS" : "31mFAIL", name, input, bitstr, hexsum); else if (!testcases[i].input_repeat && *bitstr) - printf("[\033[1;%s\033[m] %s(%s) = %s\n", - caseok ? "32mPASS" : "31mFAIL", name, &bitstr[3], hexsum); + fprintf(stderr, "[\033[1;%s\033[m] %s(%s) = %s\n", + caseok ? "32mPASS" : "31mFAIL", name, &bitstr[3], hexsum); else if (!testcases[i].input_repeat) - printf("[\033[1;%s\033[m] %s(\"\") = %s\n", - caseok ? "32mPASS" : "31mFAIL", name, hexsum); + fprintf(stderr, "[\033[1;%s\033[m] %s(\"\") = %s\n", + caseok ? "32mPASS" : "31mFAIL", name, hexsum); else - printf("[\033[1;%s\033[m] %s(%zu * \"%s\"%s) = %s\n", - caseok ? "32mPASS" : "31mFAIL", name, testcases[i].input_repeat, input, bitstr, hexsum); + fprintf(stderr, "[\033[1;%s\033[m] %s(%zu * \"%s\"%s) = %s\n", + caseok ? "32mPASS" : "31mFAIL", name, testcases[i].input_repeat, input, bitstr, hexsum); free(input); } return !ok; @@ -182,3 +182,21 @@ run_tests(const char *name, enum libhashsum_algorithm algorithm, size_t hash_siz testcases, sizeof(testcases) / sizeof(*testcases), hexsum) #endif + + +#ifdef TEST_UNSUPPORTED +# include <stdio.h> + +# define TEST_MAIN(NAME, ID)\ + struct libhashsum_hasher hasher;\ + if (!libhashsum_init_hasher(&hasher, LIBHASHSUM_##ID)) {\ + fprintf(stderr, "expected libhashsum_init_hasher to fail, but it returned successfully\n");\ + return 2;\ + }\ + if (errno != ENOSYS) {\ + perror("expected libhashsum_init_hasher to set errno to ENOSYS, but got");\ + return 2;\ + }\ + return 0; + +#endif -- cgit v1.2.3-70-g09d2