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 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 | //TESTED_COMPONENT=src/multimedia |
30 | |
31 | #include <private/qmediapluginloader_p.h> |
32 | #include <qmediaserviceproviderplugin.h> |
33 | |
34 | #include <QtTest/QtTest> |
35 | #include <QDebug> |
36 | |
37 | QT_USE_NAMESPACE |
38 | |
39 | class tst_QMediaPluginLoader : public QObject |
40 | { |
41 | Q_OBJECT |
42 | |
43 | public slots: |
44 | void initTestCase(); |
45 | void cleanupTestCase(); |
46 | |
47 | private slots: |
48 | void testInstance(); |
49 | void testInstances(); |
50 | void testInvalidKey(); |
51 | |
52 | private: |
53 | QMediaPluginLoader *loader; |
54 | }; |
55 | |
56 | void tst_QMediaPluginLoader::initTestCase() |
57 | { |
58 | loader = new QMediaPluginLoader(QMediaServiceProviderFactoryInterface_iid, |
59 | QLatin1String("mediaservice"), |
60 | Qt::CaseInsensitive); |
61 | } |
62 | |
63 | void tst_QMediaPluginLoader::cleanupTestCase() |
64 | { |
65 | delete loader; |
66 | } |
67 | |
68 | void tst_QMediaPluginLoader::testInstance() |
69 | { |
70 | const QStringList keys = loader->keys(); |
71 | |
72 | if (keys.isEmpty()) // Test is invalidated, skip. |
73 | QSKIP("No plug-ins available"); |
74 | |
75 | for (const QString &key : keys) |
76 | QVERIFY(loader->instance(key) != 0); |
77 | } |
78 | |
79 | void tst_QMediaPluginLoader::testInstances() |
80 | { |
81 | const QStringList keys = loader->keys(); |
82 | |
83 | if (keys.isEmpty()) // Test is invalidated, skip. |
84 | QSKIP("No plug-ins available"); |
85 | |
86 | for (const QString &key : keys) |
87 | QVERIFY(loader->instances(key).size() > 0); |
88 | } |
89 | |
90 | // Last so as to not interfere with the other tests if there is a failure. |
91 | void tst_QMediaPluginLoader::testInvalidKey() |
92 | { |
93 | const QString key(QLatin1String("invalid-key")); |
94 | |
95 | // This test assumes there is no 'invalid-key' in the key list, verify that. |
96 | if (loader->keys().contains(str: key)) |
97 | QSKIP("a plug-in includes the invalid key"); |
98 | |
99 | QVERIFY(loader->instance(key) == 0); |
100 | |
101 | // Test looking up the key hasn't inserted it into the list. See QMap::operator[]. |
102 | QVERIFY(!loader->keys().contains(key)); |
103 | |
104 | QVERIFY(loader->instances(key).isEmpty()); |
105 | QVERIFY(!loader->keys().contains(key)); |
106 | } |
107 | |
108 | QTEST_MAIN(tst_QMediaPluginLoader) |
109 | |
110 | #include "tst_qmediapluginloader.moc" |
111 |