tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QFile>
       
    43 #include <QtTest/QtTest>
       
    44 
       
    45 #ifdef QTEST_XMLPATTERNS
       
    46 
       
    47 #include "../qxmlquery/TestFundament.h"
       
    48 #include "../network-settings.h"
       
    49 
       
    50 /*!
       
    51  \class tst_XmlPatterns
       
    52  \internal
       
    53  \since 4.6
       
    54  \brief Tests the command line interface, \c xmlpatternsvalidator, for the XML validation code.
       
    55  */
       
    56 class tst_XmlPatternsValidator : public QObject
       
    57                                , private TestFundament
       
    58 {
       
    59     Q_OBJECT
       
    60 
       
    61 public:
       
    62     tst_XmlPatternsValidator();
       
    63 
       
    64 private Q_SLOTS:
       
    65     void initTestCase();
       
    66     void xsdSupport();
       
    67     void xsdSupport_data() const;
       
    68 
       
    69 private:
       
    70     const QString   m_command;
       
    71     bool            m_dontRun;
       
    72 };
       
    73 
       
    74 tst_XmlPatternsValidator::tst_XmlPatternsValidator()
       
    75     : m_command(QLatin1String("xmlpatternsvalidator"))
       
    76     , m_dontRun(false)
       
    77 {
       
    78 }
       
    79 
       
    80 void tst_XmlPatternsValidator::initTestCase()
       
    81 {
       
    82     QProcess process;
       
    83     process.start(m_command);
       
    84 
       
    85     if(!process.waitForFinished())
       
    86     {
       
    87         m_dontRun = true;
       
    88         QEXPECT_FAIL("", "The command line tool is not in the path, most likely because Qt "
       
    89                          "has been partically built, such as only the sub-src rule. No tests will be run.", Abort);
       
    90         QVERIFY(false);
       
    91     }
       
    92 }
       
    93 
       
    94 void tst_XmlPatternsValidator::xsdSupport()
       
    95 {
       
    96     if(m_dontRun)
       
    97         QSKIP("The command line utility is not in the path.", SkipAll);
       
    98 
       
    99 #ifdef Q_OS_WINCE
       
   100     QSKIP("WinCE: This test uses unsupported WinCE functionality", SkipAll);
       
   101 #endif
       
   102 
       
   103     QFETCH(int,         expectedExitCode);
       
   104     QFETCH(QStringList, arguments);
       
   105     QFETCH(QString,     cwd);
       
   106 
       
   107     QProcess process;
       
   108 
       
   109     if(!cwd.isEmpty())
       
   110         process.setWorkingDirectory(inputFile(cwd));
       
   111 
       
   112     process.start(m_command, arguments);
       
   113 
       
   114     QCOMPARE(process.exitStatus(), QProcess::NormalExit);
       
   115     QVERIFY(process.waitForFinished());
       
   116 
       
   117     if(process.exitCode() != expectedExitCode)
       
   118         QTextStream(stderr) << "foo:" << process.readAllStandardError();
       
   119 
       
   120     QCOMPARE(process.exitCode(), expectedExitCode);
       
   121 }
       
   122 
       
   123 void tst_XmlPatternsValidator::xsdSupport_data() const
       
   124 {
       
   125 #ifdef Q_OS_WINCE
       
   126     return;
       
   127 #endif
       
   128 
       
   129     QTest::addColumn<int>("expectedExitCode");
       
   130     QTest::addColumn<QStringList>("arguments");
       
   131     QTest::addColumn<QString>("cwd");
       
   132 
       
   133     QTest::newRow("No arguments")
       
   134         << 2
       
   135         << QStringList()
       
   136         << QString();
       
   137 
       
   138     QTest::newRow("A valid schema")
       
   139         << 0
       
   140         << QStringList(QLatin1String("files/valid_schema.xsd"))
       
   141         << QString();
       
   142 
       
   143     QTest::newRow("An invalid schema")
       
   144         << 1
       
   145         << QStringList(QLatin1String("files/invalid_schema.xsd"))
       
   146         << QString();
       
   147 
       
   148     QTest::newRow("An instance and valid schema")
       
   149         << 0
       
   150         << (QStringList() << QLatin1String("files/instance.xml")
       
   151                           << QLatin1String("files/valid_schema.xsd"))
       
   152         << QString();
       
   153 
       
   154     QTest::newRow("An instance and invalid schema")
       
   155         << 1
       
   156         << (QStringList() << QLatin1String("files/instance.xml")
       
   157                           << QLatin1String("files/invalid_schema.xsd"))
       
   158         << QString();
       
   159 
       
   160     QTest::newRow("An instance and not matching schema")
       
   161         << 1
       
   162         << (QStringList() << QLatin1String("files/instance.xml")
       
   163                           << QLatin1String("files/other_valid_schema.xsd"))
       
   164         << QString();
       
   165 
       
   166     QTest::newRow("Two instance documents")
       
   167         << 1
       
   168         << (QStringList() << QLatin1String("files/instance.xml")
       
   169                           << QLatin1String("files/instance.xml"))
       
   170         << QString();
       
   171 
       
   172     QTest::newRow("Three instance documents")
       
   173         << 2
       
   174         << (QStringList() << QLatin1String("files/instance.xml")
       
   175                           << QLatin1String("files/instance.xml")
       
   176                           << QLatin1String("files/instance.xml"))
       
   177         << QString();
       
   178 
       
   179     QTest::newRow("Two schema documents")
       
   180         << 1
       
   181         << (QStringList() << QLatin1String("files/valid_schema.xsd")
       
   182                           << QLatin1String("files/valid_schema.xsd"))
       
   183         << QString();
       
   184 
       
   185     QTest::newRow("A schema aware valid instance document")
       
   186         << 0
       
   187         << (QStringList() << QLatin1String("files/sa_valid_instance.xml"))
       
   188         << QString();
       
   189 
       
   190     QTest::newRow("A schema aware invalid instance document")
       
   191         << 1
       
   192         << (QStringList() << QLatin1String("files/sa_invalid_instance.xml"))
       
   193         << QString();
       
   194 
       
   195     QTest::newRow("A non-schema aware instance document")
       
   196         << 1
       
   197         << (QStringList() << QLatin1String("files/instance.xml"))
       
   198         << QString();
       
   199 }
       
   200 
       
   201 QTEST_MAIN(tst_XmlPatternsValidator)
       
   202 
       
   203 #include "tst_xmlpatternsvalidator.moc"
       
   204 #else
       
   205 QTEST_NOOP_MAIN
       
   206 #endif
       
   207 
       
   208 // vim: et:ts=4:sw=4:sts=4