|
1 // Copyright (c) 1998-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 "EmailTestUtils.h" |
|
17 #include "miutlog.h" |
|
18 #include <txtrich.h> |
|
19 #include <c32comm.h> |
|
20 |
|
21 // local variables etc // |
|
22 |
|
23 _LIT(KImcmTest, "T_IMCM04 - Testing MTM::InvokeAsyncFunctionL()"); |
|
24 RTest test(KImcmTest); |
|
25 |
|
26 LOCAL_D TMsvId imap4Service; |
|
27 LOCAL_D TMsvId smtpService; |
|
28 LOCAL_D TMsvId pop3Service; |
|
29 |
|
30 LOCAL_D CTrapCleanup* theCleanup; |
|
31 LOCAL_D CImLog* log; |
|
32 LOCAL_D CEmailTestUtils* testUtils; |
|
33 |
|
34 LOCAL_D CMsvOperation* msvOperation; |
|
35 LOCAL_D CMsvEntrySelection* msvSelection; |
|
36 LOCAL_D CConsoleBase* console; |
|
37 |
|
38 class COperationActive; |
|
39 LOCAL_D COperationActive* opActive; |
|
40 |
|
41 // |
|
42 class TestUiTimer : public CTimer |
|
43 { |
|
44 public: |
|
45 static TestUiTimer* NewLC(CConsoleBase* aConsole); |
|
46 ~TestUiTimer(); |
|
47 |
|
48 void RunL(); |
|
49 void DoCancel(); |
|
50 void ConstructL(); |
|
51 void IssueRequest(); |
|
52 void SetOperation(CMsvOperation* aOperation); |
|
53 TTimeIntervalMicroSeconds32 period; |
|
54 protected: |
|
55 TestUiTimer(CConsoleBase* aConsole); |
|
56 |
|
57 CConsoleBase* iConsole; |
|
58 CMsvOperation* iOperation; |
|
59 }; |
|
60 |
|
61 // |
|
62 TestUiTimer* TestUiTimer::NewLC(CConsoleBase* aConsole) |
|
63 { |
|
64 TestUiTimer* self = new(ELeave) TestUiTimer(aConsole); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL(); |
|
67 return self; |
|
68 } |
|
69 |
|
70 TestUiTimer::TestUiTimer(CConsoleBase* aConsole) |
|
71 : CTimer(1) |
|
72 { |
|
73 iConsole = aConsole; |
|
74 period = 10000; |
|
75 } |
|
76 |
|
77 TestUiTimer::~TestUiTimer() |
|
78 { |
|
79 delete iOperation; |
|
80 } |
|
81 |
|
82 void TestUiTimer::ConstructL() |
|
83 { |
|
84 CTimer::ConstructL(); |
|
85 CActiveScheduler::Add(this); |
|
86 } |
|
87 |
|
88 void TestUiTimer::IssueRequest() |
|
89 { |
|
90 After(period); |
|
91 } |
|
92 |
|
93 void TestUiTimer::SetOperation(CMsvOperation* aOperation) |
|
94 { |
|
95 if(iOperation) |
|
96 { |
|
97 delete iOperation; |
|
98 iOperation=NULL; |
|
99 } |
|
100 iOperation = aOperation; |
|
101 } |
|
102 |
|
103 void TestUiTimer::DoCancel() |
|
104 { |
|
105 CTimer::DoCancel(); |
|
106 } |
|
107 |
|
108 void TestUiTimer::RunL() |
|
109 { |
|
110 IssueRequest(); |
|
111 }; |
|
112 |
|
113 // |
|
114 |
|
115 class COperationActive : public CActive |
|
116 { |
|
117 public: |
|
118 COperationActive(); |
|
119 ~COperationActive(); |
|
120 static COperationActive* NewL(); |
|
121 void StartL(); |
|
122 void SetOperation(CMsvOperation*); |
|
123 |
|
124 protected: |
|
125 void DoCancel(); |
|
126 void RunL(); |
|
127 |
|
128 TestUiTimer* iTimer; |
|
129 }; |
|
130 |
|
131 // |
|
132 COperationActive::COperationActive() |
|
133 : CActive(0) |
|
134 { |
|
135 } |
|
136 |
|
137 COperationActive::~COperationActive() |
|
138 { |
|
139 Cancel(); |
|
140 delete iTimer; |
|
141 } |
|
142 |
|
143 COperationActive* COperationActive::NewL() |
|
144 { |
|
145 COperationActive* self = new (ELeave) COperationActive; |
|
146 CActiveScheduler::Add(self); |
|
147 |
|
148 self->iSetActive = ETrue; |
|
149 self->iTimer = TestUiTimer::NewLC(test.Console()); |
|
150 CleanupStack::Pop(); |
|
151 return self; |
|
152 } |
|
153 |
|
154 void COperationActive::DoCancel() |
|
155 { |
|
156 } |
|
157 |
|
158 void COperationActive::StartL() |
|
159 { |
|
160 iTimer->IssueRequest(); // Start the connect observation timer |
|
161 |
|
162 SetActive(); |
|
163 test.Console()->SetPos(0, 17); |
|
164 test.Printf(TRefByValue<const TDesC>_L("Operation TRequestStatus %d"), iStatus); |
|
165 } |
|
166 |
|
167 void COperationActive::SetOperation(CMsvOperation *aOperation) |
|
168 { |
|
169 iTimer->SetOperation(aOperation); |
|
170 } |
|
171 |
|
172 void COperationActive::RunL() |
|
173 { |
|
174 iTimer->Cancel(); |
|
175 test.Console()->SetPos(25, 17); |
|
176 test.Printf(_L(" ")); |
|
177 test.Console()->SetPos(0, 17); |
|
178 test.Printf(TRefByValue<const TDesC>_L("Operation TRequestStatus %d"), iStatus); |
|
179 CActiveScheduler::Stop(); |
|
180 } |
|
181 |
|
182 // |
|
183 |
|
184 LOCAL_C void CreateNewPlaintextMessageViaPop3MtmL() |
|
185 { |
|
186 log->AppendComment(_L8("Create new plaintext msg via POP3 MTM")); |
|
187 |
|
188 TMsvPartList partList = (KMsvMessagePartBody | KMsvMessagePartAttachments); |
|
189 TMsvEmailTypeList msvEmailTypeList = 0; |
|
190 |
|
191 TImCreateMessageOptions msgOptions; |
|
192 msgOptions.iMessageType = KUidMsgTypeSMTP; |
|
193 msgOptions.iMsvPartList = partList; |
|
194 msgOptions.iMsvEmailTypeList = msvEmailTypeList; |
|
195 TPckgBuf<TImCreateMessageOptions> options(msgOptions); |
|
196 |
|
197 msvSelection->ResizeL(0); |
|
198 msvSelection->AppendL(KMsvGlobalOutBoxIndexEntryId); // destination folder is Global Outbox |
|
199 |
|
200 opActive->iStatus = KRequestPending; |
|
201 msvOperation = testUtils->iPopClientMtm->InvokeAsyncFunctionL(KPOP3MTMCreateNewEmailMessage, *msvSelection, options, opActive->iStatus); |
|
202 opActive->SetOperation(msvOperation); |
|
203 opActive->StartL(); // Start the active object |
|
204 } |
|
205 |
|
206 // |
|
207 |
|
208 LOCAL_C void InitL() |
|
209 { |
|
210 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
211 CActiveScheduler::Install(scheduler); |
|
212 CleanupStack::PushL(scheduler); |
|
213 |
|
214 testUtils = CEmailTestUtils::NewLC(test); |
|
215 console = test.Console(); |
|
216 testUtils->FileSession().SetSessionPath(_L("C:\\")); |
|
217 testUtils->CleanMessageFolderL(); |
|
218 testUtils->GoServerSideL(); |
|
219 |
|
220 // Create Services |
|
221 smtpService = testUtils->CreateSmtpServiceL(); |
|
222 pop3Service = testUtils->CreatePopServiceL(); |
|
223 imap4Service = testUtils->CreateImapServiceL(); |
|
224 |
|
225 log = CImLog::NewL(_L("c:\\logs\\email\\T_IMCM.log"), EAppend); |
|
226 CleanupStack::PushL(log); |
|
227 log->AppendComment(_L8("**** T_IMCM04 - Testing MTM::InvokeAsyncFunctionL() ****")); |
|
228 TBuf8<80> buf; |
|
229 #if defined(__WINS__) |
|
230 buf.Append(_L8("WINS ")); |
|
231 #else |
|
232 buf.Append(_L8("MARM ")); |
|
233 #endif |
|
234 #if defined(_UNICODE) |
|
235 buf.Append(_L8("U")); |
|
236 #endif |
|
237 #if defined(_DEBUG) |
|
238 buf.Append(_L8("DEB")); |
|
239 #else |
|
240 buf.Append(_L8("REL")); |
|
241 #endif |
|
242 log->AppendComment(buf); |
|
243 } |
|
244 |
|
245 LOCAL_C void Closedown() |
|
246 { |
|
247 log->AppendComment(_L8("********** T_IMCM04 Tests Complete **********")); |
|
248 log->AppendComment(_L8("")); |
|
249 |
|
250 CleanupStack::PopAndDestroy(3); //testUtils, log, scheduler |
|
251 } |
|
252 |
|
253 // |
|
254 |
|
255 LOCAL_C void doMainL() |
|
256 { |
|
257 InitL(); |
|
258 testUtils->FileSession().SetSessionPath(_L("c:\\")); |
|
259 |
|
260 // Instantiate the POP3 Client MTM |
|
261 testUtils->GoClientSideL(); |
|
262 testUtils->InstantiatePopClientMtmL(); |
|
263 msvSelection = new (ELeave) CMsvEntrySelection; |
|
264 CleanupStack::PushL(msvSelection); |
|
265 |
|
266 opActive = COperationActive::NewL(); |
|
267 CleanupStack::PushL(opActive); |
|
268 console->SetPos(0, 7); |
|
269 test.Printf(_L("Creating new plaintext message via POP3 MTM \n")); |
|
270 CreateNewPlaintextMessageViaPop3MtmL(); |
|
271 CActiveScheduler::Start(); |
|
272 testUtils->FindChildrenL(KMsvRootIndexEntryId, EFalse); |
|
273 |
|
274 CleanupStack::PopAndDestroy(); //opActive |
|
275 CleanupStack::PopAndDestroy(); //msvSelection |
|
276 testUtils->Reset(); |
|
277 Closedown(); |
|
278 } |
|
279 |
|
280 GLDEF_C TInt E32Main() |
|
281 { |
|
282 __UHEAP_MARK; |
|
283 test.Start(_L("T_IMCM04 - Testing MTM::InvokeAsyncFunctionL()")); |
|
284 theCleanup=CTrapCleanup::New(); |
|
285 TRAPD(ret,doMainL()); |
|
286 test(ret==KErrNone); |
|
287 delete theCleanup; |
|
288 test.End(); |
|
289 test.Close(); |
|
290 __UHEAP_MARKEND; |
|
291 User::Heap().Check(); |
|
292 return(KErrNone); |
|
293 } |