125
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "t_tstasksettings.h"
|
|
19 |
|
|
20 |
#include <s32mem.h>
|
|
21 |
|
|
22 |
#include <QtTest/QtTest>
|
|
23 |
#include <QDesktopWidget>
|
|
24 |
#include <QPainter>
|
|
25 |
|
|
26 |
#include <QDebug>
|
|
27 |
#include <XQConversions>
|
|
28 |
|
|
29 |
#if defined (Q_OS_SYMBIAN)
|
|
30 |
#include <coecntrl.h>
|
|
31 |
#include "tstaskmonitorclient.h"
|
|
32 |
#include "tsscreenshotclient.h"
|
|
33 |
#include "tsutils.h"
|
|
34 |
using TaskSwitcher::CleanupResetAndDestroyPushL;
|
|
35 |
#endif
|
|
36 |
|
|
37 |
#include "tstask.h"
|
|
38 |
#include "tstaskchangeinfo.h"
|
|
39 |
#include "tstestutils.h"
|
|
40 |
|
|
41 |
void T_TsTaskSettings::initTestCase()
|
|
42 |
{
|
|
43 |
while (!unitTestTask().data())
|
|
44 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
45 |
}
|
|
46 |
|
|
47 |
void T_TsTaskSettings::testRegisteringScreenshotTriggersTaskListChangeSignal()
|
|
48 |
{
|
|
49 |
QVERIFY(mTaskSettings.registerScreenshot(imageWithCircle()));
|
|
50 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
51 |
}
|
|
52 |
|
|
53 |
void T_TsTaskSettings::testUnregisteringScreenshotTriggersTaskListChangeSignal()
|
|
54 |
{
|
|
55 |
QVERIFY(mTaskSettings.registerScreenshot(imageWithCircle()));
|
|
56 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
57 |
|
|
58 |
QVERIFY(mTaskSettings.unregisterScreenshot());
|
|
59 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
60 |
}
|
|
61 |
|
|
62 |
void T_TsTaskSettings::testIconIsReturnedAfterUnregisteringScreenshot()
|
|
63 |
{
|
|
64 |
// get icon
|
|
65 |
QSharedPointer<TsTask> taskBefore = unitTestTask();
|
|
66 |
QVERIFY(taskBefore.data());
|
|
67 |
QPixmap icon = taskBefore->screenshot();
|
|
68 |
QVERIFY(!icon.isNull());
|
|
69 |
|
|
70 |
// register and unregister screenshot
|
|
71 |
QVERIFY(mTaskSettings.registerScreenshot(imageWithCircle()));
|
|
72 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
73 |
QVERIFY(mTaskSettings.unregisterScreenshot());
|
|
74 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
75 |
|
|
76 |
// compare pixmap returned after register/unregister with icon
|
|
77 |
QSharedPointer<TsTask> taskAfter = unitTestTask();
|
|
78 |
QVERIFY(taskAfter.data());
|
|
79 |
QVERIFY(taskAfter->screenshot().toImage() == icon.toImage());
|
|
80 |
}
|
|
81 |
|
|
82 |
void T_TsTaskSettings::testRegisteringEmptyPixmapReturnsFalse()
|
|
83 |
{
|
|
84 |
QVERIFY(!mTaskSettings.registerScreenshot(QPixmap()));
|
|
85 |
}
|
|
86 |
|
|
87 |
void T_TsTaskSettings::testRegisteringTheSameScreenshotTwiceTriggersTaskListChangeSignal()
|
|
88 |
{
|
|
89 |
QPixmap image = imageWithCircle();
|
|
90 |
|
|
91 |
QVERIFY(mTaskSettings.registerScreenshot(image));
|
|
92 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
93 |
QVERIFY(mTaskSettings.registerScreenshot(image));
|
|
94 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
95 |
}
|
|
96 |
|
|
97 |
void T_TsTaskSettings::testRegisteringOverwritesOldScreenshot()
|
|
98 |
{
|
|
99 |
QPixmap previousScreenshot;
|
|
100 |
{
|
|
101 |
QSharedPointer<TsTask> myTask = unitTestTask();
|
|
102 |
QVERIFY(myTask.data());
|
|
103 |
previousScreenshot = myTask->screenshot();
|
|
104 |
}
|
|
105 |
|
|
106 |
QVERIFY(mTaskSettings.registerScreenshot(imageWithCircle()));
|
|
107 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
108 |
|
|
109 |
QPixmap screenshotAfterFirstRegistration;
|
|
110 |
{
|
|
111 |
QSharedPointer<TsTask> myTask = unitTestTask();
|
|
112 |
QVERIFY(myTask.data());
|
|
113 |
screenshotAfterFirstRegistration = myTask->screenshot();
|
|
114 |
}
|
|
115 |
|
|
116 |
QVERIFY(previousScreenshot.toImage() != screenshotAfterFirstRegistration.toImage());
|
|
117 |
|
|
118 |
QVERIFY(mTaskSettings.registerScreenshot(imageWithCircle()));
|
|
119 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
120 |
|
|
121 |
QPixmap screenshotAfterSecondRegistration;
|
|
122 |
{
|
|
123 |
QSharedPointer<TsTask> myTask = unitTestTask();
|
|
124 |
QVERIFY(myTask.data());
|
|
125 |
screenshotAfterSecondRegistration = myTask->screenshot();
|
|
126 |
}
|
|
127 |
|
|
128 |
QVERIFY(screenshotAfterSecondRegistration.toImage() != screenshotAfterFirstRegistration.toImage());
|
|
129 |
}
|
|
130 |
|
|
131 |
void T_TsTaskSettings::testRegisteringFailsIfHigherPriorityScreenshotIsRegistered()
|
|
132 |
{
|
|
133 |
QPixmap highPriorityScreenshot = imageWithCircle();
|
|
134 |
registerHighPriorityScreenshot(highPriorityScreenshot);
|
|
135 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
136 |
|
|
137 |
QVERIFY(!mTaskSettings.registerScreenshot(imageWithCircle()));
|
|
138 |
|
|
139 |
// clean up and verify the screenshots can be registered
|
|
140 |
QVERIFY(mTaskSettings.unregisterScreenshot());
|
|
141 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
142 |
QVERIFY(mTaskSettings.registerScreenshot(imageWithCircle()));
|
|
143 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
144 |
}
|
|
145 |
|
|
146 |
void T_TsTaskSettings::testChangingVisibilityOfApplication()
|
|
147 |
{
|
|
148 |
{
|
|
149 |
QSharedPointer<TsTask> myTask = unitTestTask();
|
|
150 |
QVERIFY(myTask.data());
|
|
151 |
}
|
|
152 |
|
|
153 |
// hide unit test task
|
|
154 |
mTaskSettings.setVisibility(false);
|
|
155 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
156 |
{
|
|
157 |
QSharedPointer<TsTask> myTask = unitTestTask();
|
|
158 |
QVERIFY(!myTask.data());
|
|
159 |
}
|
|
160 |
|
|
161 |
// show unit test task
|
|
162 |
mTaskSettings.setVisibility(true);
|
|
163 |
QVERIFY(TsTestUtils::waitForSignal(&mTaskMonitor, SIGNAL(taskListChanged())));
|
|
164 |
{
|
|
165 |
QSharedPointer<TsTask> myTask = unitTestTask();
|
|
166 |
QVERIFY(myTask.data());
|
|
167 |
}
|
|
168 |
}
|
|
169 |
|
|
170 |
QSharedPointer<TsTask> T_TsTaskSettings::unitTestTask()
|
|
171 |
{
|
|
172 |
// find unit test task
|
|
173 |
QSharedPointer<TsTask> myTask;
|
|
174 |
foreach(TsTaskChange taskChange, mTaskMonitor.changeList(true)) {
|
|
175 |
if (!taskChange.second.isNull()) {
|
|
176 |
if (taskChange.second->name() == "t_tstasksettings") {
|
|
177 |
myTask = taskChange.second;
|
|
178 |
break;
|
|
179 |
}
|
|
180 |
}
|
|
181 |
}
|
|
182 |
return myTask;
|
|
183 |
}
|
|
184 |
|
|
185 |
bool T_TsTaskSettings::registerHighPriorityScreenshot(const QPixmap &screenshot)
|
|
186 |
{
|
|
187 |
#if defined (Q_OS_SYMBIAN)
|
|
188 |
int wgId = QApplication::desktop()->winId()->ControlEnv()->RootWin().WindowGroupId();
|
|
189 |
|
|
190 |
QScopedPointer<CFbsBitmap> bitmap(screenshot.toSymbianCFbsBitmap());
|
|
191 |
if (bitmap.isNull())
|
|
192 |
return false;
|
|
193 |
|
|
194 |
int error(KErrGeneral);
|
|
195 |
|
|
196 |
QT_TRAP_THROWING (
|
|
197 |
CTsScreenshotClient* screenshotClient = CTsScreenshotClient::NewLC();
|
|
198 |
error = screenshotClient->RegisterScreenshot(bitmap.data(), wgId, High);
|
|
199 |
CleanupStack::PopAndDestroy(screenshotClient);
|
|
200 |
);
|
|
201 |
|
|
202 |
return error == KErrNone;
|
|
203 |
#else
|
|
204 |
return false;
|
|
205 |
#endif
|
|
206 |
}
|
|
207 |
|
|
208 |
QPixmap T_TsTaskSettings::imageWithCircle()
|
|
209 |
{
|
|
210 |
static int hue = 0;
|
|
211 |
QPixmap screenshot(10, 10);
|
|
212 |
|
|
213 |
{
|
|
214 |
QPainter painter(&screenshot);
|
|
215 |
painter.setBrush(Qt::black);
|
|
216 |
painter.drawRect(screenshot.rect());
|
|
217 |
painter.setBrush(QColor::fromHsv(hue, 255, 255));
|
|
218 |
painter.drawEllipse(screenshot.rect());
|
|
219 |
}
|
|
220 |
|
|
221 |
hue += 17;
|
|
222 |
return screenshot;
|
|
223 |
}
|
|
224 |
|
|
225 |
QTEST_MAIN(T_TsTaskSettings)
|