First public contribution.
1 // Copyright (c) 1995-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\system\t_inact.cpp
15 // Test inactivity timers
21 RTest test(_L("T_INACT"));
23 class CTimer1 : public CTimer
26 static CTimer1* NewL();
32 class CTimer2 : public CTimer
35 static CTimer2* NewL();
41 class CTimer3 : public CTimer
44 static CTimer3* NewL();
52 class CRepeatedTimer : public CTimer
55 static CRepeatedTimer* NewL(TInt aCount, TInt aPeriod);
64 CActiveScheduler* ActiveSched;
68 CRepeatedTimer* RepTimer;
71 : CTimer(EPriorityStandard)
75 CTimer1* CTimer1::NewL()
77 CTimer1* pT=new (ELeave) CTimer1;
78 CleanupStack::PushL(pT);
91 test.Printf(_L("CTimer1 expired\n"));
96 : CTimer(EPriorityStandard)
100 CTimer2* CTimer2::NewL()
102 CTimer2* pT=new (ELeave) CTimer2;
103 CleanupStack::PushL(pT);
109 void CTimer2::Start()
116 test.Printf(_L("CTimer2 expired\n"));
121 : CTimer(EPriorityStandard)
125 CTimer3* CTimer3::NewL()
127 CTimer3* pT=new (ELeave) CTimer3;
128 CleanupStack::PushL(pT);
134 void CTimer3::Start()
136 iInactive=User::InactivityTime().Int();
142 TInt inactive=User::InactivityTime().Int();
143 if (inactive!=iInactive)
146 test.Printf(_L("%d\n"),inactive);
151 CRepeatedTimer::CRepeatedTimer()
152 : CTimer(EPriorityStandard)
156 CRepeatedTimer* CRepeatedTimer::NewL(TInt aCount, TInt aPeriod)
158 CRepeatedTimer* pT=new (ELeave) CRepeatedTimer;
161 CleanupStack::PushL(pT);
167 void CRepeatedTimer::Start()
172 void CRepeatedTimer::RunL()
174 test.Printf(_L("RepeatTimer expired %d\n"),iCount);
178 CActiveScheduler::Stop();
183 ActiveSched=new (ELeave) CActiveScheduler;
184 Timer1=CTimer1::NewL();
185 Timer2=CTimer2::NewL();
186 Timer3=CTimer3::NewL();
187 RepTimer=CRepeatedTimer::NewL(5,10);
188 CActiveScheduler::Install(ActiveSched);
189 CActiveScheduler::Add(Timer1);
190 CActiveScheduler::Add(Timer2);
191 CActiveScheduler::Add(Timer3);
192 CActiveScheduler::Add(RepTimer);
199 void TestNonPositiveTimeout()
202 TRequestStatus x1,x2;
205 test.Next(_L("Test RTimer::Inactivity() with zero timeout"));
206 ret=rt1.CreateLocal();
207 ret=rt2.CreateLocal();
209 rt1.Inactivity(x1, 2);
211 rt2.Inactivity(x2, 0);
212 User::ResetInactivityTime();
214 User::WaitForRequest(x1);
216 User::WaitForRequest(x2);
219 test.Next(_L("Test RTimer::Inactivity() with negative timeout"));
220 rt1.Inactivity(x1, -1);
221 User::WaitForRequest(x1);
222 test(x1==KErrArgument);
225 GLDEF_C TInt E32Main()
229 test.Start(_L("Test RTimer::Inactivity"));
231 TestNonPositiveTimeout();
235 TInt r=t1.CreateLocal();
239 test.Printf(_L("\nPress a key...\n"));
244 before.UniversalTime();
245 test.Printf(_L("Wait... "));
246 User::WaitForRequest(s);
248 after.UniversalTime();
249 TTimeIntervalMicroSeconds interval=after.MicroSecondsFrom(before);
250 TInt interval_int=I64INT(interval.Int64());
251 test.Printf(_L("Timer expired after %d us\n"),interval_int);
252 test.Printf(_L("Press a key...\n"));
255 before.UniversalTime();
256 test.Printf(_L("Test changing time"));
257 r=User::SetUTCTime(before+TTimeIntervalDays(1));
259 test(s==KRequestPending); // make sure time change doesn't trigger inactivity timers
260 r=User::SetUTCTime(before-TTimeIntervalDays(1));
262 test(s==KRequestPending); // make sure time change doesn't trigger inactivity timers
263 r=User::SetUTCTime(before);
265 test(s==KRequestPending); // make sure time change doesn't trigger inactivity timers
268 if ((r = secure.UniversalTimeSecure()) == KErrNone)
269 r = User::SetUTCTimeSecure(secure-TTimeIntervalDays(1));
272 RDebug::Printf("WARNING: Secure clock change test skipped because secure time could not be changed!");
276 User::SetUTCTimeSecure(secure+TTimeIntervalDays(1));
277 User::SetUTCTimeSecure(secure);
278 test(s == KRequestPending); // make sure secure time change doesn't trigger inactivity timers
281 User::WaitForRequest(s);
282 after.UniversalTime();
283 interval=after.MicroSecondsFrom(before);
284 interval_int=I64INT(interval.Int64());
285 test.Printf(_L("Timer expired after %d us\n"),interval_int);
286 test.Printf(_L("Press a key...\n"));
289 TInt inactive=User::InactivityTime().Int();
292 t1.Inactivity(s1, 10);
293 t2.Inactivity(s2, 15);
296 TInt new_inact=User::InactivityTime().Int();
297 if (new_inact!=inactive)
300 test.Printf(_L("%d\n"),inactive);
302 if (s2!=KRequestPending)
304 User::WaitForRequest(s2);
305 test(s2.Int()==KErrNone);
306 test.Printf(_L("Timer 2 expired\n"));
309 if (s1!=KRequestPending)
311 User::WaitForRequest(s1);
312 test(s1.Int()==KErrNone);
313 test.Printf(_L("Timer 1 expired\n"));
318 test.Next(_L("Test RTimer::Cancel()"));
319 test.Printf(_L("Press a key...\n"));
321 t1.Inactivity(s1, 300);
323 User::WaitForRequest(s1);
324 test(s1==KErrCancel);
326 test.Next(_L("Test CTimer::Inactivity()"));
327 test.Printf(_L("Press a key...\n"));
330 CTrapCleanup* pC=CTrapCleanup::New();
332 TRAP(r,InitialiseL());
335 CActiveScheduler::Start();
349 test.Printf(_L("Press a key...\n"));