networksecurity/tlsprovider/Test/tlstest2/checkfilesstep.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2008-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 checkfilestep.cpp
       
    18  @internalTechnology
       
    19 */
       
    20 #include "checkfilesstep.h"
       
    21 #include <tlsprovinterface.h>
       
    22 #include "bautils.h" 
       
    23 
       
    24 CCheckFilesStep::CCheckFilesStep()
       
    25 	{
       
    26 	SetTestStepName(KCheckFilesStep);
       
    27 	}
       
    28 	
       
    29 CCheckFilesStep::~CCheckFilesStep()
       
    30 	{
       
    31 	}
       
    32 
       
    33 TVerdict CCheckFilesStep::doTestStepL()
       
    34 	{
       
    35 	// check files presence
       
    36 	RArray<TPtrC> fileNumExist;
       
    37 	RArray<TPtrC> fileNumNonExist;
       
    38 	GetFileNamesForCheck(fileNumExist, fileNumNonExist);
       
    39 
       
    40 	CheckIfFilesExist(ETrue,fileNumExist);
       
    41 	CheckIfFilesExist(EFalse,fileNumNonExist);
       
    42 	return TestStepResult();
       
    43 	}
       
    44 
       
    45 
       
    46 void CCheckFilesStep::CheckIfFilesExist(TBool aCheckExist, const RArray<TPtrC>& aFileArray)
       
    47 	{
       
    48 	TInt nErr =0;
       
    49 	RFs fs;
       
    50 	User::LeaveIfError(fs.Connect());
       
    51 	CleanupClosePushL(fs);
       
    52 	
       
    53 	if(aCheckExist)
       
    54 		{
       
    55 		for(TInt i =0; i< aFileArray.Count(); i++)
       
    56 			{
       
    57 			if(!BaflUtils::FileExists(fs, aFileArray[i]))
       
    58 				{
       
    59 				ERR_PRINTF2(_L("File missing: %S"), &aFileArray[i]);
       
    60 				nErr++;
       
    61 				}
       
    62 			}
       
    63 		}
       
    64 	else
       
    65 		{
       
    66 		for(TInt i =0; i< aFileArray.Count(); i++)
       
    67 			{
       
    68 			if(BaflUtils::FileExists(fs, aFileArray[i]))
       
    69 				{
       
    70 				ERR_PRINTF2(_L("File exists (but shouldn't): %S"), &aFileArray[i]);
       
    71 				nErr++;
       
    72 				}
       
    73 			}
       
    74 		}
       
    75 	if(nErr)
       
    76 		{
       
    77 		SetTestStepResult(EFail);
       
    78 		}
       
    79 	CleanupStack::PopAndDestroy(1);
       
    80 	}
       
    81 
       
    82 
       
    83 void CCheckFilesStep::GetFileNamesForCheck(RArray<TPtrC>& aFileNumExist,RArray<TPtrC>& aFileNumNonExist)
       
    84 	{
       
    85 	_LIT(KNumExist, "numexist"); 
       
    86 	_LIT(KExistBase, "exist"); 
       
    87 	_LIT(KNumNonExist, "numnonexist"); 
       
    88 	_LIT(KNonExistBase, "nonexist"); 
       
    89 
       
    90 	TInt entriesNumExist=0;
       
    91 	TInt entriesNumNonExist=0;
       
    92 	
       
    93 	GetIntFromConfig(ConfigSection(), KNumExist, entriesNumExist);
       
    94 	GetIntFromConfig(ConfigSection(), KNumNonExist, entriesNumNonExist);
       
    95 	ExtractFileName(entriesNumExist, KExistBase, aFileNumExist);
       
    96 	ExtractFileName(entriesNumNonExist, KNonExistBase, aFileNumNonExist);
       
    97 	}
       
    98 		
       
    99 void CCheckFilesStep::ExtractFileName(TInt aEntries, const TDesC& aEntryBase, RArray<TPtrC>& aFileArray)
       
   100 	{
       
   101 	TPtrC fname;
       
   102 	const TInt KKeyBufSize =64;
       
   103 	
       
   104 	for(TInt i=0; i<aEntries; i++)
       
   105 		{
       
   106 		//construct name of the key
       
   107 		TBuf<KKeyBufSize> keyBuf(aEntryBase);
       
   108 		keyBuf.AppendNum(i);
       
   109 		
       
   110 		if(GetStringFromConfig(ConfigSection(),keyBuf,fname))
       
   111 			{
       
   112 			aFileArray.Insert(fname, i);
       
   113 			}
       
   114 		}
       
   115 	}