llvm-project
91 строка · 3.5 Кб
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//===----------------------------------------------------------------------===//
9
10#include "gtest/gtest.h"
11
12#include "lldb/Utility/Checksum.h"
13#include "lldb/Utility/FileSpec.h"
14#include "lldb/Utility/SupportFile.h"
15
16using namespace lldb_private;
17
18static llvm::MD5::MD5Result hash1 = {
19{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
20
21static llvm::MD5::MD5Result hash2 = {
22{8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7}};
23
24TEST(SupportFileTest, TestDefaultConstructor) {
25SupportFile support_file;
26
27EXPECT_EQ(support_file.GetSpecOnly(), FileSpec());
28EXPECT_EQ(support_file.GetChecksum(), Checksum());
29}
30
31TEST(SupportFileTest, TestConstructor) {
32FileSpec file_spec("/foo/bar");
33Checksum checksum(hash1);
34SupportFile support_file(file_spec, checksum);
35
36EXPECT_EQ(support_file.GetSpecOnly(), file_spec);
37EXPECT_EQ(support_file.GetChecksum(), checksum);
38}
39
40TEST(SupportFileTest, TestEqual) {
41auto EQ = [&](const SupportFile &LHS, const SupportFile &RHS,
42SupportFile::SupportFileEquality equality) -> bool {
43EXPECT_EQ(LHS.Equal(RHS, equality), RHS.Equal(LHS, equality));
44return LHS.Equal(RHS, equality);
45};
46
47FileSpec foo_bar("/foo/bar");
48Checksum checksum_foo_bar(hash1);
49
50FileSpec bar_baz("/bar/baz");
51Checksum checksum_bar_baz(hash2);
52
53// The canonical support file we're comparing against.
54SupportFile support_file(foo_bar, checksum_foo_bar);
55
56// Support file A is identical.
57SupportFile support_file_a(foo_bar, checksum_foo_bar);
58EXPECT_TRUE(EQ(support_file, support_file_a, SupportFile::eEqualFileSpec));
59EXPECT_TRUE(EQ(support_file, support_file_a, SupportFile::eEqualChecksum));
60EXPECT_TRUE(
61EQ(support_file, support_file_a, SupportFile::eEqualFileSpecAndChecksum));
62EXPECT_TRUE(EQ(support_file, support_file_a,
63SupportFile::eEqualFileSpecAndChecksumIfSet));
64
65// Support file C is has the same path but no checksum.
66SupportFile support_file_b(foo_bar);
67EXPECT_TRUE(EQ(support_file, support_file_b, SupportFile::eEqualFileSpec));
68EXPECT_FALSE(EQ(support_file, support_file_b, SupportFile::eEqualChecksum));
69EXPECT_FALSE(
70EQ(support_file, support_file_b, SupportFile::eEqualFileSpecAndChecksum));
71EXPECT_TRUE(EQ(support_file, support_file_b,
72SupportFile::eEqualFileSpecAndChecksumIfSet));
73
74// Support file D has a different path and checksum.
75SupportFile support_file_c(bar_baz, checksum_bar_baz);
76EXPECT_FALSE(EQ(support_file, support_file_c, SupportFile::eEqualFileSpec));
77EXPECT_FALSE(EQ(support_file, support_file_c,
78SupportFile::eEqualFileSpecAndChecksumIfSet));
79EXPECT_FALSE(EQ(support_file, support_file_c, SupportFile::eEqualChecksum));
80EXPECT_FALSE(
81EQ(support_file, support_file_c, SupportFile::eEqualFileSpecAndChecksum));
82
83// Support file E has a different path but the same checksum.
84SupportFile support_file_d(bar_baz, checksum_foo_bar);
85EXPECT_FALSE(EQ(support_file, support_file_d, SupportFile::eEqualFileSpec));
86EXPECT_FALSE(EQ(support_file, support_file_d,
87SupportFile::eEqualFileSpecAndChecksumIfSet));
88EXPECT_TRUE(EQ(support_file, support_file_d, SupportFile::eEqualChecksum));
89EXPECT_FALSE(
90EQ(support_file, support_file_d, SupportFile::eEqualFileSpecAndChecksum));
91}
92