2
* Copyright 2009 Benjamin C. Meyer <ben@meyerhome.net>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301 USA
21
#include <qstringlistmodel.h>
23
#include <editlistview.h>
25
class tst_EditListView : public QObject
31
void cleanupTestCase();
36
void editlistview_data();
39
void keyPressEvent_data();
41
void removeAll_data();
43
void removeSelected_data();
44
void removeSelected();
47
// Subclass that exposes the protected functions.
48
class SubEditListView : public EditListView
54
// This will be called before the first test function is executed.
55
// It is only called once.
56
void tst_EditListView::initTestCase()
60
// This will be called after the last test function is executed.
61
// It is only called once.
62
void tst_EditListView::cleanupTestCase()
66
// This will be called before each test function is executed.
67
void tst_EditListView::init()
71
// This will be called after every test function.
72
void tst_EditListView::cleanup()
76
void tst_EditListView::editlistview_data()
80
Q_DECLARE_METATYPE(Qt::Key)
81
void tst_EditListView::editlistview()
84
QTest::keyClick(&view, Qt::Key_Delete);
85
QTest::keyClick(&view, Qt::Key_R);
87
view.removeSelected();
90
void tst_EditListView::keyPressEvent_data()
92
QTest::addColumn<Qt::Key>("key");
93
QTest::addColumn<QStringList>("predata");
94
QTest::addColumn<QStringList>("postdata");
97
QTest::newRow("R") << Qt::Key_R << predata << predata;
98
QTest::newRow("delete") << Qt::Key_Delete << predata << QStringList();
101
// public void keyPressEvent(QKeyEvent *event)
102
void tst_EditListView::keyPressEvent()
104
QFETCH(Qt::Key, key);
105
QFETCH(QStringList, predata);
106
QFETCH(QStringList, postdata);
108
SubEditListView view;
109
QStringListModel *model = new QStringListModel(predata);
110
view.setModel(model);
111
view.setCurrentIndex(model->index(0, 0));
112
QTest::keyClick(&view, key);
113
QCOMPARE(model->stringList(), postdata);
116
void tst_EditListView::removeAll_data()
118
QTest::addColumn<QStringList>("data");
119
QTest::newRow("0") << QStringList();
120
QTest::newRow("3") << (QStringList() << "x" << "y" << "z");
123
// public void removeAll()
124
void tst_EditListView::removeAll()
126
QFETCH(QStringList, data);
128
SubEditListView view;
129
view.setModel(new QStringListModel(data));
132
QCOMPARE(view.model()->rowCount(), 0);
135
void tst_EditListView::removeSelected_data()
137
QTest::addColumn<Qt::Key>("key");
138
QTest::addColumn<QStringList>("predata");
139
QTest::addColumn<QStringList>("postdata");
142
QTest::newRow("R") << Qt::Key_R << predata << predata;
143
QTest::newRow("delete") << Qt::Key_Delete << predata << QStringList();
146
// public void removeSelected()
147
void tst_EditListView::removeSelected()
149
QFETCH(Qt::Key, key);
150
QFETCH(QStringList, predata);
151
QFETCH(QStringList, postdata);
153
SubEditListView view;
154
QStringListModel *model = new QStringListModel(predata);
155
view.setModel(model);
156
view.setCurrentIndex(model->index(0, 0));
157
QTest::keyClick(&view, key);
158
QCOMPARE(model->stringList(), postdata);
161
QTEST_MAIN(tst_EditListView)
162
#include "tst_editlistview.moc"