1/**
2 * Copyright (C) 2006 Brad Hards <bradh@frogmouth.net>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "clientplugin.h"
27
28#include <QtCore/QPointer>
29#include <QtCrypto>
30#include <QtTest/QtTest>
31
32#ifdef QT_STATICPLUGIN
33#include "import_plugins.h"
34#endif
35
36void ClientPlugin::initTestCase()
37{
38 m_init = new QCA::Initializer;
39}
40
41void ClientPlugin::cleanupTestCase()
42{
43 delete m_init;
44}
45
46static const QLatin1String providerName("testClientSideProvider");
47
48class TestClientProvider : public QObject, public QCA::Provider
49{
50 Q_OBJECT
51public:
52 int qcaVersion() const override
53 {
54 return QCA_VERSION;
55 }
56
57 QString name() const override
58 {
59 return providerName;
60 }
61
62 QStringList features() const override
63 {
64 QStringList list;
65 list += QStringLiteral("testClientSideProviderFeature1");
66 list += QStringLiteral("testClientSideProviderFeature2");
67 return list;
68 }
69
70 Provider::Context *createContext(const QString &type) override
71 {
72 if (type == QLatin1String("testClientSideProviderFeature1"))
73 // return new Feature1Context(this);
74 return nullptr;
75 else if (type == QLatin1String("testClientSideProviderFeature2"))
76 // return new Feature2Context(this);
77 return nullptr;
78 else
79 return nullptr;
80 }
81};
82
83void ClientPlugin::testInsertRemovePlugin()
84{
85 QPointer<TestClientProvider> provider = new TestClientProvider;
86
87 QVERIFY(QCA::insertProvider(provider, 10));
88 QCOMPARE(QCA::findProvider(providerName), provider.data());
89 QCOMPARE(QCA::providerPriority(providerName), 10);
90
91 QVERIFY(QCA::unloadProvider(providerName));
92 QCOMPARE(QCA::findProvider(providerName), static_cast<QCA::Provider *>(nullptr));
93 QVERIFY(provider.isNull());
94}
95
96QTEST_MAIN(ClientPlugin)
97
98#include "clientplugin.moc"
99

source code of qca/unittest/clientplugin/clientplugin.cpp