2014-10-07 12:30:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
2014-10-07 12:30:54 +02:00
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-22 10:37:55 +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.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +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.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
#include "testconfiguration.h"
|
2016-02-03 15:59:59 +01:00
|
|
|
#include "testtreeitem.h"
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
#include <cplusplus/CppDocument.h>
|
|
|
|
|
|
2015-09-10 15:32:12 +02:00
|
|
|
#include <utils/treemodel.h>
|
|
|
|
|
|
2014-11-11 17:30:34 +01:00
|
|
|
#include <QSortFilterProxyModel>
|
2014-10-07 12:30:54 +02:00
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class TestCodeParser;
|
2016-02-03 15:59:59 +01:00
|
|
|
struct TestParseResult;
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2015-09-10 15:32:12 +02:00
|
|
|
class TestTreeModel : public Utils::TreeModel
|
2014-10-07 12:30:54 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2015-02-05 16:07:45 +01:00
|
|
|
enum Type {
|
2016-02-03 15:59:59 +01:00
|
|
|
Invalid,
|
2015-02-05 16:07:45 +01:00
|
|
|
AutoTest,
|
2015-12-07 15:15:00 +01:00
|
|
|
QuickTest,
|
|
|
|
|
GoogleTest
|
2015-02-05 16:07:45 +01:00
|
|
|
};
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
static TestTreeModel* instance();
|
|
|
|
|
~TestTreeModel();
|
2015-02-12 15:48:24 +01:00
|
|
|
void enableParsing();
|
2016-02-01 15:12:10 +01:00
|
|
|
void enableParsingFromSettings();
|
2015-02-12 15:48:24 +01:00
|
|
|
void disableParsing();
|
2016-02-01 15:12:10 +01:00
|
|
|
void disableParsingFromSettings();
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2015-09-10 15:32:12 +02:00
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
2014-10-07 12:30:54 +02:00
|
|
|
|
|
|
|
|
TestCodeParser *parser() const { return m_parser; }
|
|
|
|
|
bool hasTests() const;
|
2014-10-07 15:51:02 +02:00
|
|
|
QList<TestConfiguration *> getAllTestCases() const;
|
|
|
|
|
QList<TestConfiguration *> getSelectedTests() const;
|
2015-04-16 14:04:36 +02:00
|
|
|
TestConfiguration *getTestConfiguration(const TestTreeItem *item) const;
|
2015-02-05 16:07:45 +01:00
|
|
|
bool hasUnnamedQuickTests() const;
|
2014-11-06 16:01:06 +01:00
|
|
|
|
2015-02-10 14:20:43 +01:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
int autoTestsCount() const;
|
|
|
|
|
int namedQuickTestsCount() const;
|
|
|
|
|
int unnamedQuickTestsCount() const;
|
2015-11-02 11:06:19 +01:00
|
|
|
int dataTagsCount() const;
|
2015-12-10 13:46:04 +01:00
|
|
|
int gtestNamesCount() const;
|
2016-01-13 09:10:11 +01:00
|
|
|
QMultiMap<QString, int> gtestNamesAndSets() const;
|
2015-02-10 14:20:43 +01:00
|
|
|
#endif
|
2014-11-06 16:01:06 +01:00
|
|
|
|
2016-01-26 13:52:45 +01:00
|
|
|
void markAllForRemoval();
|
|
|
|
|
void markForRemoval(const QString &filePath);
|
|
|
|
|
void sweep();
|
2016-03-09 08:17:33 +01:00
|
|
|
QHash<QString, QString> testCaseNamesForFiles(QStringList files);
|
2016-01-25 09:30:41 +01:00
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
signals:
|
2014-11-04 13:42:38 +01:00
|
|
|
void testTreeModelChanged();
|
2016-02-10 10:43:31 +01:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
void sweepingDone();
|
|
|
|
|
#endif
|
2014-10-07 12:30:54 +02:00
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
|
|
private:
|
2016-02-12 09:04:19 +01:00
|
|
|
void onParseResultReady(const TestParseResult &result);
|
2016-02-08 15:56:07 +01:00
|
|
|
void handleParseResult(const TestParseResult &result);
|
|
|
|
|
void handleUnnamedQuickParseResult(const TestParseResult &result);
|
|
|
|
|
void handleGTestParseResult(const TestParseResult &result);
|
2015-02-05 16:07:45 +01:00
|
|
|
void removeAllTestItems();
|
2016-01-25 13:05:12 +01:00
|
|
|
void removeFiles(const QStringList &files);
|
|
|
|
|
void markForRemoval(const QString &filePath, Type type);
|
2016-02-01 10:04:02 +01:00
|
|
|
bool sweepChildren(TestTreeItem *item);
|
2015-02-05 16:07:45 +01:00
|
|
|
|
|
|
|
|
TestTreeItem *unnamedQuickTests() const;
|
|
|
|
|
TestTreeItem *rootItemForType(Type type);
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
explicit TestTreeModel(QObject *parent = 0);
|
2016-02-01 15:12:10 +01:00
|
|
|
void setupParsingConnections();
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2016-02-23 15:56:52 +01:00
|
|
|
AutoTestTreeItem *m_autoTestRootItem;
|
|
|
|
|
QuickTestTreeItem *m_quickTestRootItem;
|
|
|
|
|
GoogleTestTreeItem *m_googleTestRootItem;
|
2014-10-07 12:30:54 +02:00
|
|
|
TestCodeParser *m_parser;
|
2015-02-12 15:48:24 +01:00
|
|
|
bool m_connectionsInitialized;
|
2015-04-15 09:34:11 +02:00
|
|
|
QAtomicInt m_refCounter;
|
2014-10-07 12:30:54 +02:00
|
|
|
};
|
|
|
|
|
|
2014-11-11 17:30:34 +01:00
|
|
|
class TestTreeSortFilterModel : public QSortFilterProxyModel
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
enum SortMode {
|
|
|
|
|
Alphabetically,
|
|
|
|
|
Naturally
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum FilterMode {
|
|
|
|
|
Basic,
|
|
|
|
|
ShowInitAndCleanup = 0x01,
|
|
|
|
|
ShowTestData = 0x02,
|
|
|
|
|
ShowAll = ShowInitAndCleanup | ShowTestData
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TestTreeSortFilterModel(TestTreeModel *sourceModel, QObject *parent = 0);
|
|
|
|
|
void setSortMode(SortMode sortMode);
|
|
|
|
|
void setFilterMode(FilterMode filterMode);
|
|
|
|
|
void toggleFilter(FilterMode filterMode);
|
|
|
|
|
static FilterMode toFilterMode(int f);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
|
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TestTreeModel *m_sourceModel;
|
|
|
|
|
SortMode m_sortMode;
|
|
|
|
|
FilterMode m_filterMode;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2016-01-27 13:52:33 +01:00
|
|
|
struct TestParseResult
|
|
|
|
|
{
|
2016-02-03 15:59:59 +01:00
|
|
|
TestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : type(t) {}
|
|
|
|
|
|
2016-01-27 13:52:33 +01:00
|
|
|
TestTreeModel::Type type;
|
2016-02-03 15:59:59 +01:00
|
|
|
QString fileName;
|
2016-02-23 15:56:52 +01:00
|
|
|
QString proFile;
|
2016-02-03 15:59:59 +01:00
|
|
|
QString testCaseName;
|
2016-02-08 14:49:15 +01:00
|
|
|
unsigned line = 0;
|
|
|
|
|
unsigned column = 0;
|
2016-02-03 15:59:59 +01:00
|
|
|
bool parameterized = false;
|
2016-02-22 11:23:53 +01:00
|
|
|
bool typed = false;
|
2016-02-23 17:40:10 +01:00
|
|
|
bool disabled = false;
|
2016-02-03 15:59:59 +01:00
|
|
|
QMap<QString, TestCodeLocationAndType> functions;
|
|
|
|
|
QMap<QString, TestCodeLocationList> dataTagsOrTestSets;
|
2016-01-27 13:52:33 +01:00
|
|
|
};
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|
|
|
|
|
|
2015-02-13 15:44:18 +01:00
|
|
|
Q_DECLARE_METATYPE(Autotest::Internal::TestTreeModel::Type)
|
2016-02-03 15:59:59 +01:00
|
|
|
Q_DECLARE_METATYPE(Autotest::Internal::TestParseResult)
|