smsprotocols/smsstack/wapprot/test/Te_wapprot/WapIoctlSteps.cpp
changeset 69 b982c3e940f3
parent 20 244d7c5f118e
equal deleted inserted replaced
59:ac20d6a0a19d 69:b982c3e940f3
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   662 	//
   662 	//
   663 	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
   663 	INFO_PRINTF1(_L("Socket set option for indicating receipt of message"));
   664 	User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
   664 	User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0));
   665 
   665 
   666 	iSocket.Close();
   666 	iSocket.Close();
   667 	return TestStepResult();
       
   668 	}
       
   669 
       
   670 TInt CBackupRestoreStep::SendWapL()
       
   671 	{
       
   672 	//modified from test 10
       
   673 	INFO_PRINTF1(_L("SendWapL: send 7-Bit business card using IOCTL"));
       
   674 
       
   675 	TInt ret = KErrNone;
       
   676 
       
   677 	TPtrC16 TelNumber;
       
   678 	TInt port=226;
       
   679 
       
   680 	if(!GetStringFromConfig(ConfigSection(),KSCNumber,TelNumber) ||
       
   681 	   !GetIntFromConfig(ConfigSection(),KWapPort,port)
       
   682 		)
       
   683 		{
       
   684 		// Leave if there's any error.
       
   685 		User::Leave(KErrNotFound);
       
   686 		}
       
   687 	
       
   688 	//
       
   689 	//	Setting the port number and service center number of the wap address
       
   690 	//	The service center number should be the same as the sim phone number used
       
   691 	//  for test (not required for SIM tsy)
       
   692 	//
       
   693 	TWapAddr wapAddr;
       
   694 	wapAddr.SetWapPort(TWapPortNumber(port));
       
   695 
       
   696 	TBuf8<100> scNumber;
       
   697 	scNumber.Copy(TelNumber);
       
   698 	TPtrC8 scAddr(scNumber);
       
   699 	wapAddr.SetWapAddress(scAddr);
       
   700 
       
   701 	//
       
   702 	//	Define and open the socket
       
   703 	//
       
   704 	RSocket sock;
       
   705 	ret = sock.Open(iSocketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol);
       
   706 	if (ret != KErrNone)
       
   707 		{
       
   708 		//
       
   709 		// PREQ399 changes mean that -1 is sometimes now returned from Open() when
       
   710 		// a Backup and Restore session is in progress (DEF114381).
       
   711 		//
       
   712 		INFO_PRINTF2(_L("Socket could not be opened (error %d)..."), ret);
       
   713 
       
   714 		return ret;
       
   715 		}
       
   716 	CleanupClosePushL(sock);
       
   717 
       
   718 	TRequestStatus status;
       
   719 
       
   720 	//
       
   721 	//	Indicating to the protocol that it's a new client
       
   722 	//
       
   723 	INFO_PRINTF1(_L("Socket set option for indicating new client"));
       
   724 	User::LeaveIfError(sock.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0));
       
   725 	//
       
   726 	//	Bind
       
   727 	//
       
   728 	User::LeaveIfError(sock.Bind(wapAddr));
       
   729 	
       
   730     TTimeIntervalMicroSeconds32 InitPause=9000000;  //Pause to Allow SMSStack to Complete its Async Init
       
   731     User::After(InitPause);                         //call to the TSY and finish its StartUp.
       
   732 
       
   733 	//
       
   734 	//	Send a calendar entry
       
   735 	//
       
   736     TPtrC testData = GetStringFromConfigL(KTestData1);
       
   737 	TBuf8<200> data;
       
   738 	data.Copy(testData);
       
   739 	sock.SendTo(data, wapAddr, 0, status);
       
   740 	User::WaitForRequest(status);
       
   741 	ret = status.Int();
       
   742 
       
   743 	if(ret == KErrNone)
       
   744 		{
       
   745 		INFO_PRINTF1(_L("Message sent..."));
       
   746 		}
       
   747 	else
       
   748 		{
       
   749 		INFO_PRINTF2(_L("Message NOT sent (error %d)..."), ret);
       
   750 		}
       
   751 
       
   752 	CleanupStack::PopAndDestroy(&sock);
       
   753 	return ret;
       
   754 	}
       
   755 
       
   756 TBool CBackupRestoreStep::IsWapFileOpenL()
       
   757 	{
       
   758 	TBool ret = ETrue; //assume the file was open
       
   759 	RFs fsSession;
       
   760 	User::LeaveIfError(fsSession.Connect());
       
   761 	CleanupClosePushL(fsSession);
       
   762 
       
   763 	CFileMan*  fileManager = CFileMan::NewL(fsSession);
       
   764 	CleanupStack::PushL(fileManager);
       
   765 
       
   766 	_LIT(KWapFile,"C:\\Private\\101F7989\\sms\\wapreast.dat");
       
   767 	_LIT(KWapFileBackup,"C:\\Private\\101f7989\\sms\\wapreast.backup");
       
   768 
       
   769 	TEntry entry;
       
   770 	if (fsSession.Entry(KWapFile,entry)==KErrNone)  //  File found
       
   771 		{
       
   772 		TInt moveStatus = fileManager->Move(KWapFile,KWapFileBackup);
       
   773 		TESTL(moveStatus == KErrNone || moveStatus == KErrInUse);
       
   774 
       
   775 		// If the move was successful, the file is not opened
       
   776 		// If the move failed with KErrInUse the file is opened
       
   777 		if (moveStatus == KErrNone)
       
   778 			{
       
   779 			// move it back
       
   780 			TEST(fileManager->Move(KWapFileBackup,KWapFile) == KErrNone);
       
   781 			ret = EFalse;
       
   782 			}
       
   783 		else // moveStatus == KErrInUse
       
   784 			{
       
   785 			ret = ETrue;
       
   786 			}
       
   787 		}
       
   788 	else
       
   789 		{
       
   790 		//file not found so it couldn't be open
       
   791 		ret = EFalse;
       
   792 		}
       
   793 
       
   794 	CleanupStack::PopAndDestroy(fileManager);
       
   795 	CleanupStack::PopAndDestroy(&fsSession);
       
   796 
       
   797 	if(ret)
       
   798 		INFO_PRINTF1(_L("Wapfile open..."));
       
   799 	else
       
   800 		INFO_PRINTF1(_L("Wapfile closed..."));
       
   801 
       
   802 	return ret;
       
   803 	}
       
   804 
       
   805 TVerdict CBackupRestoreStep::doTestStepL()
       
   806 /**
       
   807  *  Test step 16:
       
   808  *  simulating backup and restore
       
   809  *  @return - TVerdict code
       
   810  */
       
   811 	{
       
   812     INFO_PRINTF1(_L("IOCTL Test step 16: send 7-Bit business card using IOCTL to test backup and restore"));
       
   813     CSBEClient*  secureBackupEngine = CSBEClient::NewL();
       
   814     CleanupStack::PushL(secureBackupEngine);
       
   815     secureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
       
   816                                      EBURNormal, ENoBackup);
       
   817 
       
   818 	INFO_PRINTF1(_L("Expecting SendWapL to succeed and the wap data file to be open"));
       
   819 	TEST(SendWapL() == KErrNone);
       
   820 	TEST(IsWapFileOpenL() != EFalse);
       
   821 
       
   822 	// Notify the WAPPROT server that a backup is about to take place and
       
   823 	// that the server should close the wapstor
       
   824 	INFO_PRINTF1(_L("Simulating a backup notification"));
       
   825 	secureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
       
   826 									 EBURBackupFull, EBackupBase);
       
   827 
       
   828 	INFO_PRINTF1(_L("Expecting SendWapL to fail and the wap data file to be closed"));
       
   829 	TEST(SendWapL() != KErrNone);
       
   830 	TEST(IsWapFileOpenL() == EFalse);
       
   831 
       
   832 	// Notify the WAPPROT server that a backup has completed
       
   833 	// that the server should open the wapstor
       
   834 	INFO_PRINTF1(_L("Simulating a backup complete notification"));
       
   835 	secureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
       
   836 									 EBURNormal, ENoBackup);
       
   837 
       
   838 	INFO_PRINTF1(_L("Expecting SendWapL to succeed and the wap data file to be open"));
       
   839 	TEST(SendWapL() == KErrNone);
       
   840 	TEST(IsWapFileOpenL() != EFalse);
       
   841 
       
   842 	// Notify the WAPPROT server that a restore is about to take place and
       
   843 	// that the server should close the wapstor
       
   844 	INFO_PRINTF1(_L("Simulating a restore notification"));
       
   845 	secureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
       
   846 									 EBURRestorePartial, EBackupIncrement);
       
   847 
       
   848 	INFO_PRINTF1(_L("Expecting SendWapL to fail and the wap data file to be closed"));
       
   849 	TEST(SendWapL() != KErrNone);
       
   850 	TEST(IsWapFileOpenL() == EFalse);
       
   851 
       
   852 	// Notify the WAPPROT server that a restore has completed
       
   853 	// that the server should open the wapstor
       
   854 	INFO_PRINTF1(_L("Simulating a restore complete notification"));
       
   855 	secureBackupEngine->SetBURModeL(TDriveList(_L8("C")),
       
   856 									 EBURNormal, ENoBackup);
       
   857 
       
   858 	INFO_PRINTF1(_L("Expecting SendWapL to succeed and the wap data file to be open"));
       
   859 	TEST(SendWapL() == KErrNone);
       
   860 	TEST(IsWapFileOpenL() != EFalse);
       
   861 	
       
   862     CleanupStack::PopAndDestroy(secureBackupEngine); // testNumberProperty, secureBackupEngine
       
   863 	return TestStepResult();
   667 	return TestStepResult();
   864 	}
   668 	}
   865 	
   669 	
   866 TVerdict CIoctlStep_17::doTestStepL()
   670 TVerdict CIoctlStep_17::doTestStepL()
   867 /**
   671 /**