os/kernelhwsrv/kerneltest/f32test/cfileman/t_cfileman_aux.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// f32test\cfileman\t_cfileman_aux.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "t_cfileman_aux.h"
sl@0
    19
sl@0
    20
CFileMan* gFileMan = NULL;
sl@0
    21
RPointerArray<RFile>* gFileHandles = NULL;
sl@0
    22
TBool gAsynch = EFalse;
sl@0
    23
TRequestStatus gStat;
sl@0
    24
TBool testingInvalidPathLengths;
sl@0
    25
sl@0
    26
void InitialiseL()
sl@0
    27
	{
sl@0
    28
	gFileMan=CFileMan::NewL(TheFs);
sl@0
    29
	}
sl@0
    30
sl@0
    31
void RmDir(const TDesC& aDirName)
sl@0
    32
	{
sl@0
    33
	TFileName filename_dir = aDirName;
sl@0
    34
	TInt r = 0;
sl@0
    35
	r = TheFs.SetAtt(filename_dir, 0, KEntryAttReadOnly);
sl@0
    36
	r=gFileMan->RmDir(filename_dir);
sl@0
    37
	test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
sl@0
    38
	}
sl@0
    39
sl@0
    40
// Cleanup test variables
sl@0
    41
void Cleanup()
sl@0
    42
	{
sl@0
    43
	delete gFileMan;
sl@0
    44
	}
sl@0
    45
sl@0
    46
//Test that the contents of two directories are identical
sl@0
    47
TBool CompareL(const TDesC& aDir1,const TDesC& aDir2)
sl@0
    48
	{
sl@0
    49
	TBool rel = ETrue;
sl@0
    50
	CDirScan* scanDir1=CDirScan::NewL(TheFs);
sl@0
    51
	scanDir1->SetScanDataL(aDir1,KEntryAttMaskSupported,ESortByName);
sl@0
    52
	CDirScan* scanDir2=CDirScan::NewL(TheFs);
sl@0
    53
	scanDir2->SetScanDataL(aDir2,KEntryAttMaskSupported,ESortByName);
sl@0
    54
sl@0
    55
	FOREVER
sl@0
    56
		{
sl@0
    57
		CDir* entryList1;
sl@0
    58
		CDir* entryList2;
sl@0
    59
sl@0
    60
		scanDir1->NextL(entryList1);
sl@0
    61
		scanDir2->NextL(entryList2);
sl@0
    62
sl@0
    63
		if (entryList1==NULL || entryList2==NULL)
sl@0
    64
			{
sl@0
    65
			if (!(entryList1==NULL && entryList2==NULL))
sl@0
    66
				{
sl@0
    67
				delete entryList1, 
sl@0
    68
				delete entryList2, 
sl@0
    69
				delete scanDir1, 
sl@0
    70
				delete scanDir2;
sl@0
    71
				return(EFalse);
sl@0
    72
				}
sl@0
    73
			break;
sl@0
    74
			}
sl@0
    75
sl@0
    76
		TFileName abbPath1=scanDir1->AbbreviatedPath();
sl@0
    77
		TFileName abbPath2=scanDir2->AbbreviatedPath();
sl@0
    78
		if (!(abbPath1==abbPath2))
sl@0
    79
			{
sl@0
    80
			delete entryList1, 
sl@0
    81
			delete entryList2, 
sl@0
    82
			delete scanDir1, 
sl@0
    83
			delete scanDir2;
sl@0
    84
			return(EFalse);
sl@0
    85
			}
sl@0
    86
sl@0
    87
		TInt count1=entryList1->Count();
sl@0
    88
		TInt count2=entryList2->Count();
sl@0
    89
		if (!(count1==count2))
sl@0
    90
			{
sl@0
    91
			delete entryList1, 
sl@0
    92
			delete entryList2, 
sl@0
    93
			delete scanDir1, 
sl@0
    94
			delete scanDir2;
sl@0
    95
			return(EFalse);
sl@0
    96
			}
sl@0
    97
sl@0
    98
		while(count1--)
sl@0
    99
			{
sl@0
   100
			TEntry entry1=(*entryList1)[count1];
sl@0
   101
			TEntry entry2=(*entryList2)[count1];
sl@0
   102
			if (!(entry1.iName==entry2.iName))
sl@0
   103
				{
sl@0
   104
				delete entryList1, 
sl@0
   105
				delete entryList2, 
sl@0
   106
				delete scanDir1, 
sl@0
   107
				delete scanDir2;
sl@0
   108
				return(EFalse);
sl@0
   109
				}
sl@0
   110
			if (!(entry1.iAtt==entry2.iAtt))
sl@0
   111
				{
sl@0
   112
				delete entryList1, 
sl@0
   113
				delete entryList2, 
sl@0
   114
				delete scanDir1, 
sl@0
   115
				delete scanDir2;
sl@0
   116
				return(EFalse);
sl@0
   117
				}
sl@0
   118
sl@0
   119
			}
sl@0
   120
sl@0
   121
		delete entryList1;
sl@0
   122
		delete entryList2;
sl@0
   123
		}
sl@0
   124
sl@0
   125
	delete scanDir1;
sl@0
   126
	delete scanDir2;
sl@0
   127
	
sl@0
   128
	return rel;
sl@0
   129
	}
sl@0
   130
sl@0
   131
/**
sl@0
   132
    Parsing Dir Data Block
sl@0
   133
    @param  aDataBlock		data block in TInt[] for parsing	
sl@0
   134
    @param  aDirDataArray	returning dir data array after parsing
sl@0
   135
sl@0
   136
    @panic 					if data setup error
sl@0
   137
sl@0
   138
*/
sl@0
   139
void ParsingDirDataBlock(const TInt aDataBlock[], RArray<TInt>& aDirDataArray)
sl@0
   140
	{
sl@0
   141
	TInt err = KErrNone;
sl@0
   142
	aDirDataArray.Reset();
sl@0
   143
sl@0
   144
	if (aDataBlock[0] == EOB)
sl@0
   145
		{
sl@0
   146
		return;
sl@0
   147
		}
sl@0
   148
sl@0
   149
	TInt i = 1;
sl@0
   150
	FOREVER
sl@0
   151
		{
sl@0
   152
		TInt lastItem = aDataBlock[i-1];
sl@0
   153
		TInt currentItem = aDataBlock[i];
sl@0
   154
		
sl@0
   155
		// check currentItem
sl@0
   156
		if (currentItem == EOB)
sl@0
   157
			{
sl@0
   158
			if (lastItem == CON || lastItem > LAST)
sl@0
   159
			//check last
sl@0
   160
				{
sl@0
   161
				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
sl@0
   162
				test(EFalse);
sl@0
   163
				}
sl@0
   164
			else
sl@0
   165
			// passed, insert last, break
sl@0
   166
				{
sl@0
   167
				err = aDirDataArray.InsertInOrder(lastItem);
sl@0
   168
				if (err != KErrNone && err != KErrAlreadyExists)
sl@0
   169
					{
sl@0
   170
					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
sl@0
   171
					test(EFalse);
sl@0
   172
					}
sl@0
   173
				break;
sl@0
   174
				}
sl@0
   175
			}
sl@0
   176
		
sl@0
   177
		else if (currentItem == CON)
sl@0
   178
		// if current == CON
sl@0
   179
			{
sl@0
   180
			if (lastItem == CON || lastItem >= LAST)
sl@0
   181
			// check last item
sl@0
   182
				{
sl@0
   183
				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
sl@0
   184
				test(EFalse);
sl@0
   185
				}
sl@0
   186
			else // last < LAST, last != CON
sl@0
   187
				{
sl@0
   188
				// check next item
sl@0
   189
				TInt nextItem = aDataBlock[i+1];
sl@0
   190
				if (nextItem <= 0 || nextItem > LAST || lastItem >= nextItem)
sl@0
   191
					{
sl@0
   192
					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
sl@0
   193
					test(EFalse);
sl@0
   194
					}
sl@0
   195
				else
sl@0
   196
					{
sl@0
   197
					// all valid
sl@0
   198
					for (TInt j = lastItem; j < nextItem; j++)
sl@0
   199
						{
sl@0
   200
						err = aDirDataArray.InsertInOrder(j);
sl@0
   201
						if (err != KErrNone && err != KErrAlreadyExists)
sl@0
   202
							{
sl@0
   203
							test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
sl@0
   204
							test(EFalse);
sl@0
   205
							}
sl@0
   206
						}
sl@0
   207
					}
sl@0
   208
				}
sl@0
   209
			i++;
sl@0
   210
			}
sl@0
   211
sl@0
   212
		else if (0 <= currentItem && currentItem <= LAST)
sl@0
   213
		// if current == normal item
sl@0
   214
			{
sl@0
   215
			if (lastItem == CON)
sl@0
   216
				{
sl@0
   217
				i++;
sl@0
   218
				continue;
sl@0
   219
				}
sl@0
   220
			else if (lastItem >= LAST)
sl@0
   221
			// check last item
sl@0
   222
				{
sl@0
   223
				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
sl@0
   224
				test(EFalse);
sl@0
   225
				}
sl@0
   226
			else
sl@0
   227
			// passed, insert last
sl@0
   228
				{
sl@0
   229
				err = aDirDataArray.InsertInOrder(lastItem);
sl@0
   230
				if (err != KErrNone && err != KErrAlreadyExists)
sl@0
   231
					{
sl@0
   232
					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
sl@0
   233
					test(EFalse);
sl@0
   234
					}
sl@0
   235
				}
sl@0
   236
			i++;
sl@0
   237
			}
sl@0
   238
		
sl@0
   239
		else	// invalid input
sl@0
   240
			{
sl@0
   241
			test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
sl@0
   242
			test(EFalse);
sl@0
   243
			}
sl@0
   244
		}
sl@0
   245
	}
sl@0
   246
sl@0
   247
	
sl@0
   248
/**
sl@0
   249
	Setup attribs:
sl@0
   250
	@param  filenamedir   		root path of dir data or a file data
sl@0
   251
	@param  mode			    value of an mode to be set(Normal/Open/Shared..)
sl@0
   252
*/
sl@0
   253
void OpenFile(TDesC& aFile, TFileMode aFileMode)
sl@0
   254
	{
sl@0
   255
	RFile* file = new (ELeave) RFile;
sl@0
   256
	gFileHandles->Append(file);
sl@0
   257
	TInt ret = 0;
sl@0
   258
	ret = file->Open(TheFs, aFile, aFileMode);
sl@0
   259
	test(ret==KErrNone);
sl@0
   260
	}
sl@0
   261
	
sl@0
   262
sl@0
   263
/**
sl@0
   264
    Setup dir structure for testing and verifying functional results
sl@0
   265
    @param	datastr			data structure to setup directory
sl@0
   266
    @param  iOperation   	Operation to be performed 
sl@0
   267
    @param  SrcDrive		Source drive
sl@0
   268
    @param	Targetdrive		Target drive input
sl@0
   269
    @panic					if data structure definition is incorrect
sl@0
   270
*/
sl@0
   271
void SetupDirFiles(const TDesC& aPath, const TDirSetupFiles& aDirFiles)
sl@0
   272
	{
sl@0
   273
	TFileName path = aPath;
sl@0
   274
	if (path.Length() == 0)
sl@0
   275
		{
sl@0
   276
		test.Printf(_L("ERROR<SetupDirFiles()>: Zero length src path!\n"));
sl@0
   277
		test(EFalse);
sl@0
   278
		}
sl@0
   279
	
sl@0
   280
	RmDir(path);
sl@0
   281
	MakeDir(path);
sl@0
   282
sl@0
   283
	RArray<TInt> addBlockDataArray;
sl@0
   284
	RArray<TInt> deductBlockDataArray;
sl@0
   285
	
sl@0
   286
	ParsingDirDataBlock(aDirFiles.iAddingBlock, addBlockDataArray);
sl@0
   287
	ParsingDirDataBlock(aDirFiles.iDeductBlock, deductBlockDataArray);
sl@0
   288
	
sl@0
   289
	if (addBlockDataArray.Count() == 0)
sl@0
   290
	// empty dir setup
sl@0
   291
		{
sl@0
   292
		return;
sl@0
   293
		}
sl@0
   294
	else
sl@0
   295
		{
sl@0
   296
		for (TInt i = 0; i < deductBlockDataArray.Count(); ++i)
sl@0
   297
			{
sl@0
   298
			TInt idxToDelete = addBlockDataArray.FindInOrder(deductBlockDataArray[i]);
sl@0
   299
			if (idxToDelete >= 0)
sl@0
   300
				{
sl@0
   301
				addBlockDataArray.Remove(idxToDelete);
sl@0
   302
				}
sl@0
   303
			else if (idxToDelete == KErrNotFound)
sl@0
   304
				{
sl@0
   305
				continue;
sl@0
   306
				}
sl@0
   307
			else
sl@0
   308
				{
sl@0
   309
				test.Printf(_L("ERROR<<SetupDir>>: wrong dir data setup! err=%d\n"), idxToDelete);
sl@0
   310
				test(EFalse);
sl@0
   311
				}
sl@0
   312
			}
sl@0
   313
		}
sl@0
   314
sl@0
   315
	if (addBlockDataArray.Count() > 0)
sl@0
   316
		{
sl@0
   317
		for (TInt i = 0; i < addBlockDataArray.Count(); ++i)
sl@0
   318
			{
sl@0
   319
			TInt idx = addBlockDataArray[i];
sl@0
   320
			path = aPath;
sl@0
   321
			path += gDirPatterns[idx];
sl@0
   322
			if (path[path.Length() - 1] == '\\')
sl@0
   323
				{
sl@0
   324
				MakeDir(path);
sl@0
   325
				}
sl@0
   326
			else
sl@0
   327
				{
sl@0
   328
				MakeFile(path, _L8("blahblah"));
sl@0
   329
sl@0
   330
				}
sl@0
   331
			}
sl@0
   332
		}
sl@0
   333
sl@0
   334
	addBlockDataArray.Reset();
sl@0
   335
	deductBlockDataArray.Reset();
sl@0
   336
	}
sl@0
   337
sl@0
   338
/**
sl@0
   339
    Print out all items in aPath
sl@0
   340
    @param  aPath 		root path for scanning
sl@0
   341
sl@0
   342
    @panic				SetScanData error
sl@0
   343
*/
sl@0
   344
void PrintDir(const TDesC& aPath, const TChar& aDrv)
sl@0
   345
	{
sl@0
   346
	TFileName fn;
sl@0
   347
	if (aPath.Length() == 0)
sl@0
   348
		{
sl@0
   349
		return;
sl@0
   350
		}
sl@0
   351
	else
sl@0
   352
		{
sl@0
   353
		fn = aPath;
sl@0
   354
		fn[0] = (TUint16)aDrv;
sl@0
   355
		test.Printf(_L("==============================\n"));
sl@0
   356
		test.Printf(_L("<<PrintDir>>: root = \"%S\"\n"), &fn);
sl@0
   357
		}
sl@0
   358
sl@0
   359
	CDirScan* scan = CDirScan::NewL(TheFs);
sl@0
   360
	TUint entryAttMask = KEntryAttMaskSupported;
sl@0
   361
	TUint entrySortMask = EDirsLast|EAscending;
sl@0
   362
	CDirScan::TScanDirection scanDirection = CDirScan::EScanDownTree;
sl@0
   363
sl@0
   364
sl@0
   365
	TRAPD(err, scan->SetScanDataL(fn, entryAttMask, entrySortMask, scanDirection));
sl@0
   366
	test(err == KErrNone);
sl@0
   367
sl@0
   368
	CDir* dir = NULL;
sl@0
   369
	TInt i = 0;
sl@0
   370
	TBool temp_val = ETrue;
sl@0
   371
	while (temp_val)
sl@0
   372
		{
sl@0
   373
		scan->NextL(dir);
sl@0
   374
		if (dir != NULL)
sl@0
   375
			{
sl@0
   376
			for (TInt j = 0; j < dir->Count(); ++j)
sl@0
   377
				{
sl@0
   378
				TFileName item(fn.Left(aPath.Length() - 1));
sl@0
   379
				item.Append(scan->AbbreviatedPath());
sl@0
   380
				TEntry dummy = (*dir)[j];
sl@0
   381
				item.Append(dummy.iName);
sl@0
   382
				if (dummy.iAtt & KEntryAttDir)
sl@0
   383
					{
sl@0
   384
					item.Append('\\');
sl@0
   385
					}
sl@0
   386
				test.Printf(_L("<<PrintDir>>: item %d: \"%S\"\n"), i, &item);
sl@0
   387
				++i;
sl@0
   388
				}
sl@0
   389
			delete dir;
sl@0
   390
			dir = NULL;
sl@0
   391
			}
sl@0
   392
		else
sl@0
   393
			{
sl@0
   394
			break;
sl@0
   395
			}
sl@0
   396
		}
sl@0
   397
	delete scan;
sl@0
   398
	}