From 21a80101ba1fe358de2be38da9a81b1be7779043 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Fri, 22 Mar 2013 21:00:06 +0100 Subject: [PATCH] Add TestEntryModel::testDatabaseDelete(). It tests that EntryModel in EntryList mode correctly removes entries from the model when that database of these entries is deleted. --- tests/TestEntryModel.cpp | 31 +++++++++++++++++++++++++++++++ tests/TestEntryModel.h | 1 + 2 files changed, 32 insertions(+) diff --git a/tests/TestEntryModel.cpp b/tests/TestEntryModel.cpp index 286750728..3ac22c991 100644 --- a/tests/TestEntryModel.cpp +++ b/tests/TestEntryModel.cpp @@ -311,4 +311,35 @@ void TestEntryModel::testProxyModel() delete db; } +void TestEntryModel::testDatabaseDelete() +{ + EntryModel* model = new EntryModel(this); + ModelTest* modelTest = new ModelTest(model, this); + + Database* db1 = new Database(); + Group* group1 = new Group(); + group1->setParent(db1->rootGroup()); + + Entry* entry1 = new Entry(); + entry1->setGroup(group1); + + Database* db2 = new Database(); + Entry* entry2 = new Entry(); + entry2->setGroup(db2->rootGroup()); + + model->setEntryList(QList() << entry1 << entry2); + + QCOMPARE(model->rowCount(), 2); + + delete db1; + QCOMPARE(model->rowCount(), 1); + + delete entry2; + QCOMPARE(model->rowCount(), 0); + + delete db2; + delete modelTest; + delete model; +} + QTEST_GUILESS_MAIN(TestEntryModel) diff --git a/tests/TestEntryModel.h b/tests/TestEntryModel.h index 3d37f6b68..ffca78eb4 100644 --- a/tests/TestEntryModel.h +++ b/tests/TestEntryModel.h @@ -33,6 +33,7 @@ private Q_SLOTS: void testCustomIconModel(); void testAutoTypeAssociationsModel(); void testProxyModel(); + void testDatabaseDelete(); }; #endif // KEEPASSX_TESTENTRYMODEL_H