os/ossrv/genericservices/httputils/Test/Integration/TestInetProtUtilsSuite/Src/TestTelUriParsingStep.cpp
Update contrib.
1 // Copyright (c) 2007-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 // Contains implementation of CTestTelUriParsingStep class
24 #include "TestTelUriParsingStep.h"
27 #include <uriutilscommon.h>
30 Constructor: Sets the test step name.
34 CTestTelUriParsingStep::CTestTelUriParsingStep()
36 //Call base class method to set human readable name for test step
37 SetTestStepName(KTestTelUriParsingStep);
45 CTestTelUriParsingStep::~CTestTelUriParsingStep()
51 Does the main functionality of a test step.
52 Here, reads values from INI file
53 and calls TestTelUriParsingAndCompareL() which does parsing of a tel uri.
56 @return EPass or EFail indicating the success or failure of the test step
58 TVerdict CTestTelUriParsingStep::doTestStepL()
61 INFO_PRINTF1(_L("\n"));
62 // Get necessary information from INI file
67 if(!GetStringFromConfig(ConfigSection(), KIniUri, telUri) ||
68 !GetStringFromConfig(ConfigSection(), KIniExpectedTelScheme, expTelScheme) ||
69 !GetStringFromConfig(ConfigSection(), KIniExpectedTelPath, expTelPath) )
71 ERR_PRINTF4(_L("Problem in reading values from ini. \
72 \nExpected fields are: \n%S\n%S\n%S\n"
73 ),&KIniUri, &KIniExpectedTelScheme, &KIniExpectedTelPath
75 SetTestStepResult(EFail);
79 // No problem in reading values from INI file. Proceed.
80 // Calling TestTelUriParsingL which does parisng of tel uri and comparing results.
81 TRAPD(err, TestTelUriParsingAndCompareL(telUri,expTelScheme, expTelPath));
84 ERR_PRINTF2(_L("Test step failed: Tel URI parsing failed: %D\n"), err);
85 SetTestStepResult(EFail);
89 INFO_PRINTF1(_L("\nTest of TelUriParsing is Executed\n"));
90 return TestStepResult();
94 Performs tel uri parsing and compares actual & expected result.
95 @param aUri A reference to tel-uri to be parsed.
96 @param aScheme A reference to expected scheme component of tel-uri.
97 @param aPath A reference to expected path component of tel-uri.
99 void CTestTelUriParsingStep::TestTelUriParsingAndCompareL(const TDesC16& aUri, const TDesC16& aScheme, const TDesC16& aPath)
102 HBufC8* uriBuf = HBufC8::NewLC(aUri.Length());
103 TPtr8 uri8Bit(uriBuf->Des());
106 TUriParser8 uriParser;
107 TInt error = KErrNone;
108 error = uriParser.Parse(uri8Bit);
109 // Is this a valid Uri?
110 if( error != KErrNone )
112 ERR_PRINTF2(_L("Tel URI parsing failed: %D\n"), error);
113 SetTestStepResult(EFail);
114 User::LeaveIfError(error);
118 TInt result = TestComponentL(uriParser, aScheme, EUriScheme);
121 ERR_PRINTF1(_L("Scheme component not matched \n"));
122 User::LeaveIfError(KUriUtilsErrDifferentScheme);
126 result = TestComponentL(uriParser, aPath, EUriPath);
129 ERR_PRINTF1(_L("Path component not matched \n"));
130 User::LeaveIfError(KUriUtilsErrDifferentPath);
133 //tel-uri Should not contain Host, UserInfo, Port, Query and Fragment components.
135 const TDesC8& host = uriParser.Extract(EUriHost);
136 if( (host.Length() != 0) || (host.Size() != 0) )
138 ERR_PRINTF1(_L("host component is not empty, but it should be empty. \n"));
139 User::LeaveIfError(KUriUtilsErrDifferentHost);
143 const TDesC8& userInfo = uriParser.Extract(EUriUserinfo);
144 if( (userInfo.Length() != 0) || (userInfo.Size() != 0) )
146 ERR_PRINTF1(_L("UserInfo component is not empty, but it should be empty. \n"));
147 User::LeaveIfError(KUriUtilsErrDifferentUserInfo);
151 const TDesC8& uriPort = uriParser.Extract(EUriPort);
152 if( (uriPort.Length() != 0) || (uriPort.Size() != 0) )
154 ERR_PRINTF1(_L("Port component is not empty, but it should be empty. \n"));
155 User::LeaveIfError(KUriUtilsErrDifferentPort);
159 const TDesC8& uriQuery = uriParser.Extract(EUriQuery);
160 if( (uriQuery.Length() != 0) || (uriQuery.Size() != 0) )
162 ERR_PRINTF1(_L("Query component is not empty, but it should be empty. \n"));
163 User::LeaveIfError(KUriUtilsErrDifferentQuery);
167 const TDesC8& uriFrag = uriParser.Extract(EUriFragment);
168 if( (uriFrag.Length() != 0) || (uriFrag.Size() != 0) )
170 ERR_PRINTF1(_L("Fragment component is not empty, but it should be empty. \n"));
171 User::LeaveIfError(KUriUtilsErrDifferentFragment);
173 CleanupStack::PopAndDestroy(uriBuf);
177 It extracts and compares with expected component for specified TUriComponent.
178 @param aParser A reference to parsed tel-uri.
179 @param aExpectedComponent A reference to expected component of tel-uri.
180 @param aComponent Enumeration of TUriComponent.
182 TInt CTestTelUriParsingStep::TestComponentL(const TUriParser8& aParser, const TDesC16& aExpectedComponent,TUriComponent aComponent)
184 HBufC8* expectedBuf = HBufC8::NewLC(aExpectedComponent.Length());
185 TPtr8 expected8Bit = expectedBuf->Des();
186 expected8Bit.Copy(aExpectedComponent);
187 TInt result = aParser.Extract(aComponent).Compare(expected8Bit);
188 CleanupStack::PopAndDestroy(expectedBuf);