|
1 // Copyright (c) 2005-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 // Contains implementation of CTestStartAlertServerStep class |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 // User Include |
|
24 #include "TestStartAlertServerStep.h" |
|
25 #include "AlarmControlsManager.h" |
|
26 |
|
27 // System Include |
|
28 #include <uikon/eikalsrv.h> |
|
29 |
|
30 /** |
|
31 Constructor. Sets the test step name. Testserver reference passed to make use |
|
32 of TEF's method of sharing data between test steps |
|
33 Max alarms defaults to 1 if not mentioned in ini |
|
34 @internalTechnology |
|
35 @test |
|
36 */ |
|
37 CTestStartAlertServerStep::CTestStartAlertServerStep(CTestMultipleAlarmsServer& aTestServer) |
|
38 : CTestBaseStep(aTestServer) |
|
39 { |
|
40 //Call base class method to set human readable name for test step |
|
41 SetTestStepName(KTestStartAlertServerStep); |
|
42 } |
|
43 |
|
44 /** |
|
45 Base class pure virtual. |
|
46 @return EPass or EFail indicating the result of the test step. |
|
47 @internalTechnology |
|
48 @test |
|
49 */ |
|
50 TVerdict CTestStartAlertServerStep::doTestStepL() |
|
51 { |
|
52 TInt maxAlarms; |
|
53 if(!ReadIntsFromConfig(ConfigSection(), &KIniMaxAlarms(), &maxAlarms, NULL)) |
|
54 { |
|
55 INFO_PRINTF1(_L("maxalarms value not found in ini. maxalarms will hence default to 1")); |
|
56 maxAlarms = 1; |
|
57 } |
|
58 |
|
59 // Let the test server record the current maxalarms value, to share it |
|
60 // with other test steps |
|
61 TestServer()->CurrentMaxAlarms() = maxAlarms; |
|
62 |
|
63 PrintIfError(CreateThreadAndStartAltSrv()); |
|
64 return TestStepResult(); |
|
65 } |
|
66 |
|
67 /** |
|
68 Starts the alarm alert server |
|
69 @param aTestStep Pointer to the CTestStartAlertServerStep. |
|
70 @internalTechnology |
|
71 @test |
|
72 */ |
|
73 LOCAL_C void StartAlarmAlertServer(CTestMultipleAlarmsServer* aTestServer) |
|
74 { |
|
75 const TInt KMaxAttempts = 5; |
|
76 TInt error = KErrNone; |
|
77 CEikServAlarmAlertServer* alertServer = NULL; |
|
78 CAlarmControlsManager *manager = NULL; |
|
79 |
|
80 TRAP(error, manager = CAlarmControlsManager::NewL(*aTestServer)); |
|
81 |
|
82 if(error == KErrNone) |
|
83 { |
|
84 aTestServer->AlarmControlsManager() = manager; |
|
85 for(TInt attempt = 0; attempt < KMaxAttempts; ++attempt) |
|
86 { |
|
87 if(aTestServer->CurrentMaxAlarms() == 1) |
|
88 {// Calling the single alarm notification version. Can still call the multiple alarm |
|
89 // version with 1 as maxalarms value, but still just to cover the existing API too. |
|
90 TRAP(error, alertServer = CEikServAlarmAlertServer::NewL(manager)); |
|
91 } |
|
92 else |
|
93 {// Multiple alarm version |
|
94 TRAP(error, alertServer = CEikServAlarmAlertServer::NewL(manager, aTestServer->CurrentMaxAlarms())); |
|
95 } |
|
96 |
|
97 if(error != KErrAlreadyExists) |
|
98 {// Although the thread is shown as dead, EPOC seems to do some |
|
99 // background closing operations, and does not allow us to create a |
|
100 // thread with the same name till then. So we try a few more times |
|
101 // only if it is KErrAlreadyExists |
|
102 break; |
|
103 } |
|
104 } |
|
105 } |
|
106 // Tell the test step thread about the status |
|
107 RThread::Rendezvous(error); |
|
108 |
|
109 if(error == KErrNone) |
|
110 { |
|
111 aTestServer->AlertServer() = alertServer; |
|
112 |
|
113 // enter the active scheduler if everything is ok |
|
114 CActiveScheduler::Start(); |
|
115 |
|
116 // When thread exits, clean up |
|
117 delete (aTestServer->AlertServer()); |
|
118 delete (aTestServer->AlarmControlsManager()); |
|
119 } |
|
120 } |
|
121 |
|
122 /** |
|
123 Thread entry point |
|
124 @return Error code of the operation performed |
|
125 @internalTechnology |
|
126 @test |
|
127 */ |
|
128 static TInt ThreadStartFn(TAny* aPtr) |
|
129 { |
|
130 __UHEAP_MARK; |
|
131 CActiveScheduler* sched = new(ELeave) CActiveScheduler; |
|
132 CActiveScheduler::Install(sched); |
|
133 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
134 if(cleanup == NULL) |
|
135 { |
|
136 delete sched; |
|
137 return KErrNoMemory; |
|
138 } |
|
139 CTestMultipleAlarmsServer* testServer = (static_cast<CTestStartAlertServerStep*>(aPtr))->TestServer(); |
|
140 StartAlarmAlertServer(testServer); |
|
141 delete sched; |
|
142 delete cleanup; |
|
143 __UHEAP_MARKEND; |
|
144 return KErrNone; |
|
145 } |
|
146 |
|
147 |
|
148 /** |
|
149 Starts the alarm alert server |
|
150 @param aMaxAlarms Maximum number of alarms for which we want the alert server |
|
151 to notify at a time |
|
152 @return The error code |
|
153 @internalTechnology |
|
154 @test |
|
155 */ |
|
156 TInt CTestStartAlertServerStep::CreateThreadAndStartAltSrv() |
|
157 { |
|
158 _LIT(KChildThreadName, "ChildThreadThatStartsAlarmAlertServerInAlarmAlertServerTests"); |
|
159 TBuf<65> childThreadName(KChildThreadName); |
|
160 RThread childThread; |
|
161 |
|
162 const TInt KMaxTestThreadHeapSize = 0x10000; |
|
163 |
|
164 TInt err = childThread.Create( |
|
165 childThreadName, |
|
166 ThreadStartFn, |
|
167 KDefaultStackSize, |
|
168 KMinHeapSize, |
|
169 KMaxTestThreadHeapSize, |
|
170 this, |
|
171 EOwnerProcess); |
|
172 |
|
173 if(err == KErrNone) |
|
174 { |
|
175 TRequestStatus status; |
|
176 childThread.Rendezvous(status); |
|
177 if(status != KRequestPending) |
|
178 { |
|
179 childThread.Kill(0); |
|
180 } |
|
181 else |
|
182 { |
|
183 childThread.Resume(); |
|
184 |
|
185 // Cache the thread handle, so as to examine its death later |
|
186 TestServer()->AltSrvThread() = childThread; |
|
187 |
|
188 INFO_PRINTF2(_L("<B>Alert Server thread has started, Max alarms = %D</B>"), TestServer()->CurrentMaxAlarms()); |
|
189 } |
|
190 User::WaitForRequest(status); |
|
191 |
|
192 // Examine the child thread's exit type and reason. |
|
193 // If it is a panic, it can be KErrNone too, and if so, make it KErrGeneral, |
|
194 // so that the Test Step does not wrongly EPass seeing KErrNone in err. |
|
195 // The Kern-Exec Panic 0 information will not be lost either, as each test |
|
196 // step checks and displays this in its Postamble. |
|
197 err = (childThread.ExitType()==EExitPanic && childThread.ExitReason() == KErrNone |
|
198 ) ? KErrGeneral : status.Int(); |
|
199 } |
|
200 return err; |
|
201 } |
|
202 |