[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / unittests / Support / MD5Test.cpp
blob3a24e1fa69796bb7ac6261f3a9296fa2e277e7c8
1 //===- llvm/unittest/Support/MD5Test.cpp - MD5 tests ----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements unit tests for the MD5 functions.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Support/MD5.h"
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/SmallString.h"
16 #include "gtest/gtest.h"
18 using namespace llvm;
20 namespace {
21 /// Tests an arbitrary set of bytes passed as \p Input.
22 void TestMD5Sum(ArrayRef<uint8_t> Input, StringRef Final) {
23 MD5 Hash;
24 Hash.update(Input);
25 MD5::MD5Result MD5Res;
26 Hash.final(MD5Res);
27 SmallString<32> Res;
28 MD5::stringifyResult(MD5Res, Res);
29 EXPECT_EQ(Res, Final);
32 void TestMD5Sum(StringRef Input, StringRef Final) {
33 MD5 Hash;
34 Hash.update(Input);
35 MD5::MD5Result MD5Res;
36 Hash.final(MD5Res);
37 SmallString<32> Res;
38 MD5::stringifyResult(MD5Res, Res);
39 EXPECT_EQ(Res, Final);
42 TEST(MD5Test, MD5) {
43 TestMD5Sum(makeArrayRef((const uint8_t *)"", (size_t) 0),
44 "d41d8cd98f00b204e9800998ecf8427e");
45 TestMD5Sum(makeArrayRef((const uint8_t *)"a", (size_t) 1),
46 "0cc175b9c0f1b6a831c399e269772661");
47 TestMD5Sum(makeArrayRef((const uint8_t *)"abcdefghijklmnopqrstuvwxyz",
48 (size_t) 26),
49 "c3fcd3d76192e4007dfb496cca67e13b");
50 TestMD5Sum(makeArrayRef((const uint8_t *)"\0", (size_t) 1),
51 "93b885adfe0da089cdf634904fd59f71");
52 TestMD5Sum(makeArrayRef((const uint8_t *)"a\0", (size_t) 2),
53 "4144e195f46de78a3623da7364d04f11");
54 TestMD5Sum(makeArrayRef((const uint8_t *)"abcdefghijklmnopqrstuvwxyz\0",
55 (size_t) 27),
56 "81948d1f1554f58cd1a56ebb01f808cb");
57 TestMD5Sum("abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b");
60 TEST(MD5HashTest, MD5) {
61 ArrayRef<uint8_t> Input((const uint8_t *)"abcdefghijklmnopqrstuvwxyz", 26);
62 std::array<uint8_t, 16> Vec = MD5::hash(Input);
63 MD5::MD5Result MD5Res;
64 SmallString<32> Res;
65 memcpy(MD5Res.Bytes.data(), Vec.data(), Vec.size());
66 MD5::stringifyResult(MD5Res, Res);
67 EXPECT_EQ(Res, "c3fcd3d76192e4007dfb496cca67e13b");
68 EXPECT_EQ(0x3be167ca6c49fb7dULL, MD5Res.high());
69 EXPECT_EQ(0x00e49261d7d3fcc3ULL, MD5Res.low());