|
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 "ctestimapfetchflags.h" |
|
17 |
|
18 #include "cfakeinputstream.h" |
|
19 #include "cfakeoutputstream.h" |
|
20 #include "cactivewaiter.h" |
|
21 |
|
22 #include "moutputstream.h" |
|
23 #include "cimapsession.h" |
|
24 #include "cimapsessionconsts.h" |
|
25 #include "cimapfolderinfo.h" |
|
26 #include "cimaputils.h" |
|
27 |
|
28 CTestImapFetchFlags::CTestImapFetchFlags() |
|
29 : iInputStream(NULL) |
|
30 , iOutputStream(NULL) |
|
31 , iActiveWaiter(NULL) |
|
32 , iImapSession(NULL) |
|
33 {} |
|
34 |
|
35 CTestImapFetchFlags::~CTestImapFetchFlags() |
|
36 { |
|
37 delete iImapSession; |
|
38 delete iActiveWaiter; |
|
39 delete iOutputStream; |
|
40 delete iInputStream; |
|
41 CImapUtils::Delete(); |
|
42 } |
|
43 |
|
44 void CTestImapFetchFlags::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("2 OK [READ-WRITE] SELECT completed\r\n")); |
|
83 |
|
84 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
85 CleanupStack::PushL(folderInfo); |
|
86 |
|
87 folderInfo->SetNameL(_L16("inbox")); |
|
88 CleanupStack::Pop(folderInfo); |
|
89 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
90 iActiveWaiter->WaitActive(); |
|
91 |
|
92 ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState()); |
|
93 ASSERT_EQUALS(folderInfo, iImapSession->SelectedFolderInfo()); |
|
94 folderInfo = NULL; |
|
95 } |
|
96 |
|
97 void CTestImapFetchFlags::TearDownL() |
|
98 { |
|
99 delete iImapSession; |
|
100 iImapSession = NULL; |
|
101 |
|
102 delete iActiveWaiter; |
|
103 iActiveWaiter = NULL; |
|
104 |
|
105 delete iOutputStream; |
|
106 iOutputStream = NULL; |
|
107 |
|
108 delete iInputStream; |
|
109 iInputStream = NULL; |
|
110 |
|
111 CImapUtils::Delete(); |
|
112 } |
|
113 |
|
114 // Tests |
|
115 void CTestImapFetchFlags::TestFetchFlagsWithFlagsL() |
|
116 { |
|
117 INFO_PRINTF1(_L("TestFetchFlagsWithFlagsL")); |
|
118 iInputStream->ResetInputStrings(); |
|
119 |
|
120 iInputStream->AppendInputStringL(_L8("* 12 EXISTS\r\n")); |
|
121 iInputStream->AppendInputStringL(_L8("* 1 FETCH (UID 18 FLAGS (\\Seen \\Recent))\r\n")); |
|
122 iInputStream->AppendInputStringL(_L8("* 2 FETCH (UID 19 FLAGS (\\Seen \\Draft \\Recent))\r\n")); |
|
123 iInputStream->AppendInputStringL(_L8("* 3 FETCH (FLAGS (\\Seen \\Deleted) UID 20)\r\n")); |
|
124 iInputStream->AppendInputStringL(_L8("3 OK completed\r\n")); |
|
125 |
|
126 RArrayMessageFlagInfo messageFlagInfo; |
|
127 iImapSession->FetchFlagsL(iActiveWaiter->iStatus, _L8("18:20"), messageFlagInfo); |
|
128 iActiveWaiter->WaitActive(); |
|
129 |
|
130 ASSERT_EQUALS(messageFlagInfo.Count(), 3); |
|
131 ASSERT_EQUALS(messageFlagInfo[0].MessageUid(), (TUint)18); |
|
132 ASSERT_TRUE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::ESeen)); |
|
133 ASSERT_FALSE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::EAnswered)); |
|
134 ASSERT_FALSE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::EFlagged)); |
|
135 ASSERT_FALSE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::EDeleted)); |
|
136 ASSERT_FALSE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::EDraft)); |
|
137 ASSERT_TRUE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::ERecent)); |
|
138 |
|
139 ASSERT_EQUALS(messageFlagInfo[1].MessageUid(), (TUint)19); |
|
140 ASSERT_TRUE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::ESeen)); |
|
141 ASSERT_FALSE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::EAnswered)); |
|
142 ASSERT_FALSE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::EFlagged)); |
|
143 ASSERT_FALSE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::EDeleted)); |
|
144 ASSERT_TRUE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::EDraft)); |
|
145 ASSERT_TRUE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::ERecent)); |
|
146 |
|
147 ASSERT_EQUALS(messageFlagInfo[2].MessageUid(), (TUint)20); |
|
148 ASSERT_TRUE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::ESeen)); |
|
149 ASSERT_FALSE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::EAnswered)); |
|
150 ASSERT_FALSE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::EFlagged)); |
|
151 ASSERT_TRUE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::EDeleted)); |
|
152 ASSERT_FALSE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::EDraft)); |
|
153 ASSERT_FALSE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::ERecent)); |
|
154 |
|
155 CImapFolderInfo* folderInfo = iImapSession->SelectedFolderInfo(); |
|
156 ASSERT_NOT_NULL(folderInfo); |
|
157 ASSERT_FALSE(folderInfo->MessageFlagsChanged()); |
|
158 |
|
159 messageFlagInfo.Reset(); |
|
160 |
|
161 INFO_PRINTF1(_L("Complete")); |
|
162 } |
|
163 |
|
164 /** |
|
165 Tests that unknown extension flags are succsfully ignored without crashing |
|
166 */ |
|
167 void CTestImapFetchFlags::TestFetchFlagsWithUnknownExtensionFlagsL() |
|
168 { |
|
169 INFO_PRINTF1(_L("TestFetchFlagsWithUnknownExtensionFlagsL")); |
|
170 iInputStream->ResetInputStrings(); |
|
171 |
|
172 iInputStream->AppendInputStringL(_L8("* 12 EXISTS\r\n")); |
|
173 // Try a couple of flag-extension's. |
|
174 iInputStream->AppendInputStringL(_L8("* 1 FETCH (UID 18 FLAGS (\\FlagExtension \\Recent))\r\n")); |
|
175 iInputStream->AppendInputStringL(_L8("* 2 FETCH (UID 19 FLAGS (\\Seen \\Unread \\Recent))\r\n")); |
|
176 // Try a flag-keyword's (defined as an atom without the forward slash) |
|
177 iInputStream->AppendInputStringL(_L8("* 3 FETCH (FLAGS (\\Seen Keyword) UID 20)\r\n")); |
|
178 iInputStream->AppendInputStringL(_L8("3 OK completed\r\n")); |
|
179 |
|
180 RArrayMessageFlagInfo messageFlagInfo; |
|
181 iImapSession->FetchFlagsL(iActiveWaiter->iStatus, _L8("18:20"), messageFlagInfo); |
|
182 iActiveWaiter->WaitActive(); |
|
183 |
|
184 ASSERT_EQUALS(messageFlagInfo.Count(), 3); |
|
185 ASSERT_EQUALS(messageFlagInfo[0].MessageUid(), (TUint)18); |
|
186 ASSERT_FALSE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::ESeen)); |
|
187 ASSERT_FALSE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::EAnswered)); |
|
188 ASSERT_FALSE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::EFlagged)); |
|
189 ASSERT_FALSE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::EDeleted)); |
|
190 ASSERT_FALSE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::EDraft)); |
|
191 ASSERT_TRUE(messageFlagInfo[0].QueryFlag(TMessageFlagInfo::ERecent)); |
|
192 |
|
193 ASSERT_EQUALS(messageFlagInfo[1].MessageUid(), (TUint)19); |
|
194 ASSERT_TRUE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::ESeen)); |
|
195 ASSERT_FALSE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::EAnswered)); |
|
196 ASSERT_FALSE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::EFlagged)); |
|
197 ASSERT_FALSE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::EDeleted)); |
|
198 ASSERT_FALSE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::EDraft)); |
|
199 ASSERT_TRUE(messageFlagInfo[1].QueryFlag(TMessageFlagInfo::ERecent)); |
|
200 |
|
201 ASSERT_EQUALS(messageFlagInfo[2].MessageUid(), (TUint)20); |
|
202 ASSERT_TRUE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::ESeen)); |
|
203 ASSERT_FALSE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::EAnswered)); |
|
204 ASSERT_FALSE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::EFlagged)); |
|
205 ASSERT_FALSE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::EDeleted)); |
|
206 ASSERT_FALSE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::EDraft)); |
|
207 ASSERT_FALSE(messageFlagInfo[2].QueryFlag(TMessageFlagInfo::ERecent)); |
|
208 |
|
209 messageFlagInfo.Reset(); |
|
210 |
|
211 INFO_PRINTF1(_L("Complete")); |
|
212 } |
|
213 |
|
214 /** |
|
215 Check that a flags response without a UID is classed as an unsolicitied |
|
216 response and is not stored in the message flag info. |
|
217 */ |
|
218 void CTestImapFetchFlags::TestFetchFlagsWithMissingUidL() |
|
219 { |
|
220 INFO_PRINTF1(_L("TestFetchFlagsWithMissingUidL")); |
|
221 |
|
222 iInputStream->ResetInputStrings(); |
|
223 iInputStream->AppendInputStringL(_L8("* 1 FETCH (FLAGS (\\Seen \\Recent))\r\n")); // Missing UID |
|
224 iInputStream->AppendInputStringL(_L8("3 OK completed\r\n")); |
|
225 |
|
226 RArrayMessageFlagInfo messageFlagInfo; |
|
227 iImapSession->FetchFlagsL(iActiveWaiter->iStatus, _L8("18:20"), messageFlagInfo); |
|
228 iActiveWaiter->WaitActive(); |
|
229 |
|
230 ASSERT_EQUALS(messageFlagInfo.Count(), 0); |
|
231 messageFlagInfo.Reset(); |
|
232 |
|
233 INFO_PRINTF1(_L("Complete")); |
|
234 } |
|
235 |
|
236 /** |
|
237 Check that corrupt data is detected without causing a panic and without hanging. |
|
238 */ |
|
239 void CTestImapFetchFlags::TestFetchFlagsCorruptMissingFlagsL() |
|
240 { |
|
241 INFO_PRINTF1(_L("TestFetchFlagsCorruptMissingFlagsL")); |
|
242 |
|
243 iInputStream->ResetInputStrings(); |
|
244 iInputStream->AppendInputStringL(_L8("* 2 FETCH (UID 19)\r\n")); // Missing FLAGS |
|
245 iInputStream->AppendInputStringL(_L8("3 OK completed\r\n")); |
|
246 |
|
247 RArrayMessageFlagInfo messageFlagInfo; |
|
248 iImapSession->FetchFlagsL(iActiveWaiter->iStatus, _L8("18:20"), messageFlagInfo); |
|
249 iActiveWaiter->WaitActive(KErrImapCorrupt); |
|
250 |
|
251 messageFlagInfo.Reset(); |
|
252 |
|
253 INFO_PRINTF1(_L("Complete")); |
|
254 } |
|
255 |
|
256 /** |
|
257 Check that corrupt data is detected without causing a panic and without hanging. |
|
258 */ |
|
259 void CTestImapFetchFlags::TestFetchFlagsCorruptNoDataItemsL() |
|
260 { |
|
261 INFO_PRINTF1(_L("TestFetchFlagsCorruptNoDataItemsL")); |
|
262 |
|
263 iInputStream->ResetInputStrings(); |
|
264 iInputStream->AppendInputStringL(_L8("* 3 FETCH ()\r\n")); // No data items |
|
265 iInputStream->AppendInputStringL(_L8("3 OK completed\r\n")); |
|
266 |
|
267 RArrayMessageFlagInfo messageFlagInfo; |
|
268 iImapSession->FetchFlagsL(iActiveWaiter->iStatus, _L8("18:20"), messageFlagInfo); |
|
269 iActiveWaiter->WaitActive(KErrImapCorrupt); |
|
270 |
|
271 messageFlagInfo.Reset(); |
|
272 |
|
273 INFO_PRINTF1(_L("Complete")); |
|
274 } |
|
275 |
|
276 /** |
|
277 Check that corrupt data is detected without causing a panic and without hanging. |
|
278 */ |
|
279 void CTestImapFetchFlags::TestFetchFlagsCorruptNoFetchDataL() |
|
280 { |
|
281 INFO_PRINTF1(_L("TestFetchFlagsCorruptNoFetchDataL")); |
|
282 iInputStream->ResetInputStrings(); |
|
283 |
|
284 iInputStream->AppendInputStringL(_L8("* 3 FETCH\r\n")); // No FETCH data at all |
|
285 iInputStream->AppendInputStringL(_L8("3 OK completed\r\n")); |
|
286 |
|
287 RArrayMessageFlagInfo messageFlagInfo; |
|
288 iImapSession->FetchFlagsL(iActiveWaiter->iStatus, _L8("18:20"), messageFlagInfo); |
|
289 iActiveWaiter->WaitActive(KErrImapCorrupt); |
|
290 |
|
291 messageFlagInfo.Reset(); |
|
292 |
|
293 INFO_PRINTF1(_L("Complete")); |
|
294 } |
|
295 |
|
296 /** |
|
297 Check that corrupt data is detected without causing a panic and without hanging. |
|
298 */ |
|
299 void CTestImapFetchFlags::TestFetchFlagsCorruptMismatchedTagL() |
|
300 { |
|
301 INFO_PRINTF1(_L("TestFetchFlagsCorruptMismatchedTagL")); |
|
302 iInputStream->ResetInputStrings(); |
|
303 |
|
304 iInputStream->AppendInputStringL(_L8("* 1 FETCH (FLAGS (\\Seen \\Recent) UID 18)\r\n")); // OK |
|
305 iInputStream->AppendInputStringL(_L8("4 OK completed\r\n")); // Mismatched |
|
306 |
|
307 RArrayMessageFlagInfo messageFlagInfo; |
|
308 iImapSession->FetchFlagsL(iActiveWaiter->iStatus, _L8("18:20"), messageFlagInfo); |
|
309 iActiveWaiter->WaitActive(KErrImapCorrupt); |
|
310 |
|
311 messageFlagInfo.Reset(); |
|
312 |
|
313 INFO_PRINTF1(_L("Complete")); |
|
314 } |
|
315 |
|
316 CTestSuite* CTestImapFetchFlags::CreateSuiteL(const TDesC& aName) |
|
317 // static |
|
318 { |
|
319 SUB_SUITE; |
|
320 ADD_ASYNC_TEST_STEP(TestFetchFlagsWithFlagsL); |
|
321 ADD_ASYNC_TEST_STEP(TestFetchFlagsWithUnknownExtensionFlagsL); |
|
322 ADD_ASYNC_TEST_STEP(TestFetchFlagsWithMissingUidL); |
|
323 ADD_ASYNC_TEST_STEP(TestFetchFlagsCorruptMissingFlagsL); |
|
324 ADD_ASYNC_TEST_STEP(TestFetchFlagsCorruptNoDataItemsL); |
|
325 ADD_ASYNC_TEST_STEP(TestFetchFlagsCorruptNoFetchDataL); |
|
326 ADD_ASYNC_TEST_STEP(TestFetchFlagsCorruptMismatchedTagL); |
|
327 END_SUITE; |
|
328 } |