|
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 // ctestimapcommnad.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "ctestimapcommand.h" |
|
19 |
|
20 #include "cfakeinputstream.h" |
|
21 #include "cfakeoutputstream.h" |
|
22 #include "cactivewaiter.h" |
|
23 |
|
24 #include "moutputstream.h" |
|
25 |
|
26 #include "cimapsession.h" |
|
27 #include "cimapsessionconsts.h" |
|
28 #include "cimaputils.h" |
|
29 |
|
30 CTestImapCommand::CTestImapCommand() |
|
31 : iInputStream(NULL) |
|
32 , iOutputStream(NULL) |
|
33 , iActiveWaiter(NULL) |
|
34 , iImapSession(NULL) |
|
35 {} |
|
36 |
|
37 CTestImapCommand::~CTestImapCommand() |
|
38 { |
|
39 delete iImapSession; |
|
40 delete iActiveWaiter; |
|
41 delete iOutputStream; |
|
42 delete iInputStream; |
|
43 CImapUtils::Delete(); |
|
44 } |
|
45 |
|
46 void CTestImapCommand::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 SetupServerGreetingL(); |
|
64 } |
|
65 |
|
66 void CTestImapCommand::TearDownL() |
|
67 { |
|
68 delete iImapSession; |
|
69 iImapSession = NULL; |
|
70 |
|
71 delete iActiveWaiter; |
|
72 iActiveWaiter = NULL; |
|
73 |
|
74 delete iOutputStream; |
|
75 iOutputStream = NULL; |
|
76 |
|
77 delete iInputStream; |
|
78 iInputStream = NULL; |
|
79 |
|
80 CImapUtils::Delete(); |
|
81 } |
|
82 |
|
83 void CTestImapCommand::SetupServerGreetingL() |
|
84 { |
|
85 INFO_PRINTF1(_L("Setup: ServerGreeting")); |
|
86 iInputStream->ResetInputStrings(); |
|
87 iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n")); |
|
88 |
|
89 ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState()); |
|
90 |
|
91 iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus); |
|
92 iActiveWaiter->WaitActive(); |
|
93 |
|
94 ASSERT_EQUALS(CImapSession::EServerStateNotAuthenticated, iImapSession->ServerState()); |
|
95 |
|
96 INFO_PRINTF1(_L("Setup: Complete")); |
|
97 } |
|
98 |
|
99 // Tests |
|
100 void CTestImapCommand::TestTaggedOkOnlyL() |
|
101 { |
|
102 INFO_PRINTF1(_L("TestTaggedOkOnlyL")); |
|
103 |
|
104 iInputStream->ResetInputStrings(); |
|
105 iInputStream->AppendInputStringL(_L8("1 OK LOGOUT completed\r\n")); |
|
106 |
|
107 iImapSession->LogoutL(iActiveWaiter->iStatus); |
|
108 iActiveWaiter->WaitActive(); |
|
109 |
|
110 INFO_PRINTF1(_L("Complete")); |
|
111 } |
|
112 |
|
113 void CTestImapCommand::TestTaggedNoL() |
|
114 { |
|
115 INFO_PRINTF1(_L("TestTaggedNoL")); |
|
116 |
|
117 iInputStream->ResetInputStrings(); |
|
118 iInputStream->AppendInputStringL(_L8("1 NO LOGOUT not allowed right now\r\n")); |
|
119 |
|
120 iImapSession->LogoutL(iActiveWaiter->iStatus); |
|
121 iActiveWaiter->WaitActive(KErrImapNo); |
|
122 |
|
123 INFO_PRINTF1(_L("Complete")); |
|
124 } |
|
125 |
|
126 void CTestImapCommand::TestTaggedBadL() |
|
127 { |
|
128 INFO_PRINTF1(_L("TestTaggedBadL")); |
|
129 |
|
130 iInputStream->ResetInputStrings(); |
|
131 iInputStream->AppendInputStringL(_L8("1 BAD malformed just testing\r\n")); |
|
132 |
|
133 iImapSession->LogoutL(iActiveWaiter->iStatus); |
|
134 iActiveWaiter->WaitActive(KErrImapBad); |
|
135 |
|
136 INFO_PRINTF1(_L("Complete")); |
|
137 } |
|
138 |
|
139 void CTestImapCommand::TestKnownThenTaggedOkL() |
|
140 { |
|
141 INFO_PRINTF1(_L("TestKnownThenTaggedOkL")); |
|
142 |
|
143 iInputStream->ResetInputStrings(); |
|
144 iInputStream->AppendInputStringL(_L8("* BYE IMAP4rev1 Server logging out\r\n")); |
|
145 iInputStream->AppendInputStringL(_L8("1 OK LOGOUT completed\r\n")); |
|
146 |
|
147 iImapSession->LogoutL(iActiveWaiter->iStatus); |
|
148 iActiveWaiter->WaitActive(); |
|
149 |
|
150 INFO_PRINTF1(_L("Complete")); |
|
151 } |
|
152 |
|
153 void CTestImapCommand::TestUnilateralThenTaggedOkL() |
|
154 { |
|
155 INFO_PRINTF1(_L("TestUnilateralThenTaggedOkL")); |
|
156 |
|
157 iInputStream->ResetInputStrings(); |
|
158 iInputStream->AppendInputStringL(_L8("* 23 EXISTS\r\n")); |
|
159 iInputStream->AppendInputStringL(_L8("1 OK LOGOUT completed\r\n")); |
|
160 |
|
161 iImapSession->LogoutL(iActiveWaiter->iStatus); |
|
162 iActiveWaiter->WaitActive(); |
|
163 |
|
164 INFO_PRINTF1(_L("Complete")); |
|
165 } |
|
166 |
|
167 void CTestImapCommand::TestUnknownLineThenTaggedOkL() |
|
168 { |
|
169 INFO_PRINTF1(_L("TestUnknownLineThenTaggedOkL")); |
|
170 |
|
171 iInputStream->ResetInputStrings(); |
|
172 // Emulates a one-line extension response |
|
173 iInputStream->AppendInputStringL(_L8("* XWIBBLE wobble\r\n")); |
|
174 iInputStream->AppendInputStringL(_L8("1 OK LOGOUT completed\r\n")); |
|
175 |
|
176 iImapSession->LogoutL(iActiveWaiter->iStatus); |
|
177 iActiveWaiter->WaitActive(); |
|
178 |
|
179 INFO_PRINTF1(_L("Complete")); |
|
180 } |
|
181 |
|
182 void CTestImapCommand::TestUnknownLiteralThenTaggedOkL() |
|
183 { |
|
184 INFO_PRINTF1(_L("TestUnknownLiteralThenTaggedOkL")); |
|
185 |
|
186 iInputStream->ResetInputStrings(); |
|
187 // Emulates a server-pushed FETCH (which we don't handle) |
|
188 iInputStream->AppendInputStringL(_L8("* 1 FETCH (BODY[1]<0> {19}\r\n")); |
|
189 iInputStream->AppendInputStringL(_L8("a small test body\r\n")); |
|
190 iInputStream->AppendInputStringL(_L8("UID 2717 FLAGS (\\Seen))\r\n")); |
|
191 iInputStream->AppendInputStringL(_L8("1 OK LOGOUT completed\r\n")); |
|
192 |
|
193 iImapSession->LogoutL(iActiveWaiter->iStatus); |
|
194 iActiveWaiter->WaitActive(); |
|
195 |
|
196 INFO_PRINTF1(_L("Complete")); |
|
197 } |
|
198 |
|
199 void CTestImapCommand::TestUnknownMultiLiteralThenTaggedOkL() |
|
200 { |
|
201 INFO_PRINTF1(_L("TestUnknownMultiLiteralThenTaggedOkL")); |
|
202 // Emulates a server-pushed FETCH (which we don't handle), with two literals |
|
203 iInputStream->ResetInputStrings(); |
|
204 iInputStream->AppendInputStringL(_L8("* 1 FETCH (BODY[1]<0> {19}\r\n")); |
|
205 iInputStream->AppendInputStringL(_L8("a small test body\r\n")); |
|
206 iInputStream->AppendInputStringL(_L8(" BODY[1.MIME] {766}\r\n")); |
|
207 iInputStream->AppendInputStringL(_L8("Received: from LONDAVIDS02 ([10.23.152.33]) by msexchange2k.closedtest.intra with Microsoft SMTPSVC(5.0.2195.6713);\r\n")); |
|
208 iInputStream->AppendInputStringL(_L8(" Wed, 22 Mar 2006 14:43:56 +0000\r\n")); |
|
209 iInputStream->AppendInputStringL(_L8("Message-ID: <001901c64dbf$c42ec6d0$0100a8c0@intra>\r\n")); |
|
210 iInputStream->AppendInputStringL(_L8("From: \"IMAP\" <davids@msexchange2k.closedtest.intra>\r\n")); |
|
211 iInputStream->AppendInputStringL(_L8("To: \"David Test Account\" <davids@msexchange2k.closedtest.intra>\r\n")); |
|
212 iInputStream->AppendInputStringL(_L8("Subject: t1\r\n")); |
|
213 iInputStream->AppendInputStringL(_L8("Date: Wed, 22 Mar 2006 14:49:05 -0000\r\n")); |
|
214 iInputStream->AppendInputStringL(_L8("MIME-Version: 1.0\r\n")); |
|
215 iInputStream->AppendInputStringL(_L8("Content-Type: text/plain;\r\n")); |
|
216 iInputStream->AppendInputStringL(_L8(" charset=\"iso-8859-1\"\r\n")); |
|
217 iInputStream->AppendInputStringL(_L8("Content-Transfer-Encoding: 7bit\r\n")); |
|
218 iInputStream->AppendInputStringL(_L8("X-Priority: 3\r\n")); |
|
219 iInputStream->AppendInputStringL(_L8("X-MSMail-Priority: Normal\r\n")); |
|
220 iInputStream->AppendInputStringL(_L8("X-Mailer: Microsoft Outlook Express 6.00.2800.1506\r\n")); |
|
221 iInputStream->AppendInputStringL(_L8("X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506\r\n")); |
|
222 iInputStream->AppendInputStringL(_L8("Return-Path: davids@msexchange2k.closedtest.intra\r\n")); |
|
223 iInputStream->AppendInputStringL(_L8("X-OriginalArrivalTime: 22 Mar 2006 14:43:56.0562 (UTC) FILETIME=[0C365F20:01C64DBF]\r\n")); |
|
224 iInputStream->AppendInputStringL(_L8("\r\n")); |
|
225 iInputStream->AppendInputStringL(_L8(" UID 2717 FLAGS (\\Seen))\r\n")); |
|
226 // Let's have an extra (known) untagged response, too |
|
227 iInputStream->AppendInputStringL(_L8("* BYE IMAP4rev1 Server logging out\r\n")); |
|
228 // And finally, the tagged response |
|
229 iInputStream->AppendInputStringL(_L8("1 OK LOGOUT completed\r\n")); |
|
230 |
|
231 iImapSession->LogoutL(iActiveWaiter->iStatus); |
|
232 iActiveWaiter->WaitActive(); |
|
233 |
|
234 // Not in the selected state, so not folder info |
|
235 CImapFolderInfo* folderInfo = iImapSession->SelectedFolderInfo(); |
|
236 ASSERT_NULL(folderInfo); |
|
237 |
|
238 INFO_PRINTF1(_L("Complete")); |
|
239 } |
|
240 |
|
241 void CTestImapCommand::TestEncodeMailboxsL() |
|
242 { |
|
243 INFO_PRINTF1(_L("TestEncodeMailboxL")); |
|
244 |
|
245 DoTestEncodeMailboxL(_L16("inbox"), _L8("inbox")); |
|
246 DoTestEncodeMailboxL(_L16("inbox/folder"), _L8("inbox/folder")); |
|
247 DoTestEncodeMailboxL(_L16("inbox\\folder"), _L8("\"inbox\\\\folder\"")); |
|
248 DoTestEncodeMailboxL(_L16("my folder"), _L8("\"my folder\"")); |
|
249 DoTestEncodeMailboxL(_L16("daft folder name with \"newline\"\r\nand a smily face \x263a symbol"), _L8("\"daft folder name with \\\"newline\\\"&AA0ACg-and a smily face &Jjo- symbol\"")); |
|
250 DoTestEncodeMailboxL(_L16("bits&pieces"), _L8("bits&-pieces")); |
|
251 DoTestEncodeMailboxL(_L16("smiley:\x263a"), _L8("smiley:&Jjo-")); |
|
252 DoTestEncodeMailboxL(_L16("folder[square]"), _L8("\"folder[square]\"")); |
|
253 DoTestEncodeMailboxL(_L16("toplevel"), _L8("toplevel")); |
|
254 |
|
255 INFO_PRINTF1(_L("Complete")); |
|
256 } |
|
257 |
|
258 void CTestImapCommand::DoTestEncodeMailboxL(const TDesC16& aUnicode, const TDesC8& aExpectedEncoding) |
|
259 { |
|
260 HBufC8* encodedMailbox = CImapCommand::EncodeMailboxNameForSendL(aUnicode); |
|
261 CleanupStack::PushL(encodedMailbox); |
|
262 |
|
263 ASSERT_EQUALS((const TDesC8&)*encodedMailbox, aExpectedEncoding); |
|
264 |
|
265 CleanupStack::PopAndDestroy(); |
|
266 } |
|
267 |
|
268 CTestSuite* CTestImapCommand::CreateSuiteL(const TDesC& aName) |
|
269 // static |
|
270 { |
|
271 SUB_SUITE; |
|
272 ADD_ASYNC_TEST_STEP(TestTaggedOkOnlyL); |
|
273 ADD_ASYNC_TEST_STEP(TestTaggedNoL); |
|
274 ADD_ASYNC_TEST_STEP(TestTaggedBadL); |
|
275 ADD_ASYNC_TEST_STEP(TestKnownThenTaggedOkL); |
|
276 ADD_ASYNC_TEST_STEP(TestUnilateralThenTaggedOkL); |
|
277 ADD_ASYNC_TEST_STEP(TestUnknownLineThenTaggedOkL); |
|
278 ADD_ASYNC_TEST_STEP(TestUnknownLiteralThenTaggedOkL); |
|
279 ADD_ASYNC_TEST_STEP(TestUnknownMultiLiteralThenTaggedOkL); |
|
280 ADD_ASYNC_TEST_STEP(TestEncodeMailboxsL); |
|
281 END_SUITE; |
|
282 } |