2013-12-16 16:02:45 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-12-16 16:02:45 +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:57:40 +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.
|
2013-12-16 16:02:45 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +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.
|
2013-12-16 16:02:45 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2013-12-16 16:02:45 +01:00
|
|
|
|
|
|
|
|
#include "cpptools_global.h"
|
|
|
|
|
|
2015-03-05 08:22:48 +01:00
|
|
|
#include <cplusplus/CppDocument.h>
|
2017-01-19 16:44:22 +01:00
|
|
|
#include <utils/temporarydirectory.h>
|
2013-12-16 16:02:45 +01:00
|
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
|
|
namespace CPlusPlus {
|
|
|
|
|
class Document;
|
|
|
|
|
class Snapshot;
|
|
|
|
|
}
|
2014-09-19 12:32:43 +02:00
|
|
|
|
2014-02-11 21:55:42 +02:00
|
|
|
namespace Core { class IEditor; }
|
2020-06-16 13:11:10 +02:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
class Kit;
|
|
|
|
|
class Project;
|
|
|
|
|
}
|
2014-09-19 12:32:43 +02:00
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
class BaseTextEditor;
|
|
|
|
|
class IAssistProposal;
|
|
|
|
|
}
|
2013-12-16 16:02:45 +01:00
|
|
|
|
|
|
|
|
namespace CppTools {
|
2015-03-05 08:22:48 +01:00
|
|
|
class CppModelManager;
|
|
|
|
|
class ProjectInfo;
|
|
|
|
|
|
2013-12-16 16:02:45 +01:00
|
|
|
namespace Tests {
|
|
|
|
|
|
|
|
|
|
class CPPTOOLS_EXPORT TestDocument
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker = '@');
|
|
|
|
|
|
2014-12-10 17:03:49 +01:00
|
|
|
QString baseDirectory() const { return m_baseDirectory; }
|
2014-12-09 18:42:15 +01:00
|
|
|
void setBaseDirectory(const QString &baseDirectory) { m_baseDirectory = baseDirectory; }
|
|
|
|
|
|
2013-12-16 16:02:45 +01:00
|
|
|
QString filePath() const;
|
|
|
|
|
bool writeToDisk() const;
|
|
|
|
|
|
|
|
|
|
public:
|
2014-12-09 18:42:15 +01:00
|
|
|
QString m_baseDirectory;
|
2014-05-08 13:21:42 -04:00
|
|
|
QString m_fileName;
|
|
|
|
|
QString m_source;
|
2013-12-16 16:02:45 +01:00
|
|
|
char m_cursorMarker;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CPPTOOLS_EXPORT TestCase
|
|
|
|
|
{
|
|
|
|
|
Q_DISABLE_COPY(TestCase)
|
|
|
|
|
|
|
|
|
|
public:
|
2019-01-14 01:40:53 +01:00
|
|
|
explicit TestCase(bool runGarbageCollector = true);
|
2013-12-16 16:02:45 +01:00
|
|
|
~TestCase();
|
|
|
|
|
|
2013-12-30 19:44:42 +01:00
|
|
|
bool succeededSoFar() const;
|
2014-02-19 11:39:06 -03:00
|
|
|
bool openBaseTextEditor(const QString &fileName, TextEditor::BaseTextEditor **editor);
|
2013-12-16 16:02:45 +01:00
|
|
|
void closeEditorAtEndOfTestCase(Core::IEditor *editor);
|
|
|
|
|
|
2013-12-17 13:54:52 +01:00
|
|
|
static bool closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *editor);
|
|
|
|
|
|
2013-12-16 16:02:45 +01:00
|
|
|
static bool parseFiles(const QString &filePath);
|
2014-09-04 14:59:50 +02:00
|
|
|
static bool parseFiles(const QSet<QString> &filePaths);
|
2013-12-16 16:02:45 +01:00
|
|
|
|
|
|
|
|
static CPlusPlus::Snapshot globalSnapshot();
|
|
|
|
|
static bool garbageCollectGlobalSnapshot();
|
|
|
|
|
|
2015-07-07 15:02:14 +02:00
|
|
|
static bool waitForProcessedEditorDocument(const QString &filePath, int timeOutInMs = 5000);
|
|
|
|
|
|
2015-02-17 15:05:22 +01:00
|
|
|
enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ };
|
2019-11-21 15:09:08 +01:00
|
|
|
static bool waitUntilProjectIsFullyOpened(ProjectExplorer::Project *project,
|
|
|
|
|
int timeOutInMs = defaultTimeOutInMs);
|
2015-02-17 15:05:22 +01:00
|
|
|
static CPlusPlus::Document::Ptr waitForFileInGlobalSnapshot(
|
|
|
|
|
const QString &filePath,
|
|
|
|
|
int timeOutInMs = defaultTimeOutInMs);
|
2013-12-16 16:02:45 +01:00
|
|
|
static QList<CPlusPlus::Document::Ptr> waitForFilesInGlobalSnapshot(
|
2015-02-17 15:05:22 +01:00
|
|
|
const QStringList &filePaths,
|
|
|
|
|
int timeOutInMs = defaultTimeOutInMs);
|
2013-12-16 16:02:45 +01:00
|
|
|
|
|
|
|
|
static bool writeFile(const QString &filePath, const QByteArray &contents);
|
|
|
|
|
|
|
|
|
|
protected:
|
2014-09-15 00:12:27 +02:00
|
|
|
CppModelManager *m_modelManager;
|
2013-12-30 19:44:42 +01:00
|
|
|
bool m_succeededSoFar;
|
2013-12-16 16:02:45 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QList<Core::IEditor *> m_editorsToClose;
|
|
|
|
|
bool m_runGarbageCollector;
|
|
|
|
|
};
|
|
|
|
|
|
2015-04-13 17:41:17 +02:00
|
|
|
class CPPTOOLS_EXPORT ProjectOpenerAndCloser
|
2014-12-09 13:01:44 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2015-04-13 17:41:17 +02:00
|
|
|
ProjectOpenerAndCloser();
|
2014-12-09 13:01:44 +01:00
|
|
|
~ProjectOpenerAndCloser(); // Closes opened projects
|
|
|
|
|
|
2020-06-16 13:11:10 +02:00
|
|
|
ProjectInfo open(const QString &projectFile, bool configureAsExampleProject = false,
|
|
|
|
|
ProjectExplorer::Kit *kit = nullptr);
|
2014-12-09 13:01:44 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QList<ProjectExplorer::Project *> m_openProjects;
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-10 17:03:49 +01:00
|
|
|
class CPPTOOLS_EXPORT TemporaryDir
|
2014-12-09 13:01:44 +01:00
|
|
|
{
|
2014-12-09 18:42:15 +01:00
|
|
|
Q_DISABLE_COPY(TemporaryDir)
|
|
|
|
|
|
2014-12-09 13:01:44 +01:00
|
|
|
public:
|
2014-12-09 18:42:15 +01:00
|
|
|
TemporaryDir();
|
2014-12-09 13:01:44 +01:00
|
|
|
|
|
|
|
|
bool isValid() const { return m_isValid; }
|
|
|
|
|
QString path() const { return m_temporaryDir.path(); }
|
|
|
|
|
|
2014-12-09 18:42:15 +01:00
|
|
|
QString createFile(const QByteArray &relativePath, const QByteArray &contents);
|
|
|
|
|
|
|
|
|
|
protected:
|
2017-01-19 16:44:22 +01:00
|
|
|
Utils::TemporaryDirectory m_temporaryDir;
|
2014-12-09 13:01:44 +01:00
|
|
|
bool m_isValid;
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-09 18:42:15 +01:00
|
|
|
class CPPTOOLS_EXPORT TemporaryCopiedDir : public TemporaryDir
|
|
|
|
|
{
|
|
|
|
|
public:
|
2019-01-14 01:40:53 +01:00
|
|
|
explicit TemporaryCopiedDir(const QString &sourceDirPath);
|
2014-12-09 18:42:15 +01:00
|
|
|
QString absolutePath(const QByteArray &relativePath) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TemporaryCopiedDir();
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-10 11:05:52 +01:00
|
|
|
class CPPTOOLS_EXPORT VerifyCleanCppModelManager
|
2014-12-09 17:09:45 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2015-01-15 14:58:16 +01:00
|
|
|
VerifyCleanCppModelManager();
|
|
|
|
|
~VerifyCleanCppModelManager();
|
2015-05-08 12:19:08 +02:00
|
|
|
static bool isClean(bool testCleanedProjects = true);
|
2014-12-09 17:09:45 +01:00
|
|
|
};
|
|
|
|
|
|
2014-06-13 12:59:24 -04:00
|
|
|
class FileWriterAndRemover
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FileWriterAndRemover(const QString &filePath, const QByteArray &contents); // Writes file
|
|
|
|
|
bool writtenSuccessfully() const { return m_writtenSuccessfully; }
|
|
|
|
|
~FileWriterAndRemover(); // Removes file
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const QString m_filePath;
|
|
|
|
|
bool m_writtenSuccessfully;
|
|
|
|
|
};
|
|
|
|
|
|
2013-12-16 16:02:45 +01:00
|
|
|
} // namespace Tests
|
|
|
|
|
} // namespace CppTools
|