1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/httputils/Test/t_uriparser/CTextUtilsTest.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,604 @@
1.4 +// Copyright (c) 2001-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 +#include "CTextUtilsTest.h"
1.20 +
1.21 +#include <uriutilscommon.h>
1.22 +#include <inetprottextutils.h>
1.23 +
1.24 +#include "TextUtilsTestCommon.h"
1.25 +#include "TextUtilsTests.h"
1.26 +
1.27 +CTextUtilsTest* CTextUtilsTest::NewLC(CIpuTestHarness* aTestHarness)
1.28 + {
1.29 + CTextUtilsTest* self = new (ELeave) CTextUtilsTest(aTestHarness);
1.30 + CleanupStack::PushL(self);
1.31 + self->ConstructL();
1.32 + return self;
1.33 + }
1.34 +
1.35 +CTextUtilsTest* CTextUtilsTest::NewL(CIpuTestHarness* aTestHarness)
1.36 + {
1.37 + CTextUtilsTest* self = CTextUtilsTest::NewLC(aTestHarness);
1.38 + CleanupStack::Pop(self);
1.39 + return self;
1.40 + }
1.41 +
1.42 +CTextUtilsTest::CTextUtilsTest(CIpuTestHarness* aTestHarness)
1.43 +: iTestHarness(aTestHarness)
1.44 + {
1.45 + }
1.46 +
1.47 +void CTextUtilsTest::ConstructL()
1.48 + {
1.49 + }
1.50 +
1.51 +CTextUtilsTest::~CTextUtilsTest()
1.52 + {
1.53 + }
1.54 +
1.55 +void CTextUtilsTest::DoTestsL()
1.56 + {
1.57 +
1.58 + TestTextUtilsRemoveL(KRemove0_base, KRemove0_left, KRemove0_left_consumed,
1.59 + KRemove0_right, KRemove0_right_consumed,
1.60 + KRemove0_both, KRemove0_both_consumed);
1.61 +
1.62 + TestTextUtilsDesToIntConversionL(KDecRep0, KNumericValue0, KIsValid0);
1.63 + TestTextUtilsDesToIntConversionL(KDecRep1, KNumericValue1, KIsValid1);
1.64 + TestTextUtilsDesToIntConversionL(KDecRep2, KNumericValue2, KIsValid2);
1.65 + TestTextUtilsDesToIntConversionL(KDecRep3, KNumericValue3, KIsValid3);
1.66 +
1.67 + TestTextUtilsIntToDesConversionL(KNumericValue0, KDecRep0);
1.68 + TestTextUtilsIntToDesConversionL(KNumericValue1, KDecRep1);
1.69 +
1.70 + _LIT(KWhiteSpace," \t");
1.71 + TestTextUtilsDesToHexConversionL(KWhiteSpace, 0, EFalse);
1.72 +
1.73 + TestTextUtilsDesToHexConversionL(KHexRep0, KNumericValue0, KIsValid0);
1.74 + TestTextUtilsDesToHexConversionL(KHexRep1, KNumericValue1, KIsValid1);
1.75 + TestTextUtilsDesToHexConversionL(KHexRep2, KNumericValue2, KIsValid2);
1.76 + TestTextUtilsDesToHexConversionL(KHexRep3, KNumericValue3, KIsValid3);
1.77 +
1.78 + TestTextUtilsHexToDesConversionL(KNumericValue0, KHexRep0);
1.79 + TestTextUtilsHexToDesConversionL(KNumericValue1, KHexRep1);
1.80 +
1.81 + TestTextUtilsExtractQuotedStringL(KQuotedBuffer0, KQuotedString0, KQuotedRemainder0, KExpectedError0);
1.82 + TestTextUtilsExtractQuotedStringL(KQuotedBuffer1, KQuotedString1, KQuotedRemainder1, KExpectedError1);
1.83 + TestTextUtilsExtractQuotedStringL(KQuotedBuffer2, KQuotedString2, KQuotedRemainder2, KExpectedError2);
1.84 + TestTextUtilsExtractQuotedStringL(KQuotedBuffer3, KQuotedString3, KQuotedRemainder3, KExpectedError3);
1.85 +
1.86 + TestTextUtilsExtractTokenFromListL(
1.87 + KListBuffer0,
1.88 + KListToken0_0,
1.89 + KListToken0_1,
1.90 + KListToken0_2,
1.91 + KListRemainder0,
1.92 + KListSeparator0
1.93 + );
1.94 +
1.95 + TestTextUtilsExtractTokenFromListL(
1.96 + KListBuffer1,
1.97 + KListToken1_0,
1.98 + KListToken1_1,
1.99 + KListToken1_2,
1.100 + KListRemainder1,
1.101 + KListSeparator1
1.102 + );
1.103 +
1.104 + TestTextUtilsExtractTokenFromListL(
1.105 + KListBuffer2,
1.106 + KListToken2_0,
1.107 + KListToken2_1,
1.108 + KListToken2_2,
1.109 + KListRemainder2,
1.110 + KListSeparator2
1.111 + );
1.112 +
1.113 + TestTextUtilsExtractTokenFromListL(
1.114 + KListBuffer3,
1.115 + KListToken3_0,
1.116 + KListToken3_1,
1.117 + KListToken3_2,
1.118 + KListRemainder3,
1.119 + KListSeparator3
1.120 + );
1.121 + }
1.122 +
1.123 +void CTextUtilsTest::TestTextUtilsRemoveL(const TDesC& aBase,
1.124 + const TDesC& aRemoveLeft, TInt aConsumedLeft,
1.125 + const TDesC& aRemoveRight, TInt aConsumedRight,
1.126 + const TDesC& aRemoveBoth, TInt aConsumedBoth)
1.127 + {
1.128 + iTestHarness->StartTestL(_L("Test TextUtils Remove (16-bit)"));
1.129 +
1.130 + TInt error = DoTestTextUtilsRemove<TPtrC16>(aBase, aRemoveLeft, aConsumedLeft,
1.131 + aRemoveRight, aConsumedRight,
1.132 + aRemoveBoth, aConsumedBoth);
1.133 +
1.134 + iTestHarness->EndTest(error);
1.135 +
1.136 + // Make 8-bit copy
1.137 + HBufC8* baseBuf = HBufC8::NewLC(aBase.Length());
1.138 + TPtr8 base8Bit = baseBuf->Des();
1.139 + base8Bit.Copy(aBase);
1.140 +
1.141 + HBufC8* removeLeftBuf = HBufC8::NewLC(aRemoveLeft.Length());
1.142 + TPtr8 removeLeft8Bit = removeLeftBuf->Des();
1.143 + removeLeft8Bit.Copy(aRemoveLeft);
1.144 +
1.145 + HBufC8* removeRightBuf = HBufC8::NewLC(aRemoveRight.Length());
1.146 + TPtr8 removeRight8Bit = removeRightBuf->Des();
1.147 + removeRight8Bit.Copy(aRemoveRight);
1.148 +
1.149 + HBufC8* removeBothBuf = HBufC8::NewLC(aRemoveBoth.Length());
1.150 + TPtr8 removeBoth8Bit = removeBothBuf->Des();
1.151 + removeBoth8Bit.Copy(aRemoveBoth);
1.152 +
1.153 + iTestHarness->StartTestL(_L("Test TextUtils Remove (8-bit)"));
1.154 +
1.155 + error = DoTestTextUtilsRemove<TPtrC8>(base8Bit, removeLeft8Bit, aConsumedLeft,
1.156 + removeRight8Bit, aConsumedRight,
1.157 + removeBoth8Bit, aConsumedBoth);
1.158 +
1.159 + iTestHarness->EndTest(error);
1.160 +
1.161 + CleanupStack::PopAndDestroy(4, baseBuf); // baseBuf, removeLeftBuf, removeRightBuf, removeBothBuf
1.162 + }
1.163 +
1.164 +void CTextUtilsTest::TestTextUtilsDesToIntConversionL(const TDesC& aDes, TInt aInt, TBool aValid)
1.165 + {
1.166 + iTestHarness->StartTestL(_L("Test TextUtils ConvertDescriptorToInt (16-bit)"));
1.167 +
1.168 + TInt error = DoTestTextUtilsDesToIntConversion(aDes, aInt, aValid);
1.169 +
1.170 + iTestHarness->EndTest(error);
1.171 +
1.172 + // Make 8-bit copy
1.173 + HBufC8* desBuf = HBufC8::NewLC(aDes.Length());
1.174 + TPtr8 des8Bit = desBuf->Des();
1.175 + des8Bit.Copy(aDes);
1.176 +
1.177 + iTestHarness->StartTestL(_L("Test TextUtils ConvertDescriptorToInt (8-bit)"));
1.178 +
1.179 + error = DoTestTextUtilsDesToIntConversion(des8Bit, aInt, aValid);
1.180 +
1.181 + iTestHarness->EndTest(error);
1.182 +
1.183 + CleanupStack::PopAndDestroy(desBuf); // desBuf
1.184 + }
1.185 +
1.186 +void CTextUtilsTest::TestTextUtilsIntToDesConversionL(TInt aInt, const TDesC& aDes)
1.187 + {
1.188 + iTestHarness->StartTestL(_L("Test TextUtils ConvertIntToDescriptor (16-bit)"));
1.189 +
1.190 + TInt error = DoTestTextUtilsIntToDesConversion<HBufC16>(aInt, aDes);
1.191 +
1.192 + iTestHarness->EndTest(error);
1.193 +
1.194 + // Make 8-bit copy
1.195 + HBufC8* desBuf = HBufC8::NewLC(aDes.Length());
1.196 + TPtr8 des8Bit = desBuf->Des();
1.197 + des8Bit.Copy(aDes);
1.198 +
1.199 + iTestHarness->StartTestL(_L("Test TextUtils ConvertIntToDescriptor (8-bit)"));
1.200 +
1.201 + error = DoTestTextUtilsIntToDesConversion<HBufC8>(aInt, des8Bit);
1.202 +
1.203 + iTestHarness->EndTest(error);
1.204 +
1.205 + CleanupStack::PopAndDestroy(desBuf); // desBuf
1.206 + }
1.207 +
1.208 +
1.209 +
1.210 +void CTextUtilsTest::TestTextUtilsDesToHexConversionL(const TDesC& aDes, TInt aHexNumber, TBool aValid)
1.211 + {
1.212 + iTestHarness->StartTestL(_L("Test TextUtils ConvertDescriptorToHex (16-bit)"));
1.213 +
1.214 + TInt error = DoTestTextUtilsDesToHexConversion(aDes, aHexNumber, aValid);
1.215 + iTestHarness->EndTest(error);
1.216 +
1.217 + // Test 8 bit version
1.218 + TestTextUtilsDesToHexConversion8L(aDes, aHexNumber, aValid);
1.219 + }
1.220 +
1.221 +
1.222 +void CTextUtilsTest::TestTextUtilsDesToHexConversion8L(const TDesC& aDes, TInt aHexNumber, TBool aValid)
1.223 + {
1.224 + HBufC8* desBuf = HBufC8::NewLC(aDes.Length());
1.225 + TPtr8 des8Bit = desBuf->Des();
1.226 + des8Bit.Copy(aDes);
1.227 +
1.228 + iTestHarness->StartTestL(_L("Test TextUtils ConvertDescriptorToHex (8-bit)"));
1.229 +
1.230 + TInt error = DoTestTextUtilsDesToHexConversion(des8Bit, aHexNumber, aValid);
1.231 +
1.232 + iTestHarness->EndTest(error);
1.233 +
1.234 + CleanupStack::PopAndDestroy(desBuf); // desBuf
1.235 + }
1.236 +
1.237 +
1.238 +
1.239 +void CTextUtilsTest::TestTextUtilsHexToDesConversionL(TInt aHex, const TDesC& aDes)
1.240 + {
1.241 + iTestHarness->StartTestL(_L("Test TextUtils ConvertHexToDescriptor (16-bit)"));
1.242 +
1.243 + TInt error = DoTestTextUtilsHexToDesConversion<HBufC16>(aHex, aDes);
1.244 +
1.245 + iTestHarness->EndTest(error);
1.246 +
1.247 + // Make 8-bit copy
1.248 + HBufC8* desBuf = HBufC8::NewLC(aDes.Length());
1.249 + TPtr8 des8Bit = desBuf->Des();
1.250 + des8Bit.Copy(aDes);
1.251 +
1.252 + iTestHarness->StartTestL(_L("Test TextUtils ConvertHexToDescriptor (8-bit)"));
1.253 +
1.254 + error = DoTestTextUtilsHexToDesConversion<HBufC8>(aHex, des8Bit);
1.255 +
1.256 + iTestHarness->EndTest(error);
1.257 +
1.258 + CleanupStack::PopAndDestroy(desBuf); // desBuf
1.259 + }
1.260 +
1.261 +void CTextUtilsTest::TestTextUtilsExtractQuotedStringL(
1.262 + const TDesC& aBuffer,
1.263 + const TDesC& aString,
1.264 + const TDesC& aRemainder,
1.265 + TInt aExpectedError
1.266 + )
1.267 + {
1.268 + iTestHarness->StartTestL(_L("Test TextUtils ExtractQuotedStringL (16-bit)"));
1.269 +
1.270 + TInt error = DoTestExtractQuotedStringL<TPtrC>(aBuffer, aString, aRemainder, aExpectedError);
1.271 +
1.272 + iTestHarness->EndTest(error);
1.273 +
1.274 + // Make 8-bit copy
1.275 + HBufC8* buffer = HBufC8::NewLC(aBuffer.Length());
1.276 + buffer->Des().Copy(aBuffer);
1.277 +
1.278 + HBufC8* string = HBufC8::NewLC(aString.Length());
1.279 + string->Des().Copy(aString);
1.280 +
1.281 + HBufC8* remainder = HBufC8::NewLC(aRemainder.Length());
1.282 + remainder->Des().Copy(aRemainder);
1.283 +
1.284 + iTestHarness->StartTestL(_L("Test TextUtils ExtractQuotedStringL (8-bit)"));
1.285 +
1.286 + error = DoTestExtractQuotedStringL<TPtrC8>(*buffer, *string, *remainder, aExpectedError);
1.287 +
1.288 + iTestHarness->EndTest(error);
1.289 +
1.290 + CleanupStack::PopAndDestroy(3, buffer);
1.291 + }
1.292 +
1.293 +void CTextUtilsTest::TestTextUtilsExtractTokenFromListL(
1.294 + const TDesC& aBuffer,
1.295 + const TDesC& aToken0,
1.296 + const TDesC& aToken1,
1.297 + const TDesC& aToken2,
1.298 + const TDesC& aRemainder,
1.299 + const TDesC& aSeparator
1.300 + )
1.301 + {
1.302 + iTestHarness->StartTestL(_L("Test TextUtils ExtractTokenFromList, multiple separator (16-bit)"));
1.303 +
1.304 + TInt error = DoExtractTokenFromListMultipleSeparator<TPtrC>(aBuffer, aToken0, aToken1, aToken2, aRemainder, aSeparator);
1.305 +
1.306 + iTestHarness->EndTest(error);
1.307 +
1.308 + // Make 8-bit copy
1.309 + HBufC8* buffer = HBufC8::NewLC(aBuffer.Length());
1.310 + buffer->Des().Copy(aBuffer);
1.311 +
1.312 + HBufC8* token0 = HBufC8::NewLC(aToken0.Length());
1.313 + token0->Des().Copy(aToken0);
1.314 +
1.315 + HBufC8* token1 = HBufC8::NewLC(aToken1.Length());
1.316 + token1->Des().Copy(aToken1);
1.317 +
1.318 + HBufC8* token2 = HBufC8::NewLC(aToken2.Length());
1.319 + token2->Des().Copy(aToken2);
1.320 +
1.321 + HBufC8* remainder = HBufC8::NewLC(aRemainder.Length());
1.322 + remainder->Des().Copy(aRemainder);
1.323 +
1.324 + HBufC8* separator = HBufC8::NewLC(aSeparator.Length());
1.325 + separator->Des().Copy(aSeparator);
1.326 +
1.327 + iTestHarness->StartTestL(_L("Test TextUtils ExtractTokenFromList, multiple separator (8-bit)"));
1.328 +
1.329 + error = DoExtractTokenFromListMultipleSeparator<TPtrC8>(*buffer, *token0, *token1, *token2, *remainder, *separator);
1.330 +
1.331 + iTestHarness->EndTest(error);
1.332 +
1.333 + CleanupStack::PopAndDestroy(6, buffer);
1.334 + }
1.335 +
1.336 +void CTextUtilsTest::TestTextUtilsExtractTokenFromListL(
1.337 + const TDesC& aBuffer,
1.338 + const TDesC& aToken0,
1.339 + const TDesC& aToken1,
1.340 + const TDesC& aToken2,
1.341 + const TDesC& aRemainder,
1.342 + TChar aSeparator
1.343 + )
1.344 + {
1.345 + iTestHarness->StartTestL(_L("Test TextUtils ExtractTokenFromList, single separator (16-bit)"));
1.346 +
1.347 + TInt error = DoExtractTokenFromListSingleSeparator<TPtrC>(aBuffer, aToken0, aToken1, aToken2, aRemainder, aSeparator);
1.348 +
1.349 + iTestHarness->EndTest(error);
1.350 +
1.351 + // Make 8-bit copy
1.352 + HBufC8* buffer = HBufC8::NewLC(aBuffer.Length());
1.353 + buffer->Des().Copy(aBuffer);
1.354 +
1.355 + HBufC8* token0 = HBufC8::NewLC(aToken0.Length());
1.356 + token0->Des().Copy(aToken0);
1.357 +
1.358 + HBufC8* token1 = HBufC8::NewLC(aToken1.Length());
1.359 + token1->Des().Copy(aToken1);
1.360 +
1.361 + HBufC8* token2 = HBufC8::NewLC(aToken2.Length());
1.362 + token2->Des().Copy(aToken2);
1.363 +
1.364 + HBufC8* remainder = HBufC8::NewLC(aRemainder.Length());
1.365 + remainder->Des().Copy(aRemainder);
1.366 +
1.367 + iTestHarness->StartTestL(_L("Test TextUtils ExtractTokenFromList, single separator (8-bit)"));
1.368 +
1.369 + error = DoExtractTokenFromListSingleSeparator<TPtrC8>(*buffer, *token0, *token1, *token2, *remainder, aSeparator);
1.370 +
1.371 + iTestHarness->EndTest(error);
1.372 +
1.373 + CleanupStack::PopAndDestroy(5, buffer);
1.374 + }
1.375 +
1.376 +/*
1.377 + * Local methods
1.378 + */
1.379 +
1.380 +template<class TPtrCType, class TDesCType>
1.381 +LOCAL_C TInt DoTestTextUtilsRemove(const TDesCType& aBase,
1.382 + const TDesCType& aRemoveLeft, TInt aConsumedLeft,
1.383 + const TDesCType& aRemoveRight, TInt aConsumedRight,
1.384 + const TDesCType& aRemoveBoth, TInt aConsumedBoth)
1.385 + {
1.386 + // Do remove left...
1.387 + TPtrCType data = aBase;
1.388 + TInt consumed = InetProtTextUtils::RemoveWhiteSpace(data, InetProtTextUtils::ERemoveLeft);
1.389 + // Check...
1.390 + if( data.Compare(aRemoveLeft) != 0 || consumed != aConsumedLeft )
1.391 + {
1.392 + return KErrNotFound;
1.393 + }
1.394 + // Do remove right...
1.395 + data.Set(aBase);
1.396 + consumed = InetProtTextUtils::RemoveWhiteSpace(data, InetProtTextUtils::ERemoveRight);
1.397 + // Check...
1.398 + if( data.Compare(aRemoveRight) != 0 || consumed != aConsumedRight )
1.399 + {
1.400 + return KErrNotFound;
1.401 + }
1.402 + // Do remove both...
1.403 + data.Set(aBase);
1.404 + consumed = InetProtTextUtils::RemoveWhiteSpace(data, InetProtTextUtils::ERemoveBoth);
1.405 + // Check...
1.406 + if( data.Compare(aRemoveBoth) != 0 || consumed != aConsumedBoth )
1.407 + {
1.408 + return KErrNotFound;
1.409 + }
1.410 + return KErrNone;
1.411 + }
1.412 +
1.413 +template<class TDesCType>
1.414 +LOCAL_C TInt DoTestTextUtilsDesToIntConversion(const TDesCType& aDes, TInt aInt, TBool aValid)
1.415 + {
1.416 + TInt theInt;
1.417 + TInt error = InetProtTextUtils::ConvertDescriptorToInt(aDes, theInt);
1.418 + if( (error < KErrNone && aValid) || (error >= KErrNone && !aValid) )
1.419 + {
1.420 + return KErrNotFound;
1.421 + }
1.422 + if( aValid && theInt != aInt )
1.423 + {
1.424 + return KErrNotFound;
1.425 + }
1.426 + return KErrNone;
1.427 + }
1.428 +
1.429 +template<class HBufCType, class TDesCType>
1.430 +LOCAL_C TInt DoTestTextUtilsIntToDesConversion(TInt aInt, const TDesCType& aDes)
1.431 + {
1.432 + HBufCType* theDes = NULL;
1.433 + TRAPD(error, InetProtTextUtils::ConvertIntToDescriptorL(aInt, theDes));
1.434 + if( error != KErrNone )
1.435 + {
1.436 + return KErrNotFound;
1.437 + }
1.438 + if( theDes->CompareF(aDes) != 0 )
1.439 + {
1.440 + delete theDes;
1.441 + return KErrNotFound;
1.442 + }
1.443 + delete theDes;
1.444 + return KErrNone;
1.445 + }
1.446 +
1.447 +template<class TDesCType>
1.448 +LOCAL_C TInt DoTestTextUtilsDesToHexConversion(const TDesCType& aDes, TInt aHex, TBool aValid)
1.449 + {
1.450 + TInt theHex;
1.451 + TInt error = InetProtTextUtils::ConvertDescriptorToHex(aDes, theHex);
1.452 + if( (error < KErrNone && aValid) || (error >= KErrNone && !aValid) )
1.453 + {
1.454 + return KErrNotFound;
1.455 + }
1.456 + if( aValid && theHex != aHex )
1.457 + {
1.458 + return KErrNotFound;
1.459 + }
1.460 + return KErrNone;
1.461 + }
1.462 +
1.463 +template<class HBufCType, class TDesCType>
1.464 +LOCAL_C TInt DoTestTextUtilsHexToDesConversion(TInt aHex, const TDesCType& aDes)
1.465 + {
1.466 + HBufCType* theDes = NULL;
1.467 + TRAPD(error, InetProtTextUtils::ConvertHexToDescriptorL(aHex, theDes));
1.468 + if( error != KErrNone )
1.469 + {
1.470 + return KErrNotFound;
1.471 + }
1.472 + if( theDes->CompareF(aDes) != 0 )
1.473 + {
1.474 + delete theDes;
1.475 + return KErrNotFound;
1.476 + }
1.477 + delete theDes;
1.478 + return KErrNone;
1.479 + }
1.480 +
1.481 +template<class TPtrCType, class TDesCType>
1.482 +LOCAL_C TInt DoTestExtractQuotedStringL(const TDesCType& aBuffer, const TDesCType& aString, const TDesCType& aRemainder, TInt aExpectedError)
1.483 + {
1.484 + TPtrCType buffer(aBuffer);
1.485 + TPtrCType string;
1.486 + TRAPD( error, InetProtTextUtils::ExtractQuotedStringL(buffer, string) );
1.487 +
1.488 + if( error == KErrNone && aExpectedError == KErrNone)
1.489 + {
1.490 + if( aString.Compare(string) == 0 && aRemainder.Compare(buffer) == 0 )
1.491 + {
1.492 + // Passed
1.493 + return KErrNone;
1.494 + }
1.495 + else
1.496 + {
1.497 + // Failed
1.498 + return KErrNotFound;
1.499 + }
1.500 + }
1.501 + else if( error == aExpectedError )
1.502 + {
1.503 + // Got expected error - passed
1.504 + return KErrNone;
1.505 + }
1.506 + else
1.507 + {
1.508 + // Failed
1.509 + return KErrNotFound;
1.510 + }
1.511 + }
1.512 +
1.513 +template<class TPtrCType, class TDesCType>
1.514 +LOCAL_C TInt DoExtractTokenFromListMultipleSeparator(
1.515 + const TDesCType& aBuffer,
1.516 + const TDesCType& aToken0,
1.517 + const TDesCType& aToken1,
1.518 + const TDesCType& aToken2,
1.519 + const TDesCType& aRemainder,
1.520 + const TDesCType& aSeparator
1.521 + )
1.522 + {
1.523 + // get the first token...
1.524 + TPtrCType buffer = aBuffer;
1.525 + TPtrCType token;
1.526 + InetProtTextUtils::ExtractNextTokenFromList(buffer, token, aSeparator);
1.527 +
1.528 + // Is it correct?
1.529 + if( token.Compare(aToken0) != 0 )
1.530 + {
1.531 + // Failed
1.532 + return KErrNotFound;
1.533 + }
1.534 + // get the second token
1.535 + InetProtTextUtils::ExtractNextTokenFromList(buffer, token, aSeparator);
1.536 +
1.537 + // Is it correct?
1.538 + if( token.Compare(aToken1) != 0 )
1.539 + {
1.540 + // Failed
1.541 + return KErrNotFound;
1.542 + }
1.543 + // get the third token
1.544 + InetProtTextUtils::ExtractNextTokenFromList(buffer, token, aSeparator);
1.545 +
1.546 + // Is it correct?
1.547 + if( token.Compare(aToken2) != 0 )
1.548 + {
1.549 + // Failed
1.550 + return KErrNotFound;
1.551 + }
1.552 + // Check that the remainder is correct
1.553 + if( buffer.Compare(aRemainder) != 0 )
1.554 + {
1.555 + // Failed
1.556 + return KErrNotFound;
1.557 + }
1.558 + return KErrNone;
1.559 + }
1.560 +
1.561 +template<class TPtrCType, class TDesCType>
1.562 +LOCAL_C TInt DoExtractTokenFromListSingleSeparator(
1.563 + const TDesCType& aBuffer,
1.564 + const TDesCType& aToken0,
1.565 + const TDesCType& aToken1,
1.566 + const TDesCType& aToken2,
1.567 + const TDesCType& aRemainder,
1.568 + TChar aSeparator
1.569 + )
1.570 + {
1.571 + // get the first token...
1.572 + TPtrCType buffer = aBuffer;
1.573 + TPtrCType token;
1.574 + InetProtTextUtils::ExtractNextTokenFromList(buffer, token, aSeparator);
1.575 +
1.576 + // Is it correct?
1.577 + if( token.Compare(aToken0) != 0 )
1.578 + {
1.579 + // Failed
1.580 + return KErrNotFound;
1.581 + }
1.582 + // get the second token
1.583 + InetProtTextUtils::ExtractNextTokenFromList(buffer, token, aSeparator);
1.584 +
1.585 + // Is it correct?
1.586 + if( token.Compare(aToken1) != 0 )
1.587 + {
1.588 + // Failed
1.589 + return KErrNotFound;
1.590 + }
1.591 + // get the third token
1.592 + InetProtTextUtils::ExtractNextTokenFromList(buffer, token, aSeparator);
1.593 +
1.594 + // Is it correct?
1.595 + if( token.Compare(aToken2) != 0 )
1.596 + {
1.597 + // Failed
1.598 + return KErrNotFound;
1.599 + }
1.600 + // Check that the remainder is correct
1.601 + if( buffer.Compare(aRemainder) != 0 )
1.602 + {
1.603 + // Failed
1.604 + return KErrNotFound;
1.605 + }
1.606 + return KErrNone;
1.607 + }