Update contrib.
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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\cfileman\t_cfileman_aux.cpp
18 #include "t_cfileman_aux.h"
20 CFileMan* gFileMan = NULL;
21 RPointerArray<RFile>* gFileHandles = NULL;
22 TBool gAsynch = EFalse;
24 TBool testingInvalidPathLengths;
28 gFileMan=CFileMan::NewL(TheFs);
31 void RmDir(const TDesC& aDirName)
33 TFileName filename_dir = aDirName;
35 r = TheFs.SetAtt(filename_dir, 0, KEntryAttReadOnly);
36 r=gFileMan->RmDir(filename_dir);
37 test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
40 // Cleanup test variables
46 //Test that the contents of two directories are identical
47 TBool CompareL(const TDesC& aDir1,const TDesC& aDir2)
50 CDirScan* scanDir1=CDirScan::NewL(TheFs);
51 scanDir1->SetScanDataL(aDir1,KEntryAttMaskSupported,ESortByName);
52 CDirScan* scanDir2=CDirScan::NewL(TheFs);
53 scanDir2->SetScanDataL(aDir2,KEntryAttMaskSupported,ESortByName);
60 scanDir1->NextL(entryList1);
61 scanDir2->NextL(entryList2);
63 if (entryList1==NULL || entryList2==NULL)
65 if (!(entryList1==NULL && entryList2==NULL))
76 TFileName abbPath1=scanDir1->AbbreviatedPath();
77 TFileName abbPath2=scanDir2->AbbreviatedPath();
78 if (!(abbPath1==abbPath2))
87 TInt count1=entryList1->Count();
88 TInt count2=entryList2->Count();
89 if (!(count1==count2))
100 TEntry entry1=(*entryList1)[count1];
101 TEntry entry2=(*entryList2)[count1];
102 if (!(entry1.iName==entry2.iName))
110 if (!(entry1.iAtt==entry2.iAtt))
132 Parsing Dir Data Block
133 @param aDataBlock data block in TInt[] for parsing
134 @param aDirDataArray returning dir data array after parsing
136 @panic if data setup error
139 void ParsingDirDataBlock(const TInt aDataBlock[], RArray<TInt>& aDirDataArray)
142 aDirDataArray.Reset();
144 if (aDataBlock[0] == EOB)
152 TInt lastItem = aDataBlock[i-1];
153 TInt currentItem = aDataBlock[i];
156 if (currentItem == EOB)
158 if (lastItem == CON || lastItem > LAST)
161 test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
165 // passed, insert last, break
167 err = aDirDataArray.InsertInOrder(lastItem);
168 if (err != KErrNone && err != KErrAlreadyExists)
170 test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
177 else if (currentItem == CON)
180 if (lastItem == CON || lastItem >= LAST)
183 test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
186 else // last < LAST, last != CON
189 TInt nextItem = aDataBlock[i+1];
190 if (nextItem <= 0 || nextItem > LAST || lastItem >= nextItem)
192 test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
198 for (TInt j = lastItem; j < nextItem; j++)
200 err = aDirDataArray.InsertInOrder(j);
201 if (err != KErrNone && err != KErrAlreadyExists)
203 test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
212 else if (0 <= currentItem && currentItem <= LAST)
213 // if current == normal item
220 else if (lastItem >= LAST)
223 test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
227 // passed, insert last
229 err = aDirDataArray.InsertInOrder(lastItem);
230 if (err != KErrNone && err != KErrAlreadyExists)
232 test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
239 else // invalid input
241 test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
250 @param filenamedir root path of dir data or a file data
251 @param mode value of an mode to be set(Normal/Open/Shared..)
253 void OpenFile(TDesC& aFile, TFileMode aFileMode)
255 RFile* file = new (ELeave) RFile;
256 gFileHandles->Append(file);
258 ret = file->Open(TheFs, aFile, aFileMode);
264 Setup dir structure for testing and verifying functional results
265 @param datastr data structure to setup directory
266 @param iOperation Operation to be performed
267 @param SrcDrive Source drive
268 @param Targetdrive Target drive input
269 @panic if data structure definition is incorrect
271 void SetupDirFiles(const TDesC& aPath, const TDirSetupFiles& aDirFiles)
273 TFileName path = aPath;
274 if (path.Length() == 0)
276 test.Printf(_L("ERROR<SetupDirFiles()>: Zero length src path!\n"));
283 RArray<TInt> addBlockDataArray;
284 RArray<TInt> deductBlockDataArray;
286 ParsingDirDataBlock(aDirFiles.iAddingBlock, addBlockDataArray);
287 ParsingDirDataBlock(aDirFiles.iDeductBlock, deductBlockDataArray);
289 if (addBlockDataArray.Count() == 0)
296 for (TInt i = 0; i < deductBlockDataArray.Count(); ++i)
298 TInt idxToDelete = addBlockDataArray.FindInOrder(deductBlockDataArray[i]);
299 if (idxToDelete >= 0)
301 addBlockDataArray.Remove(idxToDelete);
303 else if (idxToDelete == KErrNotFound)
309 test.Printf(_L("ERROR<<SetupDir>>: wrong dir data setup! err=%d\n"), idxToDelete);
315 if (addBlockDataArray.Count() > 0)
317 for (TInt i = 0; i < addBlockDataArray.Count(); ++i)
319 TInt idx = addBlockDataArray[i];
321 path += gDirPatterns[idx];
322 if (path[path.Length() - 1] == '\\')
328 MakeFile(path, _L8("blahblah"));
334 addBlockDataArray.Reset();
335 deductBlockDataArray.Reset();
339 Print out all items in aPath
340 @param aPath root path for scanning
342 @panic SetScanData error
344 void PrintDir(const TDesC& aPath, const TChar& aDrv)
347 if (aPath.Length() == 0)
354 fn[0] = (TUint16)aDrv;
355 test.Printf(_L("==============================\n"));
356 test.Printf(_L("<<PrintDir>>: root = \"%S\"\n"), &fn);
359 CDirScan* scan = CDirScan::NewL(TheFs);
360 TUint entryAttMask = KEntryAttMaskSupported;
361 TUint entrySortMask = EDirsLast|EAscending;
362 CDirScan::TScanDirection scanDirection = CDirScan::EScanDownTree;
365 TRAPD(err, scan->SetScanDataL(fn, entryAttMask, entrySortMask, scanDirection));
366 test(err == KErrNone);
370 TBool temp_val = ETrue;
376 for (TInt j = 0; j < dir->Count(); ++j)
378 TFileName item(fn.Left(aPath.Length() - 1));
379 item.Append(scan->AbbreviatedPath());
380 TEntry dummy = (*dir)[j];
381 item.Append(dummy.iName);
382 if (dummy.iAtt & KEntryAttDir)
386 test.Printf(_L("<<PrintDir>>: item %d: \"%S\"\n"), i, &item);