From 7a6850d5fe38b4e19f12d0dc658c8b05ad0ea3bb Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Wed, 24 Jan 2018 13:22:20 +0100 Subject: [PATCH] Move useful QTest template specializations to global header file Fix KDBX test linker errors on Windows --- tests/CMakeLists.txt | 5 +- tests/TestAutoType.cpp | 4 +- tests/TestBase32.cpp | 2 +- tests/TestCryptoHash.cpp | 3 +- tests/TestCsvExporter.cpp | 5 +- tests/TestDatabase.cpp | 4 +- tests/TestDeletedObjects.cpp | 5 +- tests/TestEntry.cpp | 7 +- tests/TestEntryModel.cpp | 2 +- tests/TestEntrySearcher.cpp | 3 +- tests/TestGlobal.h | 69 ++++++++++++++++ tests/TestGroup.cpp | 7 +- tests/TestGroupModel.cpp | 4 +- tests/TestHashedBlockStream.cpp | 2 +- tests/TestKdbx2.cpp | 6 +- tests/TestKdbx3.cpp | 3 +- tests/TestKdbx4.cpp | 3 +- tests/TestKeePass1Reader.cpp | 5 +- tests/TestKeePass2Format.cpp | 117 +++++++-------------------- tests/TestKeePass2Format.h | 3 - tests/TestKeePass2RandomStream.cpp | 4 +- tests/TestKeys.cpp | 3 +- tests/TestMerge.cpp | 6 +- tests/TestOpenSSHKey.cpp | 4 +- tests/TestRandom.cpp | 3 +- tests/TestSymmetricCipher.cpp | 2 +- tests/TestTotp.cpp | 7 +- tests/TestWildcardMatcher.cpp | 4 +- tests/TestYkChallengeResponseKey.cpp | 25 ++---- tests/TestYkChallengeResponseKey.h | 6 +- tests/gui/CMakeLists.txt | 2 + tests/gui/TestGui.cpp | 2 +- tests/gui/TestGuiPixmaps.cpp | 7 +- 33 files changed, 143 insertions(+), 191 deletions(-) create mode 100644 tests/TestGlobal.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5e6043609..3b8ada32d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -82,7 +82,6 @@ macro(add_unit_test) endif() endmacro(add_unit_test) - set(TEST_LIBRARIES keepassx_core ${keepasshttp_LIB} @@ -96,7 +95,7 @@ set(TEST_LIBRARIES ${ZLIB_LIBRARIES} ) -set(testsupport_SOURCES modeltest.cpp FailDevice.cpp) +set(testsupport_SOURCES TestGlobal.h modeltest.cpp FailDevice.cpp) add_library(testsupport STATIC ${testsupport_SOURCES}) target_link_libraries(testsupport Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test) @@ -185,7 +184,7 @@ add_unit_test(NAME testcsvexporter SOURCES TestCsvExporter.cpp LIBS ${TEST_LIBRARIES}) add_unit_test(NAME testykchallengeresponsekey - SOURCES TestYkChallengeResponseKey.cpp TestYkChallengeResponseKey.h + SOURCES TestYkChallengeResponseKey.cpp LIBS ${TEST_LIBRARIES}) add_unit_test(NAME testdatabase SOURCES TestDatabase.cpp diff --git a/tests/TestAutoType.cpp b/tests/TestAutoType.cpp index 2f980e546..9d2f063e8 100644 --- a/tests/TestAutoType.cpp +++ b/tests/TestAutoType.cpp @@ -17,14 +17,12 @@ */ #include "TestAutoType.h" +#include "TestGlobal.h" #include -#include #include "core/Config.h" #include "core/FilePath.h" -#include "core/Entry.h" -#include "core/Group.h" #include "crypto/Crypto.h" #include "autotype/AutoType.h" #include "autotype/AutoTypePlatformPlugin.h" diff --git a/tests/TestBase32.cpp b/tests/TestBase32.cpp index 1d30e7817..1fe61f9f3 100644 --- a/tests/TestBase32.cpp +++ b/tests/TestBase32.cpp @@ -16,8 +16,8 @@ */ #include "TestBase32.h" +#include "TestGlobal.h" #include "core/Base32.h" -#include QTEST_GUILESS_MAIN(TestBase32) diff --git a/tests/TestCryptoHash.cpp b/tests/TestCryptoHash.cpp index 469ce8192..914bcf193 100644 --- a/tests/TestCryptoHash.cpp +++ b/tests/TestCryptoHash.cpp @@ -16,8 +16,7 @@ */ #include "TestCryptoHash.h" - -#include +#include "TestGlobal.h" #include "crypto/Crypto.h" #include "crypto/CryptoHash.h" diff --git a/tests/TestCsvExporter.cpp b/tests/TestCsvExporter.cpp index 6515c39c2..b85dbf268 100644 --- a/tests/TestCsvExporter.cpp +++ b/tests/TestCsvExporter.cpp @@ -17,13 +17,10 @@ */ #include "TestCsvExporter.h" +#include "TestGlobal.h" #include -#include -#include "core/Database.h" -#include "core/Entry.h" -#include "core/Group.h" #include "crypto/Crypto.h" #include "format/CsvExporter.h" diff --git a/tests/TestDatabase.cpp b/tests/TestDatabase.cpp index 284ba4bfb..4aae91dc2 100644 --- a/tests/TestDatabase.cpp +++ b/tests/TestDatabase.cpp @@ -17,17 +17,15 @@ */ #include "TestDatabase.h" +#include "TestGlobal.h" -#include #include #include #include "config-keepassx-tests.h" -#include "core/Database.h" #include "crypto/Crypto.h" #include "keys/PasswordKey.h" #include "core/Metadata.h" -#include "core/Group.h" #include "format/KeePass2Writer.h" QTEST_GUILESS_MAIN(TestDatabase) diff --git a/tests/TestDeletedObjects.cpp b/tests/TestDeletedObjects.cpp index 63dab0edf..ee9d8de2c 100644 --- a/tests/TestDeletedObjects.cpp +++ b/tests/TestDeletedObjects.cpp @@ -16,11 +16,8 @@ */ #include "TestDeletedObjects.h" +#include "TestGlobal.h" -#include - -#include "core/Database.h" -#include "core/Group.h" #include "crypto/Crypto.h" #include "format/KeePass2.h" #include "format/KdbxXmlReader.h" diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp index 598ad33fd..264f202d1 100644 --- a/tests/TestEntry.cpp +++ b/tests/TestEntry.cpp @@ -16,12 +16,7 @@ */ #include "TestEntry.h" -#include "config-keepassx-tests.h" - -#include - -#include "core/Entry.h" -#include "core/Group.h" +#include "TestGlobal.h" #include "crypto/Crypto.h" QTEST_GUILESS_MAIN(TestEntry) diff --git a/tests/TestEntryModel.cpp b/tests/TestEntryModel.cpp index ab4ecf754..d290507f1 100644 --- a/tests/TestEntryModel.cpp +++ b/tests/TestEntryModel.cpp @@ -16,9 +16,9 @@ */ #include "TestEntryModel.h" +#include "TestGlobal.h" #include -#include #include "modeltest.h" #include "core/DatabaseIcons.h" diff --git a/tests/TestEntrySearcher.cpp b/tests/TestEntrySearcher.cpp index 6b951c703..25d83e4d2 100644 --- a/tests/TestEntrySearcher.cpp +++ b/tests/TestEntrySearcher.cpp @@ -16,8 +16,7 @@ */ #include "TestEntrySearcher.h" - -#include +#include "TestGlobal.h" QTEST_GUILESS_MAIN(TestEntrySearcher) diff --git a/tests/TestGlobal.h b/tests/TestGlobal.h new file mode 100644 index 000000000..017fbd5f9 --- /dev/null +++ b/tests/TestGlobal.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2018 KeePassXC Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KEEPASSXC_TESTGLOBAL_H +#define KEEPASSXC_TESTGLOBAL_H + +#include "core/Uuid.h" +#include "core/Group.h" + +#include +#include + +namespace QTest { + +template<> +inline char* toString(const Uuid& uuid) +{ + QByteArray ba = "Uuid("; + ba += uuid.toHex().toLatin1().constData(); + ba += ")"; + return qstrdup(ba.constData()); +} + +template<> +inline char* toString(const Group::TriState& triState) +{ + QString value; + + if (triState == Group::Inherit) { + value = "null"; + } else if (triState == Group::Enable) { + value = "true"; + } else { + value = "false"; + } + + return qstrdup(value.toLocal8Bit().constData()); +} + +} // namespace QTest + + +namespace Test { + +inline QDateTime datetime(int year, int month, int day, int hour, int min, int second) +{ + return QDateTime( + QDate(year, month, day), + QTime(hour, min, second), + Qt::UTC); +} + +} // namespace Test + +#endif //KEEPASSXC_TESTGLOBAL_H diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index 24bdfeb5a..d9eb2c765 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -17,15 +17,10 @@ */ #include "TestGroup.h" +#include "TestGlobal.h" -#include -#include -#include #include -#include -#include "core/Database.h" -#include "core/Group.h" #include "core/Metadata.h" #include "crypto/Crypto.h" diff --git a/tests/TestGroupModel.cpp b/tests/TestGroupModel.cpp index 1faf82aa2..f9f55e247 100644 --- a/tests/TestGroupModel.cpp +++ b/tests/TestGroupModel.cpp @@ -16,13 +16,11 @@ */ #include "TestGroupModel.h" +#include "TestGlobal.h" #include -#include #include "modeltest.h" -#include "core/Database.h" -#include "core/Group.h" #include "crypto/Crypto.h" #include "gui/group/GroupModel.h" diff --git a/tests/TestHashedBlockStream.cpp b/tests/TestHashedBlockStream.cpp index b78a46ba8..90c96582f 100644 --- a/tests/TestHashedBlockStream.cpp +++ b/tests/TestHashedBlockStream.cpp @@ -16,9 +16,9 @@ */ #include "TestHashedBlockStream.h" +#include "TestGlobal.h" #include -#include #include "FailDevice.h" #include "crypto/Crypto.h" diff --git a/tests/TestKdbx2.cpp b/tests/TestKdbx2.cpp index f10f10b94..c0a0b3074 100644 --- a/tests/TestKdbx2.cpp +++ b/tests/TestKdbx2.cpp @@ -16,17 +16,15 @@ */ #include "TestKdbx2.h" +#include "TestGlobal.h" + #include "crypto/Crypto.h" -#include "keys/CompositeKey.h" #include "keys/PasswordKey.h" #include "format/KeePass2Reader.h" #include "format/KeePass2Writer.h" -#include "core/Entry.h" -#include "core/Group.h" #include "core/Metadata.h" #include "config-keepassx-tests.h" -#include #include QTEST_GUILESS_MAIN(TestKdbx2) diff --git a/tests/TestKdbx3.cpp b/tests/TestKdbx3.cpp index 210ddc752..94ceafb5d 100644 --- a/tests/TestKdbx3.cpp +++ b/tests/TestKdbx3.cpp @@ -16,6 +16,8 @@ */ #include "TestKdbx3.h" +#include "TestGlobal.h" + #include "core/Metadata.h" #include "keys/PasswordKey.h" #include "format/KeePass2.h" @@ -26,7 +28,6 @@ #include "format/KeePass2Repair.h" #include "config-keepassx-tests.h" -#include QTEST_GUILESS_MAIN(TestKdbx3) diff --git a/tests/TestKdbx4.cpp b/tests/TestKdbx4.cpp index 0a21215ac..8fb0f219b 100644 --- a/tests/TestKdbx4.cpp +++ b/tests/TestKdbx4.cpp @@ -16,6 +16,8 @@ */ #include "TestKdbx4.h" +#include "TestGlobal.h" + #include "core/Metadata.h" #include "keys/PasswordKey.h" #include "format/KeePass2.h" @@ -25,7 +27,6 @@ #include "format/KdbxXmlWriter.h" #include "config-keepassx-tests.h" -#include QTEST_GUILESS_MAIN(TestKdbx4) diff --git a/tests/TestKeePass1Reader.cpp b/tests/TestKeePass1Reader.cpp index a4ad56ca6..892f746e4 100644 --- a/tests/TestKeePass1Reader.cpp +++ b/tests/TestKeePass1Reader.cpp @@ -16,14 +16,11 @@ */ #include "TestKeePass1Reader.h" +#include "TestGlobal.h" #include -#include #include "config-keepassx-tests.h" -#include "core/Database.h" -#include "core/Entry.h" -#include "core/Group.h" #include "core/Metadata.h" #include "crypto/Crypto.h" #include "format/KeePass1Reader.h" diff --git a/tests/TestKeePass2Format.cpp b/tests/TestKeePass2Format.cpp index 6c3777387..34daea879 100644 --- a/tests/TestKeePass2Format.cpp +++ b/tests/TestKeePass2Format.cpp @@ -16,8 +16,8 @@ */ #include "TestKeePass2Format.h" +#include "TestGlobal.h" -#include "core/Group.h" #include "core/Metadata.h" #include "crypto/Crypto.h" #include "keys/PasswordKey.h" @@ -26,9 +26,6 @@ #include "FailDevice.h" #include "config-keepassx-tests.h" -#include -#include - void TestKeePass2Format::initTestCase() { QVERIFY(Crypto::init()); @@ -80,14 +77,14 @@ void TestKeePass2Format::testXmlMetadata() { QCOMPARE(m_xmlDb->metadata()->generator(), QString("KeePass")); QCOMPARE(m_xmlDb->metadata()->name(), QString("ANAME")); - QCOMPARE(m_xmlDb->metadata()->nameChanged(), genDT(2010, 8, 8, 17, 24, 53)); + QCOMPARE(m_xmlDb->metadata()->nameChanged(), Test::datetime(2010, 8, 8, 17, 24, 53)); QCOMPARE(m_xmlDb->metadata()->description(), QString("ADESC")); - QCOMPARE(m_xmlDb->metadata()->descriptionChanged(), genDT(2010, 8, 8, 17, 27, 12)); + QCOMPARE(m_xmlDb->metadata()->descriptionChanged(), Test::datetime(2010, 8, 8, 17, 27, 12)); QCOMPARE(m_xmlDb->metadata()->defaultUserName(), QString("DEFUSERNAME")); - QCOMPARE(m_xmlDb->metadata()->defaultUserNameChanged(), genDT(2010, 8, 8, 17, 27, 45)); + QCOMPARE(m_xmlDb->metadata()->defaultUserNameChanged(), Test::datetime(2010, 8, 8, 17, 27, 45)); QCOMPARE(m_xmlDb->metadata()->maintenanceHistoryDays(), 127); QCOMPARE(m_xmlDb->metadata()->color(), QColor(0xff, 0xef, 0x00)); - QCOMPARE(m_xmlDb->metadata()->masterKeyChanged(), genDT(2012, 4, 5, 17, 9, 34)); + QCOMPARE(m_xmlDb->metadata()->masterKeyChanged(), Test::datetime(2012, 4, 5, 17, 9, 34)); QCOMPARE(m_xmlDb->metadata()->masterKeyChangeRec(), 101); QCOMPARE(m_xmlDb->metadata()->masterKeyChangeForce(), -1); QCOMPARE(m_xmlDb->metadata()->protectTitle(), false); @@ -98,9 +95,9 @@ void TestKeePass2Format::testXmlMetadata() QCOMPARE(m_xmlDb->metadata()->recycleBinEnabled(), true); QVERIFY(m_xmlDb->metadata()->recycleBin() != nullptr); QCOMPARE(m_xmlDb->metadata()->recycleBin()->name(), QString("Recycle Bin")); - QCOMPARE(m_xmlDb->metadata()->recycleBinChanged(), genDT(2010, 8, 25, 16, 12, 57)); + QCOMPARE(m_xmlDb->metadata()->recycleBinChanged(), Test::datetime(2010, 8, 25, 16, 12, 57)); QVERIFY(m_xmlDb->metadata()->entryTemplatesGroup() == nullptr); - QCOMPARE(m_xmlDb->metadata()->entryTemplatesGroupChanged(), genDT(2010, 8, 8, 17, 24, 19)); + QCOMPARE(m_xmlDb->metadata()->entryTemplatesGroupChanged(), Test::datetime(2010, 8, 8, 17, 24, 19)); QVERIFY(m_xmlDb->metadata()->lastSelectedGroup() != nullptr); QCOMPARE(m_xmlDb->metadata()->lastSelectedGroup()->name(), QString("NewDatabase")); QVERIFY(m_xmlDb->metadata()->lastTopVisibleGroup() == m_xmlDb->metadata()->lastSelectedGroup()); @@ -147,13 +144,13 @@ void TestKeePass2Format::testXmlGroupRoot() QCOMPARE(group->iconUuid(), Uuid()); QVERIFY(group->isExpanded()); TimeInfo ti = group->timeInfo(); - QCOMPARE(ti.lastModificationTime(), genDT(2010, 8, 8, 17, 24, 27)); - QCOMPARE(ti.creationTime(), genDT(2010, 8, 7, 17, 24, 27)); - QCOMPARE(ti.lastAccessTime(), genDT(2010, 8, 9, 9, 9, 44)); - QCOMPARE(ti.expiryTime(), genDT(2010, 8, 8, 17, 24, 17)); + QCOMPARE(ti.lastModificationTime(), Test::datetime(2010, 8, 8, 17, 24, 27)); + QCOMPARE(ti.creationTime(), Test::datetime(2010, 8, 7, 17, 24, 27)); + QCOMPARE(ti.lastAccessTime(), Test::datetime(2010, 8, 9, 9, 9, 44)); + QCOMPARE(ti.expiryTime(), Test::datetime(2010, 8, 8, 17, 24, 17)); QVERIFY(!ti.expires()); QCOMPARE(ti.usageCount(), 52); - QCOMPARE(ti.locationChanged(), genDT(2010, 8, 8, 17, 24, 27)); + QCOMPARE(ti.locationChanged(), Test::datetime(2010, 8, 8, 17, 24, 27)); QCOMPARE(group->defaultAutoTypeSequence(), QString("")); QCOMPARE(group->autoTypeEnabled(), Group::Inherit); QCOMPARE(group->searchingEnabled(), Group::Inherit); @@ -215,13 +212,13 @@ void TestKeePass2Format::testXmlEntry1() QCOMPARE(entry->tags(), QString("a b c")); const TimeInfo ti = entry->timeInfo(); - QCOMPARE(ti.lastModificationTime(), genDT(2010, 8, 25, 16, 19, 25)); - QCOMPARE(ti.creationTime(), genDT(2010, 8, 25, 16, 13, 54)); - QCOMPARE(ti.lastAccessTime(), genDT(2010, 8, 25, 16, 19, 25)); - QCOMPARE(ti.expiryTime(), genDT(2010, 8, 25, 16, 12, 57)); + QCOMPARE(ti.lastModificationTime(), Test::datetime(2010, 8, 25, 16, 19, 25)); + QCOMPARE(ti.creationTime(), Test::datetime(2010, 8, 25, 16, 13, 54)); + QCOMPARE(ti.lastAccessTime(), Test::datetime(2010, 8, 25, 16, 19, 25)); + QCOMPARE(ti.expiryTime(), Test::datetime(2010, 8, 25, 16, 12, 57)); QVERIFY(!ti.expires()); QCOMPARE(ti.usageCount(), 8); - QCOMPARE(ti.locationChanged(), genDT(2010, 8, 25, 16, 13, 54)); + QCOMPARE(ti.locationChanged(), Test::datetime(2010, 8, 25, 16, 13, 54)); QList attrs = entry->attributes()->keys(); QCOMPARE(entry->attributes()->value("Notes"), QString("Notes")); @@ -320,7 +317,7 @@ void TestKeePass2Format::testXmlEntryHistory() const Entry* entry = entryMain->historyItems().at(0); QCOMPARE(entry->uuid(), entryMain->uuid()); QVERIFY(!entry->parent()); - QCOMPARE(entry->timeInfo().lastModificationTime(), genDT(2010, 8, 25, 16, 13, 54)); + QCOMPARE(entry->timeInfo().lastModificationTime(), Test::datetime(2010, 8, 25, 16, 13, 54)); QCOMPARE(entry->timeInfo().usageCount(), 3); QCOMPARE(entry->title(), QString("Sample Entry")); QCOMPARE(entry->url(), QString("http://www.somesite.com/")); @@ -330,7 +327,7 @@ void TestKeePass2Format::testXmlEntryHistory() const Entry* entry = entryMain->historyItems().at(1); QCOMPARE(entry->uuid(), entryMain->uuid()); QVERIFY(!entry->parent()); - QCOMPARE(entry->timeInfo().lastModificationTime(), genDT(2010, 8, 25, 16, 15, 43)); + QCOMPARE(entry->timeInfo().lastModificationTime(), Test::datetime(2010, 8, 25, 16, 15, 43)); QCOMPARE(entry->timeInfo().usageCount(), 7); QCOMPARE(entry->title(), QString("Sample Entry 1")); QCOMPARE(entry->url(), QString("http://www.somesite.com/")); @@ -344,11 +341,11 @@ void TestKeePass2Format::testXmlDeletedObjects() delObj = objList.takeFirst(); QCOMPARE(delObj.uuid.toBase64(), QString("5K/bzWCSmkCv5OZxYl4N/w==")); - QCOMPARE(delObj.deletionTime, genDT(2010, 8, 25, 16, 14, 12)); + QCOMPARE(delObj.deletionTime, Test::datetime(2010, 8, 25, 16, 14, 12)); delObj = objList.takeFirst(); QCOMPARE(delObj.uuid.toBase64(), QString("80h8uSNWgkKhKCp1TgXF7g==")); - QCOMPARE(delObj.deletionTime, genDT(2010, 8, 25, 16, 14, 14)); + QCOMPARE(delObj.deletionTime, Test::datetime(2010, 8, 25, 16, 14, 14)); QVERIFY(objList.isEmpty()); } @@ -462,16 +459,16 @@ void TestKeePass2Format::testXmlInvalidXmlChars() Entry* entryRead = dbRead->rootGroup()->entries().at(0); EntryAttributes* attrRead = entryRead->attributes(); - QCOMPARE(strToBytes(attrRead->value("PlainInvalid")), QByteArray()); - QCOMPARE(strToBytes(attrRead->value("PlainValid")), strToBytes(strPlainValid)); - QCOMPARE(strToBytes(attrRead->value("SingleHighSurrogate1")), QByteArray()); - QCOMPARE(strToBytes(attrRead->value("SingleHighSurrogate2")), strToBytes(QString("12"))); - QCOMPARE(strToBytes(attrRead->value("HighHighSurrogate")), QByteArray()); - QCOMPARE(strToBytes(attrRead->value("SingleLowSurrogate1")), QByteArray()); - QCOMPARE(strToBytes(attrRead->value("SingleLowSurrogate2")), strToBytes(QString("12"))); - QCOMPARE(strToBytes(attrRead->value("LowLowSurrogate")), QByteArray()); - QCOMPARE(strToBytes(attrRead->value("SurrogateValid1")), strToBytes(strSurrogateValid1)); - QCOMPARE(strToBytes(attrRead->value("SurrogateValid2")), strToBytes(strSurrogateValid2)); + QCOMPARE(attrRead->value("PlainInvalid"), QString()); + QCOMPARE(attrRead->value("PlainValid"), strPlainValid); + QCOMPARE(attrRead->value("SingleHighSurrogate1"), QString()); + QCOMPARE(attrRead->value("SingleHighSurrogate2"), QString("12")); + QCOMPARE(attrRead->value("HighHighSurrogate"), QString()); + QCOMPARE(attrRead->value("SingleLowSurrogate1"), QString()); + QCOMPARE(attrRead->value("SingleLowSurrogate2"), QString("12")); + QCOMPARE(attrRead->value("LowLowSurrogate"), QString()); + QCOMPARE(attrRead->value("SurrogateValid1"), strSurrogateValid1); + QCOMPARE(attrRead->value("SurrogateValid2"), strSurrogateValid2); } void TestKeePass2Format::testXmlRepairUuidHistoryItem() @@ -568,55 +565,3 @@ void TestKeePass2Format::testKdbxDeviceFailure() QVERIFY(hasError); QCOMPARE(errorString, QString("FAILDEVICE")); } - - - -// ==================================================================================================== -// Helper functions -// ==================================================================================================== - -namespace QTest { -template<> -char* toString(const Uuid& uuid) -{ - QByteArray ba = "Uuid("; - ba += uuid.toBase64().toLatin1().constData(); - ba += ")"; - return qstrdup(ba.constData()); -} - -template<> -char* toString(const Group::TriState& triState) -{ - QString value; - - if (triState == Group::Inherit) { - value = "null"; - } else if (triState == Group::Enable) { - value = "true"; - } else { - value = "false"; - } - - return qstrdup(value.toLocal8Bit().constData()); -} -} - -QDateTime TestKeePass2Format::genDT(int year, int month, int day, int hour, int min, int second) -{ - QDate date(year, month, day); - QTime time(hour, min, second); - return QDateTime(date, time, Qt::UTC); -} - -QByteArray TestKeePass2Format::strToBytes(const QString& str) -{ - QByteArray result; - - for (auto i : str) { - result.append(static_cast(i.unicode() >> 8)); - result.append(static_cast(i.unicode() & 0xFF)); - } - - return result; -} diff --git a/tests/TestKeePass2Format.h b/tests/TestKeePass2Format.h index 11420bab0..a2bdd4f49 100644 --- a/tests/TestKeePass2Format.h +++ b/tests/TestKeePass2Format.h @@ -77,9 +77,6 @@ protected: bool& hasError, QString& errorString) = 0; virtual void writeKdbx(QIODevice* device, Database* db, bool& hasError, QString& errorString) = 0; - static QDateTime genDT(int year, int month, int day, int hour, int min, int second); - static QByteArray strToBytes(const QString& str); - QScopedPointer m_xmlDb; QScopedPointer m_kdbxSourceDb; QScopedPointer m_kdbxTargetDb; diff --git a/tests/TestKeePass2RandomStream.cpp b/tests/TestKeePass2RandomStream.cpp index 53852e82d..edb95b6c6 100644 --- a/tests/TestKeePass2RandomStream.cpp +++ b/tests/TestKeePass2RandomStream.cpp @@ -16,13 +16,11 @@ */ #include "TestKeePass2RandomStream.h" - -#include +#include "TestGlobal.h" #include "crypto/Crypto.h" #include "crypto/CryptoHash.h" #include "crypto/SymmetricCipher.h" -#include "format/KeePass2.h" #include "format/KeePass2RandomStream.h" QTEST_GUILESS_MAIN(TestKeePass2RandomStream) diff --git a/tests/TestKeys.cpp b/tests/TestKeys.cpp index 811a7688f..094a397d7 100644 --- a/tests/TestKeys.cpp +++ b/tests/TestKeys.cpp @@ -17,13 +17,12 @@ */ #include "TestKeys.h" +#include "TestGlobal.h" #include -#include #include "config-keepassx-tests.h" -#include "core/Database.h" #include "core/Metadata.h" #include "core/Tools.h" #include "crypto/Crypto.h" diff --git a/tests/TestMerge.cpp b/tests/TestMerge.cpp index d68c4f102..8f38a2f85 100644 --- a/tests/TestMerge.cpp +++ b/tests/TestMerge.cpp @@ -16,12 +16,8 @@ */ #include "TestMerge.h" +#include "TestGlobal.h" -#include -#include - -#include "core/Database.h" -#include "core/Group.h" #include "core/Metadata.h" #include "crypto/Crypto.h" diff --git a/tests/TestOpenSSHKey.cpp b/tests/TestOpenSSHKey.cpp index 949c708cf..55033d7e1 100644 --- a/tests/TestOpenSSHKey.cpp +++ b/tests/TestOpenSSHKey.cpp @@ -16,9 +16,9 @@ */ #include "TestOpenSSHKey.h" -#include "crypto/Crypto.h" +#include "TestGlobal.h" #include "sshagent/OpenSSHKey.h" -#include +#include "crypto/Crypto.h" QTEST_GUILESS_MAIN(TestOpenSSHKey) diff --git a/tests/TestRandom.cpp b/tests/TestRandom.cpp index 69f0fcb7c..7575e3a58 100644 --- a/tests/TestRandom.cpp +++ b/tests/TestRandom.cpp @@ -16,11 +16,10 @@ */ #include "TestRandom.h" - +#include "TestGlobal.h" #include "core/Endian.h" #include "core/Global.h" -#include QTEST_GUILESS_MAIN(TestRandom) diff --git a/tests/TestSymmetricCipher.cpp b/tests/TestSymmetricCipher.cpp index bfa3c3db8..f1e7c0e06 100644 --- a/tests/TestSymmetricCipher.cpp +++ b/tests/TestSymmetricCipher.cpp @@ -17,9 +17,9 @@ */ #include "TestSymmetricCipher.h" +#include "TestGlobal.h" #include -#include #include "crypto/Crypto.h" #include "crypto/SymmetricCipher.h" diff --git a/tests/TestTotp.cpp b/tests/TestTotp.cpp index 06e360148..dd69a076d 100644 --- a/tests/TestTotp.cpp +++ b/tests/TestTotp.cpp @@ -17,12 +17,7 @@ */ #include "TestTotp.h" - -#include -#include -#include -#include -#include +#include "TestGlobal.h" #include "crypto/Crypto.h" #include "totp/totp.h" diff --git a/tests/TestWildcardMatcher.cpp b/tests/TestWildcardMatcher.cpp index 621dc898e..e5d1d117d 100644 --- a/tests/TestWildcardMatcher.cpp +++ b/tests/TestWildcardMatcher.cpp @@ -16,9 +16,7 @@ */ #include "TestWildcardMatcher.h" - -#include - +#include "TestGlobal.h" #include "autotype/WildcardMatcher.h" QTEST_GUILESS_MAIN(TestWildcardMatcher) diff --git a/tests/TestYkChallengeResponseKey.cpp b/tests/TestYkChallengeResponseKey.cpp index 558920f4a..276ba7325 100644 --- a/tests/TestYkChallengeResponseKey.cpp +++ b/tests/TestYkChallengeResponseKey.cpp @@ -18,36 +18,23 @@ */ #include "TestYkChallengeResponseKey.h" - -#include -#include - +#include "TestGlobal.h" #include "crypto/Crypto.h" -#include "keys/YkChallengeResponseKey.h" + +#include QTEST_GUILESS_MAIN(TestYubiKeyChalResp) void TestYubiKeyChalResp::initTestCase() { - m_detected = 0; - m_key = NULL; - // crypto subsystem needs to be initialized for YubiKey testing QVERIFY(Crypto::init()); } -void TestYubiKeyChalResp::cleanupTestCase() -{ - if (m_key) - delete m_key; -} - void TestYubiKeyChalResp::init() { - bool result = YubiKey::instance()->init(); - - if (!result) { - QSKIP("Unable to connect to YubiKey", SkipAll); + if (!YubiKey::instance()->init()) { + QSKIP("Unable to connect to YubiKey"); } } @@ -104,7 +91,7 @@ void TestYubiKeyChalResp::ykDetected(int slot, bool blocking) /* Key used for later testing */ if (!m_key) - m_key = new YkChallengeResponseKey(slot, blocking); + m_key.reset(new YkChallengeResponseKey(slot, blocking)); } void TestYubiKeyChalResp::deinit() diff --git a/tests/TestYkChallengeResponseKey.h b/tests/TestYkChallengeResponseKey.h index 2bc344ec0..82223ec35 100644 --- a/tests/TestYkChallengeResponseKey.h +++ b/tests/TestYkChallengeResponseKey.h @@ -20,6 +20,7 @@ #define KEEPASSX_TESTYUBIKEYCHALRESP_H #include +#include #include "keys/YkChallengeResponseKey.h" @@ -29,7 +30,6 @@ class TestYubiKeyChalResp: public QObject private slots: void initTestCase(); - void cleanupTestCase(); void init(); @@ -48,8 +48,8 @@ private slots: void ykDetected(int slot, bool blocking); private: - int m_detected; - YkChallengeResponseKey *m_key; + int m_detected = 0; + QScopedPointer m_key; }; #endif // KEEPASSX_TESTYUBIKEYCHALRESP_H diff --git a/tests/gui/CMakeLists.txt b/tests/gui/CMakeLists.txt index 4c0eebbe6..6cae88830 100644 --- a/tests/gui/CMakeLists.txt +++ b/tests/gui/CMakeLists.txt @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) + add_unit_test(NAME testgui SOURCES TestGui.cpp TemporaryFile.cpp LIBS ${TEST_LIBRARIES}) add_unit_test(NAME testguipixmaps SOURCES TestGuiPixmaps.cpp LIBS ${TEST_LIBRARIES}) diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index a663b30a3..44b1d0664 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -17,6 +17,7 @@ */ #include "TestGui.h" +#include "TestGlobal.h" #include #include @@ -29,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/gui/TestGuiPixmaps.cpp b/tests/gui/TestGuiPixmaps.cpp index 363749474..c71fe51b9 100644 --- a/tests/gui/TestGuiPixmaps.cpp +++ b/tests/gui/TestGuiPixmaps.cpp @@ -16,13 +16,8 @@ */ #include "TestGuiPixmaps.h" - -#include - -#include "core/Database.h" +#include "TestGlobal.h" #include "core/DatabaseIcons.h" -#include "core/Entry.h" -#include "core/Group.h" #include "core/Metadata.h" #include "crypto/Crypto.h"