[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / lldb / unittests / Utility / SupportFileTest.cpp
blob44fbfe0f5725434888ade8b63d47725884b4db87
1 //===-- SupportFileTest.cpp
2 //--------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
12 #include "lldb/Utility/Checksum.h"
13 #include "lldb/Utility/FileSpec.h"
14 #include "lldb/Utility/SupportFile.h"
16 using namespace lldb_private;
18 static llvm::MD5::MD5Result hash1 = {
19 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
21 static llvm::MD5::MD5Result hash2 = {
22 {8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7}};
24 TEST(SupportFileTest, TestDefaultConstructor) {
25 SupportFile support_file;
27 EXPECT_EQ(support_file.GetSpecOnly(), FileSpec());
28 EXPECT_EQ(support_file.GetChecksum(), Checksum());
31 TEST(SupportFileTest, TestConstructor) {
32 FileSpec file_spec("/foo/bar");
33 Checksum checksum(hash1);
34 SupportFile support_file(file_spec, checksum);
36 EXPECT_EQ(support_file.GetSpecOnly(), file_spec);
37 EXPECT_EQ(support_file.GetChecksum(), checksum);
40 TEST(SupportFileTest, TestEqual) {
41 auto EQ = [&](const SupportFile &LHS, const SupportFile &RHS,
42 SupportFile::SupportFileEquality equality) -> bool {
43 EXPECT_EQ(LHS.Equal(RHS, equality), RHS.Equal(LHS, equality));
44 return LHS.Equal(RHS, equality);
47 FileSpec foo_bar("/foo/bar");
48 Checksum checksum_foo_bar(hash1);
50 FileSpec bar_baz("/bar/baz");
51 Checksum checksum_bar_baz(hash2);
53 // The canonical support file we're comparing against.
54 SupportFile support_file(foo_bar, checksum_foo_bar);
56 // Support file A is identical.
57 SupportFile support_file_a(foo_bar, checksum_foo_bar);
58 EXPECT_TRUE(EQ(support_file, support_file_a, SupportFile::eEqualFileSpec));
59 EXPECT_TRUE(EQ(support_file, support_file_a, SupportFile::eEqualChecksum));
60 EXPECT_TRUE(
61 EQ(support_file, support_file_a, SupportFile::eEqualFileSpecAndChecksum));
62 EXPECT_TRUE(EQ(support_file, support_file_a,
63 SupportFile::eEqualFileSpecAndChecksumIfSet));
65 // Support file C is has the same path but no checksum.
66 SupportFile support_file_b(foo_bar);
67 EXPECT_TRUE(EQ(support_file, support_file_b, SupportFile::eEqualFileSpec));
68 EXPECT_FALSE(EQ(support_file, support_file_b, SupportFile::eEqualChecksum));
69 EXPECT_FALSE(
70 EQ(support_file, support_file_b, SupportFile::eEqualFileSpecAndChecksum));
71 EXPECT_TRUE(EQ(support_file, support_file_b,
72 SupportFile::eEqualFileSpecAndChecksumIfSet));
74 // Support file D has a different path and checksum.
75 SupportFile support_file_c(bar_baz, checksum_bar_baz);
76 EXPECT_FALSE(EQ(support_file, support_file_c, SupportFile::eEqualFileSpec));
77 EXPECT_FALSE(EQ(support_file, support_file_c,
78 SupportFile::eEqualFileSpecAndChecksumIfSet));
79 EXPECT_FALSE(EQ(support_file, support_file_c, SupportFile::eEqualChecksum));
80 EXPECT_FALSE(
81 EQ(support_file, support_file_c, SupportFile::eEqualFileSpecAndChecksum));
83 // Support file E has a different path but the same checksum.
84 SupportFile support_file_d(bar_baz, checksum_foo_bar);
85 EXPECT_FALSE(EQ(support_file, support_file_d, SupportFile::eEqualFileSpec));
86 EXPECT_FALSE(EQ(support_file, support_file_d,
87 SupportFile::eEqualFileSpecAndChecksumIfSet));
88 EXPECT_TRUE(EQ(support_file, support_file_d, SupportFile::eEqualChecksum));
89 EXPECT_FALSE(
90 EQ(support_file, support_file_d, SupportFile::eEqualFileSpecAndChecksum));