|
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 "ctestimapstore.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 _LIT(KMessageIdAndFlags, "%d %S"); |
|
28 |
|
29 CTestImapStore::CTestImapStore() |
|
30 : iInputStream(NULL) |
|
31 , iOutputStream(NULL) |
|
32 , iActiveWaiter(NULL) |
|
33 , iImapSession(NULL) |
|
34 {} |
|
35 |
|
36 CTestImapStore::~CTestImapStore() |
|
37 { |
|
38 delete iImapSession; |
|
39 delete iActiveWaiter; |
|
40 delete iOutputStream; |
|
41 delete iInputStream; |
|
42 CImapUtils::Delete(); |
|
43 } |
|
44 |
|
45 void CTestImapStore::SetupL() |
|
46 { |
|
47 ASSERT(iInputStream == NULL); |
|
48 ASSERT(iOutputStream == NULL); |
|
49 ASSERT(iActiveWaiter == NULL); |
|
50 ASSERT(iImapSession == NULL); |
|
51 |
|
52 CImapUtils::CreateL(); |
|
53 iInputStream = CFakeInputStream::NewL(Logger()); |
|
54 iOutputStream = CFakeOutputStream::NewL(Logger()); |
|
55 iActiveWaiter = new(ELeave)CActiveWaiter(Logger()); |
|
56 |
|
57 CImapSettings* imapSettings=NULL; |
|
58 CImapMailStore* imapMailStore=NULL; |
|
59 |
|
60 iImapSession = CImapSession::NewL(*imapSettings,*imapMailStore,*iInputStream, *iOutputStream); |
|
61 |
|
62 INFO_PRINTF1(_L("Setup: ServerGreeting")); |
|
63 iInputStream->ResetInputStrings(); |
|
64 iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n")); |
|
65 |
|
66 ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState()); |
|
67 |
|
68 iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus); |
|
69 iActiveWaiter->WaitActive(); |
|
70 |
|
71 INFO_PRINTF1(_L("...Login")); |
|
72 iInputStream->ResetInputStrings(); |
|
73 iInputStream->AppendInputStringL(_L8("1 OK LOGIN completed\r\n")); |
|
74 |
|
75 iImapSession->LoginL(iActiveWaiter->iStatus, _L8("username"), _L8("password")); |
|
76 iActiveWaiter->WaitActive(); |
|
77 |
|
78 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
79 |
|
80 |
|
81 INFO_PRINTF1(_L("...Select inbox")); |
|
82 iInputStream->ResetInputStrings(); |
|
83 iInputStream->AppendInputStringL(_L8("2 OK [READ-WRITE] SELECT completed\r\n")); |
|
84 |
|
85 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
86 CleanupStack::PushL(folderInfo); |
|
87 |
|
88 folderInfo->SetNameL(_L16("inbox")); |
|
89 CleanupStack::Pop(folderInfo); |
|
90 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
91 iActiveWaiter->WaitActive(); |
|
92 |
|
93 ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState()); |
|
94 ASSERT_EQUALS(folderInfo, iImapSession->SelectedFolderInfo()); |
|
95 folderInfo = NULL; |
|
96 } |
|
97 |
|
98 void CTestImapStore::TearDownL() |
|
99 { |
|
100 delete iImapSession; |
|
101 iImapSession = NULL; |
|
102 |
|
103 delete iActiveWaiter; |
|
104 iActiveWaiter = NULL; |
|
105 |
|
106 delete iOutputStream; |
|
107 iOutputStream = NULL; |
|
108 |
|
109 delete iInputStream; |
|
110 iInputStream = NULL; |
|
111 |
|
112 CImapUtils::Delete(); |
|
113 } |
|
114 |
|
115 // Tests |
|
116 void CTestImapStore::TestStoreWithFlagsL() |
|
117 { |
|
118 INFO_PRINTF1(_L("TestStoreWithFlagsL")); |
|
119 iInputStream->ResetInputStrings(); |
|
120 iInputStream->AppendInputStringL(_L8("* 2 FETCH (FLAGS (\\Deleted \\Seen) UID 2)\r\n")); |
|
121 iInputStream->AppendInputStringL(_L8("* 3 FETCH (FLAGS (\\Deleted) UID 3)\r\n")); |
|
122 iInputStream->AppendInputStringL(_L8("* 4 FETCH (FLAGS (\\Deleted \\Flagged \\Seen) UID 4)\r\n")); |
|
123 iInputStream->AppendInputStringL(_L8("* 5 FETCH (FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft) UID 5)\r\n")); |
|
124 iInputStream->AppendInputStringL(_L8("* 6 FETCH (FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft))\r\n")); |
|
125 iInputStream->AppendInputStringL(_L8("3 OK STORE completed\r\n")); |
|
126 |
|
127 RArrayMessageFlagInfo messageFlagInfo; |
|
128 iImapSession->StoreL(iActiveWaiter->iStatus, _L8("2:5"), _L8("+FLAGS"), _L8("(Deleted)"), 0, messageFlagInfo); |
|
129 iActiveWaiter->WaitActive(); |
|
130 |
|
131 INFO_PRINTF1(_L("FLAGS LIST")); |
|
132 |
|
133 TInt countMessageFlagInfo = messageFlagInfo.Count(); |
|
134 ASSERT_EQUALS(countMessageFlagInfo, 4); |
|
135 |
|
136 for (TInt i = 0; i < countMessageFlagInfo; ++i) |
|
137 { |
|
138 // create account Id |
|
139 TMessageFlagInfo entry = messageFlagInfo[i]; |
|
140 TUint messageUid = entry.MessageUid(); |
|
141 TBuf<100> mesageUidAndFlags; |
|
142 TPtrC flag; |
|
143 if (entry.QueryFlag(TMessageFlagInfo::EDeleted) && entry.QueryFlag(TMessageFlagInfo::EFlagged) |
|
144 && entry.QueryFlag(TMessageFlagInfo::ESeen) && entry.QueryFlag(TMessageFlagInfo::EDraft) && entry.QueryFlag(TMessageFlagInfo::EAnswered)) |
|
145 { |
|
146 // Check the other flags are false |
|
147 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::ERecent)); |
|
148 |
|
149 // Check that this is the expected entry |
|
150 ASSERT_EQUALS(i, 3); |
|
151 |
|
152 flag.Set(_L("Answered Flagged Deleted Seen Draft")); |
|
153 mesageUidAndFlags.AppendFormat(KMessageIdAndFlags, messageUid, &flag); |
|
154 INFO_PRINTF1(mesageUidAndFlags); |
|
155 } |
|
156 else if (entry.QueryFlag(TMessageFlagInfo::EDeleted) && entry.QueryFlag(TMessageFlagInfo::EFlagged) && entry.QueryFlag(TMessageFlagInfo::ESeen)) |
|
157 { |
|
158 // Check the other flags are false |
|
159 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::EAnswered)); |
|
160 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::EDraft)); |
|
161 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::ERecent)); |
|
162 |
|
163 // Check that this is the expected entry |
|
164 ASSERT_EQUALS(i, 2); |
|
165 |
|
166 flag.Set(_L("Deleted Flagged Seen")); |
|
167 mesageUidAndFlags.AppendFormat(KMessageIdAndFlags, messageUid, &flag); |
|
168 INFO_PRINTF1(mesageUidAndFlags); |
|
169 } |
|
170 else if (entry.QueryFlag(TMessageFlagInfo::EDeleted) && entry.QueryFlag(TMessageFlagInfo::ESeen)) |
|
171 { |
|
172 // Check the other flags are false |
|
173 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::EAnswered)); |
|
174 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::EFlagged)); |
|
175 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::EDraft)); |
|
176 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::ERecent)); |
|
177 |
|
178 // Check that this is the expected entry |
|
179 ASSERT_EQUALS(i, 0); |
|
180 |
|
181 flag.Set(_L("Deleted Seen")); |
|
182 mesageUidAndFlags.AppendFormat(KMessageIdAndFlags, messageUid, &flag); |
|
183 INFO_PRINTF1(mesageUidAndFlags); |
|
184 } |
|
185 else if (entry.QueryFlag(TMessageFlagInfo::EDeleted)) |
|
186 { |
|
187 // Check the other flags are false |
|
188 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::ESeen)); |
|
189 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::EAnswered)); |
|
190 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::EFlagged)); |
|
191 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::EDraft)); |
|
192 ASSERT_FALSE(entry.QueryFlag(TMessageFlagInfo::ERecent)); |
|
193 |
|
194 // Check that this is the expected entry |
|
195 ASSERT_EQUALS(i, 1); |
|
196 |
|
197 flag.Set(_L("Deleted")); |
|
198 mesageUidAndFlags.AppendFormat(KMessageIdAndFlags, messageUid, &flag); |
|
199 INFO_PRINTF1(mesageUidAndFlags); |
|
200 } |
|
201 } |
|
202 messageFlagInfo.Reset(); |
|
203 messageFlagInfo.Close(); |
|
204 INFO_PRINTF1(_L("Complete")); |
|
205 } |
|
206 |
|
207 CTestSuite* CTestImapStore::CreateSuiteL(const TDesC& aName) |
|
208 // static |
|
209 { |
|
210 SUB_SUITE; |
|
211 ADD_ASYNC_TEST_STEP(TestStoreWithFlagsL); |
|
212 END_SUITE; |
|
213 } |