summaryrefslogtreecommitdiff
path: root/client/test/testcomboboxedit.cc
blob: 76a9792b89213cdf531bfdbfe2623152c9deb0a7 (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
/* -*- 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 TestComboBoxEdit: 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, createMacroWindow());

    QTest::keyClicks(cmb.qwidget(), "Item 2");
    QCOMPARE(cmb.value(), QString("Item 2"));
  }

  void arrowSelect()
	{
		QDomDocument doc;	doc.setContent(xml_select);
    QDomElement e = doc.documentElement();

    ComboBox cmb(e, createMacroWindow());
		cmb.qwidget()->setFocus();
    QTest::keyPress(cmb.qwidget(), Qt::Key_Down);
    QTest::keyPress(cmb.qwidget(), Qt::Key_Down);
    QTest::keyPress(cmb.qwidget(), Qt::Key_Enter);
    QCOMPARE(cmb.value(), QString("item3"));
  }

	void changeEmits()
	{
		QDomDocument doc;	doc.setContent(xml_search);
    QDomElement e = doc.documentElement();
    ComboBox cmb(e, createMacroWindow());
		QSignalSpy spy(&cmb, SIGNAL(wasChanged()));
    QTest::keyClicks(cmb.qwidget(), "I");
		QCOMPARE(spy.count(), 1);
	}
};

QTEST_MAIN(TestComboBoxEdit)
#include "testcomboboxedit.moc"