|
1 // Copyright (c) 2007-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 <push/sislpushmsgutils.h> |
|
17 #include <push/csipushmsgentry.h> |
|
18 #include <push/pushmessage.h> |
|
19 #include <ineturilist.h> |
|
20 #include <ineturilistdef.h> |
|
21 |
|
22 #include "pushtests.h" |
|
23 #include "dummywapstack.h" |
|
24 #include "wappushmsggen.h" |
|
25 |
|
26 #include "httptestutils.h" |
|
27 #if !defined(__TESTSCRIPTS_H__) |
|
28 #include "TestScripts.h" |
|
29 #endif |
|
30 |
|
31 |
|
32 _LIT(KWapIniFolder, "wapini"); |
|
33 _LIT(KWapIni, "wap.ini"); |
|
34 |
|
35 _LIT(KSiId, "SI-Id"); |
|
36 _LIT(KSICreated, "SI-Created"); |
|
37 _LIT(KSIExpires, "SI-Expires"); |
|
38 |
|
39 CWapPushSIMessageTest::CWapPushSIMessageTest(TInt aIndex, CHTTPTestUtils* aTestUtils):CWapPushMessageTest(aIndex, aTestUtils) |
|
40 { |
|
41 } |
|
42 |
|
43 CWapPushSIMessageTest::~CWapPushSIMessageTest() |
|
44 { |
|
45 delete iSiId; |
|
46 delete iSiCreatedDate; |
|
47 delete iSiExpiresDate; |
|
48 } |
|
49 |
|
50 const TDesC& CWapPushSIMessageTest::TestName() |
|
51 { |
|
52 _LIT(KTextSIMessageTest, "Service Indication"); |
|
53 return KTextSIMessageTest; |
|
54 } |
|
55 |
|
56 void CWapPushSIMessageTest::NumberTestCasesToRun() |
|
57 { |
|
58 iNumberOfTestCases = 1; |
|
59 } |
|
60 |
|
61 TDesC8& CWapPushSIMessageTest::GetSiId() const |
|
62 { |
|
63 return (*(iSiId)); |
|
64 } |
|
65 |
|
66 TDesC8& CWapPushSIMessageTest::GetSICreatedDate() const |
|
67 { |
|
68 return(*(iSiCreatedDate)); |
|
69 } |
|
70 |
|
71 TDesC8& CWapPushSIMessageTest::GetSIExpiresDate() const |
|
72 { |
|
73 return(*(iSiExpiresDate)); |
|
74 } |
|
75 |
|
76 TDesC8& CWapPushSIMessageTest::Uri() const |
|
77 { |
|
78 return (*(iUri)); |
|
79 } |
|
80 |
|
81 void CWapPushSIMessageTest::ReadAndSetSIParamsFromIniFileL() |
|
82 { |
|
83 // Delete previously read buffers. |
|
84 delete iSiId; |
|
85 delete iSiCreatedDate; |
|
86 delete iSiExpiresDate; |
|
87 |
|
88 |
|
89 CScriptFile* iniFile = NULL; |
|
90 iniFile = CScriptFile::NewL(*iTestUtils, KWapIniFolder(), KWapIni()); |
|
91 CleanupStack::PushL(iniFile); |
|
92 |
|
93 TInt itemFieldCount= iniFile->Section(iSectionIndex).Items().Count(); |
|
94 |
|
95 TBuf8<200> itemFieldValue8; |
|
96 |
|
97 for (TInt fctr=0; fctr < itemFieldCount ; ++fctr) |
|
98 { |
|
99 TPtrC itemFieldPtr(iniFile->Section(iSectionIndex).Item(fctr).Item()); |
|
100 itemFieldValue8.Copy(iniFile->Section(iSectionIndex).Item(fctr).Value()); |
|
101 |
|
102 if(itemFieldPtr.Compare(KSiId) == 0) |
|
103 { |
|
104 iSiId = itemFieldValue8.AllocL(); |
|
105 RemoveQuotes(iSiId); |
|
106 } |
|
107 else if(itemFieldPtr.Compare(KSICreated) == 0) |
|
108 { |
|
109 iSiCreatedDate = itemFieldValue8.AllocL(); |
|
110 RemoveQuotes(iSiCreatedDate); |
|
111 } |
|
112 else if(itemFieldPtr.Compare(KSIExpires) == 0) |
|
113 { |
|
114 iSiExpiresDate = itemFieldValue8.AllocL(); |
|
115 RemoveQuotes(iSiExpiresDate); |
|
116 } |
|
117 } |
|
118 CleanupStack::PopAndDestroy(iniFile); |
|
119 } |
|
120 |
|
121 void CWapPushSIMessageTest::PrepareTestMessageL(TInt aTestCase) |
|
122 { |
|
123 ReadAndSetParamsFromIniFileL(); |
|
124 ReadAndSetSIParamsFromIniFileL(); |
|
125 |
|
126 CWapPushMsgGen* msgGen = CWapPushMsgGen::NewL(); |
|
127 CleanupStack::PushL(msgGen); |
|
128 |
|
129 msgGen->StartNewMsgL(CWapPushMsgGen::EServiceIndication); |
|
130 |
|
131 if(iHRef) |
|
132 { |
|
133 msgGen->AppendFieldL(CWapPushMsgGen::EHRef, GetHRef()); |
|
134 } |
|
135 if(iAction) |
|
136 { |
|
137 msgGen->AppendFieldL(CWapPushMsgGen::EAction, GetAction()); |
|
138 } |
|
139 if(iSiId) |
|
140 { |
|
141 msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationID, GetSiId()); |
|
142 } |
|
143 if(iSiCreatedDate) |
|
144 { |
|
145 msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationCreated, GetSICreatedDate()); |
|
146 } |
|
147 if(iSiExpiresDate) |
|
148 { |
|
149 msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationExpires, GetSIExpiresDate()); |
|
150 } |
|
151 |
|
152 const TUint8 KMessageHeader2[] = |
|
153 { |
|
154 0xAD, |
|
155 0x92, // Date |
|
156 0x04, // length of field |
|
157 0x39, // Monday 15 August 2000 10:41:37 GMT |
|
158 0x90, |
|
159 0x6a, |
|
160 0xd0, |
|
161 0x94, // Expires |
|
162 0x04, // length of field |
|
163 0x39, // Monday 15 August 2000 10:41:37 GMT |
|
164 0x9a, |
|
165 0x6a, |
|
166 0xd0, |
|
167 0xAF, //X-Wap-Application-ID |
|
168 0x82 // Short int - 0x02 represent x-wap-application:push.ua |
|
169 }; |
|
170 |
|
171 TBuf8<40> tempBuf; |
|
172 TUint8 value; |
|
173 |
|
174 for (TInt i = 0; i < 15; i++) |
|
175 { |
|
176 value = KMessageHeader2[i]; |
|
177 tempBuf.Append(value); |
|
178 } |
|
179 |
|
180 iHeadersBuf.Copy(tempBuf); |
|
181 tempBuf.Copy(_L8("")); |
|
182 |
|
183 iBodyBuf.Delete(0,KBufferSize); |
|
184 |
|
185 switch (aTestCase) |
|
186 { |
|
187 case 0 : |
|
188 msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationText, _L8("You have 4 new e-mails")); |
|
189 break; |
|
190 |
|
191 default: |
|
192 // do nothing |
|
193 break; |
|
194 } |
|
195 |
|
196 HBufC8* msg = msgGen->CreateMsgLC(); |
|
197 iBodyBuf = msg->Des(); |
|
198 |
|
199 CleanupStack::PopAndDestroy(2); //msgGen, msg |
|
200 } |
|
201 |
|
202 TBool CWapPushSIMessageTest::ConfirmMessagesSavedL() |
|
203 { |
|
204 TInt returnVal = 0; |
|
205 const TDesC& siId16 = _L("http://www.xyz.com/ppaid/123/abc.wml"); |
|
206 |
|
207 CSISLPushMsgUtils *wapPushUtils = CSISLPushMsgUtils::NewL(); |
|
208 CleanupStack::PushL(wapPushUtils); |
|
209 |
|
210 CMsvEntrySelection* matchingIdList; |
|
211 matchingIdList = wapPushUtils->FindSiIdLC(siId16); |
|
212 |
|
213 TMsvId matchingSiMsgEntryId; |
|
214 |
|
215 if(matchingIdList->Count()) |
|
216 { |
|
217 TInt matchingListCount = matchingIdList->Count(); |
|
218 matchingSiMsgEntryId = matchingIdList->At(matchingListCount-1); |
|
219 |
|
220 HBufC8* header = iHeadersBuf.AllocLC(); |
|
221 HBufC8* body = iBodyBuf.AllocLC(); |
|
222 |
|
223 CPushMessage* pushMsg = CPushMessage::NewL(header, body); |
|
224 CleanupStack::Pop(2); // body, header |
|
225 CleanupStack::PushL(pushMsg); |
|
226 |
|
227 TBool isInt; |
|
228 TPtrC8 appURI; |
|
229 TInt appID=0; |
|
230 pushMsg->GetAppIdL(appURI, appID, isInt); |
|
231 CSIPushMsgEntry* siEntry=NULL; |
|
232 if (isInt) |
|
233 { |
|
234 siEntry = CSIPushMsgEntry::NewL(appID); |
|
235 } |
|
236 else |
|
237 { |
|
238 siEntry = CSIPushMsgEntry::NewL(appURI); |
|
239 } |
|
240 CleanupStack::PushL(siEntry); |
|
241 |
|
242 siEntry->RetrieveL(wapPushUtils->Session(), matchingSiMsgEntryId); |
|
243 |
|
244 TInt trusted = siEntry->Trusted(); |
|
245 TPtrC8 ptr(siEntry->MsgOriginUri()); |
|
246 |
|
247 RInetUriList inetUriList; |
|
248 InetUriList::TListType listType; |
|
249 TRAPD(err, inetUriList.OpenL()); |
|
250 if(err == KErrNone) |
|
251 { |
|
252 TPtrC8 serverAddress(iUri->Des()); |
|
253 err = inetUriList.GetListType(serverAddress, InetUriList::EWapPush, listType); |
|
254 } |
|
255 inetUriList.Close(); |
|
256 |
|
257 if(trusted == 1) |
|
258 { |
|
259 // whitelist |
|
260 if((iUri->Compare(siEntry->MsgOriginUri()) == 0) && (err == KErrNone) && (listType == InetUriList::EWhiteList)) |
|
261 { |
|
262 returnVal = KErrNone; |
|
263 } |
|
264 else |
|
265 { |
|
266 returnVal = KErrGeneral; |
|
267 } |
|
268 } |
|
269 else if(trusted == 0) |
|
270 { |
|
271 // unknown |
|
272 if((iUri->Compare(siEntry->MsgOriginUri()) == 0) && (err == InetUriList::KErrUriNotFound)) |
|
273 { |
|
274 returnVal = KErrNone; |
|
275 } |
|
276 else |
|
277 { |
|
278 returnVal = KErrGeneral; |
|
279 } |
|
280 } |
|
281 |
|
282 wapPushUtils->DeleteEntryNowL(matchingSiMsgEntryId); |
|
283 CleanupStack::PopAndDestroy(siEntry); |
|
284 CleanupStack::PopAndDestroy(pushMsg); |
|
285 |
|
286 } |
|
287 CleanupStack::PopAndDestroy(matchingIdList); |
|
288 |
|
289 CleanupStack::PopAndDestroy(wapPushUtils); |
|
290 |
|
291 return returnVal; |
|
292 } |
|
293 |
|
294 |