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 |
#include <q3action.h>
|
|
46 |
#include <q3mainwindow.h>
|
|
47 |
#include <q3toolbar.h>
|
|
48 |
#include <qcombobox.h>
|
|
49 |
#include <qlist.h>
|
|
50 |
#include <qmainwindow.h>
|
|
51 |
#include <qmenubar.h>
|
|
52 |
#include <q3popupmenu.h>
|
|
53 |
#include <qtoolbar.h>
|
|
54 |
|
|
55 |
//TESTED_CLASS=
|
|
56 |
//TESTED_FILES=qt3support/widgets/q3action.h qt3support/widgets/q3action.cpp
|
|
57 |
|
|
58 |
class tst_Q3ActionGroup : public QObject
|
|
59 |
{
|
|
60 |
Q_OBJECT
|
|
61 |
|
|
62 |
public:
|
|
63 |
tst_Q3ActionGroup();
|
|
64 |
virtual ~tst_Q3ActionGroup();
|
|
65 |
|
|
66 |
private slots:
|
|
67 |
void enabledPropagation();
|
|
68 |
void visiblePropagation();
|
|
69 |
void dropDownDeleted();
|
|
70 |
void exclusive();
|
|
71 |
|
|
72 |
void separators();
|
|
73 |
};
|
|
74 |
|
|
75 |
tst_Q3ActionGroup::tst_Q3ActionGroup()
|
|
76 |
{
|
|
77 |
}
|
|
78 |
|
|
79 |
tst_Q3ActionGroup::~tst_Q3ActionGroup()
|
|
80 |
{
|
|
81 |
|
|
82 |
}
|
|
83 |
|
|
84 |
void tst_Q3ActionGroup::enabledPropagation()
|
|
85 |
{
|
|
86 |
Q3ActionGroup testActionGroup( 0 );
|
|
87 |
|
|
88 |
Q3Action* childAction = new Q3Action( &testActionGroup );
|
|
89 |
Q3Action* anotherChildAction = new Q3Action( &testActionGroup );
|
|
90 |
Q3Action* freeAction = new Q3Action(0);
|
|
91 |
|
|
92 |
QVERIFY( testActionGroup.isEnabled() );
|
|
93 |
QVERIFY( childAction->isEnabled() );
|
|
94 |
|
|
95 |
testActionGroup.setEnabled( FALSE );
|
|
96 |
QVERIFY( !testActionGroup.isEnabled() );
|
|
97 |
QVERIFY( !childAction->isEnabled() );
|
|
98 |
QVERIFY( !anotherChildAction->isEnabled() );
|
|
99 |
|
|
100 |
anotherChildAction->setEnabled( FALSE );
|
|
101 |
|
|
102 |
testActionGroup.setEnabled( TRUE );
|
|
103 |
QVERIFY( testActionGroup.isEnabled() );
|
|
104 |
QVERIFY( childAction->isEnabled() );
|
|
105 |
QVERIFY( !anotherChildAction->isEnabled() );
|
|
106 |
|
|
107 |
testActionGroup.setEnabled( FALSE );
|
|
108 |
Q3Action *lastChildAction = new Q3Action(&testActionGroup);
|
|
109 |
|
|
110 |
QVERIFY(!lastChildAction->isEnabled());
|
|
111 |
testActionGroup.setEnabled( TRUE );
|
|
112 |
QVERIFY(lastChildAction->isEnabled());
|
|
113 |
|
|
114 |
freeAction->setEnabled(FALSE);
|
|
115 |
testActionGroup.add(freeAction);
|
|
116 |
QVERIFY(!freeAction->isEnabled());
|
|
117 |
delete freeAction;
|
|
118 |
}
|
|
119 |
|
|
120 |
void tst_Q3ActionGroup::visiblePropagation()
|
|
121 |
{
|
|
122 |
Q3ActionGroup testActionGroup( 0 );
|
|
123 |
|
|
124 |
Q3Action* childAction = new Q3Action( &testActionGroup );
|
|
125 |
Q3Action* anotherChildAction = new Q3Action( &testActionGroup );
|
|
126 |
Q3Action* freeAction = new Q3Action(0);
|
|
127 |
|
|
128 |
QVERIFY( testActionGroup.isVisible() );
|
|
129 |
QVERIFY( childAction->isVisible() );
|
|
130 |
|
|
131 |
testActionGroup.setVisible( FALSE );
|
|
132 |
QVERIFY( !testActionGroup.isVisible() );
|
|
133 |
QVERIFY( !childAction->isVisible() );
|
|
134 |
QVERIFY( !anotherChildAction->isVisible() );
|
|
135 |
|
|
136 |
anotherChildAction->setVisible(FALSE);
|
|
137 |
|
|
138 |
testActionGroup.setVisible( TRUE );
|
|
139 |
QVERIFY( testActionGroup.isVisible() );
|
|
140 |
QVERIFY( childAction->isVisible() );
|
|
141 |
|
|
142 |
QVERIFY( !anotherChildAction->isVisible() );
|
|
143 |
|
|
144 |
testActionGroup.setVisible( FALSE );
|
|
145 |
Q3Action *lastChildAction = new Q3Action(&testActionGroup);
|
|
146 |
|
|
147 |
QVERIFY(!lastChildAction->isVisible());
|
|
148 |
testActionGroup.setVisible( TRUE );
|
|
149 |
QVERIFY(lastChildAction->isVisible());
|
|
150 |
|
|
151 |
freeAction->setVisible(FALSE);
|
|
152 |
testActionGroup.add(freeAction);
|
|
153 |
QVERIFY(!freeAction->isVisible());
|
|
154 |
delete freeAction;
|
|
155 |
}
|
|
156 |
|
|
157 |
void tst_Q3ActionGroup::exclusive()
|
|
158 |
{
|
|
159 |
Q3ActionGroup group( 0, 0, FALSE );
|
|
160 |
QVERIFY( !group.isExclusive() );
|
|
161 |
|
|
162 |
Q3Action* actOne = new Q3Action( &group );
|
|
163 |
actOne->setToggleAction( TRUE );
|
|
164 |
Q3Action* actTwo = new Q3Action( &group );
|
|
165 |
actTwo->setToggleAction( TRUE );
|
|
166 |
Q3Action* actThree = new Q3Action( &group );
|
|
167 |
actThree->setToggleAction( TRUE );
|
|
168 |
|
|
169 |
group.setExclusive( TRUE );
|
|
170 |
QVERIFY( !actOne->isOn() );
|
|
171 |
QVERIFY( !actTwo->isOn() );
|
|
172 |
QVERIFY( !actThree->isOn() );
|
|
173 |
|
|
174 |
actOne->setOn( TRUE );
|
|
175 |
QVERIFY( actOne->isOn() );
|
|
176 |
QVERIFY( !actTwo->isOn() );
|
|
177 |
QVERIFY( !actThree->isOn() );
|
|
178 |
|
|
179 |
actTwo->setOn( TRUE );
|
|
180 |
QVERIFY( !actOne->isOn() );
|
|
181 |
QVERIFY( actTwo->isOn() );
|
|
182 |
QVERIFY( !actThree->isOn() );
|
|
183 |
}
|
|
184 |
|
|
185 |
void tst_Q3ActionGroup::dropDownDeleted()
|
|
186 |
{
|
|
187 |
Q3MainWindow mw;
|
|
188 |
Q3ToolBar *tb = new Q3ToolBar(&mw);
|
|
189 |
Q3ActionGroup *actGroup = new Q3ActionGroup(&mw);
|
|
190 |
actGroup->setUsesDropDown(TRUE);
|
|
191 |
Q3Action *actOne = new Q3Action(actGroup);
|
|
192 |
actOne->setText("test one");
|
|
193 |
Q3Action *actTwo = new Q3Action(actGroup);
|
|
194 |
actTwo->setText("test two");
|
|
195 |
Q3Action *actThree= new Q3Action(actGroup);
|
|
196 |
actThree->setText("test three");
|
|
197 |
actGroup->addTo(tb);
|
|
198 |
QObjectList comboList = tb->queryList("QComboBox");
|
|
199 |
QCOMPARE(comboList.count(), 1);
|
|
200 |
QCOMPARE((int)((QComboBox*)comboList[0])->count(), 3);
|
|
201 |
|
|
202 |
delete actOne;
|
|
203 |
QCOMPARE((int)((QComboBox*)comboList[0])->count(), 2);
|
|
204 |
delete actTwo;
|
|
205 |
QCOMPARE((int)((QComboBox*)comboList[0])->count(), 1);
|
|
206 |
delete actThree;
|
|
207 |
QCOMPARE((int)((QComboBox*)comboList[0])->count(), 0);
|
|
208 |
|
|
209 |
delete actGroup;
|
|
210 |
}
|
|
211 |
|
|
212 |
void tst_Q3ActionGroup::separators()
|
|
213 |
{
|
|
214 |
QMainWindow mw;
|
|
215 |
Q3PopupMenu menu(&mw);
|
|
216 |
Q3ActionGroup actGroup(&mw);
|
|
217 |
|
|
218 |
mw.show();
|
|
219 |
|
|
220 |
Q3Action *action = new Q3Action(&actGroup);
|
|
221 |
action->setText("test one");
|
|
222 |
actGroup.addSeparator();
|
|
223 |
|
|
224 |
actGroup.addTo(&menu);
|
|
225 |
QCOMPARE((int)menu.count(), 2);
|
|
226 |
|
|
227 |
actGroup.removeFrom(&menu);
|
|
228 |
QCOMPARE((int)menu.count(), 0);
|
|
229 |
|
|
230 |
action = new Q3Action(&actGroup);
|
|
231 |
action->setText("test two");
|
|
232 |
actGroup.addTo(&menu);
|
|
233 |
QCOMPARE((int)menu.count(), 3);
|
|
234 |
}
|
|
235 |
|
|
236 |
QTEST_MAIN(tst_Q3ActionGroup)
|
|
237 |
#include "tst_q3actiongroup.moc"
|
|
238 |
|