smsprotocols/smsstack/wapprot/test/Te_wapprot/WapIoctlSteps.cpp
changeset 20 244d7c5f118e
parent 0 3553901f7fa8
child 24 6638e7f4bd8f
child 69 b982c3e940f3
--- a/smsprotocols/smsstack/wapprot/test/Te_wapprot/WapIoctlSteps.cpp	Fri Mar 19 09:55:57 2010 +0200
+++ b/smsprotocols/smsstack/wapprot/test/Te_wapprot/WapIoctlSteps.cpp	Fri Apr 16 16:12:37 2010 +0300
@@ -16,1000 +16,318 @@
 //
 
 /**
- @file
+	@file
+	@test
 */
 
-
 #include "WapIoctlSteps.h"
-#include "WapProtSuiteDefs.h"
-#include <etel.h>
-#include <es_wsms.h>
+
 #include <simtsy.h>
-#include <sacls.h>
-#include <s32mem.h>
 #include <smspver.h>
+#include <wap_sock.h>
 
+#include "smsstacktestconsts.h"
+#include "WapProtSuiteDefs.h"
 
 TVerdict CIoctlStep_1::doTestStepL()
 /**
  *  Test step one:
  *  Sends/receives a 7Bit business card using IOCTL
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 1: send/receive 7-Bit business card"));
-
-	TPtrC TestData1;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber=1;
-	
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData1) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM tsy)
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
+    // Configure and bind to a socket
+	SetupWapSocketL();
 
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
- 	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
+	//	Send a business card
+	TPtrC testData = GetStringFromConfigL(KTestData1);
 
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
-
-	//
-	//	Send a business card
-	//
-	TRequestStatus  status;
-	
-	TBuf8<200> data;
-	data.Copy(TestData1);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Message sent..."));
-
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+	SendWapMessage(testData);
 
-	//
-	//	Get the size of the first incomming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed"));
-
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<256> recvBuf(length);
-	
-	TEST(length()==data.Length());
+    //  Receive the business card
+	ReceiveWapMessage(testData);
 	
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the message..."));
-	
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-	TEST(recvBuf.Compare(data) == 0);
-	
-	//
-	//	Closing the socket
-	//
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
+	iSocket.Close();
 	return TestStepResult();
 	}
 
-
 TVerdict CIoctlStep_2::doTestStepL()
 /** 
  *	Test step two: 
  *	Sends/receives a 7-Bit calendar entry and VCard using IOCTL(two segments each)
  *	@return - TVerdict code
- * 
  */
 	{
-
 	INFO_PRINTF1(_L("IOCTL Test step 2: send/receive a VCal and VCard"));
-
-	TPtrC TestData1;
-	TPtrC TestData2;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber = 2;
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData1) ||
-	   !GetStringFromConfig(ConfigSection(),KTestData2, TestData2) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port)
-		)
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-		
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used 
-	//  for test (not required for SIM Tsy)
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
+    // Configure and bind to a socket
+    SetupWapSocketL();
 	
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
- 	
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-	
+	//	Issue Ioctl for getting the length of the message
 	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
 	TPckgBuf<TInt> length;
-	
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
-	
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of the IOCTL for GetLength for first VCal entry"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+
+	INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the first message (VCal)..."));
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 
-	
-	TBuf8<300> data;
-	
-	//
-	//	Send a calendar entry  
-	//	
-	TRequestStatus  status;
+    TPtrC testData1 = GetStringFromConfigL(KTestData1);
+    TPtrC testData2 = GetStringFromConfigL(KTestData2);
+    
+    //  Send a VCal entry
+    SendWapMessage(testData1);
 
-	data.Copy(TestData1);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("First Message (VCal) sent..."));
+	//	Send a VCard entry with extended GSM alphabets
+    SendWapMessage(testData2);
 
-	//	Send a VCard entry 	
-	data.Copy(TestData2);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Second message (VCard with extended GSM alphabets) sent..."));
-	
-	//
-	//	Get the size of the first incomming message
-	//
+    //	Get the size of the first incoming message
 	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed"));
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<300> recvBuf;
-	TEST(length()==TestData1.Length());
-	
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the first message (VCal)..."));
-	
-	//	Compare the received VCal message with the original one.
-	//	They should be identical
-	data.Copy(TestData1);	
-	if (recvBuf.Compare(data) != 0)
-		{
-		ERR_PRINTF1(_L("VCal message received does not match with original message."));
-		TEST(recvBuf.Compare(data) == 0);
-		}		
+	TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+	TESTCHECK(length(), testData1.Length(), "Check if reported length is correct");
 	
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of first message (VCal)"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-	
-	
-	//Issue Ioctl for getting the length of the second message	
-	INFO_PRINTF1(_L("Issue of the IOCTL for GetLength for second VCard entry"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-	
-	//Get the size of the second incomming message
-	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed for second message (VCard)"));
-	
-	//Check if reported length is correct	
-	TEST(length()==TestData2.Length());
-	
-	//Receiving a datagram (VCard)
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the second message (VCard)..."));
-	
-	//	Compare the received VCard message with the original one
-	//	They should be identical
-	data.Copy(TestData2);	
-	if (recvBuf.Compare(data) != 0)
-		{
-		ERR_PRINTF1(_L("VCard message received does not match with original message."));
-		TEST(recvBuf.Compare(data) == 0);
-		}
-		
-	//Confirm the receipt of the message to the client	
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-    CleanupStack::PopAndDestroy(&sock);
-	CleanupStack::Pop(&socketServer);
+    // Receive the VCal message
+    ReceiveWapMessageFromSocket(length(), testData1);
 
-	return TestStepResult();
+    // Receive the VCard message
+    ReceiveWapMessage(testData2);
+    
+	iSocket.Close();
+    return TestStepResult();
 	}
 
-
 TVerdict CIoctlStep_3::doTestStepL()
 /**
  *  Test step 3:
  *  send/receive one 7-Bit two segments message and one 7-Bit one segment message
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 3: send/receive two 7-Bit messages"));
-
-	TPtrC TestData1;
-	TPtrC TestData2;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber = 3;
-
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData1) ||
-	   !GetStringFromConfig(ConfigSection(),KTestData2, TestData2) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-	OpenSocketLC(socketServer, sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
+	//	Issue Ioctl for getting the length of the message
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+    
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the first message..."));
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
-
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
-	//	Send a calendar entry
-	//
-	TRequestStatus  status;
+    TPtrC testData1 = GetStringFromConfigL(KTestData1);
+    TPtrC testData2 = GetStringFromConfigL(KTestData2);
+    
+    //  Send a business card
+    SendWapMessage(testData2);
 
-	TBuf8<300> data2;
-	data2.Copy(TestData2);
-	sock.SendTo(data2, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("First message sent..."));
-
-	//
-	//	Send a business card
-	//
-	TBuf8<200> data1;
-	data1.Copy(TestData1);
-	sock.SendTo(data1, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Second message sent..."));
-	//
-	//	Get the size of the first incomming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed..."));
-	TBuf8<256> recvBuf2(length);
-
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf2,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the first message..."));
-	TEST(recvBuf2.Compare(data2) == 0);
+    //  Send a business card
+    SendWapMessage(testData1);
 
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-	//
-	//	Issue Ioctl for getting the length of the second message
-	//
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-	INFO_PRINTF1(_L("Issue of the 2nd IOCTL for GetLength"));
-
-	//
-	//	Get the size of the SECOND incomming message
-	//
+	//	Get the size of the first incoming message
 	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed"));
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<256> recvBuf1(length);
-	TEST(length()==data1.Length());
+	TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+	TESTCHECK(length(), testData2.Length(), "Check if reported length is correct");
+	    
+	//	Receive the first message
+    ReceiveWapMessageFromSocket(length(), testData2);
 
-	//
-	//	Receiving the second message
-	//
-	sock.RecvFrom(recvBuf1,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Receievd the second datagram"));
-	TEST(recvBuf1.Compare(data1) == 0);
-
-	//
-	//	Confirm the receipt of the second message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of the second message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
+	//	Receive the second message
+    ReceiveWapMessage(testData1);
+    
+    iSocket.Close();
 	return TestStepResult();
 	}
 
-
 TVerdict CIoctlStep_4::doTestStepL()
 /**
- *  
  *  Test step 4:
  *  simulating client crash conditions with 7bit message
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 4: client crash condition 7-Bit message "));
-
-	TPtrC TestData;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber =4;
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
+	//	Issue Ioctl for getting the length of the message
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+    
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the first message..."));
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
+	//	Send a business card
+    TPtrC testData = GetStringFromConfigL(KTestData1);
+    SendWapMessage(testData);
 
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
-  
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
+    //  Get the size of the first incoming message
+	User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+    TESTCHECK(length(), testData.Length(), "Check if reported length is correct");
+	
+	//	Receive a message
+    TRequestStatus recvStatus;
+    TWapAddr recvWapAddr;
+    HBufC8* recvBuf = HBufC8::NewLC(length());
+    TPtr8 recvPtr = recvBuf->Des(); 
+    
+	iSocket.RecvFrom(recvPtr, recvWapAddr, 0, recvStatus);
+	User::WaitForRequest(recvStatus);
+    TESTCHECKL(recvStatus.Int(), KErrNone, "Receiving a message");
+	
+	// Simulate a crash by closing and reopening the socket
+	iSocket.Close();
+	INFO_PRINTF1(_L("Socket was closed..."));
+	
+	OpenSocketL(iSocketServer, iSocket);
+	User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
 	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
+	User::LeaveIfError(iSocket.Bind(iWapAddr));
+	INFO_PRINTF1(_L("Socket was opened..."));
+	
+	// Issue another get length of datagram as if not aware of the previous message
+	// and retrieve the message from the SAR store
+    ReceiveWapMessage(testData);
+	
+	iSocket.Close();
+    CleanupStack::PopAndDestroy(recvBuf);
+    return TestStepResult();
+	}
 
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
-	//	Send a business card
-	//
-	TRequestStatus  status;
+TVerdict CIoctlStep_5::doTestStepL()
+/**
+ *  Test step 5:
+ *  simulating client crash conditions with 8bit push message
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 5: client crash condition with 8Bit push message"));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+ 
+    //  Issue Ioctl for getting the length of the message
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+    
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the first message..."));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 
-	TBuf8<200> data;
-	data.Copy(TestData);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Message sent..."));
-	//
-	//	Get the size of the incomming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed..."));
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<256> recvBuf(length);
-	TEST(length()==data.Length());
+    //  Get the size of the incoming message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
 
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the message..."));
-	//
-	//	Close socket
-	//
-	sock.Close();
-	INFO_PRINTF1(_L("Socket was closed..."));
-	//
-	//	Open the socket
-	//
-	OpenSocketL(socketServer, sock);
- 	INFO_PRINTF1(_L("Socket was opened..."));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.Bind(wapAddr));
-	//
+    //  Receive a message
+    TRequestStatus recvStatus;
+    TWapAddr recvWapAddr;
+    HBufC8* recvBuf = HBufC8::NewLC(length());
+    TPtr8 recvPtr = recvBuf->Des(); 
+    
+    iSocket.RecvFrom(recvPtr, recvWapAddr, 0, recvStatus);
+    User::WaitForRequest(recvStatus);
+    TESTCHECKL(recvStatus.Int(), KErrNone, "Receiving a message");
+	
+    // Simulate a crash by closing and reopening the socket
+    iSocket.Close();
+    INFO_PRINTF1(_L("Socket was closed..."));
+    
+    OpenSocketL(iSocketServer, iSocket);
+    User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
+    INFO_PRINTF1(_L("Socket set option for indicating new client"));
+    User::LeaveIfError(iSocket.Bind(iWapAddr));
+    INFO_PRINTF1(_L("Socket was opened..."));
+	
 	//	Issue another get length of datagram as if not aware of the previous message
-	//
 	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-	//
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+	
 	//	waiting for request to be completed
-	//
 	User::WaitForRequest(ioctlStatus);
 	User::LeaveIfError(ioctlStatus.Int());
 	INFO_PRINTF1(_L("IOCTL completed..."));
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<256> newRecvBuf(length);
-	TEST(length()==data.Length());
-
-	//
+	
 	//	New message retrieved from SAR store
-	//
-	sock.RecvFrom(newRecvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the message..."));
-	TEST(newRecvBuf.Compare(data) == 0);
-
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
-	return TestStepResult();
-	}
-
-
-TVerdict CIoctlStep_5::doTestStepL()
-/**
- *  
- *  Test step 5:
- *  simulating client crash conditions with 8bit push message
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 5: client crash condition with 8Bit push message"));
-
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber= 5;
-
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
- 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
-	//	Get the size of the incomming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed..."));
-
-	TBuf8<256> recvBuf(length);
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the message..."));
-	//
-	//	Close socket
-	//
-	sock.Close();
-	INFO_PRINTF1(_L("Socket was closed..."));
-	//
-	//	Open the socket
-	//
-	OpenSocketL(socketServer, sock);
- 	INFO_PRINTF1(_L("Socket was opened..."));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.Bind(wapAddr));
-	//
-	//	Issue another get length of datagram as if not aware of the previous message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-	//
-	//	waiting for request to be completed
-	//
-	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed..."));
-	//
-	//	Allocate buffer
-	//
-	TBuf8<256> newRecvBuf(length);
-
-	//
-	//	New message retrieved from SAR store
-	//
-	sock.RecvFrom(newRecvBuf,recvWapAddr,0,recvStatus);
+    HBufC8* recvBuf2 = HBufC8::NewLC(length());
+    TPtr8 recvPtr2 = recvBuf2->Des(); 
+	   
+	iSocket.RecvFrom(recvPtr2,recvWapAddr,0,recvStatus);
 	User::WaitForRequest(recvStatus);
 	User::LeaveIfError(recvStatus.Int());
 	INFO_PRINTF1(_L("Received the message..."));
 
-	//
 	//	Confirm the receipt of the message to the client
-	//
 	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
+	User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
 
-	//
 	//	Compare the received message with the previous one
 	//	They should be identical
-	//
-	TEST(newRecvBuf.Compare(recvBuf) == 0);
+	TEST(recvPtr2.Compare(recvPtr) == 0);
 
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
+	iSocket.Close();
+    CleanupStack::PopAndDestroy(2, recvBuf); // recvBuf, recvBuf2
 	return TestStepResult();
 	}
 
-
 TVerdict CIoctlStep_6::doTestStepL()
 /**
  *  Test step 6:
  *  Sends/receives a business card (Old client testing)
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 6: send/receive a VCard (Old client testing)"));
-
-	TPtrC TestData1;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber = 6;
-
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData1) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
+	// Configure and bind to a socket, do not set the "new style client" option 
+	SetupWapSocketL(iSocket, iWapAddr, KWapPort, EFalse);
 
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
+	//	Send a calendar entry
+    TPtrC testData = GetStringFromConfigL(KTestData1);
+    SendWapMessage(testData);
 
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
- 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
+	//	Receiving a datagram
 	TRequestStatus recvStatus;
-
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
-
-	//
-	//	Send a calendar entry
-	//
-	TRequestStatus  status;
-
-	TBuf8<200> data;
-	data.Copy(TestData1);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Message sent..."));
-
-	//
-	//	Receiving a datagram
-	//
+	TWapAddr recvWapAddr;
 	TBuf8<256> recvBuf;
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
+	
+    INFO_PRINTF1(_L("Receiving a message from the socket..."));
+	iSocket.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
 	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the message..."));
-
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
+    TESTCHECKL(recvStatus.Int(), KErrNone, "Receiving a message");
+	
+	iSocket.Close();
 	return TestStepResult();
 	}
 
-
 TVerdict CIoctlStep_7::doTestStepL()
 /**
  *  Test step 7:
  *  Receives a Push Message (8-Bit)
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 7: Receive push message(8-Bit)"));
-
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber = 7;
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-	OpenSocketLC(socketServer, sock);
- 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
 	//
 	//	Issue Ioctl for getting the length of the message
-	//
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+
 	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+	
 	//
 	//	Get the size of the incomming push message
 	//
 	User::WaitForRequest(ioctlStatus);
 	User::LeaveIfError(ioctlStatus.Int());
 	INFO_PRINTF1(_L("IOCTL completed..."));
-	//
-	//	Allocate buffer
-	//
-	TBuf8<256> recvBuf2(length);
 
 	//
 	//	Receiving push datagram
 	//
-	sock.RecvFrom(recvBuf2,recvWapAddr,0,recvStatus);
+	TRequestStatus recvStatus;
+	TWapAddr recvWapAddr;
+    TBuf8<256> recvBuf2(length);
+    
+    iSocket.RecvFrom(recvBuf2,recvWapAddr,0,recvStatus);
 	User::WaitForRequest(recvStatus);
 	User::LeaveIfError(recvStatus.Int());
 	INFO_PRINTF1(_L("Received the push message..."));
@@ -1018,109 +336,46 @@
 	//	Confirm the receipt of the message to the client
 	//
 	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
+	User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
 
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
+	iSocket.Close();
 	return TestStepResult();
 	}
 
-
 TVerdict CIoctlStep_8::doTestStepL()
 /**
  *  Test step 8:
  *  Receives two Push Messages (8-Bit) Tests store of 8-Bit messages
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 8: Receive two push message(8-Bit)"));
-
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber=8;
-
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
 	//
 	//	Issue Ioctl for getting the length of the message
 	//
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+    
 	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 	//
 	//	Get the size of the incomming push message
 	//
 	User::WaitForRequest(ioctlStatus);
 	User::LeaveIfError(ioctlStatus.Int());
 	INFO_PRINTF1(_L("IOCTL completed..."));
-	//
-	//	Allocate buffer
-	//
-	TBuf8<256> recvBuf1(length);
 
 	//
 	//	Receiving push datagram
 	//
-	sock.RecvFrom(recvBuf1,recvWapAddr,0,recvStatus);
+    TRequestStatus recvStatus;
+	TWapAddr recvWapAddr;
+	TBuf8<256> recvBuf1(length);
+
+	iSocket.RecvFrom(recvBuf1,recvWapAddr,0,recvStatus);
 	User::WaitForRequest(recvStatus);
 	User::LeaveIfError(recvStatus.Int());
 	INFO_PRINTF1(_L("Received the push message..."));
@@ -1129,13 +384,13 @@
 	//	Confirm the receipt of the message to the client
 	//
 	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
+	User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
 
 	//
 	//	Issue another Ioctl for getting the length of the message
 	//
 	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 	//
 	//	Get the size of the second incomming push message
 	//
@@ -1150,7 +405,7 @@
 	//
 	//	Receiving push datagram
 	//
-	sock.RecvFrom(recvBuf2,recvWapAddr,0,recvStatus);
+	iSocket.RecvFrom(recvBuf2,recvWapAddr,0,recvStatus);
 	User::WaitForRequest(recvStatus);
 	User::LeaveIfError(recvStatus.Int());
 	INFO_PRINTF1(_L("Received the second push message..."));
@@ -1164,788 +419,224 @@
 	//	Confirm the receipt of the message to the client
 	//
 	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
+	User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
 
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
+	iSocket.Close();
 	return TestStepResult();
 	}
 
-
 TVerdict CIoctlStep_9::doTestStepL()
 /**
  *  Test step 9:
  *  Receive a 8-Bit push message (Old client testing)
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 9: receive a push message (Testing old client)"));
-
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber = 9;
-
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
- 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus recvStatus;
-
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
+	// Configure and bind to a socket, do not set the "new style client" option 
+    SetupWapSocketL(iSocket, iWapAddr, KWapPort, EFalse);
 
 	//
 	//	Receiving a datagram
 	//
+	TRequestStatus recvStatus;
+	TWapAddr recvWapAddr;
 	TBuf8<256> recvBuf;
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
+	
+	iSocket.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
 	User::WaitForRequest(recvStatus);
 	User::LeaveIfError(recvStatus.Int());
 	INFO_PRINTF1(_L("Received the message..."));
 
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
+	iSocket.Close();
 	return TestStepResult();
 	}
 
-
 TVerdict CIoctlStep_10::doTestStepL()
 /**
  *  Test step Ten:
  *  Sends/receives a 7Bit business card using IOCTL
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 10: send/receive 7-Bit business card using IOCTL"));
-
-	TPtrC TestData1;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber=10;
-
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData1) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM tsy)
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
- 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
+    // Configure and bind to a socket
+    SetupWapSocketL();
+  
+	//	Send a calendar entry
+    TPtrC testData = GetStringFromConfigL(KTestData1);
+    SendWapMessage(testData);
 
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
-
-	//
-	//	Send a calendar entry
-	//
-	TRequestStatus  status;
-
-	TBuf8<200> data;
-	data.Copy(TestData1);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Message sent..."));
-
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+	ReceiveWapMessage(testData);
 
-	//
-	//	Get the size of the first incomming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed"));
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<256> recvBuf(length);
-	TEST(length()==data.Length());
-
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the message..."));
-	TEST(recvBuf.Compare(data) == 0);
-
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-    CleanupStack::PopAndDestroy(&sock);
-	CleanupStack::Pop(&socketServer);
-
+	iSocket.Close();
 	return TestStepResult();
 	}
 
-
-
 TVerdict CIoctlStep_11::doTestStepL()
 /**
  *  Test step 11:
  *  Test Cancel IOCTL
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 11: Testing CancelIOCTL"));
-
-	TPtrC16 TelNumber;
-	TInt port=226;
-
-
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM tsy)
-	//
-	TWapAddr wapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
+	//	Issue Ioctl for getting the length of the message
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
 
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
- 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
+	INFO_PRINTF1(_L("Issue of IOCTL for GetLength"));
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
 	//	Issue Cancel Ioctl
-	//
 	INFO_PRINTF1(_L("Issue of cancel IOCTL for GetLength"));
-	sock.CancelIoctl();
+	iSocket.CancelIoctl();
+	TESTCHECK(ioctlStatus.Int(), KErrCancel, "Check if the outstanding IOCTL has been canceled");
 
-	//
-	//	Check if the outstanding IOCTL has been canceled
-	//
-	TEST(ioctlStatus==KErrCancel);
-
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
+	iSocket.Close();
 	return TestStepResult();
 	}
 
-
 TVerdict CIoctlStep_12::doTestStepL()
 /**
  *  Test step 12:
  *  Test issue IOCTL without SetOption NewStyleClient
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 12: Test issue IOCTL without SetOption NewStyleClient"));
-
-	TPtrC16 TelNumber;
-	TInt port=226;
-
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM tsy)
-	//
-	TWapAddr wapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
+    // Configure and bind to a socket, do not set the "new style client" option 
+    SetupWapSocketL(iSocket, iWapAddr, KWapPort, EFalse);
+    
+	//	Issue Ioctl for getting the length of the message (should fail)
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
 
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-
-	TPckgBuf<TInt> length;
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+    TESTCHECKCONDITION(ioctlStatus.Int()!=KErrNone, "Getting the length of the incoming message");
 
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
-
-	//
-	//	Issue Ioctl for getting the length of the message (should fail)
-	//
-	INFO_PRINTF1(_L("Issue of IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-	User::WaitForRequest(ioctlStatus);
-	TEST(ioctlStatus!=KErrNone);
-
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
+	iSocket.Close();
 	return TestStepResult();
 	}
 
-
-
 TVerdict CIoctlStep_13::doTestStepL()
 /**
  *  Test step two:
  *  Sends/receives a 8-Bit calendar entry using IOCTL(two segments)
  *  @return - TVerdict code
- *  
  */
 	{
-
 	INFO_PRINTF1(_L("IOCTL Test step 13: send/receive a 8-Bit VCal"));
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
-	TPtrC TestData;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber = 13;
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
+    User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms8BitDCS));
 
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM Tsy)
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
+	//	Issue Ioctl for getting the length of the message
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+    
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
+	//	Send a calendar entry
+    TPtrC testData = GetStringFromConfigL(KTestData1);
+    SendWapMessage(testData);
+    
+    //  Get the size of the incoming message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the incoming message");
+    TESTCHECK(length(), testData.Length(), "Check if reported length is correct");
+    
+    ReceiveWapMessageFromSocket(length(), testData);
+    
+	iSocket.Close();
+	return TestStepResult();
+	}
 
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
- 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms8BitDCS));
-
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
+TVerdict CIoctlStep_14::doTestStepL()
+/**
+ *  Test step 14:
+ *  simulating client crash conditions with 8bit calendar entry
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 14: client crash condition 8-Bit calendar entry "));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+    
+    User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms8BitDCS));
 
 	//
 	//	Issue Ioctl for getting the length of the message
 	//
-	INFO_PRINTF1(_L("Issue of the IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
-	//	Send a calendar entry
-	//
-	TRequestStatus  status;
-
-	TBuf8<300> data;
-	data.Copy(TestData);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Message sent..."));
-
-	//
-	//	Get the size of the incomming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed"));
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<300> recvBuf(length);
-	TEST(length()==data.Length());
-
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the message..."));
-	TEST(recvBuf.Compare(data) == 0);
-
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-    CleanupStack::PopAndDestroy(&sock);
-	CleanupStack::Pop(&socketServer);
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+    
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 
-	return TestStepResult();
-	}
-
-
-TVerdict CIoctlStep_14::doTestStepL()
-/**
- *  
- *  Test step 14:
- *  simulating client crash conditions with 8bit calendar entry
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 14: client crash condition 8-Bit calendar entry "));
-
-	TPtrC TestData;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber =14;
-
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
+	//	Send a Calendar entry
+    TPtrC testData = GetStringFromConfigL(KTestData1);
+    SendWapMessage(testData);
 
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
- 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms8BitDCS));
-
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
-
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
-	//	Send a Calendar entry
-	//
-	TRequestStatus  status;
-
-	TBuf8<300> data;
-	data.Copy(TestData);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Message sent..."));
-	//
-	//	Get the size of the incomming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed..."));
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<300> recvBuf(length);
-	TEST(length()==data.Length());
-
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the message..."));
-	//
-	//	Close socket
-	//
-	sock.Close();
-	INFO_PRINTF1(_L("Socket was closed..."));
-	//
-	//	Open the socket
-	//
-	OpenSocketL(socketServer, sock);
-	INFO_PRINTF1(_L("Socket was opened..."));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.Bind(wapAddr));
-	//
-	//	Issue another get length of datagram as if not aware of the previous message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-	//
-	//	waiting for request to be completed
-	//
-	User::WaitForRequest(ioctlStatus);
-	User::LeaveIfError(ioctlStatus.Int());
-	INFO_PRINTF1(_L("IOCTL completed..."));
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<300> newRecvBuf(length);
-	TEST(length()==data.Length());
-
-	//
-	//	New message retrieved from SAR store
-	//
-	sock.RecvFrom(newRecvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	User::LeaveIfError(recvStatus.Int());
-	INFO_PRINTF1(_L("Received the message..."));
-	TEST(newRecvBuf.Compare(data) == 0);
-
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
-	return TestStepResult();
+    //  Get the size of the incoming message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the incoming message");
+    TESTCHECK(length(), testData.Length(), "Check if reported length is correct");
+    
+    //  Receive a message
+    TRequestStatus recvStatus;
+    TWapAddr recvWapAddr;
+    HBufC8* recvBuf = HBufC8::NewLC(length());
+    TPtr8 recvPtr = recvBuf->Des(); 
+    
+    iSocket.RecvFrom(recvPtr, recvWapAddr, 0, recvStatus);
+    User::WaitForRequest(recvStatus);
+    TESTCHECKL(recvStatus.Int(), KErrNone, "Receiving a message");
+    
+    // Simulate a crash by closing and reopening the socket
+    iSocket.Close();
+    INFO_PRINTF1(_L("Socket was closed..."));
+    
+    OpenSocketL(iSocketServer, iSocket);
+    User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
+    INFO_PRINTF1(_L("Socket set option for indicating new client"));
+    User::LeaveIfError(iSocket.Bind(iWapAddr));
+    INFO_PRINTF1(_L("Socket was opened..."));
+    
+    // Issue another get length of datagram as if not aware of the previous message
+    // and retrieve the message from the SAR store
+    ReceiveWapMessage(testData);
+    
+    iSocket.Close();
+    CleanupStack::PopAndDestroy(recvBuf);
+    return TestStepResult();
 	}
 
-
 TVerdict CIoctlStep_15::doTestStepL()
 /**
  *  Test step fifteen:
  *  Receives a 7Bit v-card using IOCTL with concatenation for new style client
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 15: send/receive 7-Bit v-card"));
-
-	TPtrC16 TelNumber;
-	TInt port=9204;
-	TInt testNumber=15;
-
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM tsy)
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    OpenSocketLC(socketServer, sock);
- 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-	//
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
-
-	//
+    // Configure and bind to a socket
+    SetupWapSocketL();
+    
+    //
 	//	Issue Ioctl for getting the length of the message
 	//
-	INFO_PRINTF1(_L("Issue of IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+
+    INFO_PRINTF1(_L("Issue of IOCTL for GetLength"));
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 
 	//
 	//	Get the size of the first incoming message
@@ -1954,12 +645,14 @@
 	User::LeaveIfError(ioctlStatus.Int());
 	INFO_PRINTF1(_L("IOCTL completed"));
 
-	TBuf8<360> recvBuf(length);
-
 	//
 	//	Receiving a datagram that is 7bit with a concatenated length of > 160 characters
 	//
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
+    TRequestStatus recvStatus;
+    TWapAddr recvWapAddr;
+    TBuf8<360> recvBuf(length);
+
+    iSocket.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
 	User::WaitForRequest(recvStatus);
 	User::LeaveIfError(recvStatus.Int());
 	INFO_PRINTF1(_L("Received the message..."));
@@ -1968,40 +661,30 @@
 	//	Confirm the receipt of the message to the client
 	//
 	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
+	User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
 
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-	socketServer.Close();
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::Pop(&socketServer);
-
+	iSocket.Close();
 	return TestStepResult();
 	}
 
-
 TInt CBackupRestoreStep::SendWapL()
 	{
 	//modified from test 10
 	INFO_PRINTF1(_L("SendWapL: send 7-Bit business card using IOCTL"));
 
 	TInt ret = KErrNone;
-	TPtrC TestData1;
+
 	TPtrC16 TelNumber;
 	TInt port=226;
 
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData1) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
+	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
 	   !GetIntFromConfig(ConfigSection(),KWapPort,port)
 		)
 		{
 		// Leave if there's any error.
 		User::Leave(KErrNotFound);
 		}
-
-
+	
 	//
 	//	Setting the port number and service center number of the wap address
 	//	The service center number should be the same as the sim phone number used
@@ -2015,8 +698,6 @@
 	TPtrC8 scAddr(scNumber);
 	wapAddr.SetWapAddress(scAddr);
 
-
-
 	//
 	//	Define and open the socket
 	//
@@ -2034,11 +715,6 @@
 		}
 	CleanupClosePushL(sock);
 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
 	TRequestStatus status;
 
 	//
@@ -2050,12 +726,16 @@
 	//	Bind
 	//
 	User::LeaveIfError(sock.Bind(wapAddr));
+	
+    TTimeIntervalMicroSeconds32 InitPause=9000000;  //Pause to Allow SMSStack to Complete its Async Init
+    User::After(InitPause);                         //call to the TSY and finish its StartUp.
 
 	//
 	//	Send a calendar entry
 	//
+    TPtrC testData = GetStringFromConfigL(KTestData1);
 	TBuf8<200> data;
-	data.Copy(TestData1);
+	data.Copy(testData);
 	sock.SendTo(data, wapAddr, 0, status);
 	User::WaitForRequest(status);
 	ret = status.Int();
@@ -2069,15 +749,7 @@
 		INFO_PRINTF2(_L("Message NOT sent (error %d)..."), ret);
 		}
 
-
-	//
-	//	Closing the socket
-	//
-	sock.Close();
-
 	CleanupStack::PopAndDestroy(&sock);
-
-
 	return ret;
 	}
 
@@ -2132,35 +804,16 @@
 
 TVerdict CBackupRestoreStep::doTestStepL()
 /**
- *  
  *  Test step 16:
  *  simulating backup and restore
  *  @return - TVerdict code
- *  
  */
 	{
-	TInt testNumber =16;
-	RProperty testNumberProperty;
-
-	User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber));
-	CleanupClosePushL(testNumberProperty);
-
-	TRequestStatus status;
-	testNumberProperty.Subscribe(status);
-	User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNumber));
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	TInt testNumberCheck;
-	User::LeaveIfError(testNumberProperty.Get(testNumberCheck));
-	if (testNumber != testNumberCheck)
-		User::Leave(KErrNotFound);
-
-	//
-	//	Connect to socket server
-	//
- 	User::LeaveIfError(iSocketServer.Connect());
-
-	INFO_PRINTF1(_L("IOCTL Test step 16: send 7-Bit business card using IOCTL to test backup and restore"));
+    INFO_PRINTF1(_L("IOCTL Test step 16: send 7-Bit business card using IOCTL to test backup and restore"));
+    CSBEClient*  secureBackupEngine = CSBEClient::NewL();
+    CleanupStack::PushL(secureBackupEngine);
+    secureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
+                                     EBURNormal, ENoBackup);
 
 	INFO_PRINTF1(_L("Expecting SendWapL to succeed and the wap data file to be open"));
 	TEST(SendWapL() == KErrNone);
@@ -2169,7 +822,7 @@
 	// Notify the WAPPROT server that a backup is about to take place and
 	// that the server should close the wapstor
 	INFO_PRINTF1(_L("Simulating a backup notification"));
-	iSecureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
+	secureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
 									 EBURBackupFull, EBackupBase);
 
 	INFO_PRINTF1(_L("Expecting SendWapL to fail and the wap data file to be closed"));
@@ -2179,7 +832,7 @@
 	// Notify the WAPPROT server that a backup has completed
 	// that the server should open the wapstor
 	INFO_PRINTF1(_L("Simulating a backup complete notification"));
-	iSecureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
+	secureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
 									 EBURNormal, ENoBackup);
 
 	INFO_PRINTF1(_L("Expecting SendWapL to succeed and the wap data file to be open"));
@@ -2189,7 +842,7 @@
 	// Notify the WAPPROT server that a restore is about to take place and
 	// that the server should close the wapstor
 	INFO_PRINTF1(_L("Simulating a restore notification"));
-	iSecureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
+	secureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
 									 EBURRestorePartial, EBackupIncrement);
 
 	INFO_PRINTF1(_L("Expecting SendWapL to fail and the wap data file to be closed"));
@@ -2199,17 +852,14 @@
 	// Notify the WAPPROT server that a restore has completed
 	// that the server should open the wapstor
 	INFO_PRINTF1(_L("Simulating a restore complete notification"));
-	iSecureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
+	secureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
 									 EBURNormal, ENoBackup);
 
 	INFO_PRINTF1(_L("Expecting SendWapL to succeed and the wap data file to be open"));
 	TEST(SendWapL() == KErrNone);
 	TEST(IsWapFileOpenL() != EFalse);
-
-	INFO_PRINTF1(_L("Closing SocketServer ..."));
-	iSocketServer.Close();
 	
-	CleanupStack::PopAndDestroy(&testNumberProperty);
+    CleanupStack::PopAndDestroy(secureBackupEngine); // testNumberProperty, secureBackupEngine
 	return TestStepResult();
 	}
 	
@@ -2218,28 +868,581 @@
  *  Test step seventeen:
  *  Sends a 7_Bit business card. Using IOCTL query SMS transport parameters
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("IOCTL Test step 17: send 7-Bit v-card and query SMS transport parameters"));
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
-	TInt result = KErrNone;
-	TPtrC TestData1;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber=1;
+	//	Send a business card
+    TPtrC testData = GetStringFromConfigL(KTestData1);
+    SendWapMessage(testData);
+
+	// Create a descriptor with correct size for obtaining the message parameter
+	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr = parameterStore->Des();
+	
+	// Get the message parameter value
+	GetMessageParameterL(iSocket, parameterStorePtr);
+	
+	// Internalise the message parameter and check
+    TPtrC8 scAddr = iWapAddr.WapAddress(); 
+        
+	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
+	
+	iSocket.Close();
+	CleanupStack::PopAndDestroy(parameterStore);
+	return TestStepResult();
+	}
+	
+TVerdict CIoctlStep_18::doTestStepL()
+/**
+ *  Test step eighteen:
+ *  Sends a 7-Bit calendar entry (two segments). Using IOCTL query SMS transport parameters.
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 18: Sends a 7-Bit calendar entry (two segments). Using IOCTL query SMS transport parameters."));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+
+	//	Send a calendar entry
+	TPtrC testData = GetStringFromConfigL(KTestData1);
+	SendWapMessage(testData);
+	
+	// Create a descriptor with correct size for obtaining the message parameter
+	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr = parameterStore->Des();
+	
+	// Get the message parameter value
+	GetMessageParameterL(iSocket, parameterStorePtr);
+	
+	// Internalise the message parameter and check
+    TPtrC8 scAddr = iWapAddr.WapAddress(); 
+    
+	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
+	
+	iSocket.Close();
+	CleanupStack::PopAndDestroy(parameterStore);
+	return TestStepResult();
+	}
+	
+TVerdict CIoctlStep_19::doTestStepL()
+/**
+ *  Test step 19:
+ *  send/receive one 7-Bit two segments message and one 7-Bit one segment message
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 19: send/receive two 7-Bit messages"));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+    
+	//
+	//	Issue Ioctl for getting the length of the message
+	//
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the first message..."));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+
+    TPtrC testData1 = GetStringFromConfigL(KTestData1);
+    TPtrC testData2 = GetStringFromConfigL(KTestData2);
+
+    //	Send a calendar entry
+	SendWapMessage(testData2);
+    
+	//	Send a business card
+	SendWapMessage(testData1);
+	
+    //  Get the size of the first incoming message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+	
+	// Get the first message parameter value
+	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr = parameterStore->Des();
+	    
+    INFO_PRINTF1(_L("Getting parameter value of first message..."));
+    GetMessageParameterL(iSocket, parameterStorePtr);
+	
+	// Internalise the first message parameter and check
+    TPtrC8 scAddr = iWapAddr.WapAddress(); 
+    
+	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
+	
+	CleanupStack::PopAndDestroy(parameterStore);
+	
+	//	Receiving a datagram
+    TRequestStatus recvStatus;
+    TWapAddr recvWapAddr;
+    TBuf8<256> recvBuf2(length);
+    
+    iSocket.RecvFrom(recvBuf2,recvWapAddr,0,recvStatus);
+	User::WaitForRequest(recvStatus);
+	TESTL(recvStatus.Int()==KErrNone);
+	INFO_PRINTF1(_L("Received the first message..."));
+
+	//	Confirm the receipt of the message to the client
+	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
+	TESTL(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
+
+	INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the second message..."));
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+
+	//	Get the size of the SECOND incoming message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+    TESTCHECK(length(), testData1.Length(), "Check if reported length is correct");
+
+	// Create a descriptor with correct size for obtaining the second message parameter
+	HBufC8* parameterStore2 = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr2 = parameterStore2->Des();
+	
+	// Get the second message parameter value
+    INFO_PRINTF1(_L("Getting parameter value of second message..."));
+	GetMessageParameterL(iSocket, parameterStorePtr2);
+	
+	// Internalise the second message parameter and check
+	InternaliseSmsDataAndCheckL(parameterStorePtr2, scAddr);
+	
+	CleanupStack::PopAndDestroy(parameterStore2);
+	
+	//	Receiving the second message
+	ReceiveWapMessageFromSocket(length(), testData1);
+	
+	iSocket.Close();
+	return TestStepResult();
+	}
+	
+TVerdict CIoctlStep_20::doTestStepL()
+/**
+ *  Test step 20:
+ *  simulating client crash conditions with 7bit message
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 20: client crash condition 7-Bit message "));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+
+	//	Issue Ioctl for getting the length of the message
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+
+	//	Send a business card
+    TPtrC testData = GetStringFromConfigL(KTestData1);
+    SendWapMessage(testData);
+	
+    //  Get the size of the incoming message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+    TESTCHECK(length(), testData.Length(), "Check if reported length is correct");
+    
+	// Create a descriptor with correct size for obtaining the message parameter
+	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr = parameterStore->Des();
+	
+	// Get the message parameter value
+	GetMessageParameterL(iSocket, parameterStorePtr);
+	
+	// Internalise the message parameter and check
+	TPtrC8 scAddr = iWapAddr.WapAddress(); 
+
+	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
+	
+	CleanupStack::PopAndDestroy(parameterStore);
+
+    //  Receive a message
+    TRequestStatus recvStatus;
+    TWapAddr recvWapAddr;
+    HBufC8* recvBuf = HBufC8::NewLC(length());
+    TPtr8 recvPtr = recvBuf->Des(); 
+    
+    iSocket.RecvFrom(recvPtr, recvWapAddr, 0, recvStatus);
+    User::WaitForRequest(recvStatus);
+    TESTCHECKL(recvStatus.Int(), KErrNone, "Receiving a message");
+    
+    // Simulate a crash by closing and reopening the socket
+    iSocket.Close();
+    INFO_PRINTF1(_L("Socket was closed..."));
+    
+    OpenSocketL(iSocketServer, iSocket);
+    User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
+    INFO_PRINTF1(_L("Socket set option for indicating new client"));
+    User::LeaveIfError(iSocket.Bind(iWapAddr));
+    INFO_PRINTF1(_L("Socket was opened..."));
+		
+	//	Issue another get length of datagram as if not aware of the previous message
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+	
+    //  Get the size of the incoming message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+    TESTCHECK(length(), testData.Length(), "Check if reported length is correct");
+	
+	// Recreate a descriptor with correct size for obtaining the message parameter
+	HBufC8* parameterStore2 = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr2 = parameterStore2->Des();
+	
+	// Get the message parameter value
+	GetMessageParameterL(iSocket, parameterStorePtr2);
+	
+	// Internalise the message parameter and check
+	InternaliseSmsDataAndCheckL(parameterStorePtr2, scAddr);
+	
+	CleanupStack::PopAndDestroy(parameterStore2);
+
+	//	New message retrieved from SAR store
+	ReceiveWapMessageFromSocket(length(), testData);
+
+	iSocket.Close();
+    CleanupStack::PopAndDestroy(recvBuf);
+	return TestStepResult();
+	}
+	
+TVerdict CIoctlStep_21::doTestStepL()
+/**
+ *  Test step 21:
+ *  simulating client crash conditions with 8bit push message
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 21: client crash condition with 8Bit push message"));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+
+    //  Issue Ioctl for getting the length of the message
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+
+    //  Get the size of the incoming message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+
+	// Create a descriptor with correct size for obtaining the message parameter
+	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr = parameterStore->Des();
+	
+	// Get the message parameter value
+	GetMessageParameterL(iSocket, parameterStorePtr);
+	
+	// Internalise the message parameter and check
+    TPtrC8 scAddr = iWapAddr.WapAddress(); 
+	
+	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
+	
+	CleanupStack::PopAndDestroy(parameterStore);
+	
+	//	Receiving a datagram
+    TRequestStatus recvStatus;
+    TWapAddr recvWapAddr;
+    TBuf8<256> recvBuf(length);
+    
+    iSocket.RecvFrom(recvBuf, recvWapAddr, 0, recvStatus);
+	User::WaitForRequest(recvStatus);
+	TESTL(recvStatus.Int()==KErrNone);
+	INFO_PRINTF1(_L("Received the message..."));
+	
+	// Simulate a crash by closing and reopening the socket
+	iSocket.Close();
+	INFO_PRINTF1(_L("Socket was closed..."));
 
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData1) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result = KErrNotFound;
-		}
+	OpenSocketL(iSocketServer, iSocket);
+	User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
+	INFO_PRINTF1(_L("Socket set option for indicating new client"));
+	User::LeaveIfError(iSocket.Bind(iWapAddr));
+	INFO_PRINTF1(_L("Socket was opened..."));
+	
+	//	Issue another get length of datagram as if not aware of the previous message
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+
+    //  Get the size of the incoming message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+	
+	// Recreate a descriptor with correct size for obtaining the message parameter
+    HBufC8* parameterStore2 = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr2 = parameterStore2->Des();
+	
+	// Get the message parameter value
+	GetMessageParameterL(iSocket, parameterStorePtr2);
+	
+	// Internalise the message parameter and check
+	InternaliseSmsDataAndCheckL(parameterStorePtr2, scAddr);
+	
+	CleanupStack::PopAndDestroy(parameterStore2);
+	
+	//	New message retrieved from SAR store
+	TBuf8<256> newRecvBuf(length);
+    iSocket.RecvFrom(newRecvBuf,recvWapAddr,0,recvStatus);
+	User::WaitForRequest(recvStatus);
+	TESTL(recvStatus.Int()==KErrNone);
+	INFO_PRINTF1(_L("Received the message..."));
+	
+	//	Confirm the receipt of the message to the client
+	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
+	TESTL(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
+	
+	//	Compare the received message with the previous one
+	//	They should be identical
+	TESTL(newRecvBuf.Compare(recvBuf)==0);
+
+	iSocket.Close();
+	return TestStepResult();
+	}
+
+TVerdict CIoctlStep_22::doTestStepL()
+/**
+ *  Test step 22:
+ *  Push Message (8-Bit). Using IOCTL query SMS transport parameters
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 22: Push Message (8-Bit) and query SMS transport parameters"));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+    
+	// Create a descriptor with correct size for obtaining the message parameter
+	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr = parameterStore->Des();
+	
+	// Get the message parameter value
+	GetMessageParameterL(iSocket, parameterStorePtr);
+	
+	// Internalise the message parameter and check
+    TPtrC8 scAddr = iWapAddr.WapAddress(); 
+    
+	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
+	
+	CleanupStack::PopAndDestroy(parameterStore);
+	
+	iSocket.Close();
+	return TestStepResult();
+	}
+	
+TVerdict CIoctlStep_23::doTestStepL()
+/**
+ *  Test step 23:
+ *  Two Push Messages (8-Bit). Using IOCTL query SMS transport parameters
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 23: Push two push message(8-Bit) query transport parameters"));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+    
+    //  Issue Ioctl for getting the length of the message
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> length;
+
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+
+    //  Get the size of the incoming message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+    
+	INFO_PRINTF1(_L("Getting parameter value of first message..."));
+	
+	// Create a descriptor with correct size for obtaining the first message parameter
+	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr = parameterStore->Des();
+	
+	// Get the first message parameter value
+	GetMessageParameterL(iSocket, parameterStorePtr);
+	
+	// Internalise the first message parameter and check
+	TPtrC8 scAddr = iWapAddr.WapAddress(); 
+    
+	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
+	
+	CleanupStack::PopAndDestroy(parameterStore);
+
+	//	Receiving push datagram
+	TRequestStatus recvStatus;
+    TWapAddr recvWapAddr;
+    TBuf8<256> recvBuf1(length);
+    
+    iSocket.RecvFrom(recvBuf1,recvWapAddr,0,recvStatus);
+	User::WaitForRequest(recvStatus);
+	TESTL(recvStatus.Int()==KErrNone);
+	INFO_PRINTF1(_L("Received the push message..."));
+
+	//	Confirm the receipt of the message to the client
+	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
+	TESTL(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
+
+    INFO_PRINTF1(_L("Issuing IOCTL for getting the length of the message..."));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+
+    //  Get the size of the second incoming push message
+    User::WaitForRequest(ioctlStatus);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the size of the first incoming message");
+	
+	INFO_PRINTF1(_L("Getting parameter value of second message..."));
+
+	// Create a descriptor with correct size for obtaining the second message parameter
+	HBufC8* parameterStore2 = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr2 = parameterStore2->Des();
+	
+	// Get the second message parameter value
+	GetMessageParameterL(iSocket, parameterStorePtr2);
 	
-	TESTL(result==KErrNone);
+	// Internalise the second message parameter and check
+	InternaliseSmsDataAndCheckL(parameterStorePtr2, scAddr);
+	
+	CleanupStack::PopAndDestroy(parameterStore2);
+	
+	//	Receiving push datagram
+	TBuf8<256> recvBuf2(length);
+
+	iSocket.RecvFrom(recvBuf2,recvWapAddr,0,recvStatus);
+	User::WaitForRequest(recvStatus);
+	TESTL(recvStatus.Int()==KErrNone);
+	INFO_PRINTF1(_L("Received the second push message..."));
+
+	//	Compare the received message with the previous one
+	//	They should be identical
+	TESTL(recvBuf2.Compare(recvBuf1)==0);
+		
+	//	Confirm the receipt of the message to the client
+	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
+	TESTL(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
+
+	iSocket.Close();
+	return TestStepResult();
+	}
+
+TVerdict CIoctlStep_24::doTestStepL()
+/**
+ *  Test step 24:
+ *  Test Cancel IOCTL
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 24: Testing Cancel IOCTL"));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+
+	TRequestStatus ioctlStatus;
+	TBuf8<200> smsdata;
+	TPckgBuf<TInt> paramLength;
+	
+	//	Issue Ioctl for getting the length of the message parameter
+	INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParametersLength"));
+	iSocket.Ioctl(KSOGetMessageParametersLength, ioctlStatus, &smsdata, KSolWapProv);
 	
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
+	//	Issue Cancel Ioctl
+	INFO_PRINTF1(_L("Issue of cancel IOCTL for KSOGetMessageParametersLength"));
+	iSocket.CancelIoctl();
+	TESTCHECKL(ioctlStatus.Int(), KErrCancel, "Checking if the outstanding IOCTL has been cancelled");
+
+	//	Issue Ioctl for getting the message parameter
+	INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParameters"));
+	iSocket.Ioctl(KSOGetMessageParameters, ioctlStatus, &smsdata, KSolWapProv);
+
+	//	Issue Cancel Ioctl
+	INFO_PRINTF1(_L("Issue of cancel IOCTL for KSOGetMessageParameters"));
+	iSocket.CancelIoctl();
+    TESTCHECKL(ioctlStatus.Int(), KErrCancel, "Checking if the outstanding IOCTL has been cancelled");
+
+	iSocket.Close();
+	return TestStepResult();
+	}
+
+TVerdict CIoctlStep_25::doTestStepL()
+/**
+ *  Test step 25:
+ *  Test issue IOCTL without SetOption NewStyleClient
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 25: Test issue IOCTL without SetOption NewStyleClient"));
+    // Configure and bind to a socket
+    SetupWapSocketL(iSocket, iWapAddr, KWapPort, EFalse);
+
+	//	Issue Ioctl for getting the length of the message parameter (should fail)
+    TRequestStatus ioctlStatus;
+    TPckgBuf<TInt> paramLength;
+
+	INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParametersLength"));
+	iSocket.Ioctl(KSOGetMessageParametersLength, ioctlStatus, &paramLength, KSolWapProv);
+	TESTL(ioctlStatus.Int()!=KErrNone);
+				
+	//	Issue Ioctl for getting the message parameter (should fail)
+	INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParameters"));
+	TBuf8<200> smsdata;
+	   
+	iSocket.Ioctl(KSOGetMessageParameters, ioctlStatus, &smsdata, KSolWapProv);
+	User::WaitForRequest(ioctlStatus);
+	TESTL(ioctlStatus.Int()!=KErrNone);
+
+	iSocket.Close();
+	return TestStepResult();
+	}
+	
+TVerdict CIoctlStep_26::doTestStepL()
+/**
+ *  Test step 26:
+ *  Sends a 8-Bit calendar entry using IOCTL(two segments)
+ *  @return - TVerdict code
+ */
+	{
+	INFO_PRINTF1(_L("IOCTL Test step 26: send a 8-Bit VCal (two segments)"));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+
+	TESTL(iSocket.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms8BitDCS)==KErrNone);
+
+	//	Send a calendar entry
+    TPtrC testData = GetStringFromConfigL(KTestData1);
+    SendWapMessage(testData);
+
+	// Create a descriptor with correct size for obtaining the message parameter
+	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(iSocket));
+	TPtr8 parameterStorePtr = parameterStore->Des();
+	
+	// Get the message parameter value
+	GetMessageParameterL(iSocket, parameterStorePtr);
+	
+	// Internalise the message parameter and check
+    TPtrC8 scAddr = iWapAddr.WapAddress(); 
+    
+	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
+	
+	CleanupStack::PopAndDestroy(parameterStore);		
+	
+	iSocket.Close();
+	return TestStepResult();
+	}
+
+struct SOneOpTestThreadInfo
+	{
+	CIoctlStep_27* iTest;
+	TPtrC* iTestData1;
+	TPtrC16* iTelNumber;
+	TInt iPort;
+	};
+
+TInt CIoctlStep_27::DoPanicTestL(TPtrC* aTestData1, TPtrC16* aTelNumber, TInt aPort)
+	{
+    TInt testNumber = 1;
+    TInt port = aPort;
+    TPtrC TestData1 = *aTestData1;
+    TPtrC16 TelNumber = *aTelNumber;
+
+    User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
+    User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
 
 	//
     //	Setting the port number and service center number of the wap address
@@ -2266,1437 +1469,16 @@
 	//	Define and open the socket
 	//
 	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-	
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-	
-	//
-	//	Send a business card
-	//
-	TRequestStatus status;
-	TBuf8<200> data;
-	data.Copy(TestData1);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	TESTL(status.Int()==KErrNone);
-	INFO_PRINTF1(_L("Message sent..."));
-	
-	//
-	// Create a descriptor with correct size for obtaining the message parameter
-	//
-	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr = parameterStore->Des();
-	
-	//
-	// Get the message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr);
-	
-	//
-	// Internalise the message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore);
-	
-	//
-	//	Closing the socket
-	//
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
-	return TestStepResult();
-	}
-	
-TVerdict CIoctlStep_18::doTestStepL()
-/**
- *  Test step eighteen:
- *  Sends a 7-Bit calendar entry (two segments). Using IOCTL query SMS transport parameters.
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 18: Sends a 7-Bit calendar entry (two segments). Using IOCTL query SMS transport parameters."));
-
-	TInt result = KErrNone;
-	TPtrC TestData;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber = 2;
-	
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result = KErrNotFound;
-		}
-
-	TESTL(result==KErrNone);
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM Tsy)
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-	
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-		
-	//
-	//	Send a calendar entry
-	//
-	TRequestStatus status;
-	TBuf8<300> data;
-	data.Copy(TestData);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	TESTL(status.Int()==KErrNone);
-	INFO_PRINTF1(_L("Message sent..."));
-
-	//
-	// Create a descriptor with correct size for obtaining the message parameter
-	//
-	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr = parameterStore->Des();
-	
-	//
-	// Get the message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr);
-	
-	//
-	// Internalise the message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore);
-	
-	//
-	//	Closing the socket
-
-    CleanupStack::PopAndDestroy(&sock);
-	CleanupStack::PopAndDestroy(&socketServer);
-
-	return TestStepResult();
-	}
-	
-TVerdict CIoctlStep_19::doTestStepL()
-/**
- *  Test step 19:
- *  send/receive one 7-Bit two segments message and one 7-Bit one segment message
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 19: send/receive two 7-Bit messages"));
-
-	TInt result = KErrNone;
-	TPtrC TestData1;
-	TPtrC TestData2;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber = 3;
-
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData1) ||
-	   !GetStringFromConfig(ConfigSection(),KTestData2, TestData2) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result = KErrNotFound;
-		}
-
-	TESTL(result==KErrNone);
-	
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
-	//	Send a calendar entry
-	//
-	TRequestStatus  status;
-
-	TBuf8<300> data2;
-	data2.Copy(TestData2);
-	sock.SendTo(data2, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	TESTL(status.Int()==KErrNone);
-	INFO_PRINTF1(_L("First message sent..."));
-	//
-	//	Send a business card
-	//
-	TBuf8<200> data1;
-	data1.Copy(TestData1);
-	sock.SendTo(data1, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	TESTL(status.Int()==KErrNone);
-	INFO_PRINTF1(_L("Second message sent..."));
-	//
-	//	Get the size of the first incoming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	TESTL(ioctlStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("IOCTL for GetLength completed..."));
-	TBuf8<256> recvBuf2(length);
-	
-	INFO_PRINTF1(_L("Getting parameter value of first message..."));
-	
-	//
-	// Create a descriptor with correct size for obtaining the first message parameter
-	//
-	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr = parameterStore->Des();
-	
-	//
-	// Get the first message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr);
-	
-	//
-	// Internalise the first message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore);
-	
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf2,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	TESTL(recvStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("Received the first message..."));
-
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	TESTL(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
-	
-	//
-	//	Issue Ioctl for getting the length of the second message
-	//
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-	INFO_PRINTF1(_L("Issue of the 2nd IOCTL for GetLength"));
-
-	//
-	//	Get the size of the SECOND incoming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	TESTL(ioctlStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("IOCTL completed"));
-	
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<256> recvBuf1(length);
-	TESTL(length()==data1.Length());
-		
-	INFO_PRINTF1(_L("Getting parameter value of second message..."));
-	
-	//
-	// Create a descriptor with correct size for obtaining the second message parameter
-	//
-	HBufC8* parameterStore2 = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr2 = parameterStore2->Des();
-	
-	//
-	// Get the second message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr2);
-	
-	//
-	// Internalise the second message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr2, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore2);
-	
-	//
-	//	Receiving the second message
-	//
-	sock.RecvFrom(recvBuf1,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	TESTL(recvStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("Receievd the second datagram"));
-	TEST(recvBuf1.Compare(data1) == 0);
-
-	//
-	//	Confirm the receipt of the second message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of the second message"));
-	TESTL(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
-
-	//
-	//	Closing the socket
-	//
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
-	return TestStepResult();
-	}
-	
-TVerdict CIoctlStep_20::doTestStepL()
-/**
- *  
- *  Test step 20:
- *  simulating client crash conditions with 7bit message
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 20: client crash condition 7-Bit message "));
-
-	TInt result = KErrNone;
-	TPtrC TestData;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber =4;
-
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result=KErrNotFound;
-		}
-		
-	TESTL(result==KErrNone);
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
-	//	Send a business card
-	//
-	TRequestStatus status;
-	TBuf8<200> data;
-	data.Copy(TestData);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	TESTL(status.Int()==KErrNone);
-	INFO_PRINTF1(_L("Message sent..."));
-	//
-	//	Get the size of the incoming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	TESTL(ioctlStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("IOCTL completed..."));
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<256> recvBuf(length);
-	TESTL(length()==data.Length());
-	
-	//
-	// Create a descriptor with correct size for obtaining the message parameter
-	//
-	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr = parameterStore->Des();
-	
-	//
-	// Get the message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr);
-	
-	//
-	// Internalise the message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore);
-
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	TESTL(recvStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("Received the message..."));
-	
-	//
-	//	Close socket
-	//
-	sock.Close();
-	INFO_PRINTF1(_L("Socket was closed..."));
-	
-	//
-	//	Open the socket
-	//
-	TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	INFO_PRINTF1(_L("Socket was opened..."));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-	
-	//
-	//	Issue another get length of datagram as if not aware of the previous message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-	
-	//
-	//	waiting for request to be completed
-	//
-	User::WaitForRequest(ioctlStatus);
-	TESTL(ioctlStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("IOCTL completed..."));
-	
-	//
-	//	Check if reported length is correct
-	//
-	TBuf8<256> newRecvBuf(length);
-	TESTL(length()==data.Length());
-	
-	//
-	// Recreate a descriptor with correct size for obtaining the message parameter
-	//
-	HBufC8* parameterStore2 = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr2 = parameterStore2->Des();
-	
-	//
-	// Get the message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr2);
-	
-	//
-	// Internalise the message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr2, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore2);
-
-	//
-	//	New message retrieved from SAR store
-	//
-	sock.RecvFrom(newRecvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	TESTL(recvStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("Received the message..."));
-	TEST(newRecvBuf.Compare(data) == 0);
-	
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	TESTL(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
-
-	//
-	//	Closing the socket
-	//
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
-	return TestStepResult();
-	}
-	
-TVerdict CIoctlStep_21::doTestStepL()
-/**
- *  
- *  Test step 21:
- *  simulating client crash conditions with 8bit push message
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 21: client crash condition with 8Bit push message"));
-
-	TInt result = KErrNone;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber= 5;
-
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result=KErrNotFound;
-		}
-		
-	TESTL(result==KErrNone);
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
+	OpenSocketLC(socketServer, sock);
 	//
 	//	Indicating to the protocol that it's a new client
 	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-	
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-	
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
-	//	Get the size of the incoming message
-	//
-	User::WaitForRequest(ioctlStatus);
-	TESTL(ioctlStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("IOCTL completed..."));
-
-	TBuf8<256> recvBuf(length);
-	
-	//
-	// Create a descriptor with correct size for obtaining the message parameter
-	//
-	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr = parameterStore->Des();
-	
-	//
-	// Get the message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr);
-	
-	//
-	// Internalise the message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore);
-	
-	//
-	//	Receiving a datagram
-	//
-	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	TESTL(recvStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("Received the message..."));
-	
-	//
-	//	Close socket
-	//
-	sock.Close();
-	INFO_PRINTF1(_L("Socket was closed..."));
-	
-	//
-	//	Open the socket
-	//
-	TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	INFO_PRINTF1(_L("Socket was opened..."));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-	
-	//
-	//	Issue another get length of datagram as if not aware of the previous message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-	
-	//
-	//	waiting for request to be completed
-	//
-	User::WaitForRequest(ioctlStatus);
-	TESTL(ioctlStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("IOCTL completed..."));
-	
-	//
-	//	Allocate buffer
-	//
-	TBuf8<256> newRecvBuf(length);
-	
-	//
-	// Recreate a descriptor with correct size for obtaining the message parameter
-	//
-	HBufC8* parameterStore2 = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr2 = parameterStore2->Des();
-	
-	//
-	// Get the message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr2);
-	
-	//
-	// Internalise the message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr2, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore2);
-	
-	//
-	//	New message retrieved from SAR store
-	//
-	sock.RecvFrom(newRecvBuf,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	TESTL(recvStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("Received the message..."));
-	
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	TESTL(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
-	
-	//
-	//	Compare the received message with the previous one
-	//	They should be identical
-	//
-	TESTL(newRecvBuf.Compare(recvBuf)==0);
-	
-	//
-	//	Closing the socket
-	//
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
-	return TestStepResult();
-	}
-
-TVerdict CIoctlStep_22::doTestStepL()
-/**
- *  Test step 22:
- *  Push Message (8-Bit). Using IOCTL query SMS transport parameters
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 22: Push Message (8-Bit) and query SMS transport parameters"));
-
-	TInt result = KErrNone;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber = 7;
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result=KErrNotFound;
-		}
-		
-	TESTL(result==KErrNone);
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-	
-	//
-	// Create a descriptor with correct size for obtaining the message parameter
-	//
-	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr = parameterStore->Des();
-	
-	//
-	// Get the message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr);
-	
-	//
-	// Internalise the message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore);
-	
-	//
-	//	Closing the socket
-	//
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
-	return TestStepResult();
-	}
-	
-TVerdict CIoctlStep_23::doTestStepL()
-/**
- *  Test step 23:
- *  Two Push Messages (8-Bit). Using IOCTL query SMS transport parameters
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 23: Push two push message(8-Bit) query transport parameters"));
-
-	TInt result=KErrNone;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber=8;
-
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result=KErrNotFound;
-		}
-		
-	TESTL(result==KErrNone);
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TRequestStatus recvStatus;
-	TPckgBuf<TInt> length;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
-	//	Get the size of the incoming push message
-	//
-	User::WaitForRequest(ioctlStatus);
-	TESTL(ioctlStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("IOCTL completed..."));
-	
-	INFO_PRINTF1(_L("Getting parameter value of first message..."));
-	
-	//
-	// Create a descriptor with correct size for obtaining the first message parameter
-	//
-	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr = parameterStore->Des();
-	
-	//
-	// Get the first message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr);
-	
-	//
-	// Internalise the first message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore);
-
-	//
-	//	Allocate buffer
-	//
-	TBuf8<256> recvBuf1(length);
-
-	//
-	//	Receiving push datagram
-	//
-	sock.RecvFrom(recvBuf1,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	TESTL(recvStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("Received the push message..."));
-
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	TESTL(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
-
-	//
-	//	Issue another Ioctl for getting the length of the message
-	//
-	INFO_PRINTF1(_L("Issue of first IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-
-	//
-	//	Get the size of the second incoming push message
-	//
-	User::WaitForRequest(ioctlStatus);
-	TESTL(ioctlStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("IOCTL completed..."));
-	
-	INFO_PRINTF1(_L("Getting parameter value of second message..."));
-
-	//
-	// Create a descriptor with correct size for obtaining the second message parameter
-	//
-	HBufC8* parameterStore2 = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr2 = parameterStore2->Des();
-	
-	//
-	// Get the second message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr2);
-	
-	//
-	// Internalise the second message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr2, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore2);
-	
-	//
-	//	Allocate buffer
-	//
-	TBuf8<256> recvBuf2(length);
+    INFO_PRINTF1(_L("Socket set option for indicating new client"));
+    TInt ret = sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0);
+    TESTCHECKL(ret, KErrNone, "Indicating to the protocol that it's a new client")
 
-	//
-	//	Receiving push datagram
-	//
-	sock.RecvFrom(recvBuf2,recvWapAddr,0,recvStatus);
-	User::WaitForRequest(recvStatus);
-	TESTL(recvStatus.Int()==KErrNone);
-	INFO_PRINTF1(_L("Received the second push message..."));
-
-	//
-	//	Compare the received message with the previous one
-	//	They should be identical
-	//
-	TESTL(recvBuf2.Compare(recvBuf1)==0);
-		
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-	TESTL(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
-
-	//
-	//	Closing the socket
-	//
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
-	return TestStepResult();
-	}
-
-TVerdict CIoctlStep_24::doTestStepL()
-/**
- *  Test step 24:
- *  Test Cancel IOCTL
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 24: Testing Cancel IOCTL"));
-
-	TInt result=KErrNone;
-	TPtrC16 TelNumber;
-	TInt port=226;
-
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result=KErrNotFound;
-		}
-		
-	TESTL(result==KErrNone);
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM tsy)
-	//
-	TWapAddr wapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TBuf8<200> smsdata;
-	TPckgBuf<TInt> paramLength;
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-	
-	//
-	//	Issue Ioctl for getting the length of the message parameter
-	//
-	INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParametersLength"));
-	sock.Ioctl(KSOGetMessageParametersLength, ioctlStatus, &smsdata, KSolWapProv);
-	
-	//
-	//	Issue Cancel Ioctl
-	//
-	INFO_PRINTF1(_L("Issue of cancel IOCTL for KSOGetMessageParametersLength"));
-	sock.CancelIoctl();
-	
-	//
-	//	Check if the outstanding IOCTL has been cancelled
-	//
-	TESTL(ioctlStatus.Int()==KErrCancel);
-
-	//
-	//	Issue Ioctl for getting the message parameter
-	//
-	INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParameters"));
-	sock.Ioctl(KSOGetMessageParameters, ioctlStatus, &smsdata, KSolWapProv);
-
-	//
-	//	Issue Cancel Ioctl
-	//
-	INFO_PRINTF1(_L("Issue of cancel IOCTL for KSOGetMessageParameters"));
-	sock.CancelIoctl();
-
-	//
-	//	Check if the outstanding IOCTL has been cancelled
-	//
-	TESTL(ioctlStatus==KErrCancel);
-
-	//
-	//	Closing the socket
-	//
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
-	return TestStepResult();
-	}
-
-TVerdict CIoctlStep_25::doTestStepL()
-/**
- *  Test step 25:
- *  Test issue IOCTL without SetOption NewStyleClient
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 25: Test issue IOCTL without SetOption NewStyleClient"));
-
-	TInt result=KErrNone;
-	TPtrC16 TelNumber;
-	TInt port=226;
-
-	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result=KErrNotFound;
-		}
-		
-	TESTL(result==KErrNone);
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM tsy)
-	//
-	TWapAddr wapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	TRequestStatus ioctlStatus;
-	TBuf8<200> smsdata;
-	TPckgBuf<TInt> paramLength;
-
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-	
-	//
-	//	Issue Ioctl for getting the length of the message parameter (should fail)
-	//
-	INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParametersLength"));
-	sock.Ioctl(KSOGetMessageParametersLength, ioctlStatus, &paramLength, KSolWapProv);
-	TESTL(ioctlStatus.Int()!=KErrNone);
-				
-	//
-	//	Issue Ioctl for getting the message parameter (should fail)
-	//
-	INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParameters"));
-	sock.Ioctl(KSOGetMessageParameters, ioctlStatus, &smsdata, KSolWapProv);
-	User::WaitForRequest(ioctlStatus);
-	TESTL(ioctlStatus.Int()!=KErrNone);
-
-	//
-	//	Closing the socket
-	//
-    CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
-	return TestStepResult();
-	}
-	
-TVerdict CIoctlStep_26::doTestStepL()
-/**
- *  Test step 26:
- *  Sends a 8-Bit calendar entry using IOCTL(two segments)
- *  @return - TVerdict code
- *  
- */
-	{
-	INFO_PRINTF1(_L("IOCTL Test step 26: send a 8-Bit VCal (two segments)"));
-
-	TInt result=KErrNone;
-	TPtrC TestData;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber = 13;
-	
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result=KErrNotFound;
-		}
-	
-	TESTL(result==KErrNone);
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM Tsy)
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-	TESTL(sock.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,EWapSms8BitDCS)==KErrNone);
-
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
-
-	//
-	//	Send a calendar entry
-	//
-	TRequestStatus  status;
-
-	TBuf8<300> data;
-	data.Copy(TestData);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	TESTL(status.Int()==KErrNone);
-	INFO_PRINTF1(_L("Message sent..."));
-	
-	//
-	// Create a descriptor with correct size for obtaining the message parameter
-	//
-	HBufC8* parameterStore = HBufC8::NewLC(GetMessageParameterLengthL(sock));
-	TPtr8 parameterStorePtr = parameterStore->Des();
-	
-	//
-	// Get the message parameter value
-	//
-	GetMessageParameterL(sock, parameterStorePtr);
-	
-	//
-	// Internalise the message parameter and check
-	//
-	InternaliseSmsDataAndCheckL(parameterStorePtr, scAddr);
-	
-	CleanupStack::PopAndDestroy(parameterStore);		
-	
-	//
-	//	Closing the socket
-	//
-    CleanupStack::PopAndDestroy(&sock);
-	CleanupStack::PopAndDestroy(&socketServer);
-
-	return TestStepResult();
-	}
-
-struct SOneOpTestThreadInfo
-	{
-	CIoctlStep_27* iTest;
-	TPtrC* iTestData1;
-	TPtrC16* iTelNumber;
-	TInt iPort;
-	};
-
-TInt CIoctlStep_27::DoPanicTestL(TPtrC* aTestData1, TPtrC16* aTelNumber, TInt aPort)
-	{
-	TInt testNumber = 1;
-	TInt port = aPort;
-	TPtrC TestData1 = *aTestData1;
-	TPtrC16 TelNumber = *aTelNumber;
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM tsy)
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
+    ret = sock.Bind(wapAddr);
+    TESTCHECKL(ret, KErrNone, "Socket bind");
 
 	//
 	//	Send a business card
@@ -3707,7 +1489,7 @@
 	data.Copy(TestData1);
 	sock.SendTo(data, wapAddr, 0, status);
 	User::WaitForRequest(status);
-	TESTL(status.Int()==KErrNone);
+    TESTCHECKL(status.Int(), KErrNone, "Sending a message");
 
 	TRequestStatus ioctlStatus;
 	TRequestStatus recvStatus;
@@ -3730,7 +1512,7 @@
 	//	Get the size of the first incoming message
 	//
 	User::WaitForRequest(ioctlStatus);
-	TESTL(ioctlStatus.Int()==KErrNone);
+    TESTCHECKL(ioctlStatus.Int(), KErrNone, "Getting the length of the incoming message");
 
 	//
 	//	Receiving a datagram
@@ -3738,13 +1520,16 @@
 	TBuf8<256> recvBuf(length);
 	sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
 	User::WaitForRequest(recvStatus);
-	TESTL(recvStatus.Int()==KErrNone);
-	TEST(recvBuf.Compare(data) == 0);
+    TESTCHECKL(recvStatus.Int(), KErrNone, "Receiving a message");
+    TESTCHECK(recvBuf.Compare(data), 0, "Checking the received message matched expected");
+
 	
 	//
 	//	Confirm the receipt of the message to the client
 	//
-	TESTL(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0)==KErrNone);
+    INFO_PRINTF1(_L("Setting Socket option for indicating receipt of the message..."));
+    ret = iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0);
+    TESTCHECKL(ret, KErrNone, "Setting Socket option for indicating receipt of the message");
 	
 	//
 	//	Closing the socket
@@ -3773,7 +1558,6 @@
  *  Test step 27:
  *  Send a 7_Bit business card. Issue both a get length and get message parameters to IOCTL  at sametime
  *  @return - TVerdict code
- *  
  */
 	{
 	const TUint KHeapMinSize=0x01000;
@@ -3806,13 +1590,13 @@
 	RThread thread;
 	TInt rc = thread.Create(_L("PanicThread"),testPanicsL,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,&info);
 	
-	TESTL(rc==KErrNone);
+	TESTCHECKL(rc, KErrNone,"Creating a thread" );
 		
 	TRequestStatus s;
     thread.Logon(s);
 	thread.Resume();
 	User::WaitForRequest(s);
-	TESTL(thread.ExitType()==EExitPanic);
+	TESTCHECK(thread.ExitType(), EExitPanic, "Checking the correct exit type");
 			
 	INFO_PRINTF2(_L("Exit type is: %d"), thread.ExitType());
 	
@@ -3827,20 +1611,11 @@
 	{
 	__UHEAP_MARK;
 	
+    SetTestNumberFromConfigurationFileL();
+	
 	iScheduler = new(ELeave) CActiveScheduler;
 	CActiveScheduler::Install(iScheduler);
 
-	TInt err;
-    err=User::LoadPhysicalDevice(PDD_NAME);
-    TESTL(err==KErrNone || err==KErrAlreadyExists);
-
-    err=User::LoadLogicalDevice(LDD_NAME);
-    TESTL(err==KErrNone || err==KErrAlreadyExists);
-
-    err = StartC32();
-	ERR_PRINTF2(TRefByValue<const TDesC>(_L("Start Comms Process Status = %d")), err);
-    TESTL(err==KErrNone || err==KErrAlreadyExists);
-
 	INFO_PRINTF1(_L("Deleting segmentation and reassembly stores..."));
 
 	RFs fileServer;
@@ -3856,12 +1631,20 @@
 	fileServer.Delete(KSegmentationStoreName);
 
 	fileServer.Close();
+	
+    TInt  ret = iSocketServer.Connect(KSocketMessageSlots);
+    if (ret != KErrNone)
+        {
+        ERR_PRINTF2(_L("Connecting to socket server failed [ret=%d]"), ret);
+        }
 
 	return TestStepResult();
 	}
 	
 TVerdict CIoctlStep_28::doTestStepPostambleL()
 	{
+    iSocketServer.Close();
+    
 	delete iScheduler;
 	iScheduler = NULL;
 
@@ -3871,85 +1654,25 @@
 	}
 	
 TVerdict CIoctlStep_28::doTestStepL()
-
 /**
  *  Test step seventeen:
  *  Sends a 7_Bit business card. Issue a get message parameters to IOCTL without correct platform security
  *  @return - TVerdict code
- *  
  */
 	{
 	INFO_PRINTF1(_L("Sends a 7_Bit business card. Issue a get message parameters to IOCTL without correct platform security"));
-
-	TInt result=KErrNone;
-	TPtrC TestData1;
-	TPtrC16 TelNumber;
-	TInt port=226;
-	TInt testNumber=1;
-
-	if(!GetStringFromConfig(ConfigSection(),KTestData1, TestData1) ||
-	   !GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
-	   !GetIntFromConfig(ConfigSection(),KWapPort,port))
-		{
-		result=KErrNotFound;
-		}
-		
-	TESTL(result==KErrNone);
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM tsy)
-	//
-	TWapAddr wapAddr;
-	TWapAddr recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100> scNumber;
-	scNumber.Copy(TelNumber);
-	TPtrC8 scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket sock;
-    TESTL(sock.Open(socketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol)==KErrNone);
-	CleanupClosePushL(sock);
-
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	TESTL(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)==KErrNone);
-
-	//
-	//	Bind
-	//
-	TESTL(sock.Bind(wapAddr)==KErrNone);
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
 	//
 	//	Send a business card
 	//
 	TRequestStatus status;
+    TPtrC testData = GetStringFromConfigL(KTestData1);
+    
 	TBuf8<200> data;
-	data.Copy(TestData1);
-	sock.SendTo(data, wapAddr, 0, status);
+	data.Copy(testData);
+	iSocket.SendTo(data, iWapAddr, 0, status);
 	User::WaitForRequest(status);
 	TESTL(status.Int()==KErrNone);
 	INFO_PRINTF1(_L("Message sent..."));
@@ -3961,33 +1684,38 @@
 	TBuf8<200> smsdata;
 	
 	INFO_PRINTF1(_L("Issue of IOCTL for KSOGetMessageParameters"));
-	sock.Ioctl(KSOGetMessageParameters, testStatus, &smsdata, KSolWapProv);
+	iSocket.Ioctl(KSOGetMessageParameters, testStatus, &smsdata, KSolWapProv);
 	
 	User::WaitForRequest(testStatus);
 	TESTL(testStatus.Int()==KErrPermissionDenied);
 	INFO_PRINTF2(_L("KSOGetMessageParameters on Ioctl failed to complete with: %d"), testStatus.Int());
 			
-	//
-	//	Closing the socket
-	//
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
+	iSocket.Close();
 	return TestStepResult();
 	}
 
+CSetDiskMonitorLimits::CSetDiskMonitorLimits()
+    {
+    iPartOfMultiStepTestCase = ETrue;
+    }
 
 TVerdict CSetDiskMonitorLimits::doTestStepL()
 /**
 	Creates smsu.rsc file which defines the upper and lower limits for the disk space monitor
 */
-
-   {
+    {
 #ifndef _DEBUG
     INFO_PRINTF1(_L("This test can only be run when the SMS Stack is in debug mode."));
-#else       
-    TInt highDrop = 4;
-    TInt lowDrop = 10;
+#else
+    TInt err = RProperty::Define(KUidPSSMSStackCategory, KUidPSSMSStackFreeDiskSpaceKey, RProperty::EInt);
+    if ((err != KErrNone) && (err != KErrAlreadyExists))    
+        {
+        ERR_PRINTF2(_L("RProperty::Define() failure [err=%d]"), err);
+        User::Leave(err);
+        }
+		
+    TInt highDrop = 3;
+    TInt lowDrop = 8;
     TInt freeDrop = 0;
   
     GetIntFromConfig(_L("DiskMonitorLimits"), _L("highDrop"), highDrop);
@@ -3997,7 +1725,12 @@
 #endif    
 	return TestStepResult();
     }
-    
+
+CSetDiskSpace::CSetDiskSpace()
+    {
+    iPartOfMultiStepTestCase = ETrue;
+    }
+
 /**
  *  Set free disk space to the required limit
  */
@@ -4020,7 +1753,7 @@
 	Free up disk space by deleting the temp files created
 */
 TVerdict CFreeDiskSpace::doTestStepL()
-   {
+    {
 #ifndef _DEBUG
     INFO_PRINTF1(_L("This test can only be run when the SMS Stack is in debug mode."));
 #else   
@@ -4031,62 +1764,27 @@
         {
         ERR_PRINTF2(_L("RProperty::Delete() failure [err=%d]"), err);
         }           
-#endif  
-   	  	
-	return TestStepResult();
-   }    
+#endif
+    return TestStepResult();
+    }    
 
-/**
-	Free up disk space by deleting the temp files created
-*/
-TVerdict CInitializePhone::doTestStepL()
-   {
-	SetTestNumberL();
-	WaitForInitializeL();
-	
-#ifdef _DEBUG   
-    TInt err = RProperty::Define(KUidPSSMSStackCategory, KUidPSSMSStackFreeDiskSpaceKey, RProperty::EInt);
-    if ((err != KErrNone) && (err != KErrAlreadyExists))    
-        {
-        ERR_PRINTF2(_L("RProperty::Define() failure [err=%d]"), err);
-        User::Leave(err);
-        }
-#endif  	
+CReceiveWapMessage::CReceiveWapMessage()
+    {
+    iPartOfMultiStepTestCase = ETrue;
+    }
 
-	return TestStepResult();
-   }    
-   
-   
-/**
-	Free up disk space by deleting the temp files created
-*/
 TVerdict CReceiveWapMessage::doTestStepL()
-   {
+    {
 #ifndef _DEBUG
     INFO_PRINTF1(_L("This test can only be run when the SMS Stack is in debug mode."));
-#else   
-    
-	//	Connect to socket server
-	RSocketServ socketServer;
-	User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-	//	Define and open the socket
-	RSocket sock;	
-	OpenSocketLC(socketServer, sock);
-	WaitForInitializeL();
-	
-	//Read port and SC number from ini file
-	TWapAddr wapAddr;
-	ReadWapPortSettingsL(wapAddr);
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client"));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-
-	//	Bind
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
+#else
+    TInt  ret = iSocketServer.Connect(KSocketMessageSlots);
+     if (ret != KErrNone)
+         {
+         ERR_PRINTF2(_L("Connecting to socket server failed [ret=%d]"), ret);
+         }
+     
+    SetupWapSocketL();
 
 	TRequestStatus recvStatus;
 	TRequestStatus ioctlStatus;
@@ -4100,12 +1798,11 @@
 	GetStringFromConfig(ConfigSection(),KTestData1, testData);
 	TBuf8<200> data;
 	data.Copy(testData);
-	sock.SendTo(data, wapAddr, 0, status);
+	
+	iSocket.SendTo(data, iWapAddr, 0, status);
 	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Message sent..."));
+	TESTCHECKL(status.Int(), KErrNone, "Sending Message...");
 
-	//	Issue Ioctl for getting the length of the message
 	TBool messageIsExpected;
 	GetBoolFromConfig(ConfigSection(), _L("messageIsExpected"), messageIsExpected);
 
@@ -4113,20 +1810,15 @@
 	TRequestStatus timerStatus;
 	RTimer timer;
 	//Read from the INI file.  
-	TInt timeout;
-	TBool found = GetIntFromConfig(_L("ReceiveTimeout"), _L("timeout"), timeout);
-		//Timeout must be specified
-	if(!found)
-		{
-		timeout=10000000;		// else a default of 10 seconds will be used
-		}
+	TInt timeout = 10000000; // default 10 seconds timeout
+	GetIntFromConfig(_L("ReceiveTimeout"), _L("timeout"), timeout);
 	
 	timer.CreateLocal();
 	timer.After(timerStatus, TTimeIntervalMicroSeconds32(timeout));
 
 	//	Get the size of the first incomming message
 	INFO_PRINTF1(_L("Issue of the IOCTL for GetLength"));
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 
 	//Check if there is in fact a message
 	TBool received=EFalse;
@@ -4135,7 +1827,7 @@
 	if(ioctlStatus == KRequestPending)
 		{
 		// if timer elapsed but ESock request is still pending
-		sock.CancelIoctl();
+		iSocket.CancelIoctl();
 		User::WaitForRequest(ioctlStatus);
 		}
 	else
@@ -4146,6 +1838,7 @@
 		// check ESock error status
 		if(ioctlStatus.Int() == KErrNone)
 			{
+            INFO_PRINTF1(_L("IOCTL for GetLength completed successfully"));
 			received=ETrue;		     
 			}
 		}
@@ -4153,39 +1846,37 @@
 
 	if(received && messageIsExpected)
 		{
-		//	Receiving push datagram
+        INFO_PRINTF1(_L("Receiving push datagram..."));
 		TWapAddr recvWapAddr;			
 		TBuf8<256> recvBuf1(length);
-		sock.RecvFrom(recvBuf1,recvWapAddr,0,recvStatus);
+		iSocket.RecvFrom(recvBuf1,recvWapAddr,0,recvStatus);
 		User::WaitForRequest(recvStatus);
 		User::LeaveIfError(recvStatus.Int());
-		INFO_PRINTF1(_L("Received the push message..."));
 		TEST(recvBuf1.Compare(data) == 0);
 
 		//
 		//	Confirm the receipt of the message to the client
 		//
-		INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-		User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-		
+		TInt ret = iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0);
+		TESTCHECKL(ret, KErrNone, "Setting Socket option for indicating receipt of message" )
 		}
-	else if (received  ||  messageIsExpected)
+	else if (received && !messageIsExpected)
 		{
-		//Message is not expected
-		TEST(EFalse);
+        ERR_PRINTF1(_L("Message is received but not expected"));
+		SetTestStepResult(EFail);
 		}
+	else if (!received && messageIsExpected)
+	    {
+        ERR_PRINTF1(_L("Message is expected but not received"));
+        SetTestStepResult(EFail);
+	    }
 
-    CleanupStack::Pop(&sock);
-    CleanupStack::Pop(&socketServer);
-    sock.Close();
-    socketServer.Close();
-	INFO_PRINTF1(_L("End of ReceiveWapMessage test step"));
+	iSocket.Close();
+	iSocketServer.Close();
 #endif	
-
 	return TestStepResult();
    } 
 
-
 /**
  *  Tests enumerating of a VCard which needs to go via the observer and not returned to the client.
  *
@@ -4193,55 +1884,20 @@
  */
 TVerdict CTestEnumeratingVCard::doTestStepL()
 	{
-	//
-	// Setup the test...
-	//
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, 34));
-
-	//
-	// Connect to socket server
-	//
-	RSocketServ  socketServer;
-
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	// Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
-	//
-	// Define and open the socket to receive the datagram on...
-	//
-	RSocket  sock;
-	TWapAddr  wapAddr;
-	OpenSocketLC(socketServer, sock);
-
-	wapAddr.SetWapPort(TWapPortNumber(226));
-	User::LeaveIfError(sock.Bind(wapAddr));
-
-	//
-	//	Indicate to the protocol that it's a new client
-	//
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-
-	//
 	// Create a socket for the enumeration...
-	//
 	RSocket   enumerateSock;
 	TSmsAddr  smsAddr;
 
-	OpenSocketLC(socketServer, enumerateSock, KSMSAddrFamily,KSMSDatagramProtocol);
- 
+	OpenSocketLC(iSocketServer, enumerateSock, KSMSAddrFamily,KSMSDatagramProtocol);
+
 	smsAddr.SetSmsAddrFamily(ESmsAddrLocalOperation);
 	User::LeaveIfError(enumerateSock.Bind(smsAddr));
 
-	//
 	// Trigger the enumeration...
-	//
-	TPckgBuf<TUint>  messageCount;
+	TPckgBuf<TUint>  messageCount(0);
 	TRequestStatus  enumStatus;
 	
 	User::After(1000000); // Gives SMS Prot and WAP Prot time to initialise after loading!
@@ -4250,47 +1906,35 @@
 	TESTL(enumStatus.Int() == KErrNone);
 	TEST(messageCount() == 0);
 
-	//
 	// Issue an Ioctl for getting the length of the enumerated datagram...
-	//
 	TRequestStatus  ioctlStatus;
 	TPckgBuf<TInt>  length;
 
-	sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+	iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
 	User::WaitForRequest(ioctlStatus);
 	TESTL(ioctlStatus.Int() == KErrNone);
 	TEST(length() == 118);
 
-	//
 	// Receive the VCard...
-	//
 	TRequestStatus  recvStatus;
 	TBuf8<256>  recvBuf;
 	TBuf<256>  vcardBuf16;
 	TWapAddr  recvWapAddr;
 
-	sock.RecvFrom(recvBuf, recvWapAddr, 0, recvStatus);
+	iSocket.RecvFrom(recvBuf, recvWapAddr, 0, recvStatus);
 	User::WaitForRequest(recvStatus);
 	TESTL(recvStatus.Int() == KErrNone);
 	
 	vcardBuf16.Copy(recvBuf);
 	INFO_PRINTF2(_L("Received the VCard: \"%S\""), &vcardBuf16);
 
-	//
 	// Confirm the receipt of the message...
-	//
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
+	User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
 
-	//
-	//	Close all the sockets
-	//
-	CleanupStack::PopAndDestroy(&enumerateSock);
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
+	iSocket.Close();
+    CleanupStack::PopAndDestroy(&enumerateSock);
 	return TestStepResult();
-	} // CTestEnumeratingVCard::doTestStepL
-
+	} 
 
 /**
  *  Sends a 7-bit VCard with an email address in it, to ensure that '@'
@@ -4300,118 +1944,18 @@
  */
 TVerdict CTest7BitBusinessCardWithEmail::doTestStepL()
 	{
-	TPtrC    testData;
-	TPtrC16  telNumber;
-	TInt     port;
-	TInt     testNumber = 35;
-	
-	if(!GetStringFromConfig(ConfigSection(), KTestData1, testData) ||
-	   !GetStringFromConfig(ConfigSection(), KSCNumber, telNumber) ||
-	   !GetIntFromConfig(ConfigSection(), KWapPort, port))
-		{
-		// Leave if there's any error.
-		User::Leave(KErrNotFound);
-		}
-
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, testNumber));
-
-	//
-    //	Setting the port number and service center number of the wap address
-	//	The service center number should be the same as the sim phone number used
-	//  for test (not required for SIM tsy)
-	//
-	TWapAddr  wapAddr;
-	TWapAddr  recvWapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(port));
-
-	TBuf8<100>  scNumber;
-	scNumber.Copy(telNumber);
-	TPtrC8  scAddr(scNumber);
-	wapAddr.SetWapAddress(scAddr);
-
-	//
-	//	Connect to socket server
-	//
-	RSocketServ  socketServer;
-    User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
-
-	//
-	//	Define and open the socket
-	//
-	RSocket  sock;
-    OpenSocketLC(socketServer, sock);
- 
-	//
-	//	Waiting for the phone to be initialised
-	//
-	WaitForInitializeL();
-
-	//
-	//	Indicating to the protocol that it's a new client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating new client..."));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient, KWapSmsOptionLevel, 0));
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
-	//
-	//	Bind to the port...
-	//
-	User::LeaveIfError(sock.Bind(wapAddr));
-
-	//
 	//	Send a business card with the email address.
-	//
-	TRequestStatus  status;
-	
-	TBuf8<200>  data;
-	data.Copy(testData);
-	sock.SendTo(data, wapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Message sent..."));
-
-	//
-	//	Issue Ioctl for getting the length of the message
-	//
-	TPckgBuf<TInt>  length;
-
-	INFO_PRINTF1(_L("Issue of IOCTL for GetLength..."));
-	sock.Ioctl(KSOGetLength, status, &length, KSolWapProv);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
+	TPtrC testData = GetStringFromConfigL(KTestData1);
+	SendWapMessage(testData);
 
-	//
-	//	Check if reported length is correct
-	//
-	TEST(length() == data.Length());
-	
-	//
-	//	Receiving a datagram
-	//
-	TBuf8<256>  recvBuf(length);
-	
-	sock.RecvFrom(recvBuf, recvWapAddr, 0, status);
-	User::WaitForRequest(status);
-	User::LeaveIfError(status.Int());
-	INFO_PRINTF1(_L("Received the message..."));
+	ReceiveWapMessage(testData);
 	
-	//
-	//	Confirm the receipt of the message to the client
-	//
-	INFO_PRINTF1(_L("Socket set option for indicating receipt of message..."));
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-	TEST(recvBuf.Compare(data) == 0);
-	
-	//
-	//	Closing the socket
-	//
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
+	iSocket.Close();
 	return TestStepResult();
-	} // CTest7BitBusinessCardWithEmail::doTestStepL
-
+	}
 
 /**
  *  Attempts to send datagrams bigger than the maximum message and bigger
@@ -4421,78 +1965,37 @@
  */
 TVerdict CTestOversizedDatagram::doTestStepL()
 	{
-	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, ESAPhoneOn));
-	User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory, KPSSimTsyTestNumber, 1));
-
-	TWapAddr wapAddr;
-	wapAddr.SetWapPort(TWapPortNumber(226));
-
-	//
-	// Connect to socket server...
-	//
-	RSocketServ  socketServer;
-
-	User::LeaveIfError(socketServer.Connect());
-	CleanupClosePushL(socketServer);
+    // Configure and bind to a socket
+    SetupWapSocketL();
 
-	//
-	// Define and open the socket...
-	//
-	RSocket  sock;
-    OpenSocketLC(socketServer, sock);
- 
-	//
-	// Wait for the phone to be initialised...
-	//
-	WaitForInitializeL();
-
-	//
-	// Indicating to the protocol that it's a new client...
-	//
-	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-
-	//
 	// Send a datagram of the maximum datagram size (this will fail because
 	// of the WAP headers)...
-	//
 	TRequestStatus  status;
 	
-	HBufC8*  textBuf = HBufC8::NewL(65536+1);
-	CleanupStack::PushL(textBuf);
+	HBufC8*  textBuf = HBufC8::NewLC(65536+1);
 	TPtr8  textPtr = textBuf->Des();
 
 	textPtr.Fill('A', KWAPSMSMaxDatagramSize);
-	sock.SendTo(textPtr, wapAddr, 0, status);
+	iSocket.SendTo(textPtr, iWapAddr, 0, status);
 	User::WaitForRequest(status);
 	TEST(status.Int() == KErrOverflow);
 
-	//
 	// Send a datagram bigger than the maximum datagram...
-	//
 	textPtr.Fill('B', KWAPSMSMaxDatagramSize+1);
-	sock.SendTo(textPtr, wapAddr, 0, status);
+	iSocket.SendTo(textPtr, iWapAddr, 0, status);
 	User::WaitForRequest(status);
 	TEST(status.Int() == KErrTooBig);
 
-	//
 	// Send a datagram bigger than the maximum MBuf...
-	//
 	textPtr.Fill('C', 65536+1);
-	sock.SendTo(textPtr, wapAddr, 0, status);
+	iSocket.SendTo(textPtr, iWapAddr, 0, status);
 	User::WaitForRequest(status);
 	TEST(status.Int() == KErrTooBig);
 
+	iSocket.Close();
 	CleanupStack::PopAndDestroy(textBuf);
-
-	//
-	//	Close the socket...
-	//
-	CleanupStack::PopAndDestroy(&sock);
-    CleanupStack::PopAndDestroy(&socketServer);
-
 	return TestStepResult();
-	} // CTestOversizedDatagram::doTestStepL
-
+	}
 
 TVerdict CTestWapDatagramSegmentContainingNoData::doTestStepL()
 /** 
@@ -4500,237 +2003,162 @@
   *  one or more segments which comprise of a wap header but no data. 
   *  
   *  @return - TVerdict code
-  * 
   */
-     {
-     INFO_PRINTF1(_L("CTestWapDatagramSegmentContainingNoData:"));
- 
-     TVerdict verdict = EPass;
- 
-     // Create an empty string which will encode into a single segment wap message which contains a wap header, but no wap data.
-     _LIT8(KLocalTestData1, "");
-     TBuf8<300> data1(KLocalTestData1);      
-     // Create a VCard which will encode into 2 segment wapdatagram, the 2nd segment contains a wap header, but no wap data.
-     // Use a local literal string rather than reading from a text file. This prevents extra unwanted '\' being added to the string, for example \\r\\n
- 	_LIT8(KLocalTestData2,"BEGIN:VCARD\r\nVERSION:2.1\r\nREV:20090403T094807Z\r\nUID:83702f931a905a6e-00e14456815a8324-33\r\nN:;3SIM;;;\r\nTEL;WORK;CELL:07878931672\r\nEND:VCARD\r");
-      TBuf8<300> data2(KLocalTestData2);
- 
-     
-     TPtrC16 TelNumber;
-     TInt port=9204;
-     TInt testNumber = 36;
-     if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber))
-         {
-         // Leave if there's any error.
-         User::Leave(KErrNotFound);
-         }
-         
-     RProperty phonePowerProperty;
-     User::LeaveIfError(phonePowerProperty.Attach(KUidSystemCategory, KUidPhonePwr.iUid));
-     CleanupClosePushL(phonePowerProperty);
- 
-     RProperty testNumberProperty;
-     User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber));
-     CleanupClosePushL(testNumberProperty);  
- 
-     TRequestStatus status;
-     phonePowerProperty.Subscribe(status);
-     User::LeaveIfError(phonePowerProperty.Set(KUidSystemCategory,KUidPhonePwr.iUid,ESAPhoneOn));
-     User::WaitForRequest(status);
-     User::LeaveIfError(status.Int());
-     
-     testNumberProperty.Subscribe(status);
-     User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNumber));
-     User::WaitForRequest(status);
-     User::LeaveIfError(status.Int());
-     TInt testNumberCheck;
-     User::LeaveIfError(testNumberProperty.Get(testNumberCheck));
-     if (testNumber != testNumberCheck)
-         {
-         User::Leave(KErrNotFound);  
-         }
-     //
-     //  Setting the port number and service center number of the wap address
-     //  The service center number should be the same as the sim phone number used 
-     //  for test (not required for SIM Tsy)
-     //
-     TWapAddr wapAddr;
-     TWapAddr recvWapAddr;
-     wapAddr.SetWapPort(TWapPortNumber(port));
-     TBuf8<100> scNumber;
-     scNumber.Copy(TelNumber);
-     TPtrC8 scAddr(scNumber);
-     wapAddr.SetWapAddress(scAddr);
-     
-     //
-     //  Connect to socket server
-     //
-     RSocketServ socketServer;
-     User::LeaveIfError(socketServer.Connect());
-     CleanupClosePushL(socketServer);
- 
-     //
-     //  Define and open the socket
-     //
-     RSocket sock;
-     OpenSocketLC(socketServer, sock);
-     
+    {
+    INFO_PRINTF1(_L("CTestWapDatagramSegmentContainingNoData:"));
+    // Configure and bind to a socket
+    SetupWapSocketL();
+    
+    TVerdict verdict = EPass;
+
+    // Create an empty string which will encode into a single segment wap message which contains a wap header, but no wap data.
+    _LIT8(KLocalTestData1, "");
+    TBuf8<300> data1(KLocalTestData1);      
+    // Create a VCard which will encode into 2 segment wapdatagram, the 2nd segment contains a wap header, but no wap data.
+    // Use a local literal string rather than reading from a text file. This prevents extra unwanted '\' being added to the string, for example \\r\\n
+    _LIT8(KLocalTestData2,"BEGIN:VCARD\r\nVERSION:2.1\r\nREV:20090403T094807Z\r\nUID:83702f931a905a6e-00e14456815a8324-33\r\nN:;3SIM;;;\r\nTEL;WORK;CELL:07878931672\r\nEND:VCARD\r");
+    TBuf8<300> data2(KLocalTestData2);
+
+
+    TRequestStatus ioctlStatus;
+    TRequestStatus recvStatus;
+    TPckgBuf<TInt> length;
+
+    //
+    //  Issue Ioctl for getting the length of the message
+    //
+    INFO_PRINTF1(_L("Issue of the IOCTL for GetLength for first VCal entry"));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+
+
+    TBuf8<300> data;
+
+    //
+    //  Send a SMS in order to trigger receiving the SMS messages.
+    //  This is to make sure the SMS messages are not received before the 
+    //  wap address is bound to the socket.
+    // 
+    TRequestStatus status;
+    
+    iSocket.SendTo(data1, iWapAddr, 0, status);
+    User::WaitForRequest(status);
+    User::LeaveIfError(status.Int());
+    INFO_PRINTF1(_L("First Message (VCal) sent..."));
 
-     //
-     //  Waiting for the phone to be initialised
-     //
-     WaitForInitializeL();
-     
-     TRequestStatus ioctlStatus;
-     TRequestStatus recvStatus;
-     TPckgBuf<TInt> length;
-     
-     //
-     //  Indicating to the protocol that it's a new client
-     //
-     INFO_PRINTF1(_L("Socket set option for indicating new client"));
-     User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
-     //
-     //  Bind
-     //
-     User::LeaveIfError(sock.Bind(wapAddr));
-     
-     //
-     //  Issue Ioctl for getting the length of the message
-     //
-     INFO_PRINTF1(_L("Issue of the IOCTL for GetLength for first VCal entry"));
-     sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
- 
-     
-     TBuf8<300> data;
-     
-     //
-     //  Send a SMS in order to trigger receiving the SMS messages.
-     //  This is to make sure the SMS messages are not received before the 
-     //  wap address is bound to the socket.
-     //  
-     sock.SendTo(data1, wapAddr, 0, status);
-     User::WaitForRequest(status);
-     User::LeaveIfError(status.Int());
-     INFO_PRINTF1(_L("First Message (VCal) sent..."));
-     
-     //
-     //  Get the size of the first incoming message
-     //  The text string should be empty.
-     //
-     TBuf8<300> recvBuf;    
-     User::WaitForRequest(ioctlStatus);
-     User::LeaveIfError(ioctlStatus.Int());
-     INFO_PRINTF1(_L("IOCTL completed"));
-     //
-     //  Check if reported length is correct
-     //
-     if(length()!=data1.Length())    
-         {
-         verdict = EFail;
-         }
-     //>     //  Receiving a datagram
-     //
-     sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-     User::WaitForRequest(recvStatus);
-     User::LeaveIfError(recvStatus.Int());
-     INFO_PRINTF1(_L("Received the first message (VCal)..."));
-     
-     //  The receive buffer should contain an empty string.
-     //  This is as a consequence of the wapprot receiving
-     //  a single segment wap message which contains no data.
-     if(recvBuf.Compare(data1))
-         {
-         ERR_PRINTF1(_L("Non empty string returned"));
-         verdict = EFail;
-         }       
-     
-     //
-     //  Confirm the receipt of the message to the client
-     //
-     INFO_PRINTF1(_L("Socket set option for indicating receipt of first message (VCal)"));
-     User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-     
-     
-     //Issue Ioctl for getting the length of the second message  
-     INFO_PRINTF1(_L("Issue of the IOCTL for GetLength for second VCard entry"));
-     sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
-     
-     //Get the size of the second incoming message
-     User::WaitForRequest(ioctlStatus);
-     User::LeaveIfError(ioctlStatus.Int());
-     INFO_PRINTF1(_L("IOCTL completed for second message (VCard)"));
-     
-     //Check if reported length is correct
-     if(length()!=data2.Length())
-         {
-         verdict = EFail;
-         }
-         
-     //Receiving a datagram (VCard)
-     sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-     User::WaitForRequest(recvStatus);
-     User::LeaveIfError(recvStatus.Int());
-     INFO_PRINTF1(_L("Received the second message (VCard)..."));
-     
-     //  Compare the received VCard message with the original one.
-     //  They should be identical. This checks that the WAPPROT
-     //  can receive a 2 segment wap datagram, with the 2nd segment containing no data.
-     //
-     if(recvBuf.Compare(data2))
-         {
-         ERR_PRINTF1(_L("VCard message received does not match with original message."));
-         verdict = EFail;
-         }
-         
-     //Confirm the receipt of the message to the client  
-     INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-     User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
-     //Issue Ioctl for getting the length of the third message  
+    //
+    //  Get the size of the first incoming message
+    //  The text string should be empty.
+    //
+    TBuf8<300> recvBuf;    
+    User::WaitForRequest(ioctlStatus);
+    User::LeaveIfError(ioctlStatus.Int());
+    INFO_PRINTF1(_L("IOCTL completed"));
+    
+    //
+    //  Check if reported length is correct
+    //
+    if(length()!=data1.Length())    
+        {
+        verdict = EFail;
+        }
+    
+    //
+    //  Receiving a datagram
+    //
+    TWapAddr recvWapAddr;
+    
+    iSocket.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
+    User::WaitForRequest(recvStatus);
+    User::LeaveIfError(recvStatus.Int());
+    INFO_PRINTF1(_L("Received the first message (VCal)..."));
+
+    //  The receive buffer should contain an empty string.
+    //  This is as a consequence of the wapprot receiving
+    //  a single segment wap message which contains no data.
+    if(recvBuf.Compare(data1))
+        {
+        ERR_PRINTF1(_L("Non empty string returned"));
+        verdict = EFail;
+        }       
 
-     INFO_PRINTF1(_L("Issue of the IOCTL for GetLength for second VCard entry"));
-     sock.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+    //
+    //  Confirm the receipt of the message to the client
+    //
+    INFO_PRINTF1(_L("Socket set option for indicating receipt of first message (VCal)"));
+    User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
+
+
+    //Issue Ioctl for getting the length of the second message  
+    INFO_PRINTF1(_L("Issue of the IOCTL for GetLength for second VCard entry"));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
+
+    //Get the size of the second incoming message
+    User::WaitForRequest(ioctlStatus);
+    User::LeaveIfError(ioctlStatus.Int());
+    INFO_PRINTF1(_L("IOCTL completed for second message (VCard)"));
+
+    //Check if reported length is correct
+    if(length()!=data2.Length())
+        {
+        verdict = EFail;
+        }
+
+    //Receiving a datagram (VCard)
+    iSocket.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
+    User::WaitForRequest(recvStatus);
+    User::LeaveIfError(recvStatus.Int());
+    INFO_PRINTF1(_L("Received the second message (VCard)..."));
+
+    //  Compare the received VCard message with the original one.
+    //  They should be identical. This checks that the WAPPROT
+    //  can receive a 2 segment wap datagram, with the 2nd segment containing no data.
+    //
+    if(recvBuf.Compare(data2))
+        {
+        ERR_PRINTF1(_L("VCard message received does not match with original message."));
+        verdict = EFail;
+        }
+
+    //Confirm the receipt of the message to the client  
+    INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
+    User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
+    //Issue Ioctl for getting the length of the third message  
+
+    INFO_PRINTF1(_L("Issue of the IOCTL for GetLength for second VCard entry"));
+    iSocket.Ioctl(KSOGetLength, ioctlStatus, &length, KSolWapProv);
      
      //Get the size of the third incoming message
-     User::WaitForRequest(ioctlStatus);
-     User::LeaveIfError(ioctlStatus.Int());
-     INFO_PRINTF1(_L("IOCTL completed for third message (VCard)"));
-     
-     //Check if reported length is correct   
-     if(length()!=data1.Length())
-         {
-         verdict = EFail;
-         }
-     
-     //Receiving a datagram (VCard)
-     sock.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
-     User::WaitForRequest(recvStatus);
-     User::LeaveIfError(recvStatus.Int());
-     INFO_PRINTF1(_L("Received the third message (VCard)..."));
+    User::WaitForRequest(ioctlStatus);
+    User::LeaveIfError(ioctlStatus.Int());
+    INFO_PRINTF1(_L("IOCTL completed for third message (VCard)"));
+
+    //Check if reported length is correct   
+    if(length()!=data1.Length())
+        {
+        verdict = EFail;
+        }
      
-     //  The receive buffer should contain an empty string.
-     //  This is as a consequence of the WAPPROT containing 2 concatenated WAP Datagrams
-     //  each datagram segement containing no data.
-      if(recvBuf.Compare(data1))
-         {
-         ERR_PRINTF1(_L("VCard message received does not match with original message."));
-         verdict = EFail;
-         }
-         
-     //Confirm the receipt of the message to the client  
-     INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
-     User::LeaveIfError(sock.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));  
-     //
-     //  Closing the socket
-     //
-     sock.Close();
-     socketServer.Close();
-     CleanupStack::PopAndDestroy(&sock);
-     CleanupStack::Pop(&socketServer);
-     CleanupStack::PopAndDestroy(&testNumberProperty);
-     CleanupStack::PopAndDestroy(&phonePowerProperty);
-     INFO_PRINTF1(_L("End of CTestWapDatagramSegmentContainingNoData"));
-     SetTestStepResult(verdict);
-     return TestStepResult();
-     }
+    //Receiving a datagram (VCard)
+    iSocket.RecvFrom(recvBuf,recvWapAddr,0,recvStatus);
+    User::WaitForRequest(recvStatus);
+    User::LeaveIfError(recvStatus.Int());
+    INFO_PRINTF1(_L("Received the third message (VCard)..."));
 
+    //  The receive buffer should contain an empty string.
+    //  This is as a consequence of the WAPPROT containing 2 concatenated WAP Datagrams
+    //  each datagram segement containing no data.
+    if(recvBuf.Compare(data1))
+        {
+        ERR_PRINTF1(_L("VCard message received does not match with original message."));
+        verdict = EFail;
+        }
+
+    //Confirm the receipt of the message to the client  
+    INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
+    User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));  
+
+    iSocket.Close();
+    SetTestStepResult(verdict);
+    return TestStepResult();
+    }
+