diff options
Diffstat (limited to 'test/common/md5.h')
-rw-r--r-- | test/common/md5.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/common/md5.h b/test/common/md5.h new file mode 100644 index 0000000000..c59b6dc853 --- /dev/null +++ b/test/common/md5.h @@ -0,0 +1,50 @@ +#include <cxxtest/TestSuite.h> + +#include "common/md5.h" +#include "common/stream.h" + +/* + * those are the standard RFC 1321 test vectors + */ +static const char *md5_test_string[] = { + "", + "a", + "abc", + "message digest", + "abcdefghijklmnopqrstuvwxyz", + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "12345678901234567890123456789012345678901234567890123456789012" \ + "345678901234567890" +}; + +static const char *md5_test_digest[] = { + "d41d8cd98f00b204e9800998ecf8427e", + "0cc175b9c0f1b6a831c399e269772661", + "900150983cd24fb0d6963f7d28e17f72", + "f96b697d7cb7938d525a2f31aaf161d0", + "c3fcd3d76192e4007dfb496cca67e13b", + "d174ab98d277d9f5a5611c2c9f419d9f", + "57edf4a22be3c955ac49da2e2107b67a" +}; + +class MD5TestSuite : public CxxTest::TestSuite { + public: + void test_md5_file() { + int i, j; + char output[33]; + unsigned char md5sum[16]; + + for (i = 0; i < 7; i++) { + Common::MemoryReadStream stream((const byte *)md5_test_string[i], strlen(md5_test_string[i])); + Common::md5_file(stream, md5sum); + + for (j = 0; j < 16; j++) { + sprintf(output + j * 2, "%02x", md5sum[j]); + } + + Common::String tmp(output); + TS_ASSERT_EQUALS(tmp, md5_test_digest[i]); + } + } + +}; |