Refactor database readers/writers and XML handling

* Refactor Kdbx*Reader
* Refactor KdbxWriter
* Refactor KdbxXmlReader
* Refactor KdbxXmlWriter
This commit is contained in:
Janek Bevendorff 2018-01-07 04:08:32 +01:00 committed by Jonathan White
parent 72a1c65d00
commit a6ddc22fb8
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
29 changed files with 1313 additions and 2917 deletions

View file

@ -20,15 +20,14 @@
#include <QBuffer>
#include <QFile>
#include <QTest>
#include <format/KeePass2.h>
#include "core/Database.h"
#include "core/Group.h"
#include "core/Metadata.h"
#include "crypto/Crypto.h"
#include "format/Kdbx3XmlReader.h"
#include "format/Kdbx3XmlWriter.h"
#include "format/Kdbx4XmlReader.h"
#include "format/Kdbx4XmlWriter.h"
#include "format/KdbxXmlReader.h"
#include "format/KdbxXmlWriter.h"
#include "config-keepassx-tests.h"
namespace QTest {
@ -83,7 +82,7 @@ void TestKdbx3XmlReader::initTestCase()
{
QVERIFY(Crypto::init());
Kdbx3XmlReader reader;
KdbxXmlReader reader(KeePass2::FILE_VERSION_3);
reader.setStrictMode(true);
QString xmlFile = QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.xml");
m_db = reader.readDatabase(xmlFile);
@ -95,7 +94,7 @@ void TestKdbx4XmlReader::initTestCase()
{
QVERIFY(Crypto::init());
Kdbx4XmlReader reader;
KdbxXmlReader reader(KeePass2::FILE_VERSION_3);
reader.setStrictMode(true);
QString xmlFile = QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.xml");
m_db = reader.readDatabase(xmlFile);
@ -105,7 +104,7 @@ void TestKdbx4XmlReader::initTestCase()
void TestKdbx3XmlReader::readDatabase(QString path, bool strictMode, Database*& db, bool& hasError, QString& errorString)
{
Kdbx3XmlReader reader;
KdbxXmlReader reader(KeePass2::FILE_VERSION_3);
reader.setStrictMode(strictMode);
db = reader.readDatabase(path);
hasError = reader.hasError();
@ -114,7 +113,7 @@ void TestKdbx3XmlReader::readDatabase(QString path, bool strictMode, Database*&
void TestKdbx3XmlReader::readDatabase(QBuffer* buf, bool strictMode, Database*& db, bool& hasError, QString& errorString)
{
Kdbx3XmlReader reader;
KdbxXmlReader reader(KeePass2::FILE_VERSION_3);
reader.setStrictMode(strictMode);
db = reader.readDatabase(buf);
hasError = reader.hasError();
@ -123,7 +122,7 @@ void TestKdbx3XmlReader::readDatabase(QBuffer* buf, bool strictMode, Database*&
void TestKdbx3XmlReader::writeDatabase(QBuffer* buf, Database* db, bool& hasError, QString& errorString)
{
Kdbx3XmlWriter writer;
KdbxXmlWriter writer(KeePass2::FILE_VERSION_3);
writer.writeDatabase(buf, db);
hasError = writer.hasError();
errorString = writer.errorString();
@ -131,7 +130,7 @@ void TestKdbx3XmlReader::writeDatabase(QBuffer* buf, Database* db, bool& hasErro
void TestKdbx4XmlReader::readDatabase(QString path, bool strictMode, Database*& db, bool& hasError, QString& errorString)
{
Kdbx4XmlReader reader;
KdbxXmlReader reader(KeePass2::FILE_VERSION_3);
reader.setStrictMode(strictMode);
db = reader.readDatabase(path);
hasError = reader.hasError();
@ -140,7 +139,7 @@ void TestKdbx4XmlReader::readDatabase(QString path, bool strictMode, Database*&
void TestKdbx4XmlReader::readDatabase(QBuffer* buf, bool strictMode, Database*& db, bool& hasError, QString& errorString)
{
Kdbx4XmlReader reader;
KdbxXmlReader reader(KeePass2::FILE_VERSION_3);
reader.setStrictMode(strictMode);
db = reader.readDatabase(buf);
hasError = reader.hasError();
@ -149,7 +148,7 @@ void TestKdbx4XmlReader::readDatabase(QBuffer* buf, bool strictMode, Database*&
void TestKdbx4XmlReader::writeDatabase(QBuffer* buf, Database* db, bool& hasError, QString& errorString)
{
Kdbx4XmlWriter writer;
KdbxXmlWriter writer(KeePass2::FILE_VERSION_3);
writer.writeDatabase(buf, db);
hasError = writer.hasError();
errorString = writer.errorString();