|
1 // Copyright (c) 2007-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // @internalComponent |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32std_private.h> |
|
21 #include <u32std.h> // unicode builds |
|
22 #include <e32base.h> |
|
23 #include <e32base_private.h> |
|
24 #include <e32cons.h> |
|
25 #include <e32Test.h> // RTest headder |
|
26 #include "testcaseroot.h" |
|
27 #include "testcasewd.h" |
|
28 #include "testcasefactory.h" |
|
29 #include "exampletestcase.h" |
|
30 |
|
31 |
|
32 |
|
33 // the name below is used to add a pointer to our construction method to a pointer MAP in |
|
34 // the class factory |
|
35 _LIT(KTestCaseId,"EXAMPLETESTCASE"); |
|
36 |
|
37 // UNcomment the next line to add the test to the catalog(factory) |
|
38 const TTestCaseFactoryReceipt<CExampleTestCase> CExampleTestCase::iFactoryReceipt(KTestCaseId); |
|
39 |
|
40 CExampleTestCase* CExampleTestCase::NewL(TBool aHost) |
|
41 { |
|
42 LOG_FUNC |
|
43 CExampleTestCase* self = new (ELeave) CExampleTestCase(aHost); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 |
|
51 CExampleTestCase::CExampleTestCase(TBool aHost) |
|
52 : CTestCaseRoot(KTestCaseId, aHost) |
|
53 { |
|
54 LOG_FUNC |
|
55 } |
|
56 |
|
57 |
|
58 void CExampleTestCase::ConstructL() |
|
59 { |
|
60 LOG_FUNC |
|
61 BaseConstructL(); |
|
62 iWDTimer = CTestCaseWatchdog::NewL(); |
|
63 } |
|
64 |
|
65 |
|
66 CExampleTestCase::~CExampleTestCase() |
|
67 { |
|
68 LOG_FUNC |
|
69 |
|
70 delete iWDTimer; |
|
71 Cancel(); |
|
72 } |
|
73 |
|
74 |
|
75 void CExampleTestCase::ExecuteTestCaseL() |
|
76 { |
|
77 LOG_FUNC |
|
78 iCaseStep = EFirstStep; |
|
79 |
|
80 // |
|
81 CActiveScheduler::Add(this); |
|
82 // run our root RunL() |
|
83 SelfComplete(); |
|
84 |
|
85 } |
|
86 |
|
87 void CExampleTestCase::DescribePreconditions() |
|
88 { |
|
89 test.Printf(_L("This is an example test, there is nothing to do beforehand.\n")); |
|
90 } |
|
91 |
|
92 void CExampleTestCase::DoCancel() |
|
93 { |
|
94 LOG_FUNC |
|
95 |
|
96 } |
|
97 |
|
98 |
|
99 void CExampleTestCase::ProcessKey(TKeyCode &aKey) |
|
100 { // the default implementation does this already, but we will store the key here again anyway |
|
101 iKeyCodeInput = aKey; |
|
102 |
|
103 } |
|
104 |
|
105 void CExampleTestCase::FuncA(CTestCaseRoot *pThis) |
|
106 { |
|
107 CExampleTestCase * p = REINTERPRET_CAST(CExampleTestCase *,pThis); |
|
108 // cancel any pending call, and then complete our active obj with a timeout value |
|
109 test.Printf(_L("@@@ FuncA cancel a keyboard Read() @@@\n")); |
|
110 |
|
111 p->iConsole->ReadCancel(); |
|
112 |
|
113 } |
|
114 |
|
115 void CExampleTestCase::FuncB(CTestCaseRoot *pThis) |
|
116 { |
|
117 CExampleTestCase * p = REINTERPRET_CAST(CExampleTestCase *,pThis); |
|
118 // cancel any pending call, and then complete our active obj with a timeout value |
|
119 test.Printf(_L("@@@ FuncB cancel a 'B' keyboard Read() @@@\n")); |
|
120 |
|
121 p->Cancel(); |
|
122 p->iConsole->ReadCancel(); |
|
123 |
|
124 TRequestStatus* s = &p->iStatus; |
|
125 p->iStatus = KRequestPending; |
|
126 |
|
127 p->SetActive(); |
|
128 User::RequestComplete(s, KTestCaseWatchdogTO); |
|
129 |
|
130 } |
|
131 |
|
132 |
|
133 // handle event completion |
|
134 void CExampleTestCase::RunStepL() |
|
135 { |
|
136 LOG_FUNC |
|
137 |
|
138 // Obtain the completion code for this CActive obj. |
|
139 TInt completionCode(iStatus.Int()); |
|
140 RDebug::Printf("Example test iStatus compl.=%d\n", completionCode); |
|
141 //test.Printf(_L("Example test iStatus compl.=%d\n"), completionCode); |
|
142 |
|
143 switch(iCaseStep) |
|
144 { |
|
145 case EFirstStep: |
|
146 iCaseStep=ESecondStep; |
|
147 test.Printf(_L("Test step 1\n")); |
|
148 |
|
149 SelfComplete(); |
|
150 break; |
|
151 case ESecondStep: |
|
152 iCaseStep=EThirdStep; |
|
153 test.Printf(_L("Test step 2\n")); |
|
154 test.Printf(_L("(this test step uses Keyboard)\n")); |
|
155 test.Printf(_L("Press ANY key once you have removed the 'A' connector...\n")); |
|
156 RequestCharacter(); |
|
157 iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &FuncA); |
|
158 break; |
|
159 case EThirdStep: |
|
160 test.Printf(_L("key was a '%c'\n"), iKeyCodeInput); |
|
161 iWDTimer->Cancel(); |
|
162 iCaseStep=EFourthStep; |
|
163 test.Printf(_L("Test step 3\n")); |
|
164 test.Printf(_L("(this test step uses Keyboard)\n")); |
|
165 test.Printf(_L("Press <SPACE> key once you have removed the 'A' connector...\n")); |
|
166 RequestCharacter(); |
|
167 iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &FuncB); |
|
168 |
|
169 break; |
|
170 case EFourthStep: |
|
171 test.Printf(_L("key was a '%c'\n"), iKeyCodeInput); |
|
172 test.Printf(_L("Test step 4\n")); |
|
173 iWDTimer->Cancel(); |
|
174 |
|
175 iCaseStep=EFifthStep; |
|
176 if (' ' != iKeyCodeInput) |
|
177 { |
|
178 |
|
179 iCaseStep=EThirdStep; |
|
180 } |
|
181 SelfComplete(); |
|
182 break; |
|
183 case EFifthStep: |
|
184 iCaseStep=ESixthStep; |
|
185 test.Printf(_L("Test step 5\n")); |
|
186 test.Printf(_L("(this test uses a delay)\n")); |
|
187 iTimer.After(iStatus, 500000); |
|
188 SetActive(); |
|
189 break; |
|
190 case ESixthStep: |
|
191 iCaseStep=ELastStep; |
|
192 test.Printf(_L("Test step 6(%d)\n"), completionCode); |
|
193 RequestCharacter(); |
|
194 iConsole->ReadCancel(); |
|
195 Cancel(); |
|
196 RequestCharacter(); |
|
197 |
|
198 //SelfComplete(); |
|
199 break; |
|
200 case ELastStep: |
|
201 iCaseStep=ESecondStep; |
|
202 test.Printf(_L("LAST step7 code (%d)\n"), completionCode); |
|
203 TestPolicy().SignalTestComplete(KErrNone); |
|
204 return TestPassed(); |
|
205 //break; |
|
206 |
|
207 default: |
|
208 //test.Printf(_L("<Error> unknown test step")); |
|
209 Cancel(); |
|
210 TestFailed(KErrCorrupt, _L("unknown test step")); |
|
211 break; |
|
212 } |
|
213 |
|
214 } |
|
215 |
|
216 |