messagingfw/suplwappushhandler/test/src/Te_LbsSuplWapPushStep.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     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 // This is an integration unit test class for the SUPL WAP Push Plug-in
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21  @prototype
       
    22 */
       
    23 
       
    24 #include <e32property.h>
       
    25 #include <push/pushmessage.h>
       
    26 #include <ecom/implementationproxy.h>
       
    27 
       
    28 #include "LbsSuplWapPush.h"
       
    29 
       
    30 #include "Te_LbsSuplWapPushStep.h"
       
    31 #include "Te_LbsSuplPush.h"
       
    32 #include "Te_LbsSuplWapPushCommon.h"
       
    33 #include "Te_ErrorPattern.h"
       
    34 
       
    35 
       
    36 const TUint KTestMsgLength = 128;
       
    37 
       
    38 const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount);
       
    39 
       
    40 /**
       
    41  * Constructor. It must	call the SetTestStepName as the controlling
       
    42  * framework uses the test step name immediately following construction to set
       
    43  * up the step's unique logging ID. 
       
    44  */
       
    45 CTe_LbsSuplWapPushStep::CTe_LbsSuplWapPushStep()
       
    46 	{
       
    47 	SetTestStepName(KLbsSuplWapPushStep);
       
    48 	CTe_LbsSuplPush::SetTestObserver(this);
       
    49 	}
       
    50 
       
    51 /**
       
    52  * Destructor.
       
    53  */
       
    54 CTe_LbsSuplWapPushStep::~CTe_LbsSuplWapPushStep()
       
    55 	{
       
    56 	delete iReceiver;
       
    57 	}
       
    58 
       
    59 /**
       
    60 Creates the test step environment - the receiver part of the SUPL Push API.
       
    61 
       
    62 @return - always returns EPass.
       
    63 
       
    64 @leave If a error happens, it leaves with one of the system error codes.
       
    65 
       
    66 @see CTe_BaseStep::doTestStepPreambleL
       
    67  */
       
    68 TVerdict CTe_LbsSuplWapPushStep::doTestStepPreambleL()
       
    69 	{
       
    70 	CTe_BaseStep::doTestStepPreambleL();
       
    71 	iReceiver = CLbsSuplPushRec::NewL(*this);
       
    72 	return TestStepResult();
       
    73 	}
       
    74 
       
    75 /**
       
    76 Overrides pure virtual CTe_BaseStep::ReallyDoTestStepL. The test code is run here.
       
    77 
       
    78 @leave If a error happens, it leaves with one of the system error codes or EFail.
       
    79 */
       
    80 void CTe_LbsSuplWapPushStep::ReallyDoTestStepL()
       
    81 	{
       
    82 	//Successfuly send/receive a single message
       
    83 	CLbsSuplWapPush* wapPush = MakePluginLC();
       
    84 	CPushMessage* msg = MakeMessageLC(iSendFillDigit++);
       
    85 	iReceived = EFalse;
       
    86 	iSenderError = KErrNone;
       
    87 	wapPush->HandleMessageL(msg);
       
    88 	CleanupStack::Pop(msg);
       
    89 	iSchedulerWait->Start();
       
    90 	if(iUnexpectedError!=KErrNone || iSenderError!=KErrNone || !iReceived)
       
    91 		{
       
    92 		User::Leave(EFail);
       
    93 		}
       
    94 	
       
    95 	
       
    96 	//Dummy calls just to improve the BullsEye code coverage statistics
       
    97 	TRequestStatus dummyStatus;
       
    98 	wapPush->HandleMessageL(NULL, dummyStatus);
       
    99 	wapPush->CancelHandleMessage();
       
   100 	wapPush->CPushHandlerBase_Reserved1();
       
   101 	wapPush->CPushHandlerBase_Reserved2();
       
   102 	wapPush->RunL();
       
   103 	wapPush->DoCancel();
       
   104 	
       
   105 	TInt dummyInt;
       
   106 	ImplementationGroupProxy(dummyInt);
       
   107 	CleanupStack::PopAndDestroy(wapPush);
       
   108 	
       
   109 	
       
   110 	//Passing empty message
       
   111 	wapPush = MakePluginLC();
       
   112 	iReceived = EFalse;
       
   113 	wapPush->HandleMessageL(NULL);
       
   114 	CleanupStack::PopAndDestroy(wapPush);
       
   115 	if(iUnexpectedError!=KErrNone || iReceived)
       
   116 		{
       
   117 		User::Leave(EFail);
       
   118 		}
       
   119 	
       
   120 	
       
   121 	//Passing a message with an empty body
       
   122 	wapPush = MakePluginLC();
       
   123 	HBufC8* hdr = HBufC8::NewLC(1);
       
   124 	msg = CPushMessage::NewL(hdr, NULL);
       
   125 	CleanupStack::Pop(hdr);
       
   126 	CleanupStack::PushL(msg);
       
   127 	iReceived = EFalse;
       
   128 	wapPush->HandleMessageL(msg);
       
   129 	CleanupStack::Pop(msg);
       
   130 	CleanupStack::PopAndDestroy(wapPush);
       
   131 	if(iUnexpectedError!=KErrNone || iReceived)
       
   132 		{
       
   133 		User::Leave(EFail);
       
   134 		}
       
   135 	
       
   136 	//Memory allocation failure test - creation of CLbsSuplWapPush	
       
   137 	TInt* marker = new TInt(0);
       
   138 	delete marker;
       
   139 	for(TInt i=1; marker; i++)
       
   140 		{			
       
   141 		__UHEAP_FAILNEXT(i);
       
   142 		
       
   143 		wapPush = 0;
       
   144 		TRAPD(err, wapPush = CLbsSuplWapPush::NewL());
       
   145 		delete wapPush;
       
   146 		
       
   147 		marker = new TInt(0);
       
   148 		delete marker;
       
   149 		
       
   150 		if(!marker || (marker && err==KErrNone)) 
       
   151 			{
       
   152 			if(wapPush==0)
       
   153 				{
       
   154 				User::Leave(KErrGeneral);
       
   155 				}
       
   156 			User::LeaveIfError(err);
       
   157 			}
       
   158 		}
       
   159 	
       
   160 	//Memory allocation failure test - handling of a message	
       
   161 	marker = new TInt(0);
       
   162 	delete marker;
       
   163 	for(TInt i=1; marker; i++)
       
   164 		{			
       
   165 		wapPush = MakePluginLC();
       
   166 		iRecvFillDigit = iSendFillDigit;
       
   167 		CPushMessage* msg = MakeMessageLC(iSendFillDigit++);
       
   168 		
       
   169 		__UHEAP_FAILNEXT(i);
       
   170 		
       
   171 		iReceived = EFalse;
       
   172 		iSenderError = KErrNone;
       
   173 		TRAPD(err, wapPush->HandleMessageL(msg));
       
   174 		CleanupStack::Pop(msg);
       
   175 		iSchedulerWait->Start(12000000);
       
   176 		CleanupStack::PopAndDestroy(wapPush);
       
   177 		User::LeaveIfError(err); //this function does not leave
       
   178 		User::LeaveIfError(iUnexpectedError);
       
   179 		
       
   180 		marker = new TInt(0);
       
   181 		delete marker;
       
   182 		
       
   183 		if(!marker) //that is there were no errors in the code tested 
       
   184 			{
       
   185 			if(iSenderError!=KErrNone || !iReceived)
       
   186 				{
       
   187 				User::Leave(EFail);
       
   188 				}
       
   189 			}
       
   190 		else //there was an allocation error in the code tested
       
   191 			{
       
   192 			if(iSenderError!=KErrNone && iSenderError!=KErrTimedOut)
       
   193 				{
       
   194 				User::Leave(EFail);
       
   195 				}
       
   196 			}
       
   197 		}	
       
   198 	}
       
   199 
       
   200 
       
   201 /**
       
   202 Overrides the pure virtual MLbsSuplPushRecObserver::OnSuplInit. Receives notifications about 
       
   203 incoming SUPL INIT messages.
       
   204 
       
   205 @param aChannel  [In] The channel the call-back is related to.
       
   206 @param aReqId    [In] An Id of the request the call-back is related to.
       
   207 @param aMsg      [In] A buffer containing a SUPL INIT message.
       
   208 
       
   209 @see MLbsSuplPushRecObserver::OnSuplInit
       
   210 @see CLbsSuplPushRec
       
   211 */
       
   212 void CTe_LbsSuplWapPushStep::OnSuplInit(TLbsSuplPushChannel aChannel, 
       
   213 		TLbsSuplPushRequestId /*aReqId*/, TDesC8& aMsg)
       
   214 	{
       
   215 	iReceived = ETrue;
       
   216 	if(aChannel!=ELbsSuplPushChannelWAP || !CompareMessage(iRecvFillDigit++, aMsg))
       
   217 		{
       
   218 		if(aChannel!=ELbsSuplPushChannelWAP)
       
   219 			{
       
   220 			ERR_PRINTF1(_L("CTe_LbsSuplWapPushStep::OnSuplInit: aChannel!=ELbsSuplPushChannelWAP"));
       
   221 			}
       
   222 		iUnexpectedError = KErrGeneral;;
       
   223 		iSchedulerWait->AsyncStop();
       
   224 		return;
       
   225 		}
       
   226 	}
       
   227 
       
   228 /**
       
   229 Overrides the pure virtual MLbsSuplPushObserver::OnSuplInitComplete. Receives message delivery 
       
   230 notifications.
       
   231 
       
   232 @param aChannel  [In] The channel the call-back is related to.
       
   233 @param aReqId    [In] An Id of the request the call-back is related to.
       
   234 @param aError    [In] KErrNone if successful, KErrTimeout if it was not possible to deliver
       
   235 	                      the request before the timeout period, KErrArgument if the structure 
       
   236 	                      or content of the SUPL INIT message was incorrect. 
       
   237 	                      Any system wide error code otherwise.
       
   238 @param aReserved [In] Reserved for future use.
       
   239 
       
   240 @see MLbsSuplPushObserver::OnSuplInitComplete
       
   241 @see CLbsSuplPush
       
   242 */
       
   243 void CTe_LbsSuplWapPushStep::OnSuplInitComplete(TLbsSuplPushChannel aChannel, 
       
   244 		TLbsSuplPushRequestId /*aReqId*/, TInt aError, TInt /*aReserved*/)
       
   245 	{
       
   246 	iSenderError = aError;
       
   247 	if(aChannel!=ELbsSuplPushChannelWAP)
       
   248 		{
       
   249 		ERR_PRINTF1(_L("CTe_LbsSuplSmsTriggerIntegStep::OnSuplInit: aChannel!=ELbsSuplPushChannelSMS"));
       
   250 		iUnexpectedError = KErrGeneral;;
       
   251 		}
       
   252 	iSchedulerWait->AsyncStop();
       
   253 	}
       
   254 
       
   255 CLbsSuplWapPush* CTe_LbsSuplWapPushStep::MakePluginLC()
       
   256 	{
       
   257 	CLbsSuplWapPush* wapPush = CLbsSuplWapPush::NewL();
       
   258 	CleanupStack::PushL(wapPush);
       
   259 	return wapPush;
       
   260 	}
       
   261 
       
   262 CPushMessage* CTe_LbsSuplWapPushStep::MakeMessageLC(TUint aNum)
       
   263 	{
       
   264 	HBufC8* body = HBufC8::NewMaxLC(KTestMsgLength);
       
   265 	HBufC8* hdr = HBufC8::NewLC(1);
       
   266 	TPtr8 des = body->Des();
       
   267 	aNum = aNum%10;
       
   268 	for(TUint i=0;i<KTestMsgLength;i++)
       
   269 		{
       
   270 		des[i]=aNum;
       
   271 		}
       
   272 	
       
   273 	des[0] = 0;
       
   274 	des[1] = 0;
       
   275 
       
   276 	// set the encoded length field
       
   277 	des[0] |= (TUint8)( KTestMsgLength >> 8 );
       
   278 	des[1] |= (TUint8)( KTestMsgLength );
       
   279 	
       
   280 	CPushMessage* msg = CPushMessage::NewL(hdr, body);
       
   281 	CleanupStack::Pop(hdr);
       
   282 	CleanupStack::Pop(body);
       
   283 	CleanupStack::PushL(msg);
       
   284 	return msg;
       
   285 	}
       
   286 
       
   287 /**
       
   288 Generates a message using the pattern specified and compares it with the given message.
       
   289 
       
   290 @param aNum [In] The number used to fill the generated message.
       
   291 
       
   292 @return ETrue if the messages are identical, EFalse otherwise.
       
   293 
       
   294 @see CTe_LbsSuplWapPushStep::OnSuplInit
       
   295 @see CTe_LbsSuplWapPushStep::SendMessage
       
   296 */
       
   297 TBool CTe_LbsSuplWapPushStep::CompareMessage(TUint aNum, TDesC8& aMsg)
       
   298 	{
       
   299 	aNum = aNum%10;
       
   300 	
       
   301 	if ( aMsg[0] != (TUint8)( KTestMsgLength >> 8 )
       
   302 	  || aMsg[1] != (TUint8)( KTestMsgLength ) )
       
   303 		{
       
   304 		ERR_PRINTF1(_L("CTe_LbsSuplWapPushStep::CompareMessage: wrong message length"));
       
   305 		return EFalse;
       
   306 		}
       
   307 	
       
   308 	for(TUint i=2;i<KTestMsgLength;i++)
       
   309 		{
       
   310 		if(aMsg[i]!=aNum)
       
   311 			{
       
   312 			ERR_PRINTF1(_L("CTe_LbsSuplWapPushStep::CompareMessage: wrong message"));
       
   313 			return EFalse;
       
   314 			}
       
   315 		}
       
   316 	return ETrue;
       
   317 	}
       
   318 
       
   319