|
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 // The server waits for the idle read to be cancelled by the sync command, and then sends a '* 2 EXISTS' command to indicate that |
|
15 // a new message has arrived. |
|
16 // 2. The client connects to the server, requests a sync and a populate. |
|
17 // 3. Client / server interact to complete the sync and populate. One message is fetched. |
|
18 // 4. The client requests a full sync (causing the idle read cancel). |
|
19 // 5. The server indicates a new message has arrived |
|
20 // 6. Client / server interact to complete the full sync. The new message is fetched |
|
21 // 7. The client requests a full sync (causing the idle read cancel). |
|
22 // 8. The server indicates a new message has arrived |
|
23 // 9. Client / server interact to complete the full sync. The new message is fetched |
|
24 // 10. The client disconnects. |
|
25 // |
|
26 // |
|
27 |
|
28 /** |
|
29 @SYMTestCaseID DEF067159 |
|
30 @SYMTestType UT |
|
31 @SYMTestPriority High |
|
32 @SYMDEF DEF067159 |
|
33 @SYMTestCaseDesc IMAP spoof server test that checks that a new message indication is correctly handled if idle read is being cancelled during a sync |
|
34 @SYMTestActions 1. The Server is started and listens on port 143. |
|
35 @SYMTestExpectedResults Client should have fetched three messages |
|
36 */ |
|
37 |
|
38 #include "T_ImapNewMsgDuringSyncIdleCancelStep.h" |
|
39 #include "T_ImapNewMsgDuringSyncIdleCancelClient.h" |
|
40 |
|
41 #include "emailtestutils.h" |
|
42 |
|
43 #include <e32test.h> |
|
44 |
|
45 RTest test(_L("IMAP receive new message while synch is cancelling idle")); |
|
46 |
|
47 const TInt KSizeDateTimeBuffer = 45; |
|
48 const TInt KImapPort = 143; |
|
49 |
|
50 LOCAL_C void FormatDateTime(TDes& aBuffer, const TTime& aTime) |
|
51 { |
|
52 aBuffer.Zero(); |
|
53 _LIT(KFormat4,"%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B"); |
|
54 aTime.FormatL(aBuffer,KFormat4); |
|
55 } |
|
56 |
|
57 CImapNewMsgDuringSyncIdleCancelStep::CImapNewMsgDuringSyncIdleCancelStep() |
|
58 { |
|
59 // Call base class method to set up the human readable name for logging |
|
60 SetTestStepName(KTestImapNewMsgDuringSyncIdleCancel); |
|
61 } |
|
62 |
|
63 CImapNewMsgDuringSyncIdleCancelStep::~CImapNewMsgDuringSyncIdleCancelStep() |
|
64 { |
|
65 delete iConsole; |
|
66 delete iSpoofServer; |
|
67 delete iTestUtils; |
|
68 delete iImapClient; |
|
69 delete iScheduler; |
|
70 if(iSession!=NULL) |
|
71 iSession->CloseMessageServer(); |
|
72 delete iSession; |
|
73 delete iSessionObserver; |
|
74 } |
|
75 |
|
76 void CImapNewMsgDuringSyncIdleCancelStep::TestComplete(TInt aEventCode) |
|
77 { |
|
78 CActiveScheduler::Stop(); |
|
79 |
|
80 if(aEventCode!=KErrNone && aEventCode!=KErrEof) |
|
81 { |
|
82 ERR_PRINTF2(_L("Error: %d"),aEventCode); |
|
83 } |
|
84 } |
|
85 |
|
86 void CImapNewMsgDuringSyncIdleCancelStep::PrintEntryTime(TTime* aTIme) |
|
87 { |
|
88 TBuf<KSizeDateTimeBuffer> dateTimeString; |
|
89 FormatDateTime(dateTimeString,*aTIme); |
|
90 INFO_PRINTF2(_L("%S"),&dateTimeString); |
|
91 } |
|
92 |
|
93 void CImapNewMsgDuringSyncIdleCancelStep::GetDetailsFromIniFileL() |
|
94 { |
|
95 // get the script file path |
|
96 _LIT(KScriptFile,"ScriptFile"); |
|
97 if(!GetStringFromConfig(ConfigSection(),KScriptFile,iScriptFile)) |
|
98 { |
|
99 _LIT(KErrorScriptFile, "Error reading script file path from ini file"); |
|
100 ERR_PRINTF1(KErrorScriptFile); |
|
101 User::Leave(KErrArgument); |
|
102 } |
|
103 |
|
104 // get the expected number of mails |
|
105 _LIT(KExpectedCountString, "ExpectedEntryCount"); |
|
106 if(!GetIntFromConfig(ConfigSection(),KExpectedCountString,iExpectedEntryCount)) |
|
107 { |
|
108 _LIT(KErrorExpectedCount, "Error reading expected entry count from ini file"); |
|
109 ERR_PRINTF1(KErrorExpectedCount); |
|
110 User::Leave(KErrArgument); |
|
111 } |
|
112 } |
|
113 |
|
114 TVerdict CImapNewMsgDuringSyncIdleCancelStep::doTestStepPreambleL() |
|
115 { |
|
116 SetTestStepResult(EPass); |
|
117 iScheduler = new (ELeave) CActiveScheduler; |
|
118 CActiveScheduler::Install(iScheduler); |
|
119 |
|
120 iTestUtils = CEmailTestUtils::NewL(test); |
|
121 iTestUtils->FileSession().SetSessionPath(_L("C:\\")); |
|
122 iTestUtils->CleanMessageFolderL(); |
|
123 iTestUtils->ClearEmailAccountsL(); |
|
124 |
|
125 iTestUtils->GoClientSideL(); |
|
126 |
|
127 // start the imap server |
|
128 GetDetailsFromIniFileL(); |
|
129 iConsole=Console::NewL(_L("IMAP Receive New Msg During Sync Idle Cancel"),TSize(KConsFullScreen,KConsFullScreen)); |
|
130 iSpoofServer = CSpoofServer::NewL(*this,iScriptFile); |
|
131 iSpoofServer->StartL(KImapPort); |
|
132 |
|
133 // start the imap client |
|
134 iImapClient = CImapNewMsgDuringSyncIdleCancelClient::NewL(this); |
|
135 iImapClient->StartL(); |
|
136 |
|
137 CActiveScheduler::Start(); |
|
138 return TestStepResult(); |
|
139 } |
|
140 |
|
141 TInt CImapNewMsgDuringSyncIdleCancelStep::GetEntryCountL() |
|
142 { |
|
143 TImapAccount imapAccount=iImapClient->GetImapAccount(); |
|
144 |
|
145 TMsvSelectionOrdering ordering; |
|
146 |
|
147 // open the imap service entry |
|
148 CMsvEntry* imapService = CMsvEntry::NewL(*iSession,imapAccount.iImapService,ordering); |
|
149 CleanupStack::PushL(imapService); |
|
150 // get its children |
|
151 CMsvEntrySelection* msvEntrySelection; |
|
152 msvEntrySelection=imapService->ChildrenL(); |
|
153 // open its child inbox entry |
|
154 CMsvEntry* inboxEntry = CMsvEntry::NewL(*iSession, (*msvEntrySelection)[0],ordering); |
|
155 CleanupStack::PushL(inboxEntry); |
|
156 |
|
157 // get the childeren of the inbox |
|
158 delete msvEntrySelection; |
|
159 msvEntrySelection=NULL; |
|
160 msvEntrySelection=inboxEntry->ChildrenL(); |
|
161 TInt count=msvEntrySelection->Count(); |
|
162 |
|
163 delete msvEntrySelection; |
|
164 msvEntrySelection=NULL; |
|
165 CleanupStack::PopAndDestroy(2,imapService); |
|
166 |
|
167 return count; |
|
168 } |
|
169 |
|
170 |
|
171 TVerdict CImapNewMsgDuringSyncIdleCancelStep::doTestStepL() |
|
172 { |
|
173 TVerdict result; |
|
174 // Session observer. Needed to create a session |
|
175 iSessionObserver = new (ELeave) TDummySessionObserver; |
|
176 // Session. Needed to create a client registry. |
|
177 iSession=CMsvSession::OpenSyncL(*iSessionObserver); |
|
178 // get entry count |
|
179 TInt entryCount=GetEntryCountL(); |
|
180 result = (entryCount==iExpectedEntryCount? EPass:EFail); |
|
181 SetTestStepResult(result); |
|
182 return TestStepResult(); |
|
183 } |
|
184 |
|
185 TVerdict CImapNewMsgDuringSyncIdleCancelStep::doTestStepPostambleL() |
|
186 { |
|
187 return TestStepResult(); |
|
188 } |