1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include <QLibraryInfo>
50 class tst_qmlmin : public QObject
58 #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
59 void qmlMinify_data();
65 QStringList excludedDirs;
66 QStringList invalidFiles;
68 QStringList findFiles(const QDir &);
69 bool isInvalidFile(const QFileInfo &fileName) const;
72 tst_qmlmin::tst_qmlmin()
76 void tst_qmlmin::initTestCase()
78 qmlminPath = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/qmlmin");
80 qmlminPath += QLatin1String(".exe");
82 if (!QFileInfo(qmlminPath).exists()) {
83 QString message = QString::fromLatin1("qmlmin executable not found (looked for %0)")
85 QFAIL(qPrintable(message));
88 // Add directories you want excluded here
90 // These snippets are not expected to run on their own.
91 excludedDirs << "doc/src/snippets/qml/visualdatamodel_rootindex";
92 excludedDirs << "doc/src/snippets/qml/qtbinding";
93 excludedDirs << "doc/src/snippets/qml/imports";
94 excludedDirs << "doc/src/snippets/qtquick1/visualdatamodel_rootindex";
95 excludedDirs << "doc/src/snippets/qtquick1/qtbinding";
96 excludedDirs << "doc/src/snippets/qtquick1/imports";
98 // Add invalid files (i.e. files with syntax errors)
99 invalidFiles << "tests/auto/quick/qquickloader/data/InvalidSourceComponent.qml";
100 invalidFiles << "tests/auto/qml/qqmllanguage/data/dynamicObjectProperties.2.qml";
101 invalidFiles << "tests/auto/qml/qqmllanguage/data/signal.2.qml";
102 invalidFiles << "tests/auto/qml/qqmllanguage/data/signal.3.qml";
103 invalidFiles << "tests/auto/qml/qqmllanguage/data/signal.5.qml";
104 invalidFiles << "tests/auto/qml/qqmllanguage/data/property.4.qml";
105 invalidFiles << "tests/auto/qml/qqmllanguage/data/empty.qml";
106 invalidFiles << "tests/auto/qml/qqmllanguage/data/missingObject.qml";
107 invalidFiles << "tests/auto/qml/qqmllanguage/data/insertedSemicolon.1.qml";
108 invalidFiles << "tests/auto/qml/qqmllanguage/data/nonexistantProperty.5.qml";
109 invalidFiles << "tests/auto/qml/qqmllanguage/data/invalidRoot.1.qml";
110 invalidFiles << "tests/auto/qml/qquickfolderlistmodel/data/dummy.qml";
111 invalidFiles << "tests/auto/qml/qqmlecmascript/data/qtbug_22843.js";
112 invalidFiles << "tests/auto/qml/qqmlecmascript/data/qtbug_22843.library.js";
113 invalidFiles << "tests/auto/qml/qquickworkerscript/data/script_error_onLoad.js";
114 invalidFiles << "tests/auto/qml/parserstress/tests/ecma_3/Unicode/regress-352044-02-n.js";
115 invalidFiles << "tests/auto/qml/qqmlecmascript/data/jsimportfail/malformedFileQualifier.js";
116 invalidFiles << "tests/auto/qml/qqmlecmascript/data/jsimportfail/malformedImport.js";
117 invalidFiles << "tests/auto/qml/qqmlecmascript/data/jsimportfail/malformedModule.js";
118 invalidFiles << "tests/auto/qml/qqmlecmascript/data/jsimportfail/malformedModuleQualifier.js";
119 invalidFiles << "tests/auto/qml/qqmlecmascript/data/jsimportfail/malformedModuleVersion.js";
120 invalidFiles << "tests/auto/qml/qqmlecmascript/data/jsimportfail/missingFileQualifier.js";
121 invalidFiles << "tests/auto/qml/qqmlecmascript/data/jsimportfail/missingModuleQualifier.js";
122 invalidFiles << "tests/auto/qml/qqmlecmascript/data/jsimportfail/missingModuleVersion.js";
125 QStringList tst_qmlmin::findFiles(const QDir &d)
127 for (int ii = 0; ii < excludedDirs.count(); ++ii) {
128 QString s = excludedDirs.at(ii);
129 if (d.absolutePath().endsWith(s))
130 return QStringList();
135 QStringList files = d.entryList(QStringList() << QLatin1String("*.qml") << QLatin1String("*.js"),
137 foreach (const QString &file, files) {
138 rv << d.absoluteFilePath(file);
141 QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot |
143 foreach (const QString &dir, dirs) {
146 rv << findFiles(sub);
152 bool tst_qmlmin::isInvalidFile(const QFileInfo &fileName) const
154 foreach (const QString &invalidFile, invalidFiles) {
155 if (fileName.absoluteFilePath().endsWith(invalidFile))
162 This test runs all the examples in the QtQml UI source tree and ensures
163 that they start and exit cleanly.
165 Examples are any .qml files under the examples/ directory that start
166 with a lower case letter.
169 #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
170 void tst_qmlmin::qmlMinify_data()
172 QTest::addColumn<QString>("file");
174 QString examples = QLatin1String(SRCDIR) + "/../../../../examples/";
175 QString tests = QLatin1String(SRCDIR) + "/../../../../tests/";
178 files << findFiles(QDir(examples));
179 files << findFiles(QDir(tests));
181 foreach (const QString &file, files)
182 QTest::newRow(qPrintable(file)) << file;
186 #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
187 void tst_qmlmin::qmlMinify()
189 QFETCH(QString, file);
193 // Restrict line width to 100 characters
194 qmlminify.start(qmlminPath, QStringList() << QLatin1String("--verify-only") << QLatin1String("-w100") << file);
195 qmlminify.waitForFinished();
197 QCOMPARE(qmlminify.error(), QProcess::UnknownError);
198 QCOMPARE(qmlminify.exitStatus(), QProcess::NormalExit);
200 if (isInvalidFile(file))
201 QCOMPARE(qmlminify.exitCode(), EXIT_FAILURE); // cannot minify files with syntax errors
203 QCOMPARE(qmlminify.exitCode(), 0);
207 QTEST_MAIN(tst_qmlmin)
209 #include "tst_qmlmin.moc"