From 5e1d48ce032c80f8a48a4a0bbc3600e62e961be2 Mon Sep 17 00:00:00 2001 From: EndrII <endriimail@gmail.com> Date: Sun, 16 Jul 2023 21:44:34 +0200 Subject: [PATCH] fix tests --- tests/tstMain.cpp | 10 +++++++-- tests/units/crttest.cpp | 0 tests/units/crttest.h | 48 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 tests/units/crttest.cpp create mode 100644 tests/units/crttest.h diff --git a/tests/tstMain.cpp b/tests/tstMain.cpp index d96354f..3a4770b 100644 --- a/tests/tstMain.cpp +++ b/tests/tstMain.cpp @@ -8,9 +8,11 @@ #include <QtTest> #include "cryptotest.h" #include "authtest.h" +#include "crttest.h" #include "easyssl/rsassl.h" #include <easyssl/ecdsassl.h> + // Use This macros for initialize your own test classes. // Check exampletests #define TestCase(name, testClass) \ @@ -18,6 +20,9 @@ initTest(new testClass()); \ } +using CrtTestX509RSA = CrtTest<EasySSL::X509, EasySSL::RSASSL>; +using CrtTestX509ECDSA = CrtTest<EasySSL::X509, EasySSL::ECDSASSL>; + /** * @brief The tstMain class - this is main test class */ @@ -33,13 +38,14 @@ public: private slots: - // BEGIN TESTS CASES TestCase(authTest, AuthTest) TestCase(cryptoTestESDSA, CryptoTest<EasySSL::ECDSASSL>) TestCase(cryptoTestRSA, CryptoTest<EasySSL::RSASSL>) + TestCase(crtTestX509RSA, CrtTestX509RSA) + TestCase(crtTestX509ECDSA, CrtTestX509ECDSA) - // END TEST CASES + // END TEST CASESa private: diff --git a/tests/units/crttest.cpp b/tests/units/crttest.cpp new file mode 100644 index 0000000..e69de29 diff --git a/tests/units/crttest.h b/tests/units/crttest.h new file mode 100644 index 0000000..01ea6bd --- /dev/null +++ b/tests/units/crttest.h @@ -0,0 +1,48 @@ +//# +//# Copyright (C) 2020-2023 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + + +#ifndef CRTTEST_H +#define CRTTEST_H + +#include "qtestcase.h" +#include "test.h" +#include "testutils.h" +#include <easyssl/icertificate.h> +#include <easyssl/x509.h> + + +/** + * @brief The CrtTest class is bse test class for the testin all certificate generators + * @tparam CrtGenerator This any class inheret of ICertificate interface. + * + * @example + * @code{cpp} + * #include "x509.h" + * #include "CrtTest" + * + * TestCase(cryptoTestRSA, CrtTest<EasySSL::x509, EasySSL::RSASSL>) + * @endcode + */ +template <class CrtGenerator, class Algorithm> +class CrtTest: public Test, protected TestUtils +{ +public: + CrtTest() = default; + void test() override { + + CrtGenerator gen(QSharedPointer<Algorithm>::create()); + EasySSL::SslSrtData data; + + auto crt = gen.create(data); + QVERIFY2(!crt.crt.isNull(), "Failed to generate certificate."); + QVERIFY2(!crt.key.isNull(), "Failed to generate private key for certificate."); + + } +}; + +#endif // CRTTEST_H