Blame lang/qt/tests/t-config.cpp

Packit Service 672cf4
/* t-config.cpp
Packit Service 672cf4
Packit Service 672cf4
    This file is part of qgpgme, the Qt API binding for gpgme
Packit Service 672cf4
    Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
Packit Service 672cf4
    Software engineering by Intevation GmbH
Packit Service 672cf4
Packit Service 672cf4
    QGpgME is free software; you can redistribute it and/or
Packit Service 672cf4
    modify it under the terms of the GNU General Public License as
Packit Service 672cf4
    published by the Free Software Foundation; either version 2 of the
Packit Service 672cf4
    License, or (at your option) any later version.
Packit Service 672cf4
Packit Service 672cf4
    QGpgME is distributed in the hope that it will be useful,
Packit Service 672cf4
    but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 672cf4
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 672cf4
    General Public License for more details.
Packit Service 672cf4
Packit Service 672cf4
    You should have received a copy of the GNU General Public License
Packit Service 672cf4
    along with this program; if not, write to the Free Software
Packit Service 672cf4
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit Service 672cf4
Packit Service 672cf4
    In addition, as a special exception, the copyright holders give
Packit Service 672cf4
    permission to link the code of this program with any edition of
Packit Service 672cf4
    the Qt library by Trolltech AS, Norway (or with modified versions
Packit Service 672cf4
    of Qt that use the same license as Qt), and distribute linked
Packit Service 672cf4
    combinations including the two.  You must obey the GNU General
Packit Service 672cf4
    Public License in all respects for all of the code used other than
Packit Service 672cf4
    Qt.  If you modify this file, you may extend this exception to
Packit Service 672cf4
    your version of the file, but you are not obligated to do so.  If
Packit Service 672cf4
    you do not wish to do so, delete this exception statement from
Packit Service 672cf4
    your version.
Packit Service 672cf4
*/
Packit Service 672cf4
#ifdef HAVE_CONFIG_H
Packit Service 672cf4
 #include "config.h"
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include <QDebug>
Packit Service 672cf4
#include <QTest>
Packit Service 672cf4
#include <QTemporaryDir>
Packit Service 672cf4
#include "t-support.h"
Packit Service 672cf4
#include "protocol.h"
Packit Service 672cf4
#include "cryptoconfig.h"
Packit Service 672cf4
#include <unistd.h>
Packit Service 672cf4
Packit Service 672cf4
using namespace QGpgME;
Packit Service 672cf4
Packit Service 672cf4
class CryptoConfigTest: public QGpgMETest
Packit Service 672cf4
{
Packit Service 672cf4
    Q_OBJECT
Packit Service 672cf4
Packit Service 672cf4
private Q_SLOTS:
Packit Service 672cf4
    void testKeyserver()
Packit Service 672cf4
    {
Packit Service 672cf4
        // Repeatedly set a config value and clear it
Packit Service 6c01f9
        // this war broken at some point so it gets a
Packit Service 672cf4
        // unit test.
Packit Service 672cf4
        for (int i = 0; i < 10; i++) {
Packit Service 672cf4
            auto conf = cryptoConfig();
Packit Service 672cf4
            QVERIFY(conf);
Packit Service 672cf4
            auto entry = conf->entry(QStringLiteral("gpg"),
Packit Service 672cf4
                    QStringLiteral("Keyserver"),
Packit Service 672cf4
                    QStringLiteral("keyserver"));
Packit Service 672cf4
            QVERIFY(entry);
Packit Service 672cf4
            const QString url(QStringLiteral("hkp://foo.bar.baz"));
Packit Service 672cf4
            entry->setStringValue(url);
Packit Service 672cf4
            conf->sync(false);
Packit Service 672cf4
            conf->clear();
Packit Service 672cf4
            entry = conf->entry(QStringLiteral("gpg"),
Packit Service 672cf4
                    QStringLiteral("Keyserver"),
Packit Service 672cf4
                    QStringLiteral("keyserver"));
Packit Service 672cf4
            QCOMPARE (entry->stringValue(), url);
Packit Service 672cf4
            entry->setStringValue(QString());
Packit Service 672cf4
            conf->sync(false);
Packit Service 672cf4
            conf->clear();
Packit Service 672cf4
            entry = conf->entry(QStringLiteral("gpg"),
Packit Service 672cf4
                    QStringLiteral("Keyserver"),
Packit Service 672cf4
                    QStringLiteral("keyserver"));
Packit Service 672cf4
            QCOMPARE (entry->stringValue(), QString());
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    void initTestCase()
Packit Service 672cf4
    {
Packit Service 672cf4
        QGpgMETest::initTestCase();
Packit Service 672cf4
        const QString gpgHome = qgetenv("GNUPGHOME");
Packit Service 672cf4
        qputenv("GNUPGHOME", mDir.path().toUtf8());
Packit Service 672cf4
        QVERIFY(mDir.isValid());
Packit Service 672cf4
    }
Packit Service 672cf4
private:
Packit Service 672cf4
    QTemporaryDir mDir;
Packit Service 672cf4
Packit Service 672cf4
};
Packit Service 672cf4
Packit Service 672cf4
QTEST_MAIN(CryptoConfigTest)
Packit Service 672cf4
Packit Service 672cf4
#include "t-config.moc"