From bee570c3cf54d44787f6c7c0785f0c44977c4d5b Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Thu, 4 Apr 2013 21:48:55 +0200 Subject: Add Group::clone(). Move all the data we want to clone into a GroupData struct. --- tests/TestGroup.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests/TestGroup.cpp') diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index f32e943b4..36bff7054 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -430,4 +430,54 @@ void TestGroup::testAndConcatenationInSearch() delete group; } +void TestGroup::testClone() +{ + Database* db = new Database(); + + Group* originalGroup = new Group(); + originalGroup->setParent(db->rootGroup()); + originalGroup->setName("Group"); + originalGroup->setIcon(42); + + Entry* originalGroupEntry = new Entry(); + originalGroupEntry->setGroup(originalGroup); + originalGroupEntry->setTitle("GroupEntry"); + originalGroupEntry->setIcon(43); + + Group* subGroup = new Group(); + subGroup->setParent(originalGroup); + subGroup->setName("SubGroup"); + + Entry* subGroupEntry = new Entry(); + subGroupEntry->setGroup(subGroup); + subGroupEntry->setTitle("SubGroupEntry"); + + Group* clonedGroup = originalGroup->clone(); + QVERIFY(!clonedGroup->parentGroup()); + QVERIFY(!clonedGroup->database()); + QVERIFY(clonedGroup->uuid() != originalGroup->uuid()); + QCOMPARE(clonedGroup->name(), QString("Group")); + QCOMPARE(clonedGroup->iconNumber(), 42); + QCOMPARE(clonedGroup->children().size(), 1); + QCOMPARE(clonedGroup->entries().size(), 1); + + Entry* clonedGroupEntry = clonedGroup->entries().at(0); + QVERIFY(clonedGroupEntry->uuid() != originalGroupEntry->uuid()); + QCOMPARE(clonedGroupEntry->title(), QString("GroupEntry")); + QCOMPARE(clonedGroupEntry->iconNumber(), 43); + + Group* clonedSubGroup = clonedGroup->children().at(0); + QVERIFY(clonedSubGroup->uuid() != subGroup->uuid()); + QCOMPARE(clonedSubGroup->name(), QString("SubGroup")); + QCOMPARE(clonedSubGroup->children().size(), 0); + QCOMPARE(clonedSubGroup->entries().size(), 1); + + Entry* clonedSubGroupEntry = clonedSubGroup->entries().at(0); + QVERIFY(clonedSubGroupEntry->uuid() != subGroupEntry->uuid()); + QCOMPARE(clonedSubGroupEntry->title(), QString("SubGroupEntry")); + + delete clonedGroup; + delete db; +} + QTEST_GUILESS_MAIN(TestGroup) -- cgit v1.2.3