blob: c5658ec4976aa0a1b4e91c8ffea8fe8079dde00a [file] [log] [blame]
Eric Christopherf7306f22013-05-24 23:08:17 +00001//===- llvm/unittest/Support/MD5Test.cpp - MD5 tests ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements unit tests for the MD5 functions.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/ADT/ArrayRef.h"
15#include "llvm/ADT/SmallString.h"
16#include "llvm/Support/MD5.h"
17#include "gtest/gtest.h"
18
19using namespace llvm;
20
21namespace {
Eric Christopher12378d42013-05-30 00:43:26 +000022/// \brief Tests an arbitrary set of bytes passed as \p Input.
Eric Christophercbb45aa2013-05-31 22:34:52 +000023void TestMD5Sum(ArrayRef<uint8_t> Input, StringRef Final) {
Eric Christopherf7306f22013-05-24 23:08:17 +000024 MD5 Hash;
25 Hash.update(Input);
26 MD5::MD5Result MD5Res;
27 Hash.final(MD5Res);
28 SmallString<32> Res;
29 MD5::stringifyResult(MD5Res, Res);
30 EXPECT_EQ(Res, Final);
31}
32
33TEST(MD5Test, MD5) {
Eric Christophercbb45aa2013-05-31 22:34:52 +000034 TestMD5Sum(ArrayRef<uint8_t>((const uint8_t *)"", (size_t) 0),
Eric Christopherf7306f22013-05-24 23:08:17 +000035 "d41d8cd98f00b204e9800998ecf8427e");
Eric Christophercbb45aa2013-05-31 22:34:52 +000036 TestMD5Sum(ArrayRef<uint8_t>((const uint8_t *)"a", (size_t) 1),
Eric Christopherf7306f22013-05-24 23:08:17 +000037 "0cc175b9c0f1b6a831c399e269772661");
Eric Christophercbb45aa2013-05-31 22:34:52 +000038 TestMD5Sum(ArrayRef<uint8_t>(
39 (const uint8_t *)"abcdefghijklmnopqrstuvwxyz",
Eric Christopherf7306f22013-05-24 23:08:17 +000040 (size_t) 26),
41 "c3fcd3d76192e4007dfb496cca67e13b");
Eric Christophercbb45aa2013-05-31 22:34:52 +000042 TestMD5Sum(ArrayRef<uint8_t>((const uint8_t *)"\0", (size_t) 1),
Eric Christopher12378d42013-05-30 00:43:26 +000043 "93b885adfe0da089cdf634904fd59f71");
Eric Christophercbb45aa2013-05-31 22:34:52 +000044 TestMD5Sum(ArrayRef<uint8_t>((const uint8_t *)"a\0", (size_t) 2),
Eric Christopher12378d42013-05-30 00:43:26 +000045 "4144e195f46de78a3623da7364d04f11");
Eric Christophercbb45aa2013-05-31 22:34:52 +000046 TestMD5Sum(ArrayRef<uint8_t>(
47 (const uint8_t *)"abcdefghijklmnopqrstuvwxyz\0",
Eric Christopher12378d42013-05-30 00:43:26 +000048 (size_t) 27),
49 "81948d1f1554f58cd1a56ebb01f808cb");
Eric Christopherf7306f22013-05-24 23:08:17 +000050}
51}