0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
|
|
45 |
|
|
46 |
#include <qsignalmapper.h>
|
|
47 |
#include <qspinbox.h>
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
//TESTED_CLASS=
|
|
54 |
//TESTED_FILES=
|
|
55 |
|
|
56 |
class tst_QSignalMapper : public QObject
|
|
57 |
{
|
|
58 |
Q_OBJECT
|
|
59 |
|
|
60 |
public:
|
|
61 |
tst_QSignalMapper();
|
|
62 |
virtual ~tst_QSignalMapper();
|
|
63 |
|
|
64 |
|
|
65 |
public slots:
|
|
66 |
void initTestCase();
|
|
67 |
void cleanupTestCase();
|
|
68 |
void init();
|
|
69 |
void cleanup();
|
|
70 |
private slots:
|
|
71 |
void mapped();
|
|
72 |
};
|
|
73 |
|
|
74 |
tst_QSignalMapper::tst_QSignalMapper()
|
|
75 |
{
|
|
76 |
}
|
|
77 |
|
|
78 |
tst_QSignalMapper::~tst_QSignalMapper()
|
|
79 |
{
|
|
80 |
}
|
|
81 |
|
|
82 |
void tst_QSignalMapper::initTestCase()
|
|
83 |
{
|
|
84 |
}
|
|
85 |
|
|
86 |
void tst_QSignalMapper::cleanupTestCase()
|
|
87 |
{
|
|
88 |
}
|
|
89 |
|
|
90 |
void tst_QSignalMapper::init()
|
|
91 |
{
|
|
92 |
}
|
|
93 |
|
|
94 |
void tst_QSignalMapper::cleanup()
|
|
95 |
{
|
|
96 |
}
|
|
97 |
|
|
98 |
class QtTestObject : public QObject
|
|
99 |
{
|
|
100 |
Q_OBJECT
|
|
101 |
public slots:
|
|
102 |
void myslot(int id);
|
|
103 |
void myslot(const QString &str);
|
|
104 |
|
|
105 |
public:
|
|
106 |
int id;
|
|
107 |
QString str;
|
|
108 |
};
|
|
109 |
|
|
110 |
void QtTestObject::myslot(int id)
|
|
111 |
{
|
|
112 |
this->id = id;
|
|
113 |
}
|
|
114 |
|
|
115 |
void QtTestObject::myslot(const QString &str)
|
|
116 |
{
|
|
117 |
this->str = str;
|
|
118 |
}
|
|
119 |
|
|
120 |
void tst_QSignalMapper::mapped()
|
|
121 |
{
|
|
122 |
QSignalMapper mapper(0);
|
|
123 |
|
|
124 |
QtTestObject target;
|
|
125 |
QSpinBox spinBox1(0);
|
|
126 |
QSpinBox spinBox2(0);
|
|
127 |
QSpinBox spinBox3(0);
|
|
128 |
|
|
129 |
connect(&spinBox1, SIGNAL(valueChanged(int)), &mapper, SLOT(map()));
|
|
130 |
connect(&spinBox2, SIGNAL(valueChanged(int)), &mapper, SLOT(map()));
|
|
131 |
connect(&spinBox3, SIGNAL(valueChanged(int)), &mapper, SLOT(map()));
|
|
132 |
|
|
133 |
mapper.setMapping(&spinBox1, 7);
|
|
134 |
mapper.setMapping(&spinBox1, 1);
|
|
135 |
mapper.setMapping(&spinBox2, 2);
|
|
136 |
mapper.setMapping(&spinBox2, "two");
|
|
137 |
mapper.setMapping(&spinBox3, "three");
|
|
138 |
|
|
139 |
connect(&mapper, SIGNAL(mapped(int)), &target, SLOT(myslot(int)));
|
|
140 |
connect(&mapper, SIGNAL(mapped(const QString &)), &target, SLOT(myslot(const QString &)));
|
|
141 |
|
|
142 |
spinBox1.setValue(20);
|
|
143 |
QVERIFY(target.id == 1);
|
|
144 |
QVERIFY(target.str.isEmpty());
|
|
145 |
|
|
146 |
spinBox2.setValue(20);
|
|
147 |
QVERIFY(target.id == 2);
|
|
148 |
QVERIFY(target.str == "two");
|
|
149 |
|
|
150 |
spinBox3.setValue(20);
|
|
151 |
QVERIFY(target.id == 2);
|
|
152 |
QVERIFY(target.str == "three");
|
|
153 |
}
|
|
154 |
|
|
155 |
QTEST_MAIN(tst_QSignalMapper)
|
|
156 |
#include "tst_qsignalmapper.moc"
|