From 8e9a38659e53e1b6e4e91d4f7d76c4b314a85b39 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 26 May 2011 15:13:15 +0200 Subject: [PATCH] unit testing for Plasma::Signing --- tests/CMakeLists.txt | 3 +- tests/signingtest.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++ tests/signingtest.h | 53 ++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 tests/signingtest.cpp create mode 100644 tests/signingtest.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d2ed1aebf..e99b54c92 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,11 +12,12 @@ MACRO(PLASMA_UNIT_TESTS) ENDMACRO(PLASMA_UNIT_TESTS) PLASMA_UNIT_TESTS( + configloadertest packagestructuretest packagemetadatatest plasmoidpackagetest runnercontexttest - configloadertest + signingtest ) if(QCA2_FOUND) target_link_libraries(plasmoidpackagetest ${QCA2_LIBRARIES}) diff --git a/tests/signingtest.cpp b/tests/signingtest.cpp new file mode 100644 index 000000000..338295989 --- /dev/null +++ b/tests/signingtest.cpp @@ -0,0 +1,80 @@ +/******************************************************************************** +* Copyright 2011 by Aaron Seigo * +* * +* This library is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Library General Public * +* License as published by the Free Software Foundation; either * +* version 2 of the License, or (at your option) any later version. * +* * +* This library is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * +* Library General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public License * +* along with this library; see the file COPYING.LIB. If not, write to * +* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * +* Boston, MA 02110-1301, USA. * +*********************************************************************************/ + +#include "signingtest.h" + +#include + +#include + +#include "plasma/remote/signing.h" + +SigningTest::SigningTest(QObject *parent) + : QObject(parent), + m_signing(0) +{ + const QString prefix = QString::fromLatin1(KDESRCDIR); + m_package = prefix + "signed.plasmoid"; + m_packageSig = prefix + "signed.plasmoid.asc"; +} + +void SigningTest::init() +{ +} + +void SigningTest::cleanup() +{ +} + +void SigningTest::confirmCtorPerformance() +{ + QTime t; + t.start(); + m_signing = new Plasma::Signing; + QVERIFY(t.elapsed() < 50); +} + +void SigningTest::missingFiles() +{ + QVERIFY(m_signing->signerOf(KUrl("/nonexistantpackage"), KUrl("/noneexistantsignature")).isEmpty()); + QVERIFY(m_signing->signerOf(KUrl(m_package), KUrl("/noneexistantsignature")).isEmpty()); + QVERIFY(m_signing->signerOf(KUrl("/nonexistantpackage"), KUrl(m_packageSig)).isEmpty()); +} + +void SigningTest::validSignature() +{ + QVERIFY(!m_signing->signerOf(m_package, m_packageSig).isEmpty()); +} + +void SigningTest::validSignatureWithoutDefinedSigFile() +{ + QVERIFY(!m_signing->signerOf(m_package).isEmpty()); +} + +void SigningTest::confirmDtorPerformance() +{ + QTime t; + t.start(); + delete m_signing; + m_signing = 0; + QVERIFY(t.elapsed() < 50); +} + +QTEST_KDEMAIN(SigningTest, NoGUI) + diff --git a/tests/signingtest.h b/tests/signingtest.h new file mode 100644 index 000000000..539b20a28 --- /dev/null +++ b/tests/signingtest.h @@ -0,0 +1,53 @@ +/******************************************************************************** +* Copyright 2011 by Aaron Seigo * +* * +* This library is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Library General Public * +* License as published by the Free Software Foundation; either * +* version 2 of the License, or (at your option) any later version. * +* * +* This library is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * +* Library General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public License * +* along with this library; see the file COPYING.LIB. If not, write to * +* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * +* Boston, MA 02110-1301, USA. * +*********************************************************************************/ + +#ifndef SIGNINGTEST_H + +#include + +namespace Plasma +{ + class Signing; +} + +class SigningTest : public QObject +{ + Q_OBJECT +public: + explicit SigningTest(QObject *parent = 0); + +public Q_SLOTS: + void init(); + void cleanup(); + +private Q_SLOTS: + void confirmCtorPerformance(); + void missingFiles(); + void validSignature(); + void validSignatureWithoutDefinedSigFile(); + void confirmDtorPerformance(); + +private: + Plasma::Signing *m_signing; + QString m_package; + QString m_packageSig; +}; + +#endif +