|
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 "ctestimapexpunge.h" |
|
17 |
|
18 #include "cfakeinputstream.h" |
|
19 #include "cfakeoutputstream.h" |
|
20 #include "cactivewaiter.h" |
|
21 #include "moutputstream.h" |
|
22 #include "cimapsession.h" |
|
23 #include "cimaputils.h" |
|
24 #include "cimapfolderinfo.h" |
|
25 |
|
26 CTestImapExpunge::CTestImapExpunge() |
|
27 : iInputStream(NULL) |
|
28 , iOutputStream(NULL) |
|
29 , iActiveWaiter(NULL) |
|
30 , iImapSession(NULL) |
|
31 {} |
|
32 |
|
33 CTestImapExpunge::~CTestImapExpunge() |
|
34 { |
|
35 delete iImapSession; |
|
36 delete iActiveWaiter; |
|
37 delete iOutputStream; |
|
38 delete iInputStream; |
|
39 CImapUtils::Delete(); |
|
40 } |
|
41 |
|
42 void CTestImapExpunge::SetupL() |
|
43 { |
|
44 ASSERT(iInputStream == NULL); |
|
45 ASSERT(iOutputStream == NULL); |
|
46 ASSERT(iActiveWaiter == NULL); |
|
47 ASSERT(iImapSession == NULL); |
|
48 |
|
49 CImapUtils::CreateL(); |
|
50 iInputStream = CFakeInputStream::NewL(Logger()); |
|
51 iOutputStream = CFakeOutputStream::NewL(Logger()); |
|
52 iActiveWaiter = new(ELeave)CActiveWaiter(Logger()); |
|
53 |
|
54 CImapSettings* imapSettings=NULL; |
|
55 CImapMailStore* imapMailStore=NULL; |
|
56 |
|
57 iImapSession = CImapSession::NewL(*imapSettings,*imapMailStore,*iInputStream, *iOutputStream); |
|
58 |
|
59 INFO_PRINTF1(_L("Setup: ServerGreeting")); |
|
60 iInputStream->ResetInputStrings(); |
|
61 iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n")); |
|
62 |
|
63 ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState()); |
|
64 |
|
65 iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus); |
|
66 iActiveWaiter->WaitActive(); |
|
67 |
|
68 INFO_PRINTF1(_L("...Login")); |
|
69 iInputStream->ResetInputStrings(); |
|
70 iInputStream->AppendInputStringL(_L8("1 OK LOGIN completed\r\n")); |
|
71 |
|
72 iImapSession->LoginL(iActiveWaiter->iStatus, _L8("username"), _L8("password")); |
|
73 iActiveWaiter->WaitActive(); |
|
74 |
|
75 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
76 |
|
77 |
|
78 INFO_PRINTF1(_L("...Select inbox")); |
|
79 iInputStream->ResetInputStrings(); |
|
80 iInputStream->AppendInputStringL(_L8("* 23 EXISTS\r\n")); |
|
81 iInputStream->AppendInputStringL(_L8("* 1 RECENT\r\n")); |
|
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 |
|
95 INFO_PRINTF1(_L("Setup: Complete")); |
|
96 } |
|
97 |
|
98 void CTestImapExpunge::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 CTestImapExpunge::TestExpungeL() |
|
117 { |
|
118 INFO_PRINTF1(_L("TestExpungeL")); |
|
119 iInputStream->ResetInputStrings(); |
|
120 |
|
121 iInputStream->AppendInputStringL(_L8("* 3 EXPUNGE\r\n")); |
|
122 iInputStream->AppendInputStringL(_L8("* 3 EXPUNGE\r\n")); |
|
123 iInputStream->AppendInputStringL(_L8("* 5 EXPUNGE\r\n")); |
|
124 iInputStream->AppendInputStringL(_L8("3 OK Expunge completed\r\n")); |
|
125 |
|
126 iImapSession->ExpungeL(iActiveWaiter->iStatus); |
|
127 iActiveWaiter->WaitActive(); |
|
128 |
|
129 CImapFolderInfo* folderInfo = iImapSession->SelectedFolderInfo(); |
|
130 ASSERT_NOT_NULL(folderInfo); |
|
131 |
|
132 RArray<TUint> expungedMessages = folderInfo->ExpungedMessages(); |
|
133 |
|
134 ASSERT_EQUALS(expungedMessages.Count(), 3); |
|
135 ASSERT_EQUALS(expungedMessages[0], 3u); // unsigned 3 (etc) |
|
136 ASSERT_EQUALS(expungedMessages[1], 3u); |
|
137 ASSERT_EQUALS(expungedMessages[2], 5u); |
|
138 |
|
139 INFO_PRINTF1(_L("Complete")); |
|
140 } |
|
141 |
|
142 CTestSuite* CTestImapExpunge::CreateSuiteL(const TDesC& aName) |
|
143 // static |
|
144 { |
|
145 SUB_SUITE; |
|
146 ADD_ASYNC_TEST_STEP(TestExpungeL); |
|
147 END_SUITE; |
|
148 } |