os/ossrv/genericservices/httputils/Test/Integration/TestFileUriSuite/TestForAllFilesStep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// TESTGENERATEFILEURIFORALLFILESSTEP.CPP
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology 
sl@0
    21
*/
sl@0
    22
sl@0
    23
// Epoc Includes
sl@0
    24
// For File URI handler API
sl@0
    25
#include <uri16.h>
sl@0
    26
#include <uri8.h>
sl@0
    27
#include <escapeutils.h>
sl@0
    28
sl@0
    29
// User Include
sl@0
    30
#include "TestForAllFilesStep.h"
sl@0
    31
sl@0
    32
/**
sl@0
    33
Constructor. Sets the test step name
sl@0
    34
*/
sl@0
    35
CTestForAllFilesStep::CTestForAllFilesStep()
sl@0
    36
	{
sl@0
    37
	//Call base class method to set human readable name for test step
sl@0
    38
	SetTestStepName(KTestForAllFilesStep);
sl@0
    39
	}
sl@0
    40
sl@0
    41
/**
sl@0
    42
Does the main functionality of a test step. Here just calls DoTestL.
sl@0
    43
@internalTechnology 
sl@0
    44
@param		None
sl@0
    45
@return		EPass or EFail indicating the success or failure of the test step
sl@0
    46
*/
sl@0
    47
TVerdict CTestForAllFilesStep::doTestStepL()
sl@0
    48
	{
sl@0
    49
	__UHEAP_MARK;
sl@0
    50
	INFO_PRINTF1(_L("\n"));
sl@0
    51
	TRAPD(err, DoTestL());
sl@0
    52
	if(err != KErrNone)
sl@0
    53
		{
sl@0
    54
		ERR_PRINTF2(_L("Leave occured in CTestForAllFilesStep::DoTestL: %D"), err);
sl@0
    55
		SetTestStepResult(EFail);
sl@0
    56
		}
sl@0
    57
	INFO_PRINTF1(_L("\n"));	
sl@0
    58
	__UHEAP_MARKEND;
sl@0
    59
	return TestStepResult();	
sl@0
    60
	}		// doTestStepL()
sl@0
    61
sl@0
    62
/**
sl@0
    63
Scans all the directories and calls TestBothWaysL that tests the
sl@0
    64
creation of URI from a filename and vice versa for all the files.
sl@0
    65
*/
sl@0
    66
void CTestForAllFilesStep::DoTestL()
sl@0
    67
	{
sl@0
    68
	RFs fs;
sl@0
    69
	TInt err = fs.Connect();
sl@0
    70
	if(err != KErrNone)
sl@0
    71
		{
sl@0
    72
		ERR_PRINTF2(_L("Error occured while connecting to file server: %D"), err);
sl@0
    73
		SetTestStepResult(EFail);
sl@0
    74
		}
sl@0
    75
	else
sl@0
    76
		{
sl@0
    77
		TBuf<4> rootDir;
sl@0
    78
		CDirScan *dirScan = CDirScan::NewLC(fs);
sl@0
    79
		TInt drive;
sl@0
    80
		for(drive = EDriveA; drive <= EDriveZ; ++drive)
sl@0
    81
			{
sl@0
    82
			rootDir.Format(_L("%c:\\"), static_cast<char>(KLetterA + drive));
sl@0
    83
			dirScan->SetScanDataL(rootDir, KEntryAttNormal, ESortNone);
sl@0
    84
			CDir* entryList = NULL;
sl@0
    85
			FOREVER
sl@0
    86
				{
sl@0
    87
				TRAPD(err, dirScan->NextL(entryList));
sl@0
    88
				if(err == KErrNotReady)
sl@0
    89
					{
sl@0
    90
					INFO_PRINTF2(_L("Drive %S not ready"), &rootDir);
sl@0
    91
					break;
sl@0
    92
					}
sl@0
    93
				if (entryList==NULL)
sl@0
    94
					{
sl@0
    95
					break;
sl@0
    96
					}
sl@0
    97
				CleanupStack::PushL(entryList);
sl@0
    98
				TFileName filename;
sl@0
    99
				TInt index;
sl@0
   100
				for(index = 0; index < entryList->Count(); ++index)
sl@0
   101
					{
sl@0
   102
					const TEntry& entry = (*entryList)[index];
sl@0
   103
					filename = dirScan->FullPath();
sl@0
   104
					filename.Append(entry.iName);
sl@0
   105
					INFO_PRINTF1(_L("\n"));
sl@0
   106
					INFO_PRINTF2(_L("The next file name in the dir-scan = %S"), &filename);
sl@0
   107
					INFO_PRINTF1(_L("Calling 8-bit versions"));
sl@0
   108
					
sl@0
   109
					// To keep VC compiler happy as it does not support
sl@0
   110
					// explicit template calls.Hence passing empty variables 
sl@0
   111
					// cUri8 and tUriParser8
sl@0
   112
					CUri8* cUri8 = NULL;
sl@0
   113
					TUriParser8 tUriParser8;
sl@0
   114
					TestBothWaysL(cUri8, tUriParser8, filename);
sl@0
   115
					INFO_PRINTF1(_L("\n"));
sl@0
   116
					INFO_PRINTF1(_L("Calling 16-bit versions"));
sl@0
   117
					CUri16* cUri16 = NULL;
sl@0
   118
					TUriParser16 tUriParser16;
sl@0
   119
					TestBothWaysL(cUri16, tUriParser16, filename);
sl@0
   120
					}
sl@0
   121
				CleanupStack::PopAndDestroy(entryList);	
sl@0
   122
				}	// FOREVER
sl@0
   123
			}
sl@0
   124
		fs.Close();
sl@0
   125
		CleanupStack::PopAndDestroy(dirScan);	
sl@0
   126
		}
sl@0
   127
	}	// DoTestL
sl@0
   128
sl@0
   129
/**
sl@0
   130
Template function that calls CUri::CreateFileUriL to generate a URI and 
sl@0
   131
calls TUriC::GetFileNameL() with this URI, to verify that the filename so got
sl@0
   132
is the same as the original one.
sl@0
   133
*/
sl@0
   134
template <class CUriType, class TUriParserType>
sl@0
   135
void CTestForAllFilesStep::TestBothWaysL(CUriType*& cUri8Or16, TUriParserType& tUriParser8Or16, TFileName& aFileName)
sl@0
   136
	{
sl@0
   137
	TUint flags = KErrNone;
sl@0
   138
	TDriveNumber driveNum;
sl@0
   139
	TParse parser;
sl@0
   140
	parser.Set(aFileName, 0, 0);
sl@0
   141
	TBuf<1> drive = parser.Drive().Left(1);
sl@0
   142
	drive.LowerCase();
sl@0
   143
		
sl@0
   144
	CTestFileUriServer::GetDriveNumber(drive, driveNum);
sl@0
   145
	TBool aResult;
sl@0
   146
	TInt err = CTestFileUriServer::IsRemovableDrive(driveNum, aResult);
sl@0
   147
	if(err != KErrNone)
sl@0
   148
		{
sl@0
   149
		ERR_PRINTF2(_L("Error occured while checking whether drive is removable: %D"), err);
sl@0
   150
		SetTestStepResult(EFail);
sl@0
   151
		}
sl@0
   152
	else
sl@0
   153
		{
sl@0
   154
		if(aResult)
sl@0
   155
			{// The drive is a removable drive
sl@0
   156
			INFO_PRINTF1(_L("The drive is a removable drive"));
sl@0
   157
			flags = EExtMedia;
sl@0
   158
			}
sl@0
   159
		
sl@0
   160
		// Generate the URI	
sl@0
   161
		TRAPD(err, cUri8Or16 = CUriType::CreateFileUriL(aFileName, flags));
sl@0
   162
			
sl@0
   163
		if(err != KErrNone)
sl@0
   164
			{
sl@0
   165
			ERR_PRINTF2(_L("Error occured in CreateFileUriL: %D"), err);
sl@0
   166
			SetTestStepResult(EFail);
sl@0
   167
			}
sl@0
   168
		else
sl@0
   169
			{
sl@0
   170
			CleanupStack::PushL(cUri8Or16);
sl@0
   171
			// Just in case, create a 16-bit heap desc and print.
sl@0
   172
			HBufC16* tempBuf = HBufC16::NewL(cUri8Or16->Uri().UriDes().Length());
sl@0
   173
			tempBuf->Des().Copy(cUri8Or16->Uri().UriDes());
sl@0
   174
			INFO_PRINTF2(_L("File URI returned by CreateFileUriL = %S"), tempBuf);
sl@0
   175
			delete tempBuf;
sl@0
   176
			
sl@0
   177
			if(aResult)
sl@0
   178
				{
sl@0
   179
				TBuf<1> correctDrive;
sl@0
   180
				err = CTestFileUriServer::FirstRemovableDriveWithSameFileName(aFileName, correctDrive);
sl@0
   181
				if(err != KErrNone)
sl@0
   182
					{
sl@0
   183
					ERR_PRINTF2(_L("Error occured in FirstRemovableDriveWithSameFileName: %D"), err);
sl@0
   184
					SetTestStepResult(EFail);
sl@0
   185
					}
sl@0
   186
				else
sl@0
   187
					{
sl@0
   188
					correctDrive.LowerCase();
sl@0
   189
					if(correctDrive != drive)
sl@0
   190
						{
sl@0
   191
						aFileName.Replace(0, 1, correctDrive);
sl@0
   192
						INFO_PRINTF1(_L("One more removable drive found with the same file name, but is ahead in alphabetical order"));
sl@0
   193
						INFO_PRINTF2(_L("Hence the correct expected file name is %S"), aFileName);
sl@0
   194
						}	
sl@0
   195
					}
sl@0
   196
				}
sl@0
   197
				
sl@0
   198
			// Convert the URI to filename back again
sl@0
   199
			HBufC16* returnedFileName = NULL;
sl@0
   200
			
sl@0
   201
			tUriParser8Or16.Parse(cUri8Or16->Uri().UriDes());
sl@0
   202
			TRAPD(err, returnedFileName = tUriParser8Or16.GetFileNameL());
sl@0
   203
			CleanupStack::PopAndDestroy(cUri8Or16);
sl@0
   204
			if(err != KErrNone)
sl@0
   205
				{
sl@0
   206
				ERR_PRINTF2(_L("Error occured in GetFileNameL: %D"), err);
sl@0
   207
				SetTestStepResult(EFail);
sl@0
   208
				}
sl@0
   209
			else
sl@0
   210
				{
sl@0
   211
				INFO_PRINTF2(_L("The filename returned by GetFileNameL = %S"), returnedFileName);
sl@0
   212
			
sl@0
   213
				// Verify the result
sl@0
   214
				aFileName.LowerCase();
sl@0
   215
				returnedFileName->Des().LowerCase();
sl@0
   216
				
sl@0
   217
				if(returnedFileName->Compare(aFileName) != KErrNone)
sl@0
   218
					{
sl@0
   219
					INFO_PRINTF1(_L("The returned filename did not match the original filename. Result = INCORRECT"));
sl@0
   220
					SetTestStepResult(EFail);
sl@0
   221
					}
sl@0
   222
				else
sl@0
   223
					{
sl@0
   224
					INFO_PRINTF1(_L("The returned filename is same as the original filename. Result = CORRECT"));
sl@0
   225
					}	
sl@0
   226
				delete returnedFileName;
sl@0
   227
				}	
sl@0
   228
			}
sl@0
   229
		}
sl@0
   230
	}	// TestBothWaysL
sl@0
   231
sl@0
   232