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 "mockpchmanagernotifier.h"
|
|
|
|
#include "mockpchmanagerserver.h"
|
2018-02-20 12:43:05 +01:00
|
|
|
#include "mockprecompiledheaderstorage.h"
|
2017-01-30 11:24:46 +01:00
|
|
|
|
|
|
|
#include <pchmanagerclient.h>
|
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>
|
|
|
|
#include <refactoringdatabaseinitializer.h>
|
2017-01-30 11:24:46 +01:00
|
|
|
#include <precompiledheadersupdatedmessage.h>
|
2018-02-20 12:43:05 +01:00
|
|
|
#include <removeprojectpartsmessage.h>
|
|
|
|
#include <updateprojectpartsmessage.h>
|
2017-01-30 11:24:46 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using ClangBackEnd::PrecompiledHeadersUpdatedMessage;
|
|
|
|
|
|
|
|
using testing::_;
|
|
|
|
using testing::Contains;
|
|
|
|
using testing::Not;
|
|
|
|
|
|
|
|
class PchManagerClient : public ::testing::Test
|
|
|
|
{
|
|
|
|
protected:
|
2018-02-20 12:43:05 +01:00
|
|
|
NiceMock<MockPchManagerServer> mockPchManagerServer;
|
|
|
|
NiceMock<MockPrecompiledHeaderStorage> mockPrecompiledHeaderStorage;
|
|
|
|
ClangPchManager::PchManagerClient client{mockPrecompiledHeaderStorage};
|
|
|
|
NiceMock<MockPchManagerNotifier> mockPchManagerNotifier{client};
|
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};
|
|
|
|
ClangPchManager::PchManagerProjectUpdater projectUpdater{mockPchManagerServer, client, filePathCache};
|
2017-01-30 11:24:46 +01:00
|
|
|
Utils::SmallString projectPartId{"projectPartId"};
|
|
|
|
Utils::SmallString pchFilePath{"/path/to/pch"};
|
2018-02-15 14:29:20 +01:00
|
|
|
PrecompiledHeadersUpdatedMessage message{{{projectPartId.clone(), pchFilePath.clone(), 1}}};
|
2018-02-20 12:43:05 +01:00
|
|
|
Utils::SmallString projectPartId2{"projectPartId2"};
|
|
|
|
Utils::SmallString pchFilePath2{"/path/to/pch2"};
|
|
|
|
PrecompiledHeadersUpdatedMessage message2{{{projectPartId2.clone(), pchFilePath2.clone(), 1}}};
|
2017-01-30 11:24:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(PchManagerClient, NotifierAttached)
|
|
|
|
{
|
|
|
|
MockPchManagerNotifier notifier(client);
|
|
|
|
|
|
|
|
ASSERT_THAT(client.notifiers(), Contains(¬ifier));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PchManagerClient, NotifierDetached)
|
|
|
|
{
|
|
|
|
MockPchManagerNotifier *notifierPointer = nullptr;
|
|
|
|
|
|
|
|
{
|
|
|
|
MockPchManagerNotifier notifier(client);
|
|
|
|
notifierPointer = ¬ifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_THAT(client.notifiers(), Not(Contains(notifierPointer)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PchManagerClient, Update)
|
|
|
|
{
|
2018-02-15 14:29:20 +01:00
|
|
|
EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderUpdated(projectPartId.toQString(), pchFilePath.toQString(), Eq(1)));
|
2017-01-30 11:24:46 +01:00
|
|
|
|
|
|
|
client.precompiledHeadersUpdated(message.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PchManagerClient, Remove)
|
|
|
|
{
|
|
|
|
EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId.toQString()))
|
|
|
|
.Times(2);
|
|
|
|
|
2017-08-29 12:54:10 +02:00
|
|
|
projectUpdater.removeProjectParts({QString(projectPartId.clone()),
|
|
|
|
QString(projectPartId.clone())});
|
2017-01-30 11:24:46 +01:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
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)});
|
|
|
|
}
|
|
|
|
|
2017-01-30 11:24:46 +01:00
|
|
|
}
|