messagingfw/wappushfw/tpush/t_simessage.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2000-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 
       
    18 #include "pushtests.h"
       
    19 #include "dummywapstack.h"
       
    20 #include "wappushmsggen.h"
       
    21 
       
    22 // si text message data
       
    23 
       
    24 _LIT8(KSIAction,"delete");
       
    25 _LIT8(KSIHref, "http://www.xyz.com/ppaid/123/abc.wml");
       
    26 _LIT8(KSINewHref, "http://www.xyz.com/ppaid/123/new.wml");
       
    27 _LIT8(KSIOldDate,		"2000-01-01T15:23:15Z");
       
    28 _LIT8(KSeptemberDate,	"2000-09-30T00:00:00Z");
       
    29 _LIT8(KOctoberDate,		"2000-10-30T00:00:00Z");
       
    30 _LIT8(KSISiId, "http://www.xyz.com/ppaid/123/abc.wml");
       
    31 
       
    32 /** set test name to 'Service Indication'
       
    33 	@param void
       
    34 	@return string
       
    35 		string represents test name
       
    36 */
       
    37 const TDesC& CWapPushSIMessageTest::TestName()
       
    38 {
       
    39 	_LIT(KTextSIMessageTest, "Service Indication");
       
    40 	return KTextSIMessageTest;
       
    41 }
       
    42 
       
    43 /** set the number of test messages to use */
       
    44 void CWapPushSIMessageTest::NumberTestCasesToRun()
       
    45 {
       
    46 	iNumberOfTestCases = 8;
       
    47 }
       
    48 
       
    49 /** build different test messages to test specific SI reception aspects
       
    50 	in the SI content handler processing code.
       
    51 	@param TInt
       
    52 		the number of test messages to create and use
       
    53 	@return void
       
    54 */
       
    55 void CWapPushSIMessageTest::PrepareTestMessageL(TInt aTestCase)
       
    56 {
       
    57 	// this set of test messages adds a test message
       
    58 	// to the store for the match cases, 
       
    59 	// replaces the stored message and ends with no stored si message 	
       
    60 	const TUint8 KMessageHeader2[] = 
       
    61 		{
       
    62 		//0xB0,  //Content type "application/vnd.wap.slc"
       
    63 		0xAD,  //Content type "application/vnd.wap.si" 
       
    64 		0x92,  // Date
       
    65 		0x04,  // length of field
       
    66 		0x39,  // Monday 15 August 2000 10:41:37 GMT
       
    67 		0x90,	
       
    68 		0x6a,
       
    69 		0xd0,
       
    70 		0x94,  // Expires 
       
    71 		0x04,  // length of field
       
    72 		0x39,  // Monday 15 August 2000 10:41:37 GMT
       
    73 		0x9a,	
       
    74 		0x6a,
       
    75 		0xd0,
       
    76 		0xAF,  //X-Wap-Application-ID
       
    77 		0x82  // Short int - 0x02 represent x-wap-application:push.ua
       
    78 		};	
       
    79 
       
    80 	TBuf8<40> tempBuf;
       
    81 	TUint8 value;
       
    82 	for (TInt i = 0; i < 15; i++)
       
    83 		{
       
    84 		value = KMessageHeader2[i];
       
    85 		tempBuf.Append(value);
       
    86 		}
       
    87 
       
    88 	iHeadersBuf.Copy(tempBuf);
       
    89 	tempBuf.Copy(_L8(""));
       
    90 
       
    91 	iBodyBuf.Delete(0,KBufferSize);
       
    92 	//iBodyBuf.Zero();
       
    93 		
       
    94 	CWapPushMsgGen* msgGen = CWapPushMsgGen::NewL();
       
    95 	CleanupStack::PushL(msgGen);
       
    96 
       
    97 	msgGen->StartNewMsgL(CWapPushMsgGen::EServiceIndication);
       
    98 		
       
    99 	switch (aTestCase)
       
   100 		{
       
   101 	case 0 : // no action - msg stored with action = "signal-medium"
       
   102 			// this initial msg will match in cases 2 and 3...
       
   103 		msgGen->AppendFieldL(CWapPushMsgGen::EHRef, KSIHref);
       
   104 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationID, KSISiId);
       
   105 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationCreated, KSeptemberDate);
       
   106 		break;
       
   107 	case 1 : // message expired - delete
       
   108 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationExpires, KSIOldDate);
       
   109 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationID, _L8("do not store this message"));
       
   110 		break;	
       
   111 	case 2 : // match existing si - delete received si 
       
   112 		msgGen->AppendFieldL(CWapPushMsgGen::EHRef, KSIHref);
       
   113 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationCreated, KSIOldDate);
       
   114 		break;
       
   115 	case 3 : // match existing si - delete existing si
       
   116 			 // deletes msg created in case 0 and will replace it
       
   117 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationID, KSISiId);
       
   118 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationCreated, KOctoberDate); // date > stored date
       
   119 		break;
       
   120 	case 4 : // match existing si and discard receved message
       
   121 		     // matches msg from case 3 
       
   122 		msgGen->AppendFieldL(CWapPushMsgGen::EHRef, KSINewHref);
       
   123 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationID, KSISiId);
       
   124 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationCreated, KOctoberDate);	// date = stored date
       
   125 		break;
       
   126 	case 5 : // action = delete; href set but no si-id (no deletion occurs)
       
   127 			 // store msg but has si-id equal to received msg href.... 
       
   128 		msgGen->AppendFieldL(CWapPushMsgGen::EAction, KSIAction);
       
   129 		msgGen->AppendFieldL(CWapPushMsgGen::EHRef, KSIHref);
       
   130 		break;
       
   131 	case 6 : // action = delete; si-id set (delete msg)
       
   132 			// any matching record will already have been deleted
       
   133 		msgGen->AppendFieldL(CWapPushMsgGen::EAction, KSIAction);
       
   134 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationID, KSISiId);
       
   135 		msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationCreated, KOctoberDate);
       
   136 		break;
       
   137 	case 7 :
       
   138 		// testing fix for INC038455 - Apostrophe char (0x27) in SI message makes CXmlLibrary leave with -13106
       
   139 		PrepareApostropheTestMessageL();
       
   140 		break;
       
   141 	default: 
       
   142 		// do nothing
       
   143 		break;
       
   144 	}
       
   145 	msgGen->AppendFieldL(CWapPushMsgGen::EServiceIndicationText, _L8("You have 4 new e-mails"));
       
   146 
       
   147 	HBufC8* msg = msgGen->CreateMsgLC();
       
   148 	// copy data to iBodyBuf
       
   149 	if (aTestCase!=7)
       
   150 		{
       
   151 		iBodyBuf = msg->Des(); 
       
   152 		}
       
   153 	CleanupStack::PopAndDestroy(2); //msgGen, msg
       
   154 }
       
   155 
       
   156 /** confirm the message has been stored.
       
   157 	Writes the number of stored messages found to the log file - if present.
       
   158 	@param void
       
   159 	@return TBool
       
   160 		returns ETrue if messages found
       
   161 		returns EFalse if no messages found 
       
   162 */
       
   163 TBool CWapPushSIMessageTest::ConfirmMessagesSavedL()
       
   164 	{
       
   165 	CSISLPushMsgUtils* wapPushUtils = CSISLPushMsgUtils::NewL();
       
   166 	CleanupStack::PushL(wapPushUtils);
       
   167 	
       
   168 	TMsvId localFolderId;
       
   169 	wapPushUtils->GetPushMsgFolderIdL(localFolderId);
       
   170 	
       
   171 	const TDesC& siId16 = _L("http://www.xyz.com/ppaid/123/abc.wml"); 
       
   172 	CMsvEntrySelection* matchingIdList = wapPushUtils->FindSiIdLC(siId16);
       
   173 
       
   174 	// check there are any entries - zero indicates no matches
       
   175 	TInt foundCount;
       
   176 	if (matchingIdList) 
       
   177 		foundCount = matchingIdList->Count(); 
       
   178 	else
       
   179 		foundCount = 0;
       
   180 	
       
   181 	TBuf<KPushLogBuffer> buf;
       
   182 	_LIT(KLogSICount,"SI messages stored:\t%d");
       
   183 	buf.Format(KLogSICount,foundCount);
       
   184 	WPLPrintf(buf);	
       
   185 
       
   186 	CleanupStack::PopAndDestroy(2);  // wapPushUtils, matchingIdList
       
   187 	return foundCount;
       
   188 	}
       
   189 
       
   190 void CWapPushSIMessageTest::PrepareApostropheTestMessageL()
       
   191 	{
       
   192 	const TUint8 KMessageHeader2[] = 
       
   193 		{
       
   194 		0xAE,  //Content type "application/vnd.wap.si" 
       
   195 		0x92,  // Date
       
   196 		0x04,  // length of field
       
   197 		0x39,  // Monday 15 August 2000 10:41:37 GMT
       
   198 		0x90,	
       
   199 		0x6a,
       
   200 		0xd0,
       
   201 		0x94,  // Expires 
       
   202 		0x04,  // length of field
       
   203 		0x39,  // Monday 15 August 2000 10:41:37 GMT
       
   204 		0x9a,	
       
   205 		0x6a,
       
   206 		0xd0,
       
   207 		0xAF,  //X-Wap-Application-ID
       
   208 		0x82  // Short int - 0x02 represent x-wap-application:push.ua
       
   209 		};	
       
   210 
       
   211 	const TUint8 KBody[] = 
       
   212 		{
       
   213 		0x02,
       
   214 		0x05,
       
   215 		0x6A,
       
   216 		0x00,
       
   217 		0x45,
       
   218 		0xC6,
       
   219 		0x0C, 
       
   220 		0x03,
       
   221 		0x77,
       
   222 		0x61,
       
   223 		0x70,
       
   224 		0x2E,
       
   225 		0x67,
       
   226 		0x6F,
       
   227 		0x6F,
       
   228 		0x67,
       
   229 		0x6C,
       
   230 		0x65,
       
   231 		0x2E,
       
   232 		0x63,
       
   233 		0x6F,
       
   234 		0x6D,
       
   235 		0x00,
       
   236 		0x01,
       
   237 		0x03,
       
   238 		0xA0,
       
   239 		0x49,
       
   240 		0x74,
       
   241 		0x27, //
       
   242 //		0x22, //
       
   243 		0x73,
       
   244 		0xA0,
       
   245 		0x46,
       
   246 		0xA0,
       
   247 		0x46,
       
   248 		0xA0,
       
   249 		0x46,
       
   250 		0xA0,
       
   251 		0x46,
       
   252 		0x72,
       
   253 		0x69,
       
   254 		0x64,
       
   255 		0x61,
       
   256 		0x79,
       
   257 		0x21,
       
   258 		0x21,
       
   259 		0x21,
       
   260 		0xA0,
       
   261 		0x00,
       
   262 		0x01,
       
   263 		0x01
       
   264 		};	
       
   265 
       
   266 
       
   267 	TBuf8<60> tempBuf;
       
   268 	TUint8 value;
       
   269 	for (TInt i = 0; i < 15; i++)
       
   270 		{
       
   271 		value = KMessageHeader2[i];
       
   272 		tempBuf.Append(value);
       
   273 		}
       
   274 
       
   275 	iHeadersBuf.Copy(tempBuf);
       
   276 	tempBuf.Copy(_L8(""));
       
   277 
       
   278 	iBodyBuf.Delete(0,KBufferSize);
       
   279 		
       
   280 	for (TInt ii = 0; ii < 50; ii++)
       
   281 		{
       
   282 		value = KBody[ii];
       
   283 		tempBuf.Append(value);
       
   284 		}
       
   285 
       
   286 	// copy data to iBodyBuf
       
   287 	iBodyBuf.Copy(tempBuf); 
       
   288 	tempBuf.Copy(_L8(""));
       
   289 	}
       
   290 
       
   291