2017-01-30 11:24:46 +01:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2016 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 "mockpchmanagerclient.h"
|
|
|
|
#include "mockpchmanagernotifier.h"
|
|
|
|
#include "mockpchmanagerserver.h"
|
2018-02-20 12:43:05 +01:00
|
|
|
#include "mockprecompiledheaderstorage.h"
|
2017-01-30 11:24:46 +01:00
|
|
|
|
2017-08-17 12:44:52 +02:00
|
|
|
#include <pchmanagerprojectupdater.h>
|
2017-01-30 11:24:46 +01:00
|
|
|
|
2018-01-22 14:21:01 +01:00
|
|
|
#include <filepathcaching.h>
|
2017-01-30 11:24:46 +01:00
|
|
|
#include <pchmanagerclient.h>
|
2018-02-20 12:43:05 +01:00
|
|
|
#include <precompiledheaderstorage.h>
|
2017-01-30 11:24:46 +01:00
|
|
|
#include <precompiledheadersupdatedmessage.h>
|
2018-01-22 14:21:01 +01:00
|
|
|
#include <refactoringdatabaseinitializer.h>
|
2018-08-06 19:14:00 +02:00
|
|
|
#include <removegeneratedfilesmessage.h>
|
2018-02-20 12:43:05 +01:00
|
|
|
#include <removeprojectpartsmessage.h>
|
2018-08-06 19:14:00 +02:00
|
|
|
#include <updategeneratedfilesmessage.h>
|
2018-02-20 12:43:05 +01:00
|
|
|
#include <updateprojectpartsmessage.h>
|
2017-01-30 11:24:46 +01:00
|
|
|
|
2017-09-27 10:32:52 +02:00
|
|
|
#include <cpptools/compileroptionsbuilder.h>
|
2017-01-30 11:24:46 +01:00
|
|
|
#include <cpptools/projectpart.h>
|
|
|
|
|
2018-01-22 14:21:01 +01:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
2017-01-30 11:24:46 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
using testing::_;
|
2017-02-01 13:43:28 +01:00
|
|
|
using testing::ElementsAre;
|
2017-01-30 11:24:46 +01:00
|
|
|
using testing::SizeIs;
|
|
|
|
using testing::NiceMock;
|
|
|
|
using testing::AnyNumber;
|
|
|
|
|
2018-02-08 12:48:46 +01:00
|
|
|
using ClangBackEnd::CompilerMacro;
|
2017-02-01 13:43:28 +01:00
|
|
|
using ClangBackEnd::V2::FileContainer;
|
2017-01-30 11:24:46 +01:00
|
|
|
using ClangBackEnd::V2::ProjectPartContainer;
|
2017-09-27 10:32:52 +02:00
|
|
|
using CppTools::CompilerOptionsBuilder;
|
2018-09-03 16:10:43 +02:00
|
|
|
using ProjectExplorer::HeaderPath;
|
2017-01-30 11:24:46 +01:00
|
|
|
|
|
|
|
class ProjectUpdater : public testing::Test
|
|
|
|
{
|
|
|
|
protected:
|
2018-01-22 14:21:01 +01:00
|
|
|
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);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetUp() override
|
|
|
|
{
|
|
|
|
projectPart.files.push_back(header1ProjectFile);
|
|
|
|
projectPart.files.push_back(header2ProjectFile);
|
|
|
|
projectPart.files.push_back(source1ProjectFile);
|
|
|
|
projectPart.files.push_back(source2ProjectFile);
|
|
|
|
projectPart.displayName = QString(projectPartId);
|
2018-08-07 19:01:01 +02:00
|
|
|
projectPart.projectMacros = {{"FOO", "2"}, {"BAR", "1"}};
|
2018-01-22 14:21:01 +01:00
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
projectPart2.files.push_back(header2ProjectFile);
|
|
|
|
projectPart2.files.push_back(header1ProjectFile);
|
|
|
|
projectPart2.files.push_back(source2ProjectFile);
|
|
|
|
projectPart2.files.push_back(source1ProjectFile);
|
|
|
|
projectPart2.displayName = QString(projectPartId2);
|
|
|
|
projectPart2.projectMacros = {{"BAR", "1"}, {"FOO", "2"}};
|
2018-02-08 12:48:46 +01:00
|
|
|
|
2018-01-22 14:21:01 +01:00
|
|
|
Utils::SmallStringVector arguments{ClangPchManager::ProjectUpdater::compilerArguments(
|
|
|
|
&projectPart)};
|
2018-08-07 19:01:01 +02:00
|
|
|
Utils::SmallStringVector arguments2{ClangPchManager::ProjectUpdater::compilerArguments(
|
|
|
|
&projectPart2)};
|
2018-01-22 14:21:01 +01:00
|
|
|
|
|
|
|
expectedContainer = {projectPartId.clone(),
|
|
|
|
arguments.clone(),
|
2018-02-06 19:03:14 +01:00
|
|
|
Utils::clone(compilerMacros),
|
2018-02-08 12:48:46 +01:00
|
|
|
{},
|
2018-01-22 14:21:01 +01:00
|
|
|
{filePathId(headerPaths[1])},
|
|
|
|
{filePathIds(sourcePaths)}};
|
2018-08-07 19:01:01 +02:00
|
|
|
expectedContainer2 = {projectPartId2.clone(),
|
|
|
|
arguments2.clone(),
|
|
|
|
Utils::clone(compilerMacros),
|
|
|
|
{},
|
|
|
|
{filePathId(headerPaths[1])},
|
|
|
|
{filePathIds(sourcePaths)}};
|
2018-01-22 14:21:01 +01:00
|
|
|
}
|
2017-01-30 11:24:46 +01:00
|
|
|
|
|
|
|
protected:
|
2018-01-22 14:21:01 +01:00
|
|
|
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
|
|
|
|
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
|
|
|
|
ClangBackEnd::FilePathCaching filePathCache{database};
|
2018-02-20 12:43:05 +01:00
|
|
|
MockPrecompiledHeaderStorage mockPrecompiledHeaderStorage;
|
|
|
|
ClangPchManager::PchManagerClient pchManagerClient{mockPrecompiledHeaderStorage};
|
2017-01-30 11:24:46 +01:00
|
|
|
MockPchManagerNotifier mockPchManagerNotifier{pchManagerClient};
|
|
|
|
NiceMock<MockPchManagerServer> mockPchManagerServer;
|
2018-01-22 14:21:01 +01:00
|
|
|
ClangPchManager::ProjectUpdater updater{mockPchManagerServer, filePathCache};
|
2017-01-30 11:24:46 +01:00
|
|
|
Utils::SmallString projectPartId{"project1"};
|
|
|
|
Utils::SmallString projectPartId2{"project2"};
|
2017-02-01 13:43:28 +01:00
|
|
|
Utils::PathStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"};
|
|
|
|
Utils::PathStringVector sourcePaths = {"/path/to/source1.cpp", "/path/to/source2.cpp"};
|
2018-08-07 19:01:01 +02:00
|
|
|
ClangBackEnd::CompilerMacros compilerMacros = {{"BAR", "1"}, {"FOO", "2"}};
|
2017-08-29 12:54:10 +02:00
|
|
|
CppTools::ProjectFile header1ProjectFile{QString(headerPaths[0]), CppTools::ProjectFile::CXXHeader};
|
|
|
|
CppTools::ProjectFile header2ProjectFile{QString(headerPaths[1]), CppTools::ProjectFile::CXXHeader};
|
|
|
|
CppTools::ProjectFile source1ProjectFile{QString(sourcePaths[0]), CppTools::ProjectFile::CXXSource};
|
|
|
|
CppTools::ProjectFile source2ProjectFile{QString(sourcePaths[1]), CppTools::ProjectFile::CXXSource};
|
2017-01-30 11:24:46 +01:00
|
|
|
CppTools::ProjectPart projectPart;
|
2018-08-07 19:01:01 +02:00
|
|
|
CppTools::ProjectPart projectPart2;
|
2017-01-30 11:24:46 +01:00
|
|
|
ProjectPartContainer expectedContainer;
|
2018-08-07 19:01:01 +02:00
|
|
|
ProjectPartContainer expectedContainer2;
|
2017-02-01 13:43:28 +01:00
|
|
|
FileContainer generatedFile{{"/path/to", "header1.h"}, "content", {}};
|
2018-08-07 19:01:01 +02:00
|
|
|
FileContainer generatedFile2{{"/path/to2", "header1.h"}, "content", {}};
|
|
|
|
FileContainer generatedFile3{{"/path/to", "header2.h"}, "content", {}};
|
2017-01-30 11:24:46 +01:00
|
|
|
};
|
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
TEST_F(ProjectUpdater, CallUpdateProjectParts)
|
2017-01-30 11:24:46 +01:00
|
|
|
{
|
2018-08-07 19:01:01 +02:00
|
|
|
std::vector<CppTools::ProjectPart*> projectParts = {&projectPart2, &projectPart};
|
|
|
|
ClangBackEnd::UpdateProjectPartsMessage message{{expectedContainer.clone(), expectedContainer2.clone()}};
|
|
|
|
updater.updateGeneratedFiles({generatedFile});
|
2017-01-30 11:24:46 +01:00
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
EXPECT_CALL(mockPchManagerServer, updateProjectParts(message));
|
2017-01-30 11:24:46 +01:00
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
updater.updateProjectParts(projectParts);
|
2017-01-30 11:24:46 +01:00
|
|
|
}
|
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
TEST_F(ProjectUpdater, CallUpdateGeneratedFilesWithSortedEntries)
|
2018-08-06 19:14:00 +02:00
|
|
|
{
|
2018-08-07 19:01:01 +02:00
|
|
|
ClangBackEnd::UpdateGeneratedFilesMessage message{{generatedFile, generatedFile3, generatedFile2}};
|
2018-08-06 19:14:00 +02:00
|
|
|
|
|
|
|
EXPECT_CALL(mockPchManagerServer, updateGeneratedFiles(message));
|
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProjectUpdater, GeneratedFilesAddedAreSorted)
|
|
|
|
{
|
|
|
|
updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile});
|
|
|
|
|
|
|
|
ASSERT_THAT(updater.generatedFiles().fileContainers(),
|
|
|
|
ElementsAre(generatedFile, generatedFile3, generatedFile2));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProjectUpdater, GeneratedFilesAddedToExcludePaths)
|
|
|
|
{
|
|
|
|
updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile});
|
|
|
|
|
|
|
|
ASSERT_THAT(updater.excludedPaths(), ElementsAre(generatedFile.filePath,
|
|
|
|
generatedFile3.filePath,
|
|
|
|
generatedFile2.filePath));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProjectUpdater, CallRemoveGeneratedFiles)
|
|
|
|
{
|
|
|
|
ClangBackEnd::RemoveGeneratedFilesMessage message{{{"/path/to/header1.h"}}};
|
|
|
|
|
|
|
|
EXPECT_CALL(mockPchManagerServer, removeGeneratedFiles(message));
|
|
|
|
|
|
|
|
updater.removeGeneratedFiles({{"/path/to/header1.h"}});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProjectUpdater, GeneratedFilesRemovedFromExcludePaths)
|
|
|
|
{
|
|
|
|
updater.updateGeneratedFiles({generatedFile});
|
|
|
|
|
|
|
|
updater.removeGeneratedFiles({generatedFile.filePath});
|
|
|
|
|
|
|
|
ASSERT_THAT(updater.excludedPaths(), IsEmpty());
|
2018-08-06 19:14:00 +02:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
TEST_F(ProjectUpdater, CallRemoveProjectParts)
|
2017-01-30 11:24:46 +01:00
|
|
|
{
|
2018-02-20 12:43:05 +01:00
|
|
|
ClangBackEnd::RemoveProjectPartsMessage message{{projectPartId, projectPartId2}};
|
2017-08-17 12:44:52 +02:00
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
EXPECT_CALL(mockPchManagerServer, removeProjectParts(message));
|
2017-01-30 11:24:46 +01:00
|
|
|
|
2017-08-29 12:54:10 +02:00
|
|
|
updater.removeProjectParts({QString(projectPartId), QString(projectPartId2)});
|
2017-01-30 11:24:46 +01:00
|
|
|
}
|
|
|
|
|
2017-08-17 12:44:52 +02:00
|
|
|
TEST_F(ProjectUpdater, CallPrecompiledHeaderRemovedInPchManagerProjectUpdater)
|
2017-01-30 11:24:46 +01:00
|
|
|
{
|
2018-01-22 14:21:01 +01:00
|
|
|
ClangPchManager::PchManagerProjectUpdater pchUpdater{mockPchManagerServer, pchManagerClient, filePathCache};
|
2018-02-20 12:43:05 +01:00
|
|
|
ClangBackEnd::RemoveProjectPartsMessage message{{projectPartId, projectPartId2}};
|
2018-08-07 19:01:01 +02:00
|
|
|
EXPECT_CALL(mockPrecompiledHeaderStorage, deletePrecompiledHeader(_)).Times(AnyNumber());
|
2017-01-30 11:24:46 +01:00
|
|
|
|
|
|
|
EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId.toQString()));
|
|
|
|
EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId2.toQString()));
|
|
|
|
|
2017-08-17 12:44:52 +02:00
|
|
|
pchUpdater.removeProjectParts({QString(projectPartId), QString(projectPartId2)});
|
2017-01-30 11:24:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainer)
|
|
|
|
{
|
2017-02-01 13:43:28 +01:00
|
|
|
updater.setExcludedPaths({"/path/to/header1.h"});
|
|
|
|
|
2017-01-30 11:24:46 +01:00
|
|
|
auto container = updater.toProjectPartContainer(&projectPart);
|
|
|
|
|
|
|
|
ASSERT_THAT(container, expectedContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainersHaveSameSizeLikeProjectParts)
|
|
|
|
{
|
|
|
|
auto containers = updater.toProjectPartContainers({&projectPart, &projectPart});
|
|
|
|
|
|
|
|
ASSERT_THAT(containers, SizeIs(2));
|
|
|
|
}
|
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
TEST_F(ProjectUpdater, CreateSortedExcludedPaths)
|
2017-02-01 13:43:28 +01:00
|
|
|
{
|
2018-08-07 19:01:01 +02:00
|
|
|
auto excludedPaths = updater.createExcludedPaths({generatedFile2, generatedFile3, generatedFile});
|
2017-02-01 13:43:28 +01:00
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
ASSERT_THAT(excludedPaths, ElementsAre(ClangBackEnd::FilePath{"/path/to/header1.h"},
|
|
|
|
ClangBackEnd::FilePath{"/path/to/header2.h"},
|
|
|
|
ClangBackEnd::FilePath{"/path/to2/header1.h"}));
|
2017-02-01 13:43:28 +01:00
|
|
|
}
|
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
TEST_F(ProjectUpdater, CreateSortedCompilerMacros)
|
2018-02-08 12:48:46 +01:00
|
|
|
{
|
2018-08-07 19:01:01 +02:00
|
|
|
auto paths = updater.createCompilerMacros({{"DEFINE", "1"}, {"FOO", "2"}, {"BAR", "1"}});
|
2018-02-08 12:48:46 +01:00
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
ASSERT_THAT(paths, ElementsAre(CompilerMacro{"BAR", "1"},
|
|
|
|
CompilerMacro{"FOO", "2"},
|
|
|
|
CompilerMacro{"DEFINE", "1"}));
|
2018-02-08 12:48:46 +01:00
|
|
|
}
|
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
TEST_F(ProjectUpdater, CreateSortedIncludeSearchPaths)
|
2018-02-08 12:48:46 +01:00
|
|
|
{
|
2018-09-03 16:10:43 +02:00
|
|
|
ProjectExplorer::HeaderPath includePath{"/to/path1", ProjectExplorer::IncludePathType::User};
|
|
|
|
ProjectExplorer::HeaderPath includePath2{"/to/path2", ProjectExplorer::IncludePathType::User};
|
|
|
|
ProjectExplorer::HeaderPath invalidPath;
|
|
|
|
ProjectExplorer::HeaderPath frameworkPath{"/framework/path", ProjectExplorer::IncludePathType::Framework};
|
2018-02-08 12:48:46 +01:00
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
auto paths = updater.createIncludeSearchPaths({frameworkPath, includePath2, includePath, invalidPath});
|
2018-02-08 12:48:46 +01:00
|
|
|
|
2018-08-07 19:01:01 +02:00
|
|
|
ASSERT_THAT(paths, ElementsAre(includePath.path, includePath2.path, frameworkPath.path));
|
2018-02-08 12:48:46 +01:00
|
|
|
}
|
2018-01-22 14:21:01 +01:00
|
|
|
|
2017-01-30 11:24:46 +01:00
|
|
|
}
|
|
|
|
|