File: | tools/clang/unittests/Basic/FileManagerTest.cpp |
Location: | line 90, column 9 |
Description: | Called C++ object pointer is null |
1 | //===- unittests/Basic/FileMangerTest.cpp ------------ FileManger tests ---===// | |||
2 | // | |||
3 | // The LLVM Compiler Infrastructure | |||
4 | // | |||
5 | // This file is distributed under the University of Illinois Open Source | |||
6 | // License. See LICENSE.TXT for details. | |||
7 | // | |||
8 | //===----------------------------------------------------------------------===// | |||
9 | ||||
10 | #include "clang/Basic/FileManager.h" | |||
11 | #include "clang/Basic/FileSystemOptions.h" | |||
12 | #include "clang/Basic/FileSystemStatCache.h" | |||
13 | #include "llvm/ADT/STLExtras.h" | |||
14 | #include "llvm/Config/llvm-config.h" | |||
15 | #include "gtest/gtest.h" | |||
16 | ||||
17 | using namespace llvm; | |||
18 | using namespace clang; | |||
19 | ||||
20 | namespace { | |||
21 | ||||
22 | // Used to create a fake file system for running the tests with such | |||
23 | // that the tests are not affected by the structure/contents of the | |||
24 | // file system on the machine running the tests. | |||
25 | class FakeStatCache : public FileSystemStatCache { | |||
26 | private: | |||
27 | // Maps a file/directory path to its desired stat result. Anything | |||
28 | // not in this map is considered to not exist in the file system. | |||
29 | llvm::StringMap<FileData, llvm::BumpPtrAllocator> StatCalls; | |||
30 | ||||
31 | void InjectFileOrDirectory(const char *Path, ino_t INode, bool IsFile) { | |||
32 | FileData Data; | |||
33 | Data.Name = Path; | |||
34 | Data.Size = 0; | |||
35 | Data.ModTime = 0; | |||
36 | Data.UniqueID = llvm::sys::fs::UniqueID(1, INode); | |||
37 | Data.IsDirectory = !IsFile; | |||
38 | Data.IsNamedPipe = false; | |||
39 | Data.InPCH = false; | |||
40 | StatCalls[Path] = Data; | |||
41 | } | |||
42 | ||||
43 | public: | |||
44 | // Inject a file with the given inode value to the fake file system. | |||
45 | void InjectFile(const char *Path, ino_t INode) { | |||
46 | InjectFileOrDirectory(Path, INode, /*IsFile=*/true); | |||
47 | } | |||
48 | ||||
49 | // Inject a directory with the given inode value to the fake file system. | |||
50 | void InjectDirectory(const char *Path, ino_t INode) { | |||
51 | InjectFileOrDirectory(Path, INode, /*IsFile=*/false); | |||
52 | } | |||
53 | ||||
54 | // Implement FileSystemStatCache::getStat(). | |||
55 | LookupResult getStat(const char *Path, FileData &Data, bool isFile, | |||
56 | std::unique_ptr<vfs::File> *F, | |||
57 | vfs::FileSystem &FS) override { | |||
58 | if (StatCalls.count(Path) != 0) { | |||
59 | Data = StatCalls[Path]; | |||
60 | return CacheExists; | |||
61 | } | |||
62 | ||||
63 | return CacheMissing; // This means the file/directory doesn't exist. | |||
64 | } | |||
65 | }; | |||
66 | ||||
67 | // The test fixture. | |||
68 | class FileManagerTest : public ::testing::Test { | |||
69 | protected: | |||
70 | FileManagerTest() : manager(options) { | |||
71 | } | |||
72 | ||||
73 | FileSystemOptions options; | |||
74 | FileManager manager; | |||
75 | }; | |||
76 | ||||
77 | // When a virtual file is added, its getDir() field is set correctly | |||
78 | // (not NULL, correct name). | |||
79 | TEST_F(FileManagerTest, getVirtualFileSetsTheDirFieldCorrectly)class FileManagerTest_getVirtualFileSetsTheDirFieldCorrectly_Test : public FileManagerTest { public: FileManagerTest_getVirtualFileSetsTheDirFieldCorrectly_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); FileManagerTest_getVirtualFileSetsTheDirFieldCorrectly_Test (FileManagerTest_getVirtualFileSetsTheDirFieldCorrectly_Test const &); void operator=(FileManagerTest_getVirtualFileSetsTheDirFieldCorrectly_Test const &);};::testing::TestInfo* const FileManagerTest_getVirtualFileSetsTheDirFieldCorrectly_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FileManagerTest", "getVirtualFileSetsTheDirFieldCorrectly", __null, __null, (::testing::internal::GetTypeId<FileManagerTest >()), FileManagerTest::SetUpTestCase, FileManagerTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< FileManagerTest_getVirtualFileSetsTheDirFieldCorrectly_Test >);void FileManagerTest_getVirtualFileSetsTheDirFieldCorrectly_Test ::TestBody() { | |||
80 | const FileEntry *file = manager.getVirtualFile("foo.cpp", 42, 0); | |||
81 | ASSERT_TRUE(file != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 81, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file != nullptr", "false", "true").c_str()) = ::testing::Message (); | |||
82 | ||||
83 | const DirectoryEntry *dir = file->getDir(); | |||
84 | ASSERT_TRUE(dir != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dir != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 84, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dir != nullptr", "false", "true").c_str()) = ::testing::Message (); | |||
85 | EXPECT_STREQ(".", dir->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\".\"", "dir->getName()" , ".", dir->getName()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 85, gtest_ar.failure_message()) = ::testing::Message(); | |||
86 | ||||
87 | file = manager.getVirtualFile("x/y/z.cpp", 42, 0); | |||
| ||||
88 | ASSERT_TRUE(file != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 88, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file != nullptr", "false", "true").c_str()) = ::testing::Message (); | |||
89 | ||||
90 | dir = file->getDir(); | |||
| ||||
91 | ASSERT_TRUE(dir != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dir != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 91, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dir != nullptr", "false", "true").c_str()) = ::testing::Message (); | |||
92 | EXPECT_STREQ("x/y", dir->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"x/y\"", "dir->getName()" , "x/y", dir->getName()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 92, gtest_ar.failure_message()) = ::testing::Message(); | |||
93 | } | |||
94 | ||||
95 | // Before any virtual file is added, no virtual directory exists. | |||
96 | TEST_F(FileManagerTest, NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded)class FileManagerTest_NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded_Test : public FileManagerTest { public: FileManagerTest_NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); FileManagerTest_NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded_Test (FileManagerTest_NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded_Test const &); void operator=(FileManagerTest_NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded_Test const &);};::testing::TestInfo* const FileManagerTest_NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FileManagerTest", "NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded" , __null, __null, (::testing::internal::GetTypeId<FileManagerTest >()), FileManagerTest::SetUpTestCase, FileManagerTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< FileManagerTest_NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded_Test >);void FileManagerTest_NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded_Test ::TestBody() { | |||
97 | // An empty FakeStatCache causes all stat calls made by the | |||
98 | // FileManager to report "file/directory doesn't exist". This | |||
99 | // avoids the possibility of the result of this test being affected | |||
100 | // by what's in the real file system. | |||
101 | manager.addStatCache(llvm::make_unique<FakeStatCache>()); | |||
102 | ||||
103 | EXPECT_EQ(nullptr, manager.getDirectory("virtual/dir/foo"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(nullptr)) == 1)>::Compare( "nullptr", "manager.getDirectory(\"virtual/dir/foo\")", nullptr , manager.getDirectory("virtual/dir/foo")))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 103, gtest_ar.failure_message()) = ::testing::Message(); | |||
104 | EXPECT_EQ(nullptr, manager.getDirectory("virtual/dir"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(nullptr)) == 1)>::Compare( "nullptr", "manager.getDirectory(\"virtual/dir\")", nullptr, manager .getDirectory("virtual/dir")))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 104, gtest_ar.failure_message()) = ::testing::Message(); | |||
105 | EXPECT_EQ(nullptr, manager.getDirectory("virtual"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(nullptr)) == 1)>::Compare( "nullptr", "manager.getDirectory(\"virtual\")", nullptr, manager .getDirectory("virtual")))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 105, gtest_ar.failure_message()) = ::testing::Message(); | |||
106 | } | |||
107 | ||||
108 | // When a virtual file is added, all of its ancestors should be created. | |||
109 | TEST_F(FileManagerTest, getVirtualFileCreatesDirectoryEntriesForAncestors)class FileManagerTest_getVirtualFileCreatesDirectoryEntriesForAncestors_Test : public FileManagerTest { public: FileManagerTest_getVirtualFileCreatesDirectoryEntriesForAncestors_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); FileManagerTest_getVirtualFileCreatesDirectoryEntriesForAncestors_Test (FileManagerTest_getVirtualFileCreatesDirectoryEntriesForAncestors_Test const &); void operator=(FileManagerTest_getVirtualFileCreatesDirectoryEntriesForAncestors_Test const &);};::testing::TestInfo* const FileManagerTest_getVirtualFileCreatesDirectoryEntriesForAncestors_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FileManagerTest", "getVirtualFileCreatesDirectoryEntriesForAncestors" , __null, __null, (::testing::internal::GetTypeId<FileManagerTest >()), FileManagerTest::SetUpTestCase, FileManagerTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< FileManagerTest_getVirtualFileCreatesDirectoryEntriesForAncestors_Test >);void FileManagerTest_getVirtualFileCreatesDirectoryEntriesForAncestors_Test ::TestBody() { | |||
110 | // Fake an empty real file system. | |||
111 | manager.addStatCache(llvm::make_unique<FakeStatCache>()); | |||
112 | ||||
113 | manager.getVirtualFile("virtual/dir/bar.h", 100, 0); | |||
114 | EXPECT_EQ(nullptr, manager.getDirectory("virtual/dir/foo"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(nullptr)) == 1)>::Compare( "nullptr", "manager.getDirectory(\"virtual/dir/foo\")", nullptr , manager.getDirectory("virtual/dir/foo")))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 114, gtest_ar.failure_message()) = ::testing::Message(); | |||
115 | ||||
116 | const DirectoryEntry *dir = manager.getDirectory("virtual/dir"); | |||
117 | ASSERT_TRUE(dir != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dir != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 117, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dir != nullptr", "false", "true").c_str()) = ::testing::Message (); | |||
118 | EXPECT_STREQ("virtual/dir", dir->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"virtual/dir\"" , "dir->getName()", "virtual/dir", dir->getName()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 118, gtest_ar.failure_message()) = ::testing::Message(); | |||
119 | ||||
120 | dir = manager.getDirectory("virtual"); | |||
121 | ASSERT_TRUE(dir != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dir != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 121, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dir != nullptr", "false", "true").c_str()) = ::testing::Message (); | |||
122 | EXPECT_STREQ("virtual", dir->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"virtual\"" , "dir->getName()", "virtual", dir->getName()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 122, gtest_ar.failure_message()) = ::testing::Message(); | |||
123 | } | |||
124 | ||||
125 | // getFile() returns non-NULL if a real file exists at the given path. | |||
126 | TEST_F(FileManagerTest, getFileReturnsValidFileEntryForExistingRealFile)class FileManagerTest_getFileReturnsValidFileEntryForExistingRealFile_Test : public FileManagerTest { public: FileManagerTest_getFileReturnsValidFileEntryForExistingRealFile_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); FileManagerTest_getFileReturnsValidFileEntryForExistingRealFile_Test (FileManagerTest_getFileReturnsValidFileEntryForExistingRealFile_Test const &); void operator=(FileManagerTest_getFileReturnsValidFileEntryForExistingRealFile_Test const &);};::testing::TestInfo* const FileManagerTest_getFileReturnsValidFileEntryForExistingRealFile_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FileManagerTest", "getFileReturnsValidFileEntryForExistingRealFile" , __null, __null, (::testing::internal::GetTypeId<FileManagerTest >()), FileManagerTest::SetUpTestCase, FileManagerTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< FileManagerTest_getFileReturnsValidFileEntryForExistingRealFile_Test >);void FileManagerTest_getFileReturnsValidFileEntryForExistingRealFile_Test ::TestBody() { | |||
127 | // Inject fake files into the file system. | |||
128 | auto statCache = llvm::make_unique<FakeStatCache>(); | |||
129 | statCache->InjectDirectory("/tmp", 42); | |||
130 | statCache->InjectFile("/tmp/test", 43); | |||
131 | ||||
132 | #ifdef LLVM_ON_WIN32 | |||
133 | const char *DirName = "C:."; | |||
134 | const char *FileName = "C:test"; | |||
135 | statCache->InjectDirectory(DirName, 44); | |||
136 | statCache->InjectFile(FileName, 45); | |||
137 | #endif | |||
138 | ||||
139 | manager.addStatCache(std::move(statCache)); | |||
140 | ||||
141 | const FileEntry *file = manager.getFile("/tmp/test"); | |||
142 | ASSERT_TRUE(file != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 142, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file != nullptr", "false", "true").c_str()) = ::testing::Message (); | |||
143 | EXPECT_STREQ("/tmp/test", file->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"/tmp/test\"" , "file->getName()", "/tmp/test", file->getName()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 143, gtest_ar.failure_message()) = ::testing::Message(); | |||
144 | ||||
145 | const DirectoryEntry *dir = file->getDir(); | |||
146 | ASSERT_TRUE(dir != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dir != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 146, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dir != nullptr", "false", "true").c_str()) = ::testing::Message (); | |||
147 | EXPECT_STREQ("/tmp", dir->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"/tmp\"", "dir->getName()" , "/tmp", dir->getName()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 147, gtest_ar.failure_message()) = ::testing::Message(); | |||
148 | ||||
149 | #ifdef LLVM_ON_WIN32 | |||
150 | file = manager.getFile(FileName); | |||
151 | ASSERT_TRUE(file != NULL)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file != __null)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 151, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file != NULL", "false", "true").c_str()) = ::testing::Message (); | |||
152 | ||||
153 | dir = file->getDir(); | |||
154 | ASSERT_TRUE(dir != NULL)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dir != __null)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 154, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dir != NULL", "false", "true").c_str()) = ::testing::Message (); | |||
155 | EXPECT_STREQ(DirName, dir->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("DirName", "dir->getName()" , DirName, dir->getName()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 155, gtest_ar.failure_message()) = ::testing::Message(); | |||
156 | #endif | |||
157 | } | |||
158 | ||||
159 | // getFile() returns non-NULL if a virtual file exists at the given path. | |||
160 | TEST_F(FileManagerTest, getFileReturnsValidFileEntryForExistingVirtualFile)class FileManagerTest_getFileReturnsValidFileEntryForExistingVirtualFile_Test : public FileManagerTest { public: FileManagerTest_getFileReturnsValidFileEntryForExistingVirtualFile_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); FileManagerTest_getFileReturnsValidFileEntryForExistingVirtualFile_Test (FileManagerTest_getFileReturnsValidFileEntryForExistingVirtualFile_Test const &); void operator=(FileManagerTest_getFileReturnsValidFileEntryForExistingVirtualFile_Test const &);};::testing::TestInfo* const FileManagerTest_getFileReturnsValidFileEntryForExistingVirtualFile_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FileManagerTest", "getFileReturnsValidFileEntryForExistingVirtualFile" , __null, __null, (::testing::internal::GetTypeId<FileManagerTest >()), FileManagerTest::SetUpTestCase, FileManagerTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< FileManagerTest_getFileReturnsValidFileEntryForExistingVirtualFile_Test >);void FileManagerTest_getFileReturnsValidFileEntryForExistingVirtualFile_Test ::TestBody() { | |||
161 | // Fake an empty real file system. | |||
162 | manager.addStatCache(llvm::make_unique<FakeStatCache>()); | |||
163 | ||||
164 | manager.getVirtualFile("virtual/dir/bar.h", 100, 0); | |||
165 | const FileEntry *file = manager.getFile("virtual/dir/bar.h"); | |||
166 | ASSERT_TRUE(file != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 166, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file != nullptr", "false", "true").c_str()) = ::testing::Message (); | |||
167 | EXPECT_STREQ("virtual/dir/bar.h", file->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"virtual/dir/bar.h\"" , "file->getName()", "virtual/dir/bar.h", file->getName ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 167, gtest_ar.failure_message()) = ::testing::Message(); | |||
168 | ||||
169 | const DirectoryEntry *dir = file->getDir(); | |||
170 | ASSERT_TRUE(dir != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dir != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 170, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dir != nullptr", "false", "true").c_str()) = ::testing::Message (); | |||
171 | EXPECT_STREQ("virtual/dir", dir->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperSTREQ("\"virtual/dir\"" , "dir->getName()", "virtual/dir", dir->getName()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 171, gtest_ar.failure_message()) = ::testing::Message(); | |||
172 | } | |||
173 | ||||
174 | // getFile() returns different FileEntries for different paths when | |||
175 | // there's no aliasing. | |||
176 | TEST_F(FileManagerTest, getFileReturnsDifferentFileEntriesForDifferentFiles)class FileManagerTest_getFileReturnsDifferentFileEntriesForDifferentFiles_Test : public FileManagerTest { public: FileManagerTest_getFileReturnsDifferentFileEntriesForDifferentFiles_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); FileManagerTest_getFileReturnsDifferentFileEntriesForDifferentFiles_Test (FileManagerTest_getFileReturnsDifferentFileEntriesForDifferentFiles_Test const &); void operator=(FileManagerTest_getFileReturnsDifferentFileEntriesForDifferentFiles_Test const &);};::testing::TestInfo* const FileManagerTest_getFileReturnsDifferentFileEntriesForDifferentFiles_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FileManagerTest", "getFileReturnsDifferentFileEntriesForDifferentFiles" , __null, __null, (::testing::internal::GetTypeId<FileManagerTest >()), FileManagerTest::SetUpTestCase, FileManagerTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< FileManagerTest_getFileReturnsDifferentFileEntriesForDifferentFiles_Test >);void FileManagerTest_getFileReturnsDifferentFileEntriesForDifferentFiles_Test ::TestBody() { | |||
177 | // Inject two fake files into the file system. Different inodes | |||
178 | // mean the files are not symlinked together. | |||
179 | auto statCache = llvm::make_unique<FakeStatCache>(); | |||
180 | statCache->InjectDirectory(".", 41); | |||
181 | statCache->InjectFile("foo.cpp", 42); | |||
182 | statCache->InjectFile("bar.cpp", 43); | |||
183 | manager.addStatCache(std::move(statCache)); | |||
184 | ||||
185 | const FileEntry *fileFoo = manager.getFile("foo.cpp"); | |||
186 | const FileEntry *fileBar = manager.getFile("bar.cpp"); | |||
187 | ASSERT_TRUE(fileFoo != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(fileFoo != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 187, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "fileFoo != nullptr", "false", "true").c_str()) = ::testing ::Message(); | |||
188 | ASSERT_TRUE(fileBar != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(fileBar != nullptr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 188, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "fileBar != nullptr", "false", "true").c_str()) = ::testing ::Message(); | |||
189 | EXPECT_NE(fileFoo, fileBar)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("fileFoo", "fileBar" , fileFoo, fileBar))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 189, gtest_ar.failure_message()) = ::testing::Message(); | |||
190 | } | |||
191 | ||||
192 | // getFile() returns NULL if neither a real file nor a virtual file | |||
193 | // exists at the given path. | |||
194 | TEST_F(FileManagerTest, getFileReturnsNULLForNonexistentFile)class FileManagerTest_getFileReturnsNULLForNonexistentFile_Test : public FileManagerTest { public: FileManagerTest_getFileReturnsNULLForNonexistentFile_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); FileManagerTest_getFileReturnsNULLForNonexistentFile_Test (FileManagerTest_getFileReturnsNULLForNonexistentFile_Test const &); void operator=(FileManagerTest_getFileReturnsNULLForNonexistentFile_Test const &);};::testing::TestInfo* const FileManagerTest_getFileReturnsNULLForNonexistentFile_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FileManagerTest", "getFileReturnsNULLForNonexistentFile", __null , __null, (::testing::internal::GetTypeId<FileManagerTest> ()), FileManagerTest::SetUpTestCase, FileManagerTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< FileManagerTest_getFileReturnsNULLForNonexistentFile_Test >);void FileManagerTest_getFileReturnsNULLForNonexistentFile_Test ::TestBody() { | |||
195 | // Inject a fake foo.cpp into the file system. | |||
196 | auto statCache = llvm::make_unique<FakeStatCache>(); | |||
197 | statCache->InjectDirectory(".", 41); | |||
198 | statCache->InjectFile("foo.cpp", 42); | |||
199 | manager.addStatCache(std::move(statCache)); | |||
200 | ||||
201 | // Create a virtual bar.cpp file. | |||
202 | manager.getVirtualFile("bar.cpp", 200, 0); | |||
203 | ||||
204 | const FileEntry *file = manager.getFile("xyz.txt"); | |||
205 | EXPECT_EQ(nullptr, file)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(nullptr)) == 1)>::Compare( "nullptr", "file", nullptr, file))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 205, gtest_ar.failure_message()) = ::testing::Message(); | |||
206 | } | |||
207 | ||||
208 | // The following tests apply to Unix-like system only. | |||
209 | ||||
210 | #ifndef LLVM_ON_WIN32 | |||
211 | ||||
212 | // getFile() returns the same FileEntry for real files that are aliases. | |||
213 | TEST_F(FileManagerTest, getFileReturnsSameFileEntryForAliasedRealFiles)class FileManagerTest_getFileReturnsSameFileEntryForAliasedRealFiles_Test : public FileManagerTest { public: FileManagerTest_getFileReturnsSameFileEntryForAliasedRealFiles_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); FileManagerTest_getFileReturnsSameFileEntryForAliasedRealFiles_Test (FileManagerTest_getFileReturnsSameFileEntryForAliasedRealFiles_Test const &); void operator=(FileManagerTest_getFileReturnsSameFileEntryForAliasedRealFiles_Test const &);};::testing::TestInfo* const FileManagerTest_getFileReturnsSameFileEntryForAliasedRealFiles_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FileManagerTest", "getFileReturnsSameFileEntryForAliasedRealFiles" , __null, __null, (::testing::internal::GetTypeId<FileManagerTest >()), FileManagerTest::SetUpTestCase, FileManagerTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< FileManagerTest_getFileReturnsSameFileEntryForAliasedRealFiles_Test >);void FileManagerTest_getFileReturnsSameFileEntryForAliasedRealFiles_Test ::TestBody() { | |||
214 | // Inject two real files with the same inode. | |||
215 | auto statCache = llvm::make_unique<FakeStatCache>(); | |||
216 | statCache->InjectDirectory("abc", 41); | |||
217 | statCache->InjectFile("abc/foo.cpp", 42); | |||
218 | statCache->InjectFile("abc/bar.cpp", 42); | |||
219 | manager.addStatCache(std::move(statCache)); | |||
220 | ||||
221 | EXPECT_EQ(manager.getFile("abc/foo.cpp"), manager.getFile("abc/bar.cpp"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(manager.getFile("abc/foo.cpp" ))) == 1)>::Compare("manager.getFile(\"abc/foo.cpp\")", "manager.getFile(\"abc/bar.cpp\")" , manager.getFile("abc/foo.cpp"), manager.getFile("abc/bar.cpp" )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 221, gtest_ar.failure_message()) = ::testing::Message(); | |||
222 | } | |||
223 | ||||
224 | // getFile() returns the same FileEntry for virtual files that have | |||
225 | // corresponding real files that are aliases. | |||
226 | TEST_F(FileManagerTest, getFileReturnsSameFileEntryForAliasedVirtualFiles)class FileManagerTest_getFileReturnsSameFileEntryForAliasedVirtualFiles_Test : public FileManagerTest { public: FileManagerTest_getFileReturnsSameFileEntryForAliasedVirtualFiles_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); FileManagerTest_getFileReturnsSameFileEntryForAliasedVirtualFiles_Test (FileManagerTest_getFileReturnsSameFileEntryForAliasedVirtualFiles_Test const &); void operator=(FileManagerTest_getFileReturnsSameFileEntryForAliasedVirtualFiles_Test const &);};::testing::TestInfo* const FileManagerTest_getFileReturnsSameFileEntryForAliasedVirtualFiles_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FileManagerTest", "getFileReturnsSameFileEntryForAliasedVirtualFiles" , __null, __null, (::testing::internal::GetTypeId<FileManagerTest >()), FileManagerTest::SetUpTestCase, FileManagerTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< FileManagerTest_getFileReturnsSameFileEntryForAliasedVirtualFiles_Test >);void FileManagerTest_getFileReturnsSameFileEntryForAliasedVirtualFiles_Test ::TestBody() { | |||
227 | // Inject two real files with the same inode. | |||
228 | auto statCache = llvm::make_unique<FakeStatCache>(); | |||
229 | statCache->InjectDirectory("abc", 41); | |||
230 | statCache->InjectFile("abc/foo.cpp", 42); | |||
231 | statCache->InjectFile("abc/bar.cpp", 42); | |||
232 | manager.addStatCache(std::move(statCache)); | |||
233 | ||||
234 | manager.getVirtualFile("abc/foo.cpp", 100, 0); | |||
235 | manager.getVirtualFile("abc/bar.cpp", 200, 0); | |||
236 | ||||
237 | EXPECT_EQ(manager.getFile("abc/foo.cpp"), manager.getFile("abc/bar.cpp"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(manager.getFile("abc/foo.cpp" ))) == 1)>::Compare("manager.getFile(\"abc/foo.cpp\")", "manager.getFile(\"abc/bar.cpp\")" , manager.getFile("abc/foo.cpp"), manager.getFile("abc/bar.cpp" )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/tmp/buildd/llvm-toolchain-snapshot-3.8~svn257205/tools/clang/unittests/Basic/FileManagerTest.cpp" , 237, gtest_ar.failure_message()) = ::testing::Message(); | |||
238 | } | |||
239 | ||||
240 | TEST_F(FileManagerTest, addRemoveStatCache)class FileManagerTest_addRemoveStatCache_Test : public FileManagerTest { public: FileManagerTest_addRemoveStatCache_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); FileManagerTest_addRemoveStatCache_Test (FileManagerTest_addRemoveStatCache_Test const &); void operator =(FileManagerTest_addRemoveStatCache_Test const &);};::testing ::TestInfo* const FileManagerTest_addRemoveStatCache_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "FileManagerTest" , "addRemoveStatCache", __null, __null, (::testing::internal:: GetTypeId<FileManagerTest>()), FileManagerTest::SetUpTestCase , FileManagerTest::TearDownTestCase, new ::testing::internal:: TestFactoryImpl< FileManagerTest_addRemoveStatCache_Test> );void FileManagerTest_addRemoveStatCache_Test::TestBody() { | |||
241 | manager.addStatCache(llvm::make_unique<FakeStatCache>()); | |||
242 | auto statCacheOwner = llvm::make_unique<FakeStatCache>(); | |||
243 | auto *statCache = statCacheOwner.get(); | |||
244 | manager.addStatCache(std::move(statCacheOwner)); | |||
245 | manager.addStatCache(llvm::make_unique<FakeStatCache>()); | |||
246 | manager.removeStatCache(statCache); | |||
247 | } | |||
248 | ||||
249 | #endif // !LLVM_ON_WIN32 | |||
250 | ||||
251 | } // anonymous namespace |