|
1 // Copyright (c) 2004-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 "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This contains CTestMessSharedData |
|
15 // |
|
16 // |
|
17 |
|
18 #include "TestMessSharedData.h" |
|
19 |
|
20 #include <mtclbase.h> |
|
21 #include <msvids.h> |
|
22 #include <e32std.h> |
|
23 #include <imapcmds.h> |
|
24 |
|
25 _LIT(KName, "name"); |
|
26 |
|
27 CTestMessSharedData* CTestMessSharedData::NewL() |
|
28 /** |
|
29 * @return - Instance of the test server |
|
30 * Same code for Secure and non-secure variants |
|
31 * Called inside the MainL() function to create and start the |
|
32 * CTestServer derived server. |
|
33 */ |
|
34 { |
|
35 CTestMessSharedData* sharedData = new (ELeave) CTestMessSharedData(); |
|
36 CleanupStack::PushL(sharedData); |
|
37 sharedData->ConstructL(); |
|
38 CleanupStack::Pop(sharedData); |
|
39 return sharedData; |
|
40 } |
|
41 |
|
42 CTestMessSharedData::CTestMessSharedData() |
|
43 : CBase() |
|
44 , iSession(NULL) |
|
45 , iMtmRegistry(NULL) |
|
46 , iList(NULL) |
|
47 , iAnyPostStepToDo(NULL) |
|
48 , iDeleteTestStep(EFalse) |
|
49 { |
|
50 } |
|
51 |
|
52 void CTestMessSharedData::ConstructL() |
|
53 { |
|
54 iSession=CMsvSession::OpenSyncL(*this); |
|
55 iMtmRegistry=CClientMtmRegistry::NewL(*iSession); |
|
56 } |
|
57 |
|
58 CTestMessSharedData::~CTestMessSharedData() |
|
59 { |
|
60 while ( iList != NULL ) |
|
61 { |
|
62 CMsgEntry* entry=iList; |
|
63 iList=iList->iNext; |
|
64 delete entry; |
|
65 } |
|
66 delete iMtmRegistry; |
|
67 iMtmRegistry=NULL; |
|
68 delete iSession; |
|
69 iSession=NULL; |
|
70 } |
|
71 |
|
72 void CTestMessSharedData::DoProcessL() |
|
73 { |
|
74 if ( iAnyPostStepToDo != NULL ) |
|
75 { |
|
76 if (iDeleteTestStep) |
|
77 { |
|
78 iAnyPostStepToDo->DoCancelProcessL(); |
|
79 iDeleteTestStep=EFalse; |
|
80 } |
|
81 else |
|
82 { |
|
83 iAnyPostStepToDo->DoProcessL(*iMtmRegistry); |
|
84 } |
|
85 iAnyPostStepToDo=NULL; |
|
86 } |
|
87 } |
|
88 |
|
89 void CTestMessSharedData::IMAP4ConnectAndSyncCompleteAfterDisconnectL(TUid aMtmId, TMsvId aMsvId, CTestStep& aStep) |
|
90 { |
|
91 iList=CMsgIMAP4ConnectAndSyncComplete::NewL(aMtmId, aMsvId, aStep, iList); |
|
92 iAnyPostStepToDo=iList; |
|
93 } |
|
94 |
|
95 TInt CTestMessSharedData::DeleteEntryL(CTestStep& aStep) |
|
96 { |
|
97 TInt ret=KErrNone; |
|
98 TPtrC name; |
|
99 |
|
100 if ( !aStep.GetStringFromConfig(aStep.ConfigSection(), KName, name) ) |
|
101 { |
|
102 aStep.ERR_PRINTF1(_L("Name not found")); |
|
103 aStep.SetTestStepResult(EFail); |
|
104 ret=KErrArgument; |
|
105 } |
|
106 else |
|
107 { |
|
108 aStep.INFO_PRINTF2(_L("Name : %S"), &name); |
|
109 |
|
110 CMsgEntry* msgParent=NULL; |
|
111 CMsgEntry* msgEntry=iList; |
|
112 TBool found=EFalse; |
|
113 |
|
114 while ( (msgEntry!=NULL) && !found ) |
|
115 { |
|
116 if ( msgEntry->iName.Compare(name) == 0 ) |
|
117 { |
|
118 if ( msgParent!=NULL ) |
|
119 { |
|
120 msgParent->iNext=msgEntry->iNext; |
|
121 } |
|
122 else |
|
123 { |
|
124 iList=msgEntry->iNext; |
|
125 } |
|
126 iDeleteTestStep=ETrue; |
|
127 iAnyPostStepToDo=msgEntry; |
|
128 found=ETrue; |
|
129 } |
|
130 else |
|
131 { |
|
132 msgParent=msgEntry; |
|
133 msgEntry=msgEntry->iNext; |
|
134 } |
|
135 } |
|
136 |
|
137 if ( !found ) |
|
138 { |
|
139 aStep.ERR_PRINTF1(_L("Message Entry not found")); |
|
140 aStep.SetTestStepResult(EFail); |
|
141 ret=KErrNotFound; |
|
142 } |
|
143 } |
|
144 |
|
145 return ret; |
|
146 } |
|
147 |
|
148 CTestMessSharedData::CMsgEntry::CMsgEntry(CMsgEntry* aList) |
|
149 : CActive(EPriorityStandard) |
|
150 , iNext(aList) |
|
151 , iReadyToBeDeleted(EFalse) |
|
152 { |
|
153 } |
|
154 |
|
155 void CTestMessSharedData::CMsgEntry::ConstructL(CTestStep& aStep) |
|
156 { |
|
157 TPtrC name; |
|
158 |
|
159 // Read in name tag |
|
160 if ( !aStep.GetStringFromConfig(aStep.ConfigSection(), KName, name) ) |
|
161 { |
|
162 aStep.ERR_PRINTF1(_L("Name not found")); |
|
163 aStep.SetTestStepResult(EFail); |
|
164 } |
|
165 else |
|
166 { |
|
167 aStep.INFO_PRINTF2(_L("Name : %S"), &name); |
|
168 iName.Copy(name); |
|
169 } |
|
170 } |
|
171 |
|
172 CTestMessSharedData::CMsgEntry::~CMsgEntry() |
|
173 { |
|
174 } |
|
175 |
|
176 void CTestMessSharedData::CMsgEntry::DoCancel() |
|
177 { |
|
178 } |
|
179 |
|
180 void CTestMessSharedData::CMsgEntry::RunL() |
|
181 { |
|
182 iReadyToBeDeleted=ETrue; |
|
183 } |
|
184 |
|
185 CTestMessSharedData::CMsgIMAP4ConnectAndSyncComplete* CTestMessSharedData::CMsgIMAP4ConnectAndSyncComplete::NewL(TUid aMtmId, TMsvId aMsvId, CTestStep& aStep, CMsgEntry* aList) |
|
186 { |
|
187 CMsgIMAP4ConnectAndSyncComplete* self= new (ELeave) CMsgIMAP4ConnectAndSyncComplete(aMtmId, aMsvId, aList); |
|
188 CleanupStack::PushL(self); |
|
189 self->ConstructL(aStep); |
|
190 CleanupStack::Pop(self); |
|
191 return self; |
|
192 } |
|
193 |
|
194 CTestMessSharedData::CMsgIMAP4ConnectAndSyncComplete::CMsgIMAP4ConnectAndSyncComplete(TUid aMtmId, TMsvId aMsvId, CMsgEntry* aList) |
|
195 : CMsgEntry(aList) |
|
196 , iMtmId(aMtmId) |
|
197 , iMsvId(aMsvId) |
|
198 , iBaseMtm(NULL) |
|
199 , iOperation(NULL) |
|
200 { |
|
201 } |
|
202 |
|
203 CTestMessSharedData::CMsgIMAP4ConnectAndSyncComplete::~CMsgIMAP4ConnectAndSyncComplete() |
|
204 { |
|
205 if ( iOperation != NULL ) |
|
206 { |
|
207 delete iOperation; |
|
208 iOperation=NULL; |
|
209 } |
|
210 delete iBaseMtm; |
|
211 iBaseMtm=NULL; |
|
212 } |
|
213 |
|
214 void CTestMessSharedData::CMsgIMAP4ConnectAndSyncComplete::RunL() |
|
215 { |
|
216 CMsgEntry::RunL(); |
|
217 delete iOperation; |
|
218 iOperation=NULL; |
|
219 delete iBaseMtm; |
|
220 iBaseMtm=NULL; |
|
221 |
|
222 } |
|
223 |
|
224 void CTestMessSharedData::CMsgIMAP4ConnectAndSyncComplete::DoProcessL(CClientMtmRegistry& aMtmRegistry) |
|
225 { |
|
226 iBaseMtm=aMtmRegistry.NewMtmL(iMtmId); |
|
227 CActiveScheduler::Add(this); |
|
228 |
|
229 iBaseMtm->SwitchCurrentEntryL(iMsvId); |
|
230 CMsvEntrySelection* selection=new (ELeave) CMsvEntrySelection(); |
|
231 CleanupStack::PushL(selection); |
|
232 selection->Reset(); |
|
233 selection->AppendL(iMsvId); |
|
234 selection->AppendL(iMsvId); // remote inbox |
|
235 |
|
236 TPckg<MMsvImapConnectionObserver*> parameter(this); |
|
237 iOperation=iBaseMtm->InvokeAsyncFunctionL(KIMAP4MTMConnectAndSyncCompleteAfterDisconnect, *selection, parameter, iStatus); |
|
238 CleanupStack::PopAndDestroy(selection); |
|
239 SetActive(); |
|
240 } |
|
241 |
|
242 void CTestMessSharedData::CMsgIMAP4ConnectAndSyncComplete::DoCancelProcessL() |
|
243 { |
|
244 if ( iOperation != NULL ) |
|
245 { |
|
246 iOperation->Cancel(); |
|
247 } |
|
248 } |
|
249 |
|
250 void CTestMessSharedData::CMsgIMAP4ConnectAndSyncComplete::HandleImapConnectionEvent(TImapConnectionEvent aConnectionEvent) |
|
251 { |
|
252 switch (aConnectionEvent) |
|
253 { |
|
254 /** Connecting to server. */ |
|
255 case EConnectingToServer: |
|
256 break; |
|
257 /** Synchronising folder list. */ |
|
258 case ESynchronisingFolderList: |
|
259 break; |
|
260 /** Synchronising inbox. */ |
|
261 case ESynchronisingInbox: |
|
262 break; |
|
263 /** Synchronising folders. */ |
|
264 case ESynchronisingFolders: |
|
265 break; |
|
266 /** Synchronisation complete. */ |
|
267 case ESynchronisationComplete: |
|
268 break; |
|
269 /** Disconnecting. */ |
|
270 case EDisconnecting: |
|
271 break; |
|
272 /** Connection completed. */ |
|
273 case EConnectionCompleted: |
|
274 break; |
|
275 } |
|
276 } |