llvm-project

Форк
0
/
SupportFileTest.cpp 
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

16
using namespace lldb_private;
17

18
static llvm::MD5::MD5Result hash1 = {
19
    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
20

21
static llvm::MD5::MD5Result hash2 = {
22
    {8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7}};
23

24
TEST(SupportFileTest, TestDefaultConstructor) {
25
  SupportFile support_file;
26

27
  EXPECT_EQ(support_file.GetSpecOnly(), FileSpec());
28
  EXPECT_EQ(support_file.GetChecksum(), Checksum());
29
}
30

31
TEST(SupportFileTest, TestConstructor) {
32
  FileSpec file_spec("/foo/bar");
33
  Checksum checksum(hash1);
34
  SupportFile support_file(file_spec, checksum);
35

36
  EXPECT_EQ(support_file.GetSpecOnly(), file_spec);
37
  EXPECT_EQ(support_file.GetChecksum(), checksum);
38
}
39

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);
45
  };
46

47
  FileSpec foo_bar("/foo/bar");
48
  Checksum checksum_foo_bar(hash1);
49

50
  FileSpec bar_baz("/bar/baz");
51
  Checksum checksum_bar_baz(hash2);
52

53
  // The canonical support file we're comparing against.
54
  SupportFile support_file(foo_bar, checksum_foo_bar);
55

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));
64

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));
73

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));
82

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));
91
}
92

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.