2015-10-01 12:45:06 +02:00
|
|
|
/****************************************************************************
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://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 Digia. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2015-11-06 11:16:53 +01:00
|
|
|
#include <commandlinearguments.h>
|
2015-08-26 16:33:32 +02:00
|
|
|
#include <diagnosticset.h>
|
2015-11-18 17:07:44 +01:00
|
|
|
#include <highlightinginformations.h>
|
2015-06-01 18:51:55 +02:00
|
|
|
#include <filecontainer.h>
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <projectpart.h>
|
2015-12-07 13:37:02 +01:00
|
|
|
#include <projectpartcontainer.h>
|
2015-06-01 18:51:55 +02:00
|
|
|
#include <projects.h>
|
|
|
|
|
#include <translationunitdoesnotexistexception.h>
|
|
|
|
|
#include <translationunitfilenotexitexception.h>
|
2015-11-24 11:17:18 +01:00
|
|
|
#include <clangtranslationunit.h>
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <translationunitisnullexception.h>
|
2015-06-01 18:51:55 +02:00
|
|
|
#include <translationunitparseerrorexception.h>
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <translationunits.h>
|
|
|
|
|
#include <unsavedfiles.h>
|
|
|
|
|
#include <utf8string.h>
|
|
|
|
|
|
|
|
|
|
#include <clang-c/Index.h>
|
|
|
|
|
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
#include <gmock/gmock-matchers.h>
|
|
|
|
|
#include <gtest/gtest.h>
|
2015-07-01 14:50:35 +02:00
|
|
|
#include "gtest-qt-printing.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-10-12 17:36:18 +02:00
|
|
|
#include <QTemporaryFile>
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
#include <chrono>
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
2015-12-07 13:37:02 +01:00
|
|
|
using ClangBackEnd::FileContainer;
|
2015-06-16 11:56:00 +02:00
|
|
|
using ClangBackEnd::TranslationUnit;
|
|
|
|
|
using ClangBackEnd::UnsavedFiles;
|
|
|
|
|
using ClangBackEnd::ProjectPart;
|
2015-12-07 13:37:02 +01:00
|
|
|
using ClangBackEnd::ProjectPartContainer;
|
2015-08-31 12:40:14 +02:00
|
|
|
using ClangBackEnd::TranslationUnits;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
using testing::IsNull;
|
|
|
|
|
using testing::NotNull;
|
2015-11-06 11:16:53 +01:00
|
|
|
using testing::Eq;
|
2015-06-01 18:51:55 +02:00
|
|
|
using testing::Gt;
|
2015-08-31 12:40:14 +02:00
|
|
|
using testing::Contains;
|
|
|
|
|
using testing::EndsWith;
|
|
|
|
|
using testing::AllOf;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
class TranslationUnit : public ::testing::Test
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-10-12 17:36:18 +02:00
|
|
|
protected:
|
2015-12-07 13:37:02 +01:00
|
|
|
void SetUp() override;
|
2015-10-12 17:36:18 +02:00
|
|
|
::TranslationUnit createTemporaryTranslationUnit();
|
|
|
|
|
QByteArray readContentFromTranslationUnitFile() const;
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
protected:
|
|
|
|
|
ClangBackEnd::ProjectParts projects;
|
2015-12-07 13:37:02 +01:00
|
|
|
Utf8String projectPartId{Utf8StringLiteral("/path/to/projectfile")};
|
|
|
|
|
ProjectPart projectPart;
|
2015-10-12 17:36:18 +02:00
|
|
|
Utf8String translationUnitFilePath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp");
|
2015-08-31 12:40:14 +02:00
|
|
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
|
|
|
|
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
|
2015-12-07 13:37:02 +01:00
|
|
|
::TranslationUnit translationUnit;
|
2015-08-31 12:40:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(TranslationUnit, DefaultTranslationUnitIsInvalid)
|
|
|
|
|
{
|
|
|
|
|
::TranslationUnit translationUnit;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(translationUnit.isNull());
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, ThrowExceptionForNonExistingFilePath)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-11-05 13:57:57 +01:00
|
|
|
ASSERT_THROW(::TranslationUnit(Utf8StringLiteral("file.cpp"), projectPart, Utf8StringVector(), translationUnits),
|
2015-06-16 11:56:00 +02:00
|
|
|
ClangBackEnd::TranslationUnitFileNotExitsException);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, ThrowNoExceptionForNonExistingFilePathIfDoNotCheckIfFileExistsIsSet)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-11-05 13:57:57 +01:00
|
|
|
ASSERT_NO_THROW(::TranslationUnit(Utf8StringLiteral("file.cpp"), projectPart, Utf8StringVector(), translationUnits, ::TranslationUnit::DoNotCheckIfFileExists));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, TranslationUnitIsValid)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
ASSERT_FALSE(translationUnit.isNull());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, ThrowExceptionForGettingIndexForInvalidUnit)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
::TranslationUnit translationUnit;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
ASSERT_THROW(translationUnit.index(), ClangBackEnd::TranslationUnitIsNullException);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, IndexGetterIsNonNullForValidUnit)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
ASSERT_THAT(translationUnit.index(), NotNull());
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, ThrowExceptionForGettingCxTranslationUnitForInvalidUnit)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
::TranslationUnit translationUnit;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
ASSERT_THROW(translationUnit.cxTranslationUnit(), ClangBackEnd::TranslationUnitIsNullException);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, CxTranslationUnitGetterIsNonNullForValidUnit)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
ASSERT_THAT(translationUnit.cxTranslationUnit(), NotNull());
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, ThrowExceptionIfGettingFilePathForNullUnit)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
::TranslationUnit translationUnit;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
ASSERT_THROW(translationUnit.filePath(), ClangBackEnd::TranslationUnitIsNullException);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, ResetedTranslationUnitIsNull)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
translationUnit.reset();
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(translationUnit.isNull());
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 11:16:53 +01:00
|
|
|
TEST_F(TranslationUnit, LastCommandLineArgumentIsFilePath)
|
|
|
|
|
{
|
|
|
|
|
const auto arguments = translationUnit.commandLineArguments();
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(arguments.at(arguments.count() - 1), Eq(translationUnitFilePath));
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslationUnitIsGenerated)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
|
2015-06-01 18:51:55 +02:00
|
|
|
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
|
|
|
|
|
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
ASSERT_THAT(translationUnit.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 12:40:14 +02:00
|
|
|
TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsProjectPartIsCleared)
|
|
|
|
|
{
|
|
|
|
|
ProjectPart projectPart = translationUnit.projectPart();
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::steady_clock::duration(1));
|
|
|
|
|
|
|
|
|
|
projectPart.clear();
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(translationUnit.lastProjectPartChangeTimePoint(), Gt(lastChangeTimePoint));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TranslationUnit, DocumentRevisionInFileContainerGetter)
|
|
|
|
|
{
|
|
|
|
|
translationUnit.setDocumentRevision(74);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(translationUnit.fileContainer().documentRevision(), 74);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TranslationUnit, DependedFilePaths)
|
|
|
|
|
{
|
|
|
|
|
ASSERT_THAT(translationUnit.dependedFilePaths(),
|
2015-10-12 17:36:18 +02:00
|
|
|
AllOf(Contains(translationUnitFilePath),
|
2015-08-31 12:40:14 +02:00
|
|
|
Contains(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"))));
|
|
|
|
|
}
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
TEST_F(TranslationUnit, DeletedFileShouldNotNeedReparsing)
|
2015-11-23 13:31:46 +01:00
|
|
|
{
|
2015-11-18 17:07:44 +01:00
|
|
|
auto translationUnit = createTemporaryTranslationUnit();
|
|
|
|
|
|
|
|
|
|
translationUnit.setDirtyIfDependencyIsMet(translationUnit.filePath());
|
2015-11-23 13:31:46 +01:00
|
|
|
|
|
|
|
|
ASSERT_FALSE(translationUnit.isNeedingReparse());
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
TEST_F(TranslationUnit, NeedsNoReparseAfterCreation)
|
2015-11-23 13:31:46 +01:00
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
ASSERT_FALSE(translationUnit.isNeedingReparse());
|
2015-11-23 13:31:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TranslationUnit, NeedsReparseAfterChangeOfMainFile)
|
|
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
|
|
|
|
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(translationUnit.isNeedingReparse());
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 15:37:48 +02:00
|
|
|
TEST_F(TranslationUnit, NoNeedForReparsingForIndependendFile)
|
|
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
2015-08-26 16:33:32 +02:00
|
|
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
|
2015-08-26 15:37:48 +02:00
|
|
|
|
|
|
|
|
ASSERT_FALSE(translationUnit.isNeedingReparse());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TranslationUnit, NeedsReparsingForDependendFile)
|
|
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
2015-08-26 16:33:32 +02:00
|
|
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
2015-08-26 15:37:48 +02:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(translationUnit.isNeedingReparse());
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
TEST_F(TranslationUnit, NeedsNoReparsingAfterReparsing)
|
2015-08-26 15:37:48 +02:00
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
2015-11-18 17:07:44 +01:00
|
|
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
2015-08-26 15:37:48 +02:00
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
translationUnit.cxTranslationUnit();
|
2015-08-26 15:37:48 +02:00
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
ASSERT_FALSE(translationUnit.isNeedingReparse());
|
2015-08-26 15:37:48 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
TEST_F(TranslationUnit, HasNewDiagnosticsAfterCreation)
|
2015-08-26 15:37:48 +02:00
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
ASSERT_TRUE(translationUnit.hasNewDiagnostics());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TranslationUnit, HasNewDiagnosticsAfterChangeOfMainFile)
|
|
|
|
|
{
|
2015-08-26 15:37:48 +02:00
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(translationUnit.hasNewDiagnostics());
|
2015-08-26 15:37:48 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-26 16:33:32 +02:00
|
|
|
TEST_F(TranslationUnit, HasNoNewDiagnosticsForIndependendFile)
|
|
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
2015-11-23 13:31:46 +01:00
|
|
|
translationUnit.diagnostics(); // Reset hasNewDiagnostics
|
2015-08-26 16:33:32 +02:00
|
|
|
|
|
|
|
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
|
|
|
|
|
|
|
|
|
|
ASSERT_FALSE(translationUnit.hasNewDiagnostics());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TranslationUnit, HasNewDiagnosticsForDependendFile)
|
|
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
|
|
|
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(translationUnit.hasNewDiagnostics());
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
TEST_F(TranslationUnit, HasNoNewDiagnosticsAfterGettingDiagnostics)
|
2015-08-26 16:33:32 +02:00
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
2015-10-12 17:36:18 +02:00
|
|
|
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
2015-08-26 16:33:32 +02:00
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
translationUnit.diagnostics(); // Reset hasNewDiagnostics
|
|
|
|
|
|
|
|
|
|
ASSERT_FALSE(translationUnit.hasNewDiagnostics());
|
2015-08-26 16:33:32 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
TEST_F(TranslationUnit, HasNewHighlightingInformationsAfterCreation)
|
2015-08-26 16:33:32 +02:00
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
2015-11-18 17:07:44 +01:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(translationUnit.hasNewHighlightingInformations());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TranslationUnit, HasNewHighlightingInformationsForMainFile)
|
|
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
2015-10-12 17:36:18 +02:00
|
|
|
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
2015-08-26 16:33:32 +02:00
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
ASSERT_TRUE(translationUnit.hasNewHighlightingInformations());
|
|
|
|
|
}
|
2015-08-26 16:33:32 +02:00
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
TEST_F(TranslationUnit, HasNoNewHighlightingInformationsForIndependendFile)
|
|
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
translationUnit.highlightingInformations();
|
|
|
|
|
|
|
|
|
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/otherfiles.h"));
|
|
|
|
|
|
|
|
|
|
ASSERT_FALSE(translationUnit.hasNewHighlightingInformations());
|
2015-08-26 16:33:32 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
TEST_F(TranslationUnit, HasNewHighlightingInformationsForDependendFile)
|
2015-10-12 17:36:18 +02:00
|
|
|
{
|
2015-11-18 17:07:44 +01:00
|
|
|
translationUnit.cxTranslationUnit();
|
2015-10-12 17:36:18 +02:00
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
translationUnit.setDirtyIfDependencyIsMet(Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"));
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-11-18 17:07:44 +01:00
|
|
|
ASSERT_TRUE(translationUnit.hasNewHighlightingInformations());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TranslationUnit, HasNoNewHighlightingInformationsAfterGettingHighlightingInformations)
|
|
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
translationUnit.setDirtyIfDependencyIsMet(translationUnitFilePath);
|
|
|
|
|
|
|
|
|
|
translationUnit.highlightingInformations();
|
|
|
|
|
|
|
|
|
|
ASSERT_FALSE(translationUnit.hasNewHighlightingInformations());
|
2015-10-12 17:36:18 +02:00
|
|
|
}
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-12-07 13:37:02 +01:00
|
|
|
TEST_F(TranslationUnit, SetDirtyIfProjectPartIsOutdated)
|
|
|
|
|
{
|
|
|
|
|
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
projects.createOrUpdate({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DNEW")})});
|
|
|
|
|
|
|
|
|
|
translationUnit.setDirtyIfProjectPartIsOutdated();
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(translationUnit.isNeedingReparse());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TranslationUnit, SetNotDirtyIfProjectPartIsNotOutdated)
|
|
|
|
|
{
|
|
|
|
|
translationUnit.cxTranslationUnit();
|
|
|
|
|
|
|
|
|
|
translationUnit.setDirtyIfProjectPartIsOutdated();
|
|
|
|
|
|
|
|
|
|
ASSERT_FALSE(translationUnit.isNeedingReparse());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TranslationUnit::SetUp()
|
|
|
|
|
{
|
|
|
|
|
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
|
|
|
|
|
projectPart = *projects.findProjectPart(projectPartId);
|
|
|
|
|
|
|
|
|
|
const QVector<FileContainer> fileContainer{FileContainer(translationUnitFilePath, projectPartId)};
|
|
|
|
|
const auto createdTranslationUnits = translationUnits.create(fileContainer);
|
|
|
|
|
translationUnit = createdTranslationUnits.front();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 17:36:18 +02:00
|
|
|
::TranslationUnit TranslationUnit::createTemporaryTranslationUnit()
|
|
|
|
|
{
|
|
|
|
|
QTemporaryFile temporaryFile;
|
|
|
|
|
EXPECT_TRUE(temporaryFile.open());
|
|
|
|
|
EXPECT_TRUE(temporaryFile.write(readContentFromTranslationUnitFile()));
|
|
|
|
|
::TranslationUnit translationUnit(temporaryFile.fileName(),
|
|
|
|
|
projectPart,
|
2015-11-05 13:57:57 +01:00
|
|
|
Utf8StringVector(),
|
2015-10-12 17:36:18 +02:00
|
|
|
translationUnits);
|
|
|
|
|
|
2015-12-07 13:37:02 +01:00
|
|
|
return translationUnit;
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
2015-10-12 17:36:18 +02:00
|
|
|
|
|
|
|
|
QByteArray TranslationUnit::readContentFromTranslationUnitFile() const
|
|
|
|
|
{
|
|
|
|
|
QFile contentFile(translationUnitFilePath);
|
|
|
|
|
EXPECT_TRUE(contentFile.open(QIODevice::ReadOnly));
|
|
|
|
|
|
|
|
|
|
return contentFile.readAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|