diff options
author | Marco Benelli <marco.benelli@qt.io> | 2016-06-15 13:07:10 +0200 |
---|---|---|
committer | Marco Benelli <marco.benelli@qt.io> | 2016-06-21 07:40:03 +0000 |
commit | 2d03eb8bb9d31b42b68005d0823e8cad4337c2ea (patch) | |
tree | 24271b7479a070f4883e700a7e1c83dbf7554593 /tests/auto | |
parent | 28c841279773ad602868a3fa4411f55f7c647bd5 (diff) | |
download | qt-creator-2d03eb8bb9d31b42b68005d0823e8cad4337c2ea.tar.gz |
QmlJs code model: added test cases.
Added test cases and modified the test suite in order to make it
data-driven. Each sample file can now declare the number of
expected messages. If there is no declaration, zero is assumed.
Change-Id: Ife3daa10a258f51ea8f896156f6f6af783406b84
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@theqtcompany.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qml/codemodel/dependencies/samples/test_ApplicationWindow.qml (renamed from tests/auto/qml/codemodel/dependencies/samples/001_ApplicationWindow.qml) | 0 | ||||
-rw-r--r-- | tests/auto/qml/codemodel/dependencies/samples/test_Button.qml | 33 | ||||
-rw-r--r-- | tests/auto/qml/codemodel/dependencies/samples/test_ListModel.qml | 43 | ||||
-rw-r--r-- | tests/auto/qml/codemodel/dependencies/samples/test_ListView.qml | 35 | ||||
-rw-r--r-- | tests/auto/qml/codemodel/dependencies/samples/test_MessageDialog.qml | 37 | ||||
-rw-r--r-- | tests/auto/qml/codemodel/dependencies/samples/test_ObjectModel.qml | 41 | ||||
-rw-r--r-- | tests/auto/qml/codemodel/dependencies/samples/test_SampleLib.qml (renamed from tests/auto/qml/codemodel/dependencies/samples/SampleLib.qml) | 0 | ||||
-rw-r--r-- | tests/auto/qml/codemodel/dependencies/samples/test_Window.qml (renamed from tests/auto/qml/codemodel/dependencies/samples/002_Window.qml) | 3 | ||||
-rw-r--r-- | tests/auto/qml/codemodel/dependencies/tst_dependencies.cpp | 74 |
9 files changed, 246 insertions, 20 deletions
diff --git a/tests/auto/qml/codemodel/dependencies/samples/001_ApplicationWindow.qml b/tests/auto/qml/codemodel/dependencies/samples/test_ApplicationWindow.qml index 6c55b2e8ab..6c55b2e8ab 100644 --- a/tests/auto/qml/codemodel/dependencies/samples/001_ApplicationWindow.qml +++ b/tests/auto/qml/codemodel/dependencies/samples/test_ApplicationWindow.qml diff --git a/tests/auto/qml/codemodel/dependencies/samples/test_Button.qml b/tests/auto/qml/codemodel/dependencies/samples/test_Button.qml new file mode 100644 index 0000000000..22fa08d7ab --- /dev/null +++ b/tests/auto/qml/codemodel/dependencies/samples/test_Button.qml @@ -0,0 +1,33 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 +** 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. +** +** 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. +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 1.4 + +Button { + text: "Button" + antialiasing: true + scale: 1.0 +} diff --git a/tests/auto/qml/codemodel/dependencies/samples/test_ListModel.qml b/tests/auto/qml/codemodel/dependencies/samples/test_ListModel.qml new file mode 100644 index 0000000000..189e83b67d --- /dev/null +++ b/tests/auto/qml/codemodel/dependencies/samples/test_ListModel.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 +** 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. +** +** 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. +** +****************************************************************************/ + +import QtQuick 2.4 + +ListModel { + id: fruitModel + + ListElement { + name: "Apple" + cost: 2.45 + } + ListElement { + name: "Orange" + cost: 3.25 + } + ListElement { + name: "Banana" + cost: 1.95 + } +} diff --git a/tests/auto/qml/codemodel/dependencies/samples/test_ListView.qml b/tests/auto/qml/codemodel/dependencies/samples/test_ListView.qml new file mode 100644 index 0000000000..c347a566f1 --- /dev/null +++ b/tests/auto/qml/codemodel/dependencies/samples/test_ListView.qml @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 +** 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. +** +** 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. +** +****************************************************************************/ + +import QtQuick 2.4 + +ListView { + anchors.fill: parent + model: fruitModel + delegate: Row { + Text { text: "Fruit: " + name } + Text { text: "Cost: $" + cost } + } +} diff --git a/tests/auto/qml/codemodel/dependencies/samples/test_MessageDialog.qml b/tests/auto/qml/codemodel/dependencies/samples/test_MessageDialog.qml new file mode 100644 index 0000000000..dd112166cb --- /dev/null +++ b/tests/auto/qml/codemodel/dependencies/samples/test_MessageDialog.qml @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 +** 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. +** +** 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. +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Dialogs 1.1 + +MessageDialog { + id: messageDialog + title: "May I have your attention please" + text: "It's so cool that you are using Qt Quick." + onAccepted: { + console.log("And of course you could only agree.") + Qt.quit() + } +} diff --git a/tests/auto/qml/codemodel/dependencies/samples/test_ObjectModel.qml b/tests/auto/qml/codemodel/dependencies/samples/test_ObjectModel.qml new file mode 100644 index 0000000000..df03ba0339 --- /dev/null +++ b/tests/auto/qml/codemodel/dependencies/samples/test_ObjectModel.qml @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 +** 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. +** +** 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. +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQml.Models 2.2 + +Rectangle { + ObjectModel { + id: itemModel + Rectangle { height: 30; width: 80; color: "red" } + Rectangle { height: 30; width: 80; color: "green" } + Rectangle { height: 30; width: 80; color: "blue" } + } + + ListView { + anchors.fill: parent + model: itemModel + } +} diff --git a/tests/auto/qml/codemodel/dependencies/samples/SampleLib.qml b/tests/auto/qml/codemodel/dependencies/samples/test_SampleLib.qml index 2495247708..2495247708 100644 --- a/tests/auto/qml/codemodel/dependencies/samples/SampleLib.qml +++ b/tests/auto/qml/codemodel/dependencies/samples/test_SampleLib.qml diff --git a/tests/auto/qml/codemodel/dependencies/samples/002_Window.qml b/tests/auto/qml/codemodel/dependencies/samples/test_Window.qml index 71dbbd2b7b..813161ef80 100644 --- a/tests/auto/qml/codemodel/dependencies/samples/002_Window.qml +++ b/tests/auto/qml/codemodel/dependencies/samples/test_Window.qml @@ -23,6 +23,9 @@ ** ****************************************************************************/ +// ExpectedSemanticMessages: 0 +// ExpectedStaticMessages: 1 + import QtQuick 2.4 import QtQuick.Controls 1.3 diff --git a/tests/auto/qml/codemodel/dependencies/tst_dependencies.cpp b/tests/auto/qml/codemodel/dependencies/tst_dependencies.cpp index ffa9e2f1eb..16d0aa64fc 100644 --- a/tests/auto/qml/codemodel/dependencies/tst_dependencies.cpp +++ b/tests/auto/qml/codemodel/dependencies/tst_dependencies.cpp @@ -52,15 +52,48 @@ using namespace QmlJS; using namespace QmlJS::AST; using namespace QmlJS::StaticAnalysis; -static Document::MutablePtr readDocument(const QString &path) +static QString getValue(const QString &data, + const QString &re, + const QString &defaultValue = QString::number(0)) { + const QRegularExpressionMatch m = QRegularExpression(re).match(data); + return m.hasMatch() ? m.captured(1) : defaultValue; +} + +struct TestData { - Document::MutablePtr doc = Document::create(path, Dialect::Qml); - QFile file(doc->fileName()); + TestData(Document::MutablePtr document, int nSemanticMessages, int nStaticMessages) + : doc(document) + , semanticMessages(nSemanticMessages) + , staticMessages(nStaticMessages) + {} + Document::MutablePtr doc; + const int semanticMessages; + const int staticMessages; +}; + +static TestData testData(const QString &path) { + QFile file(path); file.open(QFile::ReadOnly | QFile::Text); - doc->setSource(file.readAll()); + const QString content = QString(file.readAll()); file.close(); + + Document::MutablePtr doc = Document::create(path, Dialect::Qml); + doc->setSource(content); doc->parse(); - return doc; + const QString nSemantic = getValue(content, "//\\s*ExpectedSemanticMessages: (\\d+)"); + const QString nStatic = getValue(content, "//\\s*ExpectedStaticMessages: (\\d+)"); + return TestData(doc, nSemantic.toInt(), nStatic.toInt()); +} + +void printUnexpectedMessages(const QmlJSTools::SemanticInfo &info, int nSemantic, int nStatic) +{ + if (nSemantic == 0 && info.semanticMessages.length() > 0) + for (auto msg: info.semanticMessages) + qDebug() << msg.message; + if (nStatic == 0 && info.staticAnalysisMessages.length() > 0) + for (auto msg: info.staticAnalysisMessages) + qDebug() << msg.message; + return; } class tst_Dependencies : public QObject @@ -97,21 +130,17 @@ void tst_Dependencies::test_data() QTest::addColumn<int>("nSemanticMessages"); QTest::addColumn<int>("nStaticMessages"); - QTest::newRow("ApplicationWindow") - << QString(m_path + QLatin1String("/001_ApplicationWindow.qml")) - << 0 - << 0; - QTest::newRow("Window") - << QString(m_path + QLatin1String("/002_Window.qml")) - << 0 - << 1; + QDirIterator it(m_path, QDir::Files); + while (it.hasNext()) { + const QString &filepath = it.next(); + const QString name = getValue(filepath, ".*/(.*).qml", filepath); + QTest::newRow(name.toLatin1().data()) << filepath; + } } void tst_Dependencies::test() { QFETCH(QString, filename); - QFETCH(int, nSemanticMessages); - QFETCH(int, nStaticMessages); ModelManagerInterface *modelManager = ModelManagerInterface::instance(); @@ -124,8 +153,10 @@ void tst_Dependencies::test() ModelManagerInterface::importScan(result, ModelManagerInterface::workingCopy(), lPaths, ModelManagerInterface::instance(), false); - - Document::MutablePtr doc = readDocument(filename); + TestData data = testData(filename); + Document::MutablePtr doc = data.doc; + int nExpectedSemanticMessages = data.semanticMessages; + int nExpectedStaticMessages = data.staticMessages; QVERIFY(!doc->source().isEmpty()); Snapshot snapshot = modelManager->snapshot(); @@ -134,7 +165,8 @@ void tst_Dependencies::test() semanticInfo.document = doc; semanticInfo.snapshot = snapshot; - Link link(semanticInfo.snapshot, modelManager->defaultVContext(doc->language(), doc), modelManager->builtins(doc)); + Link link(semanticInfo.snapshot, modelManager->defaultVContext(doc->language(), doc), + modelManager->builtins(doc)); semanticInfo.context = link(doc, &semanticInfo.semanticMessages); @@ -144,8 +176,10 @@ void tst_Dependencies::test() Check checker(doc, semanticInfo.context); semanticInfo.staticAnalysisMessages = checker(); - QCOMPARE(semanticInfo.semanticMessages.length(), nSemanticMessages); - QCOMPARE(semanticInfo.staticAnalysisMessages.length(), nStaticMessages); + printUnexpectedMessages(semanticInfo, nExpectedSemanticMessages, nExpectedStaticMessages); + + QCOMPARE(semanticInfo.semanticMessages.length(), nExpectedSemanticMessages); + QCOMPARE(semanticInfo.staticAnalysisMessages.length(), nExpectedStaticMessages); } QTEST_MAIN(tst_Dependencies) |