UnitTests: Use MockFunction instead of home grown mock class

Change-Id: Ic0cd2fb7d073e8cf962d98b850719f4311e9f35a
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2017-12-28 20:21:04 +01:00
parent 5d088e9df5
commit 640575640c
3 changed files with 9 additions and 66 deletions

View File

@@ -24,7 +24,6 @@
****************************************************************************/
#include "googletest.h"
#include "mockrefactoringclientcallback.h"
#include "mocksearchhandle.h"
#include "mockfilepathcaching.h"
#include "mocksymbolquery.h"
@@ -57,11 +56,6 @@ using ClangBackEnd::SourceLocationsForRenamingMessage;
using ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage;
using ClangBackEnd::SourceRangesForQueryMessage;
using testing::_;
using testing::Pair;
using testing::Contains;
using testing::NiceMock;
using Utils::PathString;
using Utils::SmallString;
using Utils::SmallStringVector;
@@ -74,8 +68,10 @@ protected:
NiceMock<MockFilePathCaching> mockFilePathCaching;
NiceMock<MockSearchHandle> mockSearchHandle;
NiceMock<MockSymbolQuery> mockSymbolQuery;
MockRefactoringClientCallBack callbackMock;
QBuffer ioDevice;
MockFunction<void(const QString &,
const ClangBackEnd::SourceLocationsContainer &,
int)> mockLocalRenaming;
ClangRefactoring::RefactoringClient client;
ClangBackEnd::RefactoringServerProxy serverProxy{&client, &ioDevice};
RefactoringEngine engine{serverProxy, client, mockFilePathCaching, mockSymbolQuery};
@@ -98,32 +94,19 @@ protected:
TEST_F(RefactoringClient, SourceLocationsForRenaming)
{
client.setLocalRenamingCallback([&] (const QString &symbolName,
const ClangBackEnd::SourceLocationsContainer &sourceLocations,
int textDocumentRevision) {
callbackMock.localRenaming(symbolName,
sourceLocations,
textDocumentRevision);
});
client.setLocalRenamingCallback(mockLocalRenaming.AsStdFunction());
EXPECT_CALL(callbackMock, localRenaming(renameMessage.symbolName().toQString(),
renameMessage.sourceLocations(),
renameMessage.textDocumentRevision()))
.Times(1);
EXPECT_CALL(mockLocalRenaming, Call(renameMessage.symbolName().toQString(),
renameMessage.sourceLocations(),
renameMessage.textDocumentRevision()));
client.sourceLocationsForRenamingMessage(std::move(renameMessage));
}
TEST_F(RefactoringClient, AfterSourceLocationsForRenamingEngineIsUsableAgain)
{
client.setLocalRenamingCallback([&] (const QString &symbolName,
const ClangBackEnd::SourceLocationsContainer &sourceLocations,
int textDocumentRevision) {
callbackMock.localRenaming(symbolName,
sourceLocations,
textDocumentRevision);
});
EXPECT_CALL(callbackMock, localRenaming(_,_,_));
client.setLocalRenamingCallback(mockLocalRenaming.AsStdFunction());
EXPECT_CALL(mockLocalRenaming, Call(_,_,_));
client.sourceLocationsForRenamingMessage(std::move(renameMessage));