83
|
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 the License "Symbian Foundation License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: AlarmClient unit test class.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
#include <QtTest/QtTest>
|
|
20 |
|
|
21 |
// User includes
|
|
22 |
#include "alarmclient.h"
|
|
23 |
#include "qdatetime.h"
|
|
24 |
#include "qstring.h"
|
|
25 |
#include "clockdatatypes.h"
|
|
26 |
|
|
27 |
/*!
|
|
28 |
\class TestAlarmClient
|
|
29 |
|
|
30 |
This object has functions to test the public apis in the class
|
|
31 |
AlarmClient.
|
|
32 |
*/
|
|
33 |
class TestAlarmClient: public QObject
|
|
34 |
{
|
|
35 |
Q_OBJECT
|
|
36 |
|
|
37 |
private slots:
|
|
38 |
// Test case setup.
|
|
39 |
void init();
|
|
40 |
void cleanup();
|
|
41 |
|
|
42 |
// Test cases.
|
|
43 |
void testToggleAlarmStatus();
|
|
44 |
void testDeleteAlarm();
|
|
45 |
void testGetAlarmList();
|
|
46 |
void testSetAlarmDaily();
|
|
47 |
void testSetAlarmWeekly();
|
|
48 |
void testSetAlarmWorkdays();
|
|
49 |
void testSetAlarmOnceOnly();
|
|
50 |
|
|
51 |
|
|
52 |
private:
|
|
53 |
AlarmClient *mAlarmClient;
|
|
54 |
};
|
|
55 |
|
|
56 |
/*!
|
|
57 |
This function will be called before each testfunction is executed.
|
|
58 |
*/
|
|
59 |
void TestAlarmClient::init()
|
|
60 |
{
|
|
61 |
mAlarmClient = new AlarmClient(this);
|
|
62 |
}
|
|
63 |
|
|
64 |
/*!
|
|
65 |
This function will be called after every testfunction.
|
|
66 |
*/
|
|
67 |
void TestAlarmClient::cleanup()
|
|
68 |
{
|
|
69 |
QList<AlarmInfo> alarmlist;
|
|
70 |
mAlarmClient->getAlarmList(alarmlist);
|
|
71 |
|
|
72 |
// Delete all the alarms.
|
|
73 |
int numOfAlarms = alarmlist.count();
|
|
74 |
for (int i = 0; i < numOfAlarms; i++) {
|
|
75 |
mAlarmClient->deleteAlarm(alarmlist.at(i).alarmId);
|
|
76 |
}
|
|
77 |
|
|
78 |
if (mAlarmClient) {
|
|
79 |
delete mAlarmClient;
|
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
/*!
|
|
84 |
* Test the API AlarmClient::toggleAlarmStatus.
|
|
85 |
*/
|
|
86 |
void TestAlarmClient::testToggleAlarmStatus()
|
|
87 |
{
|
|
88 |
// Set an alarm.
|
|
89 |
QTime alarmTime;
|
|
90 |
QString descInfo("This is a daily alarm");
|
|
91 |
|
|
92 |
AlarmInfo alarmInfoDaily;
|
|
93 |
// First the description.
|
|
94 |
alarmInfoDaily.alarmDesc = descInfo;
|
|
95 |
// The time.
|
|
96 |
alarmTime = QTime::fromString("12:30 pm", "hh:mm ap");
|
|
97 |
// Construct the alarm info.
|
|
98 |
alarmInfoDaily.origAlarmTime = alarmTime;
|
|
99 |
// Fill the repeat type.
|
|
100 |
alarmInfoDaily.repeatType = Daily;
|
|
101 |
|
|
102 |
// Request the listener to set the alarm.
|
|
103 |
mAlarmClient->setAlarm(alarmInfoDaily);
|
|
104 |
// Get the Id of the alarm set.
|
|
105 |
int tempId = alarmInfoDaily.alarmId;
|
|
106 |
mAlarmClient->toggleAlarmStatus(tempId, Disabled);
|
|
107 |
|
|
108 |
// Get the above alarminfo and see if its disabled.
|
|
109 |
AlarmInfo retrievedAlarmInfoDaily;
|
|
110 |
int error = mAlarmClient->getAlarmInfo(tempId, retrievedAlarmInfoDaily);
|
|
111 |
|
|
112 |
if (0 == error) {
|
|
113 |
QVERIFY(Disabled ==
|
|
114 |
retrievedAlarmInfoDaily.alarmStatus);
|
|
115 |
}
|
|
116 |
|
|
117 |
// Now toggle from disabled to enabled and check.
|
|
118 |
mAlarmClient->toggleAlarmStatus(tempId, Enabled);
|
|
119 |
error = mAlarmClient->getAlarmInfo(tempId, retrievedAlarmInfoDaily);
|
|
120 |
|
|
121 |
if (0 == error) {
|
|
122 |
QVERIFY(Enabled ==
|
|
123 |
retrievedAlarmInfoDaily.alarmStatus);
|
|
124 |
}
|
|
125 |
|
|
126 |
}
|
|
127 |
|
|
128 |
/*!
|
|
129 |
Test the API AlarmClient::deleteAlarm.
|
|
130 |
*/
|
|
131 |
void TestAlarmClient::testDeleteAlarm()
|
|
132 |
{
|
|
133 |
// Set an alarm.
|
|
134 |
QTime alarmTime;
|
|
135 |
QString descInfo("This is a daily alarm");
|
|
136 |
|
|
137 |
AlarmInfo alarmInfoDaily;
|
|
138 |
// First the description.
|
|
139 |
alarmInfoDaily.alarmDesc = descInfo;
|
|
140 |
// The time.
|
|
141 |
alarmTime = QTime::fromString("12:30 pm", "hh:mm ap");
|
|
142 |
// Construct the alarm info.
|
|
143 |
alarmInfoDaily.origAlarmTime = alarmTime;
|
|
144 |
// Fill the repeat type.
|
|
145 |
alarmInfoDaily.repeatType = Daily;
|
|
146 |
// Request the listener to set the alarm.
|
|
147 |
mAlarmClient->setAlarm(alarmInfoDaily);
|
|
148 |
|
|
149 |
QList<AlarmInfo> alarmList;
|
|
150 |
mAlarmClient->getAlarmList(alarmList);
|
|
151 |
|
|
152 |
// Delete all the alarms.
|
|
153 |
int numOfAlarms = alarmList.count();
|
|
154 |
for (int i = 0; i < numOfAlarms; i++) {
|
|
155 |
mAlarmClient->deleteAlarm(alarmList.at(i).alarmId);
|
|
156 |
}
|
|
157 |
// TODO:Have to check the number of alarms returned.Ll do later
|
|
158 |
// Check if there are no alarms.
|
|
159 |
// mAlarmClient->getAlarmList(alarmList);
|
|
160 |
// numOfAlarms = alarmList.size();
|
|
161 |
// QVERIFY(0 == numOfAlarms);
|
|
162 |
}
|
|
163 |
|
|
164 |
/*
|
|
165 |
Test the API AlarmClient::getAlarmList.
|
|
166 |
*/
|
|
167 |
void TestAlarmClient::testGetAlarmList()
|
|
168 |
{
|
|
169 |
QList<AlarmInfo> alarmlist;
|
|
170 |
|
|
171 |
// Set an alarm.
|
|
172 |
QTime alarmTime;
|
|
173 |
QString descInfo("This is a daily alarm");
|
|
174 |
|
|
175 |
AlarmInfo alarmInfoDaily;
|
|
176 |
// First the description.
|
|
177 |
alarmInfoDaily.alarmDesc = descInfo;
|
|
178 |
// The time.
|
|
179 |
alarmTime = QTime::fromString("12:30 pm", "hh:mm ap");
|
|
180 |
// Construct the alarm info.
|
|
181 |
alarmInfoDaily.origAlarmTime = alarmTime;
|
|
182 |
// Fill the repeat type.
|
|
183 |
alarmInfoDaily.repeatType = Daily;
|
|
184 |
|
|
185 |
// Request the listener to set the alarm.
|
|
186 |
mAlarmClient->setAlarm(alarmInfoDaily);
|
|
187 |
|
|
188 |
// Check if the list has only one element.
|
|
189 |
mAlarmClient->getAlarmList(alarmlist);
|
|
190 |
int numOfAlarms = alarmlist.count();
|
|
191 |
QVERIFY(1 == numOfAlarms);
|
|
192 |
}
|
|
193 |
|
|
194 |
/*!
|
|
195 |
Tests the api AlarmClient::setAlarm with a daily alarm.
|
|
196 |
*/
|
|
197 |
void TestAlarmClient::testSetAlarmDaily()
|
|
198 |
{
|
|
199 |
QTime alarmTime;
|
|
200 |
QString descInfo("This is a daily alarm");
|
|
201 |
|
|
202 |
AlarmInfo alarmInfoDaily;
|
|
203 |
// First the description.
|
|
204 |
alarmInfoDaily.alarmDesc = descInfo;
|
|
205 |
// The time.
|
|
206 |
alarmTime = QTime::fromString("12:30 pm", "hh:mm ap");
|
|
207 |
// Construct the alarm info.
|
|
208 |
alarmInfoDaily.origAlarmTime = alarmTime;
|
|
209 |
// Fill the repeat type.
|
|
210 |
alarmInfoDaily.repeatType = Daily;
|
|
211 |
|
|
212 |
// Request the listener to set the alarm.
|
|
213 |
mAlarmClient->setAlarm(alarmInfoDaily);
|
|
214 |
// Get the Id of the alarm set.
|
|
215 |
int tempId = alarmInfoDaily.alarmId;
|
|
216 |
|
|
217 |
// Retrieve the alarm information and compare.
|
|
218 |
AlarmInfo retrievedAlarmInfoDaily;
|
|
219 |
int error = mAlarmClient->getAlarmInfo(tempId, retrievedAlarmInfoDaily);
|
|
220 |
|
|
221 |
if (0 == error) {
|
|
222 |
QVERIFY(alarmInfoDaily.origAlarmTime ==
|
|
223 |
retrievedAlarmInfoDaily.origAlarmTime);
|
|
224 |
QVERIFY(alarmInfoDaily.alarmDesc ==
|
|
225 |
retrievedAlarmInfoDaily.alarmDesc);
|
|
226 |
QVERIFY(alarmInfoDaily.repeatType ==
|
|
227 |
retrievedAlarmInfoDaily.repeatType);
|
|
228 |
QVERIFY(alarmInfoDaily.alarmId ==
|
|
229 |
retrievedAlarmInfoDaily.alarmId);
|
|
230 |
}
|
|
231 |
else {
|
|
232 |
QVERIFY(false);
|
|
233 |
}
|
|
234 |
}
|
|
235 |
|
|
236 |
/*!
|
|
237 |
Tests the api AlarmClient::setAlarm with a weekly alarm.
|
|
238 |
*/
|
|
239 |
void TestAlarmClient::testSetAlarmWeekly()
|
|
240 |
{
|
|
241 |
QTime alarmTime;
|
|
242 |
QString descInfo("This is a weekly alarm");
|
|
243 |
|
|
244 |
AlarmInfo alarmInfoWeekly;
|
|
245 |
// First the description.
|
|
246 |
alarmInfoWeekly.alarmDesc = descInfo;
|
|
247 |
// The time.
|
|
248 |
alarmTime = QTime::fromString("12:30 pm", "hh:mm ap");
|
|
249 |
// Construct the alarm info.
|
|
250 |
alarmInfoWeekly.origAlarmTime = alarmTime;
|
|
251 |
// Fill the repeat type.
|
|
252 |
alarmInfoWeekly.repeatType = Weekly;
|
|
253 |
// Fill the day.
|
|
254 |
alarmInfoWeekly.alarmDay = 2;
|
|
255 |
|
|
256 |
// Request the listener to set the alarm.
|
|
257 |
mAlarmClient->setAlarm(alarmInfoWeekly);
|
|
258 |
// Get the Id of the alarm set.
|
|
259 |
int tempId = alarmInfoWeekly.alarmId;
|
|
260 |
|
|
261 |
// Retrieve the alarm information and compare.
|
|
262 |
AlarmInfo retrievedalarmInfoWeekly;
|
|
263 |
int error = mAlarmClient->getAlarmInfo(tempId, retrievedalarmInfoWeekly);
|
|
264 |
|
|
265 |
if (0 == error) {
|
|
266 |
QVERIFY(alarmInfoWeekly.alarmDesc ==
|
|
267 |
retrievedalarmInfoWeekly.alarmDesc);
|
|
268 |
QVERIFY(alarmInfoWeekly.repeatType ==
|
|
269 |
retrievedalarmInfoWeekly.repeatType);
|
|
270 |
// TODO: have to check the alarm day. ll do later.
|
|
271 |
// QVERIFY(alarmInfoWeekly.alarmDay ==
|
|
272 |
// retrievedalarmInfoWeekly.alarmDay);
|
|
273 |
QVERIFY(alarmInfoWeekly.alarmId ==
|
|
274 |
retrievedalarmInfoWeekly.alarmId);
|
|
275 |
QVERIFY(alarmInfoWeekly.origAlarmTime ==
|
|
276 |
retrievedalarmInfoWeekly.origAlarmTime);
|
|
277 |
}
|
|
278 |
else {
|
|
279 |
QVERIFY(false);
|
|
280 |
}
|
|
281 |
}
|
|
282 |
|
|
283 |
/*!
|
|
284 |
Tests the api AlarmClient::setAlarmWorkdays with a workdays alarm.
|
|
285 |
*/
|
|
286 |
void TestAlarmClient::testSetAlarmWorkdays()
|
|
287 |
{
|
|
288 |
QTime alarmTime;
|
|
289 |
QString descInfo("This is a workdays alarm");
|
|
290 |
|
|
291 |
AlarmInfo alarmInfoWorkdays;
|
|
292 |
// First the description.
|
|
293 |
alarmInfoWorkdays.alarmDesc = descInfo;
|
|
294 |
// The time.
|
|
295 |
alarmTime = QTime::fromString("12:30 pm", "hh:mm ap");
|
|
296 |
// Construct the alarm info.
|
|
297 |
alarmInfoWorkdays.origAlarmTime = alarmTime;
|
|
298 |
// Fill the repeat type.
|
|
299 |
alarmInfoWorkdays.repeatType = Workday;
|
|
300 |
|
|
301 |
// Request the listener to set the alarm.
|
|
302 |
mAlarmClient->setAlarm(alarmInfoWorkdays);
|
|
303 |
// Get the Id of the alarm set.
|
|
304 |
int tempId = alarmInfoWorkdays.alarmId;
|
|
305 |
|
|
306 |
// Retrieve the alarm information and compare.
|
|
307 |
AlarmInfo retrievedalarmInfoWorkdays;
|
|
308 |
int error = mAlarmClient->getAlarmInfo(tempId, retrievedalarmInfoWorkdays);
|
|
309 |
|
|
310 |
if (0 == error) {
|
|
311 |
QVERIFY(alarmInfoWorkdays.origAlarmTime ==
|
|
312 |
retrievedalarmInfoWorkdays.origAlarmTime);
|
|
313 |
QVERIFY(alarmInfoWorkdays.alarmDesc ==
|
|
314 |
retrievedalarmInfoWorkdays.alarmDesc);
|
|
315 |
QVERIFY(alarmInfoWorkdays.repeatType ==
|
|
316 |
retrievedalarmInfoWorkdays.repeatType);
|
|
317 |
QVERIFY(alarmInfoWorkdays.alarmId ==
|
|
318 |
retrievedalarmInfoWorkdays.alarmId);
|
|
319 |
}
|
|
320 |
else {
|
|
321 |
QVERIFY(false);
|
|
322 |
}
|
|
323 |
}
|
|
324 |
|
|
325 |
/*!
|
|
326 |
Tests the api AlarmClient::setAlarmOncleOnly for a once only alarm.
|
|
327 |
*/
|
|
328 |
void TestAlarmClient::testSetAlarmOnceOnly()
|
|
329 |
{
|
|
330 |
QTime alarmTime;
|
|
331 |
QString descInfo("This is a onceonly alarm");
|
|
332 |
|
|
333 |
AlarmInfo alarmInfoOnceonly;
|
|
334 |
// First the description.
|
|
335 |
alarmInfoOnceonly.alarmDesc = descInfo;
|
|
336 |
// The time.
|
|
337 |
alarmTime = QTime::fromString("12:30 pm", "hh:mm ap");
|
|
338 |
// Construct the alarm info.
|
|
339 |
alarmInfoOnceonly.origAlarmTime = alarmTime;
|
|
340 |
// Fill the repeat type.
|
|
341 |
alarmInfoOnceonly.repeatType = Once;
|
|
342 |
// Fill the day.
|
|
343 |
alarmInfoOnceonly.alarmDay = 6;
|
|
344 |
|
|
345 |
// Request the listener to set the alarm.
|
|
346 |
mAlarmClient->setAlarm(alarmInfoOnceonly);
|
|
347 |
// Get the Id of the alarm set.
|
|
348 |
int tempId = alarmInfoOnceonly.alarmId;
|
|
349 |
|
|
350 |
// Retrieve the alarm information and compare.
|
|
351 |
AlarmInfo retrievedalarmInfoOnceonly;
|
|
352 |
int error = mAlarmClient->getAlarmInfo(tempId, retrievedalarmInfoOnceonly);
|
|
353 |
|
|
354 |
if (0 == error) {
|
|
355 |
QVERIFY(alarmInfoOnceonly.alarmDesc ==
|
|
356 |
retrievedalarmInfoOnceonly.alarmDesc);
|
|
357 |
QVERIFY(alarmInfoOnceonly.repeatType ==
|
|
358 |
retrievedalarmInfoOnceonly.repeatType);
|
|
359 |
// TODO: have to check the alarm day. ll do later.
|
|
360 |
// QVERIFY(alarmInfoOnceonly.alarmDay ==
|
|
361 |
// retrievedalarmInfoOnceonly.alarmDay);
|
|
362 |
QVERIFY(alarmInfoOnceonly.alarmId ==
|
|
363 |
retrievedalarmInfoOnceonly.alarmId);
|
|
364 |
QVERIFY(alarmInfoOnceonly.origAlarmTime ==
|
|
365 |
retrievedalarmInfoOnceonly.origAlarmTime);
|
|
366 |
}
|
|
367 |
else {
|
|
368 |
QVERIFY(false);
|
|
369 |
}
|
|
370 |
}
|
|
371 |
|
|
372 |
QTEST_MAIN(TestAlarmClient)
|
|
373 |
#include "unittest_alarmclient.moc"
|
|
374 |
|
|
375 |
// End of file --Don't remove this.
|