|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 // System includes |
|
17 #include <e32base.h> |
|
18 #include <e32test.h> |
|
19 #include <f32file.h> |
|
20 #include <s32mem.h> |
|
21 |
|
22 // User includes |
|
23 #include <asshdalarm.h> |
|
24 #include <asclisession.h> |
|
25 #include <consolealarmalertservermain.h> |
|
26 #include "testserver.h" |
|
27 #include "ASTstAlarmTest.h" |
|
28 |
|
29 // Type definitions |
|
30 typedef void (*ThreadTestL)(void); |
|
31 |
|
32 // Constants |
|
33 const TUid KServerUid2={0x1000008D}; |
|
34 const TUid KServerUid3={0x101F502A}; |
|
35 const TUidType serverUid(KNullUid,KServerUid2,KServerUid3); |
|
36 |
|
37 // Literal constants |
|
38 _LIT(KTestTitle, "TAlarmRobustness"); |
|
39 _LIT(KRobustTestCreateServer, "Creating alarm server"); |
|
40 |
|
41 #ifdef _DEBUG |
|
42 #ifdef __WINS__ |
|
43 _LIT(KRobustTestCloseServer, "Close alarm server"); |
|
44 #endif // #ifdef __WINS__ |
|
45 #endif // #ifdef _DEBUG |
|
46 |
|
47 #ifdef _DEBUG |
|
48 #ifdef __WINS__ |
|
49 _LIT(KTestIniFile, "c:\\private\\101f5027\\AlarmServer.ini"); |
|
50 _LIT(KAlarmIniFileDir, "c:\\private\\101f5027\\"); |
|
51 #endif // #ifdef __WINS__ |
|
52 #endif // #ifdef _DEBUG |
|
53 |
|
54 // Globals |
|
55 //static RTest TheAlarmTest(KTestTitle); |
|
56 static RASCliSession TheAlarmServerSession; |
|
57 |
|
58 const TInt KAlarmObjectBuffer = 512; |
|
59 |
|
60 #ifdef _DEBUG |
|
61 #ifdef __WINS__ |
|
62 |
|
63 const TInt KAlarmTestWaitForFileWrite = 2000000; |
|
64 |
|
65 |
|
66 static void TestClearStoreL() |
|
67 { |
|
68 // Delete all alarms |
|
69 RArray<TAlarmCategory> categories; |
|
70 TheAlarmServerSession.GetAvailableCategoryListL(categories); |
|
71 const TInt KAlarmCategoriesCount = categories.Count(); |
|
72 for(TInt i=0; i<KAlarmCategoriesCount; i++) |
|
73 { |
|
74 const TAlarmCategory category = categories[i]; |
|
75 TheAlarmTest(TheAlarmServerSession.AlarmDeleteAllByCategory(category, EFalse) == KErrNone, __LINE__); |
|
76 } |
|
77 categories.Close(); |
|
78 } |
|
79 |
|
80 static void DeleteIniFileL() |
|
81 { |
|
82 RPIMTestServer serv; |
|
83 User::LeaveIfError(serv.Connect()); |
|
84 CleanupClosePushL(serv); |
|
85 serv.DeleteFileL(KTestIniFile); |
|
86 CleanupStack::PopAndDestroy(&serv); |
|
87 } |
|
88 |
|
89 #endif // #ifdef __WINS__ |
|
90 #endif // #ifdef _DEBUG |
|
91 |
|
92 //************************************************************************************* |
|
93 void InitializeAlarm(TASShdAlarm& theAlarm) |
|
94 { |
|
95 theAlarm.Category() = KASCliCategoryClock; |
|
96 theAlarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatDaily; |
|
97 _LIT(KAlarmTestInit, "This is an alarm message - alarm 1"); |
|
98 theAlarm.Message() = KAlarmTestInit; |
|
99 theAlarm.NextDueTime().HomeTime(); |
|
100 theAlarm.NextDueTime() += TTimeIntervalMinutes(1); |
|
101 _LIT(KAlarmTestSoundName, "Arf Arf Woop"); |
|
102 theAlarm.SoundName() = KAlarmTestSoundName; |
|
103 } |
|
104 |
|
105 |
|
106 #ifdef _DEBUG |
|
107 #ifdef __WINS__ |
|
108 static void CreateSingleTestAlarmL(TAlarmId& testID) |
|
109 { |
|
110 _LIT(KAlarmTestAddDisabled, "Adding disabled alarm"); |
|
111 TheAlarmTest.Next(KAlarmTestAddDisabled); |
|
112 // |
|
113 TASShdAlarm alarm; |
|
114 InitializeAlarm(alarm); |
|
115 |
|
116 // |
|
117 TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__); |
|
118 const TAlarmId id = alarm.Id(); |
|
119 testID = id; |
|
120 TheAlarmTest(id != KNullAlarmId, __LINE__); |
|
121 |
|
122 // |
|
123 _LIT(KAlarmTestGetDetails, "Get alarm details"); |
|
124 TheAlarmTest.Next(KAlarmTestGetDetails); |
|
125 TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__); |
|
126 |
|
127 // |
|
128 _LIT(KAlarmTestEnableAlarm, "Enabling a disabled alarm"); |
|
129 TheAlarmTest.Next(KAlarmTestEnableAlarm); |
|
130 TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__); |
|
131 } |
|
132 |
|
133 |
|
134 static void RunNoConfigFileTestL() |
|
135 { |
|
136 _LIT(KRobustTestNoConfig, "Run No Config File Test"); |
|
137 TheAlarmTest.Next(KRobustTestNoConfig); |
|
138 |
|
139 // 1) Delete AlarmServer.ini file |
|
140 DeleteIniFileL(); |
|
141 |
|
142 // 2) Connect to the alarm server. |
|
143 TheAlarmTest.Next(KRobustTestCreateServer); |
|
144 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
145 |
|
146 // 3) Add alarm. |
|
147 TAlarmId testID = KNullAlarmId; |
|
148 CleanupClosePushL(TheAlarmServerSession); |
|
149 CreateSingleTestAlarmL(testID); |
|
150 |
|
151 // 4) Shutdown alarm server. |
|
152 TheAlarmTest.Next(KRobustTestCloseServer); |
|
153 TheAlarmServerSession.__DbgShutDownServer(); |
|
154 CleanupStack::PopAndDestroy(&TheAlarmServerSession); |
|
155 |
|
156 // 5) Restart alarm server. |
|
157 TheAlarmTest.Next(KRobustTestCreateServer); |
|
158 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
159 |
|
160 // 6) Check alarm has persisted. |
|
161 TASShdAlarm testAlarm; |
|
162 TInt error = TheAlarmServerSession.GetAlarmDetails(testID, testAlarm); |
|
163 TheAlarmTest(error == KErrNone, __LINE__); |
|
164 } |
|
165 |
|
166 |
|
167 static void RunZeroLengthConfigFileTestL() |
|
168 { |
|
169 _LIT(KRobustTestZeroLengthConfigFile, "Run Zero Length Config File Test"); |
|
170 TheAlarmTest.Next(KRobustTestZeroLengthConfigFile); |
|
171 |
|
172 // 1) Create an alarm to make sure there is a config file. |
|
173 TAlarmId testID = KNullAlarmId; |
|
174 CreateSingleTestAlarmL(testID); |
|
175 User::After(KAlarmTestWaitForFileWrite); |
|
176 |
|
177 // 2) Zero length the AlarmServer.ini file |
|
178 TestClearStoreL(); |
|
179 |
|
180 // 3) Connect to the alarm server. |
|
181 TheAlarmTest.Next(KRobustTestCreateServer); |
|
182 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
183 |
|
184 // 4) Add alarm. |
|
185 CleanupClosePushL(TheAlarmServerSession); |
|
186 CreateSingleTestAlarmL(testID); |
|
187 |
|
188 // 5) Shutdown alarm server. |
|
189 TheAlarmTest.Next(KRobustTestCloseServer); |
|
190 TheAlarmServerSession.__DbgShutDownServer(); |
|
191 CleanupStack::PopAndDestroy(&TheAlarmServerSession); |
|
192 |
|
193 // 6) Restart alarm server. |
|
194 TheAlarmTest.Next(KRobustTestCreateServer); |
|
195 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
196 |
|
197 // 7) Check alarm has persisted. |
|
198 TASShdAlarm testAlarm; |
|
199 TInt error = TheAlarmServerSession.GetAlarmDetails(testID, testAlarm); |
|
200 TheAlarmTest(error == KErrNone, __LINE__); |
|
201 } |
|
202 |
|
203 |
|
204 static void CorruptErrorConditionTestL() |
|
205 { |
|
206 _LIT(KRobustTestCorruptErrorCondition, "Corrupt Error Condition Test"); |
|
207 TheAlarmTest.Next(KRobustTestCorruptErrorCondition); |
|
208 |
|
209 // 1) Create file session to call SetErrorCondition. |
|
210 TAlarmId testID = KNullAlarmId; |
|
211 TInt error = KErrCorrupt; |
|
212 RFs testFile; |
|
213 User::LeaveIfError(testFile.Connect()); |
|
214 CleanupClosePushL(testFile); |
|
215 |
|
216 // 2) Create a few alarms to make sure we have populated config file. |
|
217 TheAlarmTest.Next(KRobustTestCreateServer); |
|
218 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
219 CleanupClosePushL(TheAlarmServerSession); |
|
220 const TInt KNumberOfTestAlarms = 3; |
|
221 for( TInt i=0;i<KNumberOfTestAlarms;i++) |
|
222 { |
|
223 CreateSingleTestAlarmL(testID); |
|
224 } |
|
225 User::After(KAlarmTestWaitForFileWrite); |
|
226 |
|
227 // 3) Shut down server so we can re-connect and do internalization. |
|
228 TheAlarmServerSession.__DbgShutDownServer(); |
|
229 CleanupStack::PopAndDestroy(&TheAlarmServerSession); |
|
230 |
|
231 // 4) Test loop - This will cycle through file session internalization |
|
232 // process, checking to see that it leaves each time, instead of panicking. |
|
233 for (TInt failureCounter = 1 ; error == KErrCorrupt ; ++failureCounter) |
|
234 { |
|
235 testFile.SetErrorCondition(KErrCorrupt , failureCounter ); |
|
236 error = TheAlarmServerSession.Connect(); |
|
237 testFile.SetErrorCondition(KErrNone ); |
|
238 } |
|
239 |
|
240 // 5) Close file session. |
|
241 CleanupStack::PopAndDestroy(&testFile); |
|
242 |
|
243 TheAlarmTest(error == KErrNone, __LINE__); |
|
244 } |
|
245 |
|
246 static void ServerStartUpWithNoIniFileL() |
|
247 { |
|
248 _LIT(KRobustTestNoConfigDir, "Server Startup With No Config File Test"); |
|
249 _LIT(KRobustTestDeleteIniFileDir, "Delete INI file and Dir"); |
|
250 _LIT(KRobustTestDeleteIniFile, "Delete INI file"); |
|
251 TheAlarmTest.Next(KRobustTestNoConfigDir); |
|
252 RPIMTestServer serv; |
|
253 User::LeaveIfError(serv.Connect()); |
|
254 CleanupClosePushL(serv); |
|
255 |
|
256 // 1) Close Alarm Server |
|
257 TheAlarmTest.Start(KRobustTestCloseServer); |
|
258 TheAlarmServerSession.__DbgShutDownServer(); |
|
259 |
|
260 // 2) Delete AlarmServer.ini file and it's dir |
|
261 TheAlarmTest.Next(KRobustTestDeleteIniFileDir); |
|
262 serv.DeleteFileL(KTestIniFile); |
|
263 serv.DeleteDirL(KAlarmIniFileDir); |
|
264 AlarmTest(serv.CheckForFile(KTestIniFile)==KErrPathNotFound); //Check directory deleted |
|
265 |
|
266 // 3) Connect to the alarm server and check it created INI file directory |
|
267 TheAlarmTest.Next(KRobustTestCreateServer); |
|
268 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
269 AlarmTest(serv.CheckForFile(KTestIniFile)==KErrNotFound); //Check directory created but file still absent |
|
270 |
|
271 // 4) Add alarm and check INI file created |
|
272 TAlarmId testID = KNullAlarmId; |
|
273 TRequestStatus serverIniStatus; |
|
274 const TTimeIntervalMicroSeconds32 KTimeOutPeriod(1000000); |
|
275 RTimer timeoutTimer; |
|
276 CleanupClosePushL(timeoutTimer); |
|
277 TRequestStatus timerStatus; |
|
278 User::LeaveIfError(timeoutTimer.CreateLocal()); |
|
279 timeoutTimer.After(timerStatus, KTimeOutPeriod); |
|
280 serv.FileServerNotifyChange(ENotifyFile, serverIniStatus, KTestIniFile); |
|
281 |
|
282 CreateSingleTestAlarmL(testID); |
|
283 User::WaitForRequest(timerStatus, serverIniStatus); |
|
284 |
|
285 if (timerStatus.Int() != KRequestPending) |
|
286 { |
|
287 // The file creation did not time out |
|
288 // so cancel the time out timer |
|
289 timeoutTimer.Cancel(); |
|
290 User::WaitForRequest(timerStatus); |
|
291 } |
|
292 else |
|
293 { |
|
294 // The file creation timed out |
|
295 // so cancel the FileServerNotifyChange |
|
296 serv.FileServerNotifyChangeCancel(); |
|
297 User::WaitForRequest(serverIniStatus); |
|
298 } |
|
299 |
|
300 AlarmTest(serv.CheckForFile(KTestIniFile)==KErrNone); //Check file present |
|
301 |
|
302 // 6) Close Alarm Server Again |
|
303 TheAlarmTest.Next(KRobustTestCloseServer); |
|
304 TheAlarmServerSession.__DbgShutDownServer(); |
|
305 |
|
306 // 7) Delete AlarmServer.ini file only |
|
307 TheAlarmTest.Next(KRobustTestDeleteIniFile); |
|
308 serv.DeleteFileL(KTestIniFile); |
|
309 AlarmTest(serv.CheckForFile(KTestIniFile)==KErrNotFound); //Check file deleted but directory still there |
|
310 |
|
311 // 8) Connect to the alarm server |
|
312 TheAlarmTest.Next(KRobustTestCreateServer); |
|
313 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
314 AlarmTest(serv.CheckForFile(KTestIniFile)==KErrNotFound); //Check directory there but file still absent |
|
315 |
|
316 // 9) Add alarm and check INI file created |
|
317 testID = KNullAlarmId; |
|
318 serv.FileServerNotifyChange(ENotifyFile, serverIniStatus, KTestIniFile); |
|
319 timeoutTimer.After(timerStatus, KTimeOutPeriod); |
|
320 |
|
321 CreateSingleTestAlarmL(testID); |
|
322 User::WaitForRequest(timerStatus, serverIniStatus); |
|
323 |
|
324 if (timerStatus.Int() != KRequestPending) |
|
325 { |
|
326 // The file creation did not time out |
|
327 // so cancel the time out timer |
|
328 timeoutTimer.Cancel(); |
|
329 User::WaitForRequest(timerStatus); |
|
330 } |
|
331 else |
|
332 { |
|
333 // The file creation timed out |
|
334 // so cancel the FileServerNotifyChange |
|
335 serv.FileServerNotifyChangeCancel(); |
|
336 User::WaitForRequest(serverIniStatus); |
|
337 } |
|
338 |
|
339 AlarmTest(serv.CheckForFile(KTestIniFile)==KErrNone); //Check file present |
|
340 |
|
341 TheAlarmTest.UpLevel(); |
|
342 CleanupStack::PopAndDestroy(&timeoutTimer); |
|
343 CleanupStack::PopAndDestroy(&serv); |
|
344 serv.Close(); |
|
345 } |
|
346 |
|
347 |
|
348 #endif // #ifdef _DEBUG |
|
349 #endif // #ifdef __WINS__ |
|
350 |
|
351 |
|
352 static void AlarmInternalizationTestL() |
|
353 { |
|
354 _LIT(KRobustTestAlarmInternalization, "Alarm Internalization Test"); |
|
355 TheAlarmTest.Next(KRobustTestAlarmInternalization); |
|
356 |
|
357 // 1) Create an alarm object. |
|
358 TASShdAlarm alarm; |
|
359 TASShdAlarm alarm2; |
|
360 InitializeAlarm(alarm); |
|
361 |
|
362 // 2) Create a memory buffer to store alarm object created above. |
|
363 CBufFlat* buffer = CBufFlat::NewL(KAlarmObjectBuffer); // approximation |
|
364 CleanupStack::PushL(buffer); |
|
365 RBufWriteStream stream(*buffer); |
|
366 |
|
367 // 3) Externalize alarm object into memory buffer. |
|
368 alarm.ExternalizeL(stream); |
|
369 stream.CommitL(); |
|
370 |
|
371 // 4) Create second memor`y buffer to manipulate the one above. |
|
372 CBufFlat* buffer2 = CBufFlat::NewL(KAlarmObjectBuffer); |
|
373 CleanupStack::PushL(buffer2); |
|
374 |
|
375 // 5) Test loop - Copy the contents of buffer to buffer2, starting at |
|
376 // the end of buffer. |
|
377 // We just want to test that our methods leave normally under |
|
378 // the error condition and not induce a panic. So we don't need |
|
379 // to handle the Trap in this test loop. |
|
380 TInt err = KErrCorrupt; |
|
381 for(TInt i = buffer->Size()-1; i>-1; i--) |
|
382 { |
|
383 TPtr8 ptr=buffer->Ptr(i); |
|
384 buffer2->Reset(); |
|
385 buffer2->InsertL(0, ptr); |
|
386 |
|
387 RBufReadStream rStream(*buffer2); |
|
388 TRAP(err, alarm2.InternalizeL(rStream)) |
|
389 |
|
390 } |
|
391 |
|
392 TheAlarmTest.Test().Printf(_L("AlarmInternalizationTestL error = %d\n"), err); |
|
393 |
|
394 TheAlarmTest(err == KErrNone, __LINE__); |
|
395 |
|
396 CleanupStack::PopAndDestroy(buffer2); |
|
397 CleanupStack::PopAndDestroy(buffer); |
|
398 } |
|
399 |
|
400 |
|
401 static void AlarmFormatInternalizationTestL() |
|
402 { |
|
403 _LIT(KRobustTestAlarmFormatInternalization, "Alarm Format Internalization Test"); |
|
404 TheAlarmTest.Next(KRobustTestAlarmFormatInternalization); |
|
405 |
|
406 // 1) Create an alarm object. |
|
407 TASShdAlarm alarm; |
|
408 TASShdAlarm alarm2; |
|
409 InitializeAlarm(alarm); |
|
410 |
|
411 // 2) Create a memory buffer to store alarm object created above. |
|
412 CBufFlat* buffer = CBufFlat::NewL(KAlarmObjectBuffer); // approximation |
|
413 CleanupStack::PushL(buffer); |
|
414 RBufWriteStream stream(*buffer); |
|
415 |
|
416 // 3) Externalize alarm object into memory buffer. |
|
417 alarm.ExternalizeL(stream); |
|
418 stream.CommitL(); |
|
419 |
|
420 // 4) Create second memory buffer to manipulate the one above. |
|
421 TPtr8 initPtr = buffer->Ptr(0); // Ptr to beginning of buffer. |
|
422 CBufFlat* buffer2 = CBufFlat::NewL(KAlarmObjectBuffer); |
|
423 CleanupStack::PushL(buffer2); |
|
424 |
|
425 // 5) Test loop - Write a character to every position of the |
|
426 // alarm object. |
|
427 // We just want to test that our methods leave normally under |
|
428 // the error condition and not induce a panic. So we don't need |
|
429 // to handle the Trap in this test loop. |
|
430 TInt err = KErrCorrupt; |
|
431 _LIT(KRobustTestCharactter, "a"); |
|
432 const TInt KBufferSize = buffer->Size()-1; |
|
433 for(TInt i = 0; i<KBufferSize; i++) |
|
434 { |
|
435 alarm2.Reset(); |
|
436 alarm2 = alarm; |
|
437 buffer2->Reset(); |
|
438 buffer2->InsertL(0, initPtr); |
|
439 |
|
440 TPtr8 ptr = buffer2->Ptr(i); |
|
441 ptr.Copy(KRobustTestCharactter); |
|
442 |
|
443 RBufReadStream rStream(*buffer2); |
|
444 TRAP(err, alarm2.InternalizeL(rStream)) |
|
445 |
|
446 } |
|
447 |
|
448 TheAlarmTest(err == KErrNone, __LINE__); |
|
449 |
|
450 CleanupStack::PopAndDestroy(buffer2); |
|
451 CleanupStack::PopAndDestroy(buffer); |
|
452 } |
|
453 |
|
454 //************************************************************************************* |
|
455 void InitializeUtcAlarm(TASShdAlarm& theAlarm) |
|
456 { |
|
457 theAlarm.Category()=KASCliCategoryClock; |
|
458 theAlarm.RepeatDefinition()=EAlarmRepeatDefintionRepeatDaily; |
|
459 _LIT(KAlarmTestInit, "This is a UTC alarm message - alarm 1"); |
|
460 TBuf<KMaxAlarmMessageLength> buf(KAlarmTestInit); |
|
461 theAlarm.Message()=buf; |
|
462 TTime time; |
|
463 time.UniversalTime(); |
|
464 time += TTimeIntervalMinutes(1); |
|
465 theAlarm.SetUtcNextDueTime(time); |
|
466 _LIT(KAlarmTestSoundName, "Arf Arf Woop"); |
|
467 buf = KAlarmTestSoundName; |
|
468 theAlarm.SoundName()=buf; |
|
469 } |
|
470 |
|
471 |
|
472 #ifdef _DEBUG |
|
473 #ifdef __WINS__ |
|
474 static void CreateSingleTestUtcAlarmL(TAlarmId& testID) |
|
475 { |
|
476 _LIT(KAlarmTestAddDisabled, "Adding disabled UTC alarm"); |
|
477 TheAlarmTest.Next(KAlarmTestAddDisabled); |
|
478 // |
|
479 TASShdAlarm alarm; |
|
480 InitializeUtcAlarm(alarm); |
|
481 |
|
482 // |
|
483 TheAlarmTest(TheAlarmServerSession.AlarmAdd(alarm) == KErrNone, __LINE__); |
|
484 const TAlarmId id = alarm.Id(); |
|
485 testID = id; |
|
486 TheAlarmTest(id != KNullAlarmId, __LINE__); |
|
487 |
|
488 // |
|
489 _LIT(KAlarmTestGetDetails, "Get UTC alarm details"); |
|
490 TheAlarmTest.Next(KAlarmTestGetDetails); |
|
491 TheAlarmTest(TheAlarmServerSession.GetAlarmDetails(id, alarm) == KErrNone, __LINE__); |
|
492 |
|
493 // |
|
494 _LIT(KAlarmTestEnableAlarm, "Enabling a disabled UTC alarm"); |
|
495 TheAlarmTest.Next(KAlarmTestEnableAlarm); |
|
496 TheAlarmTest(TheAlarmServerSession.SetAlarmStatus(id, EAlarmStatusEnabled) == KErrNone, __LINE__); |
|
497 } |
|
498 |
|
499 |
|
500 static void RunNoConfigFileTestUtcL() |
|
501 { |
|
502 _LIT(KRobustTestNoConfig, "Run No Config File Test"); |
|
503 TheAlarmTest.Next(KRobustTestNoConfig); |
|
504 |
|
505 // 1) Delete AlarmServer.ini file |
|
506 DeleteIniFileL(); |
|
507 |
|
508 // 2) Connect to the alarm server. |
|
509 TheAlarmTest.Next(KRobustTestCreateServer); |
|
510 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
511 |
|
512 // 3) Add alarm. |
|
513 TAlarmId testID = KNullAlarmId; |
|
514 CleanupClosePushL(TheAlarmServerSession); |
|
515 CreateSingleTestUtcAlarmL(testID); |
|
516 |
|
517 // 4) Shutdown alarm server. |
|
518 TheAlarmTest.Next(KRobustTestCloseServer); |
|
519 TheAlarmServerSession.__DbgShutDownServer(); |
|
520 CleanupStack::PopAndDestroy(&TheAlarmServerSession); |
|
521 |
|
522 // 5) Restart alarm server. |
|
523 TheAlarmTest.Next(KRobustTestCreateServer); |
|
524 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
525 |
|
526 // 6) Check alarm has persisted. |
|
527 TASShdAlarm testAlarm; |
|
528 TInt error = TheAlarmServerSession.GetAlarmDetails(testID, testAlarm); |
|
529 TheAlarmTest(error == KErrNone, __LINE__); |
|
530 } |
|
531 |
|
532 |
|
533 static void RunZeroLengthConfigFileTestUtcL() |
|
534 { |
|
535 _LIT(KRobustTestZeroLengthConfigFile, "Run Zero Length Config File Test"); |
|
536 TheAlarmTest.Next(KRobustTestZeroLengthConfigFile); |
|
537 |
|
538 // 1) Create an alarm to make sure there is a config file. |
|
539 TAlarmId testID = KNullAlarmId; |
|
540 CreateSingleTestUtcAlarmL(testID); |
|
541 User::After(KAlarmTestWaitForFileWrite); |
|
542 |
|
543 // 2) Zero length the AlarmServer.ini file |
|
544 TestClearStoreL(); |
|
545 |
|
546 // 3) Connect to the alarm server. |
|
547 TheAlarmTest.Next(KRobustTestCreateServer); |
|
548 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
549 |
|
550 // 4) Add alarm. |
|
551 CleanupClosePushL(TheAlarmServerSession); |
|
552 CreateSingleTestUtcAlarmL(testID); |
|
553 |
|
554 // 5) Shutdown alarm server. |
|
555 TheAlarmTest.Next(KRobustTestCloseServer); |
|
556 TheAlarmServerSession.__DbgShutDownServer(); |
|
557 CleanupStack::PopAndDestroy(&TheAlarmServerSession); |
|
558 |
|
559 // 6) Restart alarm server. |
|
560 TheAlarmTest.Next(KRobustTestCreateServer); |
|
561 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
562 |
|
563 // 7) Check alarm has persisted. |
|
564 TASShdAlarm testAlarm; |
|
565 TInt error = TheAlarmServerSession.GetAlarmDetails(testID, testAlarm); |
|
566 TheAlarmTest(error == KErrNone, __LINE__); |
|
567 } |
|
568 |
|
569 |
|
570 static void CorruptErrorConditionTestUtcL() |
|
571 { |
|
572 _LIT(KRobustTestCorruptErrorCondition, "Corrupt Error Condition Test"); |
|
573 TheAlarmTest.Next(KRobustTestCorruptErrorCondition); |
|
574 |
|
575 // 1) Create file session to call SetErrorCondition. |
|
576 TAlarmId testID = KNullAlarmId; |
|
577 TInt error = KErrCorrupt; |
|
578 RFs testFile; |
|
579 CleanupClosePushL(testFile); |
|
580 testFile.Connect(); |
|
581 |
|
582 // 2) Create a few alarms to make sure we have populated config file. |
|
583 CleanupClosePushL(TheAlarmServerSession); |
|
584 const TInt KNumberOfTestAlarms = 3; |
|
585 for( TInt i=0;i<KNumberOfTestAlarms;i++) |
|
586 { |
|
587 CreateSingleTestUtcAlarmL(testID); |
|
588 } |
|
589 User::After(KAlarmTestWaitForFileWrite); |
|
590 |
|
591 |
|
592 // 3) Shut down server so we can re-connect and do internalization. |
|
593 TheAlarmServerSession.__DbgShutDownServer(); |
|
594 CleanupStack::PopAndDestroy(&TheAlarmServerSession); |
|
595 |
|
596 // 4) Test loop - This will cycle through file session internalization |
|
597 // process, checking to see that it leaves each time, instead of panicking. |
|
598 for (TInt failureCounter = 1 ; error == KErrCorrupt ; ++failureCounter) |
|
599 { |
|
600 testFile.SetErrorCondition(KErrCorrupt , failureCounter ); |
|
601 error = TheAlarmServerSession.Connect(); |
|
602 testFile.SetErrorCondition(KErrNone ); |
|
603 TheAlarmServerSession.Close(); |
|
604 } |
|
605 |
|
606 // 5) Close file session. |
|
607 CleanupStack::PopAndDestroy(&testFile); |
|
608 testFile.Close(); |
|
609 TheAlarmTest(error == KErrNone, __LINE__); |
|
610 } |
|
611 #endif // #ifdef _DEBUG |
|
612 #endif // #ifdef __WINS__ |
|
613 |
|
614 |
|
615 static void UtcAlarmInternalizationTestL() |
|
616 { |
|
617 _LIT(KRobustTestAlarmInternalization, "UTC Alarm Internalization Test"); |
|
618 TheAlarmTest.Next(KRobustTestAlarmInternalization); |
|
619 |
|
620 // 1) Create an alarm object. |
|
621 TASShdAlarm alarm; |
|
622 TASShdAlarm alarm2; |
|
623 InitializeUtcAlarm(alarm); |
|
624 |
|
625 // 2) Create a memory buffer to store alarm object created above. |
|
626 CBufFlat* buffer = CBufFlat::NewL(KAlarmObjectBuffer); // approximation |
|
627 CleanupStack::PushL(buffer); |
|
628 RBufWriteStream stream(*buffer); |
|
629 |
|
630 // 3) Externalize alarm object into memory buffer. |
|
631 alarm.ExternalizeL(stream); |
|
632 stream.CommitL(); |
|
633 |
|
634 // 4) Create second memor`y buffer to manipulate the one above. |
|
635 CBufFlat* buffer2 = CBufFlat::NewL(KAlarmObjectBuffer); |
|
636 CleanupStack::PushL(buffer2); |
|
637 |
|
638 // 5) Test loop - Copy the contents of buffer to buffer2, starting at |
|
639 // the end of buffer. |
|
640 // We just want to test that our methods leave normally under |
|
641 // the error condition and not induce a panic. So we don't need |
|
642 // to handle the Trap in this test loop. |
|
643 TInt err = KErrCorrupt; |
|
644 for(TInt i = buffer->Size()-1; i>-1; i--) |
|
645 { |
|
646 TPtr8 ptr=buffer->Ptr(i); |
|
647 buffer2->Reset(); |
|
648 buffer2->InsertL(0, ptr); |
|
649 |
|
650 RBufReadStream rStream(*buffer2); |
|
651 TRAP(err, alarm2.InternalizeL(rStream)) |
|
652 |
|
653 } |
|
654 |
|
655 TheAlarmTest.Test().Printf(_L("UtcAlarmInternalizationTestL error = %d\n"), err); |
|
656 |
|
657 TheAlarmTest(err == KErrNone, __LINE__); |
|
658 |
|
659 CleanupStack::PopAndDestroy(buffer2); |
|
660 CleanupStack::PopAndDestroy(buffer); |
|
661 } |
|
662 |
|
663 |
|
664 static void UtcAlarmFormatInternalizationTestL() |
|
665 { |
|
666 _LIT(KRobustTestAlarmFormatInternalization, "UTC Alarm Format Internalization Test"); |
|
667 TheAlarmTest.Next(KRobustTestAlarmFormatInternalization); |
|
668 |
|
669 // 1) Create an alarm object. |
|
670 TASShdAlarm alarm; |
|
671 TASShdAlarm alarm2; |
|
672 InitializeUtcAlarm(alarm); |
|
673 |
|
674 // 2) Create a memory buffer to store alarm object created above. |
|
675 CBufFlat* buffer = CBufFlat::NewL(KAlarmObjectBuffer); // approximation |
|
676 CleanupStack::PushL(buffer); |
|
677 RBufWriteStream stream(*buffer); |
|
678 |
|
679 // 3) Externalize alarm object into memory buffer. |
|
680 alarm.ExternalizeL(stream); |
|
681 stream.CommitL(); |
|
682 |
|
683 // 4) Create second memory buffer to manipulate the one above. |
|
684 TPtr8 initPtr = buffer->Ptr(0); // Ptr to beginning of buffer. |
|
685 CBufFlat* buffer2 = CBufFlat::NewL(KAlarmObjectBuffer); |
|
686 CleanupStack::PushL(buffer2); |
|
687 |
|
688 // 5) Test loop - Write a character to every position of the |
|
689 // alarm object. |
|
690 // We just want to test that our methods leave normally under |
|
691 // the error condition and not induce a panic. So we don't need |
|
692 // to handle the Trap in this test loop. |
|
693 TInt err = KErrCorrupt; |
|
694 _LIT(KRobustTestCharactter, "a"); |
|
695 const TInt KBufferSize = buffer->Size()-1; |
|
696 for(TInt i = 0; i<KBufferSize; i++) |
|
697 { |
|
698 alarm2.Reset(); |
|
699 alarm2 = alarm; |
|
700 buffer2->Reset(); |
|
701 buffer2->InsertL(0, initPtr); |
|
702 |
|
703 TPtr8 ptr = buffer2->Ptr(i); |
|
704 ptr.Copy(KRobustTestCharactter); |
|
705 |
|
706 RBufReadStream rStream(*buffer2); |
|
707 TRAP(err, alarm2.InternalizeL(rStream)) |
|
708 |
|
709 } |
|
710 |
|
711 TheAlarmTest(err == KErrNone, __LINE__); |
|
712 |
|
713 CleanupStack::PopAndDestroy(buffer2); |
|
714 CleanupStack::PopAndDestroy(buffer); |
|
715 } |
|
716 |
|
717 |
|
718 //************************************************************************************* |
|
719 static void RunTestsL() |
|
720 { |
|
721 |
|
722 // Have to start the alarm alert server otherwise the alarm |
|
723 // server cannot start. |
|
724 _LIT(KRobustTestCreateAlarmAlert, "Creating alarm alert server"); |
|
725 TheAlarmTest.Next(KRobustTestCreateAlarmAlert); |
|
726 const TInt KGmtOffset = 3600; |
|
727 _LIT(KTime, "20040730:050000.000000"); //Summertime |
|
728 TInt err = User::SetUTCTimeAndOffset(TTime(KTime), KGmtOffset); |
|
729 TheAlarmTest(err == KErrNone, __LINE__); |
|
730 |
|
731 #ifdef __WINS__ |
|
732 _LIT(KConsoleAlarmAlertServerImg,"ConsoleAlarmAlertServer"); |
|
733 TBuf<256> cmdline; |
|
734 cmdline.Append('p'); |
|
735 cmdline.Append('p'); |
|
736 cmdline.Append(EKeyEscape); |
|
737 RProcess server; |
|
738 server.Create(KConsoleAlarmAlertServerImg, cmdline, serverUid); |
|
739 TRequestStatus stat; |
|
740 server.Rendezvous(stat); |
|
741 if (stat != KRequestPending) |
|
742 { |
|
743 server.Kill(0); // abort startup |
|
744 } |
|
745 else |
|
746 { |
|
747 server.Resume(); // logon OK - start the server |
|
748 } |
|
749 |
|
750 User::WaitForRequest(stat); |
|
751 TInt result = stat.Int(); |
|
752 if(result != KErrNone && result != KErrAlreadyExists) |
|
753 { |
|
754 User::LeaveIfError(result); |
|
755 } |
|
756 #endif // __WINS__ |
|
757 |
|
758 // Connect() checks if the server is already running before connecting. |
|
759 // Here, we call connect to make sure it is running so the tests below can be |
|
760 // executed in any order. |
|
761 |
|
762 // Connect to the alarm server. |
|
763 TheAlarmTest.Next(KRobustTestCreateServer); |
|
764 User::LeaveIfError(TheAlarmServerSession.Connect()); |
|
765 |
|
766 #ifdef _DEBUG |
|
767 #ifdef __WINS__ |
|
768 TestClearStoreL(); |
|
769 DeleteIniFileL(); |
|
770 User::After(KAlarmTestWaitForFileWrite); |
|
771 #endif // #ifdef __WINS__ |
|
772 #endif // #ifdef _DEBUG |
|
773 |
|
774 // Call Test functions. |
|
775 _LIT(KRobustTestCallTests, "Calling Test functions"); |
|
776 TheAlarmTest.Next(KRobustTestCallTests); |
|
777 |
|
778 TheAlarmTest.Test().Printf(_L("Start local alarm tests.\n")); |
|
779 |
|
780 #ifdef _DEBUG |
|
781 #ifdef __WINS__ |
|
782 RunNoConfigFileTestL(); |
|
783 RunZeroLengthConfigFileTestL(); |
|
784 CorruptErrorConditionTestL(); |
|
785 ServerStartUpWithNoIniFileL(); |
|
786 #endif // #ifdef __WINS__ |
|
787 #endif // #ifdef _DEBUG |
|
788 |
|
789 AlarmInternalizationTestL(); |
|
790 AlarmFormatInternalizationTestL(); |
|
791 |
|
792 TheAlarmTest.Test().Printf(_L("Start UTC alarm tests.\n")); |
|
793 |
|
794 #ifdef _DEBUG |
|
795 #ifdef __WINS__ |
|
796 RunNoConfigFileTestUtcL(); |
|
797 RunZeroLengthConfigFileTestUtcL(); |
|
798 CorruptErrorConditionTestUtcL(); |
|
799 #endif // #ifdef __WINS__ |
|
800 #endif // #ifdef _DEBUG |
|
801 |
|
802 UtcAlarmInternalizationTestL(); |
|
803 UtcAlarmFormatInternalizationTestL(); |
|
804 |
|
805 } |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 // |
|
811 // -----> Global Exports |
|
812 // |
|
813 |
|
814 //************************************************************************************* |
|
815 TInt E32Main() |
|
816 { |
|
817 __UHEAP_MARK; |
|
818 TInt ret = KErrNone; |
|
819 // |
|
820 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
821 if (!cleanup) |
|
822 return KErrNoMemory; |
|
823 // |
|
824 TheAlarmTest.Title(); |
|
825 TheAlarmTest.Start(KTestTitle); |
|
826 // @SYMTestCaseID PIM-TALARMROBUSTNESS-0001 |
|
827 TheAlarmTest.Next(_L(" @SYMTestCaseID PIM-TALARMROBUSTNESS-0001 ")); |
|
828 // |
|
829 TRAPD(err, RunTestsL()); |
|
830 TheAlarmTest(err == KErrNone, __LINE__); |
|
831 |
|
832 delete cleanup; |
|
833 TRAP(ret,TheAlarmTest.EndL()); |
|
834 TheAlarmTest.Test().Close(); |
|
835 ASTstAlarmTest::Close(); |
|
836 |
|
837 __UHEAP_MARKEND; |
|
838 return ret; |
|
839 } |