File indexing completed on 2024-04-28 04:44:08
0001 /** 0002 * Copyright (C) 2006 Brad Hards <bradh@frogmouth.net> 0003 * 0004 * Redistribution and use in source and binary forms, with or without 0005 * modification, are permitted provided that the following conditions 0006 * are met: 0007 * 0008 * 1. Redistributions of source code must retain the above copyright 0009 * notice, this list of conditions and the following disclaimer. 0010 * 2. Redistributions in binary form must reproduce the above copyright 0011 * notice, this list of conditions and the following disclaimer in the 0012 * documentation and/or other materials provided with the distribution. 0013 * 0014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0017 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0024 */ 0025 0026 #include "clientplugin.h" 0027 0028 #include <QtCore/QPointer> 0029 #include <QtCrypto> 0030 #include <QtTest/QtTest> 0031 0032 #ifdef QT_STATICPLUGIN 0033 #include "import_plugins.h" 0034 #endif 0035 0036 void ClientPlugin::initTestCase() 0037 { 0038 m_init = new QCA::Initializer; 0039 } 0040 0041 void ClientPlugin::cleanupTestCase() 0042 { 0043 delete m_init; 0044 } 0045 0046 static const QLatin1String providerName("testClientSideProvider"); 0047 0048 class TestClientProvider : public QObject, public QCA::Provider 0049 { 0050 Q_OBJECT 0051 public: 0052 int qcaVersion() const override 0053 { 0054 return QCA_VERSION; 0055 } 0056 0057 QString name() const override 0058 { 0059 return providerName; 0060 } 0061 0062 QStringList features() const override 0063 { 0064 QStringList list; 0065 list += QStringLiteral("testClientSideProviderFeature1"); 0066 list += QStringLiteral("testClientSideProviderFeature2"); 0067 return list; 0068 } 0069 0070 Provider::Context *createContext(const QString &type) override 0071 { 0072 if (type == QLatin1String("testClientSideProviderFeature1")) 0073 // return new Feature1Context(this); 0074 return nullptr; 0075 else if (type == QLatin1String("testClientSideProviderFeature2")) 0076 // return new Feature2Context(this); 0077 return nullptr; 0078 else 0079 return nullptr; 0080 } 0081 }; 0082 0083 void ClientPlugin::testInsertRemovePlugin() 0084 { 0085 QPointer<TestClientProvider> provider = new TestClientProvider; 0086 0087 QVERIFY(QCA::insertProvider(provider, 10)); 0088 QCOMPARE(QCA::findProvider(providerName), provider.data()); 0089 QCOMPARE(QCA::providerPriority(providerName), 10); 0090 0091 QVERIFY(QCA::unloadProvider(providerName)); 0092 QCOMPARE(QCA::findProvider(providerName), static_cast<QCA::Provider *>(nullptr)); 0093 QVERIFY(provider.isNull()); 0094 } 0095 0096 QTEST_MAIN(ClientPlugin) 0097 0098 #include "clientplugin.moc"