1 //===-- SourceManagerTest.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 "lldb/Core/SourceManager.h"
10 #include "lldb/Host/FileSystem.h"
11 #include "gtest/gtest.h"
12
13 using namespace lldb;
14 using namespace lldb_private;
15
16 class SourceFileCache : public ::testing::Test {
17 public:
SetUp()18 void SetUp() override { FileSystem::Initialize(); }
TearDown()19 void TearDown() override { FileSystem::Terminate(); }
20 };
21
TEST_F(SourceFileCache,FindSourceFileFound)22 TEST_F(SourceFileCache, FindSourceFileFound) {
23 SourceManager::SourceFileCache cache;
24
25 // Insert: foo
26 FileSpec foo_file_spec("foo");
27 auto foo_file_sp =
28 std::make_shared<SourceManager::File>(foo_file_spec, nullptr);
29 cache.AddSourceFile(foo_file_sp);
30
31 // Query: foo, expect found.
32 FileSpec another_foo_file_spec("foo");
33 ASSERT_EQ(cache.FindSourceFile(another_foo_file_spec), foo_file_sp);
34 }
35
TEST_F(SourceFileCache,FindSourceFileNotFound)36 TEST_F(SourceFileCache, FindSourceFileNotFound) {
37 SourceManager::SourceFileCache cache;
38
39 // Insert: foo
40 FileSpec foo_file_spec("foo");
41 auto foo_file_sp =
42 std::make_shared<SourceManager::File>(foo_file_spec, nullptr);
43 cache.AddSourceFile(foo_file_sp);
44
45 // Query: bar, expect not found.
46 FileSpec bar_file_spec("bar");
47 ASSERT_EQ(cache.FindSourceFile(bar_file_spec), nullptr);
48 }
49