~ubuntu-branches/ubuntu/quantal/arora/quantal

« back to all changes in this revision

Viewing changes to autotests/editlistview/tst_editlistview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Roderick B. Greening
  • Date: 2009-10-01 16:08:58 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20091001160858-h1wnt3ddyzl07nih
Tags: 0.10.0-0ubuntu1
* New upstream release 
* Remove patches
  - kubuntu_01_google_lucky.diff - Open Search now used upstream
  - kubuntu_02_default_bookmarks.diff - bookmarks fixed upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2009 Benjamin C. Meyer <ben@meyerhome.net>
3
 
 *
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.
8
 
 *
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.
13
 
 *
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
18
 
 */
19
 
 
20
 
#include <qtest.h>
21
 
#include <qstringlistmodel.h>
22
 
 
23
 
#include <editlistview.h>
24
 
 
25
 
class tst_EditListView : public QObject
26
 
{
27
 
    Q_OBJECT
28
 
 
29
 
public slots:
30
 
    void initTestCase();
31
 
    void cleanupTestCase();
32
 
    void init();
33
 
    void cleanup();
34
 
 
35
 
private slots:
36
 
    void editlistview_data();
37
 
    void editlistview();
38
 
 
39
 
    void keyPressEvent_data();
40
 
    void keyPressEvent();
41
 
    void removeAll_data();
42
 
    void removeAll();
43
 
    void removeSelected_data();
44
 
    void removeSelected();
45
 
};
46
 
 
47
 
// Subclass that exposes the protected functions.
48
 
class SubEditListView : public EditListView
49
 
{
50
 
public:
51
 
 
52
 
};
53
 
 
54
 
// This will be called before the first test function is executed.
55
 
// It is only called once.
56
 
void tst_EditListView::initTestCase()
57
 
{
58
 
}
59
 
 
60
 
// This will be called after the last test function is executed.
61
 
// It is only called once.
62
 
void tst_EditListView::cleanupTestCase()
63
 
{
64
 
}
65
 
 
66
 
// This will be called before each test function is executed.
67
 
void tst_EditListView::init()
68
 
{
69
 
}
70
 
 
71
 
// This will be called after every test function.
72
 
void tst_EditListView::cleanup()
73
 
{
74
 
}
75
 
 
76
 
void tst_EditListView::editlistview_data()
77
 
{
78
 
}
79
 
 
80
 
Q_DECLARE_METATYPE(Qt::Key)
81
 
void tst_EditListView::editlistview()
82
 
{
83
 
    SubEditListView view;
84
 
    QTest::keyClick(&view, Qt::Key_Delete);
85
 
    QTest::keyClick(&view, Qt::Key_R);
86
 
    view.removeAll();
87
 
    view.removeSelected();
88
 
}
89
 
 
90
 
void tst_EditListView::keyPressEvent_data()
91
 
{
92
 
    QTest::addColumn<Qt::Key>("key");
93
 
    QTest::addColumn<QStringList>("predata");
94
 
    QTest::addColumn<QStringList>("postdata");
95
 
    QStringList predata;
96
 
    predata << "a";
97
 
    QTest::newRow("R") << Qt::Key_R << predata << predata;
98
 
    QTest::newRow("delete") << Qt::Key_Delete << predata << QStringList();
99
 
}
100
 
 
101
 
// public void keyPressEvent(QKeyEvent *event)
102
 
void tst_EditListView::keyPressEvent()
103
 
{
104
 
    QFETCH(Qt::Key, key);
105
 
    QFETCH(QStringList, predata);
106
 
    QFETCH(QStringList, postdata);
107
 
 
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);
114
 
}
115
 
 
116
 
void tst_EditListView::removeAll_data()
117
 
{
118
 
    QTest::addColumn<QStringList>("data");
119
 
    QTest::newRow("0") << QStringList();
120
 
    QTest::newRow("3") << (QStringList() << "x" << "y" << "z");
121
 
}
122
 
 
123
 
// public void removeAll()
124
 
void tst_EditListView::removeAll()
125
 
{
126
 
    QFETCH(QStringList, data);
127
 
 
128
 
    SubEditListView view;
129
 
    view.setModel(new QStringListModel(data));
130
 
 
131
 
    view.removeAll();
132
 
    QCOMPARE(view.model()->rowCount(), 0);
133
 
}
134
 
 
135
 
void tst_EditListView::removeSelected_data()
136
 
{
137
 
    QTest::addColumn<Qt::Key>("key");
138
 
    QTest::addColumn<QStringList>("predata");
139
 
    QTest::addColumn<QStringList>("postdata");
140
 
    QStringList predata;
141
 
    predata << "a";
142
 
    QTest::newRow("R") << Qt::Key_R << predata << predata;
143
 
    QTest::newRow("delete") << Qt::Key_Delete << predata << QStringList();
144
 
}
145
 
 
146
 
// public void removeSelected()
147
 
void tst_EditListView::removeSelected()
148
 
{
149
 
    QFETCH(Qt::Key, key);
150
 
    QFETCH(QStringList, predata);
151
 
    QFETCH(QStringList, postdata);
152
 
 
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);
159
 
}
160
 
 
161
 
QTEST_MAIN(tst_EditListView)
162
 
#include "tst_editlistview.moc"
163