diff --git a/tests/kgpgadduid.cpp b/tests/kgpgadduid.cpp index 68ab5398..b96c0e00 100644 --- a/tests/kgpgadduid.cpp +++ b/tests/kgpgadduid.cpp @@ -1,42 +1,42 @@ #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()); } 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, KGpgTransaction::TS_OK); }); + [](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); } QTEST_MAIN(KGpgAddUidTest) diff --git a/tests/kgpgdecrypt.cpp b/tests/kgpgdecrypt.cpp index 89e67571..2814a1e7 100644 --- a/tests/kgpgdecrypt.cpp +++ b/tests/kgpgdecrypt.cpp @@ -1,37 +1,37 @@ #include "kgpgdecrypt.h" #include "../transactions/kgpgdecrypt.h" #include "common.h" #include #include void KGpgDecryptTest::init() { QVERIFY(resetGpgConf()); } void KGpgDecryptTest::testDecrypt(){ QFETCH(QString, encryptedFile); QString passphrase = readFile(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.pass")); addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14_pub.asc")); addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.asc"), passphrase); QString text = readFile(QLatin1String("keys/sample_text")); QString encryptedText = readFile(encryptedFile); KGpgDecrypt *transaction = new KGpgDecrypt(this, encryptedText); QObject::connect(transaction, &KGpgDecrypt::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); QSignalSpy spy(transaction, &KGpgDecrypt::done); addPasswordArguments(transaction, passphrase); transaction->start(); QVERIFY(spy.wait()); QVERIFY(text.compare(transaction->decryptedText().join(QLatin1Char('\n')))); } void KGpgDecryptTest::testDecrypt_data(){ QTest::addColumn("encryptedFile"); QTest::newRow("AsciiArmored") << QString(QLatin1String("keys/encrypt_text.txt")); QTest::newRow("HideKeyId") << QString(QLatin1String("keys/encrypt_text_hide_key_id.txt")); QTest::newRow("Symmetrical") << QString(QLatin1String("keys/encrypted_symmetrical.txt")); } QTEST_MAIN(KGpgDecryptTest) diff --git a/tests/kgpgdelkey.cpp b/tests/kgpgdelkey.cpp index 1717c097..d48c4823 100644 --- a/tests/kgpgdelkey.cpp +++ b/tests/kgpgdelkey.cpp @@ -1,46 +1,46 @@ #include "kgpgdelkey.h" #include "../core/kgpgkey.h" #include "../core/KGpgRootNode.h" #include "../kgpginterface.h" #include "../model/kgpgitemmodel.h" #include "../transactions/kgpgdelkey.h" #include "common.h" #include #include void KGpgDelKeyTest::init() { resetGpgConf(); } void KGpgDelKeyTest::testDeleteKey() { QFETCH(QString, passphrase); addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.asc"), passphrase); QString keyId = QLatin1String("BA7695F3C550DF14"); KGpgItemModel *model = new KGpgItemModel(this); KGpgRootNode *rootNode = new KGpgRootNode(model); rootNode->addKeys(QStringList(keyId)); KGpgKeyNode *keyNode = rootNode->findKey(keyId); QVERIFY(keyNode != nullptr); KGpgDelKey *transaction = new KGpgDelKey(this, keyNode); QObject::connect(transaction, &KGpgDelKey::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); QSignalSpy spy(transaction, &KGpgDelKey::done); transaction->addArgument("--yes"); transaction->start(); QVERIFY(spy.wait()); QCOMPARE(KgpgInterface::readSecretKeys().size(), 0); QCOMPARE(KgpgInterface::readPublicKeys().size(), 0); } void KGpgDelKeyTest::testDeleteKey_data() { QTest::addColumn("passphrase"); QTest::newRow("public") << QString(); QTest::newRow("secret") << readFile(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.pass")); } QTEST_MAIN(KGpgDelKeyTest) diff --git a/tests/kgpgencrypt.cpp b/tests/kgpgencrypt.cpp index fa76224b..16a61f4b 100644 --- a/tests/kgpgencrypt.cpp +++ b/tests/kgpgencrypt.cpp @@ -1,137 +1,137 @@ #include "common.h" #include "kgpgencrypt.h" #include "../transactions/kgpgencrypt.h" #include "../transactions/kgpgdecrypt.h" #include #include #include #include #include void KGpgEncryptTest::init() { QVERIFY(resetGpgConf()); } void KGpgEncryptTest::testAsciiArmoredEncryption() { //Add keys to keyring addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14_pub.asc")); QString passphrase = readFile(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.pass")); addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.asc"), passphrase); //Encrypt text QString text = readFile(QLatin1String("keys/sample_text")); QStringList userIds(QLatin1String("Test KGpg")); KGpgEncrypt *encryption = new KGpgEncrypt( this, userIds, text, KGpgEncrypt::AsciiArmored | KGpgEncrypt::AllowUntrustedEncryption); QObject::connect(encryption, &KGpgEncrypt::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); QSignalSpy spy(encryption, &KGpgEncrypt::done); encryption->start(); QVERIFY(spy.wait()); QString encryptedText = encryption->encryptedText().join("\n"); //Check if the encrypted text has a header and footer QVERIFY(encryptedText.startsWith(QLatin1String("-----BEGIN PGP MESSAGE-----"))); QVERIFY(encryptedText.endsWith(QLatin1String("-----END PGP MESSAGE-----"))); //Test if encrypted text contains "KGpg" QVERIFY(!encryptedText.contains(QLatin1String("KGpg"))); //Decrypt encrypted text KGpgDecrypt *decryption = new KGpgDecrypt(this, encryptedText); QObject::connect(decryption, &KGpgDecrypt::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); QSignalSpy spy2(decryption, &KGpgDecrypt::done); addPasswordArguments(decryption, passphrase); decryption->start(); QVERIFY(spy2.wait()); //Check if decrypted text is equal to original text QVERIFY(text.compare(decryption->decryptedText().join(QLatin1Char('\n')))); } void KGpgEncryptTest::testHideKeyIdEncryption() { //Add keys to keyring addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14_pub.asc")); QString passphrase = readFile(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.pass")); addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.asc"), passphrase); //Encrypt text QString text = readFile(QLatin1String("keys/sample_text")); QStringList userIds(QLatin1String("Test KGpg")); KGpgEncrypt *encryption = new KGpgEncrypt(this, userIds, text, KGpgEncrypt::AsciiArmored | KGpgEncrypt::HideKeyId | KGpgEncrypt::AllowUntrustedEncryption); QObject::connect(encryption, &KGpgEncrypt::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); QSignalSpy spy(encryption, &KGpgEncrypt::done); encryption->start(); QVERIFY(spy.wait()); QString encryptedText = encryption->encryptedText().join("\n"); //Check if the encrypted text has a header and footer QVERIFY(encryptedText.startsWith(QLatin1String("-----BEGIN PGP MESSAGE-----"))); QVERIFY(encryptedText.endsWith(QLatin1String("-----END PGP MESSAGE-----"))); //Test if encrypted text contains "KGpg" QVERIFY(!encryptedText.contains(QLatin1String("KGpg"))); //Check if encrypted text contains key Id QString keyId = QLatin1String("BA7695F3C550DF14"); QString log = encryption->getMessages().join(QLatin1Char('\n')); QVERIFY(!log.contains(keyId)); //Decrypt encrypted text KGpgDecrypt *decryption = new KGpgDecrypt(this, encryptedText); QObject::connect(decryption, &KGpgDecrypt::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); QSignalSpy spy2(decryption, &KGpgDecrypt::done); addPasswordArguments(decryption, passphrase); decryption->start(); QVERIFY(spy2.wait()); //Check if decrypted text is equal to original text QVERIFY(text.compare(decryption->decryptedText().join(QLatin1Char('\n')))); } void KGpgEncryptTest::testSymmetricEncryption() { QString passphrase = QLatin1String("symmetric key"); QString text = readFile(QLatin1String("keys/sample_text")); QStringList userIds; //Encrypt text KGpgEncrypt *encryption = new KGpgEncrypt( this, userIds, text, KGpgEncrypt::AsciiArmored | KGpgEncrypt::AllowUntrustedEncryption); QObject::connect(encryption, &KGpgEncrypt::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); QSignalSpy spy(encryption, &KGpgEncrypt::done); addPasswordArguments(encryption, passphrase); encryption->start(); QVERIFY(spy.wait()); QString encryptedText = encryption->encryptedText().join("\n"); //Check if the encrypted text has a header and footer QVERIFY(encryptedText.startsWith(QLatin1String("-----BEGIN PGP MESSAGE-----"))); QVERIFY(encryptedText.endsWith(QLatin1String("-----END PGP MESSAGE-----"))); //Test if encrypted text contains "KGpg" QVERIFY(!encryptedText.contains(QLatin1String("KGpg"))); //Decrypt encrypted text KGpgDecrypt *decryption = new KGpgDecrypt(this, encryptedText); QObject::connect(decryption, &KGpgDecrypt::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); QSignalSpy spy2(decryption, &KGpgDecrypt::done); addPasswordArguments(decryption, passphrase); decryption->start(); QVERIFY(spy2.wait()); //Check if decrypted text is equal to original text QVERIFY(text.compare(decryption->decryptedText().join(QLatin1Char('\n')))); } QTEST_MAIN(KGpgEncryptTest) diff --git a/tests/kgpgexport.cpp b/tests/kgpgexport.cpp index e7d199a0..9fe89bcb 100644 --- a/tests/kgpgexport.cpp +++ b/tests/kgpgexport.cpp @@ -1,82 +1,82 @@ #include "kgpgexport.h" #include "../transactions/kgpgexport.h" #include "../kgpginterface.h" #include "common.h" #include #include #include void KGpgExportTest::init() { QVERIFY(resetGpgConf()); } void KGpgExportTest::testExportPublicKeyToFile() { addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14_pub.asc")); QTemporaryFile file("key_pub.asc"); QVERIFY(file.open()); QString filename = file.fileName(); QStringList ids(QLatin1String("BA7695F3C550DF14")); // Output in Ascii mode QStringList options(QLatin1String("--armor")); KGpgExport *transaction = new KGpgExport(this, ids, filename, options, false); QSignalSpy spy(transaction, &KGpgExport::done); QObject::connect(transaction, &KGpgExport::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); transaction->start(); QVERIFY(spy.wait()); QString exportedKey = readFile(filename); QString key = readFile(QLatin1String("keys/kgpgtest_BA7695F3C550DF14_pub.asc")); QVERIFY(key.compare(exportedKey) == 0); } void KGpgExportTest::testExportSecretKeyToFile() { QString passphrase = readFile(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.pass")); addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14.asc"), passphrase); QTemporaryFile file("key.asc"); QVERIFY(file.open()); QString filename = file.fileName(); QStringList ids(QLatin1String("BA7695F3C550DF14")); // Output in Ascii mode QStringList options(QLatin1String("--armor")); KGpgExport *transaction = new KGpgExport(this, ids, filename, options, true); addPasswordArguments(transaction, passphrase); QSignalSpy spy(transaction, &KGpgExport::done); QObject::connect(transaction, &KGpgExport::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); transaction->start(); QVERIFY(spy.wait()); //reset gpg home dir QVERIFY(resetGpgConf()); //Import exported key addGpgKey(filename, passphrase); KgpgCore::KgpgKeyList keys = KgpgInterface::readSecretKeys(); QString keyID = QLatin1String("BA7695F3C550DF14"); QCOMPARE(keys.size(), 1); QVERIFY(keys.first().fullId().compare(keyID) == 0); } void KGpgExportTest::testExportPublicKeyToStdOutput() { addGpgKey(QLatin1String("keys/kgpgtest_BA7695F3C550DF14_pub.asc")); QStringList ids(QLatin1String("BA7695F3C550DF14")); // Output in Ascii mode QStringList options(QLatin1String("--armor")); KGpgExport *transaction = new KGpgExport(this, ids, options, false); QSignalSpy spy(transaction, &KGpgExport::done); QObject::connect(transaction, &KGpgExport::done, - [](int result) { QCOMPARE(result, KGpgTransaction::TS_OK); }); + [](int result) { QCOMPARE(result, static_cast(KGpgTransaction::TS_OK)); }); transaction->start(); QVERIFY(spy.wait()); QString exportedKey = QLatin1String(transaction->getOutputData()); QString key = readFile(QLatin1String("keys/kgpgtest_BA7695F3C550DF14_pub.asc")); QVERIFY(key.compare(exportedKey) == 0); } QTEST_MAIN(KGpgExportTest)