Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorangelsl <angelsl@in04.sg>2017-11-12 21:55:03 +0300
committerJonathan White <support@dmapps.us>2018-01-13 22:23:26 +0300
commit3461cbfb060012dbdaaea5af418eccbeb0fedc04 (patch)
tree4824ed67f9ad0538cda784c4afb9c32ab7b6163c /tests
parente5ec585f983d17fba5db23fa510776d65bceb9e6 (diff)
Rename KeePass2{,Xml}{R,W} to Kdbx3{,Xml}{R,W}, and add a redirection class
This class will in future select Kdbx4{R,W} as appropriate.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/TestDeletedObjects.cpp4
-rw-r--r--tests/TestKdbx3XmlReader.cpp22
-rw-r--r--tests/TestKeePass2Writer.cpp1
-rw-r--r--tests/TestKeePass2XmlReader.cpp112
-rw-r--r--tests/TestKeePass2XmlReader.h23
6 files changed, 123 insertions, 41 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index c36eefd4a..bdf0e6f86 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -107,7 +107,7 @@ endif()
add_unit_test(NAME testgroup SOURCES TestGroup.cpp
LIBS ${TEST_LIBRARIES})
-add_unit_test(NAME testkeepass2xmlreader SOURCES TestKeePass2XmlReader.cpp
+add_unit_test(NAME testkdbx3xmlreader SOURCES TestKeePass2XmlReader.cpp TestKdbx3XmlReader.cpp
LIBS ${TEST_LIBRARIES})
add_unit_test(NAME testkeys SOURCES TestKeys.cpp
diff --git a/tests/TestDeletedObjects.cpp b/tests/TestDeletedObjects.cpp
index 5af017885..371d318db 100644
--- a/tests/TestDeletedObjects.cpp
+++ b/tests/TestDeletedObjects.cpp
@@ -22,7 +22,7 @@
#include "core/Database.h"
#include "core/Group.h"
#include "crypto/Crypto.h"
-#include "format/KeePass2XmlReader.h"
+#include "format/Kdbx3XmlReader.h"
#include "config-keepassx-tests.h"
QTEST_GUILESS_MAIN(TestDeletedObjects)
@@ -88,7 +88,7 @@ void TestDeletedObjects::createAndDelete(Database* db, int delObjectsSize)
void TestDeletedObjects::testDeletedObjectsFromFile()
{
- KeePass2XmlReader reader;
+ Kdbx3XmlReader reader;
reader.setStrictMode(true);
QString xmlFile = QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.xml");
Database* db = reader.readDatabase(xmlFile);
diff --git a/tests/TestKdbx3XmlReader.cpp b/tests/TestKdbx3XmlReader.cpp
new file mode 100644
index 000000000..d4ce58542
--- /dev/null
+++ b/tests/TestKdbx3XmlReader.cpp
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <QTest>
+
+#include "TestKeePass2XmlReader.h"
+
+QTEST_GUILESS_MAIN(TestKdbx3XmlReader)
diff --git a/tests/TestKeePass2Writer.cpp b/tests/TestKeePass2Writer.cpp
index f6d3f58ad..049c3e66e 100644
--- a/tests/TestKeePass2Writer.cpp
+++ b/tests/TestKeePass2Writer.cpp
@@ -30,7 +30,6 @@
#include "format/KeePass2Reader.h"
#include "format/KeePass2Repair.h"
#include "format/KeePass2Writer.h"
-#include "format/KeePass2XmlWriter.h"
#include "keys/PasswordKey.h"
QTEST_GUILESS_MAIN(TestKeePass2Writer)
diff --git a/tests/TestKeePass2XmlReader.cpp b/tests/TestKeePass2XmlReader.cpp
index 495b39acf..c1e3b4b63 100644
--- a/tests/TestKeePass2XmlReader.cpp
+++ b/tests/TestKeePass2XmlReader.cpp
@@ -25,12 +25,10 @@
#include "core/Group.h"
#include "core/Metadata.h"
#include "crypto/Crypto.h"
-#include "format/KeePass2XmlReader.h"
-#include "format/KeePass2XmlWriter.h"
+#include "format/Kdbx3XmlReader.h"
+#include "format/Kdbx3XmlWriter.h"
#include "config-keepassx-tests.h"
-QTEST_GUILESS_MAIN(TestKeePass2XmlReader)
-
namespace QTest {
template<>
char* toString(const Uuid& uuid)
@@ -79,11 +77,11 @@ QByteArray TestKeePass2XmlReader::strToBytes(const QString& str)
return result;
}
-void TestKeePass2XmlReader::initTestCase()
+void TestKdbx3XmlReader::initTestCase()
{
QVERIFY(Crypto::init());
- KeePass2XmlReader reader;
+ Kdbx3XmlReader reader;
reader.setStrictMode(true);
QString xmlFile = QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.xml");
m_db = reader.readDatabase(xmlFile);
@@ -91,6 +89,32 @@ void TestKeePass2XmlReader::initTestCase()
QVERIFY(!reader.hasError());
}
+void TestKdbx3XmlReader::readDatabase(QString path, bool strictMode, Database*& db, bool& hasError, QString& errorString)
+{
+ Kdbx3XmlReader reader;
+ reader.setStrictMode(strictMode);
+ db = reader.readDatabase(path);
+ hasError = reader.hasError();
+ errorString = reader.errorString();
+}
+
+void TestKdbx3XmlReader::readDatabase(QBuffer* buf, bool strictMode, Database*& db, bool& hasError, QString& errorString)
+{
+ Kdbx3XmlReader reader;
+ reader.setStrictMode(strictMode);
+ db = reader.readDatabase(buf);
+ hasError = reader.hasError();
+ errorString = reader.errorString();
+}
+
+void TestKdbx3XmlReader::writeDatabase(QBuffer* buf, Database* db, bool& hasError, QString& errorString)
+{
+ Kdbx3XmlWriter writer;
+ writer.writeDatabase(buf, db);
+ hasError = writer.hasError();
+ errorString = writer.errorString();
+}
+
void TestKeePass2XmlReader::testMetadata()
{
QCOMPARE(m_db->metadata()->generator(), QString("KeePass"));
@@ -374,15 +398,20 @@ void TestKeePass2XmlReader::testBroken()
QFETCH(bool, strictMode);
QFETCH(bool, expectError);
- KeePass2XmlReader reader;
- reader.setStrictMode(strictMode);
+
QString xmlFile = QString("%1/%2.xml").arg(KEEPASSX_TEST_DATA_DIR, baseName);
QVERIFY(QFile::exists(xmlFile));
- QScopedPointer<Database> db(reader.readDatabase(xmlFile));
- if (reader.hasError()) {
- qWarning("Reader error: %s", qPrintable(reader.errorString()));
+ bool hasError;
+ QString errorString;
+ Database* db;
+ readDatabase(xmlFile, strictMode, db, hasError, errorString);
+ if (hasError) {
+ qWarning("Reader error: %s", qPrintable(errorString));
+ }
+ QCOMPARE(hasError, expectError);
+ if (db) {
+ delete db;
}
- QCOMPARE(reader.hasError(), expectError);
}
void TestKeePass2XmlReader::testBroken_data()
@@ -412,15 +441,20 @@ void TestKeePass2XmlReader::testBroken_data()
void TestKeePass2XmlReader::testEmptyUuids()
{
- KeePass2XmlReader reader;
- reader.setStrictMode(true);
+
QString xmlFile = QString("%1/%2.xml").arg(KEEPASSX_TEST_DATA_DIR, "EmptyUuids");
QVERIFY(QFile::exists(xmlFile));
- QScopedPointer<Database> db(reader.readDatabase(xmlFile));
- if (reader.hasError()) {
- qWarning("Reader error: %s", qPrintable(reader.errorString()));
+ Database* dbp;
+ bool hasError;
+ QString errorString;
+ readDatabase(xmlFile, true, dbp, hasError, errorString);
+ if (hasError) {
+ qWarning("Reader error: %s", qPrintable(errorString));
+ }
+ QVERIFY(!hasError);
+ if (dbp) {
+ delete dbp;
}
- QVERIFY(!reader.hasError());
}
void TestKeePass2XmlReader::testInvalidXmlChars()
@@ -459,19 +493,19 @@ void TestKeePass2XmlReader::testInvalidXmlChars()
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
- KeePass2XmlWriter writer;
- writer.writeDatabase(&buffer, dbWrite.data());
- QVERIFY(!writer.hasError());
+ bool hasError;
+ QString errorString;
+ writeDatabase(&buffer, dbWrite.data(), hasError, errorString);
+ QVERIFY(!hasError);
buffer.seek(0);
- KeePass2XmlReader reader;
- reader.setStrictMode(true);
- QScopedPointer<Database> dbRead(reader.readDatabase(&buffer));
- if (reader.hasError()) {
- qWarning("Database read error: %s", qPrintable(reader.errorString()));
+ Database* dbRead;
+ readDatabase(&buffer, true, dbRead, hasError, errorString);
+ if (hasError) {
+ qWarning("Database read error: %s", qPrintable(errorString));
}
- QVERIFY(!reader.hasError());
- QVERIFY(!dbRead.isNull());
+ QVERIFY(!hasError);
+ QVERIFY(dbRead);
QCOMPARE(dbRead->rootGroup()->entries().size(), 1);
Entry* entryRead = dbRead->rootGroup()->entries().at(0);
EntryAttributes* attrRead = entryRead->attributes();
@@ -486,22 +520,28 @@ void TestKeePass2XmlReader::testInvalidXmlChars()
QCOMPARE(strToBytes(attrRead->value("LowLowSurrogate")), QByteArray());
QCOMPARE(strToBytes(attrRead->value("SurrogateValid1")), strToBytes(strSurrogateValid1));
QCOMPARE(strToBytes(attrRead->value("SurrogateValid2")), strToBytes(strSurrogateValid2));
+
+ if (dbRead) {
+ delete dbRead;
+ }
}
void TestKeePass2XmlReader::testRepairUuidHistoryItem()
{
- KeePass2XmlReader reader;
QString xmlFile = QString("%1/%2.xml").arg(KEEPASSX_TEST_DATA_DIR, "BrokenDifferentEntryHistoryUuid");
QVERIFY(QFile::exists(xmlFile));
- QScopedPointer<Database> db(reader.readDatabase(xmlFile));
- if (reader.hasError()) {
- qWarning("Database read error: %s", qPrintable(reader.errorString()));
+ Database* db;
+ bool hasError;
+ QString errorString;
+ readDatabase(xmlFile, true, db, hasError, errorString);
+ if (hasError) {
+ qWarning("Database read error: %s", qPrintable(errorString));
}
- QVERIFY(!reader.hasError());
+ QVERIFY(!hasError);
- QList<Entry*> entries = db.data()->rootGroup()->entries();
+ QList<Entry*> entries = db->rootGroup()->entries();
QCOMPARE(entries.size(), 1);
Entry* entry = entries.at(0);
@@ -512,6 +552,10 @@ void TestKeePass2XmlReader::testRepairUuidHistoryItem()
QVERIFY(!entry->uuid().isNull());
QVERIFY(!historyItem->uuid().isNull());
QCOMPARE(historyItem->uuid(), entry->uuid());
+
+ if (db) {
+ delete db;
+ }
}
void TestKeePass2XmlReader::cleanupTestCase()
diff --git a/tests/TestKeePass2XmlReader.h b/tests/TestKeePass2XmlReader.h
index 628964b46..2ce122235 100644
--- a/tests/TestKeePass2XmlReader.h
+++ b/tests/TestKeePass2XmlReader.h
@@ -20,6 +20,7 @@
#include <QDateTime>
#include <QObject>
+#include <QBuffer>
class Database;
@@ -27,8 +28,8 @@ class TestKeePass2XmlReader : public QObject
{
Q_OBJECT
-private slots:
- void initTestCase();
+protected slots:
+ virtual void initTestCase() = 0;
void testMetadata();
void testCustomIcons();
void testCustomData();
@@ -46,11 +47,27 @@ private slots:
void testRepairUuidHistoryItem();
void cleanupTestCase();
-private:
+protected:
+ virtual void readDatabase(QBuffer* buf, bool strictMode, Database*& db, bool& hasError, QString& errorString) = 0;
+ virtual void readDatabase(QString path, bool strictMode, Database*& db, bool& hasError, QString& errorString) = 0;
+ virtual void writeDatabase(QBuffer* buf, 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);
Database* m_db;
};
+class TestKdbx3XmlReader : public TestKeePass2XmlReader
+{
+ Q_OBJECT
+
+private slots:
+ virtual void initTestCase() override;
+
+protected:
+ virtual void readDatabase(QBuffer* buf, bool strictMode, Database*& db, bool& hasError, QString& errorString) override;
+ virtual void readDatabase(QString path, bool strictMode, Database*& db, bool& hasError, QString& errorString) override;
+ virtual void writeDatabase(QBuffer* buf, Database* db, bool& hasError, QString& errorString) override;
+};
+
#endif // KEEPASSX_TESTKEEPASS2XMLREADER_H