Commit c1dc0f8b authored by Ingo Klöcker's avatar Ingo Klöcker

Remove tests that are obsolete and disabled since more than a decade

parent 7387406b
Pipeline #38099 passed with stage
in 13 minutes and 10 seconds
......@@ -10,46 +10,6 @@ include_directories(
########### next target ###############
if(PORT_ME_AWAY_FROM_EVENT_LOOPS)
set(test_keylistmodels_SRCS
test_keylistmodels.cpp
${CMAKE_SOURCE_DIR}/src/models/keylistmodel.cpp
${CMAKE_SOURCE_DIR}/src/models/keylistsortfilterproxymodel.cpp
${CMAKE_SOURCE_DIR}/src/utils/formatting.cpp
)
if(KLEO_MODEL_TEST)
set(test_keylistmodels_SRCS
${test_keylistmodels_SRCS}
${CMAKE_SOURCE_DIR}/src/models/modeltest.cpp
)
endif()
add_executable(test_keylistmodels TEST ${test_keylistmodels_SRCS})
target_link_libraries(test_keylistmodels KF5::Libkleo )
########### next target ###############
set(test_useridlistmodels_SRCS
test_useridlistmodels.cpp
${CMAKE_SOURCE_DIR}/src/models/useridlistmodel.cpp
${CMAKE_SOURCE_DIR}/src/utils/formatting.cpp
)
if(KLEO_MODEL_TEST)
set(test_useridlistmodels_SRCS
${test_useridlistmodels_SRCS}
${CMAKE_SOURCE_DIR}/src/models/modeltest.cpp
)
endif()
add_executable(test_useridlistmodels TEST ${test_useridlistmodels_SRCS})
target_link_libraries(test_useridlistmodels KF5::Libkleo )
endif()
########### next target ###############
set(test_verify_SRCS test_verify.cpp)
add_definitions(-DKLEO_TEST_GNUPGHOME="${CMAKE_CURRENT_BINARY_DIR}/gnupg_home")
......
/* -*- mode: c++; c-basic-offset:4 -*-
test_keylistmodels.cpp
This file is part of Kleopatra's test suite.
SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-kleopatra.h>
#include <models/keylistmodel.h>
#include <models/keylistsortfilterproxymodel.h>
#include <utils/formatting.h>
#include <KAboutData>
#include <QTreeView>
#include <QLineEdit>
#include <QTimer>
#include <QEventLoop>
#include <QDateTime>
#include "kleopatra_debug.h"
#include <qgpgme/eventloopinteractor.h>
#include <gpgme++/context.h>
#include <gpgme++/error.h>
#include <gpgme++/key.h>
#include <memory>
#include <vector>
#include <string>
#include <QApplication>
#include <KLocalizedString>
#include <QCommandLineParser>
#include <QCommandLineOption>
class Relay : public QObject
{
Q_OBJECT
public:
explicit Relay(QObject *p = nullptr) : QObject(p) {}
public Q_SLOTS:
void slotNextKeyEvent(GpgME::Context *, const GpgME::Key &key)
{
qDebug("next key");
mKeys.push_back(key);
// push out keys in chunks of 1..16 keys
if (mKeys.size() > qrand() % 16U) {
emit nextKeys(mKeys);
mKeys.clear();
}
}
void slotOperationDoneEvent(GpgME::Context *, const GpgME::Error &error)
{
qDebug("listing done error: %d", error.encodedError());
}
Q_SIGNALS:
void nextKeys(const std::vector<GpgME::Key> &keys);
private:
std::vector<GpgME::Key> mKeys;
};
int main(int argc, char *argv[])
{
if (const GpgME::Error initError = GpgME::initializeLibrary(0)) {
qCDebug(KLEOPATRA_LOG) << "Error initializing gpgme:" << QString::fromLocal8Bit(initError.asString());
return 1;
}
KAboutData aboutData("test_flatkeylistmodel", 0, i18n("FlatKeyListModel Test"), "0.2");
QApplication app(argc, argv);
QCommandLineParser parser;
KAboutData::setApplicationData(aboutData);
parser.addVersionOption();
parser.addHelpOption();
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("flat"), i18n("Perform flat certificate listing")));
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("hierarchical"), i18n("Perform hierarchical certificate listing")));
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("disable-smime"), i18n("Do not list SMIME certificates")));
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("secret"), i18n("List secret keys only")));
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
const bool showFlat = parser.isSet(QStringLiteral("flat")) || !parser.isSet(QStringLiteral("hierarchical"));
const bool showHier = parser.isSet(QStringLiteral("hierarchical")) || !parser.isSet(QStringLiteral("flat"));
const bool disablesmime = parser.isSet(QStringLiteral("disable-smime"));
const bool secretOnly = parser.isSet(QStringLiteral("secret"));
qsrand(QDateTime::currentDateTime().toTime_t());
QWidget flatWidget, hierarchicalWidget;
QVBoxLayout flatLay(&flatWidget), hierarchicalLay(&hierarchicalWidget);
QLineEdit flatLE(&flatWidget), hierarchicalLE(&hierarchicalWidget);
QTreeView flat(&flatWidget), hierarchical(&hierarchicalWidget);
flat.setSortingEnabled(true);
flat.sortByColumn(Kleo::AbstractKeyListModel::Fingerprint, Qt::AscendingOrder);
hierarchical.setSortingEnabled(true);
hierarchical.sortByColumn(Kleo::AbstractKeyListModel::Fingerprint, Qt::AscendingOrder);
flatLay.addWidget(&flatLE);
flatLay.addWidget(&flat);
hierarchicalLay.addWidget(&hierarchicalLE);
hierarchicalLay.addWidget(&hierarchical);
flatWidget.setWindowTitle(QStringLiteral("Flat Key Listing"));
hierarchicalWidget.setWindowTitle(QStringLiteral("Hierarchical Key Listing"));
Kleo::KeyListSortFilterProxyModel flatProxy, hierarchicalProxy;
QObject::connect(&flatLE, SIGNAL(textChanged(QString)), &flatProxy, SLOT(setFilterFixedString(QString)));
QObject::connect(&hierarchicalLE, SIGNAL(textChanged(QString)), &hierarchicalProxy, SLOT(setFilterFixedString(QString)));
Relay relay;
QObject::connect(QGpgME::EventLoopInteractor::instance(), SIGNAL(nextKeyEventSignal(GpgME::Context*,GpgME::Key)),
&relay, SLOT(slotNextKeyEvent(GpgME::Context*,GpgME::Key)));
QObject::connect(QGpgME::EventLoopInteractor::instance(), SIGNAL(operationDoneEventSignal(GpgME::Context*,GpgME::Error)),
&relay, SLOT(slotOperationDoneEvent(GpgME::Context*,GpgME::Error)));
if (showFlat)
if (Kleo::AbstractKeyListModel *const model = Kleo::AbstractKeyListModel::createFlatKeyListModel(&flat)) {
QObject::connect(&relay, SIGNAL(nextKeys(std::vector<GpgME::Key>)), model, SLOT(addKeys(std::vector<GpgME::Key>)));
model->setToolTipOptions(Kleo::Formatting::AllOptions);
flatProxy.setSourceModel(model);
flat.setModel(&flatProxy);
flatWidget.show();
}
if (showHier)
if (Kleo::AbstractKeyListModel *const model = Kleo::AbstractKeyListModel::createHierarchicalKeyListModel(&hierarchical)) {
QObject::connect(&relay, SIGNAL(nextKeys(std::vector<GpgME::Key>)), model, SLOT(addKeys(std::vector<GpgME::Key>)));
model->setToolTipOptions(Kleo::Formatting::AllOptions);
hierarchicalProxy.setSourceModel(model);
hierarchical.setModel(&hierarchicalProxy);
hierarchicalWidget.show();
}
const char *pattern[] = { nullptr };
const std::auto_ptr<GpgME::Context> pgp(GpgME::Context::createForProtocol(GpgME::OpenPGP));
pgp->setManagedByEventLoopInteractor(true);
pgp->setKeyListMode(GpgME::Local);
if (const GpgME::Error e = pgp->startKeyListing(pattern, secretOnly)) {
qCDebug(KLEOPATRA_LOG) << "pgp->startKeyListing() ->" << e.asString();
}
if (!disablesmime) {
const std::auto_ptr<GpgME::Context> cms(GpgME::Context::createForProtocol(GpgME::CMS));
cms->setManagedByEventLoopInteractor(true);
cms->setKeyListMode(GpgME::Local);
if (const GpgME::Error e = cms->startKeyListing(pattern, secretOnly)) {
qCDebug(KLEOPATRA_LOG) << "cms" << e.asString();
}
QEventLoop loop;
QTimer::singleShot(2000, &loop, SLOT(quit()));
loop.exec();
const std::auto_ptr<GpgME::Context> cms2(GpgME::Context::createForProtocol(GpgME::CMS));
cms2->setManagedByEventLoopInteractor(true);
cms2->setKeyListMode(GpgME::Local);
if (const GpgME::Error e = cms2->startKeyListing(pattern, secretOnly)) {
qCDebug(KLEOPATRA_LOG) << "cms2" << e.asString();
}
}
return app.exec();
}
#include "test_flatkeylistmodel.moc"
/* -*- mode: c++; c-basic-offset:4 -*-
test_useridlistmodels.cpp
This file is part of Kleopatra's test suite.
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-kleopatra.h>
#include <models/useridlistmodel.h>
#include <KAboutData>
#include <QTreeView>
#ifdef KLEO_MODEL_TEST
# include <models/modeltest.h>
#endif
#include <qgpgme/eventloopinteractor.h>
#include <gpgme++/context.h>
#include <gpgme++/error.h>
#include <gpgme++/key.h>
#include <gpgme++/keylistresult.h>
#include <gpg-error.h>
#include <memory>
#include <stdexcept>
#include <vector>
#include <string>
#include <iostream>
#include <QApplication>
#include <KLocalizedString>
#include <QCommandLineParser>
#include <QCommandLineOption>
class KeyResolveJob : QObject
{
Q_OBJECT
public:
explicit KeyResolveJob(GpgME::Protocol proto = GpgME::OpenPGP, QObject *p = 0)
: QObject(p),
m_ctx(GpgME::Context::createForProtocol(proto)),
m_done(false),
m_loop(0)
{
Q_ASSERT(m_ctx.get());
connect(QGpgME::EventLoopInteractor::instance(), SIGNAL(nextKeyEventSignal(GpgME::Context*,GpgME::Key)),
this, SLOT(slotNextKey(GpgME::Context*,GpgME::Key)));
connect(QGpgME::EventLoopInteractor::instance(), SIGNAL(operationDoneEventSignal(GpgME::Context*,GpgME::Error)),
this, SLOT(slotDone(GpgME::Context*,GpgME::Error)));
m_ctx->setManagedByEventLoopInteractor(true);
}
GpgME::Error start(const char *pattern, bool secretOnly = false)
{
m_ctx->addKeyListMode(GpgME::Signatures | GpgME::SignatureNotations);
return m_ctx->startKeyListing(pattern, secretOnly);
}
GpgME::Error waitForDone()
{
if (m_done) {
return m_error;
}
QEventLoop loop;
m_loop = &loop;
loop.exec();
m_loop = 0;
return m_error;
}
std::vector<GpgME::Key> keys() const
{
return m_keys;
}
private Q_SLOTS:
void slotNextKey(GpgME::Context *ctx, const GpgME::Key &key)
{
if (ctx != m_ctx.get()) {
return;
}
m_keys.push_back(key);
}
void slotDone(GpgME::Context *ctx, const GpgME::Error &err)
{
if (ctx != m_ctx.get()) {
return;
}
m_error = err;
m_done = true;
if (m_loop) {
m_loop->quit();
}
}
private:
std::auto_ptr<GpgME::Context> m_ctx;
GpgME::Error m_error;
bool m_done;
std::vector<GpgME::Key> m_keys;
QEventLoop *m_loop;
};
using namespace GpgME;
using namespace Kleo;
static void start(const QString &str, Protocol proto)
{
const QByteArray arg = str.toUtf8();
KeyResolveJob job(proto);
if (const GpgME::Error err = job.start(arg)) {
throw std::runtime_error(std::string("startKeyListing: ") + gpg_strerror(err.encodedError()));
}
if (const GpgME::Error err = job.waitForDone()) {
throw std::runtime_error(std::string("nextKey: ") + gpg_strerror(err.encodedError()));
}
const Key key = job.keys().front();
if (key.isNull()) {
throw std::runtime_error(std::string("key is null"));
}
QTreeView *const tv = new QTreeView;
tv->setWindowTitle(QString::fromLatin1("UserIDListModel Test - %1").arg(str));
UserIDListModel *const model = new UserIDListModel(tv);
#ifdef KLEO_MODEL_TEST
new ModelTest(model);
#endif
model->setKey(key);
tv->setModel(model);
tv->show();
}
int main(int argc, char *argv[])
{
KAboutData aboutData(QStringLiteral("test_useridlistmodels"), i18n("UserIDListModel Test"), QStringLiteral("0.1"));
QApplication app(argc, argv);
QCommandLineParser parser;
KAboutData::setApplicationData(aboutData);
parser.addVersionOption();
parser.addHelpOption();
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("p"), i18n("OpenPGP certificate to look up"), QStringLiteral("pattern")));
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("x"), i18n("X.509 certificate to look up"), QStringLiteral("pattern")));
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
if (parser.values(QStringLiteral("p")).empty() && parser.values(QStringLiteral("x")).empty()) {
return 1;
}
try {
Q_FOREACH (const QString &arg, parser.values(QStringLiteral("p"))) {
start(arg, OpenPGP);
}
Q_FOREACH (const QString &arg, parser.values(QStringLiteral("x"))) {
start(arg, CMS);
}
return app.exec();
} catch (const std::exception &e) {
std::cerr << "Caught exception: " << e.what() << std::endl;
return 1;
}
}
#include "test_useridlistmodel.moc"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment