aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/unittest/pchtaskqueue-test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/unittest/pchtaskqueue-test.cpp')
-rw-r--r--tests/unit/unittest/pchtaskqueue-test.cpp121
1 files changed, 111 insertions, 10 deletions
diff --git a/tests/unit/unittest/pchtaskqueue-test.cpp b/tests/unit/unittest/pchtaskqueue-test.cpp
index f516858862..6a4a2211d8 100644
--- a/tests/unit/unittest/pchtaskqueue-test.cpp
+++ b/tests/unit/unittest/pchtaskqueue-test.cpp
@@ -25,14 +25,18 @@
#include "googletest.h"
+#include "mockfilesystem.h"
#include "mockpchcreator.h"
#include "mockprecompiledheaderstorage.h"
#include "mocksqlitetransactionbackend.h"
#include "mocktaskscheduler.h"
#include "testenvironment.h"
+#include <filepathcaching.h>
#include <pchtaskqueue.h>
#include <progresscounter.h>
+#include <refactoringdatabaseinitializer.h>
+#include <sqlitedatabase.h>
namespace {
@@ -45,9 +49,26 @@ using ClangBackEnd::SlotUsage;
class PchTaskQueue : public testing::Test
{
protected:
+ ClangBackEnd::FilePathId filePathId(Utils::SmallStringView path)
+ {
+ return filePathCache.filePathId(ClangBackEnd::FilePathView{path});
+ }
+
+ ClangBackEnd::FilePathIds filePathIds(const Utils::PathStringVector &paths)
+ {
+ return filePathCache.filePathIds(Utils::transform(paths, [](const Utils::PathString &path) {
+ return ClangBackEnd::FilePathView(path);
+ }));
+ }
+
+protected:
+ Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
+ ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
+ ClangBackEnd::FilePathCaching filePathCache{database};
NiceMock<MockTaskScheduler<ClangBackEnd::PchTaskQueue::Task>> mockSytemPchTaskScheduler;
NiceMock<MockTaskScheduler<ClangBackEnd::PchTaskQueue::Task>> mockProjectPchTaskScheduler;
NiceMock<MockPrecompiledHeaderStorage> mockPrecompiledHeaderStorage;
+ NiceMock<MockFileSystem> mockFileSystem;
MockSqliteTransactionBackend mockSqliteTransactionBackend;
NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()};
@@ -57,7 +78,9 @@ protected:
progressCounter,
mockPrecompiledHeaderStorage,
mockSqliteTransactionBackend,
- testEnvironment};
+ testEnvironment,
+ mockFileSystem,
+ filePathCache};
IncludeSearchPaths systemIncludeSearchPaths{
{"/includes", 1, IncludeSearchPathType::BuiltIn},
{"/other/includes", 2, IncludeSearchPathType::System}};
@@ -71,7 +94,6 @@ protected:
{3, 4},
{6, 7},
{{"YI", "1", 1}, {"SAN", "3", 3}},
- {{"LIANG", 0}, {"YI", 1}},
{"--yi"},
systemIncludeSearchPaths,
projectIncludeSearchPaths};
@@ -82,7 +104,6 @@ protected:
{3, 4},
{6, 7},
{{"YI", "1", 1}, {"SAN", "3", 3}},
- {{"LIANG", 0}, {"YI", 1}},
{"--yi"},
systemIncludeSearchPaths,
projectIncludeSearchPaths};
@@ -93,7 +114,6 @@ protected:
{4, 7},
{8, 9},
{{"YI", "1", 1}, {"SAN", "3", 3}},
- {{"LIANG", 0}, {"YI", 1}},
{"--yi"},
systemIncludeSearchPaths,
projectIncludeSearchPaths};
@@ -104,7 +124,6 @@ protected:
{3, 4},
{6, 7},
{{"YI", "1", 1}, {"SAN", "3", 3}},
- {{"LIANG", 0}, {"YI", 1}},
{"--yi"},
systemIncludeSearchPaths,
projectIncludeSearchPaths};
@@ -115,7 +134,6 @@ protected:
{13, 14},
{16, 17},
{{"SE", "4", 4}, {"WU", "5", 5}},
- {{"ER", 2}, {"SAN", 3}},
{"--yi"},
systemIncludeSearchPaths,
projectIncludeSearchPaths};
@@ -126,7 +144,6 @@ protected:
{13, 14},
{16, 17},
{{"SE", "4", 4}, {"WU", "5", 5}},
- {{"ER", 2}, {"SAN", 3}},
{"--yi"},
systemIncludeSearchPaths,
projectIncludeSearchPaths};
@@ -137,7 +154,6 @@ protected:
{23, 24},
{26, 27},
{{"SE", "4", 4}, {"WU", "5", 5}},
- {{"ER", 2}, {"SAN", 3}},
{"--yi"},
systemIncludeSearchPaths,
projectIncludeSearchPaths};
@@ -148,7 +164,6 @@ protected:
{23, 24},
{26, 27},
{{"SE", "4", 4}, {"WU", "5", 5}},
- {{"ER", 2}, {"SAN", 3}},
{"--yi"},
systemIncludeSearchPaths,
projectIncludeSearchPaths};
@@ -159,7 +174,6 @@ protected:
{3, 4},
{5, 8},
{{"YI", "1", 1}, {"SAN", "3", 3}},
- {{"LIANG", 0}, {"YI", 1}},
{"--yi"},
systemIncludeSearchPaths,
projectIncludeSearchPaths};
@@ -399,4 +413,91 @@ TEST_F(PchTaskQueue, DeleteSystemPchEntryInDatabaseIfNoPchIsGenerated)
tasks.front()(mockPchCreator);
}
+TEST_F(PchTaskQueue, DontDeleteUnusedPchsIfSystemTaskAreProcessed)
+{
+ QString pchsDirectory{testEnvironment.pchBuildDirectory()};
+ ON_CALL(mockSytemPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 1}));
+ ON_CALL(mockProjectPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0}));
+ ON_CALL(mockFileSystem, directoryEntries(Eq(pchsDirectory)))
+ .WillByDefault(Return(filePathIds({"/tmp/foo", "/tmp/bar"})));
+ ON_CALL(mockPrecompiledHeaderStorage, fetchAllPchPaths())
+ .WillByDefault(Return(ClangBackEnd::FilePaths{"/tmp/foo", "/tmp/poo"}));
+
+ EXPECT_CALL(mockFileSystem, remove(_)).Times(0);
+
+ queue.processEntries();
+}
+
+TEST_F(PchTaskQueue, DontDeleteUnusedPchsIfProjectTaskAreProcessed)
+{
+ QString pchsDirectory{testEnvironment.pchBuildDirectory()};
+ ON_CALL(mockSytemPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0}));
+ ON_CALL(mockProjectPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 1}));
+ ON_CALL(mockFileSystem, directoryEntries(Eq(pchsDirectory)))
+ .WillByDefault(Return(filePathIds({"/tmp/foo", "/tmp/bar"})));
+ ON_CALL(mockPrecompiledHeaderStorage, fetchAllPchPaths())
+ .WillByDefault(Return(ClangBackEnd::FilePaths{"/tmp/foo", "/tmp/poo"}));
+
+ EXPECT_CALL(mockFileSystem, remove(_)).Times(0);
+
+ queue.processEntries();
+}
+
+TEST_F(PchTaskQueue, DontDeleteUnusedPchsIfSystemTaskIsAdded)
+{
+ QString pchsDirectory{testEnvironment.pchBuildDirectory()};
+ ON_CALL(mockSytemPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0}));
+ ON_CALL(mockProjectPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0}));
+ ON_CALL(mockFileSystem, directoryEntries(Eq(pchsDirectory)))
+ .WillByDefault(Return(filePathIds({"/tmp/foo", "/tmp/bar"})));
+ ON_CALL(mockPrecompiledHeaderStorage, fetchAllPchPaths())
+ .WillByDefault(Return(ClangBackEnd::FilePaths{"/tmp/foo", "/tmp/poo"}));
+ queue.addSystemPchTasks({systemTask1});
+
+ EXPECT_CALL(mockFileSystem, remove(_)).Times(0);
+
+ queue.processEntries();
+}
+
+TEST_F(PchTaskQueue, DontDeleteUnusedPchsIfProjectTaskIsAdded)
+{
+ QString pchsDirectory{testEnvironment.pchBuildDirectory()};
+ ON_CALL(mockSytemPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0}));
+ ON_CALL(mockProjectPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0}));
+ ON_CALL(mockFileSystem, directoryEntries(Eq(pchsDirectory)))
+ .WillByDefault(Return(filePathIds({"/tmp/foo", "/tmp/bar"})));
+ ON_CALL(mockPrecompiledHeaderStorage, fetchAllPchPaths())
+ .WillByDefault(Return(ClangBackEnd::FilePaths{"/tmp/foo", "/tmp/poo"}));
+ queue.addProjectPchTasks({projectTask1});
+
+ EXPECT_CALL(mockFileSystem, remove(_)).Times(0);
+
+ queue.processEntries();
+}
+
+TEST_F(PchTaskQueue, DeleteUnusedPchs)
+{
+ QString pchsDirectory{testEnvironment.pchBuildDirectory()};
+ ON_CALL(mockSytemPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0}));
+ ON_CALL(mockProjectPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0}));
+ ON_CALL(mockFileSystem, directoryEntries(Eq(pchsDirectory)))
+ .WillByDefault(Return(filePathIds({
+ "/tmp/foo",
+ "/tmp/bar",
+ "/tmp/hoo",
+ "/tmp/too",
+ })));
+ ON_CALL(mockPrecompiledHeaderStorage, fetchAllPchPaths())
+ .WillByDefault(Return(ClangBackEnd::FilePaths{
+ "/tmp/foo",
+ "/tmp/poo",
+ "/tmp/too",
+ }));
+
+ EXPECT_CALL(mockFileSystem,
+ remove(UnorderedElementsAre(filePathId("/tmp/bar"), filePathId("/tmp/hoo"))));
+
+ queue.processEntries();
+}
+
} // namespace