|
1 // Copyright (c) 2006-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 "ctestimapservereventwait.h" |
|
17 |
|
18 #include "cfakeinputstream.h" |
|
19 #include "cfakeoutputstream.h" |
|
20 #include "cactivewaiter.h" |
|
21 |
|
22 #include "moutputstream.h" |
|
23 #include "cimapsession.h" |
|
24 |
|
25 #include "cimapfolderinfo.h" |
|
26 #include "cimaputils.h" |
|
27 |
|
28 CTestImapServerEventWait::CTestImapServerEventWait() |
|
29 : iInputStream(NULL) |
|
30 , iOutputStream(NULL) |
|
31 , iActiveWaiter(NULL) |
|
32 , iImapSession(NULL) |
|
33 {} |
|
34 |
|
35 CTestImapServerEventWait::~CTestImapServerEventWait() |
|
36 { |
|
37 delete iImapSession; |
|
38 delete iActiveWaiter; |
|
39 delete iOutputStream; |
|
40 delete iInputStream; |
|
41 CImapUtils::Delete(); |
|
42 } |
|
43 |
|
44 void CTestImapServerEventWait::SetupL() |
|
45 { |
|
46 ASSERT(iInputStream == NULL); |
|
47 ASSERT(iOutputStream == NULL); |
|
48 ASSERT(iActiveWaiter == NULL); |
|
49 ASSERT(iImapSession == NULL); |
|
50 |
|
51 CImapUtils::CreateL(); |
|
52 iInputStream = CFakeInputStream::NewL(Logger()); |
|
53 iOutputStream = CFakeOutputStream::NewL(Logger()); |
|
54 iActiveWaiter = new(ELeave)CActiveWaiter(Logger()); |
|
55 |
|
56 CImapSettings* imapSettings=NULL; |
|
57 CImapMailStore* imapMailStore=NULL; |
|
58 |
|
59 iImapSession = CImapSession::NewL(*imapSettings,*imapMailStore,*iInputStream, *iOutputStream); |
|
60 |
|
61 INFO_PRINTF1(_L("Setup: ServerGreeting")); |
|
62 iInputStream->ResetInputStrings(); |
|
63 iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n")); |
|
64 |
|
65 ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState()); |
|
66 |
|
67 iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus); |
|
68 iActiveWaiter->WaitActive(); |
|
69 |
|
70 INFO_PRINTF1(_L("...Login")); |
|
71 iInputStream->ResetInputStrings(); |
|
72 iInputStream->AppendInputStringL(_L8("1 OK LOGIN completed\r\n")); |
|
73 |
|
74 iImapSession->LoginL(iActiveWaiter->iStatus, _L8("username"), _L8("password")); |
|
75 iActiveWaiter->WaitActive(); |
|
76 |
|
77 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
78 |
|
79 |
|
80 INFO_PRINTF1(_L("...Select inbox")); |
|
81 iInputStream->ResetInputStrings(); |
|
82 iInputStream->AppendInputStringL(_L8("* 23 EXISTS\r\n")); |
|
83 iInputStream->AppendInputStringL(_L8("* 1 RECENT\r\n")); |
|
84 iInputStream->AppendInputStringL(_L8("* OK [UNSEEN 12] Message 12 is first unseen\r\n")); |
|
85 iInputStream->AppendInputStringL(_L8("* OK [UIDVALIDITY 3857529045] UIDs valid\r\n")); |
|
86 iInputStream->AppendInputStringL(_L8("2 OK [READ-WRITE] SELECT completed\r\n")); |
|
87 |
|
88 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
89 CleanupStack::PushL(folderInfo); |
|
90 |
|
91 folderInfo->SetNameL(_L16("inbox")); |
|
92 CleanupStack::Pop(folderInfo); |
|
93 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
94 iActiveWaiter->WaitActive(); |
|
95 |
|
96 ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState()); |
|
97 ASSERT_EQUALS(folderInfo, iImapSession->SelectedFolderInfo()); |
|
98 folderInfo = NULL; |
|
99 } |
|
100 |
|
101 void CTestImapServerEventWait::TearDownL() |
|
102 { |
|
103 delete iImapSession; |
|
104 iImapSession = NULL; |
|
105 |
|
106 delete iActiveWaiter; |
|
107 iActiveWaiter = NULL; |
|
108 |
|
109 delete iOutputStream; |
|
110 iOutputStream = NULL; |
|
111 |
|
112 delete iInputStream; |
|
113 iInputStream = NULL; |
|
114 |
|
115 CImapUtils::Delete(); |
|
116 } |
|
117 |
|
118 |
|
119 // Tests |
|
120 void CTestImapServerEventWait::TestSimpleL() |
|
121 { |
|
122 INFO_PRINTF1(_L("TestSimpleL")); |
|
123 |
|
124 iInputStream->ResetInputStrings(); |
|
125 iInputStream->AppendInputStringL(_L8("* 22 EXPUNGE\r\n")); |
|
126 |
|
127 iImapSession->WaitForServerEventL(iActiveWaiter->iStatus); |
|
128 iActiveWaiter->WaitActive(); |
|
129 |
|
130 CImapFolderInfo* selectedFolderInfo = iImapSession->SelectedFolderInfo(); |
|
131 ASSERT_NOT_NULL(selectedFolderInfo); |
|
132 |
|
133 ASSERT_EQUALS(selectedFolderInfo->ExpungedMessages().Count(), 1); |
|
134 ASSERT_EQUALS(selectedFolderInfo->ExpungedMessages()[0], (TUint)22); |
|
135 |
|
136 INFO_PRINTF1(_L("Complete")); |
|
137 } |
|
138 |
|
139 void CTestImapServerEventWait::TestTwoEventsL() |
|
140 { |
|
141 INFO_PRINTF1(_L("TestTwoEventsL")); |
|
142 |
|
143 iInputStream->ResetInputStrings(); |
|
144 iInputStream->AppendInputStringL(_L8("* 22 EXPUNGE\r\n* 321 EXPUNGE\r\n")); |
|
145 |
|
146 iImapSession->WaitForServerEventL(iActiveWaiter->iStatus); |
|
147 iActiveWaiter->WaitActive(); |
|
148 |
|
149 iImapSession->WaitForServerEventL(iActiveWaiter->iStatus); |
|
150 iActiveWaiter->WaitActive(); |
|
151 |
|
152 CImapFolderInfo* selectedFolderInfo = iImapSession->SelectedFolderInfo(); |
|
153 ASSERT_NOT_NULL(selectedFolderInfo); |
|
154 |
|
155 ASSERT_EQUALS(selectedFolderInfo->ExpungedMessages().Count(), 2); |
|
156 ASSERT_EQUALS(selectedFolderInfo->ExpungedMessages()[0], (TUint)22); |
|
157 ASSERT_EQUALS(selectedFolderInfo->ExpungedMessages()[1], (TUint)321); |
|
158 |
|
159 INFO_PRINTF1(_L("Complete")); |
|
160 } |
|
161 |
|
162 void CTestImapServerEventWait::TestCancelAfterNoEventL() |
|
163 { |
|
164 INFO_PRINTF1(_L("TestCancelAfterNoEventL")); |
|
165 |
|
166 iInputStream->ResetInputStrings(); |
|
167 |
|
168 iImapSession->WaitForServerEventL(iActiveWaiter->iStatus); |
|
169 iActiveWaiter->SetActiveAndCancel(*this); |
|
170 |
|
171 iImapSession->FlushCancelledCommand(iActiveWaiter->iStatus); |
|
172 iActiveWaiter->WaitActive(); |
|
173 |
|
174 // Check that some other command can now be run |
|
175 iInputStream->ResetInputStrings(); |
|
176 iInputStream->AppendInputStringL(_L8("1 OK noop\r\n")); |
|
177 |
|
178 iImapSession->NoopL(iActiveWaiter->iStatus); |
|
179 iActiveWaiter->WaitActive(); |
|
180 |
|
181 |
|
182 INFO_PRINTF1(_L("Complete")); |
|
183 } |
|
184 |
|
185 void CTestImapServerEventWait::TestCancelAfterWholeEventL() |
|
186 { |
|
187 INFO_PRINTF1(_L("TestCancelAfterWholeEventL")); |
|
188 |
|
189 iInputStream->ResetInputStrings(); |
|
190 iInputStream->AppendInputStringL(_L8("* 22 EXPUNGE\r\n")); |
|
191 |
|
192 iImapSession->WaitForServerEventL(iActiveWaiter->iStatus); |
|
193 iActiveWaiter->WaitActive(); |
|
194 |
|
195 iImapSession->WaitForServerEventL(iActiveWaiter->iStatus); |
|
196 iActiveWaiter->SetActiveAndCancel(*this); |
|
197 |
|
198 iImapSession->FlushCancelledCommand(iActiveWaiter->iStatus); |
|
199 iActiveWaiter->WaitActive(); |
|
200 |
|
201 // Check that some other command can now be run |
|
202 iInputStream->ResetInputStrings(); |
|
203 iInputStream->AppendInputStringL(_L8("1 OK noop\r\n")); |
|
204 |
|
205 iImapSession->NoopL(iActiveWaiter->iStatus); |
|
206 iActiveWaiter->WaitActive(); |
|
207 |
|
208 |
|
209 INFO_PRINTF1(_L("Complete")); |
|
210 } |
|
211 |
|
212 void CTestImapServerEventWait::TestCancelDuringEventL() |
|
213 { |
|
214 INFO_PRINTF1(_L("TestCancelDuringEventL")); |
|
215 |
|
216 iInputStream->ResetInputStrings(); |
|
217 iInputStream->AppendInputStringL(_L8("* XLITERAL {10}\r\n")); // simulate an extension response that happens to return a literal |
|
218 |
|
219 iInputStreamNotifyOp = ENotifyOpCompleteXLiteralAndCancel; |
|
220 iInputStream->NotifyWhenStreamIsEmpty(*this); |
|
221 |
|
222 iImapSession->WaitForServerEventL(iActiveWaiter->iStatus); |
|
223 iActiveWaiter->WaitActive(KErrCancel); // this operation will be cancelled by the OnInputStreamIsEmptyL() callback |
|
224 |
|
225 iImapSession->FlushCancelledCommand(iActiveWaiter->iStatus); |
|
226 iActiveWaiter->WaitActive(); |
|
227 |
|
228 // Check that some other command can now be run |
|
229 iInputStream->ResetInputStrings(); |
|
230 iInputStream->AppendInputStringL(_L8("1 OK noop\r\n")); |
|
231 |
|
232 iImapSession->NoopL(iActiveWaiter->iStatus); |
|
233 iActiveWaiter->WaitActive(); |
|
234 |
|
235 |
|
236 INFO_PRINTF1(_L("Complete")); |
|
237 } |
|
238 |
|
239 void CTestImapServerEventWait::OnInputStreamIsEmptyL() |
|
240 { |
|
241 switch (iInputStreamNotifyOp) |
|
242 { |
|
243 case ENotifyOpCompleteXLiteralAndCancel: |
|
244 { |
|
245 iInputStream->ResetInputStrings(); |
|
246 iInputStream->AppendInputStringL(_L8("1234567890\r\n")); |
|
247 iActiveWaiter->CancelWaitActive(*this); |
|
248 } |
|
249 break; |
|
250 } |
|
251 } |
|
252 |
|
253 void CTestImapServerEventWait::DoCancel() |
|
254 { |
|
255 if (iImapSession) |
|
256 { |
|
257 iImapSession->Cancel(); |
|
258 } |
|
259 } |
|
260 |
|
261 CTestSuite* CTestImapServerEventWait::CreateSuiteL(const TDesC& aName) |
|
262 // static |
|
263 { |
|
264 SUB_SUITE; |
|
265 ADD_ASYNC_TEST_STEP(TestSimpleL); |
|
266 ADD_ASYNC_TEST_STEP(TestTwoEventsL); |
|
267 ADD_ASYNC_TEST_STEP(TestCancelAfterNoEventL); |
|
268 ADD_ASYNC_TEST_STEP(TestCancelAfterWholeEventL); |
|
269 ADD_ASYNC_TEST_STEP(TestCancelDuringEventL); |
|
270 END_SUITE; |
|
271 } |