diff options
author | Marco Bubke <marco.bubke@qt.io> | 2017-12-28 20:21:04 +0100 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2018-01-16 14:00:34 +0000 |
commit | 640575640c9c223a9f13abaf95903ad86f263cdf (patch) | |
tree | 1032380f833e43df5b510c11a06b2b9c425fe9d1 /tests | |
parent | 5d088e9df5b818aee0893bab9467f19b7297597b (diff) |
UnitTests: Use MockFunction instead of home grown mock class
Change-Id: Ic0cd2fb7d073e8cf962d98b850719f4311e9f35a
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/unittest/mockrefactoringclientcallback.h | 39 | ||||
-rw-r--r-- | tests/unit/unittest/refactoringclient-test.cpp | 37 | ||||
-rw-r--r-- | tests/unit/unittest/unittest.pro | 1 |
3 files changed, 10 insertions, 67 deletions
diff --git a/tests/unit/unittest/mockrefactoringclientcallback.h b/tests/unit/unittest/mockrefactoringclientcallback.h deleted file mode 100644 index a3486c366c..0000000000 --- a/tests/unit/unittest/mockrefactoringclientcallback.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#pragma once - -#include "googletest.h" - -#include <sourcelocationscontainer.h> - -class MockRefactoringClientCallBack -{ -public: - MOCK_METHOD3(localRenaming, - void(const QString &, - const ClangBackEnd::SourceLocationsContainer &, - int)); -}; diff --git a/tests/unit/unittest/refactoringclient-test.cpp b/tests/unit/unittest/refactoringclient-test.cpp index c6ed203a55..936b51a94e 100644 --- a/tests/unit/unittest/refactoringclient-test.cpp +++ b/tests/unit/unittest/refactoringclient-test.cpp @@ -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); - }); - - EXPECT_CALL(callbackMock, localRenaming(renameMessage.symbolName().toQString(), - renameMessage.sourceLocations(), - renameMessage.textDocumentRevision())) - .Times(1); + client.setLocalRenamingCallback(mockLocalRenaming.AsStdFunction()); + + 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)); diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index a16a13e88b..3c9642a46a 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -232,7 +232,6 @@ HEADERS += \ !isEmpty(LIBTOOLING_LIBS) { HEADERS += \ gtest-clang-printing.h \ - mockrefactoringclientcallback.h \ mockrefactoringclient.h \ mockrefactoringserver.h \ testclangtool.h \ |