os/ossrv/genericservices/httputils/Test/Integration/TestFileUriSuite/TestForAllFilesStep.cpp
First public contribution.
1 // Copyright (c) 2004-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 "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 // TESTGENERATEFILEURIFORALLFILESSTEP.CPP
24 // For File URI handler API
27 #include <escapeutils.h>
30 #include "TestForAllFilesStep.h"
33 Constructor. Sets the test step name
35 CTestForAllFilesStep::CTestForAllFilesStep()
37 //Call base class method to set human readable name for test step
38 SetTestStepName(KTestForAllFilesStep);
42 Does the main functionality of a test step. Here just calls DoTestL.
45 @return EPass or EFail indicating the success or failure of the test step
47 TVerdict CTestForAllFilesStep::doTestStepL()
50 INFO_PRINTF1(_L("\n"));
51 TRAPD(err, DoTestL());
54 ERR_PRINTF2(_L("Leave occured in CTestForAllFilesStep::DoTestL: %D"), err);
55 SetTestStepResult(EFail);
57 INFO_PRINTF1(_L("\n"));
59 return TestStepResult();
63 Scans all the directories and calls TestBothWaysL that tests the
64 creation of URI from a filename and vice versa for all the files.
66 void CTestForAllFilesStep::DoTestL()
69 TInt err = fs.Connect();
72 ERR_PRINTF2(_L("Error occured while connecting to file server: %D"), err);
73 SetTestStepResult(EFail);
78 CDirScan *dirScan = CDirScan::NewLC(fs);
80 for(drive = EDriveA; drive <= EDriveZ; ++drive)
82 rootDir.Format(_L("%c:\\"), static_cast<char>(KLetterA + drive));
83 dirScan->SetScanDataL(rootDir, KEntryAttNormal, ESortNone);
84 CDir* entryList = NULL;
87 TRAPD(err, dirScan->NextL(entryList));
88 if(err == KErrNotReady)
90 INFO_PRINTF2(_L("Drive %S not ready"), &rootDir);
97 CleanupStack::PushL(entryList);
100 for(index = 0; index < entryList->Count(); ++index)
102 const TEntry& entry = (*entryList)[index];
103 filename = dirScan->FullPath();
104 filename.Append(entry.iName);
105 INFO_PRINTF1(_L("\n"));
106 INFO_PRINTF2(_L("The next file name in the dir-scan = %S"), &filename);
107 INFO_PRINTF1(_L("Calling 8-bit versions"));
109 // To keep VC compiler happy as it does not support
110 // explicit template calls.Hence passing empty variables
111 // cUri8 and tUriParser8
113 TUriParser8 tUriParser8;
114 TestBothWaysL(cUri8, tUriParser8, filename);
115 INFO_PRINTF1(_L("\n"));
116 INFO_PRINTF1(_L("Calling 16-bit versions"));
117 CUri16* cUri16 = NULL;
118 TUriParser16 tUriParser16;
119 TestBothWaysL(cUri16, tUriParser16, filename);
121 CleanupStack::PopAndDestroy(entryList);
125 CleanupStack::PopAndDestroy(dirScan);
130 Template function that calls CUri::CreateFileUriL to generate a URI and
131 calls TUriC::GetFileNameL() with this URI, to verify that the filename so got
132 is the same as the original one.
134 template <class CUriType, class TUriParserType>
135 void CTestForAllFilesStep::TestBothWaysL(CUriType*& cUri8Or16, TUriParserType& tUriParser8Or16, TFileName& aFileName)
137 TUint flags = KErrNone;
138 TDriveNumber driveNum;
140 parser.Set(aFileName, 0, 0);
141 TBuf<1> drive = parser.Drive().Left(1);
144 CTestFileUriServer::GetDriveNumber(drive, driveNum);
146 TInt err = CTestFileUriServer::IsRemovableDrive(driveNum, aResult);
149 ERR_PRINTF2(_L("Error occured while checking whether drive is removable: %D"), err);
150 SetTestStepResult(EFail);
155 {// The drive is a removable drive
156 INFO_PRINTF1(_L("The drive is a removable drive"));
161 TRAPD(err, cUri8Or16 = CUriType::CreateFileUriL(aFileName, flags));
165 ERR_PRINTF2(_L("Error occured in CreateFileUriL: %D"), err);
166 SetTestStepResult(EFail);
170 CleanupStack::PushL(cUri8Or16);
171 // Just in case, create a 16-bit heap desc and print.
172 HBufC16* tempBuf = HBufC16::NewL(cUri8Or16->Uri().UriDes().Length());
173 tempBuf->Des().Copy(cUri8Or16->Uri().UriDes());
174 INFO_PRINTF2(_L("File URI returned by CreateFileUriL = %S"), tempBuf);
179 TBuf<1> correctDrive;
180 err = CTestFileUriServer::FirstRemovableDriveWithSameFileName(aFileName, correctDrive);
183 ERR_PRINTF2(_L("Error occured in FirstRemovableDriveWithSameFileName: %D"), err);
184 SetTestStepResult(EFail);
188 correctDrive.LowerCase();
189 if(correctDrive != drive)
191 aFileName.Replace(0, 1, correctDrive);
192 INFO_PRINTF1(_L("One more removable drive found with the same file name, but is ahead in alphabetical order"));
193 INFO_PRINTF2(_L("Hence the correct expected file name is %S"), aFileName);
198 // Convert the URI to filename back again
199 HBufC16* returnedFileName = NULL;
201 tUriParser8Or16.Parse(cUri8Or16->Uri().UriDes());
202 TRAPD(err, returnedFileName = tUriParser8Or16.GetFileNameL());
203 CleanupStack::PopAndDestroy(cUri8Or16);
206 ERR_PRINTF2(_L("Error occured in GetFileNameL: %D"), err);
207 SetTestStepResult(EFail);
211 INFO_PRINTF2(_L("The filename returned by GetFileNameL = %S"), returnedFileName);
214 aFileName.LowerCase();
215 returnedFileName->Des().LowerCase();
217 if(returnedFileName->Compare(aFileName) != KErrNone)
219 INFO_PRINTF1(_L("The returned filename did not match the original filename. Result = INCORRECT"));
220 SetTestStepResult(EFail);
224 INFO_PRINTF1(_L("The returned filename is same as the original filename. Result = CORRECT"));
226 delete returnedFileName;