aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2018-02-20 12:43:05 +0100
committerMarco Bubke <marco.bubke@qt.io>2018-03-22 13:26:24 +0000
commit53454b0f79fcfebab909d071e931557114ace558 (patch)
tree29294d846f6d93130324cb36d0f365b67d69bf21 /tests/unit
parent70f5e0e2643a7678e9d2b0aa57063b986acdfcaf (diff)
Clang: Use PCHs for indexing
As generating the AST is quite expensive it would be very useful to cache the not changed include. So we generate PCHs for include outside of a project part. With this change this PCHs are used by the indexer. For that they are save to the symbol database by the PCH manager and when fetched by the symbol indexer. Change-Id: I7a5b07cfb32d72d50dc52d2b108cd41727a7bfc7 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/unittest/filepathstorage-test.cpp4
-rw-r--r--tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp4
-rw-r--r--tests/unit/unittest/gtest-creator-printing.cpp7
-rw-r--r--tests/unit/unittest/gtest-creator-printing.h8
-rw-r--r--tests/unit/unittest/mockpchmanagernotifier.h4
-rw-r--r--tests/unit/unittest/mockpchmanagerserver.h16
-rw-r--r--tests/unit/unittest/mockprecompiledheaderstorage.h41
-rw-r--r--tests/unit/unittest/mockprojectpartprovider.h39
-rw-r--r--tests/unit/unittest/mockrefactoringserver.h16
-rw-r--r--tests/unit/unittest/mocksqlitedatabase.h5
-rw-r--r--tests/unit/unittest/mocksqlitereadstatement.cpp7
-rw-r--r--tests/unit/unittest/mocksqlitereadstatement.h12
-rw-r--r--tests/unit/unittest/mocksqlitewritestatement.h7
-rw-r--r--tests/unit/unittest/mocksymbolstorage.h2
-rw-r--r--tests/unit/unittest/pchmanagerclient-test.cpp86
-rw-r--r--tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp24
-rw-r--r--tests/unit/unittest/pchmanagerserver-test.cpp32
-rw-r--r--tests/unit/unittest/precompiledheaderstorage-test.cpp106
-rw-r--r--tests/unit/unittest/projectupdater-test.cpp26
-rw-r--r--tests/unit/unittest/refactoringclientserverinprocess-test.cpp20
-rw-r--r--tests/unit/unittest/refactoringdatabaseinitializer-test.cpp10
-rw-r--r--tests/unit/unittest/refactoringserver-test.cpp4
-rw-r--r--tests/unit/unittest/storagesqlitestatementfactory-test.cpp11
-rw-r--r--tests/unit/unittest/symbolindexer-test.cpp86
-rw-r--r--tests/unit/unittest/symbolindexing-test.cpp2
-rw-r--r--tests/unit/unittest/symbolstorage-test.cpp31
-rw-r--r--tests/unit/unittest/unittest.pro7
27 files changed, 502 insertions, 115 deletions
diff --git a/tests/unit/unittest/filepathstorage-test.cpp b/tests/unit/unittest/filepathstorage-test.cpp
index c9249a89b7..0e1cf6caf1 100644
--- a/tests/unit/unittest/filepathstorage-test.cpp
+++ b/tests/unit/unittest/filepathstorage-test.cpp
@@ -35,9 +35,7 @@
namespace {
-using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory<NiceMock<MockSqliteDatabase>,
- MockSqliteReadStatement,
- MockSqliteWriteStatement>;
+using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory<NiceMock<MockSqliteDatabase>>;
using Storage = ClangBackEnd::FilePathStorage<StatementFactory>;
using ClangBackEnd::Sources::Directory;
using ClangBackEnd::Sources::Source;
diff --git a/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp b/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp
index 51e3ae6719..92ddc10a4a 100644
--- a/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp
+++ b/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp
@@ -34,9 +34,7 @@
namespace {
-using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory<NiceMock<MockSqliteDatabase>,
- MockSqliteReadStatement,
- MockSqliteWriteStatement>;
+using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory<NiceMock<MockSqliteDatabase>>;
class FilePathStorageSqliteStatementFactory : public testing::Test
{
diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp
index 3f8b059e26..a2cd4c3d41 100644
--- a/tests/unit/unittest/gtest-creator-printing.cpp
+++ b/tests/unit/unittest/gtest-creator-printing.cpp
@@ -617,7 +617,7 @@ std::ostream &operator<<(std::ostream &os, const RequestDocumentAnnotationsMessa
return os;
}
-std::ostream &operator<<(std::ostream &out, const RemovePchProjectPartsMessage &message)
+std::ostream &operator<<(std::ostream &out, const RemoveProjectPartsMessage &message)
{
return out << "(" << message.projectsPartIds() << ")";
}
@@ -792,7 +792,7 @@ std::ostream &operator<<(std::ostream &os, const UnregisterUnsavedFilesForEditor
return os;
}
-std::ostream &operator<<(std::ostream &out, const UpdatePchProjectPartsMessage &message)
+std::ostream &operator<<(std::ostream &out, const UpdateProjectPartsMessage &message)
{
return out << "("
<< message.projectsParts()
@@ -945,7 +945,8 @@ std::ostream &operator<<(std::ostream &out, const ProjectPartContainer &containe
<< container.projectPartId() << ", "
<< container.arguments() << ", "
<< container.headerPathIds() << ", "
- << container.sourcePathIds()<< ")";
+ << container.compilerMacros() << ", "
+ << container.includeSearchPaths() << ")";
return out;
}
diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h
index 52681807c6..4f03d76d07 100644
--- a/tests/unit/unittest/gtest-creator-printing.h
+++ b/tests/unit/unittest/gtest-creator-printing.h
@@ -122,7 +122,7 @@ class PrecompiledHeadersUpdatedMessage;
class ProjectPartContainer;
class ProjectPartPch;
class RegisterUnsavedFilesForEditorMessage;
-class RemovePchProjectPartsMessage;
+class RemoveProjectPartsMessage;
class RequestDocumentAnnotationsMessage;
class RequestFollowSymbolMessage;
class RequestReferencesMessage;
@@ -141,7 +141,7 @@ class TokenInfo;
template<class T>
class TokenProcessor;
class UnregisterUnsavedFilesForEditorMessage;
-class UpdatePchProjectPartsMessage;
+class UpdateProjectPartsMessage;
class UpdateTranslationUnitsForEditorMessage;
class UpdateVisibleTranslationUnitsMessage;
class FilePath;
@@ -191,7 +191,7 @@ std::ostream &operator<<(std::ostream &out, const PrecompiledHeadersUpdatedMessa
std::ostream &operator<<(std::ostream &out, const ProjectPartContainer &container);
std::ostream &operator<<(std::ostream &out, const ProjectPartPch &projectPartPch);
std::ostream &operator<<(std::ostream &out, const RegisterUnsavedFilesForEditorMessage &message);
-std::ostream &operator<<(std::ostream &out, const RemovePchProjectPartsMessage &message);
+std::ostream &operator<<(std::ostream &out, const RemoveProjectPartsMessage &message);
std::ostream &operator<<(std::ostream &out, const RequestDocumentAnnotationsMessage &message);
std::ostream &operator<<(std::ostream &out, const RequestFollowSymbolMessage &message);
std::ostream &operator<<(std::ostream &out, const RequestReferencesMessage &message);
@@ -208,7 +208,7 @@ std::ostream &operator<<(std::ostream &out, const SourceRangesContainer &contain
std::ostream &operator<<(std::ostream &out, const SourceRangesForQueryMessage &message);
std::ostream &operator<<(std::ostream &out, const SourceRangeWithTextContainer &container);
std::ostream &operator<<(std::ostream &out, const UnregisterUnsavedFilesForEditorMessage &message);
-std::ostream &operator<<(std::ostream &out, const UpdatePchProjectPartsMessage &message);
+std::ostream &operator<<(std::ostream &out, const UpdateProjectPartsMessage &message);
std::ostream &operator<<(std::ostream &out, const UpdateTranslationUnitsForEditorMessage &message);
std::ostream &operator<<(std::ostream &out, const UpdateVisibleTranslationUnitsMessage &message);
std::ostream &operator<<(std::ostream &out, const FilePath &filePath);
diff --git a/tests/unit/unittest/mockpchmanagernotifier.h b/tests/unit/unittest/mockpchmanagernotifier.h
index 64f446e394..985dc3c144 100644
--- a/tests/unit/unittest/mockpchmanagernotifier.h
+++ b/tests/unit/unittest/mockpchmanagernotifier.h
@@ -32,8 +32,8 @@
class MockPchManagerNotifier : public ClangPchManager::PchManagerNotifierInterface
{
public:
- MockPchManagerNotifier(ClangPchManager::PchManagerClient &pchManagerClient)
- : ClangPchManager::PchManagerNotifierInterface(pchManagerClient)
+ MockPchManagerNotifier(const ClangPchManager::PchManagerClient &pchManagerClient)
+ : ClangPchManager::PchManagerNotifierInterface(const_cast<ClangPchManager::PchManagerClient&>(pchManagerClient))
{}
MOCK_METHOD3(precompiledHeaderUpdated,
diff --git a/tests/unit/unittest/mockpchmanagerserver.h b/tests/unit/unittest/mockpchmanagerserver.h
index f5c703afd1..766abd95ab 100644
--- a/tests/unit/unittest/mockpchmanagerserver.h
+++ b/tests/unit/unittest/mockpchmanagerserver.h
@@ -34,18 +34,18 @@ class MockPchManagerServer : public ClangBackEnd::PchManagerServerInterface
public:
MOCK_METHOD0(end,
void());
- MOCK_METHOD1(updatePchProjectParts,
- void (const ClangBackEnd::UpdatePchProjectPartsMessage&));
- MOCK_METHOD1(removePchProjectParts,
- void (const ClangBackEnd::RemovePchProjectPartsMessage&));
+ MOCK_METHOD1(updateProjectParts,
+ void (const ClangBackEnd::UpdateProjectPartsMessage&));
+ MOCK_METHOD1(removeProjectParts,
+ void (const ClangBackEnd::RemoveProjectPartsMessage&));
- void updatePchProjectParts(ClangBackEnd::UpdatePchProjectPartsMessage &&message) override
+ void updateProjectParts(ClangBackEnd::UpdateProjectPartsMessage &&message) override
{
- updatePchProjectParts(message);
+ updateProjectParts(message);
}
- void removePchProjectParts(ClangBackEnd::RemovePchProjectPartsMessage &&message) override
+ void removeProjectParts(ClangBackEnd::RemoveProjectPartsMessage &&message) override
{
- removePchProjectParts(message);
+ removeProjectParts(message);
}
};
diff --git a/tests/unit/unittest/mockprecompiledheaderstorage.h b/tests/unit/unittest/mockprecompiledheaderstorage.h
new file mode 100644
index 0000000000..60ba352584
--- /dev/null
+++ b/tests/unit/unittest/mockprecompiledheaderstorage.h
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "googletest.h"
+
+#include <precompiledheaderstorageinterface.h>
+
+class MockPrecompiledHeaderStorage : public ClangPchManager::PrecompiledHeaderStorageInterface
+{
+public:
+ MOCK_METHOD3(insertPrecompiledHeader,
+ void (Utils::SmallStringView projectPartName,
+ Utils::SmallStringView pchPath,
+ long long pchBuildTime));
+
+ MOCK_METHOD1(deletePrecompiledHeader, void (Utils::SmallStringView projectPartName));
+};
diff --git a/tests/unit/unittest/mockprojectpartprovider.h b/tests/unit/unittest/mockprojectpartprovider.h
new file mode 100644
index 0000000000..1bde9e082f
--- /dev/null
+++ b/tests/unit/unittest/mockprojectpartprovider.h
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "googletest.h"
+
+#include <projectpartproviderinterface.h>
+
+class MockProjectPartProvider : public ClangRefactoring::ProjectPartProviderInterface
+{
+public:
+ MOCK_CONST_METHOD0(generatedFiles,
+ ClangBackEnd::V2::FileContainers());
+ MOCK_CONST_METHOD1(projectPart,
+ CppTools::ProjectPart*(const QString &projectPartId));
+};
diff --git a/tests/unit/unittest/mockrefactoringserver.h b/tests/unit/unittest/mockrefactoringserver.h
index c265f88cbc..091807e203 100644
--- a/tests/unit/unittest/mockrefactoringserver.h
+++ b/tests/unit/unittest/mockrefactoringserver.h
@@ -44,11 +44,11 @@ public:
MOCK_METHOD1(requestSourceRangesForQueryMessage,
void (const ClangBackEnd::RequestSourceRangesForQueryMessage&));
- MOCK_METHOD1(updatePchProjectParts,
- void (const ClangBackEnd::UpdatePchProjectPartsMessage&));
+ MOCK_METHOD1(updateProjectParts,
+ void (const ClangBackEnd::UpdateProjectPartsMessage&));
- MOCK_METHOD1(removePchProjectParts,
- void (const ClangBackEnd::RemovePchProjectPartsMessage&));
+ MOCK_METHOD1(removeProjectParts,
+ void (const ClangBackEnd::RemoveProjectPartsMessage&));
MOCK_METHOD0(cancel,
void());
@@ -68,13 +68,13 @@ public:
requestSourceRangesForQueryMessage(message);
}
- void updatePchProjectParts(ClangBackEnd::UpdatePchProjectPartsMessage &&message) override
+ void updateProjectParts(ClangBackEnd::UpdateProjectPartsMessage &&message) override
{
- updatePchProjectParts(message);
+ updateProjectParts(message);
}
- void removePchProjectParts(ClangBackEnd::RemovePchProjectPartsMessage &&message) override
+ void removeProjectParts(ClangBackEnd::RemoveProjectPartsMessage &&message) override
{
- removePchProjectParts(message);
+ removeProjectParts(message);
}
};
diff --git a/tests/unit/unittest/mocksqlitedatabase.h b/tests/unit/unittest/mocksqlitedatabase.h
index 271fd77ae0..36fb370e70 100644
--- a/tests/unit/unittest/mocksqlitedatabase.h
+++ b/tests/unit/unittest/mocksqlitedatabase.h
@@ -27,7 +27,9 @@
#include "googletest.h"
+#include "mocksqlitereadstatement.h"
#include "mocksqlitetransactionbackend.h"
+#include "mocksqlitewritestatement.h"
#include <sqlitetable.h>
#include <sqlitetransaction.h>
@@ -37,6 +39,9 @@
class MockSqliteDatabase : public MockSqliteTransactionBackend
{
public:
+ using ReadStatement = MockSqliteReadStatement;
+ using WriteStatement = MockSqliteWriteStatement;
+
MOCK_METHOD1(execute,
void (Utils::SmallStringView sqlStatement));
diff --git a/tests/unit/unittest/mocksqlitereadstatement.cpp b/tests/unit/unittest/mocksqlitereadstatement.cpp
index d415e785a7..bb604b34e1 100644
--- a/tests/unit/unittest/mocksqlitereadstatement.cpp
+++ b/tests/unit/unittest/mocksqlitereadstatement.cpp
@@ -108,6 +108,13 @@ MockSqliteReadStatement::value<ClangBackEnd::ProjectPartArtefact, 4>(const Utils
}
template <>
+Utils::optional<ClangBackEnd::ProjectPartPch>
+MockSqliteReadStatement::value<ClangBackEnd::ProjectPartPch, 2>(const int &projectPartId)
+{
+ return valueReturnProjectPartPch(projectPartId);
+}
+
+template <>
Utils::optional<Utils::SmallString>
MockSqliteReadStatement::value<Utils::SmallString>(const int &sourceId)
{
diff --git a/tests/unit/unittest/mocksqlitereadstatement.h b/tests/unit/unittest/mocksqlitereadstatement.h
index 9e1f4cb25c..5ab53705cf 100644
--- a/tests/unit/unittest/mocksqlitereadstatement.h
+++ b/tests/unit/unittest/mocksqlitereadstatement.h
@@ -25,13 +25,14 @@
#pragma once
-#include "mocksqlitedatabase.h"
+#include "googletest.h"
#include <sourcelocations.h>
#include <filepathstoragesources.h>
#include <stringcachefwd.h>
#include <projectpartartefact.h>
+#include <projectpartpch.h>
#include <cpptools/usages.h>
@@ -47,6 +48,8 @@ using ClangRefactoring::SourceLocation;
using ClangRefactoring::SourceLocations;
namespace Sources = ClangBackEnd::Sources;
+class MockSqliteDatabase;
+
class MockSqliteReadStatement
{
public:
@@ -88,6 +91,9 @@ public:
MOCK_METHOD1(valueReturnProjectPartArtefact,
Utils::optional<ClangBackEnd::ProjectPartArtefact>(Utils::SmallStringView));
+ MOCK_METHOD1(valueReturnProjectPartPch,
+ Utils::optional<ClangBackEnd::ProjectPartPch>(int));
+
template <typename ResultType,
int ResultTypeCount = 1,
typename... QueryType>
@@ -165,5 +171,9 @@ Utils::optional<ClangBackEnd::ProjectPartArtefact>
MockSqliteReadStatement::value<ClangBackEnd::ProjectPartArtefact, 4>(const int&);
template <>
+Utils::optional<ClangBackEnd::ProjectPartPch>
+MockSqliteReadStatement::value<ClangBackEnd::ProjectPartPch, 2>(const int&);
+
+template <>
Utils::optional<Utils::SmallString>
MockSqliteReadStatement::value<Utils::SmallString>(const int&);
diff --git a/tests/unit/unittest/mocksqlitewritestatement.h b/tests/unit/unittest/mocksqlitewritestatement.h
index 3a823e8967..132fd9728e 100644
--- a/tests/unit/unittest/mocksqlitewritestatement.h
+++ b/tests/unit/unittest/mocksqlitewritestatement.h
@@ -25,10 +25,12 @@
#pragma once
-#include "mocksqlitedatabase.h"
+#include "googletest.h"
#include <utils/smallstring.h>
+class MockSqliteDatabase;
+
class MockSqliteWriteStatement
{
public:
@@ -62,6 +64,9 @@ public:
void (Utils::SmallStringView, Utils::SmallStringView));
MOCK_METHOD3(write,
+ void (Utils::SmallStringView, Utils::SmallStringView, long long));
+
+ MOCK_METHOD3(write,
void (Utils::SmallStringView, Utils::SmallStringView, Utils::SmallStringView));
MOCK_METHOD4(write,
diff --git a/tests/unit/unittest/mocksymbolstorage.h b/tests/unit/unittest/mocksymbolstorage.h
index b12f62989d..90142fe9ee 100644
--- a/tests/unit/unittest/mocksymbolstorage.h
+++ b/tests/unit/unittest/mocksymbolstorage.h
@@ -60,4 +60,6 @@ public:
Utils::optional<ClangBackEnd::ProjectPartArtefact> (Utils::SmallStringView projectPartName));
MOCK_CONST_METHOD1(fetchLowestLastModifiedTime,
long long (ClangBackEnd::FilePathId sourceId));
+ MOCK_CONST_METHOD1(fetchPrecompiledHeader,
+ Utils::optional<ClangBackEnd::ProjectPartPch> (int projectPartId));
};
diff --git a/tests/unit/unittest/pchmanagerclient-test.cpp b/tests/unit/unittest/pchmanagerclient-test.cpp
index 60bdb39fdb..9e40a21249 100644
--- a/tests/unit/unittest/pchmanagerclient-test.cpp
+++ b/tests/unit/unittest/pchmanagerclient-test.cpp
@@ -27,6 +27,7 @@
#include "mockpchmanagernotifier.h"
#include "mockpchmanagerserver.h"
+#include "mockprecompiledheaderstorage.h"
#include <pchmanagerclient.h>
#include <pchmanagerprojectupdater.h>
@@ -34,8 +35,8 @@
#include <filepathcaching.h>
#include <refactoringdatabaseinitializer.h>
#include <precompiledheadersupdatedmessage.h>
-#include <removepchprojectpartsmessage.h>
-#include <updatepchprojectpartsmessage.h>
+#include <removeprojectpartsmessage.h>
+#include <updateprojectpartsmessage.h>
namespace {
@@ -48,9 +49,10 @@ using testing::Not;
class PchManagerClient : public ::testing::Test
{
protected:
- MockPchManagerServer mockPchManagerServer;
- ClangPchManager::PchManagerClient client;
- MockPchManagerNotifier mockPchManagerNotifier{client};
+ NiceMock<MockPchManagerServer> mockPchManagerServer;
+ NiceMock<MockPrecompiledHeaderStorage> mockPrecompiledHeaderStorage;
+ ClangPchManager::PchManagerClient client{mockPrecompiledHeaderStorage};
+ NiceMock<MockPchManagerNotifier> mockPchManagerNotifier{client};
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
ClangBackEnd::FilePathCaching filePathCache{database};
@@ -58,6 +60,9 @@ protected:
Utils::SmallString projectPartId{"projectPartId"};
Utils::SmallString pchFilePath{"/path/to/pch"};
PrecompiledHeadersUpdatedMessage message{{{projectPartId.clone(), pchFilePath.clone(), 1}}};
+ Utils::SmallString projectPartId2{"projectPartId2"};
+ Utils::SmallString pchFilePath2{"/path/to/pch2"};
+ PrecompiledHeadersUpdatedMessage message2{{{projectPartId2.clone(), pchFilePath2.clone(), 1}}};
};
TEST_F(PchManagerClient, NotifierAttached)
@@ -95,4 +100,75 @@ TEST_F(PchManagerClient, Remove)
QString(projectPartId.clone())});
}
+TEST_F(PchManagerClient, GetNoProjectPartPchForWrongProjectPartId)
+{
+ auto optional = client.projectPartPch("foo");
+
+ ASSERT_FALSE(optional);
+}
+
+TEST_F(PchManagerClient, GetProjectPartPchForProjectPartId)
+{
+ client.precompiledHeadersUpdated(std::move(message));
+
+ auto optional = client.projectPartPch(projectPartId);
+
+ ASSERT_TRUE(optional);
+}
+
+TEST_F(PchManagerClient, ProjectPartPchRemoved)
+{
+ client.precompiledHeadersUpdated(std::move(message));
+
+ client.precompiledHeaderRemoved(QString(projectPartId));
+
+ ASSERT_FALSE(client.projectPartPch(projectPartId));
+}
+
+TEST_F(PchManagerClient, ProjectPartPchHasNoDublicateEntries)
+{
+ client.precompiledHeadersUpdated(message.clone());
+ client.precompiledHeadersUpdated(message2.clone());
+
+ client.precompiledHeadersUpdated(message.clone());
+
+ ASSERT_THAT(client.projectPartPchs(), SizeIs(2));
+}
+
+TEST_F(PchManagerClient, ProjectPartPchForProjectPartIdLastModified)
+{
+ client.precompiledHeadersUpdated(std::move(message));
+
+ ASSERT_THAT(client.projectPartPch(projectPartId).value().lastModified,
+ 1);
+}
+
+TEST_F(PchManagerClient, ProjectPartPchForProjectPartIdIsUpdated)
+{
+ client.precompiledHeadersUpdated(message.clone());
+ PrecompiledHeadersUpdatedMessage updateMessage{{{projectPartId.clone(), pchFilePath.clone(), 42}}};
+
+ client.precompiledHeadersUpdated(updateMessage.clone());
+
+ ASSERT_THAT(client.projectPartPch(projectPartId).value().lastModified,
+ 42);
+}
+
+TEST_F(PchManagerClient, ProjectPartPchAddedToDatabase)
+{
+ EXPECT_CALL(mockPrecompiledHeaderStorage, insertPrecompiledHeader(TypedEq<Utils::SmallStringView>(projectPartId),
+ TypedEq<Utils::SmallStringView>(pchFilePath),
+ TypedEq<long long>(1)));
+
+ client.precompiledHeadersUpdated(message.clone());
+}
+
+TEST_F(PchManagerClient, ProjectPartPchRemovedFromDatabase)
+{
+ EXPECT_CALL(mockPrecompiledHeaderStorage, deletePrecompiledHeader(TypedEq<Utils::SmallStringView>(projectPartId)));
+
+
+ projectUpdater.removeProjectParts({QString(projectPartId)});
+}
+
}
diff --git a/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp b/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp
index c5469ee8e2..f37fe2ae5e 100644
--- a/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp
+++ b/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp
@@ -32,8 +32,8 @@
#include <pchmanagerclientproxy.h>
#include <pchmanagerserverproxy.h>
#include <precompiledheadersupdatedmessage.h>
-#include <removepchprojectpartsmessage.h>
-#include <updatepchprojectpartsmessage.h>
+#include <removeprojectpartsmessage.h>
+#include <updateprojectpartsmessage.h>
#include <QBuffer>
#include <QString>
@@ -41,10 +41,10 @@
#include <vector>
-using ClangBackEnd::UpdatePchProjectPartsMessage;
+using ClangBackEnd::UpdateProjectPartsMessage;
using ClangBackEnd::V2::FileContainer;
using ClangBackEnd::V2::ProjectPartContainer;
-using ClangBackEnd::RemovePchProjectPartsMessage;
+using ClangBackEnd::RemoveProjectPartsMessage;
using ClangBackEnd::PrecompiledHeadersUpdatedMessage;
using ::testing::Args;
@@ -90,7 +90,7 @@ TEST_F(PchManagerClientServerInProcess, SendAliveMessage)
scheduleClientMessages();
}
-TEST_F(PchManagerClientServerInProcess, SendUpdatePchProjectPartsMessage)
+TEST_F(PchManagerClientServerInProcess, SendUpdateProjectPartsMessage)
{
ProjectPartContainer projectPart2{"projectPartId",
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
@@ -99,21 +99,21 @@ TEST_F(PchManagerClientServerInProcess, SendUpdatePchProjectPartsMessage)
{{1, 1}},
{{1, 2}}};
FileContainer fileContainer{{"/path/to/", "file"}, "content", {}};
- UpdatePchProjectPartsMessage message{{projectPart2}, {fileContainer}};
+ UpdateProjectPartsMessage message{{projectPart2}, {fileContainer}};
- EXPECT_CALL(mockPchManagerServer, updatePchProjectParts(message));
+ EXPECT_CALL(mockPchManagerServer, updateProjectParts(message));
- serverProxy.updatePchProjectParts(message.clone());
+ serverProxy.updateProjectParts(message.clone());
scheduleServerMessages();
}
-TEST_F(PchManagerClientServerInProcess, SendRemovePchProjectPartsMessage)
+TEST_F(PchManagerClientServerInProcess, SendRemoveProjectPartsMessage)
{
- RemovePchProjectPartsMessage message{{"projectPartId1", "projectPartId2"}};
+ RemoveProjectPartsMessage message{{"projectPartId1", "projectPartId2"}};
- EXPECT_CALL(mockPchManagerServer, removePchProjectParts(message));
+ EXPECT_CALL(mockPchManagerServer, removeProjectParts(message));
- serverProxy.removePchProjectParts(message.clone());
+ serverProxy.removeProjectParts(message.clone());
scheduleServerMessages();
}
diff --git a/tests/unit/unittest/pchmanagerserver-test.cpp b/tests/unit/unittest/pchmanagerserver-test.cpp
index 793e10345d..0950a656ac 100644
--- a/tests/unit/unittest/pchmanagerserver-test.cpp
+++ b/tests/unit/unittest/pchmanagerserver-test.cpp
@@ -34,8 +34,8 @@
#include <pchmanagerserver.h>
#include <precompiledheadersupdatedmessage.h>
#include <refactoringdatabaseinitializer.h>
-#include <removepchprojectpartsmessage.h>
-#include <updatepchprojectpartsmessage.h>
+#include <removeprojectpartsmessage.h>
+#include <updateprojectpartsmessage.h>
namespace {
using Utils::PathString;
@@ -82,14 +82,14 @@ protected:
{id(main2Path)}};
std::vector<ProjectPartContainer> projectParts{projectPart1, projectPart2};
FileContainer generatedFile{{"/path/to/", "file"}, "content", {}};
- ClangBackEnd::UpdatePchProjectPartsMessage updatePchProjectPartsMessage{Utils::clone(projectParts),
+ ClangBackEnd::UpdateProjectPartsMessage UpdateProjectPartsMessage{Utils::clone(projectParts),
{generatedFile}};
ClangBackEnd::ProjectPartPch projectPartPch1{projectPart1.projectPartId().clone(), "/path1/to/pch", 1};
ClangBackEnd::ProjectPartPch projectPartPch2{projectPart2.projectPartId().clone(), "/path2/to/pch", 1};
std::vector<ClangBackEnd::ProjectPartPch> projectPartPchs{projectPartPch1, projectPartPch2};
ClangBackEnd::PrecompiledHeadersUpdatedMessage precompiledHeaderUpdatedMessage1{{projectPartPch1}};
ClangBackEnd::PrecompiledHeadersUpdatedMessage precompiledHeaderUpdatedMessage2{{projectPartPch2}};
- ClangBackEnd::RemovePchProjectPartsMessage removePchProjectPartsMessage{{projectPart1.projectPartId().clone(),
+ ClangBackEnd::RemoveProjectPartsMessage RemoveProjectPartsMessage{{projectPart1.projectPartId().clone(),
projectPart2.projectPartId().clone()}};
};
@@ -111,39 +111,39 @@ TEST_F(PchManagerServer, DoNotCallPrecompiledHeadersForUnsuccessfullyFinishedTas
TEST_F(PchManagerServer, CallBuildInPchCreator)
{
auto &&callSetGeneratedFiles = EXPECT_CALL(mockPchCreator,
- setGeneratedFiles(updatePchProjectPartsMessage.generatedFiles()));
- EXPECT_CALL(mockPchCreator, generatePchs(updatePchProjectPartsMessage.projectsParts()))
+ setGeneratedFiles(UpdateProjectPartsMessage.generatedFiles()));
+ EXPECT_CALL(mockPchCreator, generatePchs(UpdateProjectPartsMessage.projectsParts()))
.After(callSetGeneratedFiles);
- server.updatePchProjectParts(updatePchProjectPartsMessage.clone());
+ server.updateProjectParts(UpdateProjectPartsMessage.clone());
}
TEST_F(PchManagerServer, UpdateIncludesOfFileWatcher)
{
EXPECT_CALL(mockClangPathWatcher, updateIdPaths(idPaths));
- server.updatePchProjectParts(updatePchProjectPartsMessage.clone());
+ server.updateProjectParts(UpdateProjectPartsMessage.clone());
}
TEST_F(PchManagerServer, GetChangedProjectPartsFromProjectParts)
{
EXPECT_CALL(mockProjectParts, update(_));
- server.updatePchProjectParts(updatePchProjectPartsMessage.clone());
+ server.updateProjectParts(UpdateProjectPartsMessage.clone());
}
TEST_F(PchManagerServer, RemoveIncludesFromFileWatcher)
{
- EXPECT_CALL(mockClangPathWatcher, removeIds(removePchProjectPartsMessage.projectsPartIds()));
+ EXPECT_CALL(mockClangPathWatcher, removeIds(RemoveProjectPartsMessage.projectsPartIds()));
- server.removePchProjectParts(removePchProjectPartsMessage.clone());
+ server.removeProjectParts(RemoveProjectPartsMessage.clone());
}
TEST_F(PchManagerServer, RemoveProjectPartsFromProjectParts)
{
- EXPECT_CALL(mockProjectParts, remove(removePchProjectPartsMessage.projectsPartIds()));
+ EXPECT_CALL(mockProjectParts, remove(RemoveProjectPartsMessage.projectsPartIds()));
- server.removePchProjectParts(removePchProjectPartsMessage.clone());
+ server.removeProjectParts(RemoveProjectPartsMessage.clone());
}
TEST_F(PchManagerServer, SetPathWatcherNotifier)
@@ -155,7 +155,7 @@ TEST_F(PchManagerServer, SetPathWatcherNotifier)
TEST_F(PchManagerServer, CallProjectsInProjectPartsForIncludeChange)
{
- server.updatePchProjectParts(updatePchProjectPartsMessage.clone());
+ server.updateProjectParts(UpdateProjectPartsMessage.clone());
EXPECT_CALL(mockProjectParts, projects(ElementsAre(projectPart1.projectPartId())));
@@ -164,7 +164,7 @@ TEST_F(PchManagerServer, CallProjectsInProjectPartsForIncludeChange)
TEST_F(PchManagerServer, CallGeneratePchsInPchCreatorForIncludeChange)
{
- server.updatePchProjectParts(updatePchProjectPartsMessage.clone());
+ server.updateProjectParts(UpdateProjectPartsMessage.clone());
EXPECT_CALL(mockPchCreator, generatePchs(ElementsAre(projectPart1)));
@@ -173,7 +173,7 @@ TEST_F(PchManagerServer, CallGeneratePchsInPchCreatorForIncludeChange)
TEST_F(PchManagerServer, CallUpdateIdPathsInFileSystemWatcherForIncludeChange)
{
- server.updatePchProjectParts(updatePchProjectPartsMessage.clone());
+ server.updateProjectParts(UpdateProjectPartsMessage.clone());
EXPECT_CALL(mockClangPathWatcher, updateIdPaths(idPaths));
diff --git a/tests/unit/unittest/precompiledheaderstorage-test.cpp b/tests/unit/unittest/precompiledheaderstorage-test.cpp
new file mode 100644
index 0000000000..2871e3fd11
--- /dev/null
+++ b/tests/unit/unittest/precompiledheaderstorage-test.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "googletest.h"
+#include "mocksqlitedatabase.h"
+
+#include <precompiledheaderstorage.h>
+#include <refactoringdatabaseinitializer.h>
+#include <sqlitedatabase.h>
+#include <sqlitewritestatement.h>
+
+namespace {
+
+using Storage = ClangPchManager::PrecompiledHeaderStorage<NiceMock<MockSqliteDatabase>>;
+
+class PrecompiledHeaderStorage : public testing::Test
+{
+protected:
+ NiceMock<MockSqliteDatabase> database;
+ Storage storage{database};
+ MockSqliteWriteStatement &insertPrecompiledHeaderStatement = storage.m_insertPrecompiledHeaderStatement;
+ MockSqliteWriteStatement &insertProjectPartStatement = storage.m_insertProjectPartStatement;
+ MockSqliteWriteStatement &deletePrecompiledHeaderStatement = storage.m_deletePrecompiledHeaderStatement;
+};
+
+TEST_F(PrecompiledHeaderStorage, UseTransaction)
+{
+ InSequence s;
+
+ EXPECT_CALL(database, immediateBegin());
+ EXPECT_CALL(database, commit());
+
+ Storage storage{database};
+}
+
+TEST_F(PrecompiledHeaderStorage, InsertPrecompiledHeader)
+{
+ InSequence s;
+
+ EXPECT_CALL(insertProjectPartStatement, write(TypedEq<Utils::SmallStringView>("project1")));
+ EXPECT_CALL(insertPrecompiledHeaderStatement,
+ write(TypedEq<Utils::SmallStringView>("project1"),
+ TypedEq<Utils::SmallStringView>("/path/to/pch"),
+ TypedEq<long long>(22)));
+
+ storage.insertPrecompiledHeader("project1", "/path/to/pch", 22);
+}
+
+TEST_F(PrecompiledHeaderStorage, DeletePrecompiledHeader)
+{
+ InSequence s;
+
+ EXPECT_CALL(deletePrecompiledHeaderStatement, write(TypedEq<Utils::SmallStringView>("project1")));
+
+ storage.deletePrecompiledHeader("project1");
+}
+
+TEST_F(PrecompiledHeaderStorage, InsertPrecompiledHeaderStatement)
+{
+ ASSERT_THAT(insertPrecompiledHeaderStatement.sqlStatement,
+ Eq("INSERT OR REPLACE INTO precompiledHeaders(projectPartId, pchPath, pchBuildTime) VALUES((SELECT projectPartId FROM projectParts WHERE projectPartName = ?),?,?)"));
+}
+
+TEST_F(PrecompiledHeaderStorage, InsertProjectPartStatement)
+{
+ ASSERT_THAT(insertProjectPartStatement.sqlStatement,
+ Eq("INSERT OR IGNORE INTO projectParts(projectPartName) VALUES (?)"));
+}
+
+TEST_F(PrecompiledHeaderStorage, DeletePrecompiledHeaderStatement)
+{
+ ASSERT_THAT(deletePrecompiledHeaderStatement.sqlStatement,
+ Eq("DELETE FROM precompiledHeaders WHERE projectPartId = (SELECT projectPartId FROM projectParts WHERE projectPartName = ?)"));
+}
+
+TEST_F(PrecompiledHeaderStorage, CompilePrecompiledHeaderStatements)
+{
+ Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
+ ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
+
+ ASSERT_NO_THROW(ClangPchManager::PrecompiledHeaderStorage<>{database});
+}
+
+}
diff --git a/tests/unit/unittest/projectupdater-test.cpp b/tests/unit/unittest/projectupdater-test.cpp
index 49a69aee30..a77dfc0b5b 100644
--- a/tests/unit/unittest/projectupdater-test.cpp
+++ b/tests/unit/unittest/projectupdater-test.cpp
@@ -28,15 +28,17 @@
#include "mockpchmanagerclient.h"
#include "mockpchmanagernotifier.h"
#include "mockpchmanagerserver.h"
+#include "mockprecompiledheaderstorage.h"
#include <pchmanagerprojectupdater.h>
#include <filepathcaching.h>
#include <pchmanagerclient.h>
+#include <precompiledheaderstorage.h>
#include <precompiledheadersupdatedmessage.h>
#include <refactoringdatabaseinitializer.h>
-#include <removepchprojectpartsmessage.h>
-#include <updatepchprojectpartsmessage.h>
+#include <removeprojectpartsmessage.h>
+#include <updateprojectpartsmessage.h>
#include <cpptools/compileroptionsbuilder.h>
#include <cpptools/projectpart.h>
@@ -97,7 +99,8 @@ protected:
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
ClangBackEnd::FilePathCaching filePathCache{database};
- ClangPchManager::PchManagerClient pchManagerClient;
+ MockPrecompiledHeaderStorage mockPrecompiledHeaderStorage;
+ ClangPchManager::PchManagerClient pchManagerClient{mockPrecompiledHeaderStorage};
MockPchManagerNotifier mockPchManagerNotifier{pchManagerClient};
NiceMock<MockPchManagerServer> mockPchManagerServer;
ClangPchManager::ProjectUpdater updater{mockPchManagerServer, filePathCache};
@@ -115,23 +118,22 @@ protected:
FileContainer generatedFile{{"/path/to", "header1.h"}, "content", {}};
};
-TEST_F(ProjectUpdater, CallUpdatePchProjectParts)
+TEST_F(ProjectUpdater, CallUpdateProjectParts)
{
std::vector<CppTools::ProjectPart*> projectParts = {&projectPart, &projectPart};
- ClangBackEnd::UpdatePchProjectPartsMessage message{{expectedContainer.clone(), expectedContainer.clone()},
- {generatedFile}};
+ ClangBackEnd::UpdateProjectPartsMessage message{{expectedContainer.clone(), expectedContainer.clone()},
+ {generatedFile}};
- EXPECT_CALL(mockPchManagerServer, updatePchProjectParts(message));
+ EXPECT_CALL(mockPchManagerServer, updateProjectParts(message));
updater.updateProjectParts(projectParts, {generatedFile});
}
-TEST_F(ProjectUpdater, CallRemovePchProjectParts)
+TEST_F(ProjectUpdater, CallRemoveProjectParts)
{
+ ClangBackEnd::RemoveProjectPartsMessage message{{projectPartId, projectPartId2}};
- ClangBackEnd::RemovePchProjectPartsMessage message{{projectPartId, projectPartId2}};
-
- EXPECT_CALL(mockPchManagerServer, removePchProjectParts(message));
+ EXPECT_CALL(mockPchManagerServer, removeProjectParts(message));
updater.removeProjectParts({QString(projectPartId), QString(projectPartId2)});
}
@@ -139,7 +141,7 @@ TEST_F(ProjectUpdater, CallRemovePchProjectParts)
TEST_F(ProjectUpdater, CallPrecompiledHeaderRemovedInPchManagerProjectUpdater)
{
ClangPchManager::PchManagerProjectUpdater pchUpdater{mockPchManagerServer, pchManagerClient, filePathCache};
- ClangBackEnd::RemovePchProjectPartsMessage message{{projectPartId, projectPartId2}};
+ ClangBackEnd::RemoveProjectPartsMessage message{{projectPartId, projectPartId2}};
EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId.toQString()));
EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId2.toQString()));
diff --git a/tests/unit/unittest/refactoringclientserverinprocess-test.cpp b/tests/unit/unittest/refactoringclientserverinprocess-test.cpp
index ed539afc44..a5658ab178 100644
--- a/tests/unit/unittest/refactoringclientserverinprocess-test.cpp
+++ b/tests/unit/unittest/refactoringclientserverinprocess-test.cpp
@@ -47,10 +47,10 @@ using ::testing::Args;
using ::testing::Property;
using ::testing::Eq;
-using ClangBackEnd::UpdatePchProjectPartsMessage;
+using ClangBackEnd::UpdateProjectPartsMessage;
using ClangBackEnd::V2::FileContainer;
using ClangBackEnd::V2::ProjectPartContainer;
-using ClangBackEnd::RemovePchProjectPartsMessage;
+using ClangBackEnd::RemoveProjectPartsMessage;
class RefactoringClientServerInProcess : public ::testing::Test
{
@@ -174,7 +174,7 @@ TEST_F(RefactoringClientServerInProcess, RequestSourceRangesForQueryMessage)
scheduleServerMessages();
}
-TEST_F(RefactoringClientServerInProcess, SendUpdatePchProjectPartsMessage)
+TEST_F(RefactoringClientServerInProcess, SendUpdateProjectPartsMessage)
{
ProjectPartContainer projectPart2{"projectPartId",
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
@@ -183,21 +183,21 @@ TEST_F(RefactoringClientServerInProcess, SendUpdatePchProjectPartsMessage)
{{1, 1}},
{{1, 2}}};
FileContainer fileContainer{{"/path/to/", "file"}, "content", {}};
- UpdatePchProjectPartsMessage message{{projectPart2}, {fileContainer}};
+ UpdateProjectPartsMessage message{{projectPart2}, {fileContainer}};
- EXPECT_CALL(mockRefactoringServer, updatePchProjectParts(message));
+ EXPECT_CALL(mockRefactoringServer, updateProjectParts(message));
- serverProxy.updatePchProjectParts(message.clone());
+ serverProxy.updateProjectParts(message.clone());
scheduleServerMessages();
}
-TEST_F(RefactoringClientServerInProcess, SendRemovePchProjectPartsMessage)
+TEST_F(RefactoringClientServerInProcess, SendRemoveProjectPartsMessage)
{
- RemovePchProjectPartsMessage message{{"projectPartId1", "projectPartId2"}};
+ RemoveProjectPartsMessage message{{"projectPartId1", "projectPartId2"}};
- EXPECT_CALL(mockRefactoringServer, removePchProjectParts(message));
+ EXPECT_CALL(mockRefactoringServer, removeProjectParts(message));
- serverProxy.removePchProjectParts(message.clone());
+ serverProxy.removeProjectParts(message.clone());
scheduleServerMessages();
}
diff --git a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp
index adc98c37fe..aa48e79094 100644
--- a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp
+++ b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp
@@ -133,6 +133,15 @@ TEST_F(RefactoringDatabaseInitializer, AddSourceDependenciesTable)
initializer.createSourceDependenciesTable();
}
+TEST_F(RefactoringDatabaseInitializer, AddPrecompiledHeaderTable)
+{
+ InSequence s;
+
+ EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, pchPath TEXT, pchBuildTime INTEGER)")));
+
+ initializer.createPrecompiledHeadersTable();
+}
+
TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor)
{
InSequence s;
@@ -157,6 +166,7 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor)
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, dependencySourceId INTEGER)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON sourceDependencies(sourceId, dependencySourceId)")));
+ EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, pchPath TEXT, pchBuildTime INTEGER)")));
EXPECT_CALL(mockDatabase, commit());
Initializer initializer{mockDatabase};
diff --git a/tests/unit/unittest/refactoringserver-test.cpp b/tests/unit/unittest/refactoringserver-test.cpp
index 70441e1e3b..f4161c6cb8 100644
--- a/tests/unit/unittest/refactoringserver-test.cpp
+++ b/tests/unit/unittest/refactoringserver-test.cpp
@@ -297,7 +297,7 @@ TEST_F(RefactoringServerSlowTest, ForInvalidRequestSourceRangesAndDiagnosticsGet
refactoringServer.requestSourceRangesAndDiagnosticsForQueryMessage(std::move(message));
}
-TEST_F(RefactoringServer, UpdatePchProjectPartsCallsSymbolIndexingUpdateProjectParts)
+TEST_F(RefactoringServer, UpdateProjectPartsCallsSymbolIndexingUpdateProjectParts)
{
ProjectPartContainers projectParts{{{"projectPartId",
{"-I", TESTDATA_DIR},
@@ -313,7 +313,7 @@ TEST_F(RefactoringServer, UpdatePchProjectPartsCallsSymbolIndexingUpdateProjectP
EXPECT_CALL(mockSymbolIndexing,
updateProjectParts(projectParts, unsaved));
- refactoringServer.updatePchProjectParts({Utils::clone(projectParts), Utils::clone(unsaved)});
+ refactoringServer.updateProjectParts({Utils::clone(projectParts), Utils::clone(unsaved)});
}
void RefactoringServer::SetUp()
diff --git a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp
index 4f994909d1..63876bbb36 100644
--- a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp
+++ b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp
@@ -33,9 +33,7 @@
namespace {
-using StatementFactory = ClangBackEnd::StorageSqliteStatementFactory<NiceMock<MockSqliteDatabase>,
- MockSqliteReadStatement,
- MockSqliteWriteStatement>;
+using StatementFactory = ClangBackEnd::StorageSqliteStatementFactory<NiceMock<MockSqliteDatabase>>;
using Sqlite::Table;
@@ -274,4 +272,11 @@ TEST_F(StorageSqliteStatementFactory, GetLowestLastModifiedTimeOfDependencies)
ASSERT_THAT(factory.getLowestLastModifiedTimeOfDependencies.sqlStatement,
Eq("WITH RECURSIVE sourceIds(sourceId) AS (VALUES(?) UNION SELECT dependencySourceId FROM sourceDependencies, sourceIds WHERE sourceDependencies.sourceId = sourceIds.sourceId) SELECT min(lastModified) FROM fileStatuses, sourceIds WHERE fileStatuses.sourceId = sourceIds.sourceId"));
}
+
+TEST_F(StorageSqliteStatementFactory, GetPrecompiledHeaderForProjectPartName)
+{
+ ASSERT_THAT(factory.getPrecompiledHeader.sqlStatement,
+ Eq("SELECT pchPath, pchBuildTime FROM precompiledHeaders WHERE projectPartId = ?"));
+}
+
}
diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp
index b29e1ee1fa..b2a471bf10 100644
--- a/tests/unit/unittest/symbolindexer-test.cpp
+++ b/tests/unit/unittest/symbolindexer-test.cpp
@@ -35,7 +35,7 @@
#include <projectpartcontainerv2.h>
#include <refactoringdatabaseinitializer.h>
#include <symbolindexer.h>
-#include <updatepchprojectpartsmessage.h>
+#include <updateprojectpartsmessage.h>
#include <QDateTime>
@@ -59,6 +59,7 @@ using ClangBackEnd::SourceLocationEntries;
using ClangBackEnd::SourceLocationEntry;
using ClangBackEnd::SymbolType;
using ClangBackEnd::UsedMacros;
+using OptionalProjectPartArtefact = Utils::optional<ClangBackEnd::ProjectPartArtefact>;
MATCHER_P2(IsFileId, directoryId, fileNameId,
std::string(negation ? "isn't " : "is ")
@@ -148,6 +149,8 @@ protected:
FileStatuses fileStatus{{{1, 2}, 3, 4, false}};
SourceDependencies sourceDependencies{{{1, 1}, {1, 2}}, {{1, 1}, {1, 3}}};
ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFOO\"]", "{\"FOO\":\"1\",\"BAR\":\"1\"}", "[\"/includes\"]", 74};
+ ClangBackEnd::ProjectPartArtefact emptyArtefact{"", "", "", 74};
+ ClangBackEnd::ProjectPartPch projectPartPch{"/path/to/pch", 4};
NiceMock<MockSqliteTransactionBackend> mockSqliteTransactionBackend;
NiceMock<MockSymbolsCollector> mockCollector;
NiceMock<MockSymbolStorage> mockStorage;
@@ -170,6 +173,35 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector)
indexer.updateProjectParts({projectPart1}, Utils::clone(unsaved));
}
+TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInCollector)
+{
+ ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId()))).WillByDefault(Return(emptyArtefact));
+ ON_CALL(mockStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId))).WillByDefault(Return(projectPartPch));
+
+ EXPECT_CALL(mockCollector, addFiles(projectPart1.sourcePathIds(),
+ ElementsAre(Eq("-I"),
+ Eq(TESTDATA_DIR),
+ Eq("-Wno-pragma-once-outside-header"),
+ Eq("-Xclang"),
+ Eq("-include-pch"),
+ Eq("-Xclang"),
+ Eq("/path/to/pch"))));
+
+ indexer.updateProjectParts({projectPart1}, Utils::clone(unsaved));
+}
+
+TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInCollector)
+{
+ ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId()))).WillByDefault(Return(emptyArtefact));
+
+ EXPECT_CALL(mockCollector, addFiles(projectPart1.sourcePathIds(),
+ ElementsAre(Eq("-I"),
+ Eq(TESTDATA_DIR),
+ Eq("-Wno-pragma-once-outside-header"))));
+
+ indexer.updateProjectParts({projectPart1}, Utils::clone(unsaved));
+}
+
TEST_F(SymbolIndexer, UpdateProjectPartsCallsClearInCollector)
{
EXPECT_CALL(mockCollector, clear()).Times(2);
@@ -340,8 +372,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder)
TEST_F(SymbolIndexer, HandleEmptyOptionalArtifactInUpdateChangedPath)
{
- ON_CALL(mockStorage, fetchProjectPartArtefact(A<FilePathId>()))
- .WillByDefault(Return(Utils::optional<ClangBackEnd::ProjectPartArtefact>()));
+ ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0])))
+ .WillByDefault(Return(emptyArtefact));
EXPECT_CALL(mockCollector, clear());
EXPECT_CALL(mockStorage, fetchProjectPartArtefact(sourceFileIds[0]));
@@ -358,11 +390,41 @@ TEST_F(SymbolIndexer, HandleEmptyOptionalArtifactInUpdateChangedPath)
indexer.updateChangedPath(sourceFileIds[0]);
}
+TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader)
+{
+ ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0])))
+ .WillByDefault(Return(artefact));
+ ON_CALL(mockStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId)))
+ .WillByDefault(Return(projectPartPch));
+
+ EXPECT_CALL(mockCollector, addFiles(projectPart1.sourcePathIds(),
+ ElementsAre(Eq("-DFOO"),
+ Eq("-Xclang"),
+ Eq("-include-pch"),
+ Eq("-Xclang"),
+ Eq("/path/to/pch"))));
+
+ indexer.updateChangedPath(sourceFileIds[0]);
+}
+
+TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists)
+{
+ ON_CALL(mockStorage, fetchProjectPartArtefact(TypedEq<FilePathId>(sourceFileIds[0])))
+ .WillByDefault(Return(artefact));
+
+ EXPECT_CALL(mockCollector, addFiles(projectPart1.sourcePathIds(),
+ ElementsAre(Eq("-DFOO"))));
+
+ indexer.updateChangedPath(sourceFileIds[0]);
+}
+
+
TEST_F(SymbolIndexer, CompilerMacrosAndIncludeSearchPathsAreNotDifferent)
{
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
- auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart1);
+ auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart1,
+ artefact);
ASSERT_FALSE(areDifferent);
}
@@ -371,7 +433,8 @@ TEST_F(SymbolIndexer, CompilerMacrosAreDifferent)
{
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
- auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart2);
+ auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart2,
+ artefact);
ASSERT_TRUE(areDifferent);
}
@@ -386,7 +449,8 @@ TEST_F(SymbolIndexer, IncludeSearchPathsAreDifferent)
{main1PathId}};
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
- auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart3);
+ auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart3,
+ artefact);
ASSERT_TRUE(areDifferent);
}
@@ -425,7 +489,7 @@ TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfCompilerMacrosAreDifferent)
{
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
- auto filePathIds = indexer.updatableFilePathIds(projectPart2);
+ auto filePathIds = indexer.updatableFilePathIds(projectPart2, artefact);
ASSERT_THAT(filePathIds, projectPart2.sourcePathIds());
}
@@ -434,7 +498,7 @@ TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfIncludeSearchPathsAreDifferent)
{
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
- auto filePathIds = indexer.updatableFilePathIds(projectPart3);
+ auto filePathIds = indexer.updatableFilePathIds(projectPart3, artefact);
ASSERT_THAT(filePathIds, projectPart3.sourcePathIds());
}
@@ -443,7 +507,7 @@ TEST_F(SymbolIndexer, GetNoUpdatableFilePathIdsIfArtefactsAreTheSame)
{
ON_CALL(mockStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact));
- auto filePathIds = indexer.updatableFilePathIds(projectPart1);
+ auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact);
ASSERT_THAT(filePathIds, IsEmpty());
}
@@ -455,7 +519,7 @@ TEST_F(SymbolIndexer, OutdatedFilesPassUpdatableFilePathIds)
ON_CALL(mockStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
.WillByDefault(Return(0));
- auto filePathIds = indexer.updatableFilePathIds(projectPart1);
+ auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact);
ASSERT_THAT(filePathIds, ElementsAre(main1PathId));
}
@@ -467,7 +531,7 @@ TEST_F(SymbolIndexer, UpToDateFilesDontPassFilteredUpdatableFilePathIds)
ON_CALL(mockStorage, fetchLowestLastModifiedTime(A<FilePathId>()))
.WillByDefault(Return(QDateTime::currentSecsSinceEpoch()));
- auto filePathIds = indexer.updatableFilePathIds(projectPart1);
+ auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact);
ASSERT_THAT(filePathIds, IsEmpty());
}
diff --git a/tests/unit/unittest/symbolindexing-test.cpp b/tests/unit/unittest/symbolindexing-test.cpp
index 47b09ca008..aa8452ecfb 100644
--- a/tests/unit/unittest/symbolindexing-test.cpp
+++ b/tests/unit/unittest/symbolindexing-test.cpp
@@ -115,6 +115,4 @@ TEST_F(SymbolIndexing, DISABLED_TemplateFunction)
IsLocation(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 6, 5)));
}
-
-
}
diff --git a/tests/unit/unittest/symbolstorage-test.cpp b/tests/unit/unittest/symbolstorage-test.cpp
index 1b84f9a668..f69d49c9ae 100644
--- a/tests/unit/unittest/symbolstorage-test.cpp
+++ b/tests/unit/unittest/symbolstorage-test.cpp
@@ -26,8 +26,7 @@
#include "googletest.h"
#include "mockfilepathcaching.h"
-#include "mocksqlitereadstatement.h"
-#include "mocksqlitewritestatement.h"
+#include "mocksqlitedatabase.h"
#include <storagesqlitestatementfactory.h>
#include <symbolstorage.h>
@@ -52,9 +51,7 @@ using ClangBackEnd::SymbolType;
using Sqlite::Database;
using Sqlite::Table;
-using StatementFactory = StorageSqliteStatementFactory<MockSqliteDatabase,
- MockSqliteReadStatement,
- MockSqliteWriteStatement>;
+using StatementFactory = StorageSqliteStatementFactory<MockSqliteDatabase>;
using Storage = ClangBackEnd::SymbolStorage<StatementFactory>;
class SymbolStorage : public testing::Test
@@ -90,6 +87,8 @@ protected:
MockSqliteReadStatement &getProjectPartArtefactsBySourceId = statementFactory.getProjectPartArtefactsBySourceId;
MockSqliteReadStatement &getProjectPartArtefactsByProjectPartName = statementFactory.getProjectPartArtefactsByProjectPartName;
MockSqliteReadStatement &getLowestLastModifiedTimeOfDependencies = statementFactory.getLowestLastModifiedTimeOfDependencies;
+ MockSqliteReadStatement &getPrecompiledHeader = statementFactory.getPrecompiledHeader;
+
SymbolEntries symbolEntries{{1, {"functionUSR", "function"}},
{2, {"function2USR", "function2"}}};
SourceLocationEntries sourceLocations{{1, {1, 3}, {42, 23}, SymbolType::Declaration},
@@ -215,8 +214,8 @@ TEST_F(SymbolStorage, UpdateProjectPart)
EXPECT_CALL(updateProjectPartStatement,
write(TypedEq<Utils::SmallStringView>("[\"foo\"]"),
TypedEq<Utils::SmallStringView>("{\"FOO\":\"1\"}"),
- TypedEq<Utils::SmallStringView>("project"),
- TypedEq<Utils::SmallStringView>("[\"/includes\"]")));
+ TypedEq<Utils::SmallStringView>("[\"/includes\"]"),
+ TypedEq<Utils::SmallStringView>("project")));
storage.insertOrUpdateProjectPart("project", {"foo"}, {{"FOO", "1"}}, {"/includes"});
}
@@ -321,6 +320,24 @@ TEST_F(SymbolStorage, FetchLowestLastModifiedTime)
ASSERT_THAT(lowestLastModified, Eq(12));
}
+TEST_F(SymbolStorage, FetchPrecompiledHeaderCallsValueInStatement)
+{
+ EXPECT_CALL(getPrecompiledHeader, valueReturnProjectPartPch(Eq(25)));
+
+ storage.fetchPrecompiledHeader(25);
+}
+
+TEST_F(SymbolStorage, FetchPrecompiledHeader)
+{
+ ClangBackEnd::ProjectPartPch pch{"", "/path/to/pch", 131};
+ EXPECT_CALL(getPrecompiledHeader, valueReturnProjectPartPch(Eq(25)))
+ .WillRepeatedly(Return(pch));
+
+ auto precompiledHeader = storage.fetchPrecompiledHeader(25);
+
+ ASSERT_THAT(precompiledHeader.value(), Eq(pch));
+}
+
}
diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro
index 66d675c5c6..25b29ddea4 100644
--- a/tests/unit/unittest/unittest.pro
+++ b/tests/unit/unittest/unittest.pro
@@ -94,7 +94,8 @@ SOURCES += \
tokenprocessor-test.cpp \
projectpartartefact-test.cpp \
filestatuscache-test.cpp \
- highlightingresultreporter-test.cpp
+ highlightingresultreporter-test.cpp \
+ precompiledheaderstorage-test.cpp
!isEmpty(LIBCLANG_LIBS) {
SOURCES += \
@@ -229,7 +230,9 @@ HEADERS += \
runprojectcreateorupdate-utility.h \
rundocumentparse-utility.h \
mocktimer.h \
- mocksqlitetransactionbackend.h
+ mocksqlitetransactionbackend.h \
+ mockprojectpartprovider.h \
+ mockprecompiledheaderstorage.h
!isEmpty(LIBCLANG_LIBS) {
HEADERS += \
chunksreportedmonitor.h \