1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/httputils/Test/t_uriparser/CEscapeUtilsTest.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,392 @@
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 "CEscapeUtilsTest.h"
1.20 +
1.21 +#include <e32base.h>
1.22 +
1.23 +#include "EscapeUtilsTestCommon.h"
1.24 +#include "EscapeUtilsTests.h"
1.25 +#include <tconvbase64.h>
1.26 +
1.27 +CEscapeUtilsTest* CEscapeUtilsTest::NewLC(CIpuTestHarness* aTestHarness)
1.28 + {
1.29 + CEscapeUtilsTest* self = new (ELeave) CEscapeUtilsTest(aTestHarness);
1.30 + CleanupStack::PushL(self);
1.31 + self->ConstructL();
1.32 + return self;
1.33 + }
1.34 +
1.35 +CEscapeUtilsTest* CEscapeUtilsTest::NewL(CIpuTestHarness* aTestHarness)
1.36 + {
1.37 + CEscapeUtilsTest* self = CEscapeUtilsTest::NewLC(aTestHarness);
1.38 + CleanupStack::Pop(self);
1.39 + return self;
1.40 + }
1.41 +
1.42 +CEscapeUtilsTest::CEscapeUtilsTest(CIpuTestHarness* aTestHarness)
1.43 +: iTestHarness(aTestHarness)
1.44 + {
1.45 + }
1.46 +
1.47 +void CEscapeUtilsTest::ConstructL()
1.48 + {
1.49 + }
1.50 +
1.51 +CEscapeUtilsTest::~CEscapeUtilsTest()
1.52 + {
1.53 + }
1.54 +
1.55 +void CEscapeUtilsTest::DoTestsL()
1.56 + {
1.57 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded0, KEscapeEncoded0_auth, EscapeUtils::EEscapeAuth);
1.58 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded0, KEscapeEncoded0_path, EscapeUtils::EEscapePath);
1.59 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded0, KEscapeEncoded0_query, EscapeUtils::EEscapeQuery);
1.60 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded0, KEscapeEncoded0_normal, EscapeUtils::EEscapeNormal);
1.61 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded0, KEscapeEncoded0_url, EscapeUtils::EEscapeUrlEncoded);
1.62 +
1.63 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded1, KEscapeEncoded1_auth, EscapeUtils::EEscapeAuth);
1.64 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded1, KEscapeEncoded1_path, EscapeUtils::EEscapePath);
1.65 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded1, KEscapeEncoded1_query, EscapeUtils::EEscapeQuery);
1.66 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded1, KEscapeEncoded1_normal, EscapeUtils::EEscapeNormal);
1.67 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded1, KEscapeEncoded1_url, EscapeUtils::EEscapeUrlEncoded);
1.68 +
1.69 +
1.70 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded0_auth, KEscapeDecoded0);
1.71 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded0_path, KEscapeDecoded0);
1.72 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded0_query, KEscapeDecoded0);
1.73 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded0_normal, KEscapeDecoded0);
1.74 +
1.75 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded1_auth, KEscapeDecoded1);
1.76 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded1_path, KEscapeDecoded1);
1.77 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded1_query, KEscapeDecoded1);
1.78 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded1_normal, KEscapeDecoded1);
1.79 +
1.80 + // Test cases for section 2.9.1.2 //
1.81 +
1.82 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded2, KEscapeEncoded2_auth, EscapeUtils::EEscapeAuth);
1.83 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded2, KEscapeEncoded2_path, EscapeUtils::EEscapePath);
1.84 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded2, KEscapeEncoded2_query, EscapeUtils::EEscapeQuery);
1.85 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded2, KEscapeEncoded2_normal, EscapeUtils::EEscapeNormal);
1.86 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded2, KEscapeEncoded2_url, EscapeUtils::EEscapeUrlEncoded);
1.87 +
1.88 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded3, KEscapeEncoded3_auth, EscapeUtils::EEscapeAuth);
1.89 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded3, KEscapeEncoded3_path, EscapeUtils::EEscapePath);
1.90 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded3, KEscapeEncoded3_query, EscapeUtils::EEscapeQuery);
1.91 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded3, KEscapeEncoded3_normal, EscapeUtils::EEscapeNormal);
1.92 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded3, KEscapeEncoded3_url, EscapeUtils::EEscapeUrlEncoded);
1.93 +
1.94 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded4, KEscapeEncoded4_auth, EscapeUtils::EEscapeAuth);
1.95 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded4, KEscapeEncoded4_path, EscapeUtils::EEscapePath);
1.96 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded4, KEscapeEncoded4_query, EscapeUtils::EEscapeQuery);
1.97 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded4, KEscapeEncoded4_normal, EscapeUtils::EEscapeNormal);
1.98 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded4, KEscapeEncoded4_url, EscapeUtils::EEscapeUrlEncoded);
1.99 +
1.100 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded5, KEscapeEncoded5_auth, EscapeUtils::EEscapeAuth);
1.101 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded5, KEscapeEncoded5_path, EscapeUtils::EEscapePath);
1.102 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded5, KEscapeEncoded5_query, EscapeUtils::EEscapeQuery);
1.103 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded5, KEscapeEncoded5_normal, EscapeUtils::EEscapeNormal);
1.104 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded5, KEscapeEncoded5_url, EscapeUtils::EEscapeUrlEncoded);
1.105 +
1.106 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded6, KEscapeEncoded6_auth, EscapeUtils::EEscapeAuth);
1.107 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded6, KEscapeEncoded6_path, EscapeUtils::EEscapePath);
1.108 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded6, KEscapeEncoded6_query, EscapeUtils::EEscapeQuery);
1.109 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded6, KEscapeEncoded6_normal, EscapeUtils::EEscapeNormal);
1.110 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded6, KEscapeEncoded6_url, EscapeUtils::EEscapeUrlEncoded);
1.111 +
1.112 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded7, KEscapeEncoded7_auth, EscapeUtils::EEscapeAuth);
1.113 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded7, KEscapeEncoded7_path, EscapeUtils::EEscapePath);
1.114 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded7, KEscapeEncoded7_query, EscapeUtils::EEscapeQuery);
1.115 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded7, KEscapeEncoded7_normal, EscapeUtils::EEscapeNormal);
1.116 + TestEscapeUtilsEscapeEncodeL(KEscapeDecoded7, KEscapeEncoded7_url, EscapeUtils::EEscapeUrlEncoded);
1.117 +
1.118 +
1.119 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded2_auth, KEscapeDecoded2);
1.120 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded2_path, KEscapeDecoded2);
1.121 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded2_query, KEscapeDecoded2);
1.122 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded2_normal, KEscapeDecoded2);
1.123 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded2_url, KEscapeDecoded2);
1.124 +
1.125 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded3_auth, KEscapeDecoded3);
1.126 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded3_path, KEscapeDecoded3);
1.127 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded3_query, KEscapeDecoded3);
1.128 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded3_normal, KEscapeDecoded3);
1.129 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded3_url, KEscapeDecoded3);
1.130 +
1.131 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded4_auth, KEscapeDecoded4);
1.132 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded4_path, KEscapeDecoded4);
1.133 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded4_query, KEscapeDecoded4);
1.134 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded4_normal, KEscapeDecoded4);
1.135 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded4_url, KEscapeDecoded4);
1.136 +
1.137 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded5_auth, KEscapeDecoded5);
1.138 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded5_path, KEscapeDecoded5);
1.139 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded5_query, KEscapeDecoded5);
1.140 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded5_normal, KEscapeDecoded5);
1.141 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded5_url, KEscapeDecoded5);
1.142 +
1.143 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded6_auth, KEscapeDecoded6);
1.144 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded6_path, KEscapeDecoded6);
1.145 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded6_query, KEscapeDecoded6);
1.146 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded6_normal, KEscapeDecoded6);
1.147 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded6_url, KEscapeDecoded6);
1.148 +
1.149 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded7_auth, KEscapeDecoded7);
1.150 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded7_path, KEscapeDecoded7);
1.151 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded7_query, KEscapeDecoded7);
1.152 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded7_normal, KEscapeDecoded7);
1.153 + TestEscapeUtilsEscapeDecodeL(KEscapeEncoded7_url, KEscapeDecoded7);
1.154 +
1.155 + //
1.156 +
1.157 + TestEscapeUtilsUnicodeUtf8ConversionsL(KUnicode_0, KUtf8_0);
1.158 +
1.159 + TestEscapeUtilsIsExcludedCharL(KExcludedChar0, KExcludedChar0_excluded);
1.160 + TestEscapeUtilsIsExcludedCharL(KExcludedChar1, KExcludedChar1_excluded);
1.161 + TestEscapeUtilsIsExcludedCharL(KExcludedChar2, KExcludedChar2_excluded);
1.162 + TestEscapeUtilsIsExcludedCharL(KExcludedChar3, KExcludedChar3_excluded);
1.163 + TestEscapeUtilsIsExcludedCharL(KExcludedChar4, KExcludedChar4_excluded);
1.164 +
1.165 + TestEscapeUtilsIsEscapeTripleL(KEscapeTriple0(), KEscapeTriple0_valid, KEscapeTriple0_value);
1.166 + TestEscapeUtilsIsEscapeTripleL(KEscapeTriple1(), KEscapeTriple1_valid, KEscapeTriple1_value);
1.167 + TestEscapeUtilsIsEscapeTripleL(KEscapeTriple2(), KEscapeTriple2_valid, KEscapeTriple2_value);
1.168 +
1.169 + //TConvBase64 Test
1.170 + TestEscapeUtilsBase64ConversionL(KEscapeDecoded2);
1.171 + }
1.172 +
1.173 +void CEscapeUtilsTest::TestEscapeUtilsEscapeEncodeL(const TDesC& aData, const TDesC& aExpected, EscapeUtils::TEscapeMode aEscapeMode)
1.174 + {
1.175 + iTestHarness->StartTestL(_L("Test EscapeUtils EscapeEncode (16-bit)"));
1.176 +
1.177 + TInt error = DoTestEscapeUtilsEscapeEncode<HBufC16>(aData, aExpected, aEscapeMode);
1.178 +
1.179 + iTestHarness->EndTest(error);
1.180 +
1.181 + // Make 8-bit copy
1.182 + HBufC8* dataBuf = HBufC8::NewLC(aData.Length());
1.183 + TPtr8 data8Bit = dataBuf->Des();
1.184 + data8Bit.Copy(aData);
1.185 +
1.186 + HBufC8* expectedBuf = HBufC8::NewLC(aExpected.Length());
1.187 + TPtr8 expected8Bit = expectedBuf->Des();
1.188 + expected8Bit.Copy(aExpected);
1.189 +
1.190 + iTestHarness->StartTestL(_L("Test EscapeUtils EscapeEncode (8-bit)"));
1.191 +
1.192 + error = DoTestEscapeUtilsEscapeEncode<HBufC8>(data8Bit, expected8Bit, aEscapeMode);
1.193 +
1.194 + iTestHarness->EndTest(error);
1.195 +
1.196 + CleanupStack::PopAndDestroy(2, dataBuf); // dataBuf, expectedBuf
1.197 + }
1.198 +
1.199 +void CEscapeUtilsTest::TestEscapeUtilsEscapeDecodeL(const TDesC& aData, const TDesC& aExpected)
1.200 + {
1.201 + iTestHarness->StartTestL(_L("Test EscapeUtils EscapeDecode (16-bit)"));
1.202 +
1.203 + TInt error = DoTestEscapeUtilsEscapeDecode<HBufC16>(aData, aExpected);
1.204 +
1.205 + iTestHarness->EndTest(error);
1.206 +
1.207 + // Make 8-bit copy
1.208 + HBufC8* dataBuf = HBufC8::NewLC(aData.Length());
1.209 + TPtr8 data8Bit = dataBuf->Des();
1.210 + data8Bit.Copy(aData);
1.211 +
1.212 + HBufC8* expectedBuf = HBufC8::NewLC(aExpected.Length());
1.213 + TPtr8 expected8Bit = expectedBuf->Des();
1.214 + expected8Bit.Copy(aExpected);
1.215 +
1.216 + iTestHarness->StartTestL(_L("Test EscapeUtils EscapeDecode (8-bit)"));
1.217 +
1.218 + error = DoTestEscapeUtilsEscapeDecode<HBufC8>(data8Bit, expected8Bit);
1.219 +
1.220 + iTestHarness->EndTest(error);
1.221 +
1.222 + CleanupStack::PopAndDestroy(2, dataBuf); // dataBuf, expectedBuf
1.223 + }
1.224 +
1.225 +void CEscapeUtilsTest::TestEscapeUtilsUnicodeUtf8ConversionsL(const TDesC& aUnicode, const TDesC& aUtf8)
1.226 + {
1.227 + // Make 8-bit copy of utf8
1.228 + HBufC8* utf8Buf = HBufC8::NewLC(aUtf8.Length());
1.229 + utf8Buf->Des().Copy(aUtf8);
1.230 +
1.231 + // Escape decode
1.232 + HBufC8* unescapedUtf8Buf = EscapeUtils::EscapeDecodeL(*utf8Buf);
1.233 + CleanupStack::PushL(unescapedUtf8Buf);
1.234 + TPtr8 unescapedUtf8 = unescapedUtf8Buf->Des();
1.235 +
1.236 + iTestHarness->StartTestL(_L("Test EscapeUtils ConvertFromUnicodeToUtf8"));
1.237 +
1.238 + HBufC8* convertedUtf8 = NULL;
1.239 + TRAPD(error, convertedUtf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aUnicode));
1.240 + if( error == KErrNone )
1.241 + {
1.242 + // Check is expected
1.243 + if( convertedUtf8->Compare(unescapedUtf8) != 0 )
1.244 + {
1.245 + error = KErrNotFound;
1.246 + }
1.247 + delete convertedUtf8;
1.248 + }
1.249 + iTestHarness->EndTest(error);
1.250 +
1.251 + iTestHarness->StartTestL(_L("Test EscapeUtils ConvertToUnicodeFromUtf8"));
1.252 +
1.253 + HBufC16* convertedUnicode = NULL;
1.254 + TRAP(error, convertedUnicode = EscapeUtils::ConvertToUnicodeFromUtf8L(unescapedUtf8));
1.255 + if( error == KErrNone )
1.256 + {
1.257 + // Check is expected
1.258 + if( convertedUnicode->Compare(aUnicode) != 0 )
1.259 + {
1.260 + error = KErrNotFound;
1.261 + }
1.262 + delete convertedUnicode;
1.263 + }
1.264 + iTestHarness->EndTest(error);
1.265 +
1.266 + CleanupStack::PopAndDestroy(2, utf8Buf); // utf8Buf, unescapedUtf8Buf
1.267 + }
1.268 +
1.269 +void CEscapeUtilsTest::TestEscapeUtilsIsExcludedCharL(TChar aChar, TBool aIsExcluded)
1.270 + {
1.271 + iTestHarness->StartTestL(_L("Test EscapeUtils IsExcludedChar"));
1.272 +
1.273 + TBool excluded = EscapeUtils::IsExcludedChar(aChar);
1.274 +
1.275 + TInt error = KErrNone;
1.276 + if( (!excluded && aIsExcluded) | (excluded && !aIsExcluded) )
1.277 + {
1.278 + error = KErrNotFound;
1.279 + }
1.280 + iTestHarness->EndTest(error);
1.281 + }
1.282 +
1.283 +void CEscapeUtilsTest::TestEscapeUtilsIsEscapeTripleL(const TDesC& aData, TBool aIsTriple, TInt aValue)
1.284 + {
1.285 + iTestHarness->StartTestL(_L("Test EscapeUtils IsEscapeTriple (16-Bit)"));
1.286 +
1.287 + TInt error = DoTestEscapeUtilsIsEscapeTriple(aData, aIsTriple, aValue);
1.288 +
1.289 + iTestHarness->EndTest(error);
1.290 +
1.291 + // Make 8-bit copy
1.292 + HBufC8* dataBuf = HBufC8::NewLC(aData.Length());
1.293 + TPtr8 data8Bit = dataBuf->Des();
1.294 + data8Bit.Copy(aData);
1.295 +
1.296 + iTestHarness->StartTestL(_L("Test EscapeUtils IsEscapeTriple (8-Bit)"));
1.297 +
1.298 + error = DoTestEscapeUtilsIsEscapeTriple(data8Bit, aIsTriple, aValue);
1.299 +
1.300 + iTestHarness->EndTest(error);
1.301 +
1.302 + CleanupStack::PopAndDestroy(dataBuf); // dataBuf
1.303 + }
1.304 +
1.305 +void CEscapeUtilsTest::TestEscapeUtilsBase64ConversionL(const TDesC& aData)
1.306 + {
1.307 + iTestHarness->StartTestL(_L("Test EscapeUtils Base64 Conversion Check"));
1.308 +
1.309 + TInt error = KErrNotFound;
1.310 + HBufC8* dataBuf = HBufC8::NewMaxLC (aData.Length());
1.311 + TPtr8 dataPtr(dataBuf->Des());
1.312 +
1.313 + HBufC8* encodedBuf = HBufC8::NewMaxLC(aData.Length() * 2);
1.314 + TPtr8 encodedPtr(encodedBuf->Des());
1.315 +
1.316 + TBase64 codec;
1.317 + codec.Encode(dataPtr, encodedPtr);
1.318 +
1.319 + HBufC8* decodedBuf = HBufC8::NewMaxLC(aData.Length());
1.320 + TPtr8 decodedPtr(decodedBuf->Des());
1.321 +
1.322 + codec.Decode(encodedPtr, decodedPtr);
1.323 + if(decodedPtr.Compare(dataPtr) == 0)
1.324 + {
1.325 + error = KErrNone;
1.326 + }
1.327 + iTestHarness->EndTest(error);
1.328 +
1.329 + CleanupStack::PopAndDestroy(decodedBuf); // decodedBuf
1.330 + CleanupStack::PopAndDestroy(encodedBuf); // encodedBuf
1.331 + CleanupStack::PopAndDestroy(dataBuf); // dataBuf
1.332 + }
1.333 +
1.334 +//
1.335 +//
1.336 +// Implementation of LOCAL functions
1.337 +//
1.338 +//
1.339 +
1.340 +template<class HBufCType, class TDesCType>
1.341 +LOCAL_C TInt DoTestEscapeUtilsEscapeEncode(const TDesCType& aData, const TDesCType& aExpected, EscapeUtils::TEscapeMode aEscapeMode)
1.342 + {
1.343 + // Do escaping
1.344 + HBufCType* escaped = NULL;
1.345 + TRAPD(error, escaped = EscapeUtils::EscapeEncodeL(aData, aEscapeMode));
1.346 + if( error != KErrNone )
1.347 + {
1.348 + return KErrNotFound;
1.349 + }
1.350 + // Check with expected
1.351 + if( escaped->Compare(aExpected) != 0 )
1.352 + {
1.353 + delete escaped;
1.354 + return KErrNotFound;
1.355 + }
1.356 + delete escaped;
1.357 + return KErrNone;
1.358 + }
1.359 +
1.360 +template<class HBufCType, class TDesCType>
1.361 +LOCAL_C TInt DoTestEscapeUtilsEscapeDecode(const TDesCType& aData, const TDesCType& aExpected)
1.362 + {
1.363 + // Do unescaping
1.364 + HBufCType* unescaped = NULL;
1.365 + TRAPD(error, unescaped = EscapeUtils::EscapeDecodeL(aData));
1.366 + if( error != KErrNone )
1.367 + {
1.368 + return KErrNotFound;
1.369 + }
1.370 + // Check with expected
1.371 + if( unescaped->Compare(aExpected) != 0 )
1.372 + {
1.373 + delete unescaped;
1.374 + return KErrNotFound;
1.375 + }
1.376 + delete unescaped;
1.377 + return KErrNone;
1.378 + }
1.379 +
1.380 +template<class TDesCType>
1.381 +LOCAL_C TInt DoTestEscapeUtilsIsEscapeTriple(const TDesCType& aData, TBool aIsTriple, TInt aValue)
1.382 + {
1.383 + // Check for the triple
1.384 + TInt value;
1.385 + TBool triple = EscapeUtils::IsEscapeTriple(aData, value);
1.386 + if( (!triple && aIsTriple) | (triple && !aIsTriple) )
1.387 + {
1.388 + return KErrNotFound;
1.389 + }
1.390 + if( triple && value != aValue )
1.391 + {
1.392 + return KErrNotFound;
1.393 + }
1.394 + return KErrNone;
1.395 + }