1/****************************************************************************
2**
3** Copyright (C) 2014 Governikus GmbH & Co. KG.
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
30#include <QtTest/QtTest>
31#include <QSslEllipticCurve>
32#include <QSslConfiguration>
33
34class tst_QSslEllipticCurve : public QObject
35{
36 Q_OBJECT
37
38#ifndef QT_NO_SSL
39private Q_SLOTS:
40 void constExpr();
41 void construction();
42 void fromShortName_data();
43 void fromShortName();
44 void fromLongName_data();
45 void fromLongName();
46#endif
47};
48
49#ifndef QT_NO_SSL
50
51void tst_QSslEllipticCurve::constExpr()
52{
53#ifdef Q_COMPILER_CONSTEXPR
54 // check that default ctor and op ==/!= are constexpr:
55 char array1[QSslEllipticCurve() == QSslEllipticCurve() ? 1 : -1];
56 char array2[QSslEllipticCurve() != QSslEllipticCurve() ? -1 : 1];
57 Q_UNUSED(array1);
58 Q_UNUSED(array2);
59#else
60 QSKIP("This test requires C++11 generalized constant expression support enabled in the compiler.");
61#endif
62}
63
64void tst_QSslEllipticCurve::construction()
65{
66 QSslEllipticCurve curve;
67 QCOMPARE(curve.isValid(), false);
68 QCOMPARE(curve.shortName(), QString());
69 QCOMPARE(curve.longName(), QString());
70 QCOMPARE(curve.isTlsNamedCurve(), false);
71}
72
73void tst_QSslEllipticCurve::fromShortName_data()
74{
75 QTest::addColumn<QString>(name: "shortName");
76 QTest::addColumn<QSslEllipticCurve>(name: "curve");
77 QTest::addColumn<bool>(name: "valid");
78
79 QTest::newRow(dataTag: "QString()") << QString() << QSslEllipticCurve() << false;
80 QTest::newRow(dataTag: "\"\"") << QString("") << QSslEllipticCurve() << false;
81 QTest::newRow(dataTag: "does-not-exist") << QStringLiteral("does-not-exist") << QSslEllipticCurve() << false;
82 Q_FOREACH (QSslEllipticCurve ec, QSslConfiguration::supportedEllipticCurves()) {
83 const QString sN = ec.shortName();
84 QTest::newRow(qPrintable("supported EC \"" + sN + '"')) << sN << ec << true;
85 // At least in the OpenSSL impl, the short name is case-sensitive. That feels odd.
86 //const QString SN = sN.toUpper();
87 //QTest::newRow(qPrintable("supported EC \"" + SN + '"')) << SN << ec << true;
88 //const QString sn = sN.toLower();
89 //QTest::newRow(qPrintable("supported EC \"" + sn + '"')) << sn << ec << true;
90 }
91}
92
93void tst_QSslEllipticCurve::fromShortName()
94{
95 QFETCH(QString, shortName);
96 QFETCH(QSslEllipticCurve, curve);
97 QFETCH(bool, valid);
98
99 const QSslEllipticCurve result = QSslEllipticCurve::fromShortName(name: shortName);
100 QCOMPARE(result, curve);
101 QCOMPARE(result.isValid(), valid);
102 QCOMPARE(result.shortName(), curve.shortName());
103 QCOMPARE(result.shortName(), valid ? shortName : QString());
104}
105
106void tst_QSslEllipticCurve::fromLongName_data()
107{
108 QTest::addColumn<QString>(name: "longName");
109 QTest::addColumn<QSslEllipticCurve>(name: "curve");
110 QTest::addColumn<bool>(name: "valid");
111
112 QTest::newRow(dataTag: "QString()") << QString() << QSslEllipticCurve() << false;
113 QTest::newRow(dataTag: "\"\"") << QString("") << QSslEllipticCurve() << false;
114 QTest::newRow(dataTag: "does-not-exist") << QStringLiteral("does-not-exist") << QSslEllipticCurve() << false;
115 Q_FOREACH (QSslEllipticCurve ec, QSslConfiguration::supportedEllipticCurves()) {
116 const QString lN = ec.longName();
117 QTest::newRow(qPrintable("supported EC \"" + lN + '"')) << lN << ec << true;
118 }
119}
120
121void tst_QSslEllipticCurve::fromLongName()
122{
123 QFETCH(QString, longName);
124 QFETCH(QSslEllipticCurve, curve);
125 QFETCH(bool, valid);
126
127 const QSslEllipticCurve result = QSslEllipticCurve::fromLongName(name: longName);
128 QCOMPARE(result, curve);
129 QCOMPARE(result.isValid(), valid);
130 QCOMPARE(result.longName(), curve.longName());
131 QCOMPARE(result.longName(), valid ? longName : QString());
132}
133
134#endif // QT_NO_SSL
135
136QTEST_MAIN(tst_QSslEllipticCurve)
137#include "tst_qsslellipticcurve.moc"
138

source code of qtbase/tests/auto/network/ssl/qsslellipticcurve/tst_qsslellipticcurve.cpp