diff options
author | Jarek Kobus <jaroslaw.kobus@theqtcompany.com> | 2015-09-01 11:19:25 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2015-09-03 10:10:02 +0300 |
commit | f88ca156bfdf4c944515f417ce729262501c8e9e (patch) | |
tree | a2f536817d12778d7b6acab68fa279eefda5c676 /tests/auto/parser | |
parent | 94a0e31833bde0bfb16f76698d4fbd816d8640ec (diff) |
Add parser auto test
Currently it's checking if the proper error is issued when
transition contains illegal target.
Change-Id: I6f505c6d21037a450188af061ec9b9778b548ec1
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'tests/auto/parser')
-rw-r--r-- | tests/auto/parser/parser.pro | 15 | ||||
-rw-r--r-- | tests/auto/parser/test1.scxml | 7 | ||||
-rw-r--r-- | tests/auto/parser/tst_parser.cpp | 84 | ||||
-rw-r--r-- | tests/auto/parser/tst_parser.qrc | 5 |
4 files changed, 111 insertions, 0 deletions
diff --git a/tests/auto/parser/parser.pro b/tests/auto/parser/parser.pro new file mode 100644 index 0000000..10deb2d --- /dev/null +++ b/tests/auto/parser/parser.pro @@ -0,0 +1,15 @@ +QT = core gui qml testlib scxml +CONFIG += testcase + +TARGET = tst_parser +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + +RESOURCES += tst_parser.qrc + +SOURCES += \ + tst_parser.cpp + +load(qscxmlc) diff --git a/tests/auto/parser/test1.scxml b/tests/auto/parser/test1.scxml new file mode 100644 index 0000000..05c842c --- /dev/null +++ b/tests/auto/parser/test1.scxml @@ -0,0 +1,7 @@ +<?xml version="1.0" ?> +<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" + name="test1"> + <state id="a"> + <transition event="event" target="b"/> + </state> +</scxml> diff --git a/tests/auto/parser/tst_parser.cpp b/tests/auto/parser/tst_parser.cpp new file mode 100644 index 0000000..b22d4e0 --- /dev/null +++ b/tests/auto/parser/tst_parser.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** 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. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <QtTest> +#include <QObject> +#include <QXmlStreamReader> +#include <QtScxml/scxmlparser.h> +#include <QtScxml/scxmlstatemachine.h> + +Q_DECLARE_METATYPE(Scxml::ScxmlError); + +using namespace Scxml; + +class tst_Parser: public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void error_data(); + void error(); +}; + +void tst_Parser::error_data() +{ + QTest::addColumn<QString>("scxmlFileName"); + QTest::addColumn<QVector<Scxml::ScxmlError> >("expectedErrors"); + + QVector<Scxml::ScxmlError> errors; + errors << ScxmlError(QString(":/tst_parser/test1.scxml"), 5, 46, QString("unknown state 'b' in target")); + QTest::newRow("test1") << QString(":/tst_parser/test1.scxml") << errors; +} + +void tst_Parser::error() +{ + QFETCH(QString, scxmlFileName); + QFETCH(QVector<Scxml::ScxmlError>, expectedErrors); + + StateMachine *stateMachine = StateMachine::fromFile(scxmlFileName); + + QVector<Scxml::ScxmlError> errors = stateMachine->errors(); + QCOMPARE(errors.count(), expectedErrors.count()); + + for (int i = 0; i < errors.count(); ++i) { + ScxmlError error = errors.at(i); + ScxmlError expectedError = expectedErrors.at(i); + QCOMPARE(error.fileName(), expectedError.fileName()); + QCOMPARE(error.line(), expectedError.line()); + QCOMPARE(error.column(), expectedError.column()); + QCOMPARE(error.description(), expectedError.description()); + } +} + +QTEST_MAIN(tst_Parser) + +#include "tst_parser.moc" + + diff --git a/tests/auto/parser/tst_parser.qrc b/tests/auto/parser/tst_parser.qrc new file mode 100644 index 0000000..d78f7bc --- /dev/null +++ b/tests/auto/parser/tst_parser.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/tst_parser"> + <file>test1.scxml</file> + </qresource> +</RCC> |