File indexing completed on 2024-04-21 04:44:00

0001 /**
0002  * Copyright (C)  2004, 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 <QtCrypto>
0027 #include <QtTest/QtTest>
0028 
0029 #include <limits>
0030 
0031 #ifdef QT_STATICPLUGIN
0032 #include "import_plugins.h"
0033 #endif
0034 
0035 class KeyLengthUnitTest : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 private Q_SLOTS:
0040     void initTestCase();
0041     void cleanupTestCase();
0042     void doTest();
0043 
0044 private:
0045     QCA::Initializer *m_init;
0046 };
0047 
0048 void KeyLengthUnitTest::initTestCase()
0049 {
0050     m_init = new QCA::Initializer;
0051 }
0052 
0053 void KeyLengthUnitTest::cleanupTestCase()
0054 {
0055     QCA::unloadAllPlugins();
0056     delete m_init;
0057 }
0058 
0059 void KeyLengthUnitTest::doTest()
0060 {
0061     QCA::KeyLength keylen1(0, 0, 0);
0062     QCOMPARE(keylen1.minimum(), 0);
0063     QCOMPARE(keylen1.maximum(), 0);
0064     QCOMPARE(keylen1.multiple(), 0);
0065 
0066     QCA::KeyLength keylen2(3, 40, 1);
0067     QCOMPARE(keylen2.minimum(), 3);
0068     QCOMPARE(keylen2.maximum(), 40);
0069     QCOMPARE(keylen2.multiple(), 1);
0070 
0071     QCA::KeyLength keylen3(1, INT_MAX, 1);
0072     QCOMPARE(keylen3.minimum(), 1);
0073     QCOMPARE(keylen3.maximum(), INT_MAX);
0074     QCOMPARE(keylen3.multiple(), 1);
0075 }
0076 
0077 QTEST_MAIN(KeyLengthUnitTest)
0078 
0079 #include "keylengthunittest.moc"