summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2018-08-27 15:54:08 +0200
committerMarco Bubke <marco.bubke@qt.io>2018-09-03 09:40:03 +0000
commit2f41886c4bffa000bc5d661d7e9c6baa3b0c44ae (patch)
tree643a8f85babb69a2e57f48b124a83a86accb97a9 /tests
parentc81070aa7d233eaf34982fbde0e847c4fdfe33c8 (diff)
downloadqt-creator-2f41886c4bffa000bc5d661d7e9c6baa3b0c44ae.tar.gz
ClangRefactoring: Process tasks after a task has been finished
It could be that processTasks is executed before the future is finished but in that case there are other tasks which will be called later. Change-Id: I9b1bfb6fdd642f23842b9c70d60d5b1552193b99 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/unittest/mocksymbolindexertaskqueue.h36
-rw-r--r--tests/unit/unittest/symbolindexertaskscheduler-test.cpp20
-rw-r--r--tests/unit/unittest/unittest.pro3
3 files changed, 56 insertions, 3 deletions
diff --git a/tests/unit/unittest/mocksymbolindexertaskqueue.h b/tests/unit/unittest/mocksymbolindexertaskqueue.h
new file mode 100644
index 0000000000..1eca733ade
--- /dev/null
+++ b/tests/unit/unittest/mocksymbolindexertaskqueue.h
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 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 <symbolindexertaskqueueinterface.h>
+
+class MockSymbolIndexerTaskQueue : public ClangBackEnd::SymbolIndexerTaskQueueInterface
+{
+public:
+ MOCK_METHOD0(processTasks, void());
+};
diff --git a/tests/unit/unittest/symbolindexertaskscheduler-test.cpp b/tests/unit/unittest/symbolindexertaskscheduler-test.cpp
index f7d4be201a..d4dff54a38 100644
--- a/tests/unit/unittest/symbolindexertaskscheduler-test.cpp
+++ b/tests/unit/unittest/symbolindexertaskscheduler-test.cpp
@@ -25,12 +25,15 @@
#include "googletest.h"
+#include "mocksymbolindexertaskqueue.h"
#include "mocksymbolscollectormanager.h"
#include "mocksymbolscollector.h"
#include "mocksymbolstorage.h"
#include <symbolindexertaskscheduler.h>
+#include <QCoreApplication>
+
namespace {
using ClangBackEnd::SymbolsCollectorInterface;
@@ -43,6 +46,11 @@ protected:
{
ON_CALL(mockSymbolsCollectorManager, unusedSymbolsCollector()).WillByDefault(ReturnRef(mockSymbolsCollector));
}
+ void TearDown()
+ {
+ scheduler.syncTasks();
+ QCoreApplication::processEvents();
+ }
protected:
MockFunction<void()> mock;
@@ -56,8 +64,9 @@ protected:
NiceMock<MockSymbolsCollectorManager> mockSymbolsCollectorManager;
NiceMock<MockSymbolsCollector> mockSymbolsCollector;
MockSymbolStorage mockSymbolStorage;
- ClangBackEnd::SymbolIndexerTaskScheduler scheduler{mockSymbolsCollectorManager, mockSymbolStorage, 4};
- ClangBackEnd::SymbolIndexerTaskScheduler deferedScheduler{mockSymbolsCollectorManager, mockSymbolStorage, 4, std::launch::deferred};
+ NiceMock<MockSymbolIndexerTaskQueue> mockSymbolIndexerTaskQueue;
+ ClangBackEnd::SymbolIndexerTaskScheduler scheduler{mockSymbolsCollectorManager, mockSymbolStorage, mockSymbolIndexerTaskQueue, 4};
+ ClangBackEnd::SymbolIndexerTaskScheduler deferedScheduler{mockSymbolsCollectorManager, mockSymbolStorage, mockSymbolIndexerTaskQueue, 4, std::launch::deferred};
};
TEST_F(SymbolIndexerTaskScheduler, AddTasks)
@@ -128,4 +137,11 @@ TEST_F(SymbolIndexerTaskScheduler, AddTaskCallSymbolsCollectorManagerUnusedSymbo
scheduler.addTasks({nocall, nocall});
}
+
+TEST_F(SymbolIndexerTaskScheduler, CallProcessTasksInQueueAfterFinishedTasks)
+{
+ EXPECT_CALL(mockSymbolIndexerTaskQueue, processTasks()).Times(2);
+
+ scheduler.addTasks({nocall, nocall});
+}
}
diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro
index 6dd27b53dd..126113d9a4 100644
--- a/tests/unit/unittest/unittest.pro
+++ b/tests/unit/unittest/unittest.pro
@@ -234,7 +234,8 @@ HEADERS += \
mockprojectpartprovider.h \
mockprecompiledheaderstorage.h \
mockeditormanager.h \
- mocksymbolscollectormanager.h
+ mocksymbolscollectormanager.h \
+ mocksymbolindexertaskqueue.h
!isEmpty(LIBCLANG_LIBS) {
HEADERS += \
chunksreportedmonitor.h \