aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-24 11:26:42 +0200
committerMattias Andrée <maandree@kth.se>2024-08-24 11:26:42 +0200
commit3a73ab675a19e2ea29b4cb1385db0188ce4997f8 (patch)
treeb010de454a833b01fe2ed469fd4f0fd699c59e50 /common.h
parentTest partial byte support in SHA1 and SHA-224 (diff)
downloadlibhashsum-3a73ab675a19e2ea29b4cb1385db0188ce4997f8.tar.gz
libhashsum-3a73ab675a19e2ea29b4cb1385db0188ce4997f8.tar.bz2
libhashsum-3a73ab675a19e2ea29b4cb1385db0188ce4997f8.tar.xz
Make algorithms optional
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--common.h34
1 files changed, 26 insertions, 8 deletions
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