sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <domaindefs.h>
|
sl@0
|
17 |
#include <startupdomaindefs.h>
|
sl@0
|
18 |
#include <schinfointernal.h>
|
sl@0
|
19 |
#include "TE_SSA_ScheduleStepBase.h"
|
sl@0
|
20 |
|
sl@0
|
21 |
CSSA_ScheduleStepBase::CSSA_ScheduleStepBase()
|
sl@0
|
22 |
{
|
sl@0
|
23 |
}
|
sl@0
|
24 |
|
sl@0
|
25 |
CSSA_ScheduleStepBase::~CSSA_ScheduleStepBase()
|
sl@0
|
26 |
{
|
sl@0
|
27 |
iDomainManager.Close();
|
sl@0
|
28 |
|
sl@0
|
29 |
// Delete all schedules
|
sl@0
|
30 |
TRAP_IGNORE(SchSvrHelpers::DeleteAllSchedulesL(iScheduler));
|
sl@0
|
31 |
SchSvrHelpers::Pause(2);
|
sl@0
|
32 |
|
sl@0
|
33 |
// Delete old files
|
sl@0
|
34 |
TRAP_IGNORE(SchSvrHelpers::DeleteScheduleFilesL());
|
sl@0
|
35 |
|
sl@0
|
36 |
iScheduler.Close();
|
sl@0
|
37 |
iSem.Close();
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
TVerdict CSSA_ScheduleStepBase::doTestStepPreambleL()
|
sl@0
|
41 |
{
|
sl@0
|
42 |
SetTestStepResult(EFail);
|
sl@0
|
43 |
|
sl@0
|
44 |
// Delete old files.
|
sl@0
|
45 |
SchSvrHelpers::DeleteScheduleFilesL();
|
sl@0
|
46 |
|
sl@0
|
47 |
iSem.CreateL();
|
sl@0
|
48 |
|
sl@0
|
49 |
TInt ret = iDomainManager.Connect(KDmHierarchyIdStartup);
|
sl@0
|
50 |
iConnectedToDM = (ret==KErrNone);
|
sl@0
|
51 |
|
sl@0
|
52 |
User::LeaveIfError(iScheduler.Connect());
|
sl@0
|
53 |
|
sl@0
|
54 |
// Registering Client
|
sl@0
|
55 |
User::LeaveIfError(SchSvrHelpers::RegisterClientL(iScheduler));
|
sl@0
|
56 |
|
sl@0
|
57 |
// Tests with timezone set to Europe, London
|
sl@0
|
58 |
RTz tz;
|
sl@0
|
59 |
tz.Connect();
|
sl@0
|
60 |
CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
|
sl@0
|
61 |
CleanupStack::PushL(tzId);
|
sl@0
|
62 |
tz.SetTimeZoneL(*tzId);
|
sl@0
|
63 |
CleanupStack::PopAndDestroy(tzId);
|
sl@0
|
64 |
tz.Close();
|
sl@0
|
65 |
|
sl@0
|
66 |
SetTestStepResult(EPass);
|
sl@0
|
67 |
return TestStepResult();
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
TVerdict CSSA_ScheduleStepBase::doTestStepPostambleL()
|
sl@0
|
71 |
{
|
sl@0
|
72 |
TInt err = CleanupHelpers::KillProcess(KMinimalTaskHandler);
|
sl@0
|
73 |
if((err != KErrDied) && (err != KErrNotFound))
|
sl@0
|
74 |
{
|
sl@0
|
75 |
User::LeaveIfError(err);
|
sl@0
|
76 |
}
|
sl@0
|
77 |
return TestStepResult();
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
TInt CSSA_ScheduleStepBase::RequestDomainStateTransition(TStartupStateIdentifier aTargetState)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
TRequestStatus requeststatus;
|
sl@0
|
83 |
|
sl@0
|
84 |
#ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
|
sl@0
|
85 |
iDomainManager.RequestDomainTransition(KSM2OSServicesDomain3,
|
sl@0
|
86 |
#else
|
sl@0
|
87 |
iDomainManager.RequestDomainTransition(KBaseServicesDomain3,
|
sl@0
|
88 |
#endif //SYMBIAN_SYSTEM_STATE_MANAGEMENT
|
sl@0
|
89 |
aTargetState, ETraverseParentsFirst, requeststatus);
|
sl@0
|
90 |
|
sl@0
|
91 |
User::WaitForRequest(requeststatus);
|
sl@0
|
92 |
return requeststatus.Int();
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
void CSSA_ScheduleStepBase::RestartSchedulerL()
|
sl@0
|
96 |
{
|
sl@0
|
97 |
TBool jit = User::JustInTime();
|
sl@0
|
98 |
User::SetJustInTime(EFalse);
|
sl@0
|
99 |
CleanupHelpers::KillProcess(KSchexe);
|
sl@0
|
100 |
User::After(1000000);
|
sl@0
|
101 |
|
sl@0
|
102 |
// Restore original JIT
|
sl@0
|
103 |
User::SetJustInTime(jit);
|
sl@0
|
104 |
|
sl@0
|
105 |
TESTL(iScheduler.Connect() == KErrNone);
|
sl@0
|
106 |
|
sl@0
|
107 |
// Re-register
|
sl@0
|
108 |
TESTL(SchSvrHelpers::RegisterClientL(iScheduler)==KErrNone);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
void CSSA_ScheduleStepBase::AddPersistentScheduleL(const TDesC& aName,
|
sl@0
|
112 |
const TTsTime& aDueTime,
|
sl@0
|
113 |
TSchedulerItemRef& aRef)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
|
sl@0
|
116 |
CleanupStack::PushL(entryList);
|
sl@0
|
117 |
|
sl@0
|
118 |
TScheduleEntryInfo2 entry (aDueTime, EDaily, 1, 30);
|
sl@0
|
119 |
entryList->AppendL(entry);
|
sl@0
|
120 |
|
sl@0
|
121 |
TInt ret = iScheduler.CreatePersistentSchedule(aRef, *entryList);
|
sl@0
|
122 |
TESTL(ret==KErrNone);
|
sl@0
|
123 |
CleanupStack::PopAndDestroy(entryList);
|
sl@0
|
124 |
|
sl@0
|
125 |
// Disable the schedule whilst we set it up
|
sl@0
|
126 |
User::LeaveIfError(iScheduler.DisableSchedule(aRef.iHandle));
|
sl@0
|
127 |
|
sl@0
|
128 |
// Associate a task with the time-based schedule
|
sl@0
|
129 |
TTaskInfo taskInfo;
|
sl@0
|
130 |
taskInfo.iName = aName;
|
sl@0
|
131 |
taskInfo.iPriority = 2;
|
sl@0
|
132 |
taskInfo.iRepeat = 0;
|
sl@0
|
133 |
// Create some data associated with this task
|
sl@0
|
134 |
HBufC* taskData = KTaskData().AllocLC();
|
sl@0
|
135 |
User::LeaveIfError(iScheduler.ScheduleTask(taskInfo, *taskData, aRef.iHandle));
|
sl@0
|
136 |
|
sl@0
|
137 |
CleanupStack::PopAndDestroy(taskData);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
void CSSA_ScheduleStepBase::AddTransientScheduleL(const TDesC& aName,
|
sl@0
|
141 |
const TTsTime& aDueTime,
|
sl@0
|
142 |
TSchedulerItemRef& aRef)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
|
sl@0
|
145 |
CleanupStack::PushL(entryList);
|
sl@0
|
146 |
|
sl@0
|
147 |
TScheduleEntryInfo2 entry (aDueTime, EDaily, 1, 30);
|
sl@0
|
148 |
entryList->AppendL(entry);
|
sl@0
|
149 |
|
sl@0
|
150 |
// Associate a task with the time-based schedule
|
sl@0
|
151 |
TTaskInfo taskInfo;
|
sl@0
|
152 |
taskInfo.iName = aName;
|
sl@0
|
153 |
taskInfo.iPriority = 2;
|
sl@0
|
154 |
taskInfo.iRepeat = 0;
|
sl@0
|
155 |
// Create some data associated with this task
|
sl@0
|
156 |
HBufC* taskData = KTaskData().AllocLC();
|
sl@0
|
157 |
|
sl@0
|
158 |
User::LeaveIfError(iScheduler.ScheduleTask(taskInfo, *taskData, aRef, *entryList));
|
sl@0
|
159 |
|
sl@0
|
160 |
CleanupStack::PopAndDestroy(taskData);
|
sl@0
|
161 |
CleanupStack::PopAndDestroy(entryList);
|
sl@0
|
162 |
|
sl@0
|
163 |
// Disable the schedule as persistent and condition-base do that.
|
sl@0
|
164 |
User::LeaveIfError(iScheduler.DisableSchedule(aRef.iHandle));
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
void CSSA_ScheduleStepBase::AddConditionScheduleL(const TDesC& aName,
|
sl@0
|
168 |
const TTsTime& aDefaultRunTime,
|
sl@0
|
169 |
TSchedulerItemRef& aRef,
|
sl@0
|
170 |
TInt aKeyId,
|
sl@0
|
171 |
TBool aUseTransient)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
CreatePSKeyL(aKeyId);
|
sl@0
|
174 |
|
sl@0
|
175 |
CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
|
sl@0
|
176 |
CleanupStack::PushL(conditionList);
|
sl@0
|
177 |
TTaskSchedulerCondition condition1;
|
sl@0
|
178 |
condition1.iCategory = KTestUid;
|
sl@0
|
179 |
condition1.iKey = aKeyId;
|
sl@0
|
180 |
condition1.iState = KKeyValue;
|
sl@0
|
181 |
condition1.iType = TTaskSchedulerCondition::EEquals;
|
sl@0
|
182 |
conditionList->AppendL(condition1);
|
sl@0
|
183 |
|
sl@0
|
184 |
// Associate a task with the condition-based schedule
|
sl@0
|
185 |
TTaskInfo taskInfo;
|
sl@0
|
186 |
taskInfo.iName = aName;
|
sl@0
|
187 |
taskInfo.iPriority = 2;
|
sl@0
|
188 |
taskInfo.iRepeat = 0;
|
sl@0
|
189 |
// Create some data associated with this task
|
sl@0
|
190 |
HBufC* taskData = KTaskData().AllocLC();
|
sl@0
|
191 |
|
sl@0
|
192 |
TInt ret;
|
sl@0
|
193 |
if (!aUseTransient)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
// want persistent condition schedule
|
sl@0
|
196 |
ret = iScheduler.CreatePersistentSchedule(aRef, *conditionList, aDefaultRunTime);
|
sl@0
|
197 |
TESTL(ret==KErrNone);
|
sl@0
|
198 |
|
sl@0
|
199 |
User::LeaveIfError(iScheduler.DisableSchedule(aRef.iHandle));
|
sl@0
|
200 |
User::LeaveIfError(iScheduler.ScheduleTask(taskInfo, *taskData, aRef.iHandle));
|
sl@0
|
201 |
}
|
sl@0
|
202 |
else
|
sl@0
|
203 |
{
|
sl@0
|
204 |
// doing transient condition schedule
|
sl@0
|
205 |
User::LeaveIfError(iScheduler.ScheduleTask(taskInfo, *taskData, aRef, *conditionList, aDefaultRunTime));
|
sl@0
|
206 |
User::LeaveIfError(iScheduler.DisableSchedule(aRef.iHandle));
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
CleanupStack::PopAndDestroy(taskData);
|
sl@0
|
210 |
CleanupStack::PopAndDestroy(conditionList);
|
sl@0
|
211 |
}
|
sl@0
|
212 |
|
sl@0
|
213 |
void CSSA_ScheduleStepBase::CreatePSKeyL(TInt aKeyId)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
// create P&S variables for condition based tests
|
sl@0
|
216 |
TInt ret = RProperty::Define(KTestUid, aKeyId, RProperty::EInt);
|
sl@0
|
217 |
if (ret != KErrNone && ret != KErrAlreadyExists)
|
sl@0
|
218 |
{
|
sl@0
|
219 |
User::Leave(ret);
|
sl@0
|
220 |
}
|
sl@0
|
221 |
User::LeaveIfError(RProperty::Set(KTestUid, aKeyId, 0));
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
void CSSA_ScheduleStepBase::BeginTestSetupL()
|
sl@0
|
225 |
{
|
sl@0
|
226 |
|
sl@0
|
227 |
TInt ret(KErrTimedOut);
|
sl@0
|
228 |
TInt i;
|
sl@0
|
229 |
for (i = 0; (ret == KErrTimedOut) && (i < 3); i++)
|
sl@0
|
230 |
{
|
sl@0
|
231 |
ret = RequestDomainStateTransition(EStartupStateCriticalDynamic);
|
sl@0
|
232 |
if (ret == KErrTimedOut)
|
sl@0
|
233 |
{
|
sl@0
|
234 |
User::AfterHighRes(100000); // a tenth of a second
|
sl@0
|
235 |
}
|
sl@0
|
236 |
}
|
sl@0
|
237 |
|
sl@0
|
238 |
TESTL (ret==KErrNone);
|
sl@0
|
239 |
RestartSchedulerL();
|
sl@0
|
240 |
|
sl@0
|
241 |
// Set the time to a known value
|
sl@0
|
242 |
SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
|
sl@0
|
243 |
}
|