aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/MD5Test.cpp
diff options
context:
space:
mode:
authorEric Christopher <echristo@gmail.com>2013-05-24 23:08:17 +0000
committerEric Christopher <echristo@gmail.com>2013-05-24 23:08:17 +0000
commitfcee6f0abc138a7f23d931c6af043a4b925229fd (patch)
treefdc62dd90a2a3971906515a2803558acda3662b9 /llvm/unittests/Support/MD5Test.cpp
parentcf2e9080142bdac86a2a693ca3ff4cf423e804c0 (diff)
downloadllvm-fcee6f0abc138a7f23d931c6af043a4b925229fd.zip
llvm-fcee6f0abc138a7f23d931c6af043a4b925229fd.tar.gz
llvm-fcee6f0abc138a7f23d931c6af043a4b925229fd.tar.bz2
ArrayRef-ize MD5 and clean up a few variable names.
Add a stringize method to make dumping a bit easier, and add a testcase exercising a few different paths. llvm-svn: 182692
Diffstat (limited to 'llvm/unittests/Support/MD5Test.cpp')
-rw-r--r--llvm/unittests/Support/MD5Test.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/unittests/Support/MD5Test.cpp b/llvm/unittests/Support/MD5Test.cpp
new file mode 100644
index 0000000..159ae3e
--- /dev/null
+++ b/llvm/unittests/Support/MD5Test.cpp
@@ -0,0 +1,42 @@
+//===- llvm/unittest/Support/MD5Test.cpp - MD5 tests ----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements unit tests for the MD5 functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/MD5.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+void TestMD5Sum(ArrayRef<unsigned char> Input, StringRef Final) {
+ MD5 Hash;
+ Hash.update(Input);
+ MD5::MD5Result MD5Res;
+ Hash.final(MD5Res);
+ SmallString<32> Res;
+ MD5::stringifyResult(MD5Res, Res);
+ EXPECT_EQ(Res, Final);
+}
+
+TEST(MD5Test, MD5) {
+ TestMD5Sum(ArrayRef<unsigned char>((const unsigned char *)"", (size_t) 0),
+ "d41d8cd98f00b204e9800998ecf8427e");
+ TestMD5Sum(ArrayRef<unsigned char>((const unsigned char *)"a", (size_t) 1),
+ "0cc175b9c0f1b6a831c399e269772661");
+ TestMD5Sum(ArrayRef<unsigned char>(
+ (const unsigned char *)"abcdefghijklmnopqrstuvwxyz",
+ (size_t) 26),
+ "c3fcd3d76192e4007dfb496cca67e13b");
+}
+}