From 788a14403d032682c172c8021550db2e2a81c1a4 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Sat, 6 Dec 2008 01:43:55 +0100 Subject: [PATCH] tests: add MD5 regression test Signed-off-by: Karel Zak --- tests/helpers/.gitignore | 1 + tests/helpers/Makefile.am | 5 ++++- tests/helpers/test_md5.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/helpers/test_md5.c diff --git a/tests/helpers/.gitignore b/tests/helpers/.gitignore index a2ca1fc0..62a82990 100644 --- a/tests/helpers/.gitignore +++ b/tests/helpers/.gitignore @@ -1,3 +1,4 @@ test_pathnames test_sysinfo test_byteswap +test_md5 diff --git a/tests/helpers/Makefile.am b/tests/helpers/Makefile.am index 12792329..26007d47 100644 --- a/tests/helpers/Makefile.am +++ b/tests/helpers/Makefile.am @@ -1,4 +1,7 @@ include $(top_srcdir)/config/include-Makefile.am -noinst_PROGRAMS = test_sysinfo test_pathnames test_byteswap +noinst_PROGRAMS = test_sysinfo test_pathnames test_byteswap \ + test_md5 + +test_md5_SOURCES = test_md5.c $(top_srcdir)/lib/md5.c diff --git a/tests/helpers/test_md5.c b/tests/helpers/test_md5.c new file mode 100644 index 00000000..b99882b5 --- /dev/null +++ b/tests/helpers/test_md5.c @@ -0,0 +1,30 @@ + +#include +#include + +#include "md5.h" + +int +main(int argc, char *argv[]) +{ + int i, ret; + struct MD5Context ctx; + unsigned char digest[16]; + unsigned char buf[BUFSIZ]; + + MD5Init( &ctx ); + + while(!feof(stdin) && !ferror(stdin)) { + ret = fread(buf, 1, sizeof(buf), stdin); + if (ret) + MD5Update( &ctx, buf, ret ); + } + + fclose(stdin); + MD5Final( digest, &ctx ); + + for (i = 0; i < 16; i++) + printf( "%02x", digest[i] ); + printf(" -\n"); + return 0; +} -- 2.39.5