|
1 // Copyright (c) 1999-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 // |
|
15 |
|
16 #include "emailsmoke.h" |
|
17 #include "testframeutils.h" |
|
18 #include "emailsmokeparse.h" |
|
19 #include "emailsmokecommands.h" |
|
20 #include "emailtestutils.h" |
|
21 |
|
22 |
|
23 // |
|
24 // |
|
25 // CBaseTestHarness |
|
26 // |
|
27 |
|
28 CBaseTestHarness::~CBaseTestHarness() |
|
29 { |
|
30 iStateList->ResetAndDestroy(); |
|
31 delete iStateList; |
|
32 } |
|
33 |
|
34 void CBaseTestHarness::StartL(TRequestStatus& aStatus) |
|
35 { |
|
36 TTestDebugInfo debugInfo = GetDebugInfo(); |
|
37 HBufC* startString = debugInfo.TestStartStringLC(); |
|
38 LogComment(*startString); |
|
39 TestConsole().Printf(*startString); |
|
40 TestConsole().Printf(_L("\n")); |
|
41 |
|
42 CleanupStack::PopAndDestroy(startString); |
|
43 iCurrentState = 0; |
|
44 iReportStatus = &aStatus; |
|
45 |
|
46 if (iCurrentState < iStateList->Count()) |
|
47 { |
|
48 TTestDebugInfo moreInfo=(*iStateList)[iCurrentState]->GetDebugInfo(); |
|
49 HBufC* debugString=moreInfo.TestStartStringLC(); |
|
50 TestConsole().Printf(*debugString); |
|
51 TestConsole().Printf(_L("\r")); |
|
52 CleanupStack::PopAndDestroy(debugString); |
|
53 |
|
54 (*iStateList)[iCurrentState]->StartL(iStatus); |
|
55 } |
|
56 |
|
57 aStatus = KRequestPending; |
|
58 SetActive(); |
|
59 } |
|
60 |
|
61 |
|
62 void CBaseTestHarness::AddStateL(MBaseTestState* aTestState, TTestDebugInfo aDebugInfo) |
|
63 { |
|
64 aTestState->SetDebugInfo(aDebugInfo); |
|
65 TRAPD(err, iStateList->AppendL(aTestState)); |
|
66 if (err != KErrNone) |
|
67 // If the state can't be added then delete it. |
|
68 // We do this because we have taken ownership of the state. |
|
69 { |
|
70 delete aTestState; |
|
71 User::Leave(err); |
|
72 } |
|
73 } |
|
74 |
|
75 |
|
76 // From CActive |
|
77 void CBaseTestHarness::RunL() |
|
78 { |
|
79 if (iStatus == KErrNone) |
|
80 { |
|
81 if (++iCurrentState < iStateList->Count()) |
|
82 { |
|
83 TTestDebugInfo moreInfo=(*iStateList)[iCurrentState]->GetDebugInfo(); |
|
84 HBufC* debugString=moreInfo.TestCompleteStringLC(); |
|
85 TestConsole().Printf(*debugString); |
|
86 TestConsole().Printf(_L("\r")); |
|
87 CleanupStack::PopAndDestroy(debugString); |
|
88 |
|
89 (*iStateList)[iCurrentState]->StartL(iStatus); |
|
90 SetActive(); |
|
91 } |
|
92 else |
|
93 { |
|
94 TTestDebugInfo debugInfo = GetDebugInfo(); |
|
95 HBufC* testCompleted = debugInfo.TestCompleteStringLC(); |
|
96 LogComment(*testCompleted); |
|
97 |
|
98 CleanupStack::PopAndDestroy(testCompleted); |
|
99 User::RequestComplete(iReportStatus, iStatus.Int()); |
|
100 } |
|
101 } |
|
102 else |
|
103 { |
|
104 // Pass the debug info back from the child state and log the error |
|
105 TTestDebugInfo debugInfo = (*iStateList)[iCurrentState]->GetDebugInfo(); |
|
106 SetDebugInfo(debugInfo); |
|
107 HBufC* errorText = debugInfo.TestFailedStringLC(iStatus.Int()); |
|
108 LogComment(*errorText); |
|
109 TestConsole().Printf(*errorText); |
|
110 TestConsole().Printf(_L("\r")); |
|
111 |
|
112 CleanupStack::PopAndDestroy(errorText); |
|
113 User::RequestComplete(iReportStatus, iStatus.Int()); |
|
114 } |
|
115 } |
|
116 |
|
117 void CBaseTestHarness::DoCancel() |
|
118 { |
|
119 } |
|
120 |
|
121 void CBaseTestHarness::LogComment(const TDesC& /* aError */) |
|
122 { |
|
123 } |
|
124 |
|
125 |
|
126 TInt CBaseTestHarness::RunError(TInt aError) |
|
127 { |
|
128 // Pass the debug info back from the child state and log the error |
|
129 TTestDebugInfo debugInfo = (*iStateList)[iCurrentState]->GetDebugInfo(); |
|
130 SetDebugInfo(debugInfo); |
|
131 HBufC* errorText=NULL; |
|
132 TRAPD(ret,errorText= debugInfo.TestFailedStringLC(aError)); |
|
133 if (ret!=KErrNone) |
|
134 return ret; |
|
135 TRAP(ret,LogComment(*errorText)); //LogComentL doesn't leave although it has L. |
|
136 TestConsole().Printf(*errorText); |
|
137 TestConsole().Printf(_L("\r")); |
|
138 |
|
139 CleanupStack::PopAndDestroy(errorText); |
|
140 User::RequestComplete(iReportStatus, aError); |
|
141 return KErrNone; |
|
142 } |
|
143 |
|
144 void CBaseTestHarness::ConstructL() |
|
145 { |
|
146 CActiveScheduler::Add(this); |
|
147 iStateList = new (ELeave) CArrayPtrFlat<MBaseTestState>(10); |
|
148 } |
|
149 |
|
150 CBaseTestHarness::CBaseTestHarness(RTest& aTest) : CActive(EPriorityHigh), iTest(aTest) |
|
151 { |
|
152 } |
|
153 |
|
154 RTest& CBaseTestHarness::TestConsole() |
|
155 { |
|
156 return iTest; |
|
157 } |
|
158 |
|
159 // |
|
160 // |
|
161 // CMainTestHarness |
|
162 // |
|
163 |
|
164 CMainTestHarness* CMainTestHarness::NewL(RTest& aTest) |
|
165 { |
|
166 CMainTestHarness* self = new (ELeave) CMainTestHarness(aTest); |
|
167 CleanupStack::PushL(self); |
|
168 self->ConstructL(); |
|
169 CleanupStack::Pop(self); |
|
170 return self; |
|
171 } |
|
172 |
|
173 void CMainTestHarness::ConstructL() |
|
174 { |
|
175 CBaseTestHarness::ConstructL(); |
|
176 } |
|
177 |
|
178 CMainTestHarness::CMainTestHarness(RTest& aTest) : CBaseTestHarness(aTest) |
|
179 { |
|
180 } |
|
181 |
|
182 void CMainTestHarness::StartL(TRequestStatus& aStatus) |
|
183 { |
|
184 CBaseTestHarness::StartL(aStatus); |
|
185 } |
|
186 |
|
187 |
|
188 // |
|
189 // |
|
190 // CMsvClientTest |
|
191 // |
|
192 |
|
193 |
|
194 CMsvClientTest* CMsvClientTest::NewL(CEmailTestUtils& aTestUtils, RTest& aTest) |
|
195 { |
|
196 CMsvClientTest* self = new (ELeave) CMsvClientTest(aTestUtils, aTest); |
|
197 CleanupStack::PushL(self); |
|
198 self->ConstructL(); |
|
199 CleanupStack::Pop(self); |
|
200 return self; |
|
201 } |
|
202 |
|
203 CMsvClientTest* CMsvClientTest::NewL(CEmailTestUtils* aTestUtils, RTest& aTest) |
|
204 { |
|
205 CMsvClientTest* self = new (ELeave) CMsvClientTest(aTestUtils, aTest); |
|
206 CleanupStack::PushL(self); |
|
207 self->ConstructL(); |
|
208 CleanupStack::Pop(self); |
|
209 return self; |
|
210 } |
|
211 |
|
212 CMsvClientTest::~CMsvClientTest() |
|
213 { |
|
214 Cancel(); |
|
215 delete iCurrentSelection; |
|
216 delete iOperation; |
|
217 } |
|
218 |
|
219 void CMsvClientTest::DoCancel() |
|
220 { |
|
221 if (iOperation) |
|
222 { |
|
223 iOperation->Cancel(); |
|
224 } |
|
225 } |
|
226 |
|
227 void CMsvClientTest::SetCurrentOperation(CMsvOperation* aOperation) |
|
228 { |
|
229 delete iOperation; |
|
230 iOperation = aOperation; |
|
231 } |
|
232 |
|
233 |
|
234 CMsvOperation& CMsvClientTest::CurrentOperation() |
|
235 { |
|
236 return *iOperation; |
|
237 } |
|
238 |
|
239 void CMsvClientTest::ConstructL() |
|
240 { |
|
241 CBaseTestHarness::ConstructL(); |
|
242 iCurrentSelection = new (ELeave) CMsvEntrySelection; |
|
243 } |
|
244 |
|
245 CMsvClientTest::CMsvClientTest(CEmailTestUtils& aMsvTestUtils, RTest& aTest) |
|
246 : CBaseTestHarness(aTest), |
|
247 iMsvTestUtils(aMsvTestUtils) |
|
248 { |
|
249 iOperation = NULL; |
|
250 } |
|
251 |
|
252 CMsvClientTest::CMsvClientTest(CEmailTestUtils* aMsvTestUtils, RTest& aTest) |
|
253 : CBaseTestHarness(aTest), |
|
254 iMsvTestUtils(*aMsvTestUtils), |
|
255 iOwnedMsvTestUtils(aMsvTestUtils) |
|
256 { |
|
257 iOperation = NULL; |
|
258 } |
|
259 |
|
260 CEmailTestUtils& CMsvClientTest::MsvTestUtils() |
|
261 { |
|
262 return iMsvTestUtils; |
|
263 } |
|
264 |
|
265 |
|
266 // |
|
267 // |
|
268 // CEmailClientTest |
|
269 // |
|
270 |
|
271 CEmailClientTest* CEmailClientTest::NewL(CEmailTestUtils* aTestUtils, RTest& aTest) |
|
272 { |
|
273 CEmailClientTest* self = new (ELeave) CEmailClientTest(aTestUtils, aTest); |
|
274 CleanupStack::PushL(self); |
|
275 self->ConstructL(); |
|
276 CleanupStack::Pop(self); |
|
277 return self; |
|
278 } |
|
279 |
|
280 CEmailClientTest* CEmailClientTest::NewL(CEmailTestUtils& aTestUtils, RTest& aTest) |
|
281 { |
|
282 CEmailClientTest* self = new (ELeave) CEmailClientTest(aTestUtils, aTest); |
|
283 CleanupStack::PushL(self); |
|
284 self->ConstructL(); |
|
285 CleanupStack::Pop(self); |
|
286 return self; |
|
287 } |
|
288 |
|
289 CEmailClientTest::~CEmailClientTest() |
|
290 { |
|
291 delete iOwnedEmailTestUtils; |
|
292 } |
|
293 |
|
294 void CEmailClientTest::ConstructL() |
|
295 { |
|
296 CMsvClientTest::ConstructL(); |
|
297 } |
|
298 |
|
299 CEmailTestUtils& CEmailClientTest::EmailTestUtils() |
|
300 { |
|
301 return iEmailTestUtils; |
|
302 } |
|
303 |
|
304 CEmailClientTest::CEmailClientTest(CEmailTestUtils& aTestUtils, RTest& aTest) |
|
305 : CMsvClientTest(aTestUtils, aTest), |
|
306 iEmailTestUtils(aTestUtils) |
|
307 { |
|
308 } |
|
309 |
|
310 CEmailClientTest::CEmailClientTest(CEmailTestUtils* aTestUtils, RTest& aTest) |
|
311 : CMsvClientTest(*aTestUtils, aTest), |
|
312 iEmailTestUtils(*aTestUtils), |
|
313 iOwnedEmailTestUtils(aTestUtils) |
|
314 { |
|
315 } |
|
316 |
|
317 void CEmailClientTest::LogComment(const TDesC& aError) |
|
318 { |
|
319 iEmailTestUtils.WriteComment(aError); |
|
320 } |
|
321 |