|
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 "ctestimapsyncmanager.h" |
|
17 |
|
18 #include "cactivewaiter.h" |
|
19 #include "moutputstream.h" |
|
20 #include "cimapsettings.h" |
|
21 |
|
22 #define KSyncLimit 10 |
|
23 |
|
24 _LIT(KImapSyncManagerTest,"test"); |
|
25 RTest test(KImapSyncManagerTest); |
|
26 |
|
27 _LIT(KImapServer, "msexchange2k.closedtest.intra"); |
|
28 |
|
29 #if defined (__WINS__) |
|
30 #define PDD_NAME _L("ECDRV") |
|
31 #define LDD_NAME _L("ECOMM") |
|
32 #else |
|
33 #define PDD_NAME _L("EUART1") |
|
34 #define LDD_NAME _L("ECOMM") |
|
35 #endif |
|
36 |
|
37 |
|
38 CTestImapSyncManager::CTestImapSyncManager() |
|
39 : iActiveWaiter(NULL), |
|
40 iTestUtils( NULL ) |
|
41 {} |
|
42 |
|
43 CTestImapSyncManager::~CTestImapSyncManager() |
|
44 { |
|
45 delete iSel; |
|
46 delete iImapSettings1; |
|
47 delete iImapSettings; |
|
48 delete iActiveWaiter; |
|
49 iActiveWaiter = NULL; |
|
50 delete iTestUtils; |
|
51 iTestUtils = NULL; |
|
52 } |
|
53 |
|
54 void CTestImapSyncManager::SetupL() |
|
55 { |
|
56 TInt err; |
|
57 err=User::LoadPhysicalDevice(PDD_NAME); |
|
58 if (err!=KErrNone && err!=KErrAlreadyExists) |
|
59 User::Leave(err); |
|
60 err=User::LoadLogicalDevice(LDD_NAME); |
|
61 if (err!=KErrNone && err!=KErrAlreadyExists) |
|
62 User::Leave(err); |
|
63 |
|
64 iTestUtils = CEmailTestUtils::NewL(test); |
|
65 iTestUtils->ClearEmailAccountsL( ); |
|
66 iTestUtils->CreateAllTestDirectories( ); |
|
67 iTestUtils->FileSession( ).SetSessionPath( _L( "C:\\" ) ); |
|
68 |
|
69 iActiveWaiter = new(ELeave)CActiveWaiter(); |
|
70 iTestUtils->GoServerSideL(); |
|
71 iTestUtils->DeleteImapServiceL(); |
|
72 |
|
73 iTestUtils->GoClientSideL(); |
|
74 CEmailAccounts* account = CEmailAccounts::NewLC(); |
|
75 iImapSettings1 = new(ELeave) CImImap4Settings(); |
|
76 |
|
77 CImIAPPreferences* imapIAP = CImIAPPreferences::NewLC(); |
|
78 account->PopulateDefaultImapSettingsL(*iImapSettings1, *imapIAP); |
|
79 |
|
80 iImapSettings1->SetServerAddressL(KImapServer); |
|
81 iImapSettings1->SetLoginNameL(iTestUtils->MachineName()); |
|
82 iImapSettings1->SetPasswordL(iTestUtils->MachineName()); |
|
83 iImapSettings1->SetPort(143); |
|
84 iImapSettings1->SetImapIdle(ETrue); |
|
85 iImapSettings1->SetSubscribe(EUpdateRemote); |
|
86 iImapSettings1->SetSynchronise(EUseRemote); |
|
87 iImapSettings1->SetInboxSynchronisationLimit(KSyncLimit); |
|
88 iImapSettings1->SetMailboxSynchronisationLimit(KSyncLimit); |
|
89 |
|
90 _LIT(KTxtAccountName, "testAccount"); |
|
91 iImapAccount = account->CreateImapAccountL(KTxtAccountName, *iImapSettings1, *imapIAP, EFalse); |
|
92 |
|
93 CleanupStack::PopAndDestroy(2, account); // imapIAP, account |
|
94 |
|
95 iTestUtils->GoServerSideL(); |
|
96 iEntry = iTestUtils->iServerEntry; |
|
97 |
|
98 iServiceId = iImapAccount.iImapService; |
|
99 |
|
100 iTestUtils->InstantiateImapServerMtmL(); |
|
101 |
|
102 iImapServerMtm=(CImap4ServerMtm*)iTestUtils->iImapServerMtm; |
|
103 iEntry = iTestUtils->iServerEntry; |
|
104 |
|
105 iImapSettings = CImapSettings::NewL(*iEntry); |
|
106 iImapSettings->LoadSettingsL(iServiceId); |
|
107 iSel = new (ELeave) CMsvEntrySelection; |
|
108 } |
|
109 |
|
110 |
|
111 void CTestImapSyncManager::ChangeSyncLimitL(TInt limit) |
|
112 { |
|
113 CEmailAccounts* newaccount = CEmailAccounts::NewLC(); |
|
114 iTestUtils->GoClientSideL(); |
|
115 |
|
116 newaccount->GetImapAccountL(iServiceId, iImapAccount); |
|
117 newaccount->LoadImapSettingsL(iImapAccount, *iImapSettings1); |
|
118 |
|
119 iImapSettings1->SetInboxSynchronisationLimit(limit); |
|
120 iImapSettings1->SetMailboxSynchronisationLimit(limit); |
|
121 newaccount->SaveImapSettingsL(iImapAccount, *iImapSettings1); |
|
122 CleanupStack::PopAndDestroy(newaccount); |
|
123 iTestUtils->GoServerSideL(); |
|
124 |
|
125 iTestUtils->InstantiateImapServerMtmL(); |
|
126 |
|
127 iImapServerMtm=(CImap4ServerMtm*)iTestUtils->iImapServerMtm; |
|
128 |
|
129 iEntry = iTestUtils->iServerEntry; |
|
130 |
|
131 // load the new impsettings... |
|
132 iImapSettings = CImapSettings::NewL(*iEntry); |
|
133 iImapSettings->LoadSettingsL(iServiceId); |
|
134 delete iSel; |
|
135 iSel = new (ELeave) CMsvEntrySelection; |
|
136 } |
|
137 |
|
138 void CTestImapSyncManager::ConnectToRemoteServerL() |
|
139 { |
|
140 TBuf8<128> parameter; |
|
141 iSel->AppendL(iServiceId); |
|
142 |
|
143 iImapServerMtm->StartCommandL(*iSel, KIMAP4MTMConnect, parameter, iActiveWaiter->iStatus); |
|
144 iActiveWaiter->WaitActive(); |
|
145 ASSERT_EQUALS( iActiveWaiter->iStatus.Int( ), KErrNone ); |
|
146 } |
|
147 |
|
148 void CTestImapSyncManager::DisconnectL() |
|
149 { |
|
150 TBuf8<128> parameter; |
|
151 iSel->AppendL(iServiceId); |
|
152 iImapServerMtm->StartCommandL(*iSel, KIMAP4MTMDisconnect, parameter, iActiveWaiter->iStatus); |
|
153 iActiveWaiter->WaitActive(); |
|
154 ASSERT_EQUALS( iActiveWaiter->iStatus.Int( ), KErrNone ); |
|
155 } |
|
156 |
|
157 |
|
158 void CTestImapSyncManager::CreateFolderL( const TDesC& aName,TMsvId iEntry1) |
|
159 { |
|
160 iEntry->SetEntry(iEntry1); |
|
161 TMsvEmailEntry newEntry; |
|
162 newEntry.iType=KUidMsvFolderEntry; |
|
163 newEntry.iMtm=iEntry->Entry().iMtm; |
|
164 newEntry.iServiceId=iServiceId; |
|
165 newEntry.iSize=0; |
|
166 newEntry.iDetails.Set(aName); |
|
167 newEntry.SetMailbox(ETrue); |
|
168 newEntry.SetValidUID(EFalse); |
|
169 newEntry.SetComplete(ETrue); |
|
170 newEntry.SetVisible(ETrue); |
|
171 User::LeaveIfError(iEntry->CreateEntry(newEntry)); |
|
172 iImapServerMtm->CreateL(newEntry,iActiveWaiter->iStatus); |
|
173 iActiveWaiter->WaitActive(); |
|
174 ASSERT_EQUALS( iActiveWaiter->iStatus.Int( ), KErrNone ); |
|
175 } |
|
176 |
|
177 void CTestImapSyncManager::DeleteFolderL(const TDesC& aName) |
|
178 { |
|
179 TBuf8<128> parameter; |
|
180 TMsvId id = FindFolderL(aName); |
|
181 // delete |
|
182 CMsvEntrySelection* msvEntrySelection = new (ELeave) CMsvEntrySelection; |
|
183 msvEntrySelection->AppendL(id); |
|
184 iImapServerMtm->DeleteAllL(*msvEntrySelection,iActiveWaiter->iStatus); |
|
185 iActiveWaiter->WaitActive(); |
|
186 delete msvEntrySelection; |
|
187 } |
|
188 |
|
189 |
|
190 |
|
191 TMsvId CTestImapSyncManager::FindFolderL(const TDesC& aName, TBool aCaseSensitive) |
|
192 { |
|
193 TMsvId remoteId = KErrNotFound; |
|
194 iEntry->SetEntry(iServiceId); |
|
195 CMsvEntrySelection* msvEntrySelection = new (ELeave) CMsvEntrySelection; |
|
196 iEntry->GetChildren(*msvEntrySelection); |
|
197 TPtrC iEntryName = aName; |
|
198 TInt count = msvEntrySelection->Count(); |
|
199 for (TInt i=0; i<count; i++) |
|
200 { |
|
201 iEntry->SetEntry((*msvEntrySelection)[i]); |
|
202 |
|
203 if (aCaseSensitive) |
|
204 { |
|
205 if (iEntryName.Compare(iEntry->Entry().iDetails ) == 0) |
|
206 { |
|
207 remoteId = (*msvEntrySelection)[i]; |
|
208 break; |
|
209 } |
|
210 } |
|
211 else if ((iEntryName.CompareF(iEntry->Entry().iDetails) == 0)) |
|
212 { |
|
213 remoteId = (*msvEntrySelection)[i]; |
|
214 break; |
|
215 } |
|
216 } |
|
217 delete msvEntrySelection; |
|
218 return remoteId; |
|
219 } |
|
220 |
|
221 void CTestImapSyncManager::SetSubscriptionL(const TDesC& aName) |
|
222 { |
|
223 TBuf8<128> parameter; |
|
224 TMsvId id = FindFolderL(aName); |
|
225 CMsvEntrySelection* msvEntrySelection = new (ELeave) CMsvEntrySelection; |
|
226 msvEntrySelection->Reset(); |
|
227 msvEntrySelection->AppendL(id); |
|
228 iImapServerMtm->StartCommandL(*msvEntrySelection, KIMAP4MTMLocalSubscribe, parameter, iActiveWaiter->iStatus); |
|
229 iActiveWaiter->WaitActive(); |
|
230 TBool sub = ((TMsvEmailEntry)iEntry->Entry()).LocalSubscription(); |
|
231 delete msvEntrySelection; |
|
232 } |
|
233 |
|
234 void CTestImapSyncManager::SendMessageL() |
|
235 { |
|
236 //Create a message in the local OUTBOX which can be send to server. |
|
237 iTestUtils->CreateMessageL(_L("c:\\msgtest\\testdata\\t_unit_imapsyncmanager_test_9.txt"),iServiceId,KMsvGlobalOutBoxIndexEntryId ); |
|
238 // Send a Message to remote INBOX |
|
239 CMsvEntrySelection* sendSel = new(ELeave) CMsvEntrySelection(); |
|
240 iEntry->SetEntry(KMsvGlobalOutBoxIndexEntryId); |
|
241 iEntry->GetChildren(*sendSel); |
|
242 TMsvId id0 = FindFolderL(_L("INBOX")); |
|
243 // copy message to remote server inbox |
|
244 iImapServerMtm->MoveFromLocalL(*sendSel, id0, iActiveWaiter->iStatus); |
|
245 iActiveWaiter->WaitActive(); |
|
246 delete sendSel; |
|
247 } |
|
248 |
|
249 void CTestImapSyncManager::TearDownL() |
|
250 { |
|
251 delete iSel; |
|
252 delete iImapSettings1; |
|
253 delete iImapSettings; |
|
254 delete iActiveWaiter; |
|
255 iActiveWaiter = NULL; |
|
256 delete iTestUtils; |
|
257 iTestUtils = NULL; |
|
258 } |
|
259 |