summaryrefslogtreecommitdiff
path: root/client/test/testaltcombobox.cc
blob: 5eb7afb9a3461b74722418d458a347f03c6a13eb (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
#include <QtTest/QtTest>

#include <QComboBox>

#include "util.h"
#include "altcombobox.h"

static QString xml = 
	"<altcombobox name=\"mycombobox\" value=\"item1\" type=\"search\">\n"
	"  <item value=\"item1\" caption=\"Item 1\"/>\n"
	"  <item value=\"item3\" caption=\"Item 3\"/>\n"
	"  <altitem value=\"item2\" caption=\"Item 2\" innerwidget=\"in\">\n"
	"    <lineedit name=\"in\" value=\"test\">\n"
	"  </altitem>\n"
	"</altcombobox>\n";

static QString xml_lua = 
	"<altcombobox name=\"mycombobox\" value=\"item1\" type=\"search\"\n"
  "             onInit=\"this:addItem('Item 4')\">\n"
	"  <item value=\"item1\" caption=\"Item 1\"/>\n"
	"  <item value=\"item3\" caption=\"Item 3\"/>\n"
	"  <altitem value=\"item2\" caption=\"Item 2\" innerwidget=\"in\">\n"
	"    <lineedit name=\"in\" value=\"test\">\n"
	"  </altitem>\n"
	"</altcombobox>\n";

class TestAltComboBox: public QObject
{
Q_OBJECT
private slots:

  void creation() { TEST_CREATION(AltComboBox); }
  void disable() { TEST_DISABLE(AltComboBox); }

  void visible()
	{
		QDomDocument doc;	doc.setContent(xml);
    QDomElement e = doc.documentElement();
    AltComboBox cmb(e, createMacroWindow());
    cmb.qwidget()->show();
    cmb.setValues();
    
    QCOMPARE(cmb.visible(), true);

    Widget *w = cmb.findWidget("in", true);
    QCOMPARE(w->visible(), false);

    QTest::keyClicks(cmb.qcombobox(), "\b2");
    QCOMPARE(w->visible(), true);

    QTest::keyClicks(cmb.qcombobox(), "\b3");
    QCOMPARE(w->visible(), false);
  }

  void value()
	{
		QDomDocument doc;	doc.setContent(xml);
    QDomElement e = doc.documentElement();
    AltComboBox cmb(e, createMacroWindow());
    cmb.setValues();

    QCOMPARE(cmb.value(), QString("item1"));

    QTest::keyClicks(cmb.qcombobox(), "\b3");
    QCOMPARE(cmb.value(), QString("item3"));

    QTest::keyClicks(cmb.qcombobox(), "\b2");
    QCOMPARE(cmb.value(), QString("test"));
  }

  void arrow()
	{
		QDomDocument doc;	doc.setContent(xml);
    QDomElement e = doc.documentElement();

    AltComboBox cmb(e, createMacroWindow());
    cmb.setValues();

    QCOMPARE(cmb.value(), QString("item1"));

		cmb.qcombobox()->setFocus();
    QTest::keyPress(cmb.qcombobox(), Qt::Key_Down);
    QTest::keyPress(cmb.qcombobox(), Qt::Key_Enter);
    QCOMPARE(cmb.value(), QString("item3"));

    QTest::keyPress(cmb.qcombobox(), Qt::Key_Down);
    QTest::keyPress(cmb.qcombobox(), Qt::Key_Enter);
    QCOMPARE(cmb.value(), QString("test"));
  }

	void changeEmits()
	{
		QDomDocument doc;	doc.setContent(xml);
    QDomElement e = doc.documentElement();
    AltComboBox cmb(e, createMacroWindow());
    cmb.setValues();

		QSignalSpy spy(&cmb, SIGNAL(wasChanged()));

    QTest::keyClicks(cmb.qcombobox(), "\b2");
		QCOMPARE(spy.count(), 2);
    QCOMPARE(cmb.value(), QString("test"));

    Widget *w = cmb.findWidget("in", true);
    QTest::keyClicks(w->qwidget(), "A");
    QCOMPARE(cmb.value(), QString("testA"));
		QCOMPARE(spy.count(), 3);
	}

  void lua()
  {
		QDomDocument doc;	doc.setContent(xml_lua);
    QDomElement e = doc.documentElement();
    AltComboBox cmb(e, createMacroWindow());
    cmb.setValues();
    cmb.qwidget()->show();
    cmb.runEventOnInit(true);
    
    QTest::keyClicks(cmb.qcombobox(), "\b4");
    QCOMPARE(cmb.value(), QString("Item 4"));
  }
};

QTEST_MAIN(TestAltComboBox)
#include "testaltcombobox.moc"