34
|
1 |
/**
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: tester for methods in VideoListWidget
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <hbicon.h>
|
|
19 |
#include <hbmainwindow.h>
|
|
20 |
#include <hbinstance.h>
|
|
21 |
#include <hblabel.h>
|
|
22 |
#include <hbpushbutton.h>
|
|
23 |
#include <hbapplication.h>
|
|
24 |
|
|
25 |
#include "videocollectionuiloader.h"
|
|
26 |
#include "videocollectionviewutils.h"
|
|
27 |
#include "videocollectionviewutilsdata.h"
|
|
28 |
#include "videocollectionuiloaderdata.h"
|
|
29 |
#include "testhintwidget.h"
|
|
30 |
|
|
31 |
#define private public
|
|
32 |
#include "videohintwidget.h"
|
|
33 |
#undef private
|
|
34 |
|
|
35 |
// ---------------------------------------------------------------------------
|
|
36 |
// main
|
|
37 |
// ---------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
int main(int argc, char *argv[])
|
|
40 |
{
|
|
41 |
HbApplication app(argc, argv);
|
|
42 |
HbApplication::setKeypadNavigationEnabled(false);
|
|
43 |
HbMainWindow mainWnd;
|
35
|
44 |
hbInstance->mWindowses.append(&mainWnd);
|
34
|
45 |
|
|
46 |
TestHintWidget tv;
|
|
47 |
|
|
48 |
int res;
|
|
49 |
if(argc > 1)
|
|
50 |
{
|
|
51 |
res = QTest::qExec(&tv, argc, argv);
|
|
52 |
}
|
|
53 |
else
|
|
54 |
{
|
|
55 |
char *pass[3];
|
|
56 |
pass[0] = argv[0];
|
|
57 |
pass[1] = "-o";
|
|
58 |
pass[2] = "c:\\data\\testhintwidget.txt";
|
|
59 |
res = QTest::qExec(&tv, 3, pass);
|
|
60 |
}
|
|
61 |
|
|
62 |
return res;
|
|
63 |
}
|
|
64 |
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
// constructor
|
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
//
|
|
69 |
TestHintWidget::TestHintWidget():
|
|
70 |
mTestObject(0),
|
|
71 |
mUiLoader(0)
|
|
72 |
{
|
|
73 |
// nop
|
|
74 |
}
|
|
75 |
|
|
76 |
// ---------------------------------------------------------------------------
|
|
77 |
// destructor
|
|
78 |
// ---------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
TestHintWidget::~TestHintWidget()
|
|
81 |
{
|
|
82 |
cleanup();
|
|
83 |
}
|
|
84 |
|
|
85 |
// ---------------------------------------------------------------------------
|
|
86 |
// init
|
|
87 |
// ---------------------------------------------------------------------------
|
|
88 |
//
|
|
89 |
void TestHintWidget::init(bool callInitialize)
|
|
90 |
{
|
|
91 |
mUiLoader = new VideoCollectionUiLoader;
|
|
92 |
|
35
|
93 |
HbDocumentLoader::mFindWidgetFails = false;
|
34
|
94 |
bool ok(false);
|
35
|
95 |
mUiLoader->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok);
|
|
96 |
if(!ok)
|
34
|
97 |
{
|
|
98 |
cleanup();
|
|
99 |
QFAIL("docml loading failed!");
|
|
100 |
}
|
|
101 |
|
|
102 |
mTestObject = mUiLoader->findObject<VideoHintWidget>(DOCML_NAME_VC_VIDEOHINTWIDGET);
|
|
103 |
if(!mTestObject)
|
|
104 |
{
|
|
105 |
mTestObject = new VideoHintWidget(mUiLoader);
|
|
106 |
}
|
|
107 |
|
44
|
108 |
mTestObject->mHintText = "Go get some!";
|
|
109 |
|
34
|
110 |
if (callInitialize)
|
|
111 |
{
|
44
|
112 |
mTestObject->mHintText = "";
|
|
113 |
mTestObject->initialize();
|
34
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
// ---------------------------------------------------------------------------
|
|
118 |
// cleanup
|
|
119 |
// ---------------------------------------------------------------------------
|
|
120 |
//
|
|
121 |
void TestHintWidget::cleanup()
|
|
122 |
{
|
|
123 |
if (mUiLoader)
|
|
124 |
{
|
|
125 |
VideoHintWidget* temp = mUiLoader->findObject<VideoHintWidget>(DOCML_NAME_VC_VIDEOHINTWIDGET);
|
|
126 |
if (!temp)
|
|
127 |
{
|
|
128 |
// need to delete mTestObject as it is not owned by uiloader.
|
|
129 |
delete mTestObject;
|
|
130 |
mTestObject = 0;
|
|
131 |
}
|
|
132 |
mTestObject = 0;
|
|
133 |
|
|
134 |
delete mUiLoader;
|
|
135 |
mUiLoader = 0;
|
|
136 |
}
|
|
137 |
|
|
138 |
VideoCollectionViewUtilsData::reset();
|
|
139 |
VideoCollectionUiLoaderData::reset();
|
|
140 |
}
|
44
|
141 |
|
34
|
142 |
// ---------------------------------------------------------------------------
|
|
143 |
// testInitialize
|
|
144 |
// ---------------------------------------------------------------------------
|
|
145 |
//
|
|
146 |
void TestHintWidget::testInitialize()
|
|
147 |
{
|
|
148 |
init(false);
|
44
|
149 |
|
|
150 |
// Fail
|
|
151 |
mTestObject->mHintText = "";
|
|
152 |
VideoCollectionViewUtilsData::mCenRepStringValues.append("");
|
|
153 |
mTestObject->initialize();
|
|
154 |
QVERIFY(mTestObject->mHintText.isEmpty());
|
|
155 |
|
|
156 |
// Succeed
|
|
157 |
VideoCollectionViewUtilsData::mCenRepStringValues.append("test");
|
|
158 |
mTestObject->initialize();
|
|
159 |
QVERIFY(!mTestObject->mHintText.isEmpty());
|
34
|
160 |
|
|
161 |
cleanup();
|
|
162 |
}
|
|
163 |
|
|
164 |
// ---------------------------------------------------------------------------
|
|
165 |
// testSetLevel
|
|
166 |
// ---------------------------------------------------------------------------
|
|
167 |
//
|
|
168 |
void TestHintWidget::testSetLevel()
|
|
169 |
{
|
44
|
170 |
init(false);
|
34
|
171 |
mTestObject->setVisible(false);
|
|
172 |
|
|
173 |
mTestObject->setLevel(VideoHintWidget::Collection);
|
|
174 |
QCOMPARE(mTestObject->mCurrentLevel, VideoHintWidget::Collection);
|
|
175 |
|
|
176 |
mTestObject->setLevel(VideoHintWidget::AllVideos);
|
|
177 |
QCOMPARE(mTestObject->mCurrentLevel, VideoHintWidget::AllVideos);
|
|
178 |
|
|
179 |
mTestObject->setLevel(VideoHintWidget::AllVideos);
|
|
180 |
QCOMPARE(mTestObject->mCurrentLevel, VideoHintWidget::AllVideos);
|
|
181 |
|
|
182 |
mTestObject->setLevel(VideoHintWidget::Collection);
|
|
183 |
QCOMPARE(mTestObject->mCurrentLevel, VideoHintWidget::Collection);
|
|
184 |
cleanup();
|
|
185 |
}
|
|
186 |
|
|
187 |
// ---------------------------------------------------------------------------
|
|
188 |
// testActivate
|
|
189 |
// ---------------------------------------------------------------------------
|
|
190 |
//
|
|
191 |
void TestHintWidget::testActivate()
|
|
192 |
{
|
44
|
193 |
init(false);
|
34
|
194 |
|
|
195 |
mTestObject->setVisible(false);
|
|
196 |
|
|
197 |
// successful case.
|
41
|
198 |
mTestObject->mActivated = false;
|
|
199 |
|
35
|
200 |
HbLabel *noVideosLabel = mUiLoader->findWidget<HbLabel>(DOCML_NAME_NO_VIDEOS_LABEL);
|
|
201 |
QVERIFY(noVideosLabel);
|
|
202 |
noVideosLabel->setVisible(false);
|
34
|
203 |
|
|
204 |
mTestObject->activate();
|
|
205 |
QVERIFY(mTestObject->isVisible());
|
35
|
206 |
QVERIFY(noVideosLabel->isVisible()); // checks that updateUiComponents() has been called.
|
|
207 |
QVERIFY(mTestObject->mActivated == true);
|
34
|
208 |
|
44
|
209 |
// second call
|
|
210 |
noVideosLabel->setVisible(false);
|
|
211 |
mTestObject->activate();
|
|
212 |
QVERIFY(mTestObject->isVisible());
|
|
213 |
QVERIFY(!noVideosLabel->isVisible()); // shouldn't call updateUiComponents() again.
|
|
214 |
QVERIFY(mTestObject->mActivated == true);
|
|
215 |
|
34
|
216 |
cleanup();
|
|
217 |
}
|
|
218 |
|
|
219 |
// ---------------------------------------------------------------------------
|
|
220 |
// testDeactivate
|
|
221 |
// ---------------------------------------------------------------------------
|
|
222 |
//
|
|
223 |
void TestHintWidget::testDeactivate()
|
|
224 |
{
|
44
|
225 |
init(false);
|
34
|
226 |
|
35
|
227 |
mTestObject->setVisible(true);
|
|
228 |
mTestObject->mActivated = true;
|
|
229 |
|
|
230 |
// when serviceButton does not exist
|
|
231 |
HbDocumentLoader::mFindWidgetFails = true;
|
|
232 |
mTestObject->deactivate();
|
|
233 |
QVERIFY(mTestObject->mActivated == false);
|
|
234 |
QVERIFY(mTestObject->isVisible() == false);
|
|
235 |
|
44
|
236 |
// service button exists
|
|
237 |
mTestObject->setVisible(true);
|
35
|
238 |
mTestObject->mActivated = true;
|
|
239 |
HbDocumentLoader::mFindWidgetFails = false;
|
34
|
240 |
mTestObject->deactivate();
|
44
|
241 |
QVERIFY(mTestObject->mActivated == false);
|
34
|
242 |
QVERIFY(mTestObject->isVisible() == false);
|
|
243 |
|
44
|
244 |
// second call. widget is not active.
|
34
|
245 |
mTestObject->setVisible(true);
|
35
|
246 |
mTestObject->deactivate();
|
44
|
247 |
QVERIFY(mTestObject->mActivated == false);
|
|
248 |
QVERIFY(mTestObject->isVisible());
|
34
|
249 |
|
|
250 |
cleanup();
|
|
251 |
}
|
|
252 |
|
|
253 |
// ---------------------------------------------------------------------------
|
|
254 |
// testUpdateUiComponents
|
|
255 |
// ---------------------------------------------------------------------------
|
|
256 |
//
|
|
257 |
void TestHintWidget::testUpdateUiComponents()
|
|
258 |
{
|
|
259 |
HbMainWindow *mainWnd = hbInstance->allMainWindows()[0];
|
|
260 |
|
44
|
261 |
init(false);
|
34
|
262 |
|
44
|
263 |
// when a widget cannot be found.
|
35
|
264 |
mTestObject->mActivated = true;
|
44
|
265 |
mTestObject->mButtonShown = true;
|
35
|
266 |
HbDocumentLoader::mFindWidgetFails = true;
|
|
267 |
mTestObject->setLevel(VideoHintWidget::AllVideos);
|
44
|
268 |
// no verification possible except that it doesn't crash
|
35
|
269 |
|
|
270 |
HbDocumentLoader::mFindWidgetFails = false;
|
44
|
271 |
HbLabel *hintLabel = mUiLoader->findWidget<HbLabel>(DOCML_NAME_NO_VIDEOS_LABEL);
|
34
|
272 |
QVERIFY(hintLabel);
|
|
273 |
HbPushButton *serviceButton = mUiLoader->findWidget<HbPushButton>(DOCML_NAME_HINT_BUTTON);
|
|
274 |
QVERIFY(serviceButton);
|
|
275 |
|
44
|
276 |
// current level is all videos
|
|
277 |
serviceButton->setVisible(false);
|
34
|
278 |
mTestObject->setLevel(VideoHintWidget::AllVideos);
|
|
279 |
QVERIFY(hintLabel->isVisible());
|
44
|
280 |
QVERIFY(serviceButton->isVisible());
|
34
|
281 |
|
44
|
282 |
// current level is not all videos
|
|
283 |
serviceButton->setVisible(true);
|
34
|
284 |
mTestObject->setLevel(VideoHintWidget::Collection);
|
44
|
285 |
QVERIFY(hintLabel->isVisible());
|
|
286 |
QVERIFY(serviceButton->isVisible() == false);
|
|
287 |
|
|
288 |
// no hint text
|
|
289 |
serviceButton->setVisible(true);
|
|
290 |
mTestObject->mHintText = "";
|
|
291 |
mTestObject->setLevel(VideoHintWidget::AllVideos);
|
|
292 |
QVERIFY(hintLabel->isVisible());
|
35
|
293 |
QVERIFY(serviceButton->isVisible() == false);
|
|
294 |
|
34
|
295 |
cleanup();
|
|
296 |
}
|
|
297 |
|
|
298 |
// ---------------------------------------------------------------------------
|
|
299 |
// testOrientationChangedSlot
|
|
300 |
// ---------------------------------------------------------------------------
|
|
301 |
//
|
|
302 |
void TestHintWidget::testOrientationChangedSlot()
|
|
303 |
{
|
|
304 |
// NOTE: This also checks that the signals are connected and
|
|
305 |
// disconnected correctly.
|
|
306 |
|
|
307 |
HbMainWindow *mainWnd = hbInstance->allMainWindows()[0];
|
|
308 |
mainWnd->setOrientation(Qt::Horizontal);
|
35
|
309 |
connect(this, SIGNAL(testSignal(Qt::Orientation)), mainWnd, SIGNAL(orientationChanged(Qt::Orientation)));
|
34
|
310 |
|
44
|
311 |
init(false);
|
34
|
312 |
|
35
|
313 |
HbLabel *noVideosLabel = mUiLoader->findWidget<HbLabel>(DOCML_NAME_NO_VIDEOS_LABEL);
|
|
314 |
QVERIFY(noVideosLabel);
|
34
|
315 |
|
|
316 |
// test that updateUiComponents is not called when only initialize has been called,
|
|
317 |
// ie that no activate calls have been made yet.
|
35
|
318 |
// mTestObject->setVisible is needed because othervise childs cannot be set visible, ie the
|
|
319 |
// serviceButton->setVisible does not work as expected.
|
34
|
320 |
mTestObject->setVisible(true);
|
35
|
321 |
noVideosLabel->setVisible(true);
|
|
322 |
emit testSignal(Qt::Vertical);
|
|
323 |
QVERIFY(noVideosLabel->isVisible());
|
34
|
324 |
mTestObject->setVisible(false);
|
|
325 |
|
|
326 |
// tests that updateUiComponents is called when widget is visible.
|
|
327 |
mTestObject->activate();
|
35
|
328 |
noVideosLabel->setVisible(false);
|
|
329 |
emit testSignal(Qt::Horizontal);
|
|
330 |
QVERIFY(noVideosLabel->isVisible());
|
34
|
331 |
mTestObject->deactivate();
|
|
332 |
|
|
333 |
// tests that updateUiComponents is not called when widget is not visible:
|
35
|
334 |
// mTestObject->setVisible is needed because othervise childs cannot be set visible, ie the
|
|
335 |
// serviceButton->setVisible does not work as expected.
|
34
|
336 |
mTestObject->setVisible(true);
|
35
|
337 |
noVideosLabel->setVisible(true);
|
|
338 |
emit testSignal(Qt::Vertical);
|
|
339 |
QVERIFY(noVideosLabel->isVisible());
|
34
|
340 |
|
|
341 |
cleanup();
|
|
342 |
}
|
|
343 |
|
41
|
344 |
// ---------------------------------------------------------------------------
|
|
345 |
// testSetButtonShown
|
|
346 |
// ---------------------------------------------------------------------------
|
|
347 |
//
|
|
348 |
void TestHintWidget::testSetButtonShown()
|
|
349 |
{
|
|
350 |
HbMainWindow *mainWnd = hbInstance->allMainWindows()[0];
|
|
351 |
|
|
352 |
init(true);
|
|
353 |
|
|
354 |
HbLabel *noVideosLabel = mUiLoader->findWidget<HbLabel>(DOCML_NAME_NO_VIDEOS_LABEL);
|
|
355 |
QVERIFY(noVideosLabel);
|
|
356 |
|
|
357 |
mTestObject->mActivated = true;
|
|
358 |
noVideosLabel->setVisible(false);
|
|
359 |
mTestObject->setButtonShown(true);
|
|
360 |
QVERIFY(noVideosLabel->isVisible());
|
|
361 |
|
|
362 |
mTestObject->mActivated = false;
|
|
363 |
noVideosLabel->setVisible(false);
|
|
364 |
mTestObject->setButtonShown(false);
|
|
365 |
QVERIFY(noVideosLabel->isVisible() == false);
|
|
366 |
}
|
|
367 |
|
34
|
368 |
// end of file
|