2013-12-16 16:02:45 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2013-12-16 16:02:45 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** 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.
|
2013-12-16 16:02:45 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2013-12-16 16:02:45 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef CPPTOOLSTESTCASE_H
|
|
|
|
|
#define CPPTOOLSTESTCASE_H
|
|
|
|
|
|
|
|
|
|
#include "cpptools_global.h"
|
|
|
|
|
|
2015-03-05 08:22:48 +01:00
|
|
|
#include <cplusplus/CppDocument.h>
|
2013-12-16 16:02:45 +01:00
|
|
|
|
|
|
|
|
#include <QStringList>
|
2014-12-09 13:01:44 +01:00
|
|
|
#include <QTemporaryDir>
|
2013-12-16 16:02:45 +01:00
|
|
|
|
|
|
|
|
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; }
|
2014-12-09 13:01:44 +01:00
|
|
|
namespace ProjectExplorer { 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:
|
|
|
|
|
TestCase(bool runGarbageCollector = true);
|
|
|
|
|
~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-02-17 15:05:22 +01:00
|
|
|
enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ };
|
|
|
|
|
static bool waitUntilCppModelManagerIsAwareOf(
|
|
|
|
|
ProjectExplorer::Project *project,
|
|
|
|
|
int timeOutInMs = defaultTimeOutInMs);
|
|
|
|
|
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
|
|
|
|
|
|
2014-12-09 17:09:45 +01:00
|
|
|
ProjectInfo open(const QString &projectFile, bool configureAsExampleProject = false);
|
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:
|
2014-12-09 13:01:44 +01:00
|
|
|
QTemporaryDir m_temporaryDir;
|
|
|
|
|
bool m_isValid;
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-09 18:42:15 +01:00
|
|
|
class CPPTOOLS_EXPORT TemporaryCopiedDir : public TemporaryDir
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TemporaryCopiedDir(const QString &sourceDirPath);
|
|
|
|
|
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();
|
|
|
|
|
static bool isClean();
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-19 12:32:43 +02:00
|
|
|
// Normally the proposal is deleted by the ProcessorRunner or the
|
|
|
|
|
// GenericProposalWidget, but in tests we usually don't make use of them.
|
|
|
|
|
class CPPTOOLS_EXPORT IAssistProposalScopedPointer
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
IAssistProposalScopedPointer(TextEditor::IAssistProposal *proposal);
|
|
|
|
|
~IAssistProposalScopedPointer();
|
|
|
|
|
|
|
|
|
|
QScopedPointer<TextEditor::IAssistProposal> d;
|
|
|
|
|
};
|
|
|
|
|
|
2013-12-16 16:02:45 +01:00
|
|
|
} // namespace Tests
|
|
|
|
|
} // namespace CppTools
|
|
|
|
|
|
|
|
|
|
#endif // CPPTOOLSTESTCASE_H
|