1/****************************************************************************
2**
3** Copyright (C) 2017 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 <QtCore>
30#include <QtTest>
31#include <QtQml>
32
33#if defined(Q_OS_WIN)
34# define SUFFIX QLatin1String(".dll")
35# define DEBUG_SUFFIX QLatin1String("d.dll")
36
37#elif defined(Q_OS_DARWIN)
38# define SUFFIX QLatin1String(".dylib")
39# define DEBUG_SUFFIX QLatin1String("_debug.dylib")
40
41# else // Unix
42# define SUFFIX QLatin1String(".so")
43#endif
44
45
46class tst_qqmlextensionplugin : public QObject
47{
48 Q_OBJECT
49
50 static QStringList removeDuplicates(QStringList files) {
51#ifdef DEBUG_SUFFIX
52 const auto isDuplicate = [files] (QString file) {
53# ifdef QT_DEBUG
54 return !file.endsWith(DEBUG_SUFFIX) && files.contains(file.replace(SUFFIX, DEBUG_SUFFIX));
55# else
56 return file.endsWith(DEBUG_SUFFIX) && files.contains(file.replace(DEBUG_SUFFIX, SUFFIX));
57# endif
58 };
59
60 files.erase(std::remove_if(files.begin(), files.end(), isDuplicate),
61 files.end());
62
63#endif
64 return files;
65 }
66
67public:
68 tst_qqmlextensionplugin() {}
69
70private Q_SLOTS:
71 void iidCheck_data();
72 void iidCheck();
73};
74
75
76void tst_qqmlextensionplugin::iidCheck_data()
77{
78 QList<QString> files;
79 for (QDirIterator it(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath), QDirIterator::Subdirectories); it.hasNext(); ) {
80 QString file = it.next();
81#if defined(Q_OS_DARWIN)
82 if (file.contains(QLatin1String(".dSYM/")))
83 continue;
84#endif
85 if (file.endsWith(SUFFIX)) {
86 files << file;
87 }
88 }
89
90 files = removeDuplicates(files: std::move(files));
91
92 QTest::addColumn<QString>(name: "filePath");
93 foreach (const QString &file, files) {
94 QFileInfo fileInfo(file);
95 QTest::newRow(dataTag: fileInfo.baseName().toLatin1().data()) << fileInfo.absoluteFilePath();
96 }
97}
98
99
100void tst_qqmlextensionplugin::iidCheck()
101{
102 QFETCH(QString, filePath);
103
104 QPluginLoader loader(filePath);
105 QVERIFY2(loader.load(), qPrintable(loader.errorString()));
106 QVERIFY(loader.instance() != nullptr);
107
108 if (qobject_cast<QQmlExtensionPlugin *>(object: loader.instance())) {
109 QString iid = loader.metaData().value(QStringLiteral("IID")).toString();
110 if (iid == QLatin1String(QQmlExtensionInterface_iid_old))
111 qWarning() << "Old extension plugin found. Update the IID" << loader.metaData();
112 else
113 QCOMPARE(iid, QLatin1String(QQmlExtensionInterface_iid));
114 }
115}
116
117
118QTEST_APPLESS_MAIN(tst_qqmlextensionplugin)
119#include "tst_qqmlextensionplugin.moc"
120

source code of qtdeclarative/tests/auto/qml/qqmlextensionplugin/tst_qqmlextensionplugin.cpp