|
1 // Copyright (c) 2005-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 // T_ImapNewMsgDuringSyncIdleCancel.cpp |
|
15 // The server waits for the idle read to be cancelled by the sync command, and then sends a '* 2 EXISTS' command to indicate that |
|
16 // a new message has arrived. |
|
17 // 2. The client connects to the server, requests a sync and a populate. |
|
18 // 3. Client / server interact to complete the sync and populate. One message is fetched. |
|
19 // 4. The client requests a full sync (causing the idle read cancel). |
|
20 // 5. The server indicates a new message has arrived |
|
21 // 6. Client / server interact to complete the full sync. The new message is fetched |
|
22 // 7. The client requests a full sync (causing the idle read cancel). |
|
23 // 8. The server indicates a new message has arrived |
|
24 // 9. Client / server interact to complete the full sync. The new message is fetched |
|
25 // 10. The client disconnects. |
|
26 // |
|
27 // |
|
28 |
|
29 /** |
|
30 @SYMTestCaseID DEF067159 |
|
31 @SYMTestType UT |
|
32 @SYMTestPriority High |
|
33 @SYMDEF DEF067159 |
|
34 @SYMTestCaseDesc IMAP spoof server test that checks that a new message indication is correctly handled if idle read is being cancelled during a sync |
|
35 @SYMTestActions 1. The Server is started and listens on port 143. |
|
36 @SYMTestExpectedResults Client should have fetched three messages |
|
37 */ |
|
38 |
|
39 #include "T_ImapNewMsgDuringSyncIdleCancelClient.h" |
|
40 |
|
41 #include <mtclbase.h> |
|
42 #include <mtclreg.h> |
|
43 #include <miutset.h> |
|
44 #include <imapset.h> |
|
45 #include <smtpset.h> |
|
46 #include <iapprefs.h> |
|
47 #include <imapcmds.h> |
|
48 |
|
49 _LIT(KLoopbackAddress,"127.0.0.1"); |
|
50 |
|
51 void TDummySessionObserver::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
52 { |
|
53 } |
|
54 |
|
55 CImapNewMsgDuringSyncIdleCancelClient::CImapNewMsgDuringSyncIdleCancelClient(MImapTestEventHandler* aOwner) |
|
56 : CActive(EPriorityStandard), iOwner(aOwner) |
|
57 { |
|
58 CActiveScheduler::Add(this); |
|
59 } |
|
60 |
|
61 EXPORT_C CImapNewMsgDuringSyncIdleCancelClient* CImapNewMsgDuringSyncIdleCancelClient::NewL(MImapTestEventHandler* aOwner) |
|
62 { |
|
63 CImapNewMsgDuringSyncIdleCancelClient* self = NewLC(aOwner); |
|
64 CleanupStack::Pop(self); |
|
65 return self; |
|
66 } |
|
67 |
|
68 EXPORT_C CImapNewMsgDuringSyncIdleCancelClient* CImapNewMsgDuringSyncIdleCancelClient::NewLC(MImapTestEventHandler* aOwner) |
|
69 { |
|
70 CImapNewMsgDuringSyncIdleCancelClient* self = new(ELeave) CImapNewMsgDuringSyncIdleCancelClient(aOwner); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 CImapNewMsgDuringSyncIdleCancelClient::~CImapNewMsgDuringSyncIdleCancelClient() |
|
77 { |
|
78 Cancel(); |
|
79 delete iMsvOperation; |
|
80 delete iSelection; |
|
81 delete iClientMtm; |
|
82 delete iClientRegistry; |
|
83 delete iSession; |
|
84 delete iSessionObserver; |
|
85 delete iAccounts; |
|
86 } |
|
87 |
|
88 |
|
89 void CImapNewMsgDuringSyncIdleCancelClient::ConstructL() |
|
90 { |
|
91 // create an account |
|
92 iAccounts = CEmailAccounts::NewL(); |
|
93 CreateImapAccountL(); |
|
94 // Session observer. Needed to create a session |
|
95 iSessionObserver = new (ELeave) TDummySessionObserver; |
|
96 // Session. Needed to create a client registry. |
|
97 iSession=CMsvSession::OpenSyncL(*iSessionObserver); |
|
98 // Client registry. Needed to get the MTM component |
|
99 iClientRegistry=CClientMtmRegistry::NewL(*iSession,KMsvDefaultTimeoutMicroSeconds32); |
|
100 // get the client mtm |
|
101 iClientMtm=iClientRegistry->NewMtmL(KUidMsgTypeIMAP4); |
|
102 |
|
103 // Load the serial comms device drivers. If this is not done, |
|
104 // connecting via NT-RAS returns KErrNotFound (-1). |
|
105 TInt driverErr; |
|
106 driverErr=User::LoadPhysicalDevice(PDD_NAME); |
|
107 if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists) |
|
108 User::Leave(driverErr); |
|
109 driverErr=User::LoadLogicalDevice(LDD_NAME); |
|
110 if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists) |
|
111 User::Leave(driverErr); |
|
112 } |
|
113 |
|
114 TImapAccount CImapNewMsgDuringSyncIdleCancelClient::GetImapAccount() |
|
115 { |
|
116 return iImapAccount; |
|
117 } |
|
118 |
|
119 void CImapNewMsgDuringSyncIdleCancelClient::CreateImapAccountL() |
|
120 { |
|
121 // create objects and initialise with the defaults |
|
122 CImImap4Settings* imap4Settings=new(ELeave)CImImap4Settings; |
|
123 CleanupStack::PushL(imap4Settings); |
|
124 CImSmtpSettings* smtpSettings=new(ELeave)CImSmtpSettings; |
|
125 CleanupStack::PushL(smtpSettings); |
|
126 CImIAPPreferences* imapIap = CImIAPPreferences::NewLC(); |
|
127 CImIAPPreferences* smtpIap = CImIAPPreferences::NewLC(); |
|
128 |
|
129 iAccounts->PopulateDefaultImapSettingsL(*imap4Settings, *imapIap); |
|
130 iAccounts->PopulateDefaultSmtpSettingsL(*smtpSettings, *smtpIap); |
|
131 |
|
132 // override some of the defaults |
|
133 imap4Settings->SetPasswordL(_L8("roberth")); |
|
134 imap4Settings->SetLoginNameL(_L8("roberth")); |
|
135 imap4Settings->SetServerAddressL(KLoopbackAddress); |
|
136 imap4Settings->SetFolderPathL(_L8("")); |
|
137 imap4Settings->SetSynchronise(EUseLocal); |
|
138 |
|
139 // create the account |
|
140 iImapAccount = iAccounts->CreateImapAccountL(_L("TestAccount"), *imap4Settings, *imapIap, EFalse); |
|
141 TSmtpAccount smtpAccount; |
|
142 smtpAccount = iAccounts->CreateSmtpAccountL(iImapAccount, *smtpSettings, *smtpIap, EFalse); |
|
143 |
|
144 // clean up |
|
145 CleanupStack::PopAndDestroy(smtpIap); |
|
146 CleanupStack::PopAndDestroy(imapIap); |
|
147 CleanupStack::PopAndDestroy(smtpSettings); |
|
148 CleanupStack::PopAndDestroy(imap4Settings); |
|
149 } |
|
150 |
|
151 void CImapNewMsgDuringSyncIdleCancelClient::StartL() |
|
152 { |
|
153 |
|
154 // we are to collect the whole email: the next operation will be to fetch it |
|
155 iNextStep = ESync1; |
|
156 iSelection = new (ELeave) CMsvEntrySelection; |
|
157 TPckg<MMsvImapConnectionObserver*> param(this); |
|
158 // select the imap service entry |
|
159 iSelection->AppendL(iImapAccount.iImapService); |
|
160 // make the service entry the current context |
|
161 iClientMtm->SwitchCurrentEntryL(iImapAccount.iImapService); |
|
162 // sync the account |
|
163 iMsvOperation = iClientMtm->InvokeAsyncFunctionL(KIMAP4MTMConnectAndSyncCompleteAfterFullSync,*iSelection,param,iStatus); |
|
164 SetActive(); |
|
165 } |
|
166 |
|
167 void CImapNewMsgDuringSyncIdleCancelClient::DoCancel() |
|
168 { |
|
169 __ASSERT_DEBUG(iMsvOperation!=NULL, User::Panic(_L("CImapNewMsgDuringSyncIdleCancelClient"), -3)); |
|
170 iMsvOperation->Cancel(); |
|
171 } |
|
172 |
|
173 void CImapNewMsgDuringSyncIdleCancelClient::RunL() |
|
174 { |
|
175 TPckg<MMsvImapConnectionObserver*> param(this); |
|
176 |
|
177 switch(iNextStep) |
|
178 { |
|
179 case ESync1: |
|
180 { |
|
181 // First step is to do a full sync. This will cause the cancel idle to be sent, at |
|
182 // which point the spoof server will respond to indicate a new message has been |
|
183 // received. Without the defect fix, this step will panic. |
|
184 iNextStep=ESync2; |
|
185 delete iMsvOperation; |
|
186 iMsvOperation=NULL; |
|
187 iMsvOperation = iClientMtm->InvokeAsyncFunctionL(KIMAP4MTMFullSync, *iSelection, param, iStatus); |
|
188 SetActive(); |
|
189 break; |
|
190 } |
|
191 |
|
192 case ESync2: |
|
193 { |
|
194 // Try to do another full sync. As before, this will cause the cancel idle to be |
|
195 // sent, at which point the spoof server will respond to indicate a new message |
|
196 // has been received. |
|
197 // This step is used to make sure that we have left the session state machine in |
|
198 // the correct state after the first step so that further operations can be |
|
199 // performed. It also makes it easy to spot when the test fails as for a failure, |
|
200 // the panic in the first step will mean only 2 messages are downloaded, whereas |
|
201 // for the successful case, 3 messages will be downloaded. |
|
202 iNextStep=EDisconnect; |
|
203 delete iMsvOperation; |
|
204 iMsvOperation=NULL; |
|
205 iMsvOperation = iClientMtm->InvokeAsyncFunctionL(KIMAP4MTMFullSync, *iSelection, param, iStatus); |
|
206 SetActive(); |
|
207 break; |
|
208 } |
|
209 |
|
210 case EDisconnect: |
|
211 { |
|
212 // We have finished, so do a disconnect |
|
213 iNextStep=EComplete; |
|
214 delete iMsvOperation; |
|
215 iMsvOperation=NULL; |
|
216 iMsvOperation = iClientMtm->InvokeAsyncFunctionL(KIMAP4MTMDisconnect,*iSelection,param,iStatus); |
|
217 SetActive(); |
|
218 break; |
|
219 } |
|
220 |
|
221 case EComplete: |
|
222 { |
|
223 // inform the owning object that the process is complete |
|
224 iOwner->TestComplete(KErrNone); |
|
225 break; |
|
226 } |
|
227 |
|
228 default: |
|
229 { |
|
230 __ASSERT_DEBUG(0, User::Panic(_L("CImapNewMsgDuringSyncIdleCancelClient unknown state"), KErrUnknown)); |
|
231 break; |
|
232 } |
|
233 } |
|
234 } |
|
235 |
|
236 TInt CImapNewMsgDuringSyncIdleCancelClient::RunError(TInt aError) |
|
237 { |
|
238 iOwner->TestComplete(aError); |
|
239 return KErrNone; |
|
240 } |
|
241 |
|
242 void CImapNewMsgDuringSyncIdleCancelClient::HandleImapConnectionEvent(TImapConnectionEvent /*aConnectionState*/) |
|
243 { |
|
244 // this method does nothing |
|
245 } |