From 213a687f454682b8cd1e79fc27762ac6f374502e Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 10 Feb 2015 14:20:43 +0100 Subject: Rework parsing and provide unit test Handling of parsing has slightly changed. The parser now uses simple states to be capable of postponing triggered parses if there is already a parsing in progress. Furthermore the parser now waits for the current project to be completely scanned. Change-Id: I6d4968d28194ba8d23d3a0ee6ab454d81a549e67 Reviewed-by: Andre Poenitz --- plugins/autotest/autotest.pro | 5 + plugins/autotest/autotestplugin.cpp | 12 ++ plugins/autotest/autotestplugin.h | 1 + plugins/autotest/autotestunittests.cpp | 123 ++++++++++++++++++ plugins/autotest/autotestunittests.h | 55 ++++++++ plugins/autotest/autotestunittests.qrc | 32 +++++ plugins/autotest/testcodeparser.cpp | 144 ++++++++++++++++++--- plugins/autotest/testcodeparser.h | 20 +++ plugins/autotest/testtreemodel.cpp | 23 +++- plugins/autotest/testtreemodel.h | 5 + plugins/autotest/unit_test/mixed_atp/mixed_atp.pro | 5 + plugins/autotest/unit_test/mixed_atp/src/main.cpp | 8 ++ plugins/autotest/unit_test/mixed_atp/src/src.pro | 6 + .../unit_test/mixed_atp/tests/auto/auto.pro | 15 +++ .../unit_test/mixed_atp/tests/auto/bench/bench.pro | 12 ++ .../mixed_atp/tests/auto/bench/tst_benchtest.cpp | 63 +++++++++ .../unit_test/mixed_atp/tests/auto/dummy/dummy.pro | 10 ++ .../mixed_atp/tests/auto/dummy/tst_foo.cpp | 82 ++++++++++++ .../unit_test/mixed_atp/tests/auto/dummy/tst_foo.h | 43 ++++++ .../unit_test/mixed_atp/tests/auto/gui/gui.pro | 8 ++ .../mixed_atp/tests/auto/gui/tst_guitest.cpp | 89 +++++++++++++ .../mixed_atp/tests/auto/quickauto/TestDummy.qml | 10 ++ .../mixed_atp/tests/auto/quickauto/bar/tst_foo.qml | 29 +++++ .../mixed_atp/tests/auto/quickauto/main.cpp | 3 + .../tests/auto/quickauto/notlisted/tst_bla.qml | 29 +++++ .../mixed_atp/tests/auto/quickauto/quickauto.pro | 14 ++ .../mixed_atp/tests/auto/quickauto/tst_test1.qml | 33 +++++ .../mixed_atp/tests/auto/quickauto/tst_test2.qml | 47 +++++++ .../mixed_atp/tests/auto/quickauto/tst_test3.qml | 30 +++++ .../mixed_atp/tests/auto/quickauto2/main.cpp | 3 + .../mixed_atp/tests/auto/quickauto2/quickauto2.pro | 11 ++ .../mixed_atp/tests/auto/quickauto2/tst_test1.qml | 33 +++++ .../mixed_atp/tests/auto/quickauto2/tst_test2.qml | 33 +++++ .../autotest/unit_test/mixed_atp/tests/tests.pro | 4 + plugins/autotest/unit_test/plain/plain.pro | 4 + .../unit_test/plain/test_plain/test_plain.pro | 13 ++ .../unit_test/plain/test_plain/tst_simple.cpp | 65 ++++++++++ .../unit_test/plain/test_plain/tst_simple.h | 4 + 38 files changed, 1108 insertions(+), 18 deletions(-) create mode 100644 plugins/autotest/autotestunittests.cpp create mode 100644 plugins/autotest/autotestunittests.h create mode 100644 plugins/autotest/autotestunittests.qrc create mode 100644 plugins/autotest/unit_test/mixed_atp/mixed_atp.pro create mode 100644 plugins/autotest/unit_test/mixed_atp/src/main.cpp create mode 100644 plugins/autotest/unit_test/mixed_atp/src/src.pro create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/auto.pro create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/bench/bench.pro create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/bench/tst_benchtest.cpp create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/dummy.pro create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/tst_foo.cpp create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/tst_foo.h create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/gui/gui.pro create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/gui/tst_guitest.cpp create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/TestDummy.qml create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/bar/tst_foo.qml create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/main.cpp create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/notlisted/tst_bla.qml create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/quickauto.pro create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test1.qml create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test2.qml create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test3.qml create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/main.cpp create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/quickauto2.pro create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/tst_test1.qml create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/tst_test2.qml create mode 100644 plugins/autotest/unit_test/mixed_atp/tests/tests.pro create mode 100644 plugins/autotest/unit_test/plain/plain.pro create mode 100644 plugins/autotest/unit_test/plain/test_plain/test_plain.pro create mode 100644 plugins/autotest/unit_test/plain/test_plain/tst_simple.cpp create mode 100644 plugins/autotest/unit_test/plain/test_plain/tst_simple.h diff --git a/plugins/autotest/autotest.pro b/plugins/autotest/autotest.pro index ecc8934575..4d3c6643f2 100644 --- a/plugins/autotest/autotest.pro +++ b/plugins/autotest/autotest.pro @@ -56,3 +56,8 @@ RESOURCES += \ FORMS += \ testsettingspage.ui +equals(TEST, 1) { + HEADERS += autotestunittests.h + SOURCES += autotestunittests.cpp + RESOURCES += autotestunittests.qrc +} diff --git a/plugins/autotest/autotestplugin.cpp b/plugins/autotest/autotestplugin.cpp index 624812200c..46e2a311d9 100644 --- a/plugins/autotest/autotestplugin.cpp +++ b/plugins/autotest/autotestplugin.cpp @@ -44,6 +44,10 @@ #include +#ifdef WITH_TESTS +#include "autotestunittests.h" +#endif + using namespace Autotest::Internal; static AutotestPlugin *m_instance = 0; @@ -151,3 +155,11 @@ void AutotestPlugin::triggerAction() tr("This is an action from Autotest.")); } +QList AutotestPlugin::createTestObjects() const +{ + QList tests; +#ifdef WITH_TESTS + tests << new AutoTestUnitTests(TestTreeModel::instance()); +#endif + return tests; +} diff --git a/plugins/autotest/autotestplugin.h b/plugins/autotest/autotestplugin.h index be4a803717..af5fcc91db 100644 --- a/plugins/autotest/autotestplugin.h +++ b/plugins/autotest/autotestplugin.h @@ -52,6 +52,7 @@ private slots: private: bool checkLicense(); void initializeMenuEntries(); + QList createTestObjects() const; const QSharedPointer m_settings; }; diff --git a/plugins/autotest/autotestunittests.cpp b/plugins/autotest/autotestunittests.cpp new file mode 100644 index 0000000000..50556d7e00 --- /dev/null +++ b/plugins/autotest/autotestunittests.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "autotestconstants.h" +#include "autotestunittests.h" +#include "testcodeparser.h" +#include "testtreemodel.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +using namespace Core; +using namespace ProjectExplorer; +using namespace Utils; + +namespace Autotest { +namespace Internal { + +AutoTestUnitTests::AutoTestUnitTests(TestTreeModel *model, QObject *parent) + : QObject(parent), + m_model(model), + m_tmpDir(0), + m_isQt4(false) +{ +} + +void AutoTestUnitTests::initTestCase() +{ + const QList allKits = KitManager::kits(); + if (allKits.count() != 1) + QSKIP("This test requires exactly one kit to be present"); + if (auto qtVersion = QtSupport::QtKitInformation::qtVersion(allKits.first())) + m_isQt4 = qtVersion->qtVersionString().startsWith(QLatin1Char('4')); + else + QSKIP("Could not figure out which Qt version is used for default kit."); + const ToolChain * const toolchain = ToolChainKitInformation::toolChain(allKits.first()); + if (!toolchain) + QSKIP("This test requires that there is a kit with a toolchain."); + + m_tmpDir = new CppTools::Tests::TemporaryCopiedDir(QLatin1String(":/unit_test")); +} + +void AutoTestUnitTests::cleanupTestCase() +{ + delete m_tmpDir; +} + +void AutoTestUnitTests::testCodeParser() +{ + QFETCH(QString, projectFilePath); + QFETCH(int, expectedAutoTestsCount); + QFETCH(int, expectedNamedQuickTestsCount); + QFETCH(int, expectedUnnamedQuickTestsCount); + + NavigationWidget *navigation = NavigationWidget::instance(); + navigation->activateSubWidget(Constants::AUTOTEST_ID); + + CppTools::Tests::ProjectOpenerAndCloser projectManager; + const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); + QVERIFY(projectInfo.isValid()); + + QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); + QVERIFY(parserSpy.wait(20000)); + + if (m_isQt4) + expectedNamedQuickTestsCount = expectedUnnamedQuickTestsCount = 0; + + QCOMPARE(m_model->autoTestsCount(), expectedAutoTestsCount); + QCOMPARE(m_model->namedQuickTestsCount(), expectedNamedQuickTestsCount); + QCOMPARE(m_model->unnamedQuickTestsCount(), expectedUnnamedQuickTestsCount); + + QCOMPARE(m_model->parser()->autoTestsCount(), expectedAutoTestsCount); + QCOMPARE(m_model->parser()->namedQuickTestsCount(), expectedNamedQuickTestsCount); + QCOMPARE(m_model->parser()->unnamedQuickTestsCount(), expectedUnnamedQuickTestsCount); + +} + +void AutoTestUnitTests::testCodeParser_data() +{ + QTest::addColumn("projectFilePath"); + QTest::addColumn("expectedAutoTestsCount"); + QTest::addColumn("expectedNamedQuickTestsCount"); + QTest::addColumn("expectedUnnamedQuickTestsCount"); + + + QTest::newRow("plainAutoTest") + << QString(m_tmpDir->path() + QLatin1String("/plain/plain.pro")) + << 1 << 0 << 0; + QTest::newRow("mixedAutoTestAndQuickTests") + << QString(m_tmpDir->path() + QLatin1String("/mixed_atp/mixed_atp.pro")) + << 3 << 5 << 3; +} + +} // namespace Internal +} // namespace Autotest diff --git a/plugins/autotest/autotestunittests.h b/plugins/autotest/autotestunittests.h new file mode 100644 index 0000000000..16c6042b5d --- /dev/null +++ b/plugins/autotest/autotestunittests.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#ifndef AUTOTESTUNITTESTS_H +#define AUTOTESTUNITTESTS_H + +#include +#include + +namespace CppTools { namespace Tests { class TemporaryCopiedDir; } } + +namespace Autotest { +namespace Internal { + +class TestTreeModel; + +class AutoTestUnitTests : public QObject +{ + Q_OBJECT +public: + explicit AutoTestUnitTests(TestTreeModel *model, QObject *parent = 0); + +signals: + +private slots: + void initTestCase(); + void cleanupTestCase(); + void testCodeParser(); + void testCodeParser_data(); + +private: + TestTreeModel *m_model; + CppTools::Tests::TemporaryCopiedDir *m_tmpDir; + bool m_isQt4; +}; + +} // namespace Internal +} // namespace Autotest + +#endif // AUTOTESTUNITTESTS_H diff --git a/plugins/autotest/autotestunittests.qrc b/plugins/autotest/autotestunittests.qrc new file mode 100644 index 0000000000..6fb5348e54 --- /dev/null +++ b/plugins/autotest/autotestunittests.qrc @@ -0,0 +1,32 @@ + + + unit_test/mixed_atp/src/main.cpp + unit_test/mixed_atp/tests/auto/bench/tst_benchtest.cpp + unit_test/mixed_atp/tests/auto/dummy/tst_foo.cpp + unit_test/mixed_atp/tests/auto/dummy/tst_foo.h + unit_test/mixed_atp/tests/auto/gui/tst_guitest.cpp + unit_test/mixed_atp/tests/auto/quickauto/bar/tst_foo.qml + unit_test/mixed_atp/tests/auto/quickauto/notlisted/tst_bla.qml + unit_test/mixed_atp/tests/auto/quickauto/main.cpp + unit_test/mixed_atp/tests/auto/quickauto/TestDummy.qml + unit_test/mixed_atp/tests/auto/quickauto/tst_test1.qml + unit_test/mixed_atp/tests/auto/quickauto/tst_test2.qml + unit_test/mixed_atp/tests/auto/quickauto/tst_test3.qml + unit_test/mixed_atp/tests/auto/quickauto2/main.cpp + unit_test/mixed_atp/tests/auto/quickauto2/tst_test1.qml + unit_test/mixed_atp/tests/auto/quickauto2/tst_test2.qml + unit_test/plain/test_plain/tst_simple.cpp + unit_test/plain/test_plain/tst_simple.h + unit_test/plain/plain.pro + unit_test/mixed_atp/mixed_atp.pro + unit_test/plain/test_plain/test_plain.pro + unit_test/mixed_atp/tests/tests.pro + unit_test/mixed_atp/src/src.pro + unit_test/mixed_atp/tests/auto/bench/bench.pro + unit_test/mixed_atp/tests/auto/dummy/dummy.pro + unit_test/mixed_atp/tests/auto/gui/gui.pro + unit_test/mixed_atp/tests/auto/quickauto/quickauto.pro + unit_test/mixed_atp/tests/auto/quickauto2/quickauto2.pro + unit_test/mixed_atp/tests/auto/auto.pro + + diff --git a/plugins/autotest/testcodeparser.cpp b/plugins/autotest/testcodeparser.cpp index a33a6cac9b..0f950d305b 100644 --- a/plugins/autotest/testcodeparser.cpp +++ b/plugins/autotest/testcodeparser.cpp @@ -49,7 +49,10 @@ TestCodeParser::TestCodeParser(TestTreeModel *parent) : QObject(parent), m_model(parent), m_parserEnabled(true), - m_pendingUpdate(false) + m_pendingUpdate(false), + m_fullUpdatePostPoned(false), + m_partialUpdatePostPoned(false), + m_parserState(Idle) { // connect to ProgressManager to post-pone test parsing when CppModelManager is parsing auto progressManager = qobject_cast(Core::ProgressManager::instance()); @@ -57,6 +60,8 @@ TestCodeParser::TestCodeParser(TestTreeModel *parent) this, &TestCodeParser::onTaskStarted); connect(progressManager, &Core::ProgressManager::allTasksFinished, this, &TestCodeParser::onAllTasksFinished); + connect(this, &TestCodeParser::partialParsingFinished, + this, &TestCodeParser::onPartialParsingFinished); } TestCodeParser::~TestCodeParser() @@ -81,25 +86,26 @@ void TestCodeParser::updateTestTree() { if (!m_parserEnabled) { m_pendingUpdate = true; - qDebug() << "Skipped update due to running parser or pro file evaluate"; return; } - qDebug("updating TestTreeModel"); - - clearMaps(); - emit cacheCleared(); - if (ProjectExplorer::Project *project = currentProject()) { if (auto qmakeProject = qobject_cast(project)) { + if (qmakeProject->asyncUpdateState() != QmakeProjectManager::QmakeProject::Base) { + m_pendingUpdate = true; + return; + } connect(qmakeProject, &QmakeProjectManager::QmakeProject::proFilesEvaluated, this, &TestCodeParser::onProFileEvaluated, Qt::UniqueConnection); } } else return; - scanForTests(); m_pendingUpdate = false; + + clearMaps(); + emit cacheCleared(); + scanForTests(); } /****** scan for QTest related stuff helpers ******/ @@ -443,7 +449,7 @@ void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &docume } else if (!project->files(ProjectExplorer::Project::AllFiles).contains(fileName)) { return; } - checkDocumentForTestCode(document); + scanForTests(QStringList(fileName)); } void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document) @@ -464,15 +470,17 @@ void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document) const CPlusPlus::Snapshot snapshot = CppTools::CppModelManager::instance()->snapshot(); if (m_quickDocMap.contains(fileName) && snapshot.contains(m_quickDocMap[fileName].referencingFile())) { - checkDocumentForTestCode(snapshot.document(m_quickDocMap[fileName].referencingFile())); + if (!m_quickDocMap[fileName].referencingFile().isEmpty()) + scanForTests(QStringList(m_quickDocMap[fileName].referencingFile())); } if (!m_quickDocMap.contains(tr(Constants::UNNAMED_QUICKTESTS))) return; // special case of having unnamed TestCases const QString &mainFile = m_model->getMainFileForUnnamedQuickTest(fileName); - if (!mainFile.isEmpty() && snapshot.contains(mainFile)) - checkDocumentForTestCode(snapshot.document(mainFile)); + if (!mainFile.isEmpty() && snapshot.contains(mainFile)) { + scanForTests(QStringList(mainFile)); + } } void TestCodeParser::removeFiles(const QStringList &files) @@ -481,13 +489,62 @@ void TestCodeParser::removeFiles(const QStringList &files) removeTestsIfNecessary(file); } +bool TestCodeParser::postponed(const QStringList &fileList) +{ + switch (m_parserState) { + case Idle: + return false; + case PartialParse: + // partial is running, postponing a full parse + if (fileList.isEmpty()) { + m_partialUpdatePostPoned = false; + m_postPonedFiles.clear(); + m_fullUpdatePostPoned = true; + } else { + // partial parse triggered, but full parse is postponed already, ignoring this + if (m_fullUpdatePostPoned) + return true; + // partial parse triggered, postpone or add current files to already postponed partial + foreach (const QString &file, fileList) + m_postPonedFiles.insert(file); + m_partialUpdatePostPoned = true; + } + return true; + case FullParse: + // full parse is running, postponing another full parse + if (fileList.isEmpty()) { + m_partialUpdatePostPoned = false; + m_postPonedFiles.clear(); + m_fullUpdatePostPoned = true; + } else { + // full parse already postponed, ignoring triggering a partial parse + if (m_fullUpdatePostPoned) { + return true; + } + // partial parse triggered, postpone or add current files to already postponed partial + foreach (const QString &file, fileList) + m_postPonedFiles.insert(file); + m_partialUpdatePostPoned = true; + } + return true; + } + QTC_ASSERT(false, return false); // should not happen at all +} + void TestCodeParser::scanForTests(const QStringList &fileList) { + if (postponed(fileList)) + return; + QStringList list; if (fileList.isEmpty()) { list = currentProject()->files(ProjectExplorer::Project::AllFiles); + if (list.isEmpty()) + return; + m_parserState = FullParse; } else { list << fileList; + m_parserState = PartialParse; } CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance(); @@ -499,6 +556,18 @@ void TestCodeParser::scanForTests(const QStringList &fileList) checkDocumentForTestCode(doc); } } + switch (m_parserState) { + case PartialParse: + m_parserState = Idle; + emit partialParsingFinished(); + break; + case FullParse: + m_parserState = Idle; + emit parsingFinished(); + break; + case Idle: + break; + } } void TestCodeParser::clearMaps() @@ -588,22 +657,39 @@ void TestCodeParser::removeTestsIfNecessaryByProFile(const QString &proFile) void TestCodeParser::onTaskStarted(Core::Id type) { - if (type != CppTools::Constants::TASK_INDEX - && type != QmakeProjectManager::Constants::PROFILE_EVALUATE) + if (type != CppTools::Constants::TASK_INDEX) return; m_parserEnabled = false; } void TestCodeParser::onAllTasksFinished(Core::Id type) { - if (type != CppTools::Constants::TASK_INDEX - && type != QmakeProjectManager::Constants::PROFILE_EVALUATE) + // only CPP parsing is relevant as we trigger Qml parsing internally anyway + if (type != CppTools::Constants::TASK_INDEX) return; m_parserEnabled = true; if (m_pendingUpdate) updateTestTree(); } +void TestCodeParser::onPartialParsingFinished() +{ + QTC_ASSERT(m_fullUpdatePostPoned != m_partialUpdatePostPoned + || ((m_fullUpdatePostPoned || m_partialUpdatePostPoned) == false), + m_partialUpdatePostPoned = false;m_postPonedFiles.clear();); + if (m_fullUpdatePostPoned) { + m_fullUpdatePostPoned = false; + updateTestTree(); + } else if (m_partialUpdatePostPoned) { + m_partialUpdatePostPoned = false; + QStringList tmp; + foreach (const QString &file, m_postPonedFiles) + tmp << file; + m_postPonedFiles.clear(); + scanForTests(tmp); + } +} + void TestCodeParser::updateUnnamedQuickTests(const QString &fileName, const QString &mainFile, const QMap &functions) { @@ -710,5 +796,31 @@ void TestCodeParser::onProFileEvaluated() } } +#ifdef WITH_TESTS +int TestCodeParser::autoTestsCount() const +{ + int count = 0; + foreach (const QString &file, m_cppDocMap.keys()) { + if (m_cppDocMap.value(file).referencingFile().isEmpty()) + ++count; + } + return count; +} + +int TestCodeParser::namedQuickTestsCount() const +{ + if (m_quickDocMap.contains(tr(Constants::UNNAMED_QUICKTESTS))) + return m_quickDocMap.size() - 1; + return m_quickDocMap.size(); +} + +int TestCodeParser::unnamedQuickTestsCount() const +{ + if (m_quickDocMap.contains(tr(Constants::UNNAMED_QUICKTESTS))) + return m_quickDocMap.value(tr(Constants::UNNAMED_QUICKTESTS)).testFunctions().size(); + return 0; +} +#endif + } // namespace Internal } // namespace Autotest diff --git a/plugins/autotest/testcodeparser.h b/plugins/autotest/testcodeparser.h index e2f590cabf..d846769b37 100644 --- a/plugins/autotest/testcodeparser.h +++ b/plugins/autotest/testcodeparser.h @@ -43,9 +43,21 @@ class TestCodeParser : public QObject { Q_OBJECT public: + enum State { + Idle, + PartialParse, + FullParse + }; + explicit TestCodeParser(TestTreeModel *parent = 0); virtual ~TestCodeParser(); +#ifdef WITH_TESTS + int autoTestsCount() const; + int namedQuickTestsCount() const; + int unnamedQuickTestsCount() const; +#endif + signals: void cacheCleared(); void testItemCreated(const TestTreeItem &item, TestTreeModel::Type type); @@ -55,6 +67,8 @@ signals: void unnamedQuickTestsUpdated(const QString &filePath, const QString &mainFile, const QMap &functions); void unnamedQuickTestsRemoved(const QString &filePath); + void parsingFinished(); + void partialParsingFinished(); public slots: void emitUpdateTestTree(); @@ -68,6 +82,7 @@ public slots: void onProFileEvaluated(); private: + bool postponed(const QStringList &fileList); void scanForTests(const QStringList &fileList = QStringList()); void clearMaps(); void removeTestsIfNecessary(const QString &fileName); @@ -75,6 +90,7 @@ private: void onTaskStarted(Core::Id type); void onAllTasksFinished(Core::Id type); + void onPartialParsingFinished(); void updateUnnamedQuickTests(const QString &fileName, const QString &mainFile, const QMap &functions); void updateModelAndCppDocMap(CPlusPlus::Document::Ptr document, @@ -87,6 +103,10 @@ private: QMap m_quickDocMap; bool m_parserEnabled; bool m_pendingUpdate; + bool m_fullUpdatePostPoned; + bool m_partialUpdatePostPoned; + QSet m_postPonedFiles; + State m_parserState; }; } // namespace Internal diff --git a/plugins/autotest/testtreemodel.cpp b/plugins/autotest/testtreemodel.cpp index f2ea94d626..bccabf898a 100644 --- a/plugins/autotest/testtreemodel.cpp +++ b/plugins/autotest/testtreemodel.cpp @@ -61,8 +61,6 @@ TestTreeModel::TestTreeModel(QObject *parent) : connect(m_parser, &TestCodeParser::unnamedQuickTestsRemoved, this, &TestTreeModel::removeUnnamedQuickTests); - m_parser->updateTestTree(); - // CppTools::CppModelManagerInterface *cppMM = CppTools::CppModelManagerInterface::instance(); // if (cppMM) { // // replace later on by @@ -808,6 +806,27 @@ void TestTreeModel::processChildren(QModelIndex &parentIndex, const TestTreeItem } } +#ifdef WITH_TESTS +int TestTreeModel::autoTestsCount() const +{ + return m_autoTestRootItem ? m_autoTestRootItem->childCount() : 0; +} + +int TestTreeModel::namedQuickTestsCount() const +{ + return m_quickTestRootItem + ? m_quickTestRootItem->childCount() - (hasUnnamedQuickTests() ? 1 : 0) + : 0; +} + +int TestTreeModel::unnamedQuickTestsCount() const +{ + if (TestTreeItem *unnamed = unnamedQuickTests()) + return unnamed->childCount(); + return 0; +} +#endif + /***************************** Sort/Filter Model **********************************/ TestTreeSortFilterModel::TestTreeSortFilterModel(TestTreeModel *sourceModel, QObject *parent) diff --git a/plugins/autotest/testtreemodel.h b/plugins/autotest/testtreemodel.h index 81ad9418d9..b21eafbb7f 100644 --- a/plugins/autotest/testtreemodel.h +++ b/plugins/autotest/testtreemodel.h @@ -75,6 +75,11 @@ public: QSet qmlFilesForProFile(const QString &proFile) const; bool hasUnnamedQuickTests() const; +#ifdef WITH_TESTS + int autoTestsCount() const; + int namedQuickTestsCount() const; + int unnamedQuickTestsCount() const; +#endif signals: void testTreeModelChanged(); diff --git a/plugins/autotest/unit_test/mixed_atp/mixed_atp.pro b/plugins/autotest/unit_test/mixed_atp/mixed_atp.pro new file mode 100644 index 0000000000..068ea5a3a6 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/mixed_atp.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs + +SUBDIRS += src \ + tests + diff --git a/plugins/autotest/unit_test/mixed_atp/src/main.cpp b/plugins/autotest/unit_test/mixed_atp/src/main.cpp new file mode 100644 index 0000000000..e0c10bca02 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/src/main.cpp @@ -0,0 +1,8 @@ +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + return a.exec(); +} + diff --git a/plugins/autotest/unit_test/mixed_atp/src/src.pro b/plugins/autotest/unit_test/mixed_atp/src/src.pro new file mode 100644 index 0000000000..9e554af8b7 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/src/src.pro @@ -0,0 +1,6 @@ +QT += gui widgets + +TEMPLATE = app + +SOURCES += main.cpp + diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.pro b/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.pro new file mode 100644 index 0000000000..cb4dc9ec32 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.pro @@ -0,0 +1,15 @@ +TEMPLATE = subdirs + +SUBDIRS = \ + bench \ + dummy \ + gui + +greaterThan(QT_MAJOR_VERSION, 4) { + message("enabling quick tests") + SUBDIRS += quickauto \ + quickauto2 +} else { + message("quick tests disabled") +} + diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/bench/bench.pro b/plugins/autotest/unit_test/mixed_atp/tests/auto/bench/bench.pro new file mode 100644 index 0000000000..87f391f41d --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/bench/bench.pro @@ -0,0 +1,12 @@ +QT += testlib + +QT -= gui + +TARGET = tst_benchtest +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += tst_benchtest.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/bench/tst_benchtest.cpp b/plugins/autotest/unit_test/mixed_atp/tests/auto/bench/tst_benchtest.cpp new file mode 100644 index 0000000000..1d968a0147 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/bench/tst_benchtest.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +#include +#include + +class BenchTest : public QObject +{ + Q_OBJECT + +public: + BenchTest(); + +private Q_SLOTS: + void testCase1(); + void testCase1_data(); +}; + +BenchTest::BenchTest() +{ +} + +void BenchTest::testCase1() +{ + QFETCH(bool, localAware); + + QString str1 = QLatin1String("Hello World"); + QString str2 = QLatin1String("Hallo Welt"); + if (!localAware) { + QBENCHMARK { + str1 == str2; + } + } else { + QBENCHMARK { + str1.localeAwareCompare(str2) == 0; + } + } +} + +void BenchTest::testCase1_data() +{ + QTest::addColumn("localAware"); + QTest::newRow("localAware") << true; + QTest::newRow("simple") << false; +} + +QTEST_MAIN(BenchTest) + +#include "tst_benchtest.moc" diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/dummy.pro b/plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/dummy.pro new file mode 100644 index 0000000000..40e95bcc39 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/dummy.pro @@ -0,0 +1,10 @@ +QT += testlib +QT += gui +CONFIG += qt warn_on depend_includepath testcase +TEMPLATE = app + +TARGET = tst_FooBar + +HEADERS += tst_foo.h +SOURCES += tst_foo.cpp + diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/tst_foo.cpp b/plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/tst_foo.cpp new file mode 100644 index 0000000000..9dc2c9ec3a --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/tst_foo.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +#include "tst_foo.h" +#include +#include +#include + +Foo::Foo() +{ +} + +Foo::~Foo() +{ +} + +void Foo::initTestCase() +{ +} + +void Foo::cleanupTestCase() +{ + QWARN("Warning!"); +} + +void Foo::test_caseZero() +{ + QCOMPARE(1, 2); +} + +void Foo::test_case1() +{ + qDebug() << "test_case1"; + QFETCH(int, val); + + QEXPECT_FAIL("test2", "2", Continue); + QCOMPARE(val, 1); + QEXPECT_FAIL("test1", "bla", Abort); + QCOMPARE(val, 2); + QVERIFY2(true, "Hallo"); +} + +void Foo::test_case1_data() +{ + QTest::addColumn("val"); + QTest::newRow("test1") << 1; + QTest::newRow("test2") << 2; + QTest::newRow("test3") << 3; + QTest::newRow("test4") << 4; +} + +void Foo::test_case2() +{ + QThread::sleep(1); + qDebug() << "test_case2 - all pass"; + QSKIP("Skip for now", SkipAll); + QCOMPARE(1 ,1); + QVERIFY(true); +} + +void Foo::test_case4() +{ + qDebug("äøæ"); + QSKIP("Skipping test_case4", SkipSingle); + QFAIL("bla"); +} + +QTEST_MAIN(Foo) diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/tst_foo.h b/plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/tst_foo.h new file mode 100644 index 0000000000..29bb8f5f6e --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/dummy/tst_foo.h @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +#ifndef FOO_H_INCLUDED +#define FOO_H_INCLUDED + +#include + +class Foo : public QObject +{ + Q_OBJECT + +public: + Foo(); + ~Foo(); + +private slots: + void initTestCase(); + void cleanupTestCase(); + void test_case1(); + void test_case1_data(); + void test_caseZero(); + void test_case2(); +// void test_case3() {} + void test_case4(); + void test_case5() {} +}; + +#endif diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/gui/gui.pro b/plugins/autotest/unit_test/mixed_atp/tests/auto/gui/gui.pro new file mode 100644 index 0000000000..10f8f27eb8 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/gui/gui.pro @@ -0,0 +1,8 @@ +QT += testlib gui widgets + +TARGET = tst_guitest + +TEMPLATE = app + +SOURCES += tst_guitest.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/gui/tst_guitest.cpp b/plugins/autotest/unit_test/mixed_atp/tests/auto/gui/tst_guitest.cpp new file mode 100644 index 0000000000..13d61ba151 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/gui/tst_guitest.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +#include +#include +#include +#include + +class GuiTest : public QObject +{ + Q_OBJECT + +public: + GuiTest(); + +private Q_SLOTS: + void initTestCase(); + void cleanupTestCase(); + void testCase1(); + void testGui_data(); + void testGui(); +}; + +GuiTest::GuiTest() +{ +} + +void GuiTest::initTestCase() +{ +} + +void GuiTest::cleanupTestCase() +{ +} + +void GuiTest::testCase1() +{ + QLatin1String str("Hello World"); + QLineEdit lineEdit; + QTest::keyClicks(&lineEdit, str); + QCOMPARE(lineEdit.text(), str); +} + +void GuiTest::testGui() +{ + QFETCH(QTestEventList, events); + QFETCH(QString, expected); + QLineEdit lineEdit; + events.simulate(&lineEdit); + QCOMPARE(lineEdit.text(), expected); +} + +void GuiTest::testGui_data() +{ + QTest::addColumn("events"); + QTest::addColumn("expected"); + + QTestEventList list1; + list1.addKeyClick('a'); + QTest::newRow("char") << list1 << "a"; + + QTestEventList list2; + list2.addKeyClick('a'); + list2.addKeyClick(Qt::Key_Backspace); + QTest::newRow("there and back again") << list2 << ""; +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + GuiTest gt; + return QTest::qExec(>, argc, argv); +} + +#include "tst_guitest.moc" diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/TestDummy.qml b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/TestDummy.qml new file mode 100644 index 0000000000..ae30c81143 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/TestDummy.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + name: "HalloBallo" + function test_bla() { + verify(true, "verifying true"); + } +} + diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/bar/tst_foo.qml b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/bar/tst_foo.qml new file mode 100644 index 0000000000..ff825cd989 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/bar/tst_foo.qml @@ -0,0 +1,29 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + name: "subdirTC" + + function test_blabla() { + compare(1, 2, "Bla"); + } + +} + diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/main.cpp b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/main.cpp new file mode 100644 index 0000000000..16a331e4cc --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/main.cpp @@ -0,0 +1,3 @@ +#include + +QUICK_TEST_MAIN(blob) diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/notlisted/tst_bla.qml b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/notlisted/tst_bla.qml new file mode 100644 index 0000000000..325b7c4927 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/notlisted/tst_bla.qml @@ -0,0 +1,29 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + name: "notlisted" + + function test_blablabla() { + compare(1, 2, "Blubb"); + } + +} + diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/quickauto.pro b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/quickauto.pro new file mode 100644 index 0000000000..dfe495dc1c --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/quickauto.pro @@ -0,0 +1,14 @@ +TEMPLATE = app +TARGET = test_mal_qtquick + +CONFIG += warn_on qmltestcase + +DISTFILES += \ + tst_test1.qml \ + tst_test2.qml \ + TestDummy.qml \ + bar/tst_foo.qml \ + tst_test3.qml + +SOURCES += \ + main.cpp diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test1.qml b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test1.qml new file mode 100644 index 0000000000..8bf1379dc9 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test1.qml @@ -0,0 +1,33 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + name: "Banana" + + function test_math() { + compare(5 + 5, 10, "verifying 5 + 5 = 10"); + compare(10 - 5, 5, "verifying 10 - 5 = 5"); + } + + function test_fail() { + verify(false, "verifying false"); + } +} + diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test2.qml b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test2.qml new file mode 100644 index 0000000000..c9a7f5286b --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test2.qml @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + function test_str() { + var bla = String(); + bla = bla.concat("Hallo", " ", "Welt"); + var blubb = String("Hallo Welt"); + compare(blubb, bla, "Comparing concat"); + verify(blubb == bla, "Comparing concat equality") + } + +// nested TestCases actually fail +// TestCase { +// name: "boo" + +// function test_boo() { +// verify(true); +// } + +// TestCase { +// name: "far" + +// function test_far() { +// verify(true); +// } +// } +// } +} + diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test3.qml b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test3.qml new file mode 100644 index 0000000000..3575c6b313 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test3.qml @@ -0,0 +1,30 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + function test_bolle() { + verify(true, "verifying true"); + } + + function test_str() { + compare("hallo", "hallo"); + } +} + diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/main.cpp b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/main.cpp new file mode 100644 index 0000000000..e496b3eb65 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/main.cpp @@ -0,0 +1,3 @@ +#include + +QUICK_TEST_MAIN(blob2) diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/quickauto2.pro b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/quickauto2.pro new file mode 100644 index 0000000000..61c76d1562 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/quickauto2.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = test_mal_qtquick + +CONFIG += warn_on qmltestcase + +DISTFILES += \ + tst_test1.qml \ + tst_test2.qml + +SOURCES += \ + main.cpp diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/tst_test1.qml b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/tst_test1.qml new file mode 100644 index 0000000000..8bf1379dc9 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/tst_test1.qml @@ -0,0 +1,33 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + name: "Banana" + + function test_math() { + compare(5 + 5, 10, "verifying 5 + 5 = 10"); + compare(10 - 5, 5, "verifying 10 - 5 = 5"); + } + + function test_fail() { + verify(false, "verifying false"); + } +} + diff --git a/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/tst_test2.qml b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/tst_test2.qml new file mode 100644 index 0000000000..a72913a84e --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto2/tst_test2.qml @@ -0,0 +1,33 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +import QtQuick 2.0 +import QtTest 1.0 + +Rectangle { + TestCase { + name: "nestedTC" + + function test_str() { + var bla = String(); + bla = bla.concat("Hello", " ", "World"); + var blubb = String("Hello World"); + compare(blubb, bla, "Comparing concat"); + verify(blubb == bla, "Comparing concat equality") + } + } +} diff --git a/plugins/autotest/unit_test/mixed_atp/tests/tests.pro b/plugins/autotest/unit_test/mixed_atp/tests/tests.pro new file mode 100644 index 0000000000..f1633f70c9 --- /dev/null +++ b/plugins/autotest/unit_test/mixed_atp/tests/tests.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += auto + diff --git a/plugins/autotest/unit_test/plain/plain.pro b/plugins/autotest/unit_test/plain/plain.pro new file mode 100644 index 0000000000..07cbd33922 --- /dev/null +++ b/plugins/autotest/unit_test/plain/plain.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += test_plain + diff --git a/plugins/autotest/unit_test/plain/test_plain/test_plain.pro b/plugins/autotest/unit_test/plain/test_plain/test_plain.pro new file mode 100644 index 0000000000..1e8994b34c --- /dev/null +++ b/plugins/autotest/unit_test/plain/test_plain/test_plain.pro @@ -0,0 +1,13 @@ +QT += testlib +QT += gui +CONFIG += qt warn_on depend_includepath testcase + +TEMPLATE = app + +SOURCES += \ + tst_simple.cpp + +HEADERS += \ + tst_simple.h + +TARGET = totallyDifferentName diff --git a/plugins/autotest/unit_test/plain/test_plain/tst_simple.cpp b/plugins/autotest/unit_test/plain/test_plain/tst_simple.cpp new file mode 100644 index 0000000000..785aa6a1c8 --- /dev/null +++ b/plugins/autotest/unit_test/plain/test_plain/tst_simple.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ +#include "tst_simple.h" +#include + +namespace Foo { +namespace Bar { + +class bla : public QObject +{ + Q_OBJECT + +public: + bla() {} + ~bla() {} + +private slots: + void tst_dummy() {} + +}; + +class anotherBla : public QObject +{ + Q_OBJECT + +private slots: + void init() {} + void cleanup() {} + + void tst_bla() {} + void test_foo() {} + void test_bar() {} + void tst_batz() {} + void test_hello() {} + void test_io() { qDebug("ä");} +}; + +} // namespace Foo +} // namespace Bar + +int main(int argc, char* argv[]) +{ + Foo::Bar::anotherBla *x2 = new Foo::Bar::anotherBla; + int result = QTest::qExec(x2, argc, argv); +// multiple QTest::qExec() calls actually do not work +// result += QTest::qExec(new Foo::Bar::bla, argc, argv); + return result; +} + +#include "tst_simple.moc" diff --git a/plugins/autotest/unit_test/plain/test_plain/tst_simple.h b/plugins/autotest/unit_test/plain/test_plain/tst_simple.h new file mode 100644 index 0000000000..25523237cb --- /dev/null +++ b/plugins/autotest/unit_test/plain/test_plain/tst_simple.h @@ -0,0 +1,4 @@ +#ifndef TST_SIMPLE_H +#define TST_SIMPLE_H +#include +#endif // TST_SIMPLE_H -- cgit v1.2.3