messagingfw/wappushfw/tpushscriptbased/t_baseMessage.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     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 "pushtests.h"
       
    17 #include "dummywapstack.h"
       
    18 #include <push/cwappushmsgutils.h>
       
    19 
       
    20 
       
    21 _LIT(KTextFinished,"All finished");
       
    22 
       
    23 
       
    24 /** all derived classes use this RunL to move between the states listed.
       
    25 	starts up setting up required test enbvironment, then creates a test
       
    26 	message which is simualted as a push. This 'push' stage can be repeated
       
    27 	for multiple messages and once all messages passed finishes up. */
       
    28 void CWapPushBaseMessageTest::RunL()
       
    29 	{
       
    30 	switch (iState)
       
    31 		{
       
    32 	case EInitialisation:
       
    33 		{
       
    34 		// Create WAP Stack passing MDummyWapStackObserver derived instance
       
    35 		// Create Connection Manager, once WAP stack setup
       
    36 		iWapStack = CDummyWapStack::NewL(*this);
       
    37 		iConnMan =  CConnectionManager::NewL(*this);
       
    38 		NumberTestCasesToRun();
       
    39 		iHasMsgBeenCompleted=EFalse;
       
    40 		iHasTestBeenCompleted=EFalse;
       
    41 		MoveToNextState();
       
    42 		return;
       
    43 		}
       
    44 	case EWaitForPush:
       
    45 		{
       
    46 		// wait for callback to move to the next state
       
    47 		if (iHasTestBeenCompleted)
       
    48 			MoveToNextState();
       
    49 		return;
       
    50 		}
       
    51 	case EFinished:
       
    52 		{
       
    53 		Printf(KTextFinished);
       
    54 		SetPriority(EPriorityIdle);
       
    55 		MoveToNextState();
       
    56 		return;
       
    57 		}
       
    58 	default:
       
    59 		// Finished
       
    60 		User::LeaveIfError(ConfirmMessagesSavedL());
       
    61 		iEngine->TestCompleted(iStatus.Int());
       
    62 		return;
       
    63 		}
       
    64 	};
       
    65 
       
    66 TInt CWapPushBaseMessageTest::RunError(TInt aError)
       
    67 	{
       
    68 	TBuf<80> buf;
       
    69 	_LIT(KComment, "!! Error - %d in RunError()");
       
    70 	buf.Format(KComment, aError);
       
    71 	
       
    72 	iEngine->Printf(buf, TestName());
       
    73 	iState = EFinished;
       
    74 	iEngine->TestCompleted(aError);	
       
    75 	return KErrNone;
       
    76 	}
       
    77 
       
    78 /** destructor */
       
    79 CWapPushBaseMessageTest::~CWapPushBaseMessageTest()
       
    80 	{
       
    81 	delete iConnMan;
       
    82 	delete iWapStack;
       
    83 	}	
       
    84 
       
    85 /** cancel any active request and clean up before returning to main test
       
    86 	harness
       
    87 */
       
    88 void CWapPushBaseMessageTest::DoCancel()
       
    89 	{
       
    90 	delete iConnMan;
       
    91 	delete iWapStack;
       
    92 	iEngine->TestCompleted(KErrCancel);
       
    93 	}
       
    94 
       
    95 /** increment the value of iState and set active to create call to RunL
       
    96 	with new state value 
       
    97 */
       
    98 void CWapPushBaseMessageTest::MoveToNextState()
       
    99 	{ 
       
   100 	iState = (TState)(iState+1); 
       
   101 	CompleteOwnRequest();
       
   102 	}
       
   103 
       
   104 /** set this object active */
       
   105 void CWapPushBaseMessageTest::CompleteOwnRequest()
       
   106 	{
       
   107 	TRequestStatus* stat = &iStatus;
       
   108 	User::RequestComplete(stat,KErrNone);	
       
   109 	if (!IsActive())
       
   110 		SetActive();
       
   111 	}
       
   112 
       
   113 /** sets base test name.
       
   114 	@param void
       
   115 	@return string - the test name 
       
   116 */
       
   117 const TDesC& CWapPushBaseMessageTest::TestName()
       
   118 	{
       
   119 	_LIT(KTextBaseMessageTest,"Base Message Test");
       
   120 	return KTextBaseMessageTest;
       
   121 	}
       
   122 
       
   123 /** 
       
   124 	called by DummyWapStack and returns the push message which is
       
   125 	created by the call to PrepareTestMessageL. The message is
       
   126 	then passed through to aDummyCLConn which accepts as much of
       
   127 	the message as possible and if this is not equal to the whole
       
   128 	message then issues a rerquest for the rest of the message which
       
   129 	retruns here.
       
   130 	@param CDummyWSPCLConn
       
   131 	@return void 
       
   132 
       
   133 if all tests have completed - move to the next test state and complete own req 
       
   134 if all of msg received - move to next message
       
   135 
       
   136 	Each derived class should have its own implementation of PrepareTestMessage
       
   137 	which will be called from this method. This will allow a variable number of
       
   138 	test cases to be used to test the push aspect of the dummy wap stack.
       
   139 */
       
   140 void CWapPushBaseMessageTest::DWSOUnitWaitPushL(CDummyWSPCLConn& aDummyCLConn)	
       
   141 	{
       
   142 	if (iHasTestBeenCompleted)
       
   143 		{	
       
   144 		CompleteOwnRequest();
       
   145 		return;
       
   146 		}
       
   147 	
       
   148 	PrepareTestMessageL(iCurrentTestCase);
       
   149 
       
   150 	aDummyCLConn.CompleteUnitWaitPushL(iBodyBuf, iHeadersBuf); // asynch
       
   151 
       
   152 	aDummyCLConn.SetServerAddressL(Uri());
       
   153 	
       
   154 	iHasMsgBeenCompleted=aDummyCLConn.HasMsgBeenCompleted();
       
   155 	
       
   156 	if (iHasMsgBeenCompleted)
       
   157 		{
       
   158 		iHasMsgBeenCompleted=EFalse;
       
   159 		iCurrentTestCase++;
       
   160 		}
       
   161 
       
   162 	iHasTestBeenCompleted = (iCurrentTestCase >= iNumberOfTestCases);
       
   163 	}
       
   164 
       
   165 /**
       
   166 	display error message
       
   167 	@param	string 
       
   168 	@param	line number
       
   169 */
       
   170 void CWapPushBaseMessageTest::DWSOError(const TDesC& aDes, TInt /*aLineNum*/)
       
   171 	{
       
   172 	// TO DO: format message + ?
       
   173 	
       
   174 	// simply display error message for now
       
   175 	iEngine->Printf(TestName(),aDes);
       
   176 	}
       
   177 
       
   178 /**
       
   179 	Wap Stack Server closing...
       
   180 */
       
   181 void CWapPushBaseMessageTest::DWSOServerShutDown()
       
   182 	{
       
   183 	_LIT(KWPSLServerShutdown,"Wap stack server closing down");
       
   184 	iEngine->Printf(TestName(), KWPSLServerShutdown);
       
   185 	}
       
   186 
       
   187 /**
       
   188  *	Cancel pushwait operation
       
   189  */
       
   190 void CWapPushBaseMessageTest::DWSOCancelUnitWaitPush(CDummyWSPCLConn& /*aDummyCLConn*/)
       
   191 	{
       
   192 	Cancel(); // CActive closes open requests
       
   193 	// ignore aDummyCLConn (not sure why being passed in)
       
   194 	}	
       
   195 
       
   196 /** placeholder method - does nothing */
       
   197 void CWapPushBaseMessageTest::DWSOConnect(CDummyWSPCOConn&)
       
   198 	{
       
   199 	}
       
   200 
       
   201 /** placeholder method - does nothing */
       
   202 void CWapPushBaseMessageTest::DWSOGetEventL(CDummyWSPCOConn&)
       
   203 	{
       
   204 	}
       
   205 
       
   206 /** placeholder method - does nothing */
       
   207 void CWapPushBaseMessageTest::DWSOCancelGetEvent(CDummyWSPCOConn&)
       
   208 	{
       
   209 	}
       
   210 
       
   211 /** placeholder method - does nothing */
       
   212 void CWapPushBaseMessageTest::DWSOAckTransaction(CDummyWSPCOTrans&)
       
   213 	{
       
   214 	}
       
   215 
       
   216 /** indicates number of test cases to run which should be implimented
       
   217 	in a suitable switch statement in derieved class method:
       
   218 	PrepareTestMessages()
       
   219 */
       
   220 void CWapPushBaseMessageTest::NumberTestCasesToRun()
       
   221 	{
       
   222 	// default - override for derived classes 
       
   223 	iNumberOfTestCases = 1;
       
   224 	}
       
   225 
       
   226 
       
   227 
       
   228