datacommsserver/esockserver/test/TE_EsockTestSteps/src/Te_EsockStepBase.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file Te_EsockStepBase.cpp
       
    18 */
       
    19 
       
    20 #include "Te_EsockStepBase.h"
       
    21 
       
    22 TVerdict CTe_EsockStepBase::doTestStepPreambleL()
       
    23 /**
       
    24  * This is a default implementation of doTestStepPreambleL()
       
    25  * for all test steps. It checks whether the instance of esock
       
    26  * test has been initialised.
       
    27  */
       
    28 	{
       
    29 	SetTestStepResult(EPass);
       
    30 	if (iEsockTest==NULL)
       
    31         {
       
    32         INFO_PRINTF1(_L("Esock test not instantiated!!. Aborting!"));
       
    33         SetTestStepResult(EFail);
       
    34         }
       
    35     
       
    36 	return TestStepResult();
       
    37 	}
       
    38 
       
    39 TVerdict CTe_EsockStepBase::doTestStepL()
       
    40 /**
       
    41  * Runs the test step (in the derived class), firstly by configuring from the given ini file
       
    42  */
       
    43 	{
       
    44 	SetTestStepResult(EPass);
       
    45 
       
    46 	// Configure the test step according to the ini file section
       
    47 	iSection.Copy(ConfigSection());
       
    48 	TInt configuredOk = ConfigureFromIni();
       
    49 	
       
    50 	// If we configured ok then run the test step otherwise we failed
       
    51 	if (configuredOk == KErrNone)
       
    52 		{
       
    53 		TVerdict result = doSingleTestStep();
       
    54 		SetTestStepResult(result);
       
    55 		}
       
    56 	else
       
    57 		{
       
    58 		INFO_PRINTF1(_L("Test step does not have a valid configuration."));
       
    59 		SetTestStepResult(EFail);
       
    60 		}
       
    61 	
       
    62 	return TestStepResult();
       
    63 	}
       
    64 
       
    65 
       
    66 TInt CTe_EsockStepBase::GetCurrentIdx()
       
    67 /**
       
    68  * Returns index of the current single step
       
    69  */
       
    70     {
       
    71     return iIdx;
       
    72     }
       
    73 
       
    74 CTe_EsockStepBase::~CTe_EsockStepBase()
       
    75 /**
       
    76  * Destructor
       
    77  */
       
    78 	{
       
    79 	}
       
    80 
       
    81 CTe_EsockStepBase::CTe_EsockStepBase(CCEsockTestBase*& aEsockTest)
       
    82 :   iEsockTest(aEsockTest), iFoundUniqueSection(EFalse)
       
    83 /**
       
    84  * Constructor
       
    85  */
       
    86 	{
       
    87 	}
       
    88 
       
    89 
       
    90 TBool CTe_EsockStepBase::GetIpAddressFromConfig(const TDesC &aSectName,const TDesC &aKeyName,TInetAddr &anAddr)
       
    91 /* Get the IP address from the configuration file
       
    92  *
       
    93  * get string from config file
       
    94  * convert the string to a TInetAddr
       
    95  */
       
    96 	{
       
    97 	TPtrC result;
       
    98 
       
    99 	TBool bRet = GetStringFromConfig(aSectName, aKeyName, result);
       
   100 
       
   101 	// if True
       
   102 	if (bRet)
       
   103 		{
       
   104 		TInt nRet = anAddr.Input(result);
       
   105 		// Invalid IP Address
       
   106 		if (nRet!=KErrNone)
       
   107 			{
       
   108 			INFO_PRINTF3(_L("Invalid IP address, section:%S key:%S "),&aSectName, &aKeyName);
       
   109 			bRet = EFalse;
       
   110 			}
       
   111 		}
       
   112 
       
   113 	return bRet;
       
   114 	}
       
   115 
       
   116 // Method to Copy a file to another file. 
       
   117 void CTe_EsockStepBase::CopyFileL (const TDesC& aOld,const TDesC& aNew) 
       
   118 	{
       
   119 	// create a fileserver
       
   120 	RFs fileSystem;
       
   121 
       
   122 	// connect to file server
       
   123 	TInt returnCode = fileSystem.Connect();
       
   124 	User::LeaveIfError(returnCode);
       
   125 	CleanupClosePushL(fileSystem);
       
   126 
       
   127 	// create a file manager
       
   128 	CFileMan * fileMan = CFileMan::NewL(fileSystem);
       
   129 	CleanupStack::PushL(fileMan);
       
   130 
       
   131 	// parse the filenames
       
   132 	TParse source;
       
   133 	returnCode = source.Set(aOld, NULL, NULL);
       
   134 	User::LeaveIfError(returnCode);
       
   135  
       
   136 	// parse the filenames
       
   137 	TParse target;
       
   138 	returnCode = target.Set(aNew, NULL, NULL);
       
   139 	User::LeaveIfError(returnCode);
       
   140 
       
   141     TPtrC path(target.DriveAndPath());
       
   142     INFO_PRINTF2(_L("Ensuring path %S exists"), &path);
       
   143 	returnCode = fileSystem.MkDirAll(target.DriveAndPath());
       
   144 	if (returnCode == KErrAlreadyExists)
       
   145 	    {
       
   146 	    returnCode = KErrNone;	    
       
   147 	    }
       
   148 	User::LeaveIfError(returnCode);
       
   149 	
       
   150 	// do the copy
       
   151 	returnCode = fileMan->Attribs(target.FullName(), 0, KEntryAttReadOnly, 0);
       
   152 	INFO_PRINTF2(_L("Attribs returned with %d"), returnCode);
       
   153 
       
   154 	returnCode = fileMan->Copy(source.FullName(), 
       
   155 		target.FullName(), CFileMan::EOverWrite);
       
   156 
       
   157 	if (returnCode != KErrNone)
       
   158 		{
       
   159         INFO_PRINTF2(_L("Copy failed with %d"), returnCode);
       
   160 		User::Leave(returnCode);
       
   161 		}
       
   162 	
       
   163 
       
   164 	CleanupStack::PopAndDestroy(fileMan);
       
   165 	CleanupStack::PopAndDestroy();
       
   166 	}
       
   167 
       
   168 void CTe_EsockStepBase::DeleteFileL (const TDesC& aFileName)
       
   169 	{
       
   170 	// create a fileserver
       
   171 	RFs fileSystem;
       
   172 
       
   173 	// connect to file server
       
   174 	TInt returnCode = fileSystem.Connect();
       
   175 	User::LeaveIfError(returnCode);
       
   176 	CleanupClosePushL(fileSystem);
       
   177 
       
   178 	// create a file manager
       
   179 	CFileMan * fileMan = CFileMan::NewL(fileSystem);
       
   180 	CleanupStack::PushL(fileMan);
       
   181 
       
   182 	// parse the filenames
       
   183 	TParse source;
       
   184 	returnCode = source.Set(aFileName, NULL, NULL);
       
   185 	User::LeaveIfError(returnCode);
       
   186  
       
   187 	// do the delete
       
   188 	returnCode = fileMan->Attribs(source.FullName(), 0, KEntryAttReadOnly, 0);
       
   189 	INFO_PRINTF2(_L("Attribs returned with %d"), returnCode);
       
   190 	
       
   191 	returnCode = fileMan->Delete(source.FullName()); 
       
   192 	if (returnCode != KErrNone && returnCode != KErrNotFound)
       
   193 		{
       
   194         INFO_PRINTF2(_L("Delete file %S failed"), &source.FullName());
       
   195 		User::Leave(returnCode);
       
   196 		}
       
   197 	if (returnCode == KErrNotFound)
       
   198 	    {
       
   199         INFO_PRINTF1(_L("File to delete not present"));
       
   200 	    }
       
   201 
       
   202 	CleanupStack::PopAndDestroy(fileMan);
       
   203 	CleanupStack::PopAndDestroy();
       
   204 	}
       
   205 
       
   206