smsprotocols/smsstack/smsprot/Test/TE_Smsprt/TE_SendReceiveSMSWhileServerInOOM.cpp
changeset 0 3553901f7fa8
child 14 7ef16719d8cb
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     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 // TE_SendReceiveSMSWhileServerInOOM.cpp.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include "Te_SmsTestSteps.h"
       
    23 
       
    24 CSendReceiveSMSWhileServerInOOM::CSendReceiveSMSWhileServerInOOM(RSocketServ &aSocketServer)
       
    25 /** 
       
    26 	Each test step initialises it's own name
       
    27 */
       
    28 	{
       
    29 	iSocketServer = &aSocketServer;
       
    30 	}
       
    31 
       
    32 /**
       
    33   Send and Receive a SMS Message while the socket server has been placed in OOM
       
    34 */
       
    35 TVerdict CSendReceiveSMSWhileServerInOOM::doTestStepL()
       
    36 	{
       
    37 #ifndef _DEBUG
       
    38     INFO_PRINTF1(_L("This test can only be run when the SMS Stack is in debug mode."));
       
    39 #else	
       
    40 	//Read from the INI file.  
       
    41 	TInt timeout=10;
       
    42 	GetIntFromConfig(ConfigSection(), _L("timeout"), timeout);
       
    43 	
       
    44 	
       
    45 	//Open the socket for sending messages
       
    46 	RSocket socket;
       
    47 	INFO_PRINTF1(_L("Opening socket and loading SMS Protocol"));
       
    48 	OpenSmsSocketL(*iSocketServer, socket, ESmsAddrSendOnly);
       
    49 	
       
    50 	//Create SMS
       
    51 	CSmsMessage* iSms=CreateSMSL();
       
    52 	CleanupStack::PushL(iSms);
       
    53 
       
    54 	TBool isClientExpectingMessage;
       
    55 	GetBoolFromConfig(ConfigSection(), _L("isClientExpectingMessage"), isClientExpectingMessage);
       
    56 
       
    57 	INFO_PRINTF1(_L("Sending SMS...") );
       
    58 	PrintMessageL(iSms);
       
    59 			
       
    60 	//Send SMS
       
    61 	SendSmsL(iSms,socket);
       
    62 	CleanupStack::PopAndDestroy(iSms);
       
    63 	socket.Close();
       
    64 	
       
    65 	//Open the socket for receiving messages
       
    66 	INFO_PRINTF1(_L("Opening socket and loading SMS Protocol"));
       
    67 	RSocket recSocket;
       
    68 	OpenSmsSocketL(*iSocketServer, recSocket, ESmsAddrRecvAny);
       
    69 
       
    70 	//Receive
       
    71 	TInt allocFailCount=0;
       
    72 	TInt ret=KErrNoMemory;
       
    73 	while (ret==KErrNoMemory || ret==KErrEof)
       
    74 		{
       
    75 				
       
    76 		INFO_PRINTF2(_L("Heap checking for allocation %d"),allocFailCount );
       
    77 		//Message must be received in "timeout" else the test will fail	
       
    78 		TBool messageReceived = TimedWaitForRecvL(recSocket, timeout*1000000);
       
    79 		
       
    80 		//Set the result to "fail" if no message is received in the specified time
       
    81 		if(messageReceived && isClientExpectingMessage )
       
    82 			{
       
    83 			INFO_PRINTF1(_L("Message received!"));
       
    84 			
       
    85 			iSocketServer->__DbgMarkHeap();
       
    86 			iSocketServer->__DbgFailNext(allocFailCount);
       
    87 			
       
    88 			CSmsMessage *iSmsMessage=NULL;
       
    89 			
       
    90 			TRAP(ret,iSmsMessage=RecvSmsL(recSocket));	//Get the message from the STACK.
       
    91 			iSocketServer->__DbgMarkEnd(0);			
       
    92 
       
    93 			//If a message was retrieved successfully.
       
    94 			if(ret==KErrNone)
       
    95 				{
       
    96 				INFO_PRINTF1(_L("Message received!"));		
       
    97 			
       
    98 				CleanupStack::PushL(iSmsMessage);
       
    99 				
       
   100 				//Get the text from the ini file
       
   101 				TPtrC messageText;
       
   102 				GetStringFromConfig(ConfigSection(), _L("messageExpected"), messageText);
       
   103 
       
   104 				if(messageText!=_L(""))
       
   105 					{
       
   106 					TestSmsContentsL(iSmsMessage,messageText);
       
   107 					}
       
   108 				
       
   109 				CleanupStack::PopAndDestroy(iSmsMessage);
       
   110 				}
       
   111 		
       
   112 			allocFailCount++;
       
   113 			}
       
   114 		
       
   115 		}
       
   116 
       
   117 	recSocket.Close();
       
   118 	iSocketServer->__DbgFailNext(-1); // Reset heap
       
   119 #endif	
       
   120 	return TestStepResult();
       
   121 	}
       
   122 
       
   123 //-------------------------------------------------------------------------------------