Add Entry::copyDataFrom().

This commit is contained in:
Felix Geyer 2013-04-14 14:21:42 +02:00
parent 3658a65380
commit 61ee763515
4 changed files with 47 additions and 0 deletions

View File

@ -452,6 +452,16 @@ Entry* Entry::clone() const
return entry;
}
void Entry::copyDataFrom(const Entry* other)
{
setUpdateTimeinfo(false);
m_data = other->m_data;
m_attributes->copyDataFrom(other->m_attributes);
m_attachments->copyDataFrom(other->m_attachments);
m_autoTypeAssociations->copyDataFrom(other->m_autoTypeAssociations);
setUpdateTimeinfo(true);
}
void Entry::beginUpdate()
{
Q_ASSERT(!m_tmpHistoryItem);

View File

@ -111,6 +111,7 @@ public:
void removeHistoryItems(const QList<Entry*>& historyEntries);
void truncateHistory();
Entry* clone() const;
void copyDataFrom(const Entry* other);
QString resolvePlaceholders(const QString& str) const;
/**

View File

@ -38,5 +38,40 @@ void TestEntry::testHistoryItemDeletion()
delete entry;
}
void TestEntry::testCopyDataFrom()
{
Entry* entry = new Entry();
entry->setTitle("testtitle");
entry->attributes()->set("attr1", "abc");
entry->attributes()->set("attr2", "def");
entry->attachments()->set("test", "123");
entry->attachments()->set("test2", "456");
AutoTypeAssociations::Association assoc;
assoc.window = "1";
assoc.sequence = "2";
entry->autoTypeAssociations()->add(assoc);
assoc.window = "3";
assoc.sequence = "4";
entry->autoTypeAssociations()->add(assoc);
Entry* entry2 = new Entry();
entry2->copyDataFrom(entry);
delete entry;
QCOMPARE(entry2->title(), QString("testtitle"));
QCOMPARE(entry2->attributes()->value("attr1"), QString("abc"));
QCOMPARE(entry2->attributes()->value("attr2"), QString("def"));
QCOMPARE(entry2->attachments()->keys().size(), 2);
QCOMPARE(entry2->attachments()->value("test"), QByteArray("123"));
QCOMPARE(entry2->attachments()->value("test2"), QByteArray("456"));
QCOMPARE(entry2->autoTypeAssociations()->size(), 2);
QCOMPARE(entry2->autoTypeAssociations()->get(0).window, QString("1"));
QCOMPARE(entry2->autoTypeAssociations()->get(1).window, QString("3"));
}
QTEST_GUILESS_MAIN(TestEntry)

View File

@ -28,6 +28,7 @@ class TestEntry : public QObject
private Q_SLOTS:
void testHistoryItemDeletion();
void testCopyDataFrom();
};
#endif // KEEPASSX_TESTENTRY_H