Add tests for modified, fix history for autotype

Added tests to ensure #1387 works
Fixed issue detected during testing - AutoTypeAssociations were not
pushed to history
This commit is contained in:
Christian Kieschnick 2018-01-15 18:17:56 +01:00 committed by Janek Bevendorff
parent 045f157a63
commit 943dc6cdd6
No known key found for this signature in database
GPG Key ID: 2FDEB0D40BCA5E11
4 changed files with 57 additions and 5 deletions

View File

@ -633,7 +633,7 @@ Entry* Entry::clone(CloneFlags flags) const
entry->m_attributes->set(EntryAttributes::PasswordKey, password.toUpper(), m_attributes->isProtected(EntryAttributes::PasswordKey)); entry->m_attributes->set(EntryAttributes::PasswordKey, password.toUpper(), m_attributes->isProtected(EntryAttributes::PasswordKey));
} }
entry->m_autoTypeAssociations->copyDataFrom(this->m_autoTypeAssociations); entry->m_autoTypeAssociations->copyDataFrom(m_autoTypeAssociations);
if (flags & CloneIncludeHistory) { if (flags & CloneIncludeHistory) {
for (Entry* historyItem : m_history) { for (Entry* historyItem : m_history) {
Entry* historyItemClone = historyItem->clone(flags & ~CloneIncludeHistory & ~CloneNewUuid); Entry* historyItemClone = historyItem->clone(flags & ~CloneIncludeHistory & ~CloneNewUuid);
@ -679,6 +679,7 @@ void Entry::beginUpdate()
m_tmpHistoryItem->m_data = m_data; m_tmpHistoryItem->m_data = m_data;
m_tmpHistoryItem->m_attributes->copyDataFrom(m_attributes); m_tmpHistoryItem->m_attributes->copyDataFrom(m_attributes);
m_tmpHistoryItem->m_attachments->copyDataFrom(m_attachments); m_tmpHistoryItem->m_attachments->copyDataFrom(m_attachments);
m_tmpHistoryItem->m_autoTypeAssociations->copyDataFrom(m_autoTypeAssociations);
m_modifiedSinceBegin = false; m_modifiedSinceBegin = false;
} }

View File

@ -156,9 +156,13 @@ bool EntryAttachments::operator!=(const EntryAttachments& other) const
int EntryAttachments::attachmentsSize(const QSet<QByteArray> &ignoredAttachments) const int EntryAttachments::attachmentsSize(const QSet<QByteArray> &ignoredAttachments) const
{ {
int size = 0; int size = 0;
const QSet<QByteArray> consideredAttachments = m_attachments.values().toSet() - ignoredAttachments;
for (const QByteArray& attachment : consideredAttachments) { QMapIterator<QString, QByteArray> i(m_attachments);
size += attachment.size(); while (i.hasNext()) {
i.next();
if( ! ignoredAttachments.contains( i.value() )){
size += i.key().toUtf8().size() + i.value().size();
}
} }
return size; return size;
} }

View File

@ -20,7 +20,6 @@
#include <QTest> #include <QTest>
#include "core/Database.h"
#include "core/Entry.h" #include "core/Entry.h"
#include "core/Group.h" #include "core/Group.h"
#include "crypto/Crypto.h" #include "crypto/Crypto.h"
@ -48,6 +47,7 @@ void TestEntry::testHistoryItemDeletion()
delete entry; delete entry;
} }
void TestEntry::testCopyDataFrom() void TestEntry::testCopyDataFrom()
{ {
Entry* entry = new Entry(); Entry* entry = new Entry();

View File

@ -465,5 +465,52 @@ void TestModified::testHistoryItem()
entry3->endUpdate(); entry3->endUpdate();
QCOMPARE(entry3->historyItems().size(), 2); QCOMPARE(entry3->historyItems().size(), 2);
Entry* entry4 = new Entry();
entry4->setGroup(root);
QCOMPARE(entry4->historyItems().size(), 0);
int reservedSize = entry4->attributes()->attributesSize();
entry4->beginUpdate();
entry4->attachments()->set("test1", QByteArray(17000 - 5 - reservedSize + 1, 'a'));
entry4->endUpdate();
QCOMPARE(entry4->historyItems().size(), 1);
entry4->beginUpdate();
entry4->attachments()->remove("test1");
entry4->endUpdate();
QCOMPARE(entry4->historyItems().size(), 0);
entry4->beginUpdate();
entry4->setTags(QByteArray(17000 - reservedSize + 1, 'a'));
entry4->endUpdate();
QCOMPARE(entry4->historyItems().size(), 1);
entry4->beginUpdate();
entry4->setTags("");
entry4->endUpdate();
QCOMPARE(entry4->historyItems().size(), 0);
entry4->beginUpdate();
entry4->attributes()->set("test3", QByteArray(17000 - 5 - reservedSize + 1, 'a'));
entry4->endUpdate();
QCOMPARE(entry4->historyItems().size(), 1);
entry4->beginUpdate();
entry4->attributes()->remove("test3");
entry4->endUpdate();
QCOMPARE(entry4->historyItems().size(), 0);
entry4->beginUpdate();
AutoTypeAssociations::Association association;
association.window = "test3";
association.sequence = QByteArray(17000 - 5 - reservedSize + 1, 'a');
entry4->autoTypeAssociations()->add(association);
entry4->endUpdate();
QCOMPARE(entry4->historyItems().size(), 1);
entry4->beginUpdate();
entry4->autoTypeAssociations()->remove(0);
entry4->endUpdate();
QCOMPARE(entry4->historyItems().size(), 0);
delete db; delete db;
} }