]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/kstandarditemmodeltest.cpp
daa8f1e56ceccee72506ddb895bf46c5e6451df7
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2011 by Frank Reininghaus <frank78ac@googlemail.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphindebug.h"
23 #include "kitemviews/kstandarditem.h"
24 #include "kitemviews/kstandarditemmodel.h"
28 class KStandardItemModelTest
: public QObject
37 void testRemoveItems();
40 bool isModelConsistent() const;
43 KStandardItemModel
* m_model
;
46 void KStandardItemModelTest::init()
48 m_model
= new KStandardItemModel();
51 void KStandardItemModelTest::cleanup()
57 void KStandardItemModelTest::testNewItems()
59 m_model
->insertItem(0, new KStandardItem("item 1"));
60 m_model
->insertItem(0, new KStandardItem("item 2"));
61 m_model
->insertItem(2, new KStandardItem("item 3"));
62 m_model
->appendItem(new KStandardItem("item 4"));
63 m_model
->insertItem(-1, new KStandardItem("invalid 1"));
64 m_model
->insertItem(5, new KStandardItem("invalid 2"));
65 QCOMPARE(m_model
->count(), 4);
66 QCOMPARE(m_model
->item(0)->text(), QString("item 2"));
67 QCOMPARE(m_model
->item(1)->text(), QString("item 1"));
68 QCOMPARE(m_model
->item(2)->text(), QString("item 3"));
69 QCOMPARE(m_model
->item(3)->text(), QString("item 4"));
71 QVERIFY(isModelConsistent());
74 void KStandardItemModelTest::testRemoveItems()
76 for (int i
= 1; i
<= 10; ++i
) {
77 m_model
->appendItem(new KStandardItem("item " + QString::number(i
)));
80 m_model
->removeItem(0);
81 m_model
->removeItem(3);
82 m_model
->removeItem(5);
83 m_model
->removeItem(-1);
84 QCOMPARE(m_model
->count(), 7);
85 QCOMPARE(m_model
->item(0)->text(), QString("item 2"));
86 QCOMPARE(m_model
->item(1)->text(), QString("item 3"));
87 QCOMPARE(m_model
->item(2)->text(), QString("item 4"));
88 QCOMPARE(m_model
->item(3)->text(), QString("item 6"));
89 QCOMPARE(m_model
->item(4)->text(), QString("item 7"));
90 QCOMPARE(m_model
->item(5)->text(), QString("item 9"));
91 QCOMPARE(m_model
->item(6)->text(), QString("item 10"));
94 bool KStandardItemModelTest::isModelConsistent() const
96 if (m_model
->m_items
.count() != m_model
->m_indexesForItems
.count()) {
100 for (int i
= 0; i
< m_model
->count(); ++i
) {
101 const KStandardItem
* item
= m_model
->item(i
);
103 qCWarning(DolphinDebug
) << "Item" << i
<< "is null";
107 const int itemIndex
= m_model
->index(item
);
108 if (itemIndex
!= i
) {
109 qCWarning(DolphinDebug
) << "Item" << i
<< "has a wrong index:" << itemIndex
;
117 QTEST_GUILESS_MAIN(KStandardItemModelTest
)
119 #include "kstandarditemmodeltest.moc"