|         |      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/cslpushmsgentry.h> | 
|         |     18 #include "pushtests.h" | 
|         |     19 #include "dummywapstack.h" | 
|         |     20 #include "wappushmsggen.h" | 
|         |     21 #include <push/pushmessage.h> | 
|         |     22  | 
|         |     23 #include "httptestutils.h" | 
|         |     24 #if !defined(__TESTSCRIPTS_H__) | 
|         |     25 #include "TestScripts.h" | 
|         |     26 #endif | 
|         |     27 				 | 
|         |     28 _LIT8(KSLHref, "http://www.xyz.com/ppaid/123/abc.wml"); | 
|         |     29  | 
|         |     30 CWapPushSLMessageTest::CWapPushSLMessageTest(TInt aIndex, CHTTPTestUtils* aTestUtils):CWapPushMessageTest(aIndex, aTestUtils) | 
|         |     31 	{ | 
|         |     32 	} | 
|         |     33 	 | 
|         |     34 const TDesC& CWapPushSLMessageTest::TestName() | 
|         |     35 	{ | 
|         |     36 	_LIT(KTextSLMessageTest, "Service Loading"); | 
|         |     37 	return KTextSLMessageTest; | 
|         |     38 	} | 
|         |     39  | 
|         |     40 void CWapPushSLMessageTest::NumberTestCasesToRun() | 
|         |     41 	{ | 
|         |     42 	iNumberOfTestCases = 1; | 
|         |     43 	} | 
|         |     44  | 
|         |     45 TDesC8& CWapPushSLMessageTest::Uri() const | 
|         |     46 	{ | 
|         |     47 	return (*(iUri)); | 
|         |     48 	} | 
|         |     49 	 | 
|         |     50 void CWapPushSLMessageTest::PrepareTestMessageL(TInt aTestCase) | 
|         |     51 	{ | 
|         |     52 	ReadAndSetParamsFromIniFileL(); | 
|         |     53 	 | 
|         |     54 	CWapPushMsgGen* msgGen = CWapPushMsgGen::NewL(); | 
|         |     55 	CleanupStack::PushL(msgGen); | 
|         |     56  | 
|         |     57 	msgGen->StartNewMsgL(CWapPushMsgGen::EServiceLoad);	 | 
|         |     58 	 | 
|         |     59 	if(iHRef) | 
|         |     60 		{ | 
|         |     61 		msgGen->AppendFieldL(CWapPushMsgGen::EHRef, GetHRef()); | 
|         |     62 		} | 
|         |     63 	if(iAction) | 
|         |     64 		{ | 
|         |     65 		msgGen->AppendFieldL(CWapPushMsgGen::EAction, GetAction()); | 
|         |     66 		} | 
|         |     67 	 | 
|         |     68 	const TUint8 KMessageHeader2[] =  | 
|         |     69 		{ | 
|         |     70 		0xAF, | 
|         |     71 		0x92,  // Date | 
|         |     72 		0x04,  // length of field | 
|         |     73 		0x39,  // Monday 15 August 2000 10:41:37 GMT | 
|         |     74 		0x90,	 | 
|         |     75 		0x6a, | 
|         |     76 		0xd0, | 
|         |     77 		0x94,  // Expires  | 
|         |     78 		0x04,  // length of field | 
|         |     79 		0x39,  // Monday 15 August 2000 10:41:37 GMT | 
|         |     80 		0x9a,	 | 
|         |     81 		0x6a, | 
|         |     82 		0xd0, | 
|         |     83 		0xAF,  //X-Wap-Application-ID | 
|         |     84 		0x82  // Short int - 0x02 represent x-wap-application:push.ua | 
|         |     85 		};	 | 
|         |     86  | 
|         |     87 	TBuf8<40> tempBuf; | 
|         |     88 	TUint8 value; | 
|         |     89 	 | 
|         |     90 	for (TInt i = 0; i < 15; i++) | 
|         |     91 		{ | 
|         |     92 		value = KMessageHeader2[i]; | 
|         |     93 		tempBuf.Append(value); | 
|         |     94 		} | 
|         |     95  | 
|         |     96 	iHeadersBuf.Copy(tempBuf); | 
|         |     97 	tempBuf.Copy(_L8("")); | 
|         |     98  | 
|         |     99 	iBodyBuf.Delete(0,KBufferSize); | 
|         |    100 	HBufC8* msg = msgGen->CreateMsgLC(); | 
|         |    101 	 | 
|         |    102 	switch (aTestCase) | 
|         |    103 		{ | 
|         |    104 	case 0 :  | 
|         |    105 		iBodyBuf = msg->Des();  | 
|         |    106 		break; | 
|         |    107 	 | 
|         |    108 	default:  | 
|         |    109 		// do nothing | 
|         |    110 		break; | 
|         |    111 		} | 
|         |    112  | 
|         |    113 	CleanupStack::PopAndDestroy(2); //msgGen, msg | 
|         |    114 	} | 
|         |    115  | 
|         |    116 TBool CWapPushSLMessageTest::ConfirmMessagesSavedL() | 
|         |    117 	{ | 
|         |    118 	HBufC* tempHref = HBufC::NewLC(KSLHref().Length()); | 
|         |    119 	tempHref->Des().Copy(KSLHref()); | 
|         |    120 	 | 
|         |    121 	TInt returnVal = 0; | 
|         |    122 	 | 
|         |    123 	CSISLPushMsgUtils *wapPushUtils = CSISLPushMsgUtils::NewL(); | 
|         |    124 	CleanupStack::PushL(wapPushUtils); | 
|         |    125 		 | 
|         |    126 	TMsvId matchingSlMsgEntryId;  | 
|         |    127 	matchingSlMsgEntryId = wapPushUtils->FindUrlL(*tempHref, KUidWapPushMsgSL); | 
|         |    128 	 | 
|         |    129 	if(matchingSlMsgEntryId) | 
|         |    130 		{ | 
|         |    131 		HBufC8* header = iHeadersBuf.AllocLC(); | 
|         |    132 		HBufC8* body = iBodyBuf.AllocLC(); | 
|         |    133 		 | 
|         |    134 		CPushMessage* pushMsg = CPushMessage::NewL(header, body); | 
|         |    135 		CleanupStack::Pop(2); // body, header | 
|         |    136 		CleanupStack::PushL(pushMsg); | 
|         |    137 							 | 
|         |    138 		TBool isInt; | 
|         |    139 		TPtrC8 appURI; | 
|         |    140 		TInt appID=0; | 
|         |    141 		pushMsg->GetAppIdL(appURI, appID, isInt); | 
|         |    142 		CSLPushMsgEntry* slEntry=NULL; | 
|         |    143 		if (isInt) | 
|         |    144 			{ | 
|         |    145 			slEntry = CSLPushMsgEntry::NewL(appID); | 
|         |    146 			} | 
|         |    147 		else | 
|         |    148 			{ | 
|         |    149 			slEntry = CSLPushMsgEntry::NewL(appURI); | 
|         |    150 			} | 
|         |    151 		CleanupStack::PushL(slEntry); | 
|         |    152 			 | 
|         |    153 		slEntry->RetrieveL(wapPushUtils->Session(), matchingSlMsgEntryId); | 
|         |    154 		 | 
|         |    155 		TInt trusted = slEntry->Trusted(); | 
|         |    156 		TPtrC8 ptr(slEntry->MsgOriginUri()); | 
|         |    157 		 | 
|         |    158 		RInetUriList inetUriList; | 
|         |    159 		InetUriList::TListType listType; | 
|         |    160 		TRAPD(err, inetUriList.OpenL()); | 
|         |    161 		if(err == KErrNone) | 
|         |    162 			{ | 
|         |    163 			TPtrC8 serverAddress(iUri->Des()); | 
|         |    164 			err = inetUriList.GetListType(serverAddress, InetUriList::EWapPush, listType); | 
|         |    165 			} | 
|         |    166 		inetUriList.Close(); | 
|         |    167 			if(trusted == 1) | 
|         |    168 			{ | 
|         |    169 			// whitelist | 
|         |    170 			if((iUri->Compare(slEntry->MsgOriginUri()) == 0) && (err == KErrNone) && (listType == InetUriList::EWhiteList)) | 
|         |    171 				{ | 
|         |    172 				returnVal = KErrNone; | 
|         |    173 				} | 
|         |    174 			else | 
|         |    175 				{ | 
|         |    176 				returnVal = KErrGeneral;	 | 
|         |    177 				} | 
|         |    178 			} | 
|         |    179 		else if(trusted == 0) | 
|         |    180 			{ | 
|         |    181 			// unknown | 
|         |    182 			if((iUri->Compare(slEntry->MsgOriginUri()) == 0) && (err == InetUriList::KErrUriNotFound)) | 
|         |    183 				{ | 
|         |    184 				returnVal = KErrNone; | 
|         |    185 				} | 
|         |    186 			else | 
|         |    187 				{ | 
|         |    188 				returnVal = KErrGeneral;	 | 
|         |    189 				} | 
|         |    190 			} | 
|         |    191 			 | 
|         |    192 		wapPushUtils->DeleteEntryNowL(matchingSlMsgEntryId); | 
|         |    193 		CleanupStack::PopAndDestroy(slEntry); | 
|         |    194 		CleanupStack::PopAndDestroy(pushMsg); | 
|         |    195 		} | 
|         |    196 	 | 
|         |    197 	CleanupStack::PopAndDestroy(wapPushUtils); | 
|         |    198 	CleanupStack::PopAndDestroy(tempHref); | 
|         |    199 	return returnVal; | 
|         |    200 	} | 
|         |    201  | 
|         |    202  |