diff options
author | Kai Koehne <kai.koehne@digia.com> | 2014-05-16 13:11:26 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@digia.com> | 2014-05-21 16:44:49 +0200 |
commit | 472a8e5f484320f41853d0abcaa0d86f6d0d4095 (patch) | |
tree | c5149d98eed6b54fa87e70d1ed34739ef5146977 /src/plugins/qtsupport | |
parent | ff91b728aed93d16705959914f2674ea058adbcf (diff) | |
download | qt-creator-472a8e5f484320f41853d0abcaa0d86f6d0d4095.tar.gz |
Add unit testing for QtOutputFormatter
Mainly adds infrastructure to be able to test the matchLine, handleLink
methods.
Change-Id: I70aa2f84b520ad7c0cf84369afcf7bb8f7efab85
Reviewed-by: Alessandro Portale <alessandro.portale@digia.com>
Diffstat (limited to 'src/plugins/qtsupport')
-rw-r--r-- | src/plugins/qtsupport/qtoutputformatter.cpp | 103 | ||||
-rw-r--r-- | src/plugins/qtsupport/qtoutputformatter.h | 8 | ||||
-rw-r--r-- | src/plugins/qtsupport/qtsupportplugin.h | 2 |
3 files changed, 110 insertions, 3 deletions
diff --git a/src/plugins/qtsupport/qtoutputformatter.cpp b/src/plugins/qtsupport/qtoutputformatter.cpp index 14549186e1..4a4831bdc2 100644 --- a/src/plugins/qtsupport/qtoutputformatter.cpp +++ b/src/plugins/qtsupport/qtoutputformatter.cpp @@ -196,7 +196,7 @@ void QtOutputFormatter::handleLink(const QString &href) const int line = qmlLineColumnLink.cap(2).toInt(); const int column = qmlLineColumnLink.cap(3).toInt(); - Core::EditorManager::openEditorAt(m_projectFinder.findFile(fileUrl), line, column - 1); + openEditor(m_projectFinder.findFile(fileUrl), line, column - 1); return; } @@ -207,7 +207,7 @@ void QtOutputFormatter::handleLink(const QString &href) if (qmlLineLink.indexIn(href) != -1) { const QUrl fileUrl = QUrl(qmlLineLink.cap(1)); const int line = qmlLineLink.cap(2).toInt(); - Core::EditorManager::openEditorAt(m_projectFinder.findFile(fileUrl), line); + openEditor(m_projectFinder.findFile(m_projectFinder.findFile(fileUrl)), line); return; } @@ -234,7 +234,7 @@ void QtOutputFormatter::handleLink(const QString &href) if (!fileName.isEmpty()) { fileName = m_projectFinder.findFile(QUrl::fromLocalFile(fileName)); - Core::EditorManager::openEditorAt(fileName, line); + openEditor(fileName, line); return; } } @@ -246,8 +246,105 @@ void QtOutputFormatter::clearLastLine() m_lastLine.clear(); } +void QtOutputFormatter::openEditor(const QString &fileName, int line, int column) +{ + Core::EditorManager::openEditorAt(fileName, line, column); +} + void QtOutputFormatter::updateProjectFileList() { if (m_project) m_projectFinder.setProjectFiles(m_project.data()->files(Project::ExcludeGeneratedFiles)); } + +// Unit tests: + +#ifdef WITH_TESTS + +# include <QTest> + +# include "qtsupportplugin.h" + +using namespace QtSupport::Internal; + +class TestQtOutputFormatter : public QtOutputFormatter +{ +public: + TestQtOutputFormatter() : + QtOutputFormatter(0), + line(-1), + column(-1) + { + } + + void openEditor(const QString &fileName, int line, int column = -1) + { + this->fileName = fileName; + this->line = line; + this->column = column; + } + +public: + QString fileName; + int line; + int column; +}; + + +void QtSupportPlugin::testQtOutputFormatter_data() +{ + QTest::addColumn<QString>("input"); + + // matchLine results + QTest::addColumn<int>("linkStart"); + QTest::addColumn<int>("linkEnd"); + QTest::addColumn<QString>("href"); + + // handleLink results + QTest::addColumn<QString>("file"); + QTest::addColumn<int>("line"); + QTest::addColumn<int>("column"); + + QTest::newRow("pass through") + << QString::fromLatin1("Pass through plain text.") + << -1 << -1 << QString() + << QString() << -1 << -1; + + QTest::newRow("qrc:///main.qml:20") + << QString::fromLatin1("qrc:///main.qml:20 Unexpected token `identifier'") + << 0 << 18 << QString::fromLatin1("qrc:///main.qml:20") + << QString::fromLatin1("/main.qml") << 20 << -1; + + QTest::newRow("file:///main.qml:20") + << QString::fromLatin1("file:///main.qml:20 Unexpected token `identifier'") + << 0 << 19 << QString::fromLatin1("file:///main.qml:20") + << QString::fromLatin1("/main.qml") << 20 << -1; +} + +void QtSupportPlugin::testQtOutputFormatter() +{ + QFETCH(QString, input); + + QFETCH(int, linkStart); + QFETCH(int, linkEnd); + QFETCH(QString, href); + + QFETCH(QString, file); + QFETCH(int, line); + QFETCH(int, column); + + TestQtOutputFormatter formatter; + + LinkResult result = formatter.matchLine(input); + formatter.handleLink(result.href); + + QCOMPARE(result.start, linkStart); + QCOMPARE(result.end, linkEnd); + QCOMPARE(result.href, href); + + QCOMPARE(formatter.fileName, file); + QCOMPARE(formatter.line, line); + QCOMPARE(formatter.column, column); +} + +#endif // WITH_TESTS diff --git a/src/plugins/qtsupport/qtoutputformatter.h b/src/plugins/qtsupport/qtoutputformatter.h index 4bdd606e26..c50a531d2f 100644 --- a/src/plugins/qtsupport/qtoutputformatter.h +++ b/src/plugins/qtsupport/qtoutputformatter.h @@ -51,6 +51,10 @@ struct LinkResult QString href; }; +namespace Internal { + class QtSupportPlugin; +} + class QTSUPPORT_EXPORT QtOutputFormatter : public Utils::OutputFormatter { @@ -64,6 +68,7 @@ public: protected: void clearLastLine(); + virtual void openEditor(const QString &fileName, int line, int column = -1); private slots: void updateProjectFileList(); @@ -81,6 +86,9 @@ private: QPointer<ProjectExplorer::Project> m_project; QString m_lastLine; Utils::FileInProjectFinder m_projectFinder; + + // for testing + friend class Internal::QtSupportPlugin; }; diff --git a/src/plugins/qtsupport/qtsupportplugin.h b/src/plugins/qtsupport/qtsupportplugin.h index d8459a3e68..60da520200 100644 --- a/src/plugins/qtsupport/qtsupportplugin.h +++ b/src/plugins/qtsupport/qtsupportplugin.h @@ -53,6 +53,8 @@ private slots: #ifdef WITH_TESTS void testQtOutputParser_data(); void testQtOutputParser(); + void testQtOutputFormatter_data(); + void testQtOutputFormatter(); #endif }; |