From e60f4278f739ae8575ae18e06581548b0dbdf832 Mon Sep 17 00:00:00 2001 From: Aetf <7437103@gmail.com> Date: Fri, 1 Feb 2019 17:03:28 -0500 Subject: [PATCH] Fix group signals (#2670) * Fix group not emitting signals when modified through copyDataFrom * Fix Group::GroupData equals wrongly compares timeInfo --- src/core/Group.cpp | 6 ++++-- tests/TestGroup.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/TestGroup.h | 2 ++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/core/Group.cpp b/src/core/Group.cpp index fc9726f1..87741ee0 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -865,7 +865,9 @@ Group* Group::clone(Entry::CloneFlags entryFlags, Group::CloneFlags groupFlags) void Group::copyDataFrom(const Group* other) { - m_data = other->m_data; + if (set(m_data, other->m_data)) { + emit groupDataChanged(this); + } m_customData->copyDataFrom(other->m_customData); m_lastTopVisibleEntry = other->m_lastTopVisibleEntry; } @@ -1079,7 +1081,7 @@ bool Group::GroupData::equals(const Group::GroupData& other, CompareItemOptions if (::compare(customIcon, other.customIcon) != 0) { return false; } - if (timeInfo.equals(other.timeInfo, options) != 0) { + if (!timeInfo.equals(other.timeInfo, options)) { return false; } // TODO HNH: Some properties are configurable - should they be ignored? diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index 6ea43b10..9abbd31d 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -798,3 +798,46 @@ void TestGroup::testIsRecycled() db->recycleGroup(group4); QVERIFY(group4->isRecycled()); } + +void TestGroup::testCopyDataFrom() +{ + QScopedPointer group(new Group()); + group->setName("TestGroup"); + + QScopedPointer group2(new Group()); + group2->setName("TestGroup2"); + + QScopedPointer group3(new Group()); + group3->setName("TestGroup3"); + group3->customData()->set("testKey", "value"); + + + QSignalSpy spyGroupModified(group.data(), SIGNAL(groupModified())); + QSignalSpy spyGroupDataChanged(group.data(), SIGNAL(groupDataChanged(Group*))); + + group->copyDataFrom(group2.data()); + QCOMPARE(spyGroupModified.count(), 1); + QCOMPARE(spyGroupDataChanged.count(), 1); + + // if no change, no signals + spyGroupModified.clear(); + spyGroupDataChanged.clear(); + group->copyDataFrom(group2.data()); + QCOMPARE(spyGroupModified.count(), 0); + QCOMPARE(spyGroupDataChanged.count(), 0); + + // custom data change triggers a separate modified signal + spyGroupModified.clear(); + spyGroupDataChanged.clear(); + group->copyDataFrom(group3.data()); + QCOMPARE(spyGroupDataChanged.count(), 1); + QCOMPARE(spyGroupModified.count(), 2); +} + +void TestGroup::testEquals() +{ + QScopedPointer group(new Group()); + group->setName("TestGroup"); + + QVERIFY(group->equals(group.data(), CompareItemDefault)); +} diff --git a/tests/TestGroup.h b/tests/TestGroup.h index fe0fefda..9fd5c2ef 100644 --- a/tests/TestGroup.h +++ b/tests/TestGroup.h @@ -43,6 +43,8 @@ private slots: void testLocate(); void testAddEntryWithPath(); void testIsRecycled(); + void testCopyDataFrom(); + void testEquals(); }; #endif // KEEPASSX_TESTGROUP_H