messagingfw/wappushfw/examples/PushAppHandlerEx/test/t_baseMessage.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 // common code shared between the test classes:
       
    15 // CWapPushSIMessageTest
       
    16 // CWapPushSLMessageTest
       
    17 // CWapPushMMMessageTest
       
    18 // 
       
    19 //
       
    20 
       
    21 #include "pushtests.h"
       
    22 #include "dummywapstack.h"
       
    23 #include "WPushUtils.h"
       
    24 
       
    25 _LIT(KTextFinished,"All finished");
       
    26 
       
    27 
       
    28 
       
    29 /** all derived classes use this RunL to move between the states listed.
       
    30 	starts up setting up required test enbvironment, then creates a test
       
    31 	message which is simualted as a push. This 'push' stage can be repeated
       
    32 	for multiple messages and once all messages passed finishes up. */
       
    33 void CWapPushBaseMessageTest::RunL()
       
    34 	{
       
    35 	switch (iState)
       
    36 		{
       
    37 	case EInitialisation:
       
    38 		{
       
    39 		// Create WAP Stack passing MDummyWapStackObserver derived instance
       
    40 		// Create Connection Manager, once WAP stack setup
       
    41 		iWapStack = CDummyWapStack::NewL(*this);
       
    42 		iConnMan =  CConnectionManager::NewL(*this);
       
    43 		NumberTestCasesToRun();
       
    44 		iHasMsgBeenCompleted=EFalse;
       
    45 		iHasTestBeenCompleted=EFalse;
       
    46 		MoveToNextState();
       
    47 		return;
       
    48 		}
       
    49 	case EWaitForPush:
       
    50 		{
       
    51 		// wait for callback to move to the next state
       
    52 		if (iHasTestBeenCompleted)
       
    53 			MoveToNextState();
       
    54 		return;
       
    55 		}
       
    56 	case EFinished:
       
    57 		{
       
    58 		Printf(KTextFinished);
       
    59 		SetPriority(EPriorityIdle);
       
    60 		MoveToNextState();
       
    61 		return;
       
    62 		}
       
    63 	default:
       
    64 		// Finished
       
    65 		ConfirmMessagesSavedL();
       
    66 		iEngine->TestCompleted(iStatus.Int());
       
    67 		return;
       
    68 		}
       
    69 	};
       
    70 
       
    71 void CWapPushBaseMessageTest::RunError()
       
    72 	{
       
    73 	_LIT(KRunError, "CWapPushTestEngine::RunError");
       
    74 	iEngine->Printf(TestName(), KRunError);
       
    75 	iState = EFinished;
       
    76 	}
       
    77 
       
    78 
       
    79 /** destructor */
       
    80 CWapPushBaseMessageTest::~CWapPushBaseMessageTest()
       
    81 	{
       
    82 	delete iConnMan;
       
    83 	delete iWapStack;
       
    84 	}	
       
    85 
       
    86 /** cancel any active request and clean up before returning to main test
       
    87 	harness
       
    88 */
       
    89 void CWapPushBaseMessageTest::DoCancel()
       
    90 	{
       
    91 	delete iConnMan;
       
    92 	delete iWapStack;
       
    93 	iEngine->TestCompleted(KErrCancel);
       
    94 	}
       
    95 
       
    96 /** increment the value of iState and set active to create call to RunL
       
    97 	with new state value 
       
    98 */
       
    99 void CWapPushBaseMessageTest::MoveToNextState()
       
   100 	{ 
       
   101 	iState = (TState)(iState+1); 
       
   102 	CompleteOwnRequest();
       
   103 	}
       
   104 
       
   105 /** set this object active */
       
   106 void CWapPushBaseMessageTest::CompleteOwnRequest()
       
   107 	{
       
   108 	TRequestStatus* stat = &iStatus;
       
   109 	User::RequestComplete(stat,KErrNone);	
       
   110 	if (!IsActive())
       
   111 		SetActive();
       
   112 	}
       
   113 
       
   114 /** sets base test name.
       
   115 	@param void
       
   116 	@return string - the test name 
       
   117 */
       
   118 const TDesC& CWapPushBaseMessageTest::TestName()
       
   119 	{
       
   120 	_LIT(KTextBaseMessageTest,"Base Message Test");
       
   121 	return KTextBaseMessageTest;
       
   122 	}
       
   123 
       
   124 
       
   125 /** 
       
   126 	called by DummyWapStack and returns the push message which is
       
   127 	created by the call to PrepareTestMessageL. The message is
       
   128 	then passed through to aDummyCLConn which accepts as much of
       
   129 	the message as possible and if this is not equal to the whole
       
   130 	message then issues a rerquest for the rest of the message which
       
   131 	retruns here.
       
   132 	@param CDummyWSPCLConn
       
   133 	@return void 
       
   134 
       
   135 if all tests have completed - move to the next test state and complete own req
       
   136 if all of msg received - move to next message
       
   137 
       
   138 	Each derived class should have its own implementation of PrepareTestMessage
       
   139 	which will be called from this method. This will allow a variable number of
       
   140 	test cases to be used to test the push aspect of the dummy wap stack.
       
   141 */
       
   142 void CWapPushBaseMessageTest::DWSOUnitWaitPushL(CDummyWSPCLConn& aDummyCLConn)	
       
   143 	{
       
   144 	if (iHasTestBeenCompleted)
       
   145 		{	
       
   146 		CompleteOwnRequest();
       
   147 		return;
       
   148 		}
       
   149 	
       
   150 	PrepareTestMessageL(iCurrentTestCase);
       
   151 
       
   152 	aDummyCLConn.CompleteUnitWaitPushL(iBodyBuf, iHeadersBuf); // asynch
       
   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::DWSOGetEvent(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