1//===-- ChecksumTest.cpp --------------------------------------------------===//
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#include "gtest/gtest.h"
10
11#include "lldb/Utility/Checksum.h"
12
13using namespace lldb_private;
14
15static llvm::MD5::MD5Result hash1 = {
16 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
17
18static llvm::MD5::MD5Result hash2 = {
19 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
20
21static llvm::MD5::MD5Result hash3 = {
22 {8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7}};
23
24TEST(ChecksumTest, TestConstructor) {
25 Checksum checksum1;
26 EXPECT_FALSE(static_cast<bool>(checksum1));
27 EXPECT_EQ(checksum1, Checksum());
28
29 Checksum checksum2 = Checksum(hash1);
30 EXPECT_EQ(checksum2, Checksum(hash1));
31
32 Checksum checksum3(checksum2);
33 EXPECT_EQ(checksum3, Checksum(hash1));
34}
35
36TEST(ChecksumTest, TestCopyConstructor) {
37 Checksum checksum1;
38 EXPECT_FALSE(static_cast<bool>(checksum1));
39 EXPECT_EQ(checksum1, Checksum());
40
41 Checksum checksum2 = checksum1;
42 EXPECT_EQ(checksum2, checksum1);
43
44 Checksum checksum3(checksum1);
45 EXPECT_EQ(checksum3, checksum1);
46}
47
48TEST(ChecksumTest, TestMD5) {
49 Checksum checksum1(hash1);
50 EXPECT_TRUE(static_cast<bool>(checksum1));
51
52 // Make sure two checksums with the same underlying hashes are the same.
53 EXPECT_EQ(Checksum(hash1), Checksum(hash2));
54
55 // Make sure two checksums with different underlying hashes are different.
56 EXPECT_NE(Checksum(hash1), Checksum(hash3));
57}
58

source code of lldb/unittests/Utility/ChecksumTest.cpp