diff options
author | Felix Geyer <debfx@fobos.de> | 2013-04-04 23:48:55 +0400 |
---|---|---|
committer | Felix Geyer <debfx@fobos.de> | 2013-04-04 23:48:55 +0400 |
commit | bee570c3cf54d44787f6c7c0785f0c44977c4d5b (patch) | |
tree | 6f544caca7637a9be7e06577f249ace4f3268b95 /tests/TestGroup.cpp | |
parent | be288d26ca442cad0485a532d9bdd21906271053 (diff) |
Add Group::clone().
Move all the data we want to clone into a GroupData struct.
Diffstat (limited to 'tests/TestGroup.cpp')
-rw-r--r-- | tests/TestGroup.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
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) |