|
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 "ctestimapselect.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 "cimapsessionconsts.h" |
|
27 #include "cimaputils.h" |
|
28 |
|
29 |
|
30 CTestImapSelect::CTestImapSelect() |
|
31 : iInputStream(NULL) |
|
32 , iOutputStream(NULL) |
|
33 , iActiveWaiter(NULL) |
|
34 , iImapSession(NULL) |
|
35 {} |
|
36 |
|
37 CTestImapSelect::~CTestImapSelect() |
|
38 { |
|
39 delete iImapSession; |
|
40 delete iActiveWaiter; |
|
41 delete iOutputStream; |
|
42 delete iInputStream; |
|
43 CImapUtils::Delete(); |
|
44 } |
|
45 |
|
46 void CTestImapSelect::SetupL() |
|
47 { |
|
48 ASSERT(iInputStream == NULL); |
|
49 ASSERT(iOutputStream == NULL); |
|
50 ASSERT(iActiveWaiter == NULL); |
|
51 ASSERT(iImapSession == NULL); |
|
52 |
|
53 CImapUtils::CreateL(); |
|
54 iInputStream = CFakeInputStream::NewL(Logger()); |
|
55 iOutputStream = CFakeOutputStream::NewL(Logger()); |
|
56 iActiveWaiter = new(ELeave)CActiveWaiter(Logger()); |
|
57 |
|
58 CImapSettings* imapSettings=NULL; |
|
59 CImapMailStore* imapMailStore=NULL; |
|
60 |
|
61 iImapSession = CImapSession::NewL(*imapSettings,*imapMailStore,*iInputStream, *iOutputStream); |
|
62 |
|
63 INFO_PRINTF1(_L("Setup: ServerGreeting")); |
|
64 iInputStream->ResetInputStrings(); |
|
65 iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n")); |
|
66 |
|
67 ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState()); |
|
68 |
|
69 iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus); |
|
70 iActiveWaiter->WaitActive(); |
|
71 |
|
72 INFO_PRINTF1(_L("...Login")); |
|
73 iInputStream->ResetInputStrings(); |
|
74 iInputStream->AppendInputStringL(_L8("1 OK LOGIN completed\r\n")); |
|
75 |
|
76 iImapSession->LoginL(iActiveWaiter->iStatus, _L8("username"), _L8("password")); |
|
77 iActiveWaiter->WaitActive(); |
|
78 |
|
79 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
80 } |
|
81 |
|
82 void CTestImapSelect::TearDownL() |
|
83 { |
|
84 delete iImapSession; |
|
85 iImapSession = NULL; |
|
86 |
|
87 delete iActiveWaiter; |
|
88 iActiveWaiter = NULL; |
|
89 |
|
90 delete iOutputStream; |
|
91 iOutputStream = NULL; |
|
92 |
|
93 delete iInputStream; |
|
94 iInputStream = NULL; |
|
95 |
|
96 CImapUtils::Delete(); |
|
97 } |
|
98 |
|
99 /** |
|
100 Tests the example given in section 6.3.1 of RFC3501 |
|
101 */ |
|
102 void CTestImapSelect::TestSelectBasicL() |
|
103 { |
|
104 INFO_PRINTF1(_L("TestSelectBasicL")); |
|
105 |
|
106 INFO_PRINTF1(_L("...Select inbox")); |
|
107 iInputStream->ResetInputStrings(); |
|
108 iInputStream->AppendInputStringL(_L8("* 172 EXISTS\r\n")); |
|
109 iInputStream->AppendInputStringL(_L8("* 1 RECENT\r\n")); |
|
110 iInputStream->AppendInputStringL(_L8("* OK [UNSEEN 12] Message 12 is first unseen\r\n")); |
|
111 iInputStream->AppendInputStringL(_L8("* OK [UIDVALIDITY 3857529045] UIDs valid\r\n")); |
|
112 iInputStream->AppendInputStringL(_L8("* OK [UIDNEXT 4392] Predicted next UID\r\n")); |
|
113 iInputStream->AppendInputStringL(_L8("* FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\r\n")); |
|
114 iInputStream->AppendInputStringL(_L8("* OK [PERMANENTFLAGS (\\Deleted \\Seen \\*)] Limited\r\n")); |
|
115 iInputStream->AppendInputStringL(_L8("2 OK [READ-WRITE] SELECT completed\r\n")); |
|
116 |
|
117 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
118 CleanupStack::PushL(folderInfo); |
|
119 |
|
120 folderInfo->SetNameL(_L16("inbox")); |
|
121 CleanupStack::Pop(folderInfo); |
|
122 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
123 iActiveWaiter->WaitActive(); |
|
124 |
|
125 ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState()); |
|
126 ASSERT_EQUALS(folderInfo, iImapSession->SelectedFolderInfo()); |
|
127 |
|
128 ASSERT_EQUALS(folderInfo->ExpungedMessages().Count(), 0); |
|
129 ASSERT_EQUALS(folderInfo->Exists(), 172); |
|
130 ASSERT_EQUALS(folderInfo->Recent(), 1); |
|
131 ASSERT_EQUALS(folderInfo->Unseen(), 12u); |
|
132 ASSERT_EQUALS(folderInfo->UidValidity(), 3857529045u); |
|
133 ASSERT_EQUALS(folderInfo->UidNext(), 4392u); |
|
134 ASSERT_TRUE(folderInfo->QueryFlag(CImapFolderInfo::EAnswered)); |
|
135 ASSERT_TRUE(folderInfo->QueryFlag(CImapFolderInfo::EFlagged)); |
|
136 ASSERT_TRUE(folderInfo->QueryFlag(CImapFolderInfo::EDeleted)); |
|
137 ASSERT_TRUE(folderInfo->QueryFlag(CImapFolderInfo::ESeen)); |
|
138 ASSERT_TRUE(folderInfo->QueryFlag(CImapFolderInfo::EDraft)); |
|
139 ASSERT_TRUE(folderInfo->GetReadWrite()); |
|
140 |
|
141 folderInfo = NULL; |
|
142 |
|
143 INFO_PRINTF1(_L("Complete")); |
|
144 } |
|
145 |
|
146 /** |
|
147 Tests a corrupt select response |
|
148 */ |
|
149 void CTestImapSelect::TestSelectCorruptNo2ndPartL() |
|
150 { |
|
151 INFO_PRINTF1(_L("TestSelectCorruptNo2ndPartL")); |
|
152 |
|
153 INFO_PRINTF1(_L("...Select inbox")); |
|
154 iInputStream->ResetInputStrings(); |
|
155 iInputStream->AppendInputStringL(_L8("* 1\r\n")); |
|
156 iInputStream->AppendInputStringL(_L8("2 OK\r\n")); |
|
157 |
|
158 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
159 CleanupStack::PushL(folderInfo); |
|
160 |
|
161 folderInfo->SetNameL(_L16("inbox")); |
|
162 CleanupStack::Pop(folderInfo); |
|
163 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
164 iActiveWaiter->WaitActive(); // parser ignores the untagged response. |
|
165 |
|
166 ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState()); |
|
167 |
|
168 folderInfo = NULL; |
|
169 |
|
170 INFO_PRINTF1(_L("Complete")); |
|
171 } |
|
172 |
|
173 /** |
|
174 Tests that an untagged NO response will be ignored. |
|
175 RFC 4315 - UIDPLUS gives an example of an untagged NO response. |
|
176 We don't support UIDPLUS, so we should ignore this response. |
|
177 */ |
|
178 void CTestImapSelect::TestSelectUntaggedNoL() |
|
179 { |
|
180 INFO_PRINTF1(_L("TestSelectUntaggedNoL")); |
|
181 |
|
182 INFO_PRINTF1(_L("...Select inbox")); |
|
183 iInputStream->ResetInputStrings(); |
|
184 iInputStream->AppendInputStringL(_L8("* NO [UIDNOTSTICKY] Non-persistent UIDs\r\n")); |
|
185 iInputStream->AppendInputStringL(_L8("2 OK\r\n")); |
|
186 |
|
187 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
188 CleanupStack::PushL(folderInfo); |
|
189 |
|
190 folderInfo->SetNameL(_L16("inbox")); |
|
191 CleanupStack::Pop(folderInfo); |
|
192 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
193 iActiveWaiter->WaitActive(); |
|
194 |
|
195 // Since the untagged NO was ignored, the session should remain selected |
|
196 ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState()); |
|
197 |
|
198 folderInfo = NULL; |
|
199 |
|
200 INFO_PRINTF1(_L("Complete")); |
|
201 } |
|
202 |
|
203 /** |
|
204 Tests a corrupt select response |
|
205 */ |
|
206 void CTestImapSelect::TestSelectCorruptNoResponseTextCodeL() |
|
207 { |
|
208 INFO_PRINTF1(_L("TestSelectCorruptNoResponseTextCodeL")); |
|
209 |
|
210 INFO_PRINTF1(_L("...Select inbox")); |
|
211 iInputStream->ResetInputStrings(); |
|
212 iInputStream->AppendInputStringL(_L8("* OK UNSEEN not within square brackets\r\n")); |
|
213 iInputStream->AppendInputStringL(_L8("2 OK\r\n")); |
|
214 |
|
215 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
216 CleanupStack::PushL(folderInfo); |
|
217 |
|
218 folderInfo->SetNameL(_L16("inbox")); |
|
219 CleanupStack::Pop(folderInfo); |
|
220 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
221 iActiveWaiter->WaitActive(KErrImapCorrupt); |
|
222 |
|
223 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
224 |
|
225 folderInfo = NULL; |
|
226 |
|
227 INFO_PRINTF1(_L("Complete")); |
|
228 } |
|
229 |
|
230 /** |
|
231 Tests a corrupt select response |
|
232 */ |
|
233 void CTestImapSelect::TestSelectCorruptEmptyResponseCodeTextL() |
|
234 { |
|
235 INFO_PRINTF1(_L("TestSelectCorruptEmptyResponseCodeTextL")); |
|
236 |
|
237 INFO_PRINTF1(_L("...Select inbox")); |
|
238 iInputStream->ResetInputStrings(); |
|
239 iInputStream->AppendInputStringL(_L8("* OK [] Predicted next UID\r\n")); |
|
240 iInputStream->AppendInputStringL(_L8("2 OK\r\n")); |
|
241 |
|
242 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
243 CleanupStack::PushL(folderInfo); |
|
244 |
|
245 folderInfo->SetNameL(_L16("inbox")); |
|
246 CleanupStack::Pop(folderInfo); |
|
247 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
248 iActiveWaiter->WaitActive(KErrImapCorrupt); |
|
249 |
|
250 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
251 |
|
252 folderInfo = NULL; |
|
253 |
|
254 INFO_PRINTF1(_L("Complete")); |
|
255 } |
|
256 |
|
257 /** |
|
258 Tests a corrupt select response |
|
259 */ |
|
260 void CTestImapSelect::TestSelectCorruptNoFlagsL() |
|
261 { |
|
262 INFO_PRINTF1(_L("TestSelectCorruptNoFlagsL")); |
|
263 |
|
264 INFO_PRINTF1(_L("...Select inbox")); |
|
265 iInputStream->ResetInputStrings(); |
|
266 iInputStream->AppendInputStringL(_L8("* FLAGS ()\r\n")); |
|
267 iInputStream->AppendInputStringL(_L8("2 OK\r\n")); |
|
268 |
|
269 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
270 CleanupStack::PushL(folderInfo); |
|
271 |
|
272 folderInfo->SetNameL(_L16("inbox")); |
|
273 CleanupStack::Pop(folderInfo); |
|
274 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
275 iActiveWaiter->WaitActive(); |
|
276 |
|
277 // strictly speaking, no flags is corrupt, but we ignore this one. |
|
278 ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState()); |
|
279 |
|
280 folderInfo = NULL; |
|
281 |
|
282 INFO_PRINTF1(_L("Complete")); |
|
283 } |
|
284 |
|
285 /** |
|
286 Tests a corrupt select response |
|
287 */ |
|
288 void CTestImapSelect::TestSelectCorruptFlagMissingCloseBracketL() |
|
289 { |
|
290 INFO_PRINTF1(_L("TestSelectCorruptFlagMissingCloseBracketL")); |
|
291 |
|
292 INFO_PRINTF1(_L("...Select inbox")); |
|
293 iInputStream->ResetInputStrings(); |
|
294 iInputStream->AppendInputStringL(_L8("* FLAGS (\\Deleted\r\n")); |
|
295 iInputStream->AppendInputStringL(_L8("2 OK\r\n")); |
|
296 |
|
297 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
298 CleanupStack::PushL(folderInfo); |
|
299 |
|
300 folderInfo->SetNameL(_L16("inbox")); |
|
301 CleanupStack::Pop(folderInfo); |
|
302 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
303 iActiveWaiter->WaitActive(KErrImapCorrupt); |
|
304 |
|
305 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
306 |
|
307 folderInfo = NULL; |
|
308 |
|
309 INFO_PRINTF1(_L("Complete")); |
|
310 } |
|
311 |
|
312 /** |
|
313 Tests a corrupt select response |
|
314 */ |
|
315 void CTestImapSelect::TestSelectCorruptTaggedOkWrongResponseCodeL() |
|
316 { |
|
317 INFO_PRINTF1(_L("TestSelectCorruptTaggedOkWrongResponseCodeL")); |
|
318 |
|
319 INFO_PRINTF1(_L("...Select inbox")); |
|
320 iInputStream->ResetInputStrings(); |
|
321 iInputStream->AppendInputStringL(_L8("* 172 EXISTS\r\n")); |
|
322 iInputStream->AppendInputStringL(_L8("* 1 RECENT\r\n")); |
|
323 iInputStream->AppendInputStringL(_L8("* OK [UNSEEN 12] Message 12 is first unseen\r\n")); |
|
324 iInputStream->AppendInputStringL(_L8("* OK [UIDVALIDITY 3857529045] UIDs valid\r\n")); |
|
325 iInputStream->AppendInputStringL(_L8("* OK [UIDNEXT 4392] Predicted next UID\r\n")); |
|
326 iInputStream->AppendInputStringL(_L8("* FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\r\n")); |
|
327 iInputStream->AppendInputStringL(_L8("* OK [PERMANENTFLAGS (\\Deleted \\Seen \\*)] Limited\r\n")); |
|
328 iInputStream->AppendInputStringL(_L8("2 OK [WIBBLE] should be READ-WRITE\r\n")); |
|
329 |
|
330 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
331 CleanupStack::PushL(folderInfo); |
|
332 |
|
333 folderInfo->SetNameL(_L16("inbox")); |
|
334 CleanupStack::Pop(folderInfo); |
|
335 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
336 iActiveWaiter->WaitActive(); |
|
337 |
|
338 // Unrecognised response text code ignored, because it is tagged. |
|
339 ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState()); |
|
340 |
|
341 folderInfo = NULL; |
|
342 |
|
343 INFO_PRINTF1(_L("Complete")); |
|
344 } |
|
345 |
|
346 CTestSuite* CTestImapSelect::CreateSuiteL(const TDesC& aName) |
|
347 // static |
|
348 { |
|
349 SUB_SUITE; |
|
350 ADD_ASYNC_TEST_STEP(TestSelectBasicL); |
|
351 ADD_ASYNC_TEST_STEP(TestSelectCorruptNo2ndPartL); |
|
352 ADD_ASYNC_TEST_STEP(TestSelectUntaggedNoL); |
|
353 ADD_ASYNC_TEST_STEP(TestSelectCorruptNoResponseTextCodeL); |
|
354 ADD_ASYNC_TEST_STEP(TestSelectCorruptEmptyResponseCodeTextL); |
|
355 ADD_ASYNC_TEST_STEP(TestSelectCorruptNoFlagsL); |
|
356 ADD_ASYNC_TEST_STEP(TestSelectCorruptFlagMissingCloseBracketL); |
|
357 ADD_ASYNC_TEST_STEP(TestSelectCorruptTaggedOkWrongResponseCodeL); |
|
358 END_SUITE; |
|
359 } |
|
360 |
|
361 |