|
1 // Copyright (c) 1999-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 // Iaptest.cpp |
|
15 // |
|
16 |
|
17 #include <biocmtm.h> |
|
18 #include <bioscmds.h> |
|
19 #include <bitsids.h> |
|
20 #include <biouids.h> |
|
21 |
|
22 #include <bsp.h> |
|
23 #include "iacp.h" |
|
24 |
|
25 #include <pop3set.h> |
|
26 #include <imapset.h> |
|
27 |
|
28 #include <commsdattypesv1_1.h> |
|
29 #include <commsdat.h> |
|
30 using namespace CommsDat; |
|
31 |
|
32 #include <pop3cmds.h> |
|
33 #include <iapprefs.h> |
|
34 |
|
35 #include "iaptest.h" |
|
36 |
|
37 #include "parsertest.h" |
|
38 #include "tmsvbioinfo.h" |
|
39 |
|
40 const TUid KUidMsgTypePop3 = {0x10001029}; |
|
41 |
|
42 CInternetAccessTester::~CInternetAccessTester() |
|
43 { |
|
44 delete iPop3ClientMtm; |
|
45 delete iClientMtmRegistry; |
|
46 |
|
47 delete iTimer; |
|
48 |
|
49 delete iSelection; |
|
50 if(iParsedFieldArray) |
|
51 { |
|
52 iParsedFieldArray->ResetAndDestroy(); |
|
53 delete iParsedFieldArray; |
|
54 } |
|
55 } |
|
56 |
|
57 |
|
58 CInternetAccessTester* CInternetAccessTester::NewL(CSmsTestUtils& aTestUtils) |
|
59 { |
|
60 CInternetAccessTester* self = new (ELeave) CInternetAccessTester(aTestUtils); |
|
61 CleanupStack::PushL(self); |
|
62 |
|
63 self->ConstructL(); |
|
64 |
|
65 CleanupStack::Pop(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 |
|
70 |
|
71 CInternetAccessTester::CInternetAccessTester(CSmsTestUtils& aTestUtils) |
|
72 : iSmsTest(aTestUtils) |
|
73 { |
|
74 } |
|
75 |
|
76 void CInternetAccessTester::StartL(TMsvId aEntryId) |
|
77 { |
|
78 iEntryId = aEntryId; |
|
79 MsvEntry().SetEntryL(aEntryId); |
|
80 GetParsedFieldStoreL(); |
|
81 |
|
82 GetIspAndMailServiceL(); |
|
83 |
|
84 TestRefreshL(); |
|
85 |
|
86 TestQuitL(); |
|
87 } |
|
88 |
|
89 void CInternetAccessTester::ConstructL() |
|
90 { |
|
91 iClientMtmRegistry = CClientMtmRegistry::NewL(Session()); |
|
92 iPop3ClientMtm = (CPop3ClientMtm*) iClientMtmRegistry->NewMtmL(KUidMsgTypePop3); |
|
93 |
|
94 CMsvEntry* cEntry = Session().GetEntryL(KMsvGlobalInBoxIndexEntryId); |
|
95 iPop3ClientMtm->SetCurrentEntryL(cEntry); // iClientMtm takes ownership on entry |
|
96 |
|
97 iTimer = TestUiTimer::NewLC(iSmsTest); |
|
98 CleanupStack::Pop(); // iTimer |
|
99 } |
|
100 |
|
101 void CInternetAccessTester::GetParsedFieldStoreL() |
|
102 { |
|
103 CMsvStore* store = MsvEntry().ReadStoreL(); |
|
104 CleanupStack::PushL(store); |
|
105 |
|
106 // try to get our array of parsed fields |
|
107 RMsvReadStream in; |
|
108 in.OpenLC( *store, KUidMsvBIODataStream ); |
|
109 InternalizeL(in); |
|
110 CleanupStack::PopAndDestroy(2); |
|
111 } |
|
112 |
|
113 void CInternetAccessTester::InternalizeL(RMsvReadStream& aReadStream) |
|
114 { |
|
115 if(iParsedFieldArray) |
|
116 { |
|
117 iParsedFieldArray->ResetAndDestroy(); |
|
118 delete iParsedFieldArray; |
|
119 iParsedFieldArray=NULL; |
|
120 } |
|
121 |
|
122 iParsedFieldArray = new(ELeave) CArrayPtrSeg<CParsedField>(16); |
|
123 |
|
124 CParsedField* parsedField = NULL; |
|
125 TInt count = aReadStream.ReadUint8L(); |
|
126 for (TInt i=0; i < count; i++) |
|
127 { |
|
128 parsedField = new (ELeave) CParsedField(); |
|
129 TRAPD(err, parsedField->InternalizeL(aReadStream)) |
|
130 if(err) |
|
131 { |
|
132 delete parsedField; //deletes the last allocated object, privious ones will be deleted by iParsedFieldArray->ResetAndDestroy() |
|
133 User::Leave(err); |
|
134 } |
|
135 iParsedFieldArray->AppendL(parsedField); |
|
136 } |
|
137 } |
|
138 |
|
139 void CInternetAccessTester::GetIspAndMailServiceL() |
|
140 { |
|
141 HBufC* ispName = NULL; |
|
142 HBufC* mailName = NULL; |
|
143 |
|
144 TBool mailNameFound = EFalse; |
|
145 TBool ispNameFound = EFalse; |
|
146 |
|
147 TInt count = iParsedFieldArray->Count(); |
|
148 for(TInt loop = 0;loop<count && !(ispNameFound && mailNameFound);loop++) |
|
149 { |
|
150 CParsedField& field = *(*iParsedFieldArray)[loop]; |
|
151 if(field.FieldName().Compare(KMAIL)==0) |
|
152 { |
|
153 mailName = field.FieldValue().AllocLC(); |
|
154 mailNameFound = ETrue; |
|
155 } |
|
156 else if(field.FieldName().Compare(KINTERNET)==0) |
|
157 { |
|
158 ispName = field.FieldValue().AllocLC(); |
|
159 ispNameFound = ETrue; |
|
160 } |
|
161 } |
|
162 |
|
163 if(mailNameFound && ispNameFound) |
|
164 { |
|
165 GetMailServiceL(*mailName); |
|
166 GetIAPL(*ispName); |
|
167 } |
|
168 else |
|
169 User::Leave(KErrNotFound); |
|
170 CleanupStack::PopAndDestroy(2); |
|
171 } |
|
172 |
|
173 void CInternetAccessTester::GetMailServiceL(const TDesC& aServiceName) |
|
174 { |
|
175 TBool serviceFound = EFalse; |
|
176 |
|
177 // Get list of children IDs |
|
178 MsvEntry().SetEntryL(KMsvRootIndexEntryId); |
|
179 CMsvEntrySelection* msvSelection = MsvEntry().ChildrenWithTypeL(KUidMsvServiceEntry); |
|
180 CleanupStack::PushL(msvSelection); |
|
181 |
|
182 TMsvEntry entry; |
|
183 TInt count = msvSelection->Count(); |
|
184 for (TInt j = 0; j < count; j++) |
|
185 { |
|
186 MsvEntry().SetEntryL((*msvSelection)[j]); |
|
187 // set context to service entry |
|
188 entry = MsvEntry().Entry(); |
|
189 if (entry.iType == KUidMsvServiceEntry) |
|
190 if(entry.iDetails.Compare(aServiceName)==0) |
|
191 if((entry.iMtm == KUidMsgTypePOP3 || entry.iMtm == KUidMsgTypeIMAP4) && entry.iDetails.CompareF(aServiceName)==0 ) |
|
192 { |
|
193 iServiceId = entry.Id(); |
|
194 serviceFound = ETrue; |
|
195 break; |
|
196 } |
|
197 |
|
198 } |
|
199 |
|
200 CleanupStack::PopAndDestroy();//msvSelection |
|
201 if(serviceFound==EFalse) |
|
202 User::Leave(KErrNotFound); |
|
203 } |
|
204 |
|
205 void CInternetAccessTester::GetIAPL(const TDesC& aIspName) |
|
206 { |
|
207 CMDBSession* iDBSession = CMDBSession::NewL(CMDBSession::LatestVersion()); |
|
208 CCDIAPRecord *iapRecord = (CCDIAPRecord*)CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord); |
|
209 CleanupStack::PushL(iapRecord); |
|
210 iapRecord->iRecordName.SetMaxLengthL(aIspName.Length()); |
|
211 iapRecord->iRecordName = aIspName; |
|
212 |
|
213 if(iapRecord->FindL(*iDBSession)) |
|
214 iIap = iapRecord->iRecordTag.RecordId(); |
|
215 else |
|
216 User::Leave(KErrNotFound); |
|
217 |
|
218 CleanupStack::PopAndDestroy(iapRecord); |
|
219 delete iDBSession; |
|
220 iDBSession= NULL; |
|
221 } |
|
222 |
|
223 void CInternetAccessTester::TestRefreshL() |
|
224 { |
|
225 |
|
226 // try and refresh |
|
227 delete iSelection; |
|
228 iSelection = NULL; |
|
229 iSelection = new(ELeave)CMsvEntrySelection; |
|
230 iSelection->AppendL(iServiceId); |
|
231 |
|
232 TBuf8<1> dummyParam; |
|
233 |
|
234 CMsvOperationWait* wait = CMsvOperationWait::NewLC(); |
|
235 wait->iStatus = KRequestPending; |
|
236 |
|
237 CMsvOperation* operation = iPop3ClientMtm->InvokeAsyncFunctionL( KPOP3MTMConnect, *iSelection, dummyParam, wait->iStatus); |
|
238 |
|
239 iTimer->SetOperation(operation); |
|
240 iTimer->IssueRequest(); |
|
241 |
|
242 wait->Start(); |
|
243 CActiveScheduler::Start(); |
|
244 |
|
245 TInt error = operation->iStatus.Int(); |
|
246 iTimer->Cancel(); |
|
247 |
|
248 CleanupStack::PopAndDestroy(); // wait |
|
249 if(error !=KErrNone) |
|
250 User::Leave(error); |
|
251 } |
|
252 |
|
253 void CInternetAccessTester::TestQuitL() |
|
254 { |
|
255 TBuf8<1> dummyParam; |
|
256 |
|
257 CMsvOperationWait* wait = CMsvOperationWait::NewLC(); |
|
258 wait->iStatus = KRequestPending; |
|
259 |
|
260 CMsvOperation* operation = iPop3ClientMtm->InvokeAsyncFunctionL( KPOP3MTMDisconnect, *iSelection, dummyParam, wait->iStatus); |
|
261 |
|
262 iTimer->SetOperation(operation); |
|
263 iTimer->IssueRequest(); |
|
264 |
|
265 wait->Start(); |
|
266 CActiveScheduler::Start(); |
|
267 |
|
268 TInt error = operation->iStatus.Int(); |
|
269 iTimer->Cancel(); |
|
270 |
|
271 CleanupStack::PopAndDestroy(); // wait |
|
272 if(error !=KErrNone) |
|
273 User::Leave(error); |
|
274 } |