]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/kstandarditemmodeltest.cpp
2de0d0b784368aa3f9b7e0acb85993c40a046de4
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 <qtest_kde.h>
23 #include "kitemviews/kstandarditem.h"
24 #include "kitemviews/kstandarditemmodel.h"
26 class KStandardItemModelTest
: public QObject
35 void testRemoveItems();
38 bool isModelConsistent() const;
41 KStandardItemModel
* m_model
;
44 void KStandardItemModelTest::init()
46 m_model
= new KStandardItemModel();
49 void KStandardItemModelTest::cleanup()
55 void KStandardItemModelTest::testNewItems()
57 m_model
->insertItem(0, new KStandardItem("item 1"));
58 m_model
->insertItem(0, new KStandardItem("item 2"));
59 m_model
->insertItem(2, new KStandardItem("item 3"));
60 m_model
->appendItem(new KStandardItem("item 4"));
61 m_model
->insertItem(-1, new KStandardItem("invalid 1"));
62 m_model
->insertItem(5, new KStandardItem("invalid 2"));
63 QCOMPARE(m_model
->count(), 4);
64 QCOMPARE(m_model
->item(0)->text(), QString("item 2"));
65 QCOMPARE(m_model
->item(1)->text(), QString("item 1"));
66 QCOMPARE(m_model
->item(2)->text(), QString("item 3"));
67 QCOMPARE(m_model
->item(3)->text(), QString("item 4"));
69 QVERIFY(isModelConsistent());
72 void KStandardItemModelTest::testRemoveItems()
74 for (int i
= 1; i
<= 10; ++i
) {
75 m_model
->appendItem(new KStandardItem("item " + QString::number(i
)));
78 m_model
->removeItem(0);
79 m_model
->removeItem(3);
80 m_model
->removeItem(5);
81 m_model
->removeItem(-1);
82 QCOMPARE(m_model
->count(), 7);
83 QCOMPARE(m_model
->item(0)->text(), QString("item 2"));
84 QCOMPARE(m_model
->item(1)->text(), QString("item 3"));
85 QCOMPARE(m_model
->item(2)->text(), QString("item 4"));
86 QCOMPARE(m_model
->item(3)->text(), QString("item 6"));
87 QCOMPARE(m_model
->item(4)->text(), QString("item 7"));
88 QCOMPARE(m_model
->item(5)->text(), QString("item 9"));
89 QCOMPARE(m_model
->item(6)->text(), QString("item 10"));
92 bool KStandardItemModelTest::isModelConsistent() const
94 if (m_model
->m_items
.count() != m_model
->m_indexesForItems
.count()) {
98 for (int i
= 0; i
< m_model
->count(); ++i
) {
99 const KStandardItem
* item
= m_model
->item(i
);
101 qWarning() << "Item" << i
<< "is null";
105 const int itemIndex
= m_model
->index(item
);
106 if (itemIndex
!= i
) {
107 qWarning() << "Item" << i
<< "has a wrong index:" << itemIndex
;
115 QTEST_KDEMAIN(KStandardItemModelTest
, NoGUI
)
117 #include "kstandarditemmodeltest.moc"