os/ossrv/genericservices/httputils/Test/t_fileuri/CFileUriTest.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/httputils/Test/t_fileuri/CFileUriTest.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,574 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Note : Testing for file uri component extraction for external media drive will be done only 
    1.18 +// if an external media drive does exist
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include "CFileUriTest.h"
    1.23 +
    1.24 +#include <e32base.h>
    1.25 +#include <escapeutils.h>
    1.26 +#include "FileUriTestCommon.h"
    1.27 +
    1.28 +//File URI Constents
    1.29 +_LIT8(KFileUriScheme8, "file");
    1.30 +_LIT16(KFileUriScheme16, "file");
    1.31 +
    1.32 +//
    1.33 +//
    1.34 +//	File Uri Tests
    1.35 +//
    1.36 +//
    1.37 +
    1.38 +CFileUriTest* CFileUriTest::NewLC(CIpuTestHarness* aTestHarness)
    1.39 +	{
    1.40 +	CFileUriTest* self = new (ELeave) CFileUriTest(aTestHarness);
    1.41 +	CleanupStack::PushL(self);
    1.42 +	self->ConstructL();
    1.43 +	return self;
    1.44 +	}
    1.45 +
    1.46 +CFileUriTest* CFileUriTest::NewL(CIpuTestHarness* aTestHarness)
    1.47 +	{
    1.48 +	CFileUriTest* self = CFileUriTest::NewLC(aTestHarness);
    1.49 +	CleanupStack::Pop(self);
    1.50 +	return self;
    1.51 +	}
    1.52 +
    1.53 +CFileUriTest::CFileUriTest(CIpuTestHarness* aTestHarness)
    1.54 +: iTestHarness(aTestHarness)
    1.55 +	{
    1.56 +	}
    1.57 +
    1.58 +void CFileUriTest::ConstructL()
    1.59 +	{
    1.60 +	}
    1.61 +
    1.62 +CFileUriTest::~CFileUriTest()
    1.63 +	{
    1.64 +	}
    1.65 +
    1.66 +void CFileUriTest::DoTestsL()
    1.67 +	{
    1.68 +	TBuf<3> drive(_L("$:\\"));
    1.69 +	//File URI Creation Test - for public files on fixed and removable media 
    1.70 +	//----------------------------------------------------------------------------------
    1.71 +	_LIT(KFullFileName, "c:\\public\\bar\\foo\\some\\randomness.txt");
    1.72 +	
    1.73 +	//Testing 8-bit & 16-bit File URI creation for public file on a fixed drive
    1.74 +	_LIT(KExpectedUri, "file://c/public/bar/foo/some/randomness.txt");
    1.75 +	TestFileUriCreationL(KFullFileName, KExpectedUri, 0);
    1.76 +	
    1.77 +	_LIT(KFullFileName2, "c:\\dummy\\file.txt");
    1.78 + 	_LIT(KExpectedUri3, "file://c/dummy/file.txt");
    1.79 +	TestFileUriCreationL(KFullFileName2, KExpectedUri3, 0);
    1.80 +
    1.81 +	_LIT(KFullFileName1, "c:\\randomness.txt");
    1.82 +	
    1.83 +	//Testing 8-bit & 16-bit File URI creation for public file on a fixed drive
    1.84 +	_LIT(KExpectedUri2, "file://c/randomness.txt");
    1.85 +	TestFileUriCreationL(KFullFileName1, KExpectedUri2, 0);
    1.86 +
    1.87 +	//Testing 8-bit & 16-bit File URI creation for public file on a removable media drive
    1.88 +	_LIT(KExpectedUri1, "file://ext-media/public/bar/foo/some/randomness.txt");
    1.89 +	TestFileUriCreationL(KFullFileName, KExpectedUri1, EExtMedia);
    1.90 +	
    1.91 +	_LIT(KExtMediaFullFileName, "X:\\mydir\\myfile.ext");
    1.92 +	_LIT(KExtMediaExpectedUri1, "file://ext-media/mydir/myfile.ext");
    1.93 +	TestFileUriCreationL(KExtMediaFullFileName, KExtMediaExpectedUri1, EExtMedia);
    1.94 +	//----------------------------------------------------------------------------------
    1.95 +
    1.96 +	//File URI component extraction Test - Schema, Path and Filename - 
    1.97 +	// - for public files on fixed and removable media 
    1.98 +	//----------------------------------------------------------------------------------
    1.99 +	_LIT(KFileName, "c:\\public\\bar\\foo\\some\\randomness.txt");
   1.100 +	
   1.101 +	//Testing 8-bit & 16-bit File URI creation for public file on a fixed drive
   1.102 +	_LIT(KExpectedPath, "/c/public/bar/foo/some/randomness.txt");
   1.103 +	TestFileUriComponentExtractionL(KFileName, KExpectedPath, KFileName, drive, 0);
   1.104 +	
   1.105 +	//Testing 8-bit & 16-bit File URI creation for public file on a fixed drive
   1.106 +	_LIT(KFileName1, "c:\\system\\·····.ini");
   1.107 +	_LIT(KExpectedPath1, "/c/system/·····.ini");
   1.108 +	TestFileUriComponentExtractionL(KFileName1, KExpectedPath1, KFileName1, drive, 0);
   1.109 +
   1.110 +	//Creating files on removable media drive (X:) 
   1.111 +	// Need to change the removable Drive letter if X doesn't exist or its not removable media drive  	
   1.112 +	RFs fs;
   1.113 +	User::LeaveIfError(fs.Connect());
   1.114 +	CleanupClosePushL(fs);
   1.115 +	TDriveInfo driveInfo;
   1.116 +	TInt err = KErrNotFound;
   1.117 +	TInt driveNum = EDriveA;
   1.118 +	
   1.119 +	//Checking for extenal media drive does exist
   1.120 +	for (; driveNum <= EDriveZ && err!=KErrNone; driveNum++)   
   1.121 +		{
   1.122 +		if (fs.Drive(driveInfo, driveNum ) == KErrNone
   1.123 +			&& (driveInfo.iDriveAtt & KDriveAttRemovable))       
   1.124 +			{
   1.125 +			drive[0]= TInt16('A' + driveNum);
   1.126 +			err = KErrNone;
   1.127 +			}
   1.128 +		}
   1.129 +	
   1.130 +	// Test only if external media drive exist
   1.131 +  	if (err == KErrNone)
   1.132 +  		{
   1.133 +  	 	driveNum--;
   1.134 +  			
   1.135 +		User::LeaveIfError(fs.SetSessionPath(drive));
   1.136 +		TInt ret = fs.MkDir(_L("\\mydir\\"));
   1.137 +		if (ret == KErrNone || ret == KErrAlreadyExists)
   1.138 +			{		
   1.139 +			RFile file;
   1.140 +			ret = file.Create(fs,_L("\\mydir\\myfile.ext"),EFileWrite|EFileShareAny);
   1.141 +			file.Close();
   1.142 +			if (ret == KErrNone || ret == KErrAlreadyExists)
   1.143 +				{		
   1.144 +				//Testing 8-bit & 16-bit File URI creation for public file on a removable media drive
   1.145 +				_LIT(KExpectedExtMediaPath1, "/ext-media/mydir/myfile.ext");
   1.146 +				TFileName extMediaFileName(KExtMediaFullFileName);
   1.147 +				extMediaFileName[0] = drive[0];
   1.148 +				TestFileUriComponentExtractionL(extMediaFileName, KExpectedExtMediaPath1, extMediaFileName, drive, EExtMedia);
   1.149 +				CFileMan* fm = CFileMan::NewL(fs);
   1.150 +				ret = fm->RmDir(_L("\\mydir\\"));
   1.151 +				delete fm;	
   1.152 +				}
   1.153 +			}
   1.154 +		}	
   1.155 +	
   1.156 +	CleanupStack::PopAndDestroy(&fs);
   1.157 +	//----------------------------------------------------------------------------------
   1.158 +  	  		
   1.159 +	//File URI component extraction, obj created using CUri::NewLC Test 
   1.160 +	// - Schema, Path and Filename
   1.161 +	//----------------------------------------------------------------------------------
   1.162 +	
   1.163 +	TestFileUriCreationWithOldAPIAndComponentExtractionL(KFileName, KExpectedPath, KFileName );
   1.164 +		
   1.165 +	//----------------------------------------------------------------------------------
   1.166 +  		
   1.167 +	// resolve %-codes
   1.168 +	TestFileUriNameExtractionL(_L("file://c/dir/test/file%20name.html"), _L("file name.html"), _L("\\dir\\test\\file name.html") );
   1.169 +	// params in path
   1.170 +	TestFileUriNameExtractionL(_L("http://www.text.org/cgi-bin/apps/index.html;one;two;three"), _L("index.html"), _L("\\cgi-bin\\apps\\index.html") );
   1.171 +
   1.172 +	// resolve %-codes
   1.173 +	TestFileUriNameExtractionL(_L8("file://c/dir/test/file%20name.html"), _L("file name.html"), _L("\\dir\\test\\file name.html") );
   1.174 +	
   1.175 +	// params in path
   1.176 +	TestFileUriNameExtractionL(_L8("http://www.text.org/cgi-bin/apps/index.html;one;two;three"), _L("index.html"), _L("\\cgi-bin\\apps\\index.html") );
   1.177 +	
   1.178 +	//----------------------------------------------------------------------------------
   1.179 +
   1.180 +
   1.181 +				
   1.182 +	//File URI Creation Test - for private files on fixed and removable media 
   1.183 +	//----------------------------------------------------------------------------------
   1.184 +	
   1.185 +	//Testing 8-bit & 16-bit File URI creation for private file on a fixed drive
   1.186 +	_LIT(KExpectedprivateUri, "file://private/Z/bar/foo/some/randomness.txt");
   1.187 +	
   1.188 +	_LIT(KRelativeFileName, "c:\\bar\\foo\\some\\randomness.txt");
   1.189 +	TestPrivateFileUriCreationL(KRelativeFileName, EDriveZ, KExpectedprivateUri, 0);
   1.190 +	
   1.191 +	_LIT(KRelativeFileName1, "\\bar\\foo\\some\\randomness.txt");
   1.192 +	TestPrivateFileUriCreationL(KRelativeFileName1, EDriveZ, KExpectedprivateUri, 0);
   1.193 +	
   1.194 +	_LIT(KRelativeFileName2, "bar\\foo\\some\\randomness.txt");
   1.195 +	TestPrivateFileUriCreationL(KRelativeFileName2, EDriveZ, KExpectedprivateUri, 0);
   1.196 +	
   1.197 +	//Testing 8-bit & 16-bit File URI creation for private file on a removable media drive
   1.198 +	_LIT(KExtMediaRelativeFileName, "\\mydir\\myfile.ext");
   1.199 +	_LIT(KExpectedPrivateExtMediaUri, "file://private/ext-media/mydir/myfile.ext");
   1.200 +	TestPrivateFileUriCreationL(KExtMediaRelativeFileName, EDriveZ, KExpectedPrivateExtMediaUri, EExtMedia);
   1.201 +	//----------------------------------------------------------------------------------
   1.202 +			
   1.203 +	//File URI component extraction Test - Schema, Path and Filename - 
   1.204 +	// - for private files on fixed and removable media 
   1.205 +	//----------------------------------------------------------------------------------
   1.206 +	
   1.207 +	//Retrieveing application private path
   1.208 +	
   1.209 +	User::LeaveIfError(fs.Connect());
   1.210 +	CleanupClosePushL(fs);		
   1.211 +	TPath applPrivatePath;
   1.212 +	User::LeaveIfError(fs.PrivatePath(applPrivatePath));
   1.213 +	CleanupStack::PopAndDestroy(&fs);
   1.214 +		
   1.215 +	//Testing 8-bit & 16-bit File URI creation for private file on a fixed drive
   1.216 +	_LIT(KExpectedPrivateFilePath, "/private/Z/bar/foo/some/randomness.txt");
   1.217 +	_LIT(KExpectedPrivateFileName, "bar\\foo\\some\\randomness.txt");
   1.218 +	TFileName expectedPrivateFileName(_L("Z:"));
   1.219 +	expectedPrivateFileName.Append(applPrivatePath);
   1.220 +	expectedPrivateFileName.Append(KExpectedPrivateFileName);
   1.221 +	
   1.222 +	TestPrivateFileUriComponentExtractionL(KRelativeFileName1, EDriveZ, KExpectedPrivateFilePath, expectedPrivateFileName, 0);
   1.223 +		
   1.224 +	//Testing 8-bit & 16-bit File URI creation for private file on a removable media drive
   1.225 +	_LIT(KExpectedPrivateExtMediaFilePath, "/private/ext-media/mydir/myfile.ext");
   1.226 +	expectedPrivateFileName[0] = drive[0];
   1.227 +	
   1.228 +	//Since we can't create folder "private" on removable media drive for testing purpose, the file extraction testing is not possible.
   1.229 +	// So need to pass KNullDesC to avoid file extraction
   1.230 +	TestPrivateFileUriComponentExtractionL(KExtMediaRelativeFileName, EDriveZ, KExpectedPrivateExtMediaFilePath, KNullDesC, EExtMedia);
   1.231 +	//----------------------------------------------------------------------------------
   1.232 +	}
   1.233 +	
   1.234 +void CFileUriTest::TestFileUriCreationL(const TDesC16& aFullFileName, const TDesC16& aExpectedUri, TUint aFlags) const
   1.235 +	{
   1.236 +	//Testing 8-bit File URI creation for public file on a fixed drive	
   1.237 +	iTestHarness->StartTestL(_L("Test CUri - Public File URI creation (8bit)"));
   1.238 +	iTestHarness->LogIt(_L("FileName: %S; \n\t\tFileStorageType:%D; \n\t\tExpected URI:%S"), &aFullFileName, aFlags, &aExpectedUri);
   1.239 +	TInt error = KErrNone;
   1.240 +	CUri8* uri8 = CUri8::CreateFileUriL(aFullFileName,aFlags);
   1.241 +	CleanupStack::PushL(uri8);
   1.242 +	HBufC8* expectedUri8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aExpectedUri);
   1.243 +	CleanupStack::PushL(expectedUri8);
   1.244 +	error = DoFileUriExtraction<CUri8>(*uri8, *expectedUri8);
   1.245 +	CleanupStack::PopAndDestroy(expectedUri8);
   1.246 +	CleanupStack::PopAndDestroy(uri8);
   1.247 +	iTestHarness->EndTest(error);
   1.248 +	
   1.249 +	//Testing 16-bit File URI creation for public file on a fixed drive
   1.250 +	error = KErrNone;
   1.251 +	iTestHarness->StartTestL(_L("Test CUri - File URI creation (16bit)"));
   1.252 +	iTestHarness->LogIt(_L("FileName: %S; \n\t\tFileType:%D; \n\t\tExpected URI:%S"), &aFullFileName, aFlags, &aExpectedUri);
   1.253 +	CUri16* uri16 = CUri16::CreateFileUriL(aFullFileName,aFlags);
   1.254 +	CleanupStack::PushL(uri16);
   1.255 +	error = DoFileUriExtraction<CUri16>(*uri16, aExpectedUri);
   1.256 +	CleanupStack::PopAndDestroy(uri16);
   1.257 +	iTestHarness->EndTest(error);
   1.258 +	}
   1.259 +
   1.260 +void CFileUriTest::TestPrivateFileUriCreationL(const TDesC16& aRelativeFileName, const TDriveNumber aDrive, const TDesC16& aExpectedUri, TUint aFlags) const
   1.261 +	{
   1.262 +	//Testing 8-bit File URI creation for public file on a fixed drive
   1.263 +	iTestHarness->StartTestL(_L("Test CUri - Private File URI creation (8bit)"));
   1.264 +	iTestHarness->LogIt(_L("FileName: %S; \n\t\tFileStorageType:%D; \n\t\tDrive:%c; \n\t\tExpectedURI:%S"), &aRelativeFileName, aFlags, ('A' + aDrive), &aExpectedUri);
   1.265 +	TInt error = KErrNone;
   1.266 +	CUri8* uri8 = CUri8::CreatePrivateFileUriL(aRelativeFileName,aDrive,aFlags);
   1.267 +	CleanupStack::PushL(uri8);
   1.268 +	HBufC8* expectedUri8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aExpectedUri);
   1.269 +	error = DoFileUriExtraction<CUri8>(*uri8, *expectedUri8);
   1.270 +	delete expectedUri8;
   1.271 +	CleanupStack::PopAndDestroy(uri8);
   1.272 +	iTestHarness->EndTest(error);
   1.273 +
   1.274 +	//Testing 16-bit File URI creation for public file on a fixed drive
   1.275 +	error = KErrNone;
   1.276 +	iTestHarness->StartTestL(_L("Test CUri - Private File URI creation (16bit)"));
   1.277 +	iTestHarness->LogIt(_L("FileName: %S; \n\t\tFileStorageType:%D; \n\t\tDrive:%c; \n\t\tExpectedURI:%S"), &aRelativeFileName, aFlags, ('A' + aDrive), &aExpectedUri);
   1.278 +	CUri16* uri16 = CUri16::CreatePrivateFileUriL(aRelativeFileName,aDrive,aFlags);
   1.279 +	CleanupStack::PushL(uri16);
   1.280 +	error = DoFileUriExtraction<CUri16>(*uri16, aExpectedUri);
   1.281 +	CleanupStack::PopAndDestroy(uri16);
   1.282 +	iTestHarness->EndTest(error);	
   1.283 +	}
   1.284 +
   1.285 +void CFileUriTest::TestFileUriComponentExtractionL(const TDesC16& aFileName, const TDesC16& aPath, const TDesC16& aExpectedFileName, const TDesC16& aExpectedDrive, TUint aFlags) const
   1.286 +	{
   1.287 +	iTestHarness->StartTestL(_L("Test File Uri Component Extraction (8-bit)"));
   1.288 +	iTestHarness->LogIt(_L("FileName: %S; \n\t\tFileStorageType:%D; \n\t\tPath:%S"), &aFileName,aFlags, &aPath);
   1.289 +	HBufC8* fileUriScheme8 = HBufC8::NewLC(4);
   1.290 +	fileUriScheme8->Des().Copy(KFileUriScheme8);
   1.291 +	
   1.292 +	HBufC* fileUriScheme16 = HBufC::NewLC(4);
   1.293 +	fileUriScheme16->Des().Copy(KFileUriScheme16);
   1.294 +
   1.295 +	RFs fs;
   1.296 +	User::LeaveIfError(fs.Connect());
   1.297 +	CleanupClosePushL(fs);
   1.298 +	CFileMan *fm = CFileMan::NewL(fs);
   1.299 +	CleanupStack::PushL(fm);
   1.300 +	
   1.301 +	TInt len = aFileName.Length();
   1.302 +	TInt ret = 0;
   1.303 +
   1.304 +	//Testing 8-bit File URI componet extraction for public file on a fixed drive
   1.305 +	TInt error = KErrNone;
   1.306 +	
   1.307 +	CUri8* uri8 = CUri8::CreateFileUriL(aFileName,aFlags);
   1.308 +	CleanupStack::PushL(uri8);
   1.309 +	
   1.310 +	HBufC8* path8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aPath);
   1.311 +	CleanupStack::PushL(path8);
   1.312 +		
   1.313 +	HBufC8* escapedUriPath8 = EscapeUtils::EscapeEncodeL(*path8, EscapeUtils::EEscapeNormal);
   1.314 +	CleanupStack::PushL(escapedUriPath8);
   1.315 +	
   1.316 +	error = DoFileUriComponentExtraction<TUriParser8, CUri8>(*uri8, *fileUriScheme8, *escapedUriPath8, aExpectedFileName);
   1.317 +	
   1.318 +	iTestHarness->EndTest(error);	
   1.319 +	
   1.320 +	//-ve testing : After renaming file it should return error	
   1.321 +	if (aFlags == EExtMedia && error == KErrNone)
   1.322 +		{
   1.323 +		iTestHarness->StartTestL(_L("EXT-MEDIA::Test File Uri Component Extraction(8-bit)"));
   1.324 +		iTestHarness->LogIt(_L("FileName: %S; \n\t\tFileStorageType:%D; \n\t\tPath:%S; \n\t\tExpectedDrive:%S"), &aFileName,aFlags, &aPath, &aExpectedDrive);
   1.325 +	
   1.326 +		error = KErrNotFound;
   1.327 +		User::LeaveIfError(fs.SetSessionPath(aExpectedDrive));
   1.328 +		ret = fm->Rename(aFileName,(aFileName.Left(len-4)));
   1.329 +		
   1.330 +		if (ret == KErrNone || ret == KErrAlreadyExists)
   1.331 +			{
   1.332 +			TRAP(error, (DoFileUriComponentExtraction<TUriParser8, CUri8>(*uri8, *fileUriScheme8, *path8, aExpectedFileName)));
   1.333 +			error = ((error != KErrNone) ? 0 : -1);		
   1.334 +			ret = fm->Rename(aFileName.Left(aFileName.Length()-4),aFileName,CFileMan::EOverWrite);
   1.335 +			}
   1.336 +	
   1.337 +		iTestHarness->EndTest(error);	
   1.338 +		}
   1.339 +	
   1.340 +	//Testing 16-bit File URI componet extraction for public file on a removable media drive
   1.341 +	iTestHarness->StartTestL(_L("Test File Uri Component Extraction (16-bit)"));
   1.342 +	iTestHarness->LogIt(_L("FileName: \n\t\t%S; \n\t\tFileStorageType:%D; \n\t\tPath:%S"), &aFileName, aFlags, &aPath);
   1.343 +	
   1.344 +	CUri16* uri16 = CUri16::CreateFileUriL(aFileName,aFlags);
   1.345 +	CleanupStack::PushL(uri16);
   1.346 +	
   1.347 +	HBufC* escapedUriPath = HBufC::NewLC(escapedUriPath8->Length());
   1.348 +	escapedUriPath->Des().Copy(*escapedUriPath8);
   1.349 +	
   1.350 +	error = DoFileUriComponentExtraction<TUriParser16, CUri16, TDesC16>(*uri16, *fileUriScheme16, *escapedUriPath, aExpectedFileName);
   1.351 +	
   1.352 +	iTestHarness->EndTest(error);
   1.353 +	
   1.354 +	//-ve testing : After renaming file it should return error
   1.355 +	if (aFlags == EExtMedia && error == KErrNone)
   1.356 +		{
   1.357 +		iTestHarness->StartTestL(_L(" EXT-MEDIA::Test File Uri Component Extraction(16-bit)"));
   1.358 +		iTestHarness->LogIt(_L("FileName: %S; \n\t\tFileStorageType:%D; \n\t\tPath:%S; \n\t\tExpectedDrive:%S"), &aFileName,aFlags, &aPath, &aExpectedDrive);
   1.359 +	
   1.360 +		error = KErrNotFound;
   1.361 +		User::LeaveIfError(fs.SetSessionPath(aExpectedDrive));
   1.362 +		ret = fm->Rename(aFileName,(aFileName.Left(len-4)));
   1.363 +	
   1.364 +		if (ret == KErrNone || ret == KErrAlreadyExists)
   1.365 +			{			
   1.366 +			TRAP(error, (DoFileUriComponentExtraction<TUriParser16, CUri16, TDesC16>(*uri16, *fileUriScheme16, aPath, aExpectedFileName)));
   1.367 +			error = ((error != KErrNone) ? 0 : -1);		
   1.368 +			ret = fm->Rename(aFileName.Left(aFileName.Length()-4),aFileName,CFileMan::EOverWrite);
   1.369 +			}
   1.370 +	
   1.371 +		iTestHarness->EndTest(error);
   1.372 +		}
   1.373 +
   1.374 +	CleanupStack::PopAndDestroy(escapedUriPath);
   1.375 +	CleanupStack::PopAndDestroy(uri16);
   1.376 +	CleanupStack::PopAndDestroy(escapedUriPath8);
   1.377 +	CleanupStack::PopAndDestroy(path8);
   1.378 +	CleanupStack::PopAndDestroy(uri8);	
   1.379 +	CleanupStack::PopAndDestroy(4, fileUriScheme8); //fileUriScheme8, fileUriScheme16,fs,fm 		
   1.380 +	}
   1.381 +	
   1.382 +void CFileUriTest::TestPrivateFileUriComponentExtractionL(const TDesC16& aFileName, const TDriveNumber aDrive, const TDesC16& aPath, const TDesC16& aExpectedFileName, TUint aFlags) const
   1.383 +	{
   1.384 +	iTestHarness->StartTestL(_L("Test Private File Uri Component Extraction (8-bit)"));
   1.385 +	iTestHarness->LogIt(_L("FileName: %S; \n\t\tDrive:%c, \n\t\tFileStorageType:%D; \n\t\tPath:%S"), &aFileName, ('A' + aDrive), aFlags, &aPath);
   1.386 +	TInt error = KErrNone;
   1.387 +	HBufC8* fileUriScheme8 = HBufC8::NewLC(4);
   1.388 +	TPtr8 fileUriScheme8Ptr = fileUriScheme8->Des();
   1.389 +	fileUriScheme8Ptr.Copy(KFileUriScheme8);
   1.390 +	HBufC* fileUriScheme16 = HBufC::NewLC(4);
   1.391 +	TPtr16 fileUriScheme16Ptr = fileUriScheme16->Des();
   1.392 +	fileUriScheme16Ptr.Copy(KFileUriScheme16);
   1.393 +	
   1.394 +	//Testing 8-bit File URI componet extraction for private file on a fixed drive
   1.395 +	CUri8* prv_uri8 = CUri8::CreatePrivateFileUriL(aFileName,aDrive,aFlags);
   1.396 +	CleanupStack::PushL(prv_uri8);
   1.397 +	HBufC8* path8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aPath);
   1.398 +	error = DoFileUriComponentExtraction<TUriParser8>(*prv_uri8, *fileUriScheme8, *path8, aExpectedFileName);
   1.399 +	delete path8;
   1.400 +	CleanupStack::PopAndDestroy(prv_uri8);	
   1.401 +	iTestHarness->EndTest(error);	
   1.402 +	
   1.403 +	//Testing 16-bit File URI componet extraction for private file on a removable media drive
   1.404 +	iTestHarness->StartTestL(_L("Test Private File Uri Component Extraction (16-bit)"));
   1.405 +	iTestHarness->LogIt(_L("FileName: %S; \n\t\tDrive:%c, \n\t\tFileStorageType:%D; \n\t\tPath:%S"), &aFileName, ('A' + aDrive), aFlags, &aPath);
   1.406 +	CUri16* prv_uri16 = CUri16::CreatePrivateFileUriL(aFileName,aDrive,aFlags);
   1.407 +	CleanupStack::PushL(prv_uri16);
   1.408 +	error = DoFileUriComponentExtraction<TUriParser16, CUri16, TDesC16>(*prv_uri16, *fileUriScheme16, aPath, aExpectedFileName);
   1.409 +	CleanupStack::PopAndDestroy(prv_uri16);
   1.410 +	iTestHarness->EndTest(error);
   1.411 +	
   1.412 +	CleanupStack::PopAndDestroy(2, fileUriScheme8); //fileUriScheme8, fileUriScheme16 	
   1.413 +	}
   1.414 +
   1.415 +void CFileUriTest::TestFileUriCreationWithOldAPIAndComponentExtractionL(const TDesC16& aFileName, const TDesC16& aPath, const TDesC16& aExpectedFileName) const
   1.416 +	{	
   1.417 +	//Testing File URI componet extraction created using CUri::NewLC()
   1.418 +	iTestHarness->StartTestL(_L("Test File Uri Component Extraction created using NewLC (8-bit)"));
   1.419 +	iTestHarness->LogIt(_L("FileName: %S; \n\t\tPath:%S"), &aFileName, &aPath);	
   1.420 +	TInt error = KErrNone;
   1.421 +	HBufC8* fileUriScheme8 = HBufC8::NewLC(4);
   1.422 +	TPtr8 fileUriScheme8Ptr = fileUriScheme8->Des();
   1.423 +	fileUriScheme8Ptr.Copy(KFileUriScheme8);
   1.424 +	HBufC* fileUriScheme16 = HBufC::NewLC(4);
   1.425 +	TPtr16 fileUriScheme16Ptr = fileUriScheme16->Des();
   1.426 +	fileUriScheme16Ptr.Copy(KFileUriScheme16);
   1.427 +	
   1.428 +	_LIT8(KFileUri8, "file://%S");
   1.429 +	HBufC8* path8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aPath);
   1.430 +	CleanupStack::PushL(path8);
   1.431 +	HBufC8 *fileUri8 = HBufC8::NewLC((path8->Length()+10));
   1.432 +	TPtr8 fileUri8Ptr = fileUri8->Des();
   1.433 +	fileUri8Ptr.AppendFormat(KFileUri8,path8);
   1.434 +	TUriParser8 urip8;
   1.435 +	urip8.Parse(*fileUri8);
   1.436 +	CUri8* _uri8 = CUri8::NewLC(urip8); 
   1.437 +	error = DoFileUriComponentExtraction<TUriParser8, CUri8, TDesC8>(*_uri8, *fileUriScheme8, *path8, aExpectedFileName);
   1.438 +	CleanupStack::PopAndDestroy(_uri8);
   1.439 +	iTestHarness->EndTest(error);
   1.440 +
   1.441 +	iTestHarness->StartTestL(_L("Test File Uri Component Extraction created using NewLC (16-bit)"));
   1.442 +	iTestHarness->LogIt(_L("FileName: %S; \n\t\tFileStorageType:2; \n\t\tPath:%S"), &aFileName, &aPath);
   1.443 +	HBufC *fileUri16 = EscapeUtils::ConvertToUnicodeFromUtf8L(*fileUri8);
   1.444 +	CleanupStack::PushL(fileUri16);
   1.445 +	TUriParser16 urip16;
   1.446 +	urip16.Parse(*fileUri16);
   1.447 +	CUri16* _uri16 = CUri16::NewLC(urip16);  
   1.448 +	error = DoFileUriComponentExtraction<TUriParser16, CUri16, TDesC16>(*_uri16, *fileUriScheme16, aPath, aExpectedFileName);
   1.449 +	CleanupStack::PopAndDestroy(_uri16);
   1.450 +	iTestHarness->EndTest(error);
   1.451 +	
   1.452 +	CleanupStack::PopAndDestroy(5, fileUriScheme8); //fileUriScheme8, fileUriScheme16, path8, fileUri8, fileUri16  	
   1.453 +	}
   1.454 +	
   1.455 +//
   1.456 +//
   1.457 +//	Implementation of LOCAL functions
   1.458 +//
   1.459 +//
   1.460 +template<class CUriType, class TDesCType>
   1.461 +TInt DoFileUriExtraction(const CUriType& aUri, const TDesCType& aExpectedFileUri)
   1.462 +	{
   1.463 +	TInt error = 0;
   1.464 +	
   1.465 +	// Check file URI...
   1.466 +	error = aUri.Uri().UriDes().Compare(aExpectedFileUri);
   1.467 +	if( error != 0 )
   1.468 +		{
   1.469 +		return error;
   1.470 +		}
   1.471 +	return KErrNone;
   1.472 +	}
   1.473 +
   1.474 +template<class TUriParserType, class CUriType, class TDesCType, class TDesCType16>
   1.475 +TInt DoFileUriComponentExtraction(const CUriType& aUri, const TDesCType& aScheme, const TDesCType& aPath, const TDesCType16& aExpectedFileName)
   1.476 +	{
   1.477 +	TUriParserType uriParser;
   1.478 +	TInt error = uriParser.Parse(aUri.Uri().UriDes());
   1.479 +	// Is this a valid Uri?
   1.480 +	if( error == KUriUtilsErrInvalidUri )
   1.481 +		{
   1.482 +		return error;
   1.483 +		}
   1.484 +
   1.485 +	// Check scheme...
   1.486 +	if( (error = TestComponent(uriParser, aScheme, EUriScheme)) != 0 )
   1.487 +		{
   1.488 +		return error;
   1.489 +		}
   1.490 +	
   1.491 +	// Check path...
   1.492 +	if( (error = TestComponent(uriParser, aPath, EUriPath)) != 0)
   1.493 +		{
   1.494 +		return error;
   1.495 +		}
   1.496 +	
   1.497 +	if (aExpectedFileName.Length() > 0)
   1.498 +		{
   1.499 +		HBufC* tmpFileName = uriParser.GetFileNameL();
   1.500 +		error = tmpFileName->Compare(aExpectedFileName);
   1.501 +		delete tmpFileName;
   1.502 +		if (error != 0)
   1.503 +			{
   1.504 +			return error;
   1.505 +			}
   1.506 +		}	
   1.507 +		
   1.508 +	return KErrNone;
   1.509 +	}
   1.510 +	
   1.511 +template<class TParserType, class TDesCType, class TComponentType>
   1.512 +TInt TestComponent(const TParserType& aParser, const TDesCType& aExpected, TComponentType aComponent)
   1.513 +	{
   1.514 +	return aParser.Extract(aComponent).Compare(aExpected);
   1.515 +	}
   1.516 +	
   1.517 +
   1.518 +void CFileUriTest::TestFileUriNameExtractionL(const TDesC& aUri, const TDesC& aFilename, const TDesC& aPath)
   1.519 +	{
   1.520 +	TUriParser uriParser;
   1.521 +	User::LeaveIfError(uriParser.Parse(aUri));
   1.522 +	
   1.523 +	HBufC* name;
   1.524 +	TInt error = KErrNone;
   1.525 +	
   1.526 +	iTestHarness->StartTestL(_L("Test extract file name from URI (16 bit)"));
   1.527 +	iTestHarness->LogIt(_L("URI: %S; \n\t\tExpected name:%S"), &uriParser.UriDes(), &aFilename);
   1.528 +
   1.529 +	name = uriParser.GetFileNameL(EUriFileNameTail);
   1.530 +	iTestHarness->LogIt(_L("Computed name:%S"), name);
   1.531 +	error = (aFilename.Compare(*name)==0) ? KErrNone : KErrBadName;
   1.532 +	delete name;
   1.533 +	
   1.534 +	iTestHarness->EndTest(error);
   1.535 +
   1.536 +	iTestHarness->StartTestL(_L("Test extract file path from URI (16 bit)"));
   1.537 +	iTestHarness->LogIt(_L("URI: %S; \n\t\tExpected Path:%S"), &uriParser.UriDes(), &aPath);
   1.538 +
   1.539 +	name = uriParser.GetFileNameL(EUriFileNamePath);
   1.540 +	iTestHarness->LogIt(_L("Computed Path:%S"), name);
   1.541 +	error = (aPath.Compare(*name)==0) ? KErrNone : KErrBadName;
   1.542 +	delete name;
   1.543 +	
   1.544 +	iTestHarness->EndTest(error);
   1.545 +	}
   1.546 +	
   1.547 +void CFileUriTest::TestFileUriNameExtractionL(const TDesC8& aUri, const TDesC& aFilename, const TDesC& aPath)
   1.548 +	{
   1.549 +	TUriParser8 uriParser;
   1.550 +	User::LeaveIfError(uriParser.Parse(aUri));
   1.551 +	
   1.552 +	HBufC* name;
   1.553 +	TInt error = KErrNone;
   1.554 +
   1.555 +	TFileName uri;
   1.556 +	uri.Copy(uriParser.UriDes()); // safe for all valid URIs
   1.557 +	iTestHarness->StartTestL(_L("Test extract file name from URI (8 bit)"));
   1.558 +	iTestHarness->LogIt(_L("URI: %S; \n\t\tExpected name:%S"), &uri, &aFilename);
   1.559 +
   1.560 +	name = uriParser.GetFileNameL(EUriFileNameTail);
   1.561 +	iTestHarness->LogIt(_L("Computed name:%S"), name);
   1.562 +	error = (aFilename.Compare(*name)==0) ? KErrNone : KErrBadName;
   1.563 +	delete name;
   1.564 +	
   1.565 +	iTestHarness->EndTest(error);
   1.566 +
   1.567 +	iTestHarness->StartTestL(_L("Test extract file path from URI (8 bit)"));
   1.568 +	iTestHarness->LogIt(_L("URI: %S; \n\t\tExpected Path:%S"), &uri, &aPath);
   1.569 +
   1.570 +	name = uriParser.GetFileNameL(EUriFileNamePath);
   1.571 +	iTestHarness->LogIt(_L("Computed Path:%S"), name);
   1.572 +	error = (aPath.Compare(*name)==0) ? KErrNone : KErrBadName;
   1.573 +	delete name;
   1.574 +	
   1.575 +	iTestHarness->EndTest(error);
   1.576 +	}
   1.577 +