Test if we correctly detect errors when writing.

This commit is contained in:
Felix Geyer 2015-07-20 21:32:07 +02:00
parent 606e36acf3
commit 2033174d95
7 changed files with 158 additions and 7 deletions

View file

@ -21,12 +21,14 @@
#include <QTest>
#include "tests.h"
#include "FailDevice.h"
#include "core/Database.h"
#include "core/Group.h"
#include "core/Metadata.h"
#include "crypto/Crypto.h"
#include "format/KeePass2Reader.h"
#include "format/KeePass2Writer.h"
#include "format/KeePass2XmlWriter.h"
#include "keys/PasswordKey.h"
QTEST_GUILESS_MAIN(TestKeePass2Writer)
@ -101,6 +103,30 @@ void TestKeePass2Writer::testNonAsciiPasswords()
QCOMPARE(m_dbTest->rootGroup()->entries()[0]->password(), m_dbOrg->rootGroup()->entries()[0]->password());
}
void TestKeePass2Writer::testDeviceFailure()
{
CompositeKey key;
key.addKey(PasswordKey("test"));
Database* db = new Database();
db->setKey(key);
// Disable compression so we write a predictable number of bytes.
db->setCompressionAlgo(Database::CompressionNone);
Entry* entry = new Entry();
entry->setParent(db->rootGroup());
QByteArray attachment(4096, 'Z');
entry->attachments()->set("test", attachment);
FailDevice failDevice(512);
QVERIFY(failDevice.open(QIODevice::WriteOnly));
KeePass2Writer writer;
writer.writeDatabase(&failDevice, db);
QVERIFY(writer.hasError());
QCOMPARE(writer.errorString(), QString("FAILDEVICE"));
delete db;
}
void TestKeePass2Writer::cleanupTestCase()
{
delete m_dbOrg;