From ce0968fdd569bbe4aea62691654ee78f95ad3d8e Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 30 Oct 2012 21:27:25 +0100 Subject: [PATCH] MD5: Test suite --- ucw/Makefile | 3 ++- ucw/md5.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ucw/Makefile b/ucw/Makefile index a09bd1fb..9820d441 100644 --- a/ucw/Makefile +++ b/ucw/Makefile @@ -117,7 +117,7 @@ TESTS+=$(addprefix $(o)/ucw/,regex.test unicode.test hash-test.test mempool.test fb-socket.test trie-test.test string.test sha1.test asort-test.test binheap-test.test \ redblack-test.test fb-file.test fb-grow.test fb-pool.test fb-atomic.test \ fb-limfd.test fb-temp.test fb-mem.test fb-buffer.test fb-mmap.test fb-multi.test url.test strtonum-test.test \ - gary.test time.test crc.test) + gary.test time.test crc.test md5.test) $(o)/ucw/regex.test: $(o)/ucw/regex-t $(o)/ucw/unicode.test: $(o)/ucw/unicode-t @@ -145,6 +145,7 @@ $(o)/ucw/gary.test: $(o)/ucw/gary-t $(o)/ucw/time.test: $(o)/ucw/time-conf-t $(o)/ucw/crc.test: $(o)/ucw/crc-t $(o)/ucw/signames.test: $(o)/ucw/signames-t +$(o)/ucw/md5.test: $(o)/ucw/md5-t ifdef CONFIG_UCW_THREADS TESTS+=$(addprefix $(o)/ucw/,asio.test) diff --git a/ucw/md5.c b/ucw/md5.c index b04278bc..3f8384ba 100644 --- a/ucw/md5.c +++ b/ucw/md5.c @@ -252,3 +252,28 @@ void md5_hash_buffer(byte *outbuf, const byte *buffer, uns length) md5_update(&c, buffer, length); memcpy(outbuf, md5_final(&c), MD5_SIZE); } + +#ifdef TEST + +#include +#include +#include + +int main(void) +{ + md5_context hd; + byte buf[3]; + int cnt; + + md5_init(&hd); + while ((cnt = read(0, buf, sizeof(buf))) > 0) + md5_update(&hd, buf, cnt); + + char text[MD5_HEX_SIZE]; + mem_to_hex(text, md5_final(&hd), MD5_SIZE, 0); + puts(text); + + return 0; +} + +#endif -- 2.39.5