blob: 14394402c858e56fa833631bf075d0e7b97dbff2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
#include <QtTest/QtTest>
#include "util.h"
#include "combobox.h"
#include <QAbstractItemView>
static QString xml_search =
"<combobox name=\"mycombobox\" type=\"search\">\n"
" <item value=\"item1\" caption=\"Item 1\"/>\n"
" <item value=\"item3\" caption=\"Item 3\"/>\n"
" <item value=\"item2\" caption=\"Item 2\"/>\n"
"</combobox>\n";
static QString xml_edit =
"<combobox name=\"mycombobox\" type=\"edit\">\n"
" <item value=\"item1\" caption=\"Item 1\"/>\n"
" <item value=\"item3\" caption=\"Item 3\"/>\n"
" <item value=\"item2\" caption=\"Item 2\"/>\n"
"</combobox>\n";
static QString xml_select =
"<combobox name=\"mycombobox\" type=\"select\">\n"
" <item value=\"item1\" caption=\"Item 1\"/>\n"
" <item value=\"item3\" caption=\"Item 3\"/>\n"
" <item value=\"item2\" caption=\"Item 2\"/>\n"
"</combobox>\n";
class TestComboBoxSelect: public QObject
{
Q_OBJECT
private slots:
void creation() { TEST_CREATION(ComboBox); }
void disable() { TEST_DISABLE(ComboBox); }
void editSelect()
{
QDomDocument doc; doc.setContent(xml_search);
QDomElement e = doc.documentElement();
ComboBox cmb(e, NULL);
QTest::keyClicks(&cmb, "Item 2");
QCOMPARE(cmb.getValue(), QString("Item 2"));
}
void arrowSelect()
{
QDomDocument doc; doc.setContent(xml_select);
QDomElement e = doc.documentElement();
ComboBox cmb(e, NULL);
cmb.setFocus();
QTest::keyPress(&cmb, Qt::Key_Down);
QTest::keyPress(&cmb, Qt::Key_Down);
QTest::keyPress(&cmb, Qt::Key_Enter);
QCOMPARE(cmb.getValue(), QString("item3"));
}
void changeEmits()
{
QDomDocument doc; doc.setContent(xml_search);
QDomElement e = doc.documentElement();
ComboBox cmb(e, NULL);
QSignalSpy spy(&cmb, SIGNAL(wasChanged()));
QTest::keyClicks(&cmb, "I");
QCOMPARE(spy.count(), 1);
}
};
QTEST_MAIN(TestComboBoxSelect)
#include "testcomboboxselect.moc"
|