1 //===- llvm/unittest/Support/MD5Test.cpp - MD5 tests ----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements unit tests for the MD5 functions.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/Support/MD5.h"
17 #include "gtest/gtest.h"
22 /// \brief Tests an arbitrary set of bytes passed as \p Input.
23 void TestMD5Sum(ArrayRef<uint8_t> Input, StringRef Final) {
26 MD5::MD5Result MD5Res;
29 MD5::stringifyResult(MD5Res, Res);
30 EXPECT_EQ(Res, Final);
33 void TestMD5Sum(StringRef Input, StringRef Final) {
36 MD5::MD5Result MD5Res;
39 MD5::stringifyResult(MD5Res, Res);
40 EXPECT_EQ(Res, Final);
44 TestMD5Sum(makeArrayRef((const uint8_t *)"", (size_t) 0),
45 "d41d8cd98f00b204e9800998ecf8427e");
46 TestMD5Sum(makeArrayRef((const uint8_t *)"a", (size_t) 1),
47 "0cc175b9c0f1b6a831c399e269772661");
48 TestMD5Sum(makeArrayRef((const uint8_t *)"abcdefghijklmnopqrstuvwxyz",
50 "c3fcd3d76192e4007dfb496cca67e13b");
51 TestMD5Sum(makeArrayRef((const uint8_t *)"\0", (size_t) 1),
52 "93b885adfe0da089cdf634904fd59f71");
53 TestMD5Sum(makeArrayRef((const uint8_t *)"a\0", (size_t) 2),
54 "4144e195f46de78a3623da7364d04f11");
55 TestMD5Sum(makeArrayRef((const uint8_t *)"abcdefghijklmnopqrstuvwxyz\0",
57 "81948d1f1554f58cd1a56ebb01f808cb");
58 TestMD5Sum("abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b");