diff options
author | Marco Bubke <marco.bubke@qt.io> | 2019-05-22 12:26:58 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2019-06-17 10:46:21 +0000 |
commit | b213dee0134722fcdcae88efb514e0430fc72959 (patch) | |
tree | 51b62b0de0c934f30fd49a3a0056e44614f11209 /tests | |
parent | 912cb9278f7528709f9edf08060d997c20d3ec8c (diff) |
Clang: Improve updating
If project parts are up to date we send them directly to the indexer, so
the indexer can decide we something needs an update.
Change-Id: I7d4f32794c6b3a861cdefb3653a6dfd4e711f619
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/mockup/projectexplorer/project.h | 4 | ||||
-rw-r--r-- | tests/unit/unittest/gtest-creator-printing.cpp | 10 | ||||
-rw-r--r-- | tests/unit/unittest/mockpchmanagernotifier.h | 5 | ||||
-rw-r--r-- | tests/unit/unittest/mockprojectpartsmanager.h | 5 | ||||
-rw-r--r-- | tests/unit/unittest/pchcreator-test.cpp | 4 | ||||
-rw-r--r-- | tests/unit/unittest/pchmanagerclient-test.cpp | 61 | ||||
-rw-r--r-- | tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp | 2 | ||||
-rw-r--r-- | tests/unit/unittest/pchmanagerserver-test.cpp | 28 | ||||
-rw-r--r-- | tests/unit/unittest/projectpartsmanager-test.cpp | 53 | ||||
-rw-r--r-- | tests/unit/unittest/refactoringprojectupdater-test.cpp | 4 |
10 files changed, 77 insertions, 99 deletions
diff --git a/tests/unit/mockup/projectexplorer/project.h b/tests/unit/mockup/projectexplorer/project.h index e6e321ee43..c69eb6e47b 100644 --- a/tests/unit/mockup/projectexplorer/project.h +++ b/tests/unit/mockup/projectexplorer/project.h @@ -43,6 +43,10 @@ public: Target *activeTarget() const { return {}; } + QVariant namedSettings(const QString &name) const { return settings.at(name); } + void setNamedSettings(const QString &name, const QVariant &value) { settings[name] = value; } + Utils::FileName rootProjectDirectoryPath; + mutable std::map<QString, QVariant> settings; }; } // namespace ProjectExplorer diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 6b3433ef10..7ac4a676e3 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -51,7 +51,7 @@ #include <precompiledheadersupdatedmessage.h> #include <projectpartartefact.h> #include <projectpartentry.h> -#include <projectpartid.h> +#include <projectpartpch.h> #include <sourcedependency.h> #include <sourcelocationentry.h> #include <sourcelocationscontainer.h> @@ -719,18 +719,14 @@ std::ostream &operator<<(std::ostream &out, const NativeFilePath &filePath) std::ostream &operator<<(std::ostream &out, const PrecompiledHeadersUpdatedMessage &message) { - out << "(" - << message.projectPartPchs - << ")"; + out << "(" << message.projectPartIds << ")"; return out; } std::ostream &operator<<(std::ostream &out, const ProjectPartPch &projectPartPch) { - out << "(" - << projectPartPch.projectPartId << ", " - << projectPartPch.pchPath << ", " + out << "(" << projectPartPch.projectPartId << ", " << projectPartPch.pchPath << ", " << projectPartPch.lastModified << ")"; return out; diff --git a/tests/unit/unittest/mockpchmanagernotifier.h b/tests/unit/unittest/mockpchmanagernotifier.h index 600b37bd2e..8db9a63c40 100644 --- a/tests/unit/unittest/mockpchmanagernotifier.h +++ b/tests/unit/unittest/mockpchmanagernotifier.h @@ -36,9 +36,6 @@ public: : ClangPchManager::PchManagerNotifierInterface(pchManagerClient) {} - MOCK_METHOD3(precompiledHeaderUpdated, - void(ClangBackEnd::ProjectPartId projectPartId, - const QString &pchFilePath, - long long lastModified)); + MOCK_METHOD1(precompiledHeaderUpdated, void(ClangBackEnd::ProjectPartId projectPartId)); MOCK_METHOD1(precompiledHeaderRemoved, void(ClangBackEnd::ProjectPartId projectPartId)); }; diff --git a/tests/unit/unittest/mockprojectpartsmanager.h b/tests/unit/unittest/mockprojectpartsmanager.h index b2cab59060..613faf7dfc 100644 --- a/tests/unit/unittest/mockprojectpartsmanager.h +++ b/tests/unit/unittest/mockprojectpartsmanager.h @@ -33,7 +33,7 @@ class MockProjectPartsManager : public ClangBackEnd::ProjectPartsManagerInterfac { public: MOCK_METHOD1(update, - ClangBackEnd::ProjectPartContainers( + ClangBackEnd::ProjectPartsManagerInterface::UpToDataProjectParts( const ClangBackEnd::ProjectPartContainers &projectsParts)); MOCK_METHOD1(remove, void(const ClangBackEnd::ProjectPartIds &projectPartIds)); MOCK_CONST_METHOD1( @@ -42,7 +42,8 @@ public: MOCK_METHOD1(updateDeferred, void(const ClangBackEnd::ProjectPartContainers &projectsParts)); MOCK_METHOD0(deferredUpdates, ClangBackEnd::ProjectPartContainers()); - ClangBackEnd::ProjectPartContainers update(ClangBackEnd::ProjectPartContainers &&projectsParts) override + ClangBackEnd::ProjectPartsManagerInterface::UpToDataProjectParts update( + ClangBackEnd::ProjectPartContainers &&projectsParts) override { return update(projectsParts); } diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index 19bc087ca6..66943fc147 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -203,8 +203,8 @@ TEST_F(PchCreatorVerySlowTest, ProjectPartPchsSendToPchManagerClient) EXPECT_CALL(mockPchManagerClient, precompiledHeadersUpdated( - Field(&ClangBackEnd::PrecompiledHeadersUpdatedMessage::projectPartPchs, - ElementsAre(Eq(creator.projectPartPch()))))); + Field(&ClangBackEnd::PrecompiledHeadersUpdatedMessage::projectPartIds, + ElementsAre(Eq(creator.projectPartPch().projectPartId))))); creator.doInMainThreadAfterFinished(); } diff --git a/tests/unit/unittest/pchmanagerclient-test.cpp b/tests/unit/unittest/pchmanagerclient-test.cpp index 6c74143e4d..18a61d7038 100644 --- a/tests/unit/unittest/pchmanagerclient-test.cpp +++ b/tests/unit/unittest/pchmanagerclient-test.cpp @@ -65,11 +65,9 @@ protected: filePathCache, mockProjectPartsStorage}; ClangBackEnd::ProjectPartId projectPartId{1}; - ClangBackEnd::FilePath pchFilePath{"/path/to/pch"}; - PrecompiledHeadersUpdatedMessage message{{{projectPartId, pchFilePath.clone(), 1}}}; + PrecompiledHeadersUpdatedMessage message{{projectPartId}}; ClangBackEnd::ProjectPartId projectPartId2{2}; - ClangBackEnd::FilePath pchFilePath2{"/path/to/pch2"}; - PrecompiledHeadersUpdatedMessage message2{{{projectPartId2, pchFilePath2.clone(), 1}}}; + PrecompiledHeadersUpdatedMessage message2{{projectPartId2}}; }; TEST_F(PchManagerClient, NotifierAttached) @@ -93,8 +91,7 @@ TEST_F(PchManagerClient, NotifierDetached) TEST_F(PchManagerClient, Update) { - EXPECT_CALL(mockPchManagerNotifier, - precompiledHeaderUpdated(projectPartId, pchFilePath.toQString(), Eq(1))); + EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderUpdated(projectPartId)); client.precompiledHeadersUpdated(message.clone()); } @@ -106,58 +103,6 @@ TEST_F(PchManagerClient, Remove) projectUpdater.removeProjectParts({projectPartId, projectPartId}); } -TEST_F(PchManagerClient, GetNoProjectPartPchForWrongProjectPartId) -{ - auto optional = client.projectPartPch(23); - - 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(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)->lastModified, 1); -} - -TEST_F(PchManagerClient, ProjectPartPchForProjectPartIdIsUpdated) -{ - client.precompiledHeadersUpdated(message.clone()); - PrecompiledHeadersUpdatedMessage updateMessage{{{projectPartId, pchFilePath.clone(), 42}}}; - - client.precompiledHeadersUpdated(updateMessage.clone()); - - ASSERT_THAT(client.projectPartPch(projectPartId)->lastModified, 42); -} - TEST_F(PchManagerClient, SetPchCreationProgress) { EXPECT_CALL(mockPchCreationProgressManager, setProgress(10, 20)); diff --git a/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp b/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp index e55b71f860..194f52afd3 100644 --- a/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp +++ b/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp @@ -148,7 +148,7 @@ TEST_F(PchManagerClientServerInProcess, SendRemoveGeneratedFilesMessage) TEST_F(PchManagerClientServerInProcess, SendPrecompiledHeaderUpdatedMessage) { - PrecompiledHeadersUpdatedMessage message{{{1, "/path/to/pch", 1}}}; + PrecompiledHeadersUpdatedMessage message{1}; EXPECT_CALL(mockPchManagerClient, precompiledHeadersUpdated(message)); diff --git a/tests/unit/unittest/pchmanagerserver-test.cpp b/tests/unit/unittest/pchmanagerserver-test.cpp index 502b51bc8c..47b7d987ab 100644 --- a/tests/unit/unittest/pchmanagerserver-test.cpp +++ b/tests/unit/unittest/pchmanagerserver-test.cpp @@ -48,6 +48,7 @@ using ClangBackEnd::V2::FileContainer; using ClangBackEnd::V2::FileContainers; using ClangBackEnd::ProjectPartContainer; using ClangBackEnd::ProjectPartContainers; +using UpToDataProjectParts = ClangBackEnd::ProjectPartsManagerInterface::UpToDataProjectParts; class PchManagerServer : public ::testing::Test { @@ -55,7 +56,8 @@ class PchManagerServer : public ::testing::Test { server.setClient(&mockPchManagerClient); - ON_CALL(mockProjectPartsManager, update(projectParts)).WillByDefault(Return(projectParts)); + ON_CALL(mockProjectPartsManager, update(projectParts)) + .WillByDefault(Return(UpToDataProjectParts{{}, projectParts})); ON_CALL(mockGeneratedFiles, isValid()).WillByDefault(Return(true)); } @@ -107,7 +109,8 @@ protected: Utils::LanguageVersion::C11, Utils::LanguageExtension::All}; std::vector<ProjectPartContainer> projectParts{projectPart1, projectPart2}; - std::vector<ProjectPartContainer> projectParts2{projectPart2}; + std::vector<ProjectPartContainer> projectParts1{projectPart1}; + std::vector<ProjectPartContainer> projectParts2{projectPart2}; FileContainer generatedFile{{"/path/to/", "file"}, "content", {}}; ClangBackEnd::UpdateProjectPartsMessage updateProjectPartsMessage{ Utils::clone(projectParts), {"toolChainArgument"}}; @@ -120,7 +123,7 @@ TEST_F(PchManagerServer, FilterProjectPartsAndSendThemToQueue) InSequence s; EXPECT_CALL(mockProjectPartsManager, update(updateProjectPartsMessage.projectsParts)) - .WillOnce(Return(projectParts2)); + .WillOnce(Return(UpToDataProjectParts{{}, projectParts2})); EXPECT_CALL( mockPchTaskGenerator, addProjectParts(Eq(projectParts2), ElementsAre("toolChainArgument"))); @@ -219,7 +222,7 @@ TEST_F(PchManagerServer, DontGeneratePchIfGeneratedFilesAreNotValid) InSequence s; EXPECT_CALL(mockProjectPartsManager, update(ElementsAre(projectPart1))) - .WillOnce(Return(ProjectPartContainers{projectPart1})); + .WillOnce(Return(UpToDataProjectParts{{}, ProjectPartContainers{projectPart1}})); EXPECT_CALL(mockGeneratedFiles, isValid()).WillOnce(Return(false)); EXPECT_CALL(mockPchTaskGenerator, addProjectParts(_, _)).Times(0); EXPECT_CALL(mockProjectPartsManager, updateDeferred(ElementsAre(projectPart1))); @@ -233,7 +236,7 @@ TEST_F(PchManagerServer, GeneratePchIfGeneratedFilesAreValid) InSequence s; EXPECT_CALL(mockProjectPartsManager, update(ElementsAre(projectPart1))) - .WillOnce(Return(ProjectPartContainers{projectPart1})); + .WillOnce(Return(UpToDataProjectParts{{}, ProjectPartContainers{projectPart1}})); EXPECT_CALL(mockGeneratedFiles, isValid()).WillOnce(Return(true)); EXPECT_CALL(mockPchTaskGenerator, addProjectParts(_, _)); EXPECT_CALL(mockProjectPartsManager, updateDeferred(_)).Times(0); @@ -276,4 +279,19 @@ TEST_F(PchManagerServer, AfterUpdatingGeneratedFilesAreStillInvalidSoNoPchsGener server.updateGeneratedFiles(updateGeneratedFilesMessage.clone()); } +TEST_F(PchManagerServer, SentUpToDateProjectPartIdsToClient) +{ + InSequence s; + + EXPECT_CALL(mockProjectPartsManager, update(updateProjectPartsMessage.projectsParts)) + .WillOnce(Return(UpToDataProjectParts{projectParts1, projectParts2})); + EXPECT_CALL(mockPchTaskGenerator, + addProjectParts(Eq(projectParts2), ElementsAre("toolChainArgument"))); + EXPECT_CALL(mockPchManagerClient, + precompiledHeadersUpdated( + Field(&ClangBackEnd::PrecompiledHeadersUpdatedMessage::projectPartIds, + ElementsAre(Eq(projectPart1.projectPartId))))); + + server.updateProjectParts(updateProjectPartsMessage.clone()); } +} // namespace diff --git a/tests/unit/unittest/projectpartsmanager-test.cpp b/tests/unit/unittest/projectpartsmanager-test.cpp index b12cbb6b2e..d86543e9c2 100644 --- a/tests/unit/unittest/projectpartsmanager-test.cpp +++ b/tests/unit/unittest/projectpartsmanager-test.cpp @@ -36,6 +36,7 @@ namespace { using ClangBackEnd::FilePathId; using ClangBackEnd::ProjectPartContainer; using ClangBackEnd::ProjectPartContainers; +using UpToDataProjectParts = ClangBackEnd::ProjectPartsManagerInterface::UpToDataProjectParts; class ProjectPartsManager : public testing::Test { @@ -111,16 +112,20 @@ protected: TEST_F(ProjectPartsManager, GetNoProjectPartsForAddingEmptyProjectParts) { - auto updatedProjectParts = manager.update({}); + auto projectParts = manager.update({}); - ASSERT_THAT(updatedProjectParts, IsEmpty()); + ASSERT_THAT(projectParts, + AllOf(Field(&UpToDataProjectParts::upToDate, IsEmpty()), + Field(&UpToDataProjectParts::notUpToDate, IsEmpty()))); } TEST_F(ProjectPartsManager, GetProjectPartForAddingProjectPart) { - auto updatedProjectParts = manager.update({projectPartContainer1}); + auto projectParts = manager.update({projectPartContainer1}); - ASSERT_THAT(updatedProjectParts, ElementsAre(projectPartContainer1)); + ASSERT_THAT(projectParts, + AllOf(Field(&UpToDataProjectParts::upToDate, IsEmpty()), + Field(&UpToDataProjectParts::notUpToDate, ElementsAre(projectPartContainer1)))); } TEST_F(ProjectPartsManager, GetProjectPartForAddingProjectPartWithProjectPartAlreadyInTheDatabase) @@ -128,9 +133,11 @@ TEST_F(ProjectPartsManager, GetProjectPartForAddingProjectPartWithProjectPartAlr ON_CALL(mockProjectPartsStorage, fetchProjectParts(_)) .WillByDefault(Return(ProjectPartContainers{projectPartContainer1})); - auto updatedProjectParts = manager.update({projectPartContainer1, projectPartContainer2}); + auto projectParts = manager.update({projectPartContainer1, projectPartContainer2}); - ASSERT_THAT(updatedProjectParts, ElementsAre(projectPartContainer2)); + ASSERT_THAT(projectParts, + AllOf(Field(&UpToDataProjectParts::upToDate, ElementsAre(projectPartContainer1)), + Field(&UpToDataProjectParts::notUpToDate, ElementsAre(projectPartContainer2)))); } TEST_F(ProjectPartsManager, GetProjectPartForAddingProjectPartWithOlderProjectPartAlreadyInTheDatabase) @@ -138,9 +145,12 @@ TEST_F(ProjectPartsManager, GetProjectPartForAddingProjectPartWithOlderProjectPa ON_CALL(mockProjectPartsStorage, fetchProjectParts(_)) .WillByDefault(Return(ProjectPartContainers{projectPartContainer1})); - auto updatedProjectParts = manager.update({updatedProjectPartContainer1, projectPartContainer2}); + auto projectParts = manager.update({updatedProjectPartContainer1, projectPartContainer2}); - ASSERT_THAT(updatedProjectParts, ElementsAre(updatedProjectPartContainer1, projectPartContainer2)); + ASSERT_THAT(projectParts, + AllOf(Field(&UpToDataProjectParts::upToDate, IsEmpty()), + Field(&UpToDataProjectParts::notUpToDate, + ElementsAre(updatedProjectPartContainer1, projectPartContainer2)))); } TEST_F(ProjectPartsManager, ProjectPartAdded) @@ -184,9 +194,11 @@ TEST_F(ProjectPartsManager, DoNotUpdateNotNewProjectPart) { manager.update({projectPartContainer1}); - auto updatedProjectParts = manager.update({projectPartContainer1}); + auto projectParts = manager.update({projectPartContainer1}); - ASSERT_THAT(updatedProjectParts, IsEmpty()); + ASSERT_THAT(projectParts, + AllOf(Field(&UpToDataProjectParts::upToDate, ElementsAre(projectPartContainer1)), + Field(&UpToDataProjectParts::notUpToDate, IsEmpty()))); } TEST_F(ProjectPartsManager, NoDuplicateProjectPartAfterUpdatingWithNotNewProjectPart) @@ -216,8 +228,8 @@ TEST_F(ProjectPartsManager, MergeProjectMultipleTimesParts) TEST_F(ProjectPartsManager, GetNewProjectParts) { - auto newProjectParts = manager.filterNewProjectParts({projectPartContainer1, projectPartContainer2}, - {projectPartContainer2}); + auto newProjectParts = manager.filterProjectParts({projectPartContainer1, projectPartContainer2}, + {projectPartContainer2}); ASSERT_THAT(newProjectParts, ElementsAre(projectPartContainer1)); } @@ -226,9 +238,12 @@ TEST_F(ProjectPartsManager, GetUpdatedProjectPart) { manager.update({projectPartContainer1, projectPartContainer2}); - auto updatedProjectParts = manager.update({updatedProjectPartContainer1}); + auto projectParts = manager.update({updatedProjectPartContainer1}); - ASSERT_THAT(updatedProjectParts, ElementsAre(updatedProjectPartContainer1)); + ASSERT_THAT(projectParts, + AllOf(Field(&UpToDataProjectParts::upToDate, IsEmpty()), + Field(&UpToDataProjectParts::notUpToDate, + ElementsAre(updatedProjectPartContainer1)))); } TEST_F(ProjectPartsManager, ProjectPartIsReplacedWithUpdatedProjectPart) @@ -280,14 +295,14 @@ TEST_F(ProjectPartsManager, UpdateDeferred) TEST_F(ProjectPartsManager, NotUpdateDeferred) { - auto projectPartContainers = manager.update({projectPartContainer1, projectPartContainer2}); + manager.update({projectPartContainer1, projectPartContainer2}); ASSERT_THAT(manager.deferredUpdates(), IsEmpty()); } TEST_F(ProjectPartsManager, UpdateDeferredCleansDeferredUpdates) { - auto projectPartContainers = manager.update({projectPartContainer1, projectPartContainer2}); + manager.update({projectPartContainer1, projectPartContainer2}); manager.updateDeferred({projectPartContainer1}); manager.deferredUpdates(); @@ -386,9 +401,11 @@ TEST_F(ProjectPartsManager, ON_CALL(mockProjectPartsStorage, fetchProjectParts(_)) .WillByDefault(Return(ProjectPartContainers{projectPartContainerWithoutPrecompiledHeader1})); - auto updatedProjectParts = manager.update({projectPartContainer1}); + auto projectParts = manager.update({projectPartContainer1}); - ASSERT_THAT(updatedProjectParts, ElementsAre(projectPartContainer1)); + ASSERT_THAT(projectParts, + AllOf(Field(&UpToDataProjectParts::upToDate, IsEmpty()), + Field(&UpToDataProjectParts::notUpToDate, ElementsAre(projectPartContainer1)))); } TEST_F(ProjectPartsManager, ProjectPartAddedWithProjectPartAlreadyInTheDatabaseButWithoutEntries) diff --git a/tests/unit/unittest/refactoringprojectupdater-test.cpp b/tests/unit/unittest/refactoringprojectupdater-test.cpp index 8d5e60df91..6913d1a16f 100644 --- a/tests/unit/unittest/refactoringprojectupdater-test.cpp +++ b/tests/unit/unittest/refactoringprojectupdater-test.cpp @@ -101,7 +101,7 @@ TEST_F(RefactoringProjectUpdater, DontUpdateProjectPartIfNoProjectPartExistsForI EXPECT_CALL(mockCppModelManager, projectPartForId(Eq(QString("project1")))); EXPECT_CALL(mockRefactoringServer, updateProjectParts(_)).Times(0); - pchManagerClient.precompiledHeadersUpdated({{{3, "/path/to/pch", 12}}}); + pchManagerClient.precompiledHeadersUpdated({3}); } TEST_F(RefactoringProjectUpdater, UpdateProjectPart) @@ -118,7 +118,7 @@ TEST_F(RefactoringProjectUpdater, UpdateProjectPart) updateProjectParts(Field(&UpdateProjectPartsMessage::projectsParts, ElementsAre(IsProjectPartContainer(3))))); - pchManagerClient.precompiledHeadersUpdated({{{3, "/path/to/pch", 12}}}); + pchManagerClient.precompiledHeadersUpdated({3}); } TEST_F(RefactoringProjectUpdater, RemoveProjectPart) |