os/ossrv/genericservices/httputils/Test/Integration/TestFileUriSuite/TestGenerateFileUriStep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/httputils/Test/Integration/TestFileUriSuite/TestGenerateFileUriStep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,209 @@
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 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @internalTechnology
1.22 +*/
1.23 +
1.24 +// Epoc Includes
1.25 +// For File URI handler API
1.26 +#include <uri16.h>
1.27 +#include <uri8.h>
1.28 +#include <escapeutils.h>
1.29 +
1.30 +// User Include
1.31 +#include "TestGenerateFileUriStep.h"
1.32 +
1.33 +/**
1.34 +Constructor. Sets the test step name
1.35 +*/
1.36 +CTestGenerateFileUriStep::CTestGenerateFileUriStep()
1.37 + {
1.38 + //Call base class method to set human readable name for test step
1.39 + SetTestStepName(KTestGenerateFileUriStep);
1.40 + }
1.41 +
1.42 +/**
1.43 +Does the main functionality of a test step.
1.44 +Here, reads values from INI file and calls DoTestL
1.45 +@internalTechnology
1.46 +@see GenerateFileUriAndCompareL
1.47 +@param None
1.48 +@return EPass or EFail indicating the success or failure of the test step
1.49 +*/
1.50 +TVerdict CTestGenerateFileUriStep::doTestStepL()
1.51 + {
1.52 + __UHEAP_MARK;
1.53 + INFO_PRINTF1(_L("\n"));
1.54 + // Get necessary information from INI file
1.55 + TPtrC fileName;
1.56 + TPtrC expectedFileUri;
1.57 + TPtrC fileType;
1.58 + TInt characterSet;
1.59 + TPtrC drive;
1.60 +
1.61 + if(!GetStringFromConfig(ConfigSection(), KIniFileName, fileName ) ||
1.62 + !GetStringFromConfig(ConfigSection(), KIniExpectedFileUri, expectedFileUri ) ||
1.63 + !GetStringFromConfig(ConfigSection(), KIniFileType, fileType ) ||
1.64 + !GetIntFromConfig (ConfigSection(), KIniCharacterSet, characterSet ) ||
1.65 + !GetStringFromConfig(ConfigSection(), KIniDrive, drive )
1.66 + )
1.67 + {
1.68 + ERR_PRINTF6(_L("Problem in reading values from ini. \
1.69 + \nExpected fields are: \n%S\n%S\n%S\n%S\n%S\n"
1.70 + ),&KIniFileName, &KIniExpectedFileUri, &KIniFileType, &KIniCharacterSet, &KIniDrive
1.71 + );
1.72 + SetTestStepResult(EFail);
1.73 + }
1.74 + else
1.75 + {// No problem in reading values from INI file. Proceed.
1.76 + TRAPD(err, DoTestL(fileName, expectedFileUri, fileType, drive, characterSet));
1.77 + if(err != KErrNone)
1.78 + {
1.79 + ERR_PRINTF2(_L("Leave occured in CTestGenerateFileUriStep::DoTestL: %D"), err);
1.80 + SetTestStepResult(EFail);
1.81 + }
1.82 + }
1.83 + __UHEAP_MARKEND;
1.84 + INFO_PRINTF1(_L("\n"));
1.85 + return TestStepResult();
1.86 + } // doTestStepL()
1.87 +
1.88 +/**
1.89 +Checks whether the drive is a removable drive. Populates the <drive> placeholder.
1.90 +And calls ExtractFileNameAndCompareL.
1.91 +*/
1.92 +void CTestGenerateFileUriStep::DoTestL(const TPtrC& aFileName, const TPtrC& aExpectedFileUri, const TPtrC& aFileType, const TPtrC& aDrive, const TInt& aCharacterSet)
1.93 + {
1.94 + INFO_PRINTF2(_L("Character Set = %D"), aCharacterSet);
1.95 + INFO_PRINTF2(_L("File name = %S"), &aFileName);
1.96 +
1.97 + // Eliminate any characters like colon, slash etc.
1.98 + TPtrC drive(aDrive.Left(1));
1.99 +
1.100 + TUint flags = KErrNone;
1.101 + TDriveNumber driveNum;
1.102 + CTestFileUriServer::GetDriveNumber(drive, driveNum);
1.103 + TBool aResult;
1.104 + TInt err = CTestFileUriServer::IsRemovableDrive(driveNum, aResult);
1.105 + if(err != KErrNone)
1.106 + {
1.107 + ERR_PRINTF2(_L("Error occured while checking whether drive is removable: %D"), err);
1.108 + SetTestStepResult(EFail);
1.109 + }
1.110 + else
1.111 + {
1.112 + if(aResult)
1.113 + {// The drive is a removable drive
1.114 + INFO_PRINTF1(_L("The drive is a removable drive"));
1.115 + flags = EExtMedia;
1.116 + drive.Set(KExtMedia());
1.117 + }
1.118 + HBufC16* expectedUriWithDrive = NULL;
1.119 +
1.120 + // Fill the <drive> place holder if it exists
1.121 + TRAPD(err, expectedUriWithDrive = CTestFileUriServer::CheckAndFillDriveNameL(aExpectedFileUri, drive));
1.122 + if(err != KErrNone)
1.123 + {
1.124 + ERR_PRINTF2(_L("Error occured while filling the drive-placeholder: %D"), err);
1.125 + SetTestStepResult(EFail);
1.126 + }
1.127 + else
1.128 + {// All preliminary operations OK so far, go ahead and perform the test.
1.129 + CleanupStack::PushL(expectedUriWithDrive);
1.130 + INFO_PRINTF2(_L("Expected File URI = %S"), expectedUriWithDrive);
1.131 + if(aCharacterSet == KCharSet8)
1.132 + {
1.133 + CUri16* cUri8 = NULL;
1.134 + GenerateFileUriAndCompareL(cUri8, aFileName, expectedUriWithDrive, flags, driveNum, aFileType);
1.135 + }
1.136 + else if(aCharacterSet == KCharSet16)
1.137 + {
1.138 + CUri16* cUri16 = NULL;
1.139 + GenerateFileUriAndCompareL(cUri16, aFileName, expectedUriWithDrive, flags, driveNum, aFileType);
1.140 + }
1.141 + else
1.142 + {
1.143 + ERR_PRINTF1(_L("Invalid CharacterSet"));
1.144 + SetTestStepResult(EFail);
1.145 + }
1.146 + CleanupStack::PopAndDestroy(expectedUriWithDrive);
1.147 + }
1.148 + }
1.149 + } // DoTestL
1.150 +
1.151 +/**
1.152 +Template function that calls the 8 or 16-bit version of
1.153 +CreatePrivateFileUriL() or CreateFileUriL(), verifies the expected and
1.154 +actual results and sets the test step result accordingly.
1.155 +*/
1.156 +template <class CUriType>
1.157 +void CTestGenerateFileUriStep::GenerateFileUriAndCompareL(CUriType*& cUri8Or16, const TPtrC& aFileName, HBufC16*& aExpectedFileUri8Or16, const TUint& aFlags, const TInt& aDriveNum, const TPtrC& aFileType)
1.158 + {
1.159 + TInt err = KErrNone;
1.160 +
1.161 + // Get the URI object
1.162 + if(aFileType == KFileTypePrivate)
1.163 + {// Call private version
1.164 + TRAP(err, cUri8Or16 = CUriType::CreatePrivateFileUriL(aFileName, static_cast<TDriveNumber>(aDriveNum), aFlags));
1.165 +
1.166 + // Test it in case of NON-secure version too, but in that case
1.167 + // the expected result is a Leave with KErrNotSupported.
1.168 + }
1.169 + else
1.170 + {// Call non-private version
1.171 + TRAP(err, cUri8Or16 = CUriType::CreateFileUriL(aFileName, aFlags));
1.172 + }
1.173 +
1.174 + if(err != KErrNone)
1.175 + {// If it comes here, it means there's some problem. But some tests
1.176 + // expect an error. So just set the error, and leave the decision
1.177 + // to TEF
1.178 + ERR_PRINTF2(_L("Leave occured: %D"), err);
1.179 + SetTestStepError(err);
1.180 + }
1.181 + else
1.182 + {// Things seem to be OK and a URI has been returned. Do the checking
1.183 +
1.184 + CleanupStack::PushL(cUri8Or16);
1.185 +
1.186 + // Construct a fully lowercase 16-bit version of the returned URI, so that we
1.187 + // can do print, compare etc.
1.188 + HBufC16* lowerCaseUri16 = HBufC16::NewL(cUri8Or16->Uri().UriDes().Length());
1.189 + lowerCaseUri16->Des().Copy(cUri8Or16->Uri().UriDes());
1.190 + CleanupStack::PopAndDestroy(cUri8Or16);
1.191 +
1.192 + INFO_PRINTF2(_L("The returned URI = %S"), lowerCaseUri16);
1.193 +
1.194 + lowerCaseUri16->Des().LowerCase();
1.195 +
1.196 + // Make expected URI too, fully lowercase
1.197 + aExpectedFileUri8Or16->Des().LowerCase();
1.198 +
1.199 + // Compare and set the verdict
1.200 + if (lowerCaseUri16->Des() != aExpectedFileUri8Or16->Des())
1.201 + {
1.202 + INFO_PRINTF1(_L("The returned and expected URIs did not match. Result = INCORRECT"));
1.203 + SetTestStepResult(EFail);
1.204 + }
1.205 + else
1.206 + {
1.207 + INFO_PRINTF1(_L("The returned and expected URIs matched. Result = CORRECT"));
1.208 + }
1.209 + delete lowerCaseUri16;
1.210 + }
1.211 + } // GenerateFileUriAndCompareL()
1.212 +