os/kernelhwsrv/kerneltest/f32test/cfileman/t_cfileman_aux.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/cfileman/t_cfileman_aux.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,398 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32test\cfileman\t_cfileman_aux.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "t_cfileman_aux.h"
    1.22 +
    1.23 +CFileMan* gFileMan = NULL;
    1.24 +RPointerArray<RFile>* gFileHandles = NULL;
    1.25 +TBool gAsynch = EFalse;
    1.26 +TRequestStatus gStat;
    1.27 +TBool testingInvalidPathLengths;
    1.28 +
    1.29 +void InitialiseL()
    1.30 +	{
    1.31 +	gFileMan=CFileMan::NewL(TheFs);
    1.32 +	}
    1.33 +
    1.34 +void RmDir(const TDesC& aDirName)
    1.35 +	{
    1.36 +	TFileName filename_dir = aDirName;
    1.37 +	TInt r = 0;
    1.38 +	r = TheFs.SetAtt(filename_dir, 0, KEntryAttReadOnly);
    1.39 +	r=gFileMan->RmDir(filename_dir);
    1.40 +	test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
    1.41 +	}
    1.42 +
    1.43 +// Cleanup test variables
    1.44 +void Cleanup()
    1.45 +	{
    1.46 +	delete gFileMan;
    1.47 +	}
    1.48 +
    1.49 +//Test that the contents of two directories are identical
    1.50 +TBool CompareL(const TDesC& aDir1,const TDesC& aDir2)
    1.51 +	{
    1.52 +	TBool rel = ETrue;
    1.53 +	CDirScan* scanDir1=CDirScan::NewL(TheFs);
    1.54 +	scanDir1->SetScanDataL(aDir1,KEntryAttMaskSupported,ESortByName);
    1.55 +	CDirScan* scanDir2=CDirScan::NewL(TheFs);
    1.56 +	scanDir2->SetScanDataL(aDir2,KEntryAttMaskSupported,ESortByName);
    1.57 +
    1.58 +	FOREVER
    1.59 +		{
    1.60 +		CDir* entryList1;
    1.61 +		CDir* entryList2;
    1.62 +
    1.63 +		scanDir1->NextL(entryList1);
    1.64 +		scanDir2->NextL(entryList2);
    1.65 +
    1.66 +		if (entryList1==NULL || entryList2==NULL)
    1.67 +			{
    1.68 +			if (!(entryList1==NULL && entryList2==NULL))
    1.69 +				{
    1.70 +				delete entryList1, 
    1.71 +				delete entryList2, 
    1.72 +				delete scanDir1, 
    1.73 +				delete scanDir2;
    1.74 +				return(EFalse);
    1.75 +				}
    1.76 +			break;
    1.77 +			}
    1.78 +
    1.79 +		TFileName abbPath1=scanDir1->AbbreviatedPath();
    1.80 +		TFileName abbPath2=scanDir2->AbbreviatedPath();
    1.81 +		if (!(abbPath1==abbPath2))
    1.82 +			{
    1.83 +			delete entryList1, 
    1.84 +			delete entryList2, 
    1.85 +			delete scanDir1, 
    1.86 +			delete scanDir2;
    1.87 +			return(EFalse);
    1.88 +			}
    1.89 +
    1.90 +		TInt count1=entryList1->Count();
    1.91 +		TInt count2=entryList2->Count();
    1.92 +		if (!(count1==count2))
    1.93 +			{
    1.94 +			delete entryList1, 
    1.95 +			delete entryList2, 
    1.96 +			delete scanDir1, 
    1.97 +			delete scanDir2;
    1.98 +			return(EFalse);
    1.99 +			}
   1.100 +
   1.101 +		while(count1--)
   1.102 +			{
   1.103 +			TEntry entry1=(*entryList1)[count1];
   1.104 +			TEntry entry2=(*entryList2)[count1];
   1.105 +			if (!(entry1.iName==entry2.iName))
   1.106 +				{
   1.107 +				delete entryList1, 
   1.108 +				delete entryList2, 
   1.109 +				delete scanDir1, 
   1.110 +				delete scanDir2;
   1.111 +				return(EFalse);
   1.112 +				}
   1.113 +			if (!(entry1.iAtt==entry2.iAtt))
   1.114 +				{
   1.115 +				delete entryList1, 
   1.116 +				delete entryList2, 
   1.117 +				delete scanDir1, 
   1.118 +				delete scanDir2;
   1.119 +				return(EFalse);
   1.120 +				}
   1.121 +
   1.122 +			}
   1.123 +
   1.124 +		delete entryList1;
   1.125 +		delete entryList2;
   1.126 +		}
   1.127 +
   1.128 +	delete scanDir1;
   1.129 +	delete scanDir2;
   1.130 +	
   1.131 +	return rel;
   1.132 +	}
   1.133 +
   1.134 +/**
   1.135 +    Parsing Dir Data Block
   1.136 +    @param  aDataBlock		data block in TInt[] for parsing	
   1.137 +    @param  aDirDataArray	returning dir data array after parsing
   1.138 +
   1.139 +    @panic 					if data setup error
   1.140 +
   1.141 +*/
   1.142 +void ParsingDirDataBlock(const TInt aDataBlock[], RArray<TInt>& aDirDataArray)
   1.143 +	{
   1.144 +	TInt err = KErrNone;
   1.145 +	aDirDataArray.Reset();
   1.146 +
   1.147 +	if (aDataBlock[0] == EOB)
   1.148 +		{
   1.149 +		return;
   1.150 +		}
   1.151 +
   1.152 +	TInt i = 1;
   1.153 +	FOREVER
   1.154 +		{
   1.155 +		TInt lastItem = aDataBlock[i-1];
   1.156 +		TInt currentItem = aDataBlock[i];
   1.157 +		
   1.158 +		// check currentItem
   1.159 +		if (currentItem == EOB)
   1.160 +			{
   1.161 +			if (lastItem == CON || lastItem > LAST)
   1.162 +			//check last
   1.163 +				{
   1.164 +				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.165 +				test(EFalse);
   1.166 +				}
   1.167 +			else
   1.168 +			// passed, insert last, break
   1.169 +				{
   1.170 +				err = aDirDataArray.InsertInOrder(lastItem);
   1.171 +				if (err != KErrNone && err != KErrAlreadyExists)
   1.172 +					{
   1.173 +					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.174 +					test(EFalse);
   1.175 +					}
   1.176 +				break;
   1.177 +				}
   1.178 +			}
   1.179 +		
   1.180 +		else if (currentItem == CON)
   1.181 +		// if current == CON
   1.182 +			{
   1.183 +			if (lastItem == CON || lastItem >= LAST)
   1.184 +			// check last item
   1.185 +				{
   1.186 +				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.187 +				test(EFalse);
   1.188 +				}
   1.189 +			else // last < LAST, last != CON
   1.190 +				{
   1.191 +				// check next item
   1.192 +				TInt nextItem = aDataBlock[i+1];
   1.193 +				if (nextItem <= 0 || nextItem > LAST || lastItem >= nextItem)
   1.194 +					{
   1.195 +					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.196 +					test(EFalse);
   1.197 +					}
   1.198 +				else
   1.199 +					{
   1.200 +					// all valid
   1.201 +					for (TInt j = lastItem; j < nextItem; j++)
   1.202 +						{
   1.203 +						err = aDirDataArray.InsertInOrder(j);
   1.204 +						if (err != KErrNone && err != KErrAlreadyExists)
   1.205 +							{
   1.206 +							test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.207 +							test(EFalse);
   1.208 +							}
   1.209 +						}
   1.210 +					}
   1.211 +				}
   1.212 +			i++;
   1.213 +			}
   1.214 +
   1.215 +		else if (0 <= currentItem && currentItem <= LAST)
   1.216 +		// if current == normal item
   1.217 +			{
   1.218 +			if (lastItem == CON)
   1.219 +				{
   1.220 +				i++;
   1.221 +				continue;
   1.222 +				}
   1.223 +			else if (lastItem >= LAST)
   1.224 +			// check last item
   1.225 +				{
   1.226 +				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.227 +				test(EFalse);
   1.228 +				}
   1.229 +			else
   1.230 +			// passed, insert last
   1.231 +				{
   1.232 +				err = aDirDataArray.InsertInOrder(lastItem);
   1.233 +				if (err != KErrNone && err != KErrAlreadyExists)
   1.234 +					{
   1.235 +					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.236 +					test(EFalse);
   1.237 +					}
   1.238 +				}
   1.239 +			i++;
   1.240 +			}
   1.241 +		
   1.242 +		else	// invalid input
   1.243 +			{
   1.244 +			test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.245 +			test(EFalse);
   1.246 +			}
   1.247 +		}
   1.248 +	}
   1.249 +
   1.250 +	
   1.251 +/**
   1.252 +	Setup attribs:
   1.253 +	@param  filenamedir   		root path of dir data or a file data
   1.254 +	@param  mode			    value of an mode to be set(Normal/Open/Shared..)
   1.255 +*/
   1.256 +void OpenFile(TDesC& aFile, TFileMode aFileMode)
   1.257 +	{
   1.258 +	RFile* file = new (ELeave) RFile;
   1.259 +	gFileHandles->Append(file);
   1.260 +	TInt ret = 0;
   1.261 +	ret = file->Open(TheFs, aFile, aFileMode);
   1.262 +	test(ret==KErrNone);
   1.263 +	}
   1.264 +	
   1.265 +
   1.266 +/**
   1.267 +    Setup dir structure for testing and verifying functional results
   1.268 +    @param	datastr			data structure to setup directory
   1.269 +    @param  iOperation   	Operation to be performed 
   1.270 +    @param  SrcDrive		Source drive
   1.271 +    @param	Targetdrive		Target drive input
   1.272 +    @panic					if data structure definition is incorrect
   1.273 +*/
   1.274 +void SetupDirFiles(const TDesC& aPath, const TDirSetupFiles& aDirFiles)
   1.275 +	{
   1.276 +	TFileName path = aPath;
   1.277 +	if (path.Length() == 0)
   1.278 +		{
   1.279 +		test.Printf(_L("ERROR<SetupDirFiles()>: Zero length src path!\n"));
   1.280 +		test(EFalse);
   1.281 +		}
   1.282 +	
   1.283 +	RmDir(path);
   1.284 +	MakeDir(path);
   1.285 +
   1.286 +	RArray<TInt> addBlockDataArray;
   1.287 +	RArray<TInt> deductBlockDataArray;
   1.288 +	
   1.289 +	ParsingDirDataBlock(aDirFiles.iAddingBlock, addBlockDataArray);
   1.290 +	ParsingDirDataBlock(aDirFiles.iDeductBlock, deductBlockDataArray);
   1.291 +	
   1.292 +	if (addBlockDataArray.Count() == 0)
   1.293 +	// empty dir setup
   1.294 +		{
   1.295 +		return;
   1.296 +		}
   1.297 +	else
   1.298 +		{
   1.299 +		for (TInt i = 0; i < deductBlockDataArray.Count(); ++i)
   1.300 +			{
   1.301 +			TInt idxToDelete = addBlockDataArray.FindInOrder(deductBlockDataArray[i]);
   1.302 +			if (idxToDelete >= 0)
   1.303 +				{
   1.304 +				addBlockDataArray.Remove(idxToDelete);
   1.305 +				}
   1.306 +			else if (idxToDelete == KErrNotFound)
   1.307 +				{
   1.308 +				continue;
   1.309 +				}
   1.310 +			else
   1.311 +				{
   1.312 +				test.Printf(_L("ERROR<<SetupDir>>: wrong dir data setup! err=%d\n"), idxToDelete);
   1.313 +				test(EFalse);
   1.314 +				}
   1.315 +			}
   1.316 +		}
   1.317 +
   1.318 +	if (addBlockDataArray.Count() > 0)
   1.319 +		{
   1.320 +		for (TInt i = 0; i < addBlockDataArray.Count(); ++i)
   1.321 +			{
   1.322 +			TInt idx = addBlockDataArray[i];
   1.323 +			path = aPath;
   1.324 +			path += gDirPatterns[idx];
   1.325 +			if (path[path.Length() - 1] == '\\')
   1.326 +				{
   1.327 +				MakeDir(path);
   1.328 +				}
   1.329 +			else
   1.330 +				{
   1.331 +				MakeFile(path, _L8("blahblah"));
   1.332 +
   1.333 +				}
   1.334 +			}
   1.335 +		}
   1.336 +
   1.337 +	addBlockDataArray.Reset();
   1.338 +	deductBlockDataArray.Reset();
   1.339 +	}
   1.340 +
   1.341 +/**
   1.342 +    Print out all items in aPath
   1.343 +    @param  aPath 		root path for scanning
   1.344 +
   1.345 +    @panic				SetScanData error
   1.346 +*/
   1.347 +void PrintDir(const TDesC& aPath, const TChar& aDrv)
   1.348 +	{
   1.349 +	TFileName fn;
   1.350 +	if (aPath.Length() == 0)
   1.351 +		{
   1.352 +		return;
   1.353 +		}
   1.354 +	else
   1.355 +		{
   1.356 +		fn = aPath;
   1.357 +		fn[0] = (TUint16)aDrv;
   1.358 +		test.Printf(_L("==============================\n"));
   1.359 +		test.Printf(_L("<<PrintDir>>: root = \"%S\"\n"), &fn);
   1.360 +		}
   1.361 +
   1.362 +	CDirScan* scan = CDirScan::NewL(TheFs);
   1.363 +	TUint entryAttMask = KEntryAttMaskSupported;
   1.364 +	TUint entrySortMask = EDirsLast|EAscending;
   1.365 +	CDirScan::TScanDirection scanDirection = CDirScan::EScanDownTree;
   1.366 +
   1.367 +
   1.368 +	TRAPD(err, scan->SetScanDataL(fn, entryAttMask, entrySortMask, scanDirection));
   1.369 +	test(err == KErrNone);
   1.370 +
   1.371 +	CDir* dir = NULL;
   1.372 +	TInt i = 0;
   1.373 +	TBool temp_val = ETrue;
   1.374 +	while (temp_val)
   1.375 +		{
   1.376 +		scan->NextL(dir);
   1.377 +		if (dir != NULL)
   1.378 +			{
   1.379 +			for (TInt j = 0; j < dir->Count(); ++j)
   1.380 +				{
   1.381 +				TFileName item(fn.Left(aPath.Length() - 1));
   1.382 +				item.Append(scan->AbbreviatedPath());
   1.383 +				TEntry dummy = (*dir)[j];
   1.384 +				item.Append(dummy.iName);
   1.385 +				if (dummy.iAtt & KEntryAttDir)
   1.386 +					{
   1.387 +					item.Append('\\');
   1.388 +					}
   1.389 +				test.Printf(_L("<<PrintDir>>: item %d: \"%S\"\n"), i, &item);
   1.390 +				++i;
   1.391 +				}
   1.392 +			delete dir;
   1.393 +			dir = NULL;
   1.394 +			}
   1.395 +		else
   1.396 +			{
   1.397 +			break;
   1.398 +			}
   1.399 +		}
   1.400 +	delete scan;
   1.401 +	}