diff --git a/tests/kgpgadduid.cpp b/tests/kgpgadduid.cpp index b96c0e00..b1aff992 100644 --- a/tests/kgpgadduid.cpp +++ b/tests/kgpgadduid.cpp @@ -1,42 +1,63 @@ #include "kgpgadduid.h" #include "../transactions/kgpgadduid.h" #include "../kgpginterface.h" #include "../kgpgsettings.h" #include "common.h" #include #include #include #include void KGpgAddUidTest::init() { QVERIFY(resetGpgConf()); + QString passphrase = readFile(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.pass")); + addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14_pub.asc")); + addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.asc"), passphrase); } void KGpgAddUidTest::testAddUid() { QString passphrase = readFile(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.pass")); - addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14_pub.asc")); - addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.asc"), passphrase); QString keyId = QLatin1String("BA7695F3C550DF14"); QString name = QLatin1String("Test name"); QString email = QLatin1String("test@kde.org"); QString comment = QLatin1String("Test comment"); KGpgAddUid *transaction = new KGpgAddUid(this, keyId, name, email, comment); addPasswordArguments(transaction, passphrase); QObject::connect(transaction, &KGpgAddUid::done, [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); QSignalSpy spy(transaction, &KGpgAddUid::done); transaction->start(); QVERIFY(spy.wait()); KgpgCore::KgpgKeyList keyList = KgpgInterface::readPublicKeys(); QCOMPARE(keyList.size(), 1); KgpgCore::KgpgKey key = keyList.first(); QCOMPARE(key.name(), name); QCOMPARE(key.email(), email); QCOMPARE(key.comment(), comment); QCOMPARE(key.fullId(), keyId); } +void KGpgAddUidTest::testAddUidInvalid() +{ + QString passphrase = readFile(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.pass")); + QString keyId = QLatin1String("BA7695F3C550DF14"); + QString name = QLatin1String("Test name"); + QString email = QLatin1String("a b"); // intentionally invalid + QString comment = QLatin1String("Test comment"); + KGpgAddUid *transaction = new KGpgAddUid(this, keyId, name, email, comment); + QObject::connect(transaction, &KGpgAddUid::done, + [](int result) { QCOMPARE(result, static_cast(KGpgAddUid::TS_INVALID_EMAIL)); }); + QSignalSpy spy(transaction, &KGpgAddUid::done); + transaction->start(); + + // for whatever reason spy.wait() does not work here + int i = 0; + while (spy.isEmpty() && i++ < 50) + QTest::qWait(250); + QCOMPARE(spy.count(), 1); +} + QTEST_MAIN(KGpgAddUidTest) diff --git a/tests/kgpgadduid.h b/tests/kgpgadduid.h index d48d21a5..f5f2f432 100644 --- a/tests/kgpgadduid.h +++ b/tests/kgpgadduid.h @@ -1,13 +1,14 @@ #ifndef KGPGADDUID_TEST_H #define KGPGADDUID_TEST_H #include class KGpgAddUidTest : public QObject { Q_OBJECT private slots: void init(); void testAddUid(); + void testAddUidInvalid(); }; #endif