]> err.no Git - util-linux/commitdiff
tests: add MD5 regression test
authorKarel Zak <kzak@redhat.com>
Sat, 6 Dec 2008 00:43:55 +0000 (01:43 +0100)
committerKarel Zak <kzak@redhat.com>
Sat, 6 Dec 2008 00:43:55 +0000 (01:43 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
tests/helpers/.gitignore
tests/helpers/Makefile.am
tests/helpers/test_md5.c [new file with mode: 0644]

index a2ca1fc066ace1b48fe3937915a288bfbc1eda8f..62a8299083b1dd60c4bbff59dcd138ea458ae687 100644 (file)
@@ -1,3 +1,4 @@
 test_pathnames
 test_sysinfo
 test_byteswap
+test_md5
index 12792329559e3ab01137e6a8b157a4e46f2b2b92..26007d476e226a6feb1bef9448fc024b2def555f 100644 (file)
@@ -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 (file)
index 0000000..b99882b
--- /dev/null
@@ -0,0 +1,30 @@
+
+#include <stdio.h>
+#include <unistd.h>
+
+#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;
+}