|
1 /* |
|
2 * Copyright (c) 2003-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 "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "t_sleep.h" |
|
20 #include "t_input.h" |
|
21 #include "t_output.h" |
|
22 #include <e32base.h> |
|
23 |
|
24 ///////////////////////////////////////////////////////////////////////////////// |
|
25 // CSleep |
|
26 ///////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
28 _LIT8(KSecondsStart, "<seconds>"); |
|
29 |
|
30 CTestAction* CSleep::NewL(CConsoleBase& aConsole, |
|
31 Output& aOut, |
|
32 const TTestActionSpec& aTestActionSpec) |
|
33 { |
|
34 CTestAction* self = CSleep::NewLC(aConsole, aOut, aTestActionSpec); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 CTestAction* CSleep::NewLC(CConsoleBase& aConsole, |
|
40 Output& aOut, |
|
41 const TTestActionSpec& aTestActionSpec) |
|
42 { |
|
43 CSleep* self = new (ELeave) CSleep(aConsole, aOut); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(aTestActionSpec); |
|
46 return self; |
|
47 } |
|
48 |
|
49 CSleep::~CSleep() |
|
50 { |
|
51 iTimer.Close(); |
|
52 } |
|
53 |
|
54 CSleep::CSleep(CConsoleBase& aConsole, Output& aOut) : |
|
55 CTestAction(aConsole, aOut) |
|
56 { |
|
57 iState = ESleeping; |
|
58 } |
|
59 |
|
60 void CSleep::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
61 { |
|
62 CTestAction::ConstructL(aTestActionSpec); |
|
63 |
|
64 iExpectedResult = KErrNone; |
|
65 TLex8 lex(Input::ParseElement(aTestActionSpec.iActionBody, KSecondsStart)); |
|
66 lex.Val(iSeconds); |
|
67 User::LeaveIfError(iTimer.CreateLocal()); |
|
68 } |
|
69 |
|
70 void CSleep::PerformAction(TRequestStatus& aStatus) |
|
71 { |
|
72 switch (iState) |
|
73 { |
|
74 case ESleeping: |
|
75 { |
|
76 iState = EFinished; |
|
77 iTimer.After(aStatus, iSeconds*1000*1000); |
|
78 } |
|
79 break; |
|
80 case EFinished: |
|
81 { |
|
82 TRequestStatus* status = &aStatus; |
|
83 User::RequestComplete(status, aStatus.Int()); |
|
84 if (aStatus == iExpectedResult) |
|
85 { |
|
86 iResult = ETrue; |
|
87 } |
|
88 else |
|
89 { |
|
90 iResult = EFalse; |
|
91 } |
|
92 iFinished = ETrue; |
|
93 } |
|
94 } |
|
95 |
|
96 } |
|
97 |
|
98 void CSleep::PerformCancel() |
|
99 { |
|
100 if (iState == ESleeping) |
|
101 { |
|
102 iTimer.Cancel(); |
|
103 } |
|
104 } |
|
105 |
|
106 void CSleep::DoCheckResult(TInt aError) |
|
107 { |
|
108 if (iFinished) |
|
109 { |
|
110 if (aError == KErrNone) |
|
111 { |
|
112 iOut.write(_L("Slept well \n\n")); |
|
113 } |
|
114 else |
|
115 { |
|
116 iOut.write(_L("Troubled sleep... : %d\n\n"), aError); |
|
117 } |
|
118 } |
|
119 } |
|
120 |
|
121 void CSleep::DoReportAction() |
|
122 { |
|
123 iOut.write(_L("Sleeping for %d seconds...\n"), iSeconds); |
|
124 } |