sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\cfileman\t_cfileman_aux.cpp sl@0: // sl@0: // sl@0: sl@0: #include "t_cfileman_aux.h" sl@0: sl@0: CFileMan* gFileMan = NULL; sl@0: RPointerArray* gFileHandles = NULL; sl@0: TBool gAsynch = EFalse; sl@0: TRequestStatus gStat; sl@0: TBool testingInvalidPathLengths; sl@0: sl@0: void InitialiseL() sl@0: { sl@0: gFileMan=CFileMan::NewL(TheFs); sl@0: } sl@0: sl@0: void RmDir(const TDesC& aDirName) sl@0: { sl@0: TFileName filename_dir = aDirName; sl@0: TInt r = 0; sl@0: r = TheFs.SetAtt(filename_dir, 0, KEntryAttReadOnly); sl@0: r=gFileMan->RmDir(filename_dir); sl@0: test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound); sl@0: } sl@0: sl@0: // Cleanup test variables sl@0: void Cleanup() sl@0: { sl@0: delete gFileMan; sl@0: } sl@0: sl@0: //Test that the contents of two directories are identical sl@0: TBool CompareL(const TDesC& aDir1,const TDesC& aDir2) sl@0: { sl@0: TBool rel = ETrue; sl@0: CDirScan* scanDir1=CDirScan::NewL(TheFs); sl@0: scanDir1->SetScanDataL(aDir1,KEntryAttMaskSupported,ESortByName); sl@0: CDirScan* scanDir2=CDirScan::NewL(TheFs); sl@0: scanDir2->SetScanDataL(aDir2,KEntryAttMaskSupported,ESortByName); sl@0: sl@0: FOREVER sl@0: { sl@0: CDir* entryList1; sl@0: CDir* entryList2; sl@0: sl@0: scanDir1->NextL(entryList1); sl@0: scanDir2->NextL(entryList2); sl@0: sl@0: if (entryList1==NULL || entryList2==NULL) sl@0: { sl@0: if (!(entryList1==NULL && entryList2==NULL)) sl@0: { sl@0: delete entryList1, sl@0: delete entryList2, sl@0: delete scanDir1, sl@0: delete scanDir2; sl@0: return(EFalse); sl@0: } sl@0: break; sl@0: } sl@0: sl@0: TFileName abbPath1=scanDir1->AbbreviatedPath(); sl@0: TFileName abbPath2=scanDir2->AbbreviatedPath(); sl@0: if (!(abbPath1==abbPath2)) sl@0: { sl@0: delete entryList1, sl@0: delete entryList2, sl@0: delete scanDir1, sl@0: delete scanDir2; sl@0: return(EFalse); sl@0: } sl@0: sl@0: TInt count1=entryList1->Count(); sl@0: TInt count2=entryList2->Count(); sl@0: if (!(count1==count2)) sl@0: { sl@0: delete entryList1, sl@0: delete entryList2, sl@0: delete scanDir1, sl@0: delete scanDir2; sl@0: return(EFalse); sl@0: } sl@0: sl@0: while(count1--) sl@0: { sl@0: TEntry entry1=(*entryList1)[count1]; sl@0: TEntry entry2=(*entryList2)[count1]; sl@0: if (!(entry1.iName==entry2.iName)) sl@0: { sl@0: delete entryList1, sl@0: delete entryList2, sl@0: delete scanDir1, sl@0: delete scanDir2; sl@0: return(EFalse); sl@0: } sl@0: if (!(entry1.iAtt==entry2.iAtt)) sl@0: { sl@0: delete entryList1, sl@0: delete entryList2, sl@0: delete scanDir1, sl@0: delete scanDir2; sl@0: return(EFalse); sl@0: } sl@0: sl@0: } sl@0: sl@0: delete entryList1; sl@0: delete entryList2; sl@0: } sl@0: sl@0: delete scanDir1; sl@0: delete scanDir2; sl@0: sl@0: return rel; sl@0: } sl@0: sl@0: /** sl@0: Parsing Dir Data Block sl@0: @param aDataBlock data block in TInt[] for parsing sl@0: @param aDirDataArray returning dir data array after parsing sl@0: sl@0: @panic if data setup error sl@0: sl@0: */ sl@0: void ParsingDirDataBlock(const TInt aDataBlock[], RArray& aDirDataArray) sl@0: { sl@0: TInt err = KErrNone; sl@0: aDirDataArray.Reset(); sl@0: sl@0: if (aDataBlock[0] == EOB) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: TInt i = 1; sl@0: FOREVER sl@0: { sl@0: TInt lastItem = aDataBlock[i-1]; sl@0: TInt currentItem = aDataBlock[i]; sl@0: sl@0: // check currentItem sl@0: if (currentItem == EOB) sl@0: { sl@0: if (lastItem == CON || lastItem > LAST) sl@0: //check last sl@0: { sl@0: test.Printf(_L("ERROR: wrong dir data setup! err=%d\n"), err); sl@0: test(EFalse); sl@0: } sl@0: else sl@0: // passed, insert last, break sl@0: { sl@0: err = aDirDataArray.InsertInOrder(lastItem); sl@0: if (err != KErrNone && err != KErrAlreadyExists) sl@0: { sl@0: test.Printf(_L("ERROR: wrong dir data setup! err=%d\n"), err); sl@0: test(EFalse); sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: sl@0: else if (currentItem == CON) sl@0: // if current == CON sl@0: { sl@0: if (lastItem == CON || lastItem >= LAST) sl@0: // check last item sl@0: { sl@0: test.Printf(_L("ERROR: wrong dir data setup! err=%d\n"), err); sl@0: test(EFalse); sl@0: } sl@0: else // last < LAST, last != CON sl@0: { sl@0: // check next item sl@0: TInt nextItem = aDataBlock[i+1]; sl@0: if (nextItem <= 0 || nextItem > LAST || lastItem >= nextItem) sl@0: { sl@0: test.Printf(_L("ERROR: wrong dir data setup! err=%d\n"), err); sl@0: test(EFalse); sl@0: } sl@0: else sl@0: { sl@0: // all valid sl@0: for (TInt j = lastItem; j < nextItem; j++) sl@0: { sl@0: err = aDirDataArray.InsertInOrder(j); sl@0: if (err != KErrNone && err != KErrAlreadyExists) sl@0: { sl@0: test.Printf(_L("ERROR: wrong dir data setup! err=%d\n"), err); sl@0: test(EFalse); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: i++; sl@0: } sl@0: sl@0: else if (0 <= currentItem && currentItem <= LAST) sl@0: // if current == normal item sl@0: { sl@0: if (lastItem == CON) sl@0: { sl@0: i++; sl@0: continue; sl@0: } sl@0: else if (lastItem >= LAST) sl@0: // check last item sl@0: { sl@0: test.Printf(_L("ERROR: wrong dir data setup! err=%d\n"), err); sl@0: test(EFalse); sl@0: } sl@0: else sl@0: // passed, insert last sl@0: { sl@0: err = aDirDataArray.InsertInOrder(lastItem); sl@0: if (err != KErrNone && err != KErrAlreadyExists) sl@0: { sl@0: test.Printf(_L("ERROR: wrong dir data setup! err=%d\n"), err); sl@0: test(EFalse); sl@0: } sl@0: } sl@0: i++; sl@0: } sl@0: sl@0: else // invalid input sl@0: { sl@0: test.Printf(_L("ERROR: wrong dir data setup! err=%d\n"), err); sl@0: test(EFalse); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: /** sl@0: Setup attribs: sl@0: @param filenamedir root path of dir data or a file data sl@0: @param mode value of an mode to be set(Normal/Open/Shared..) sl@0: */ sl@0: void OpenFile(TDesC& aFile, TFileMode aFileMode) sl@0: { sl@0: RFile* file = new (ELeave) RFile; sl@0: gFileHandles->Append(file); sl@0: TInt ret = 0; sl@0: ret = file->Open(TheFs, aFile, aFileMode); sl@0: test(ret==KErrNone); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Setup dir structure for testing and verifying functional results sl@0: @param datastr data structure to setup directory sl@0: @param iOperation Operation to be performed sl@0: @param SrcDrive Source drive sl@0: @param Targetdrive Target drive input sl@0: @panic if data structure definition is incorrect sl@0: */ sl@0: void SetupDirFiles(const TDesC& aPath, const TDirSetupFiles& aDirFiles) sl@0: { sl@0: TFileName path = aPath; sl@0: if (path.Length() == 0) sl@0: { sl@0: test.Printf(_L("ERROR: Zero length src path!\n")); sl@0: test(EFalse); sl@0: } sl@0: sl@0: RmDir(path); sl@0: MakeDir(path); sl@0: sl@0: RArray addBlockDataArray; sl@0: RArray deductBlockDataArray; sl@0: sl@0: ParsingDirDataBlock(aDirFiles.iAddingBlock, addBlockDataArray); sl@0: ParsingDirDataBlock(aDirFiles.iDeductBlock, deductBlockDataArray); sl@0: sl@0: if (addBlockDataArray.Count() == 0) sl@0: // empty dir setup sl@0: { sl@0: return; sl@0: } sl@0: else sl@0: { sl@0: for (TInt i = 0; i < deductBlockDataArray.Count(); ++i) sl@0: { sl@0: TInt idxToDelete = addBlockDataArray.FindInOrder(deductBlockDataArray[i]); sl@0: if (idxToDelete >= 0) sl@0: { sl@0: addBlockDataArray.Remove(idxToDelete); sl@0: } sl@0: else if (idxToDelete == KErrNotFound) sl@0: { sl@0: continue; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("ERROR<>: wrong dir data setup! err=%d\n"), idxToDelete); sl@0: test(EFalse); sl@0: } sl@0: } sl@0: } sl@0: sl@0: if (addBlockDataArray.Count() > 0) sl@0: { sl@0: for (TInt i = 0; i < addBlockDataArray.Count(); ++i) sl@0: { sl@0: TInt idx = addBlockDataArray[i]; sl@0: path = aPath; sl@0: path += gDirPatterns[idx]; sl@0: if (path[path.Length() - 1] == '\\') sl@0: { sl@0: MakeDir(path); sl@0: } sl@0: else sl@0: { sl@0: MakeFile(path, _L8("blahblah")); sl@0: sl@0: } sl@0: } sl@0: } sl@0: sl@0: addBlockDataArray.Reset(); sl@0: deductBlockDataArray.Reset(); sl@0: } sl@0: sl@0: /** sl@0: Print out all items in aPath sl@0: @param aPath root path for scanning sl@0: sl@0: @panic SetScanData error sl@0: */ sl@0: void PrintDir(const TDesC& aPath, const TChar& aDrv) sl@0: { sl@0: TFileName fn; sl@0: if (aPath.Length() == 0) sl@0: { sl@0: return; sl@0: } sl@0: else sl@0: { sl@0: fn = aPath; sl@0: fn[0] = (TUint16)aDrv; sl@0: test.Printf(_L("==============================\n")); sl@0: test.Printf(_L("<>: root = \"%S\"\n"), &fn); sl@0: } sl@0: sl@0: CDirScan* scan = CDirScan::NewL(TheFs); sl@0: TUint entryAttMask = KEntryAttMaskSupported; sl@0: TUint entrySortMask = EDirsLast|EAscending; sl@0: CDirScan::TScanDirection scanDirection = CDirScan::EScanDownTree; sl@0: sl@0: sl@0: TRAPD(err, scan->SetScanDataL(fn, entryAttMask, entrySortMask, scanDirection)); sl@0: test(err == KErrNone); sl@0: sl@0: CDir* dir = NULL; sl@0: TInt i = 0; sl@0: TBool temp_val = ETrue; sl@0: while (temp_val) sl@0: { sl@0: scan->NextL(dir); sl@0: if (dir != NULL) sl@0: { sl@0: for (TInt j = 0; j < dir->Count(); ++j) sl@0: { sl@0: TFileName item(fn.Left(aPath.Length() - 1)); sl@0: item.Append(scan->AbbreviatedPath()); sl@0: TEntry dummy = (*dir)[j]; sl@0: item.Append(dummy.iName); sl@0: if (dummy.iAtt & KEntryAttDir) sl@0: { sl@0: item.Append('\\'); sl@0: } sl@0: test.Printf(_L("<>: item %d: \"%S\"\n"), i, &item); sl@0: ++i; sl@0: } sl@0: delete dir; sl@0: dir = NULL; sl@0: } sl@0: else sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: delete scan; sl@0: }