aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2017-12-13 17:35:00 +0100
committerMarco Bubke <marco.bubke@qt.io>2018-01-10 12:37:37 +0000
commit98fa7cbb3f0269032ff68b172c7de82a46178875 (patch)
tree5fd5b02376511151061b353ba4f0cea85bc7f699 /tests
parentbb07cc280cf23fe2a05ee3b43c61e7aec7f03af4 (diff)
Clang: Use FilePathId in ChangedFilePathCompressor
Change-Id: I622d9196ec12c6fe6e07ef9c953586f2f40b9a5c Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/unittest/changedfilepathcompressor-test.cpp53
-rw-r--r--tests/unit/unittest/clangpathwatcher-test.cpp4
-rw-r--r--tests/unit/unittest/google-using-declarations.h2
-rw-r--r--tests/unit/unittest/mockchangedfilepathcompressor.h43
-rw-r--r--tests/unit/unittest/mocktimer.cpp (renamed from tests/unit/unittest/faketimer.cpp)14
-rw-r--r--tests/unit/unittest/mocktimer.h (renamed from tests/unit/unittest/faketimer.h)11
-rw-r--r--tests/unit/unittest/unittest.pro9
7 files changed, 56 insertions, 80 deletions
diff --git a/tests/unit/unittest/changedfilepathcompressor-test.cpp b/tests/unit/unittest/changedfilepathcompressor-test.cpp
index d65eac708c..ab31136842 100644
--- a/tests/unit/unittest/changedfilepathcompressor-test.cpp
+++ b/tests/unit/unittest/changedfilepathcompressor-test.cpp
@@ -25,7 +25,11 @@
#include "googletest.h"
-#include <mockchangedfilepathcompressor.h>
+#include "mocktimer.h"
+
+#include <changedfilepathcompressor.h>
+#include <filepathcaching.h>
+#include <refactoringdatabaseinitializer.h>
namespace {
@@ -35,56 +39,65 @@ using testing::IsEmpty;
using testing::NiceMock;
using ClangBackEnd::FilePath;
-
+using ClangBackEnd::FilePathId;
class ChangedFilePathCompressor : public testing::Test
{
protected:
- void SetUp();
+ void SetUp()
+ {
+ compressor.setCallback(mockCompressor.AsStdFunction());
+ }
+
+ FilePathId filePathId(const QString &filePath)
+ {
+ Utils::SmallString utf8FilePath{filePath};
+
+ return filePathCache.filePathId(ClangBackEnd::FilePathView{utf8FilePath});
+ }
protected:
- NiceMock<MockChangedFilePathCompressor> mockCompressor;
- ClangBackEnd::ChangedFilePathCompressor<FakeTimer> compressor;
+ Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
+ ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
+ ClangBackEnd::FilePathCaching filePathCache{database};
+ NiceMock<MockFunction<void (const ClangBackEnd::FilePathIds &filePathIds)>> mockCompressor;
+ ClangBackEnd::ChangedFilePathCompressor<NiceMock<MockTimer>> compressor{filePathCache};
+ NiceMock<MockTimer> &mockTimer = compressor.timer();
QString filePath1{"filePath1"};
QString filePath2{"filePath2"};
};
TEST_F(ChangedFilePathCompressor, AddFilePath)
{
- mockCompressor.addFilePath(filePath1);
+ compressor.addFilePath(filePath1);
- ASSERT_THAT(mockCompressor.takeFilePaths(), ElementsAre(FilePath{filePath1}));
+ ASSERT_THAT(compressor.takeFilePathIds(), ElementsAre(filePathId(filePath1)));
}
TEST_F(ChangedFilePathCompressor, NoFilePathsAferTakenThem)
{
- mockCompressor.addFilePath(filePath1);
+ compressor.addFilePath(filePath1);
- mockCompressor.takeFilePaths();
+ compressor.takeFilePathIds();
- ASSERT_THAT(mockCompressor.takeFilePaths(), IsEmpty());
+ ASSERT_THAT(compressor.takeFilePathIds(), IsEmpty());
}
TEST_F(ChangedFilePathCompressor, CallRestartTimerAfterAddingPath)
{
- EXPECT_CALL(mockCompressor, restartTimer());
+ EXPECT_CALL(mockTimer, start(20));
- mockCompressor.addFilePath(filePath1);
+ compressor.addFilePath(filePath1);
}
TEST_F(ChangedFilePathCompressor, CallTimeOutAfterAddingPath)
{
- EXPECT_CALL(mockCompressor, callbackCalled(ElementsAre(FilePath{filePath1}, FilePath{filePath2})));
+ auto id1 = filePathId(filePath1);
+ auto id2 = filePathId(filePath2);
+ EXPECT_CALL(mockCompressor, Call(ElementsAre(id1, id2)));
compressor.addFilePath(filePath1);
compressor.addFilePath(filePath2);
}
-void ChangedFilePathCompressor::SetUp()
-{
- compressor.setCallback([&] (ClangBackEnd::FilePaths &&filePaths) {
- mockCompressor.callbackCalled(filePaths);
- });
-}
-
}
diff --git a/tests/unit/unittest/clangpathwatcher-test.cpp b/tests/unit/unittest/clangpathwatcher-test.cpp
index f1a85f5f4b..cb3a7a609a 100644
--- a/tests/unit/unittest/clangpathwatcher-test.cpp
+++ b/tests/unit/unittest/clangpathwatcher-test.cpp
@@ -25,7 +25,7 @@
#include "googletest.h"
-#include "faketimer.h"
+#include "mocktimer.h"
#include "mockfilepathcaching.h"
#include "mockqfilesystemwatcher.h"
#include "mockclangpathwatchernotifier.h"
@@ -42,7 +42,7 @@ using testing::IsEmpty;
using testing::SizeIs;
using testing::NiceMock;
-using Watcher = ClangBackEnd::ClangPathWatcher<NiceMock<MockQFileSytemWatcher>, FakeTimer>;
+using Watcher = ClangBackEnd::ClangPathWatcher<NiceMock<MockQFileSytemWatcher>, NiceMock<MockTimer>>;
using ClangBackEnd::WatcherEntry;
using ClangBackEnd::FilePath;
using ClangBackEnd::FilePathView;
diff --git a/tests/unit/unittest/google-using-declarations.h b/tests/unit/unittest/google-using-declarations.h
index 73994bd2bc..4627e04427 100644
--- a/tests/unit/unittest/google-using-declarations.h
+++ b/tests/unit/unittest/google-using-declarations.h
@@ -31,6 +31,7 @@ using testing::_;
using testing::AllOf;
using testing::AnyNumber;
using testing::AnyOf;
+using testing::Assign;
using testing::Contains;
using testing::ElementsAre;
using testing::Field;
@@ -38,6 +39,7 @@ using testing::HasSubstr;
using testing::InSequence;
using testing::IsEmpty;
using testing::Mock;
+using testing::MockFunction;
using testing::NiceMock;
using testing::Not;
using testing::Pair;
diff --git a/tests/unit/unittest/mockchangedfilepathcompressor.h b/tests/unit/unittest/mockchangedfilepathcompressor.h
deleted file mode 100644
index f1b556ba2e..0000000000
--- a/tests/unit/unittest/mockchangedfilepathcompressor.h
+++ /dev/null
@@ -1,43 +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 "faketimer.h"
-
-#include <changedfilepathcompressor.h>
-
-class MockChangedFilePathCompressor : public ClangBackEnd::ChangedFilePathCompressor<FakeTimer>
-{
-public:
- MOCK_METHOD0(restartTimer,
- void ());
-
- MOCK_METHOD1(callbackCalled,
- void (const ClangBackEnd::FilePaths &filePaths));
-};
-
diff --git a/tests/unit/unittest/faketimer.cpp b/tests/unit/unittest/mocktimer.cpp
index 61e2689373..8653f88491 100644
--- a/tests/unit/unittest/faketimer.cpp
+++ b/tests/unit/unittest/mocktimer.cpp
@@ -23,23 +23,23 @@
**
****************************************************************************/
-#include "faketimer.h"
+#include "mocktimer.h"
-FakeTimer::~FakeTimer()
+MockTimer::MockTimer()
{
- emitTimoutIfStarted();
+ ON_CALL(*this, start(_)).WillByDefault(Assign(&m_isStarted, true));
}
-void FakeTimer::start(int)
+MockTimer::~MockTimer()
{
- m_isStarted = true;
+ emitTimoutIfStarted();
}
-void FakeTimer::setSingleShot(bool)
+void MockTimer::setSingleShot(bool)
{
}
-void FakeTimer::emitTimoutIfStarted()
+void MockTimer::emitTimoutIfStarted()
{
if (m_isStarted)
emit timeout();
diff --git a/tests/unit/unittest/faketimer.h b/tests/unit/unittest/mocktimer.h
index ef6945205c..aaf389764f 100644
--- a/tests/unit/unittest/faketimer.h
+++ b/tests/unit/unittest/mocktimer.h
@@ -24,16 +24,21 @@
****************************************************************************/
#pragma once
+#include "googletest.h"
+
#include <QObject>
-class FakeTimer : public QObject
+class MockTimer : public QObject
{
Q_OBJECT
public:
- ~FakeTimer();
+ MockTimer();
+ ~MockTimer();
+
+ MOCK_METHOD1(start,
+ void (int));
- void start(int interval);
void setSingleShot(bool);
void emitTimoutIfStarted();
diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro
index 41f5a6113c..a16a13e88b 100644
--- a/tests/unit/unittest/unittest.pro
+++ b/tests/unit/unittest/unittest.pro
@@ -48,7 +48,6 @@ SOURCES += \
cppprojectinfogenerator-test.cpp \
cppprojectpartchooser-test.cpp \
fakeprocess.cpp \
- faketimer.cpp \
filepath-test.cpp \
filepathview-test.cpp \
gtest-creator-printing.cpp \
@@ -85,7 +84,8 @@ SOURCES += \
filepathstoragesqlitestatementfactory-test.cpp \
processcreator-test.cpp \
nativefilepath-test.cpp \
- nativefilepathview-test.cpp
+ nativefilepathview-test.cpp \
+ mocktimer.cpp
!isEmpty(LIBCLANG_LIBS) {
SOURCES += \
@@ -180,13 +180,11 @@ HEADERS += \
dynamicastmatcherdiagnosticcontainer-matcher.h \
eventspy.h \
fakeprocess.h \
- faketimer.h \
filesystem-utilities.h \
googletest.h \
gtest-creator-printing.h \
gtest-qt-printing.h \
mimedatabase-utilities.h \
- mockchangedfilepathcompressor.h \
mockclangcodemodelclient.h \
mockclangcodemodelserver.h \
mockclangpathwatcher.h \
@@ -221,7 +219,8 @@ HEADERS += \
unittest-utility-functions.h \
mocksymbolquery.h \
runprojectcreateorupdate-utility.h \
- rundocumentparse-utility.h
+ rundocumentparse-utility.h \
+ mocktimer.h
!isEmpty(LIBCLANG_LIBS) {
HEADERS += \
chunksreportedmonitor.h \