QtQml tests: remove QSKIP -> wrap within !QTEST_CROSS_COMPILED guards
[profile/ivi/qtdeclarative.git] / tests / auto / qml / qmlmin / tst_qmlmin.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qtest.h>
43 #include <QLibraryInfo>
44 #include <QDir>
45 #include <QProcess>
46 #include <QDebug>
47 #include <QQmlError>
48 #include <cstdlib>
49
50 class tst_qmlmin : public QObject
51 {
52     Q_OBJECT
53 public:
54     tst_qmlmin();
55
56 private slots:
57     void initTestCase();
58 #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
59     void qmlMinify_data();
60     void qmlMinify();
61 #endif
62
63 private:
64     QString qmlminPath;
65     QStringList excludedDirs;
66     QStringList invalidFiles;
67
68     QStringList findFiles(const QDir &);
69     bool isInvalidFile(const QFileInfo &fileName) const;
70 };
71
72 tst_qmlmin::tst_qmlmin()
73 {
74 }
75
76 void tst_qmlmin::initTestCase()
77 {
78     qmlminPath = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/qmlmin");
79 #ifdef Q_OS_WIN
80     qmlminPath += QLatin1String(".exe");
81 #endif
82     if (!QFileInfo(qmlminPath).exists()) {
83         QString message = QString::fromLatin1("qmlmin executable not found (looked for %0)")
84                 .arg(qmlminPath);
85         QFAIL(qPrintable(message));
86     }
87
88     // Add directories you want excluded here
89
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";
97
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";
123 }
124
125 QStringList tst_qmlmin::findFiles(const QDir &d)
126 {
127     for (int ii = 0; ii < excludedDirs.count(); ++ii) {
128         QString s = excludedDirs.at(ii);
129         if (d.absolutePath().endsWith(s))
130             return QStringList();
131     }
132
133     QStringList rv;
134
135     QStringList files = d.entryList(QStringList() << QLatin1String("*.qml") << QLatin1String("*.js"),
136                                     QDir::Files);
137     foreach (const QString &file, files) {
138         rv << d.absoluteFilePath(file);
139     }
140
141     QStringList dirs = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot |
142                                    QDir::NoSymLinks);
143     foreach (const QString &dir, dirs) {
144         QDir sub = d;
145         sub.cd(dir);
146         rv << findFiles(sub);
147     }
148
149     return rv;
150 }
151
152 bool tst_qmlmin::isInvalidFile(const QFileInfo &fileName) const
153 {
154     foreach (const QString &invalidFile, invalidFiles) {
155         if (fileName.absoluteFilePath().endsWith(invalidFile))
156             return true;
157     }
158     return false;
159 }
160
161 /*
162 This test runs all the examples in the QtQml UI source tree and ensures
163 that they start and exit cleanly.
164
165 Examples are any .qml files under the examples/ directory that start
166 with a lower case letter.
167 */
168
169 #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
170 void tst_qmlmin::qmlMinify_data()
171 {
172     QTest::addColumn<QString>("file");
173
174     QString examples = QLatin1String(SRCDIR) + "/../../../../examples/";
175     QString tests = QLatin1String(SRCDIR) + "/../../../../tests/";
176
177     QStringList files;
178     files << findFiles(QDir(examples));
179     files << findFiles(QDir(tests));
180
181     foreach (const QString &file, files)
182         QTest::newRow(qPrintable(file)) << file;
183 }
184 #endif
185
186 #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
187 void tst_qmlmin::qmlMinify()
188 {
189     QFETCH(QString, file);
190
191     QProcess qmlminify;
192
193     // Restrict line width to 100 characters
194     qmlminify.start(qmlminPath, QStringList() << QLatin1String("--verify-only") << QLatin1String("-w100") << file);
195     qmlminify.waitForFinished();
196
197     QCOMPARE(qmlminify.error(), QProcess::UnknownError);
198     QCOMPARE(qmlminify.exitStatus(), QProcess::NormalExit);
199
200     if (isInvalidFile(file))
201         QCOMPARE(qmlminify.exitCode(), EXIT_FAILURE); // cannot minify files with syntax errors
202     else
203         QCOMPARE(qmlminify.exitCode(), 0);
204 }
205 #endif
206
207 QTEST_MAIN(tst_qmlmin)
208
209 #include "tst_qmlmin.moc"