2015-11-18 17:07:44 +01:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 14:55:33 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-11-18 17:07:44 +01:00
|
|
|
**
|
|
|
|
** 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
|
2016-01-15 14:55:33 +01:00
|
|
|
** 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.
|
2015-11-18 17:07:44 +01:00
|
|
|
**
|
2016-01-15 14:55:33 +01:00
|
|
|
** 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.
|
2015-11-18 17:07:44 +01:00
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-09-15 17:41:41 +02:00
|
|
|
#include "googletest.h"
|
2019-04-24 14:07:39 +02:00
|
|
|
#include "unittest-utility-functions.h"
|
2016-09-15 17:41:41 +02:00
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
#include <chunksreportedmonitor.h>
|
2016-09-07 10:42:12 +02:00
|
|
|
#include <clangdocument.h>
|
|
|
|
#include <clangdocuments.h>
|
2016-05-31 16:07:09 +02:00
|
|
|
#include <cursor.h>
|
2017-12-05 09:42:35 +01:00
|
|
|
#include <tokeninfocontainer.h>
|
2018-02-06 15:48:24 +01:00
|
|
|
#include <tokenprocessor.h>
|
|
|
|
#include <clanghighlightingresultreporter.h>
|
2015-11-18 17:07:44 +01:00
|
|
|
#include <unsavedfiles.h>
|
|
|
|
|
|
|
|
using ClangBackEnd::Cursor;
|
2018-02-06 15:48:24 +01:00
|
|
|
using ClangBackEnd::TokenProcessor;
|
2017-12-05 09:42:35 +01:00
|
|
|
using ClangBackEnd::TokenInfoContainer;
|
2015-11-18 17:07:44 +01:00
|
|
|
using ClangBackEnd::HighlightingType;
|
2016-09-07 10:42:12 +02:00
|
|
|
using ClangBackEnd::Document;
|
|
|
|
using ClangBackEnd::Documents;
|
2015-11-18 17:07:44 +01:00
|
|
|
using ClangBackEnd::UnsavedFiles;
|
|
|
|
using ClangBackEnd::ChunksReportedMonitor;
|
2019-02-06 16:17:03 +01:00
|
|
|
using ClangCodeModel::Internal::HighlightingResultReporter;
|
2015-11-18 17:07:44 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct Data {
|
|
|
|
UnsavedFiles unsavedFiles;
|
2018-09-25 09:41:32 +02:00
|
|
|
Documents documents{unsavedFiles};
|
|
|
|
Document document{Utf8StringLiteral(TESTDATA_DIR "/highlightingmarks.cpp"),
|
2019-04-24 14:07:39 +02:00
|
|
|
UnitTest::addPlatformArguments({Utf8StringLiteral("-std=c++14")}),
|
2018-10-19 10:20:27 +02:00
|
|
|
Utf8StringVector(),
|
2016-09-07 10:42:12 +02:00
|
|
|
documents};
|
2015-11-18 17:07:44 +01:00
|
|
|
};
|
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
class HighlightingResultReporter : public ::testing::Test
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void SetUpTestCase();
|
|
|
|
static void TearDownTestCase();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static Data *d;
|
|
|
|
};
|
|
|
|
|
2017-12-05 09:42:35 +01:00
|
|
|
QVector<TokenInfoContainer> noTokenInfos()
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2017-12-05 09:42:35 +01:00
|
|
|
return QVector<TokenInfoContainer>();
|
2015-11-18 17:07:44 +01:00
|
|
|
}
|
|
|
|
|
2017-12-05 09:42:35 +01:00
|
|
|
QVector<TokenInfoContainer> generateTokenInfos(uint count)
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2017-12-05 09:42:35 +01:00
|
|
|
auto container = QVector<TokenInfoContainer>();
|
2015-11-18 17:07:44 +01:00
|
|
|
|
|
|
|
for (uint i = 0; i < count; ++i) {
|
|
|
|
const uint line = i + 1;
|
2018-02-23 12:28:30 +01:00
|
|
|
ClangBackEnd::HighlightingTypes types;
|
|
|
|
types.mainHighlightingType = ClangBackEnd::HighlightingType::Type;
|
|
|
|
container.append(TokenInfoContainer(line, 1, 1, types));
|
2015-11-18 17:07:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
TEST_F(HighlightingResultReporter, StartAndFinish)
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2019-02-06 16:17:03 +01:00
|
|
|
auto reporter = new ::HighlightingResultReporter(noTokenInfos());
|
2015-11-18 17:07:44 +01:00
|
|
|
|
|
|
|
auto future = reporter->start();
|
|
|
|
|
|
|
|
future.waitForFinished();
|
|
|
|
ASSERT_THAT(future.isFinished(), true);
|
|
|
|
}
|
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
TEST_F(HighlightingResultReporter, ReportNothingIfNothingToReport)
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2019-02-06 16:17:03 +01:00
|
|
|
auto reporter = new ::HighlightingResultReporter(generateTokenInfos(0));
|
2015-11-18 17:07:44 +01:00
|
|
|
|
|
|
|
auto future = reporter->start();
|
|
|
|
|
|
|
|
ChunksReportedMonitor monitor(future);
|
|
|
|
ASSERT_THAT(monitor.resultsReadyCounter(), 0L);
|
|
|
|
}
|
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
TEST_F(HighlightingResultReporter, ReportSingleResultAsOneChunk)
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2019-02-06 16:17:03 +01:00
|
|
|
auto reporter = new ::HighlightingResultReporter(generateTokenInfos(1));
|
2015-11-18 17:07:44 +01:00
|
|
|
reporter->setChunkSize(1);
|
|
|
|
|
|
|
|
auto future = reporter->start();
|
|
|
|
|
|
|
|
ChunksReportedMonitor monitor(future);
|
|
|
|
ASSERT_THAT(monitor.resultsReadyCounter(), 1L);
|
|
|
|
}
|
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
TEST_F(HighlightingResultReporter, ReportRestIfChunkSizeNotReached)
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2019-02-06 16:17:03 +01:00
|
|
|
auto reporter = new ::HighlightingResultReporter(generateTokenInfos(1));
|
2015-11-18 17:07:44 +01:00
|
|
|
const int notReachedChunkSize = 100;
|
|
|
|
reporter->setChunkSize(notReachedChunkSize);
|
|
|
|
|
|
|
|
auto future = reporter->start();
|
|
|
|
|
|
|
|
ChunksReportedMonitor monitor(future);
|
|
|
|
ASSERT_THAT(monitor.resultsReadyCounter(), 1L);
|
|
|
|
}
|
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
TEST_F(HighlightingResultReporter, ReportChunksWithoutRest)
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2019-02-06 16:17:03 +01:00
|
|
|
auto reporter = new ::HighlightingResultReporter(generateTokenInfos(4));
|
2015-11-18 17:07:44 +01:00
|
|
|
reporter->setChunkSize(1);
|
|
|
|
|
|
|
|
auto future = reporter->start();
|
|
|
|
|
|
|
|
ChunksReportedMonitor monitor(future);
|
|
|
|
ASSERT_THAT(monitor.resultsReadyCounter(), 2L);
|
|
|
|
}
|
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
TEST_F(HighlightingResultReporter, ReportSingleChunkAndRest)
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2019-02-06 16:17:03 +01:00
|
|
|
auto reporter = new ::HighlightingResultReporter(generateTokenInfos(5));
|
2015-11-18 17:07:44 +01:00
|
|
|
reporter->setChunkSize(2);
|
|
|
|
|
|
|
|
auto future = reporter->start();
|
|
|
|
|
|
|
|
ChunksReportedMonitor monitor(future);
|
|
|
|
ASSERT_THAT(monitor.resultsReadyCounter(), 2L);
|
|
|
|
}
|
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
TEST_F(HighlightingResultReporter, ReportCompleteLines)
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
2018-02-23 12:28:30 +01:00
|
|
|
ClangBackEnd::HighlightingTypes types;
|
|
|
|
types.mainHighlightingType = ClangBackEnd::HighlightingType::Type;
|
2017-12-05 09:42:35 +01:00
|
|
|
QVector<TokenInfoContainer> tokenInfos {
|
2018-02-23 12:28:30 +01:00
|
|
|
TokenInfoContainer(1, 1, 1, types),
|
|
|
|
TokenInfoContainer(1, 2, 1, types),
|
|
|
|
TokenInfoContainer(2, 1, 1, types),
|
2015-11-18 17:07:44 +01:00
|
|
|
};
|
2019-02-06 16:17:03 +01:00
|
|
|
auto reporter = new ::HighlightingResultReporter(tokenInfos);
|
2015-11-18 17:07:44 +01:00
|
|
|
reporter->setChunkSize(1);
|
|
|
|
|
|
|
|
auto future = reporter->start();
|
|
|
|
|
|
|
|
ChunksReportedMonitor monitor(future);
|
|
|
|
ASSERT_THAT(monitor.resultsReadyCounter(), 2L);
|
|
|
|
}
|
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
Data *HighlightingResultReporter::d;
|
2015-11-18 17:07:44 +01:00
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
void HighlightingResultReporter::SetUpTestCase()
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
|
|
|
d = new Data;
|
|
|
|
}
|
|
|
|
|
2018-02-06 15:48:24 +01:00
|
|
|
void HighlightingResultReporter::TearDownTestCase()
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
d = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous
|