os/ossrv/genericservices/httputils/Test/Integration/TestFileUriSuite/TestGenerateFileUriStep.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @internalTechnology 
sl@0
    19
*/
sl@0
    20
sl@0
    21
// Epoc Includes
sl@0
    22
// For File URI handler API
sl@0
    23
#include <uri16.h>
sl@0
    24
#include <uri8.h>
sl@0
    25
#include <escapeutils.h>
sl@0
    26
sl@0
    27
// User Include
sl@0
    28
#include "TestGenerateFileUriStep.h"
sl@0
    29
sl@0
    30
/**
sl@0
    31
Constructor. Sets the test step name
sl@0
    32
*/
sl@0
    33
CTestGenerateFileUriStep::CTestGenerateFileUriStep()
sl@0
    34
	{
sl@0
    35
	//Call base class method to set human readable name for test step
sl@0
    36
	SetTestStepName(KTestGenerateFileUriStep);
sl@0
    37
	}
sl@0
    38
sl@0
    39
/**
sl@0
    40
Does the main functionality of a test step.
sl@0
    41
Here, reads values from INI file and calls DoTestL
sl@0
    42
@internalTechnology 
sl@0
    43
@see 		GenerateFileUriAndCompareL
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 CTestGenerateFileUriStep::doTestStepL()
sl@0
    48
	{
sl@0
    49
	__UHEAP_MARK;
sl@0
    50
	INFO_PRINTF1(_L("\n"));
sl@0
    51
	// Get necessary information from INI file
sl@0
    52
	TPtrC fileName;
sl@0
    53
	TPtrC expectedFileUri;
sl@0
    54
	TPtrC fileType;
sl@0
    55
	TInt characterSet;
sl@0
    56
	TPtrC drive;
sl@0
    57
	
sl@0
    58
	if(!GetStringFromConfig(ConfigSection(), 	KIniFileName, 			fileName		) ||
sl@0
    59
	   !GetStringFromConfig(ConfigSection(), 	KIniExpectedFileUri,	expectedFileUri	) ||
sl@0
    60
	   !GetStringFromConfig(ConfigSection(), 	KIniFileType, 			fileType		) ||
sl@0
    61
	   !GetIntFromConfig   (ConfigSection(), 	KIniCharacterSet, 		characterSet	) ||
sl@0
    62
	   !GetStringFromConfig(ConfigSection(), 	KIniDrive, 				drive			)
sl@0
    63
	  )
sl@0
    64
		{
sl@0
    65
		ERR_PRINTF6(_L("Problem in reading values from ini.			\
sl@0
    66
						\nExpected fields are: \n%S\n%S\n%S\n%S\n%S\n"
sl@0
    67
					  ),&KIniFileName, &KIniExpectedFileUri, &KIniFileType, &KIniCharacterSet, &KIniDrive
sl@0
    68
				   );
sl@0
    69
		SetTestStepResult(EFail);
sl@0
    70
		}
sl@0
    71
	else
sl@0
    72
		{// No problem in reading values from INI file. Proceed.
sl@0
    73
		TRAPD(err, DoTestL(fileName, expectedFileUri, fileType, drive, characterSet));
sl@0
    74
		if(err != KErrNone)
sl@0
    75
			{
sl@0
    76
			ERR_PRINTF2(_L("Leave occured in CTestGenerateFileUriStep::DoTestL: %D"), err);
sl@0
    77
			SetTestStepResult(EFail);
sl@0
    78
			}
sl@0
    79
		}
sl@0
    80
	__UHEAP_MARKEND;
sl@0
    81
	INFO_PRINTF1(_L("\n"));	
sl@0
    82
	return TestStepResult();
sl@0
    83
	}	// doTestStepL()
sl@0
    84
sl@0
    85
/**
sl@0
    86
Checks whether the drive is a removable drive. Populates the <drive> placeholder. 
sl@0
    87
And calls ExtractFileNameAndCompareL.
sl@0
    88
*/
sl@0
    89
void CTestGenerateFileUriStep::DoTestL(const TPtrC& aFileName, const TPtrC& aExpectedFileUri, const TPtrC& aFileType, const TPtrC& aDrive, const TInt& aCharacterSet)
sl@0
    90
	{
sl@0
    91
	INFO_PRINTF2(_L("Character Set = %D"), aCharacterSet);
sl@0
    92
	INFO_PRINTF2(_L("File name = %S"), &aFileName);
sl@0
    93
	
sl@0
    94
	// Eliminate any characters like colon, slash etc.
sl@0
    95
	TPtrC drive(aDrive.Left(1));
sl@0
    96
sl@0
    97
	TUint flags = KErrNone;
sl@0
    98
	TDriveNumber driveNum;
sl@0
    99
	CTestFileUriServer::GetDriveNumber(drive, driveNum);
sl@0
   100
	TBool aResult;
sl@0
   101
	TInt err = CTestFileUriServer::IsRemovableDrive(driveNum, aResult);
sl@0
   102
	if(err != KErrNone)
sl@0
   103
		{
sl@0
   104
		ERR_PRINTF2(_L("Error occured while checking whether drive is removable: %D"), err);
sl@0
   105
		SetTestStepResult(EFail);
sl@0
   106
		}
sl@0
   107
	else
sl@0
   108
		{
sl@0
   109
		if(aResult)
sl@0
   110
			{// The drive is a removable drive
sl@0
   111
			INFO_PRINTF1(_L("The drive is a removable drive"));
sl@0
   112
			flags = EExtMedia;
sl@0
   113
			drive.Set(KExtMedia());
sl@0
   114
			}
sl@0
   115
		HBufC16* expectedUriWithDrive = NULL;
sl@0
   116
		
sl@0
   117
		// Fill the <drive> place holder if it exists
sl@0
   118
		TRAPD(err, expectedUriWithDrive = CTestFileUriServer::CheckAndFillDriveNameL(aExpectedFileUri, drive));
sl@0
   119
		if(err != KErrNone)
sl@0
   120
			{
sl@0
   121
			ERR_PRINTF2(_L("Error occured while filling the drive-placeholder: %D"), err);
sl@0
   122
			SetTestStepResult(EFail);
sl@0
   123
			}
sl@0
   124
		else
sl@0
   125
			{// All preliminary operations OK so far, go ahead and perform the test.
sl@0
   126
			CleanupStack::PushL(expectedUriWithDrive);
sl@0
   127
			INFO_PRINTF2(_L("Expected File URI = %S"), expectedUriWithDrive);	
sl@0
   128
			if(aCharacterSet == KCharSet8)
sl@0
   129
				{
sl@0
   130
				CUri16* cUri8 = NULL;
sl@0
   131
				GenerateFileUriAndCompareL(cUri8, aFileName, expectedUriWithDrive, flags, driveNum, aFileType);	
sl@0
   132
				}
sl@0
   133
			else if(aCharacterSet == KCharSet16)
sl@0
   134
				{
sl@0
   135
				CUri16* cUri16 = NULL;
sl@0
   136
				GenerateFileUriAndCompareL(cUri16, aFileName, expectedUriWithDrive, flags, driveNum, aFileType);	
sl@0
   137
				}
sl@0
   138
			else
sl@0
   139
				{
sl@0
   140
				ERR_PRINTF1(_L("Invalid CharacterSet"));
sl@0
   141
				SetTestStepResult(EFail);
sl@0
   142
				}
sl@0
   143
			CleanupStack::PopAndDestroy(expectedUriWithDrive);
sl@0
   144
			}
sl@0
   145
		}
sl@0
   146
	}	// DoTestL
sl@0
   147
	
sl@0
   148
/**	
sl@0
   149
Template function that calls the 8 or 16-bit version of 
sl@0
   150
CreatePrivateFileUriL() or CreateFileUriL(), verifies the expected and 
sl@0
   151
actual results and sets the test step result accordingly.
sl@0
   152
*/
sl@0
   153
template <class CUriType>
sl@0
   154
void CTestGenerateFileUriStep::GenerateFileUriAndCompareL(CUriType*& cUri8Or16, const TPtrC& aFileName, HBufC16*& aExpectedFileUri8Or16, const TUint& aFlags, const TInt& aDriveNum, const TPtrC& aFileType)
sl@0
   155
	{
sl@0
   156
	TInt err = KErrNone;
sl@0
   157
	
sl@0
   158
	// Get the URI object
sl@0
   159
	if(aFileType == KFileTypePrivate)
sl@0
   160
		{// Call private version
sl@0
   161
		TRAP(err, cUri8Or16 = CUriType::CreatePrivateFileUriL(aFileName, static_cast<TDriveNumber>(aDriveNum), aFlags));
sl@0
   162
		
sl@0
   163
		// Test it in case of NON-secure version too, but in that case
sl@0
   164
		// the expected result is a Leave with KErrNotSupported.
sl@0
   165
		} 
sl@0
   166
	else
sl@0
   167
		{// Call non-private version
sl@0
   168
		TRAP(err, cUri8Or16 = CUriType::CreateFileUriL(aFileName, aFlags));	
sl@0
   169
		}
sl@0
   170
		
sl@0
   171
	if(err != KErrNone)
sl@0
   172
		{// If it comes here, it means there's some problem. But some tests
sl@0
   173
	 	 // expect an error. So just set the error, and leave the decision 
sl@0
   174
	 	 // to TEF
sl@0
   175
		ERR_PRINTF2(_L("Leave occured: %D"), err);	
sl@0
   176
		SetTestStepError(err);
sl@0
   177
		}
sl@0
   178
	else
sl@0
   179
		{// Things seem to be OK and a URI has been returned. Do the checking
sl@0
   180
		
sl@0
   181
		CleanupStack::PushL(cUri8Or16);
sl@0
   182
		
sl@0
   183
		// Construct a fully lowercase 16-bit version of the returned URI, so that we
sl@0
   184
		// can do print, compare etc.
sl@0
   185
		HBufC16* lowerCaseUri16 = HBufC16::NewL(cUri8Or16->Uri().UriDes().Length());
sl@0
   186
		lowerCaseUri16->Des().Copy(cUri8Or16->Uri().UriDes());
sl@0
   187
		CleanupStack::PopAndDestroy(cUri8Or16);
sl@0
   188
		
sl@0
   189
		INFO_PRINTF2(_L("The returned URI = %S"), lowerCaseUri16);
sl@0
   190
		
sl@0
   191
		lowerCaseUri16->Des().LowerCase();
sl@0
   192
		
sl@0
   193
		// Make expected URI too, fully lowercase
sl@0
   194
		aExpectedFileUri8Or16->Des().LowerCase();
sl@0
   195
sl@0
   196
		// Compare and set the verdict
sl@0
   197
		if (lowerCaseUri16->Des() != aExpectedFileUri8Or16->Des())
sl@0
   198
			{
sl@0
   199
			INFO_PRINTF1(_L("The returned and expected URIs did not match. Result = INCORRECT"));
sl@0
   200
			SetTestStepResult(EFail); 
sl@0
   201
			}
sl@0
   202
		else
sl@0
   203
			{
sl@0
   204
			INFO_PRINTF1(_L("The returned and expected URIs matched. Result = CORRECT")); 	
sl@0
   205
			}
sl@0
   206
		delete lowerCaseUri16;
sl@0
   207
		}
sl@0
   208
	}		// GenerateFileUriAndCompareL()
sl@0
   209