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.cpp
18 #define __E32TEST_EXTENSION__
22 #include "t_cfileman_cases.h"
24 static RArray<TUint> gFailedTestCases;
26 RTest test(_L("T_CFILEMAN"));
29 * Prints failure notification for failed test cases during test running period
31 void DoLogTestCaseFailure(const TTestParamAll& aParam)
33 const TUint testCaseId = aParam.iTestCaseID;
34 test.Printf(_L("Test Failure: Case %d !\n"), testCaseId);
35 gFailedTestCases.Append(testCaseId);
36 test.Printf(_L("Print out directory contents:\n"));
37 PrintDir(aParam.iSrcPrsPath, *aParam.iSrcDrvChar);
38 PrintDir(aParam.iSrcCmpPath, *aParam.iSrcDrvChar);
39 if (aParam.iAPI == ECFMMove || aParam.iAPI == ECFMRename || aParam.iAPI == ECFMCopy || aParam.iAPI == ECFMCopyHandle)
41 PrintDir(aParam.iTrgPrsPath, *aParam.iTrgDrvChar);
42 PrintDir(aParam.iTrgCmpPath, *aParam.iTrgDrvChar);
47 * Overall test results logging module, prints out the failing test cases with their ID
49 void DoPrintTestResults()
51 // if no failure found
52 if (gFailedTestCases.Count() == 0)
54 test.Printf(_L("All test cases have passed!\n"));
58 test.Printf(_L("Test failure(s) found in following case(s):\n"));
59 for (TInt i = 0; i < gFailedTestCases.Count(); i++)
61 test.Printf(_L("Test Case: %u"), gFailedTestCases[i]);
67 * Presetting module, presets initial source, target and comparing direcotries.
68 * @param aParam test param that contains all information about a test case
70 void DoPresettings(const TTestParamAll& aParam)
74 TFileName path = aParam.iSrcPrsPath;
75 path[0] = (TUint16)*aParam.iSrcDrvChar;
77 if(path[0] == (TUint8)gDriveToTest || path[0] == (TUint8)gFixedDriveValid)
79 SetupDirFiles(path, aParam.iSrcPrsFiles);
81 // setup source cmp files
82 path = aParam.iSrcCmpPath;
83 path[0] = (TUint16)*aParam.iSrcDrvChar;
84 SetupDirFiles(path, aParam.iSrcCmpFiles);
87 if (aParam.iAPI == ECFMMove || aParam.iAPI == ECFMRename || aParam.iAPI == ECFMCopy || aParam.iAPI == ECFMCopyHandle)
90 path = aParam.iTrgPrsPath;
91 path[0] = (TUint16)*aParam.iTrgDrvChar;
93 if(path[0]== (TUint8)gDriveToTest)
95 SetupDirFiles(path, aParam.iTrgPrsFiles);
97 // setup trg cmp files
98 path = aParam.iTrgCmpPath;
99 path[0] = (TUint16)*aParam.iTrgDrvChar;
100 SetupDirFiles(path, aParam.iTrgCmpFiles);
106 * Test execution module
107 * @param aParam test param that contains all information about a test case
108 * @panic USER:84 if return codes do not match the expected values.
111 typedef TBuf<350> TTestFileName;
112 void DoCmdExecution(const TTestParamAll& aParam)
114 TTestFileName srcCmd = aParam.iSrcCmdPath;
115 if (srcCmd.Length() > 0)
117 srcCmd[0] = (TUint16)*aParam.iSrcDrvChar;
121 srcCmd= gSessionPath;
122 srcCmd[0] = (TUint16)*aParam.iSrcDrvChar;
130 r = gFileMan->Delete(srcCmd, aParam.iSwitch);
131 test_Equal(r, aParam.iSyncReturn);
135 r = gFileMan->Delete(srcCmd, aParam.iSwitch, gStat);
136 User::WaitForRequest(gStat);
137 test_Equal(r , aParam.iAsyncReturn);
138 test(gStat == aParam.iAsyncStatus);
145 r = gFileMan->RmDir(srcCmd);
146 test_Equal(r , aParam.iSyncReturn);
150 r = gFileMan->RmDir(srcCmd, gStat);
151 User::WaitForRequest(gStat);
152 test_Equal(r , aParam.iAsyncReturn);
153 test(gStat == aParam.iAsyncStatus);
159 r = gFileMan->Attribs(srcCmd, aParam.iSetAttribs, aParam.iClearAttribs, aParam.iSetModified, aParam.iSwitch);
160 test_Equal(r , aParam.iSyncReturn);
164 r = gFileMan->Attribs(srcCmd, aParam.iSetAttribs, aParam.iClearAttribs, aParam.iSetModified, aParam.iSwitch, gStat);
165 User::WaitForRequest(gStat);
166 test_Equal(r , aParam.iAsyncReturn);
167 test(gStat == aParam.iAsyncStatus);
172 TTestFileName trgCmd = aParam.iTrgCmdPath;
173 if (trgCmd.Length() > 0)
175 trgCmd[0] = (TUint16)*aParam.iTrgDrvChar;
179 trgCmd= gSessionPath;
183 r = gFileMan->Move(srcCmd, trgCmd, aParam.iSwitch);
184 test_Equal(r , aParam.iSyncReturn);
188 r = gFileMan->Move(srcCmd, trgCmd, aParam.iSwitch, gStat);
189 User::WaitForRequest(gStat);
190 test_Equal(r , aParam.iAsyncReturn);
191 test(gStat == aParam.iAsyncStatus);
197 TTestFileName trgCmd = aParam.iTrgCmdPath;
198 if (trgCmd.Length() > 0)
200 trgCmd[0] = (TUint16)*aParam.iTrgDrvChar;
204 trgCmd= gSessionPath;
208 r = gFileMan->Copy(srcCmd, trgCmd, aParam.iSwitch);
209 test_Equal(r , aParam.iSyncReturn);
213 r = gFileMan->Copy(srcCmd, trgCmd,aParam.iSwitch, gStat);
214 User::WaitForRequest(gStat);
215 test_Equal(r , aParam.iAsyncReturn);
216 test(gStat == aParam.iAsyncStatus);
222 TTestFileName trgCmd = aParam.iTrgCmdPath;
223 if (trgCmd.Length() > 0)
225 trgCmd[0] = (TUint16)*aParam.iTrgDrvChar;
229 trgCmd= gSessionPath;
233 r = gFileMan->Rename(srcCmd, trgCmd, aParam.iSwitch);
234 test_Equal(r , aParam.iSyncReturn);
238 r = gFileMan->Rename(srcCmd, trgCmd, aParam.iSwitch, gStat);
239 User::WaitForRequest(gStat);
240 test_Equal(r , aParam.iAsyncReturn);
241 test(gStat == aParam.iAsyncStatus);
247 TTestFileName trgCmd = aParam.iTrgCmdPath;
248 if (trgCmd.Length() > 0)
250 trgCmd[0] = (TUint16)*aParam.iTrgDrvChar;
254 trgCmd= gSessionPath;
261 ret = tryfile.Open(TheFs, srcCmd, EFileRead|EFileWrite);
262 test_Equal(ret , KErrNone);
263 r = gFileMan->Copy(tryfile, trgCmd, aParam.iSwitch);
264 test_Equal(r , aParam.iSyncReturn);
271 ret = tryfile.Open(TheFs, srcCmd, EFileRead|EFileWrite);
272 test(ret == KErrNone);
273 r = gFileMan->Copy(tryfile, trgCmd, aParam.iSwitch, gStat);
274 User::WaitForRequest(gStat);
275 test_Equal(r , aParam.iAsyncReturn);
276 test(gStat == aParam.iAsyncStatus);
288 * Result verification module.
289 * @param aParam test param that contains all information about a test case
290 * @return ETrue if test results in expected behaviour, i.e. test passes
291 * EFalse if test results in unexpected behaviour, i.e. test fails
293 TBool DoResultsVerification(const TTestParamAll& aParam)
295 TFileName srcPath = aParam.iSrcPrsPath;
296 srcPath[0] = (TUint16)*aParam.iSrcDrvChar;
297 TFileName srcCmpPath = aParam.iSrcCmpPath;
298 srcCmpPath[0] = (TUint16)*aParam.iSrcDrvChar;
300 if ((*aParam.iSrcDrvChar == gDriveToTest))
302 TBool rel = CompareL(srcPath, srcCmpPath);
307 if (aParam.iAPI == ECFMMove || aParam.iAPI == ECFMRename || aParam.iAPI == ECFMCopy || aParam.iAPI == ECFMCopyHandle)
309 TFileName trgPath = aParam.iTrgPrsPath;
310 trgPath[0] = (TUint16)*aParam.iTrgDrvChar;
311 TFileName trgCmpPath = aParam.iTrgCmpPath;
312 trgCmpPath[0] = (TUint16)*aParam.iTrgDrvChar;
313 if ((*aParam.iTrgDrvChar == gDriveToTest))
315 TBool rel = CompareL(trgPath, trgCmpPath);
325 * Search test cases by the index of the array of test case group, overloaded version for basic unitary cases.
326 * @param aIdx the test case index in search
327 * @param aBasicUnitaryTestCaseGroup the input test group, should always be gBasicUnitaryTestCases[]
328 * @param aTestCaseFound contains params of the test case found by the test case Id.
329 * @return KErrNone if only one test case on the id is found
330 * KErrNotFound if no test case is found
332 TInt SearchTestCaseByArrayIdx(TUint aIdx, const TTestCaseUnitaryBasic aBasicUnitaryTestCaseGroup[], TTestParamAll& aTestCaseFound)
334 if (aBasicUnitaryTestCaseGroup[aIdx].iBasic.iTestCaseID != 0)
336 aTestCaseFound.iTestCaseID = aBasicUnitaryTestCaseGroup[aIdx].iBasic.iTestCaseID;
337 aTestCaseFound.iAPI = aBasicUnitaryTestCaseGroup[aIdx].iBasic.iAPI;
338 aTestCaseFound.iSwitch = aBasicUnitaryTestCaseGroup[aIdx].iBasic.iSwitch;
339 aTestCaseFound.iSyncReturn = aBasicUnitaryTestCaseGroup[aIdx].iBasic.iSyncReturn;
340 aTestCaseFound.iAsyncReturn = aBasicUnitaryTestCaseGroup[aIdx].iBasic.iAsyncReturn;
341 aTestCaseFound.iAsyncStatus = aBasicUnitaryTestCaseGroup[aIdx].iBasic.iAsyncStatus;
343 aTestCaseFound.iSrcDrvChar = aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iDrvChar;
344 aTestCaseFound.iSrcCmdPath.Set(aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iCmdPath);
345 aTestCaseFound.iSrcPrsPath.Set(aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsPath);
346 aTestCaseFound.iSrcPrsFiles = aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsFiles;
347 aTestCaseFound.iSrcCmpPath.Set(aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iCmpPath);
348 aTestCaseFound.iSrcCmpFiles = aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iCmpFiles;
357 * Search test cases by the index of the array of test case group, overloaded version for basic binary cases.
358 * @param aIdx the test case index in search
359 * @param aBasicUnitaryTestCaseGroup the input test group, should always be gBasicBinaryTestCases[]
360 * @param aTestCaseFound contains params of the test case found by the test case Id.
361 * @return KErrNone if only one test case on the id is found
362 * KErrNotFound if no test case is found
364 TInt SearchTestCaseByArrayIdx(TUint aIdx, const TTestCaseBinaryBasic aBasicBinaryTestCaseGroup[], TTestParamAll& aTestCaseFound)
366 if (aBasicBinaryTestCaseGroup[aIdx].iBasic.iTestCaseID != 0)
368 aTestCaseFound.iTestCaseID = aBasicBinaryTestCaseGroup[aIdx].iBasic.iTestCaseID;
369 aTestCaseFound.iAPI = aBasicBinaryTestCaseGroup[aIdx].iBasic.iAPI;
370 aTestCaseFound.iSwitch = aBasicBinaryTestCaseGroup[aIdx].iBasic.iSwitch;
371 aTestCaseFound.iSyncReturn = aBasicBinaryTestCaseGroup[aIdx].iBasic.iSyncReturn;
372 aTestCaseFound.iAsyncReturn = aBasicBinaryTestCaseGroup[aIdx].iBasic.iAsyncReturn;
373 aTestCaseFound.iAsyncStatus = aBasicBinaryTestCaseGroup[aIdx].iBasic.iAsyncStatus;
375 aTestCaseFound.iSrcDrvChar = aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iDrvChar;
376 aTestCaseFound.iSrcCmdPath.Set(aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iCmdPath);
377 aTestCaseFound.iSrcPrsPath.Set(aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsPath);
378 aTestCaseFound.iSrcPrsFiles = aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsFiles;
379 aTestCaseFound.iSrcCmpPath.Set(aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iCmpPath);
380 aTestCaseFound.iSrcCmpFiles = aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iCmpFiles;
382 aTestCaseFound.iTrgDrvChar = aBasicBinaryTestCaseGroup[aIdx].iTrgPrsBasic.iDrvChar;
383 aTestCaseFound.iTrgCmdPath.Set(aBasicBinaryTestCaseGroup[aIdx].iTrgPrsBasic.iCmdPath);
384 aTestCaseFound.iTrgPrsPath.Set(aBasicBinaryTestCaseGroup[aIdx].iTrgPrsBasic.iPrsPath);
385 aTestCaseFound.iTrgPrsFiles = aBasicBinaryTestCaseGroup[aIdx].iTrgPrsBasic.iPrsFiles;
386 aTestCaseFound.iTrgCmpPath.Set(aBasicBinaryTestCaseGroup[aIdx].iTrgPrsBasic.iCmpPath);
387 aTestCaseFound.iTrgCmpFiles = aBasicBinaryTestCaseGroup[aIdx].iTrgPrsBasic.iCmpFiles;
397 * Search test cases by test case Id, overloaded version for Basic unitary cases.
398 * @param aCaseId the test case Id in search
399 * @param aBasicUnitaryTestCaseGroup the input test group, should always be gBasicUnitaryTestCases[]
400 * @param aTestCaseFound contains params of the test case found by the test case Id.
401 * @return KErrNone if only one test case on the id is found
402 * KErrAlreadyExists if more than one test cases found by the test case Id
403 * KErrNotFound if no test case is found
405 TInt SearchTestCaseByTestCaseId(TUint aCaseId, const TTestCaseUnitaryBasic aBasicUnitaryTestCaseGroup[], TTestParamAll& aTestCaseFound)
407 TBool found = EFalse;
410 // Scan through the test group by array index
411 for(TInt i = 0; rel == KErrNone; i++)
413 rel = SearchTestCaseByArrayIdx(i, aBasicUnitaryTestCaseGroup, aTestCaseFound);
414 if(aTestCaseFound.iTestCaseID == aCaseId)
416 // If more than one test cases found, return error
419 return KErrAlreadyExists;
433 * Do all basic binary test cases defined in gBasicUnitaryTestCases[]
435 void DoAllBasicUnitaryTests(const TTestCaseUnitaryBasic aBasicUnitaryTestCaseGroup[])
437 TTestParamAll nextTestCase;
440 while (SearchTestCaseByArrayIdx(i, aBasicUnitaryTestCaseGroup, nextTestCase) == KErrNone)
444 startTime.HomeTime();
445 DoPresettings(nextTestCase);
446 DoCmdExecution(nextTestCase);
447 if (!DoResultsVerification(nextTestCase))
449 DoLogTestCaseFailure(nextTestCase);
453 test.Printf(_L("Test ID %d passed \n"),nextTestCase.iTestCaseID);
456 TTimeIntervalMicroSeconds timeTaken(0);
457 timeTaken = endTime.MicroSecondsFrom(startTime);
459 time2=I64LOW(timeTaken.Int64()/1000);
460 test.Printf(_L("Time Taken by testid %d = %d mS \n"),nextTestCase.iTestCaseID,time2);
467 * Do all basic binary test cases defined in gBasicBinaryTestCases[]
469 void DoAllBasicBinaryTests(const TTestCaseBinaryBasic aBasicBinaryTestCaseGroup[])
471 TTestParamAll nextTestCase;
473 while (SearchTestCaseByArrayIdx(i, aBasicBinaryTestCaseGroup, nextTestCase) == KErrNone)
477 startTime.HomeTime();
478 DoPresettings(nextTestCase);
479 DoCmdExecution(nextTestCase);
480 if (!DoResultsVerification(nextTestCase))
482 DoLogTestCaseFailure(nextTestCase);
486 test.Printf(_L("Test ID %d passed \n"),nextTestCase.iTestCaseID);
489 TTimeIntervalMicroSeconds timeTaken(0);
490 timeTaken = endTime.MicroSecondsFrom(startTime);
493 time2=I64LOW(timeTaken.Int64()/1000);
494 test.Printf(_L("Time Taken by test id %d = %d mS \n"),nextTestCase.iTestCaseID,time2);
499 // Future work: provide command arguement parsing faclity so that users
500 // can choose specific test case(s) in ranges
501 // can choose specific API(s), switches, configurations, etc. for testing
503 * Main testing control unit
507 //The __PERFTEST__ macro is for future use when a tests are setup to run on a performance machine
508 //which will be enabled to run for both WINSCW and ARMV5
510 //Tests are enabled to run for WINSCW only on the below specified drives due to the time constraint.
511 if((gDriveToTest == 'C') || (gDriveToTest == 'X') || (gDriveToTest == 'Y'))
513 DoAllBasicUnitaryTests(gBasicUnitaryTestCases);
514 DoAllBasicBinaryTests(gBasicBinaryTestCases);
518 test.Printf(_L("Drive %C: is not supported for this configuration, see test logs for supported configuration details"),gDriveToTest);
523 DoAllBasicUnitaryTests(gBasicUnitaryTestCases);
524 DoAllBasicBinaryTests(gBasicBinaryTestCases);
530 * Initialise test, do all tests in both sync and async mode.
536 CreateTestDirectory(_L("\\F32-TST\\T_CFILEMAN\\"));
539 test.Next(_L("Synchronous tests ..."));
542 DeleteTestDirectory();
544 CreateTestDirectory(_L("\\F32-TST\\T_CFILEMAN\\"));
546 test.Next(_L("Asynchronous tests ..."));
549 DoPrintTestResults();
551 DeleteTestDirectory();