smsprotocols/smsstack/wapprot/test/Te_wapprot/WapProtSuiteStepBase.cpp
changeset 20 244d7c5f118e
parent 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
19:1f776524b15c 20:244d7c5f118e
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 /**
    16 /**
    17  @file
    17     @file
    18 */
    18     @test
    19 
    19 */
    20 #include <sacls.h>
    20 
    21 #include <smspver.h>
       
    22 #include "WapProtSuiteStepBase.h"
    21 #include "WapProtSuiteStepBase.h"
       
    22 
       
    23 #include <Gsmumsg.h>
       
    24 #include <gsmubuf.h>
       
    25 
       
    26 #include "smspver.h"
    23 #include "WapProtSuiteDefs.h"
    27 #include "WapProtSuiteDefs.h"
    24 
    28 #include "wap_sock.h"
    25 /**
    29 #include "smsstacktestconsts.h"
    26 Utility for setting the test number used by SIM TSY
    30 
    27 */
    31 TVerdict CWapProtSuiteStepBase::doTestStepPreambleL()
    28 void CWapProtSuiteStepBase::SetTestNumberL()
    32 /**
    29 {
    33  *  @return - TVerdict
    30 	TInt testNumber;
    34  *  Implementation of CTestStep base class virtual
    31 	GetIntFromConfig(ConfigSection(), _L("testNumber"), testNumber);
    35  *  Do all initialisation common to derived classes in here.
    32 
       
    33 	RProperty testNumberProperty;
       
    34 	User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber));
       
    35 	CleanupClosePushL(testNumberProperty);
       
    36 
       
    37 	TRequestStatus status;
       
    38 	testNumberProperty.Subscribe(status);
       
    39 	INFO_PRINTF1(_L("Setting Sim.Tsy test number P&S property"));
       
    40 	User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNumber));
       
    41 	User::WaitForRequest(status);
       
    42 	
       
    43 	TEST(status.Int() == KErrNone);
       
    44 	TInt testNumberCheck;
       
    45 	User::LeaveIfError(testNumberProperty.Get(testNumberCheck));
       
    46 	if (testNumber != testNumberCheck)
       
    47 		{
       
    48 	    INFO_PRINTF3(_L("Test number property set to [%d], but value returned is [%d]"),testNumber,testNumberCheck);
       
    49 		User::Leave(KErrNotFound);
       
    50 		}
       
    51 
       
    52 	CleanupStack::PopAndDestroy(&testNumberProperty);
       
    53 
       
    54 }
       
    55 
       
    56 
       
    57 void CWapProtSuiteStepBase::WaitForRecvL(RSocket& aSocket)
       
    58 /**
       
    59  * Wait for an Sms to be received
       
    60  * @param aSocket The status is return to this socket
       
    61  * @leave Leaves if receiving is completed with error code
       
    62  */
    36  */
    63 	{
    37 	{
    64 	TPckgBuf<TUint> sbuf;
    38     //base class preamble - marks the heap
    65 	sbuf()=KSockSelectRead;
    39     CSmsBaseTestStep::doTestStepPreambleL();
    66 	TRequestStatus status;
    40     
    67 	aSocket.Ioctl(KIOctlSelect,status,&sbuf,KSOLSocket);
    41 	return TestStepResult();
    68 	User::WaitForRequest(status);
    42 	}
    69 	TEST(status.Int() == KErrNone);
    43 
    70 	}
    44 TVerdict CWapProtSuiteStepBase::doTestStepPostambleL()
    71 
    45 	{
    72 
    46     //base class postamble - unmarks the heap
    73 CSmsMessage* CWapProtSuiteStepBase::RecvSmsL(RSocket& aSocket, TInt aIoctl)
    47     CSmsBaseTestStep::doTestStepPostambleL();
    74 /**
    48 	
    75  * Receive an Sms
    49 	return TestStepResult();
    76  * @param aSocket is used to stream the sms message from the socket server
    50 	}
    77  * @return CSmsMessage* :Sms message from Sms stack
    51 
    78  * @leave Leaves if streaming the message from the socket server doesn't succeed
    52 /**
    79  */
    53 	Set up and open socket
    80 	{
    54 */
    81 
    55 void CWapProtSuiteStepBase::SetupWapSocketL()
    82 	RFs lFs;	
    56 	{
    83 	User::LeaveIfError(lFs.Connect());
    57 	SetupWapSocketL(iSocket, iWapAddr, KWapPort);
    84 	
    58 	}
    85 	CSmsBuffer* buffer=CSmsBuffer::NewL();
    59 
    86 	CSmsMessage* smsMessage=CSmsMessage::NewL(lFs, CSmsPDU::ESmsSubmit,buffer);
    60 void CWapProtSuiteStepBase::SetupWapSocketL(RSocket& aSocket, TWapAddr& aWapAddr, const TDesC& aPort, TBool aNewStyleClient)
    87 	CleanupStack::PushL(smsMessage);
    61     {
    88 
    62     OpenSocketL(iSocketServer, aSocket);
    89 	RSmsSocketReadStream readstream(aSocket);
    63 
    90 	TRAPD(ret,readstream >> *smsMessage);
    64     //Read port and SC number from ini file
    91 	TEST(ret == KErrNone);
    65     ReadWapPortSettingsL(aWapAddr, aPort);
    92 
    66     
    93 	TPckgBuf<TUint> sbuf;
    67     if (aNewStyleClient)
    94 	TRequestStatus status;
    68         {
    95 	aSocket.Ioctl(aIoctl, status, &sbuf, KSolSmsProv);
    69         //  Indicating to the protocol that it's a new client
    96 	User::WaitForRequest(status);
    70         INFO_PRINTF1(_L("Socket set option for indicating new client"));
    97 
    71         TInt ret = aSocket.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0);
    98 	CleanupStack::Pop(smsMessage);
    72         TESTCHECKL(ret, KErrNone, "Indicating to the protocol that it's a new client")
    99 	
    73         }
   100 	lFs.Close();
    74     
   101 	
    75     //  Bind
   102 	return smsMessage;
    76     TInt ret = aSocket.Bind(aWapAddr);
   103 	}
    77     TESTCHECKL(ret, KErrNone, "Socket bind");
   104 
    78     
   105 
    79     TProtocolDesc desc;
   106 
    80     aSocket.Info(desc);
   107 /**
    81     INFO_PRINTF2(_L("Protocol name: %S"), &desc.iName);
   108 Utility for setting up the WAP address - Port number and service center address
    82 	
   109 */
    83     TTimeIntervalMicroSeconds32 InitPause=9000000;  //Required Pause to Allow SMSStack to Complete its Async Init
   110 void CWapProtSuiteStepBase::SetWapAddrL()
    84     User::After(InitPause);                         //call to the TSY and finish its StartUp.
   111 {
    85 
   112 	TInt port;
    86     }
   113 
       
   114 	//Get the port number from the ini file
       
   115 	GetIntFromConfig(ConfigSection(),_L("port"), port);
       
   116 	
       
   117 	iWapAddr.SetWapPort(TWapPortNumber(port));
       
   118 
       
   119 	//Get the service center number
       
   120 	TPtrC telNumber;
       
   121 	GetStringFromConfig(ConfigSection(),_L("telNumber"), telNumber);
       
   122 	TBuf8<100> scNumber;
       
   123 	scNumber.Copy(telNumber);
       
   124 	TPtrC8 scAddr(scNumber);
       
   125 	iWapAddr.SetWapAddress(scAddr);
       
   126 	
       
   127 	//	Bind
       
   128 	User::LeaveIfError(iSocket.Bind(iWapAddr));
       
   129 }
       
   130 
       
   131 
    87 
   132 /**
    88 /**
   133 Setup a socket for receiving status repots
    89 Setup a socket for receiving status repots
   134 */
    90 */
   135 void CWapProtSuiteStepBase::SetupStatusReportSocketL()
    91 void CWapProtSuiteStepBase::SetupStatusReportSocketL()
   136 {
    92 {
   137 	//	Open the socket for receiving status reports
    93     //  Open the socket for receiving status reports
   138     User::LeaveIfError(iStatusReportSocket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol));
    94     OpenSocketL(iSocketServer, iStatusReportSocket, KSMSAddrFamily, KSMSDatagramProtocol);
   139 	
    95     
   140 	//Bind to the socket
    96     //Bind to the socket
   141 	//TSmsAddr smsAddr;
    97     iSmsAddr.SetSmsAddrFamily(ESmsAddrStatusReport);
   142 	iSmsAddr.SetSmsAddrFamily(ESmsAddrStatusReport);
    98     TInt ret=iStatusReportSocket.Bind(iSmsAddr);
   143 	TInt ret=iStatusReportSocket.Bind(iSmsAddr);
    99     TESTCHECKL(ret, KErrNone, "Status Report Socket bind");
   144 	INFO_PRINTF2(_L("Socket Bind Return Value : %d"),ret);
   100 
   145 	TESTL(ret == KErrNone);
   101     TProtocolDesc desc;
   146 	
   102     iStatusReportSocket.Info(desc);
   147 	//	Waiting for the phone to be initialised
   103     INFO_PRINTF2(_L("Protocol name: %S"), &desc.iName);
   148 	//WaitForInitializeL();
   104     
       
   105     TTimeIntervalMicroSeconds32 InitPause=9000000;  //Required Pause to Allow SMSStack to Complete its Async Init
       
   106     User::After(InitPause);                         //call to the TSY and finish its StartUp.
       
   107 
   149 }
   108 }
   150 
   109 
   151 
       
   152 /**
       
   153 Get the coding of the message
       
   154 */
       
   155 void CWapProtSuiteStepBase::SetCodingSchemeL()
       
   156 {
       
   157 	TInt dataCoding;
       
   158 
       
   159 	//Get the port number from the ini file
       
   160 	GetIntFromConfig(ConfigSection(),_L("dataCoding"), dataCoding);
       
   161 	
       
   162 	if(dataCoding==8)
       
   163 		iCodingScheme = EWapSms8BitDCS;
       
   164 	else
       
   165 		iCodingScheme = EWapSms7BitDCS;
       
   166 	
       
   167 	if(iCodingScheme==EWapSms8BitDCS)	
       
   168 		User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms8BitDCS));
       
   169 	else
       
   170 		User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms7BitDCS));
       
   171 }
       
   172 
       
   173 void CWapProtSuiteStepBase::SetMessageTypeL()
       
   174 {
       
   175 	//Get the type of message
       
   176 	TPtrC messageType;
       
   177 	GetStringFromConfig(ConfigSection(),_L("type"), messageType);
       
   178 
       
   179 	//Set the message type to WapDatagram
       
   180 	if(messageType.Compare(_L("Datagram")) ==0)
       
   181 		User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionWapDatagram,KWapSmsOptionLevel));	
       
   182 //	else
       
   183 //		User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionSmartMessage,KWapSmsOptionLevel));	
       
   184 			
       
   185 	//The creation of the message will set the type to SMART by default
       
   186 }
       
   187 	
       
   188 
       
   189 
       
   190 TVerdict CWapProtSuiteStepBase::doTestStepPreambleL()
       
   191 /**
       
   192  *  @return - TVerdict
       
   193  *  Implementation of CTestStep base class virtual
       
   194  *  Load serial drivers
       
   195  *  Do all initialisation common to derived classes in here.
       
   196  */
       
   197 	{
       
   198 	__UHEAP_MARK;
       
   199 	
       
   200 	iScheduler = new(ELeave) CActiveScheduler;
       
   201 	CActiveScheduler::Install(iScheduler);
       
   202 
       
   203 	iSecureBackupEngine = CSBEClient::NewL();
       
   204 	iSecureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
       
   205 									 EBURNormal, ENoBackup);
       
   206 
       
   207 	TInt err;
       
   208     err=User::LoadPhysicalDevice(PDD_NAME);
       
   209     TESTL(err == KErrNone  ||  err == KErrAlreadyExists);
       
   210 
       
   211     err=User::LoadLogicalDevice(LDD_NAME );
       
   212     TESTL(err == KErrNone  ||  err == KErrAlreadyExists);
       
   213 
       
   214     err = StartC32();
       
   215     if(err != KErrNone && err != KErrAlreadyExists)
       
   216         {
       
   217         ERR_PRINTF2(TRefByValue<const TDesC>(_L("Start Comms Process Status = %d")), err);
       
   218         SetTestStepResult(EFail);
       
   219         }
       
   220 
       
   221 	INFO_PRINTF1(_L("Deleting segmentation and reassembly stores..."));
       
   222 
       
   223 	RFs fileServer;
       
   224 	User::LeaveIfError(fileServer.Connect());
       
   225 
       
   226 	// delete segmentation and reassembly store files before the test
       
   227 	_LIT(KReassemblyStoreName,"C:\\Private\\101F7989\\sms\\smsreast.dat");
       
   228 	_LIT(KSegmentationStoreName,"C:\\Private\\101F7989\\sms\\smssegst.dat");
       
   229 	_LIT(KWapReassemblyStoreName,"C:\\Private\\101F7989\\sms\\wapreast.dat");
       
   230 
       
   231 	fileServer.Delete(KWapReassemblyStoreName);
       
   232 	fileServer.Delete(KReassemblyStoreName);
       
   233 	fileServer.Delete(KSegmentationStoreName);
       
   234 
       
   235 	fileServer.Close();
       
   236 
       
   237 	return TestStepResult();
       
   238 	}
       
   239 
       
   240 TVerdict CWapProtSuiteStepBase::doTestStepPostambleL()
       
   241 	{
       
   242 	delete iSecureBackupEngine;
       
   243 	iSecureBackupEngine = NULL;
       
   244 
       
   245 	delete iScheduler;
       
   246 	iScheduler = NULL;
       
   247 
       
   248 	__UHEAP_MARKEND;
       
   249 	
       
   250 	return TestStepResult();
       
   251 	}
       
   252 
       
   253 void CWapProtSuiteStepBase::WaitForInitializeL()
       
   254 	{
       
   255 	TName tsy(KTSY);
       
   256 	RTelServer serverT;
       
   257 	User::LeaveIfError(serverT.Connect());
       
   258 	CleanupClosePushL(serverT);
       
   259 	User::LeaveIfError(serverT.LoadPhoneModule(tsy));
       
   260 
       
   261 	// Find the phone corresponding to this TSY and open a number of handles on it
       
   262 	TInt numPhones;
       
   263 	User::LeaveIfError(serverT.EnumeratePhones(numPhones));
       
   264 	RPhone phone;
       
   265 
       
   266 	while (numPhones--)
       
   267 		{
       
   268 		TName phoneTsy;
       
   269 		User::LeaveIfError(serverT.GetTsyName(numPhones,phoneTsy));
       
   270 		if (phoneTsy.CompareF(tsy)==KErrNone)
       
   271 			{
       
   272 			RTelServer::TPhoneInfo info;
       
   273 			User::LeaveIfError(serverT.GetPhoneInfo(numPhones,info));
       
   274 			User::LeaveIfError(phone.Open(serverT,info.iName));
       
   275 			CleanupClosePushL(phone);
       
   276 			const TInt err = phone.Initialise();
       
   277 			User::LeaveIfError(err);
       
   278 			CleanupStack::PopAndDestroy(&phone);
       
   279 			break;
       
   280 			}
       
   281 		}
       
   282 
       
   283 	CleanupStack::PopAndDestroy(&serverT);
       
   284 	}
       
   285 
       
   286 
       
   287 
       
   288 /**
       
   289   *  Set high and low limits in .RSC file. When the SMS Stack starts the limits
       
   290   *  will be loaded as if set by the licensee.
       
   291   *
       
   292   *  @param aLowLimit   Low limit value.
       
   293   *  @param aHighLimit  High limit value.
       
   294   *
       
   295   *  @note Only works in debug mode for security reasons.
       
   296   */ 
       
   297 void CWapProtSuiteStepBase::SetLowHighLimitsInSmsuRscL(TInt64 aLowLimit, TInt64 aHighLimit)
       
   298 	{
       
   299 	INFO_PRINTF3(_L("Setting high and low .RSC limits to %ld and %ld."),
       
   300 				 aHighLimit, aLowLimit);
       
   301 
       
   302 	__ASSERT_ALWAYS(aLowLimit  < 0x7fffffff, User::Leave(KErrArgument));
       
   303 	__ASSERT_ALWAYS(aHighLimit < 0x7fffffff, User::Leave(KErrArgument));
       
   304 	__ASSERT_ALWAYS(aLowLimit  < aHighLimit, User::Leave(KErrArgument));
       
   305 
       
   306 	RFs lFs;	
       
   307 	User::LeaveIfError(lFs.Connect());
       
   308 
       
   309 	//
       
   310 	// Data for the SMSU resource file. The low limit is written at position
       
   311 	// 20 and the high limit at position 24.
       
   312 	//
       
   313 	const TInt  smsuRscSize = 34;
       
   314 	TChar  smsuRscData[smsuRscSize] =
       
   315 				{0x6b, 0x4a, 0x1f, 0x10, 0x00, 0x00, 0x00, 0x00,
       
   316    	 			 0x00, 0x00, 0x00, 0x00, 0x19, 0xfd, 0x48, 0xe8,
       
   317 				 0x01, 0x04, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12,
       
   318 				 0x87, 0x65, 0x43, 0x21, 0x14, 0x00, 0x18, 0x00, 
       
   319    		 		 0x1c, 0x00};
       
   320     						  
       
   321 	smsuRscData[20] = (aLowLimit  >>  0) & 0xff;
       
   322 	smsuRscData[21] = (aLowLimit  >>  8) & 0xff;
       
   323 	smsuRscData[22] = (aLowLimit  >> 16) & 0xff;
       
   324 	smsuRscData[23] = (aLowLimit  >> 24) & 0xff;
       
   325 	smsuRscData[24] = (aHighLimit >>  0) & 0xff;
       
   326 	smsuRscData[25] = (aHighLimit >>  8) & 0xff;
       
   327 	smsuRscData[26] = (aHighLimit >> 16) & 0xff;
       
   328 	smsuRscData[27] = (aHighLimit >> 24) & 0xff;
       
   329 
       
   330 	TBuf8<smsuRscSize>  smsuRscBuffer;
       
   331 
       
   332 	for (TInt index = 0;  index < smsuRscSize;  index++)
       
   333 		{
       
   334 		smsuRscBuffer.Append(smsuRscData[index]);
       
   335 		}
       
   336 
       
   337 	//
       
   338 	// Ensure the target directory exists...
       
   339 	//
       
   340 	TInt  ret;
       
   341 	
       
   342 	ret = lFs.MkDir(KSMSUResourceDir);
       
   343 	if (ret != KErrNone  &&  ret != KErrAlreadyExists)
       
   344 		{
       
   345 		User::Leave(ret);
       
   346 		}
       
   347 
       
   348 	//
       
   349 	// Write the RSC file to the private C:\ directory...
       
   350 	//
       
   351 	RFile  file;
       
   352 
       
   353 	User::LeaveIfError(file.Replace(lFs, KSMSUResourceFile, EFileWrite));
       
   354 	CleanupClosePushL(file);
       
   355 	User::LeaveIfError(file.Write(smsuRscSize, smsuRscBuffer));
       
   356 	CleanupStack::PopAndDestroy(&file);
       
   357 	
       
   358 	lFs.Close();
       
   359 	}
       
   360 
       
   361 /**
       
   362  * Sets high and low limits in .RSC file and then reserves disk space to match requested levels.
       
   363  * 
       
   364  * Checks the current free space and then sets the high and low marks
       
   365  * to be aHighDrop MB and aLowDrop MB below the current free space 
       
   366  * level.
       
   367  * 
       
   368  * Then diskspace is reserved to aFreeDrop MB below the current free
       
   369  * space level.
       
   370  * 
       
   371  * If the current free space level is greater then aMax then the 
       
   372  * current free space level is set to aMax
       
   373  * 
       
   374  * If the current free space level is less than aLowDrop MB then this
       
   375  * method leaves with KErrArgument.
       
   376  * 
       
   377  * @param   aHighDrop   The number of MB below the current free space level for the high level mark (in the .RSC file)
       
   378  * @param   aLowDrop    The number of MB below the current free space level for the low level mark (in the .RSC file)  
       
   379  * @param   aFreeDrop   The number of MB below the current free space level to set the free space to ;
       
   380  *                      if aFreeDrop == 0, then SetFreeDiskSpaceL() is not called
       
   381  * @param   aMax        The maximum level for the high limit allowed
       
   382  * 
       
   383  * @return  The max current free space level used.
       
   384  * 
       
   385  * @leave   KErrArgument if the current free diskspace level is less than aLowDrop MB
       
   386  * @leave   KErrArgument if aMax is not greater than aLowDrop MB
       
   387  * @leave   KErrArgument if aHighDrop >= aLowDrop  
       
   388  */
       
   389 TUint64 CWapProtSuiteStepBase::SetHighLowLimitsAndDiskSpaceLevelL(TUint aHighDrop, TUint aLowDrop, TUint aFreeDrop, TUint64 aMax/*=0x7fffffff*/)
       
   390     {
       
   391     INFO_PRINTF5(_L("Setting High-Low limits and Diskspace levels [aHighDrop=%u, aLowDrop=%u, aFreeDrop=%u, aMax=%ld]"), 
       
   392             aHighDrop, aLowDrop, aFreeDrop, aMax);
       
   393     
       
   394     __ASSERT_ALWAYS( (aMax > (aLowDrop*1024*1024)), User::Leave(KErrArgument));
       
   395     __ASSERT_ALWAYS( (aLowDrop > aHighDrop), User::Leave(KErrArgument));
       
   396     
       
   397     ReleaseDiskSpaceL();
       
   398    
       
   399     TVolumeInfo  volumeInfo;
       
   400     RFs fs;
       
   401     User::LeaveIfError(fs.Connect());
       
   402     CleanupClosePushL(fs);
       
   403     User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
       
   404     INFO_PRINTF2(_L("  Drive C currently has %ld bytes free."), volumeInfo.iFree);
       
   405     
       
   406     TUint64 current = volumeInfo.iFree;
       
   407     if( current < (aLowDrop*1024*1024) )
       
   408         {
       
   409         INFO_PRINTF1(_L("  Drive C already has too little free space!"));
       
   410         User::Leave(KErrArgument);
       
   411         }
       
   412     if( current > aMax )
       
   413         {
       
   414         current = aMax;
       
   415         }
       
   416     TUint64 high = current - (aHighDrop*1024*1024);
       
   417     TUint64 low  = current - (aLowDrop*1024*1024);    
       
   418         
       
   419     SetLowHighLimitsInSmsuRscL(low, high);
       
   420     
       
   421     if( aFreeDrop > 0 )
       
   422         {
       
   423         TUint64 free = current - (aFreeDrop*1024*1024);    
       
   424         SetFreeDiskSpaceL(free);
       
   425         }
       
   426     
       
   427     CleanupStack::PopAndDestroy(&fs);   
       
   428     return current;
       
   429     }
       
   430 
       
   431 void CWapProtSuiteStepBase::SetFreeDiskSpaceFromDropLevelL(TUint aFreeDrop)
       
   432     {
       
   433     if( aFreeDrop == 0)
       
   434         {
       
   435         return;
       
   436         }
       
   437     
       
   438     RFs fs;
       
   439     User::LeaveIfError(fs.Connect());
       
   440     CleanupClosePushL(fs);    
       
   441     
       
   442     TVolumeInfo  volumeInfo;
       
   443     User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
       
   444     TUint64 current = volumeInfo.iFree;
       
   445     if( current > 0x7fffffff )
       
   446         {
       
   447         current = 0x7fffffff;
       
   448         }    
       
   449     TUint64 free = current - (aFreeDrop*1024*1024);
       
   450     SetFreeDiskSpaceL(free);
       
   451     CleanupStack::PopAndDestroy(&fs); 
       
   452     }
       
   453 /**
       
   454  *  Reserves disk space so that a specified amount of free disk space is
       
   455  *  available.
       
   456  *
       
   457  *  @param aNewFreeValue  Amount of free space required.
       
   458  */
       
   459 void CWapProtSuiteStepBase::SetFreeDiskSpaceL(TInt64 aNewFreeValue)
       
   460     {
       
   461     
       
   462 #ifndef _DEBUG
       
   463     ERR_PRINTF1(_L("Unexpected call: CWapProtSuiteStepBase::SetFreeDiskSpaceL() is expected to be called only in DEBUG mode."));
       
   464     User::Leave(KErrNotSupported);
       
   465 #else
       
   466 
       
   467     INFO_PRINTF2(_L("Setting Drive C free disk space to %ld bytes."), aNewFreeValue);
       
   468     
       
   469     __ASSERT_DEBUG( (aNewFreeValue <= 0x7fffffff), User::Leave(KErrArgument));
       
   470             
       
   471     TInt err = RProperty::Set(KUidPSSMSStackCategory, KUidPSSMSStackFreeDiskSpaceKey, (TInt)aNewFreeValue);
       
   472     if (err != KErrNone)
       
   473         {
       
   474         ERR_PRINTF2(_L("RProperty::Set() failure [err=%d]"), err);
       
   475         User::Leave(err);
       
   476         }
       
   477 #endif               
       
   478     } // CSMSTestSteps::SetFreeDiskSpaceL
       
   479 	
       
   480 /**
       
   481  *  Release all reserved disk space.
       
   482  */
       
   483 void CWapProtSuiteStepBase::ReleaseDiskSpaceL()
       
   484 	{
       
   485 	
       
   486 #ifndef _DEBUG
       
   487     ERR_PRINTF1(_L("Unexpected call: CWapProtSuiteStepBase::ReleaseDiskSpaceL() is expected to be called only in DEBUG mode."));
       
   488     User::Leave(KErrNotSupported);
       
   489 #else
       
   490 
       
   491     INFO_PRINTF1(_L("CWapProtSuiteStepBase::ReleaseDiskSpaceL()"));
       
   492     
       
   493     RFs fs;
       
   494     User::LeaveIfError(fs.Connect());
       
   495     CleanupClosePushL(fs);
       
   496     
       
   497     TVolumeInfo  volumeInfo;
       
   498     User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
       
   499     TUint64 current = volumeInfo.iFree;
       
   500     if( current > 0x7fffffff )
       
   501         {
       
   502         current = 0x7fffffff;
       
   503         }         
       
   504     
       
   505     SetFreeDiskSpaceL(current);
       
   506     CleanupStack::PopAndDestroy(&fs);
       
   507 #endif       
       
   508 	} // CSMSTestSteps::ReleaseDiskSpaceL
       
   509 
       
   510 
       
   511 /**
   110 /**
   512 	Get WAP Address from INI file
   111 	Get WAP Address from INI file
   513 */
   112 */
   514 void CWapProtSuiteStepBase::ReadWapPortSettingsL(TWapAddr &aWapAddr)
   113 void CWapProtSuiteStepBase::ReadWapPortSettingsL(TWapAddr& aWapAddr, const TDesC& aPort)
   515 	{
   114 	{
   516 	//Local vars	
   115 	//Local vars	
   517 	TPtrC16 telNumber;
   116 	TPtrC16 telNumber;
   518 	TInt port;
   117 	TInt port;
   519 	
   118 	
   520 	//Read Port and SC number from INI file
   119 	//Read Port and SC number from INI file
   521 	if(!GetStringFromConfig(ConfigSection(),KSCNumber,telNumber) ||
   120 	User::LeaveIfError(GetStringFromConfig(ConfigSection(),KSCNumber,telNumber));
   522 	   !GetIntFromConfig(ConfigSection(),KWapPort,port)
   121 	User::LeaveIfError(GetIntFromConfig(ConfigSection(), aPort, port));
   523 		)
       
   524 		{
       
   525 		// Leave if there's any error.
       
   526 		User::Leave(KErrNotFound);
       
   527 		}
       
   528 	  	
       
   529 
   122 
   530 	aWapAddr.SetWapPort(TWapPortNumber(port));
   123 	aWapAddr.SetWapPort(TWapPortNumber(port));
   531 	TBuf8<100> scNumber;
   124 	TBuf8<100> scNumber;
   532 	scNumber.Copy(telNumber);
   125 	scNumber.Copy(telNumber);
   533 	TPtrC8 scAddr(scNumber);
   126 	TPtrC8 scAddr(scNumber);
   534 	aWapAddr.SetWapAddress(scAddr);	  	
   127 	aWapAddr.SetWapAddress(scAddr);	
   535 	}
   128 	}
   536 
   129 
   537 
   130 /**
       
   131 Get the coding of the message
       
   132 */
       
   133 void CWapProtSuiteStepBase::SetCodingSchemeL()
       
   134     {
       
   135     TInt dataCoding;
       
   136     TInt err = KErrNone;
       
   137 
       
   138     //Get the port number from the ini file
       
   139     GetIntFromConfig(ConfigSection(),_L("dataCoding"), dataCoding);
       
   140 
       
   141     if(dataCoding==8)
       
   142         {
       
   143         err = iSocket.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms8BitDCS);
       
   144         }
       
   145     else
       
   146         {
       
   147         err = iSocket.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms7BitDCS);
       
   148         }
       
   149 
       
   150     TESTCHECKL(err, KErrNone, "Setting Data Coding Scheme");
       
   151     }
       
   152 
       
   153 void CWapProtSuiteStepBase::SetMessageTypeL()
       
   154     {
       
   155     TInt err = KErrNone;
       
   156     TPtrC messageType;
       
   157 
       
   158     //Get the type of message
       
   159     GetStringFromConfig(ConfigSection(),_L("type"), messageType);
       
   160 
       
   161     //Set the message type to WapDatagram
       
   162     if(messageType.Compare(_L("Datagram")) == 0)
       
   163         {
       
   164         err = iSocket.SetOpt(KWapSmsOptionWapDatagram,KWapSmsOptionLevel);
       
   165         }
       
   166     //The creation of the message will set the type to SMART by default
       
   167     //  else
       
   168     //      User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionSmartMessage,KWapSmsOptionLevel));   
       
   169     
       
   170     TESTCHECKL(err, KErrNone, "Setting Message Type");
       
   171     }
   538 
   172 
   539 /**
   173 /**
   540 Used to check the CSmsMessage, will also print details of values in CSmsMessage
   174 Used to check the CSmsMessage, will also print details of values in CSmsMessage
   541 */
   175 */
   542 void CWapProtSuiteStepBase::CheckSmsMessageL(CSmsMessage& aSmsmessagebuf, TPtrC8& aScnumber)
   176 void CWapProtSuiteStepBase::CheckSmsMessageL(CSmsMessage& aSmsmessagebuf, TPtrC8& aScnumber)
   581 Used to make call to get message parameters via Ioctl
   215 Used to make call to get message parameters via Ioctl
   582 */
   216 */
   583 void CWapProtSuiteStepBase::GetMessageParameterL(RSocket& aSock, TPtr8& aParameterStorePtr)
   217 void CWapProtSuiteStepBase::GetMessageParameterL(RSocket& aSock, TPtr8& aParameterStorePtr)
   584 	{
   218 	{
   585 	TRequestStatus getParamStatus;
   219 	TRequestStatus getParamStatus;
   586 	
   220 
   587 	// Get the message parameter and assign to TPtr8
   221 	INFO_PRINTF1(_L("Getting message parameter..."));
   588 	INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParameters"));
       
   589 	aSock.Ioctl(KSOGetMessageParameters, getParamStatus, &aParameterStorePtr, KSolWapProv);
   222 	aSock.Ioctl(KSOGetMessageParameters, getParamStatus, &aParameterStorePtr, KSolWapProv);
   590 	User::WaitForRequest(getParamStatus);
   223 	User::WaitForRequest(getParamStatus);
   591 	INFO_PRINTF1(_L("KSOGetMessageParameters on Ioctl completed"));
   224 	TESTCHECK(getParamStatus.Int(), KErrNone, "Getting message parameter");
   592 	TESTL(getParamStatus.Int()==KErrNone);
       
   593 	}
   225 	}
   594 
   226 
   595 /**
   227 /**
   596 Used to internalise the TDes8 and check the resultant CSmsMessage
   228 Used to internalise the TDes8 and check the resultant CSmsMessage
   597 */
   229 */
   605 	RFs rFs;
   237 	RFs rFs;
   606 	User::LeaveIfError(rFs.Connect());
   238 	User::LeaveIfError(rFs.Connect());
   607 	CleanupClosePushL(rFs);
   239 	CleanupClosePushL(rFs);
   608 	
   240 	
   609 	smsMessageBuf = CSmsMessage::NewL(rFs, CSmsPDU::ESmsStatusReport, CSmsBuffer::NewL());
   241 	smsMessageBuf = CSmsMessage::NewL(rFs, CSmsPDU::ESmsStatusReport, CSmsBuffer::NewL());
       
   242 	CleanupStack::PushL(smsMessageBuf);
   610 	smsMessageBuf->InternalizeWithoutBufferL(reader);
   243 	smsMessageBuf->InternalizeWithoutBufferL(reader);
   611 	
   244 	
   612 	INFO_PRINTF1(_L("Check the contents of the internalized sms message"));
   245 	INFO_PRINTF1(_L("Check the contents of the internalized sms message"));
   613 	CheckSmsMessageL(*smsMessageBuf, aScnumber);
   246 	CheckSmsMessageL(*smsMessageBuf, aScnumber);
   614 	
   247 	
   615 	rFs.Close();
   248 	CleanupStack::PopAndDestroy(3, &reader); // reader, rFs, smsMessageBuf
   616 	delete smsMessageBuf;
       
   617 	CleanupStack::PopAndDestroy(); // rFs.Close()
       
   618 	CleanupStack::PopAndDestroy(&reader);
       
   619 	}
   249 	}
   620 
   250 
   621 void CWapProtSuiteStepBase::OpenSocketL(RSocketServ& aSocketServer, RSocket& aSocket, TUint aAddrFamily,TUint aProtocol)
   251 void CWapProtSuiteStepBase::OpenSocketL(RSocketServ& aSocketServer, RSocket& aSocket, TUint aAddrFamily,TUint aProtocol)
   622     {
   252     {
   623     OpenSocketLC(aSocketServer, aSocket, aAddrFamily, aProtocol);   
   253     OpenSocketLC(aSocketServer, aSocket, aAddrFamily, aProtocol);   
   630     if(error != KErrNone)
   260     if(error != KErrNone)
   631          {
   261          {
   632          //If error == KErrNone, do nothing.
   262          //If error == KErrNone, do nothing.
   633          //If error == KErrServerBusy, change the leave code to "84" to imply the failure otherwise the failed step will be started again.
   263          //If error == KErrServerBusy, change the leave code to "84" to imply the failure otherwise the failed step will be started again.
   634          //Any other errors will leave with the error code.
   264          //Any other errors will leave with the error code.
   635 
       
   636          
       
   637          if(error == KErrServerBusy)
   265          if(error == KErrServerBusy)
   638              {
   266              {
   639              error = TEST_ERROR_CODE;
   267              error = TEST_ERROR_CODE;
   640              ERR_PRINTF2(_L("Open socket failed - error is KErrServerBusy, changing to TEST_ERROR_CODE (=%d)"), error);            
   268              ERR_PRINTF2(_L("Open socket failed - error is KErrServerBusy, changing to TEST_ERROR_CODE (=%d)"), error);            
   641              }
   269              }
   643              {
   271              {
   644              ERR_PRINTF2(_L("Open socket failed - error=%d"), error);
   272              ERR_PRINTF2(_L("Open socket failed - error=%d"), error);
   645              }
   273              }
   646           User::Leave(error);
   274           User::Leave(error);
   647           }   
   275           }   
   648   
       
   649     CleanupClosePushL(aSocket);
   276     CleanupClosePushL(aSocket);
   650     }
   277     }
   651 
   278 
       
   279 void CWapProtSuiteStepBase::ReceiveWapMessageFromSocket(TInt aLength, TPtrC& aData)
       
   280     {
       
   281     //  Receiving a message, length of which should be requested prior to calling
       
   282     // this method from the socket and supplied thought aLength parameter
       
   283     
       
   284     TRequestStatus  status;
       
   285     TWapAddr recvWapAddr;           
       
   286     HBufC8* recvBuf = HBufC8::NewLC(aLength);
       
   287     TPtr8 recvPtr = recvBuf->Des(); 
       
   288 
       
   289     INFO_PRINTF1(_L("Receiving a message from the socket..."));
       
   290     iSocket.RecvFrom(recvPtr, recvWapAddr, 0, status);
       
   291     User::WaitForRequest(status);
       
   292     TESTCHECKL(status.Int(), KErrNone, "Receiving a message");
       
   293     
       
   294     TBuf8<300> data;
       
   295     data.Copy(aData);
       
   296     TESTCHECK(recvPtr.Compare(data), 0, "Checking the received message matched expected");
       
   297     
       
   298     //  Confirm the receipt of the message to the client
       
   299     INFO_PRINTF1(_L("Setting Socket option for indicating receipt of the message..."));
       
   300     TInt ret = iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0);
       
   301     TESTCHECKL(ret, KErrNone, "Setting Socket option for indicating receipt of the message");
       
   302     CleanupStack::PopAndDestroy(recvBuf);
       
   303     }
       
   304 
       
   305 void CWapProtSuiteStepBase::ReceiveWapMessage(TPtrC& aData)
       
   306     {
       
   307     TRequestStatus ioctlStatus;
       
   308     TPckgBuf<TInt> length;
       
   309     
       
   310     INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
       
   311     iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
       
   312     User::WaitForRequest(ioctlStatus);
       
   313     TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the length of the incoming message");
       
   314     
       
   315     //  Check if reported length is correct
       
   316     TESTCHECK(length(), aData.Length(), "Check if reported length is correct");
       
   317     
       
   318     ReceiveWapMessageFromSocket(length(), aData);
       
   319     }
       
   320 
       
   321 void CWapProtSuiteStepBase::SendWapMessage(TPtrC& aData)
       
   322     {
       
   323     TRequestStatus status;
       
   324     TBuf8<300> data;
       
   325     data.Copy(aData);
       
   326 
       
   327     INFO_PRINTF1(_L("Sending a message..."));
       
   328     iSocket.SendTo(data, iWapAddr, 0, status);
       
   329     User::WaitForRequest(status);
       
   330     TESTCHECKL(status.Int(), KErrNone, "Sending a message");
       
   331     }