| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include "util.h" |
| 30 | |
| 31 | #include <qtest.h> |
| 32 | #include <QLibraryInfo> |
| 33 | #include <QDir> |
| 34 | #include <QProcess> |
| 35 | #include <QDebug> |
| 36 | #include <cstdlib> |
| 37 | |
| 38 | class tst_qmlplugindump : public QQmlDataTest |
| 39 | { |
| 40 | Q_OBJECT |
| 41 | public: |
| 42 | tst_qmlplugindump(); |
| 43 | |
| 44 | private slots: |
| 45 | void initTestCase(); |
| 46 | void builtins(); |
| 47 | void singleton(); |
| 48 | void compositeWithinSingleton(); |
| 49 | void compositeWithEnum(); |
| 50 | |
| 51 | void plugin_data(); |
| 52 | void plugin(); |
| 53 | |
| 54 | private: |
| 55 | QString qmlplugindumpPath; |
| 56 | }; |
| 57 | |
| 58 | tst_qmlplugindump::tst_qmlplugindump() |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | void tst_qmlplugindump::initTestCase() |
| 63 | { |
| 64 | QQmlDataTest::initTestCase(); |
| 65 | qmlplugindumpPath = QLibraryInfo::location(QLibraryInfo::BinariesPath); |
| 66 | |
| 67 | #if defined(Q_OS_WIN) |
| 68 | qmlplugindumpPath += QLatin1String("/qmlplugindump.exe" ); |
| 69 | #else |
| 70 | qmlplugindumpPath += QLatin1String("/qmlplugindump" ); |
| 71 | #endif |
| 72 | |
| 73 | if (!QFileInfo(qmlplugindumpPath).exists()) { |
| 74 | QString message = QString::fromLatin1(str: "qmlplugindump executable not found (looked for %0)" ) |
| 75 | .arg(a: qmlplugindumpPath); |
| 76 | QFAIL(qPrintable(message)); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void tst_qmlplugindump::builtins() |
| 81 | { |
| 82 | QProcess dumper; |
| 83 | QStringList args; |
| 84 | args += QLatin1String("-builtins" ); |
| 85 | dumper.start(program: qmlplugindumpPath, arguments: args); |
| 86 | dumper.waitForFinished(); |
| 87 | |
| 88 | if (dumper.error() != QProcess::UnknownError |
| 89 | || dumper.exitStatus() != QProcess::NormalExit) { |
| 90 | qWarning() << QString("Error while running '%1 %2'" ).arg( |
| 91 | args&: qmlplugindumpPath, args: args.join(sep: QLatin1Char(' '))); |
| 92 | } |
| 93 | |
| 94 | if (dumper.error() == QProcess::FailedToStart) { |
| 95 | QFAIL("failed to start" ); |
| 96 | } |
| 97 | if (dumper.error() == QProcess::Crashed) { |
| 98 | qWarning() << "stderr:\n" << dumper.readAllStandardError(); |
| 99 | QFAIL("crashed" ); |
| 100 | } |
| 101 | |
| 102 | QCOMPARE(dumper.error(), QProcess::UnknownError); |
| 103 | QCOMPARE(dumper.exitStatus(), QProcess::NormalExit); |
| 104 | |
| 105 | const QString &result = dumper.readAllStandardOutput(); |
| 106 | QVERIFY(result.contains(QLatin1String("Module {" ))); |
| 107 | } |
| 108 | |
| 109 | void tst_qmlplugindump::singleton() |
| 110 | { |
| 111 | QProcess dumper; |
| 112 | QStringList args; |
| 113 | args << QLatin1String("dumper.CompositeSingleton" ) << QLatin1String("1.0" ) |
| 114 | << QLatin1String(QT_QMLTEST_DIR "/data" ); |
| 115 | dumper.start(program: qmlplugindumpPath, arguments: args); |
| 116 | QVERIFY2(dumper.waitForStarted(), qPrintable(dumper.errorString())); |
| 117 | QVERIFY2(dumper.waitForFinished(), qPrintable(dumper.errorString())); |
| 118 | |
| 119 | const QString &result = dumper.readAllStandardOutput(); |
| 120 | QVERIFY2(result.contains(QLatin1String("exports: [\"Singleton 1.0\"]" )), qPrintable(result)); |
| 121 | QVERIFY2(result.contains(QLatin1String("exportMetaObjectRevisions: [0]" )), qPrintable(result)); |
| 122 | } |
| 123 | |
| 124 | void tst_qmlplugindump::compositeWithinSingleton() |
| 125 | { |
| 126 | QProcess dumper; |
| 127 | QStringList args; |
| 128 | args << QLatin1String("dumper.CompositeWithinSingleton" ) << QLatin1String("1.0" ) |
| 129 | << QLatin1String(QT_QMLTEST_DIR "/data" ); |
| 130 | dumper.start(program: qmlplugindumpPath, arguments: args); |
| 131 | QVERIFY2(dumper.waitForStarted(), qPrintable(dumper.errorString())); |
| 132 | QVERIFY2(dumper.waitForFinished(), qPrintable(dumper.errorString())); |
| 133 | |
| 134 | const QString &result = dumper.readAllStandardOutput(); |
| 135 | QVERIFY2(result.contains(QLatin1String("exports: [\"Composite 1.0\"]" )), qPrintable(result)); |
| 136 | QVERIFY2(result.contains(QLatin1String("exportMetaObjectRevisions: [0]" )), qPrintable(result)); |
| 137 | } |
| 138 | |
| 139 | void tst_qmlplugindump::compositeWithEnum() |
| 140 | { |
| 141 | QProcess dumper; |
| 142 | QStringList args; |
| 143 | args << QLatin1String("dumper.CompositeWithEnum" ) << QLatin1String("1.0" ) |
| 144 | << QLatin1String(QT_QMLTEST_DIR "/data" ); |
| 145 | dumper.start(program: qmlplugindumpPath, arguments: args); |
| 146 | QVERIFY2(dumper.waitForStarted(), qPrintable(dumper.errorString())); |
| 147 | QVERIFY2(dumper.waitForFinished(), qPrintable(dumper.errorString())); |
| 148 | |
| 149 | const QString &result = dumper.readAllStandardOutput(); |
| 150 | QVERIFY2(result.contains(QLatin1String("exports: [\"Animal 1.0\"]" )), qPrintable(result)); |
| 151 | QVERIFY2(result.contains(QLatin1String("Enum {" )), qPrintable(result)); |
| 152 | } |
| 153 | |
| 154 | void tst_qmlplugindump::plugin_data() |
| 155 | { |
| 156 | QTest::addColumn<QString>(name: "import" ); |
| 157 | QTest::addColumn<QString>(name: "version" ); |
| 158 | QTest::addColumn<QString>(name: "expectedPath" ); |
| 159 | |
| 160 | QTest::newRow(dataTag: "dumper.Dummy" ) << "dumper.Dummy" << "1.0" << testFile(fileName: "dumper/Dummy/plugins.qmltypes" ); |
| 161 | QTest::newRow(dataTag: "dumper.Imports" ) << "dumper.Imports" << "1.0" << testFile(fileName: "dumper/Imports/plugins.qmltypes" ); |
| 162 | QTest::newRow(dataTag: "dumper.Versions" ) << "dumper.Versions" << "1.1" << testFile(fileName: "dumper/Versions/plugins.qmltypes" ); |
| 163 | QTest::newRow(dataTag: "dumper.ExtendedType" ) << "dumper.ExtendedType" |
| 164 | << "1.1" << testFile(fileName: "dumper/ExtendedType/plugins.qmltypes" ); |
| 165 | } |
| 166 | |
| 167 | void tst_qmlplugindump::plugin() |
| 168 | { |
| 169 | QFETCH(QString, import); |
| 170 | QFETCH(QString, version); |
| 171 | QFETCH(QString, expectedPath); |
| 172 | |
| 173 | QProcess dumper; |
| 174 | dumper.setWorkingDirectory(dataDirectory()); |
| 175 | QStringList args = { QLatin1String("-nonrelocatable" ), QLatin1String("-noforceqtquick" ), import, version, QLatin1String("." ) }; |
| 176 | dumper.start(program: qmlplugindumpPath, arguments: args); |
| 177 | QVERIFY2(dumper.waitForStarted(), qPrintable(dumper.errorString())); |
| 178 | QVERIFY2(dumper.waitForFinished(), qPrintable(dumper.errorString())); |
| 179 | |
| 180 | const QString &result = dumper.readAllStandardOutput(); |
| 181 | QFile expectedFile(expectedPath); |
| 182 | QVERIFY2(expectedFile.open(QIODevice::ReadOnly), qPrintable(expectedFile.errorString())); |
| 183 | const QString expected = expectedFile.readAll(); |
| 184 | QCOMPARE(result, expected); |
| 185 | } |
| 186 | |
| 187 | QTEST_MAIN(tst_qmlplugindump) |
| 188 | |
| 189 | #include "tst_qmlplugindump.moc" |
| 190 | |