|
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 "ctestimapnoop.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 "cimaputils.h" |
|
25 #include "cimapfolderinfo.h" |
|
26 |
|
27 CTestImapNoop::CTestImapNoop() |
|
28 : iInputStream(NULL) |
|
29 , iOutputStream(NULL) |
|
30 , iActiveWaiter(NULL) |
|
31 , iImapSession(NULL) |
|
32 {} |
|
33 |
|
34 CTestImapNoop::~CTestImapNoop() |
|
35 { |
|
36 delete iImapSession; |
|
37 delete iActiveWaiter; |
|
38 delete iOutputStream; |
|
39 delete iInputStream; |
|
40 CImapUtils::Delete(); |
|
41 } |
|
42 |
|
43 void CTestImapNoop::SetupL() |
|
44 { |
|
45 ASSERT(iInputStream == NULL); |
|
46 ASSERT(iOutputStream == NULL); |
|
47 ASSERT(iActiveWaiter == NULL); |
|
48 ASSERT(iImapSession == NULL); |
|
49 |
|
50 CImapUtils::CreateL(); |
|
51 iInputStream = CFakeInputStream::NewL(Logger()); |
|
52 iOutputStream = CFakeOutputStream::NewL(Logger()); |
|
53 iActiveWaiter = new(ELeave)CActiveWaiter(Logger()); |
|
54 |
|
55 CImapSettings* imapSettings=NULL; |
|
56 CImapMailStore* imapMailStore=NULL; |
|
57 |
|
58 iImapSession = CImapSession::NewL(*imapSettings,*imapMailStore,*iInputStream, *iOutputStream); |
|
59 |
|
60 INFO_PRINTF1(_L("Setup: ServerGreeting")); |
|
61 iInputStream->ResetInputStrings(); |
|
62 iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n")); |
|
63 |
|
64 ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState()); |
|
65 |
|
66 iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus); |
|
67 iActiveWaiter->WaitActive(); |
|
68 |
|
69 INFO_PRINTF1(_L("...Login")); |
|
70 iInputStream->ResetInputStrings(); |
|
71 iInputStream->AppendInputStringL(_L8("1 OK LOGIN completed\r\n")); |
|
72 |
|
73 iImapSession->LoginL(iActiveWaiter->iStatus, _L8("username"), _L8("password")); |
|
74 iActiveWaiter->WaitActive(); |
|
75 |
|
76 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
77 |
|
78 |
|
79 INFO_PRINTF1(_L("...Select inbox")); |
|
80 iInputStream->ResetInputStrings(); |
|
81 iInputStream->AppendInputStringL(_L8("* 23 EXISTS\r\n")); |
|
82 iInputStream->AppendInputStringL(_L8("* 1 RECENT\r\n")); |
|
83 iInputStream->AppendInputStringL(_L8("* OK [UNSEEN 12] Message 12 is first unseen\r\n")); |
|
84 iInputStream->AppendInputStringL(_L8("* OK [UIDVALIDITY 3857529045] UIDs valid\r\n")); |
|
85 iInputStream->AppendInputStringL(_L8("2 OK [READ-WRITE] SELECT completed\r\n")); |
|
86 |
|
87 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
88 CleanupStack::PushL(folderInfo); |
|
89 |
|
90 folderInfo->SetNameL(_L16("inbox")); |
|
91 CleanupStack::Pop(folderInfo); |
|
92 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
93 iActiveWaiter->WaitActive(); |
|
94 |
|
95 ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState()); |
|
96 ASSERT_EQUALS(folderInfo, iImapSession->SelectedFolderInfo()); |
|
97 |
|
98 ResetFolderInfo(*folderInfo); |
|
99 folderInfo = NULL; |
|
100 } |
|
101 |
|
102 void CTestImapNoop::TearDownL() |
|
103 { |
|
104 delete iImapSession; |
|
105 iImapSession = NULL; |
|
106 |
|
107 delete iActiveWaiter; |
|
108 iActiveWaiter = NULL; |
|
109 |
|
110 delete iOutputStream; |
|
111 iOutputStream = NULL; |
|
112 |
|
113 delete iInputStream; |
|
114 iInputStream = NULL; |
|
115 |
|
116 CImapUtils::Delete(); |
|
117 } |
|
118 |
|
119 // Tests |
|
120 void CTestImapNoop::TestNoopWithFlagsL() |
|
121 { |
|
122 INFO_PRINTF1(_L("TestNoopWithFlagsL")); |
|
123 iInputStream->ResetInputStrings(); |
|
124 iInputStream->AppendInputStringL(_L8("* 22 EXPUNGE\r\n")); |
|
125 iInputStream->AppendInputStringL(_L8("* 23 EXISTS\r\n")); |
|
126 iInputStream->AppendInputStringL(_L8("* 3 RECENT\r\n")); |
|
127 iInputStream->AppendInputStringL(_L8("* 14 FETCH (FLAGS (Seen Deleted))\r\n")); |
|
128 iInputStream->AppendInputStringL(_L8("3 OK NOOP completed\r\n")); |
|
129 |
|
130 iImapSession->NoopL(iActiveWaiter->iStatus); |
|
131 iActiveWaiter->WaitActive(); |
|
132 |
|
133 INFO_PRINTF1(_L("NOOP Response")); |
|
134 |
|
135 CImapFolderInfo* folderInfo = iImapSession->SelectedFolderInfo(); |
|
136 ASSERT_NOT_NULL(folderInfo); |
|
137 |
|
138 TPtrC flag; |
|
139 RArray <TUint> expungedMessages = folderInfo->ExpungedMessages(); |
|
140 ASSERT_EQUALS(expungedMessages.Count(), 1); |
|
141 ASSERT_EQUALS(expungedMessages[0], 22u); |
|
142 ASSERT_EQUALS(folderInfo->Exists(), 23); |
|
143 ASSERT_EQUALS(folderInfo->Recent(), 3); |
|
144 ASSERT_TRUE(folderInfo->MessageFlagsChanged()); |
|
145 |
|
146 INFO_PRINTF1(_L("Complete")); |
|
147 } |
|
148 |
|
149 void CTestImapNoop::TestNoopWithoutFlagsL() |
|
150 { |
|
151 INFO_PRINTF1(_L("TestNoopWithoutFlagsL")); |
|
152 iInputStream->ResetInputStrings(); |
|
153 iInputStream->AppendInputStringL(_L8("* 12 EXPUNGE\r\n")); |
|
154 iInputStream->AppendInputStringL(_L8("* 10 EXPUNGE\r\n")); |
|
155 iInputStream->AppendInputStringL(_L8("3 OK NOOP completed\r\n")); |
|
156 |
|
157 iImapSession->NoopL(iActiveWaiter->iStatus); |
|
158 iActiveWaiter->WaitActive(); |
|
159 |
|
160 INFO_PRINTF1(_L("NOOP Response")); |
|
161 |
|
162 CImapFolderInfo* folderInfo = iImapSession->SelectedFolderInfo(); |
|
163 ASSERT_NOT_NULL(folderInfo); |
|
164 |
|
165 TPtrC flag; |
|
166 RArray <TUint> expungedMessages = folderInfo->ExpungedMessages(); |
|
167 ASSERT_EQUALS(expungedMessages.Count(), 2); |
|
168 ASSERT_EQUALS(expungedMessages[0], 12u); |
|
169 ASSERT_EQUALS(expungedMessages[1], 10u); |
|
170 ASSERT_EQUALS(folderInfo->Exists(), 21); // select said there were 23 but now 2 have been expunged. |
|
171 ASSERT_EQUALS(folderInfo->Recent(), 0); |
|
172 ASSERT_FALSE(folderInfo->MessageFlagsChanged()); |
|
173 |
|
174 INFO_PRINTF1(_L("Complete")); |
|
175 } |
|
176 |
|
177 /** |
|
178 Protocol Controller resets folder info after a sync, so that it can detect changes received later |
|
179 */ |
|
180 void CTestImapNoop::ResetFolderInfo(CImapFolderInfo& folderInfo) |
|
181 { |
|
182 folderInfo.ResetExpungedMessages(); |
|
183 folderInfo.SetRecent(0); |
|
184 folderInfo.SetMessageFlagsChanged(EFalse); |
|
185 } |
|
186 |
|
187 CTestSuite* CTestImapNoop::CreateSuiteL(const TDesC& aName) |
|
188 // static |
|
189 { |
|
190 SUB_SUITE; |
|
191 ADD_ASYNC_TEST_STEP(TestNoopWithFlagsL); |
|
192 ADD_ASYNC_TEST_STEP(TestNoopWithoutFlagsL); |
|
193 END_SUITE; |
|
194 } |