1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_ucs2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,618 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <e32std.h>
1.23 +#include <e32base.h>
1.24 +#include <f32file.h>
1.25 +#include <charconv.h>
1.26 +#include "t_ucs2.h"
1.27 +
1.28 +#define test(cond) \
1.29 + { \
1.30 + TBool __bb = (cond); \
1.31 + TEST(__bb); \
1.32 + if (!__bb) \
1.33 + { \
1.34 + ERR_PRINTF1(_L("ERROR: Test Failed")); \
1.35 + User::Leave(1); \
1.36 + } \
1.37 + }
1.38 +
1.39 +const TInt KMibValue = 1000;
1.40 +
1.41 +const TInt KBufferLength1=1;
1.42 +const TInt KBufferLength6=6;
1.43 +const TInt KBufferLength8=8;
1.44 +const TInt KBufferLength40=40;
1.45 +
1.46 +const TPtrC8 KForeignBufferEven12LE(_S8("\xff\xfe\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a"));
1.47 +const TPtrC8 KForeignBufferOdd13LE(_S8("\xff\xfe\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b"));
1.48 +const TPtrC8 KForeignBufferEven12BE(_S8("\xfe\xff\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49"));
1.49 +const TPtrC8 KForeignBufferOdd13BE(_S8("\xfe\xff\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4b"));
1.50 +
1.51 +const TPtrC8 KForeignBufferEvenWithoutBOM10LE(_S8("\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a"));
1.52 +const TPtrC8 KForeignBufferOddWithoutBOM11LE(_S8("\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b"));
1.53 +const TPtrC8 KForeignBufferEvenWithoutBOM10BE(_S8("\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49"));
1.54 +const TPtrC8 KForeignBufferOddWithoutBOM11BE(_S8("\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4b"));
1.55 +
1.56 +const TPtrC8 KForeignBufferEven24LE(_S8("\xff\xfe\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56"));
1.57 +const TPtrC8 KForeignBufferOdd25LE(_S8("\xff\xfe\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57"));
1.58 +const TPtrC8 KForeignBufferEven24BE(_S8("\xfe\xff\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4c\x4b\x4e\x4d\x50\x4f\x52\x51\x54\x53\x56\x55"));
1.59 +const TPtrC8 KForeignBufferOdd25BE(_S8("\xfe\xff\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4c\x4b\x4e\x4d\x50\x4f\x52\x51\x54\x53\x56\x55\x57"));
1.60 +
1.61 +const TPtrC8 KForeignBufferEvenWithoutBOM22LE(_S8("\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56"));
1.62 +const TPtrC8 KForeignBufferOddWithoutBOM23LE(_S8("\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57"));
1.63 +const TPtrC8 KForeignBufferEvenWithoutBOM22BE(_S8("\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4c\x4b\x4e\x4d\x50\x4f\x52\x51\x54\x53\x56\x55"));
1.64 +const TPtrC8 KForeignBufferOddWithoutBOM23BE(_S8("\x42\x41\x44\x43\x46\x45\x48\x47\x4a\x49\x4c\x4b\x4e\x4d\x50\x4f\x52\x51\x54\x53\x56\x55\x57"));
1.65 +
1.66 +const TPtrC16 KUnicodeBufferEven14BE(_S16("\xfeff\x4142\x4344\x4546\x4748\x494a\x4b4c\x4d4e\x4f50\x5152\x5354\x5556\x5758\x595a"));
1.67 +const TPtrC16 KUnicodeBufferOdd15BE(_S16("\xfeff\x4142\x4344\x4546\x4748\x494a\x4b4c\x4d4e\x4f50\x5152\x5354\x5556\x5758\x595a\x5b5c"));
1.68 +
1.69 +/**
1.70 +@SYMTestCaseID SYSLIB-CHARCONV-CT-0553
1.71 +@SYMTestCaseDesc 8 bit to UCS2 Little Endian Conversion - Single pass test
1.72 +@SYMTestPriority Medium
1.73 +@SYMTestActions Tests a 8 bit string to 16 bit UCS2 conversion.
1.74 + Test with and without Byte Order Mark. Byte Order Mark is set to Little Endian.
1.75 + Output buffer is large enough to contain the complete input string
1.76 + on a single pass
1.77 +@SYMTestExpectedResults Test must not fail
1.78 +@SYMREQ REQ0000
1.79 +*/
1.80 +void CT_UCS2::LEConversionSinglePassBOM(CCnvCharacterSetConverter& aCharacterSetConverter)
1.81 +{
1.82 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0553 "));
1.83 + TBuf16<KBufferLength40> generatedUnicode;
1.84 + TInt state=CCnvCharacterSetConverter::KStateDefault;
1.85 + TInt numberOfUnconvertibleCharacters=0;
1.86 + TInt indexOfFirstByteOfFirstUnconvertibleCharacter=0;
1.87 + TInt numberLeft =0;
1.88 +
1.89 + // set the default endianness to little Endian
1.90 + aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::ELittleEndian);
1.91 +
1.92 + // test even number of foreign bytes
1.93 + aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven12LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.94 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49"));
1.95 + test(numberOfUnconvertibleCharacters==0);
1.96 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.97 + INFO_PRINTF1(_L("\nLittleEndianConversionSinglePassEvenBOM - OK"));
1.98 +
1.99 + // test even number of foreign bytes without BOM
1.100 + aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM10LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.101 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49"));
1.102 + test(numberOfUnconvertibleCharacters==0);
1.103 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.104 + INFO_PRINTF1(_L("\nLittleEndianConversionSinglePassEvenBOM - OK"));
1.105 +
1.106 + // test odd number of foreign bytes
1.107 + state=CCnvCharacterSetConverter::KStateDefault;
1.108 + numberLeft = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd13LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.109 + test(numberLeft==1);
1.110 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49"));
1.111 + test(numberOfUnconvertibleCharacters==0);
1.112 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.113 +
1.114 + // test odd number of foreign bytes without BOM
1.115 + numberLeft = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM11LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.116 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49"));
1.117 + test(numberLeft==1);
1.118 + test(numberOfUnconvertibleCharacters==0);
1.119 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.120 +
1.121 + INFO_PRINTF1(_L("\nLittleEndianConversionSinglePassOddBOM - OK"));
1.122 +}
1.123 +/**
1.124 +@SYMTestCaseID SYSLIB-CHARCONV-CT-0554
1.125 +@SYMTestCaseDesc 8 bit to UCS2 Little Endian Conversion - Multiple pass test
1.126 +@SYMTestPriority Medium
1.127 +@SYMTestActions Tests a 8 bit string to 16 bit UCS2 conversion.
1.128 + With and without Byte Order Mark. Byte Order Mark is set to Little Endian.
1.129 + Output buffer is NOT large enough to contain the complete input string
1.130 + on a single pass. Multiple calls are made to complete translation.
1.131 +@SYMTestExpectedResults Test must not fail
1.132 +@SYMREQ REQ0000
1.133 +*/
1.134 +void CT_UCS2::LEConversionMultiplePassBOM(CCnvCharacterSetConverter& aCharacterSetConverter)
1.135 +{
1.136 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0554 "));
1.137 + TBuf16<KBufferLength6> generatedUnicode;
1.138 + TInt state=CCnvCharacterSetConverter::KStateDefault;
1.139 + TInt numberOfUnconvertibleCharacters=0;
1.140 + TInt indexOfFirstByteOfFirstUnconvertibleCharacter=0;
1.141 +
1.142 + // set the default endianness to little Endian
1.143 + aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::ELittleEndian);
1.144 +
1.145 + // test even number of foreign bytes
1.146 + // first pass
1.147 + TInt numberUnconverted;
1.148 + numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven24LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.149 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b"));
1.150 + test(numberUnconverted==10);
1.151 + test(numberOfUnconvertibleCharacters==0);
1.152 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.153 +
1.154 + // test even number of foreign bytes without BOM
1.155 + numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM22LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.156 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b"));
1.157 + test(numberUnconverted==10);
1.158 + test(numberOfUnconvertibleCharacters==0);
1.159 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.160 +
1.161 + // second pass
1.162 + numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven24LE.Right(numberUnconverted), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.163 + test(numberUnconverted==0);
1.164 + test(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655"));
1.165 + test(numberOfUnconvertibleCharacters==0);
1.166 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.167 + INFO_PRINTF1(_L("\nLittleEndianConversionMultiplePassOddEven - OK"));
1.168 +
1.169 + // without BOM
1.170 + numberOfUnconvertibleCharacters=10;
1.171 + aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM22LE.Right(numberOfUnconvertibleCharacters), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.172 + test(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655"));
1.173 + test(numberOfUnconvertibleCharacters==0);
1.174 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.175 + INFO_PRINTF1(_L("\nLittleEndianConversionMultiplePassOddEven - OK"));
1.176 +
1.177 +
1.178 + // test odd number of foreign bytes
1.179 + // first pass
1.180 + state=CCnvCharacterSetConverter::KStateDefault;
1.181 + numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd25LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.182 + test(numberUnconverted==11);
1.183 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.184 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b"));
1.185 +
1.186 + // without BOM
1.187 + numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM23LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.188 + test(numberUnconverted==11);
1.189 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.190 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b"));
1.191 +
1.192 + // second pass
1.193 + numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd25LE.Right(numberUnconverted), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.194 + test(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655"));
1.195 + test(numberUnconverted==1);
1.196 + test(numberOfUnconvertibleCharacters==0);
1.197 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.198 +
1.199 + // without BOM
1.200 + numberUnconverted = 11;
1.201 + numberUnconverted = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM23LE.Right(numberUnconverted), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.202 + test(numberUnconverted==1);
1.203 + test(numberOfUnconvertibleCharacters==0);
1.204 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.205 + test(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655"));
1.206 +
1.207 +
1.208 + INFO_PRINTF1(_L("\nLittleEndianConversionMultiplePassOddBOM - OK"));
1.209 +}
1.210 +/**
1.211 +@SYMTestCaseID SYSLIB-CHARCONV-CT-0555
1.212 +@SYMTestCaseDesc 8 bit to UCS2 Big Endian Conversion - Single pass
1.213 +@SYMTestPriority Medium
1.214 +@SYMTestActions Tests a 8 bit string to 16 bit UCS2 conversion.
1.215 + With and without Byte Order Mark. Byte Order Mark is set to Big Endian.
1.216 + Output buffer is large enough to contain the complete input string
1.217 + on a single pass
1.218 +@SYMTestExpectedResults Test must not fail
1.219 +@SYMREQ REQ0000
1.220 +*/
1.221 +void CT_UCS2::BEConversionSinglePassBOM(CCnvCharacterSetConverter& aCharacterSetConverter)
1.222 +{
1.223 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0555 "));
1.224 + TBuf16<KBufferLength40> generatedUnicode;
1.225 + TInt state=CCnvCharacterSetConverter::KStateDefault;
1.226 + TInt numberOfUnconvertibleCharacters=0;
1.227 + TInt indexOfFirstByteOfFirstUnconvertibleCharacter=0;
1.228 + TInt numberLeft=0;
1.229 +
1.230 + // set the default endianness to Big Endian
1.231 + aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian);
1.232 +
1.233 + // test even number of foreign bytes
1.234 + aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven12BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.235 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49"));
1.236 + test(numberOfUnconvertibleCharacters==0);
1.237 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.238 + INFO_PRINTF1(_L("\nBigEndianConversionSinglePassEvenBOM - OK"));
1.239 +
1.240 + // test even number of foreign bytes without BOM
1.241 + aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM10BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.242 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49"));
1.243 + test(numberOfUnconvertibleCharacters==0);
1.244 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.245 + INFO_PRINTF1(_L("\nBigEndianConversionSinglePassEvenBOM - OK"));
1.246 +
1.247 +
1.248 + // test odd number of foreign bytes
1.249 + state=CCnvCharacterSetConverter::KStateDefault;
1.250 + numberLeft = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd13BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.251 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49"));
1.252 + test(numberLeft==1);
1.253 + test(numberOfUnconvertibleCharacters==0);
1.254 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.255 +
1.256 + // test odd number of foreign bytes without BOM
1.257 + numberLeft = aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM11BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.258 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49"));
1.259 + test(numberLeft==1);
1.260 + test(numberOfUnconvertibleCharacters==0);
1.261 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.262 +
1.263 + INFO_PRINTF1(_L("\nBigEndianConversionSinglePassOddBOM - OK"));
1.264 +}
1.265 +/**
1.266 +@SYMTestCaseID SYSLIB-CHARCONV-CT-0556
1.267 +@SYMTestCaseDesc 8 bit to UCS2 Big Endian Conversion - Multiple pass test
1.268 +@SYMTestPriority Medium
1.269 +@SYMTestActions Tests a 8 bit string to 16 bit UCS2 conversion.
1.270 + With and without Byte Order Mark. Byte Order Mark is set to Big Endian.
1.271 + Output buffer is NOT large enough to contain the complete input string
1.272 + on a single pass. Multiple calls are made to complete translation.
1.273 +@SYMTestExpectedResults Test must not fail
1.274 +@SYMREQ REQ0000
1.275 +*/
1.276 +void CT_UCS2::BEConversionMultiplePassBOM(CCnvCharacterSetConverter& aCharacterSetConverter)
1.277 +{
1.278 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0556 "));
1.279 + TBuf16<KBufferLength6> generatedUnicode;
1.280 + TInt state=CCnvCharacterSetConverter::KStateDefault;
1.281 + TInt numberOfUnconvertibleCharacters=0;
1.282 + TInt indexOfFirstByteOfFirstUnconvertibleCharacter=0;
1.283 + TInt numberUnconverted=0;
1.284 +
1.285 + // set the default endianness to Big Endian
1.286 + aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian);
1.287 +
1.288 + // test even number of foreign bytes
1.289 + // first pass
1.290 + numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven24BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.291 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b"));
1.292 + test(numberUnconverted==10);
1.293 + test(numberOfUnconvertibleCharacters==0);
1.294 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.295 +
1.296 + // without BOM
1.297 + numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM22BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.298 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b"));
1.299 + test(numberUnconverted==10);
1.300 + test(numberOfUnconvertibleCharacters==0);
1.301 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.302 +
1.303 + // second pass
1.304 + numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEven24BE.Right(numberUnconverted), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.305 + test(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655"));
1.306 + test(numberUnconverted==0);
1.307 + test(numberOfUnconvertibleCharacters==0);
1.308 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.309 + INFO_PRINTF1(_L("\nBigEndianConversionMultiplePassOddEven - OK"));
1.310 +
1.311 + // without BOM
1.312 + numberOfUnconvertibleCharacters=10;
1.313 + numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferEvenWithoutBOM22BE.Right(numberOfUnconvertibleCharacters), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.314 + test(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655"));
1.315 + test(numberOfUnconvertibleCharacters==0);
1.316 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.317 + INFO_PRINTF1(_L("\nBigEndianConversionMultiplePassOddEven - OK"));
1.318 +
1.319 + // test odd number of foreign bytes
1.320 + // first pass
1.321 + state=CCnvCharacterSetConverter::KStateDefault;
1.322 + numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd25BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.323 + test(numberUnconverted==11);
1.324 + test(numberOfUnconvertibleCharacters==0);
1.325 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.326 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b"));
1.327 +
1.328 + // without BOM
1.329 + numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM23BE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.330 + test(numberUnconverted==11);
1.331 + test(numberOfUnconvertibleCharacters==0);
1.332 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.333 + test(generatedUnicode==_L16("\x4241\x4443\x4645\x4847\x4a49\x4c4b"));
1.334 +
1.335 + // second pass
1.336 + numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOdd25BE.Right(numberUnconverted), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.337 + test(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655"));
1.338 + test(numberUnconverted==1);
1.339 + test(numberOfUnconvertibleCharacters==0);
1.340 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.341 +
1.342 + // without BOM
1.343 + numberOfUnconvertibleCharacters=11;
1.344 + numberUnconverted=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, KForeignBufferOddWithoutBOM23BE.Right(numberOfUnconvertibleCharacters), state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.345 + test(generatedUnicode==_L16("\x4e4d\x504f\x5251\x5453\x5655"));
1.346 + test(numberUnconverted==1);
1.347 + test(numberOfUnconvertibleCharacters==0);
1.348 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.349 +
1.350 +
1.351 + INFO_PRINTF1(_L("\nBigEndianConversionMultiplePassOddBOM - OK"));
1.352 +}
1.353 +/**
1.354 +@SYMTestCaseID SYSLIB-CHARCONV-CT-0557
1.355 +@SYMTestCaseDesc UCS2 to 8 bit Big Endian Conversion - Single pass test
1.356 +@SYMTestPriority Medium
1.357 +@SYMTestActions Tests a 16 bit UCS2 to 8 bit descriptor conversion.
1.358 + Byte Order Mark is present and is set to Big Endian.
1.359 + Output buffer is large enough to contain the complete input string
1.360 + on a single pass
1.361 +@SYMTestExpectedResults Test must not fail
1.362 +@SYMREQ REQ0000
1.363 +*/
1.364 +void CT_UCS2::UCS2BEConversionSinglePassBOM(CCnvCharacterSetConverter& aCharacterSetConverter)
1.365 +{
1.366 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0557 "));
1.367 + TBuf8<KBufferLength40> generatedForeign;
1.368 + CCnvCharacterSetConverter::TArrayOfAscendingIndices indicesOfUnconvertibleCharacters;
1.369 +
1.370 + // set the default endianness to Big Endian
1.371 + aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian);
1.372 +
1.373 + // test even number of foreign bytes
1.374 + aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.375 + KUnicodeBufferEven14BE,
1.376 + indicesOfUnconvertibleCharacters );
1.377 +
1.378 + test(generatedForeign==_L8("\xfe\xff\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a"));
1.379 + INFO_PRINTF1(_L("\nUCS2BEConversionSinglePassEvenBOM - OK"));
1.380 +
1.381 + // test odd number of foreign bytes
1.382 + aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.383 + KUnicodeBufferOdd15BE,
1.384 + indicesOfUnconvertibleCharacters );
1.385 +
1.386 + test(generatedForeign==_L8("\xfe\xff\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c"));
1.387 + INFO_PRINTF1(_L("\nUCS2BEConversionSinglePassOddBOM - OK"));
1.388 +}
1.389 +/**
1.390 +@SYMTestCaseID SYSLIB-CHARCONV-CT-0558
1.391 +@SYMTestCaseDesc UCS2 to 8 bit Big Endian Conversion - Multiple pass test
1.392 +@SYMTestPriority Medium
1.393 +@SYMTestActions Tests a 16 bit UCS2 to 8 bit descriptor conversion.
1.394 + Byte Order Mark is present and is set to Big Endian.
1.395 + Output buffer is NOT large enough to contain the complete input string
1.396 + on a single pass
1.397 +@SYMTestExpectedResults Test must not fail
1.398 +@SYMREQ REQ0000
1.399 +*/
1.400 +void CT_UCS2::UCS2BEConversionMultiplePassBOM (CCnvCharacterSetConverter& aCharacterSetConverter)
1.401 +{
1.402 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0558 "));
1.403 + TBuf8<KBufferLength6> generatedForeign;
1.404 + TBuf8<KBufferLength8> generatedForeign2;
1.405 + TInt result=0;
1.406 + CCnvCharacterSetConverter::TArrayOfAscendingIndices indicesOfUnconvertibleCharacters;
1.407 +
1.408 + // set the default endianness to Big Endian
1.409 + aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian);
1.410 +
1.411 + // *** Test even number of bytes ***
1.412 + // test even number of foreign bytes - pass 1
1.413 + result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.414 + KUnicodeBufferEven14BE,
1.415 + indicesOfUnconvertibleCharacters );
1.416 + test(generatedForeign==_L8("\xfe\xff\x41\x42\x43\x44"));
1.417 + test(result==11);
1.418 +
1.419 + // test even number of foreign bytes - pass 2
1.420 + result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.421 + KUnicodeBufferEven14BE.Right(result),
1.422 + indicesOfUnconvertibleCharacters );
1.423 + test(result==8);
1.424 + test(generatedForeign==_L8("\x45\x46\x47\x48\x49\x4A"));
1.425 +
1.426 + // test even number of foreign bytes - pass 3
1.427 + result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.428 + KUnicodeBufferEven14BE.Right(result),
1.429 + indicesOfUnconvertibleCharacters );
1.430 + test(result==5);
1.431 + test(generatedForeign==_L8("\x4b\x4c\x4d\x4e\x4f\x50"));
1.432 +
1.433 +
1.434 + // test even number of foreign bytes - pass 4
1.435 + result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.436 + KUnicodeBufferEven14BE.Right(result),
1.437 + indicesOfUnconvertibleCharacters );
1.438 + test(result==2);
1.439 + test(generatedForeign==_L8("\x51\x52\x53\x54\x55\x56"));
1.440 +
1.441 + // test even number of foreign bytes - pass 5
1.442 + result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign2,
1.443 + KUnicodeBufferEven14BE.Right(result),
1.444 + indicesOfUnconvertibleCharacters );
1.445 + test(generatedForeign2==_L8("\x57\x58\x59\x5a"));
1.446 + test(result==0);
1.447 +
1.448 + INFO_PRINTF1(_L("\nUCS2LEConversionMultiplePassEvenBOM - OK"));
1.449 +
1.450 + // *** Test odd numer of bytes ***
1.451 + result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.452 + KUnicodeBufferOdd15BE,
1.453 + indicesOfUnconvertibleCharacters );
1.454 + test(generatedForeign==_L8("\xfe\xff\x41\x42\x43\x44"));
1.455 +
1.456 + // test even number of foreign bytes - pass 2
1.457 + result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.458 + KUnicodeBufferOdd15BE.Right(result),
1.459 + indicesOfUnconvertibleCharacters );
1.460 + test(generatedForeign==_L8("\x45\x46\x47\x48\x49\x4a"));
1.461 +
1.462 + // test even number of foreign bytes - pass 3
1.463 + result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.464 + KUnicodeBufferOdd15BE.Right(result),
1.465 + indicesOfUnconvertibleCharacters );
1.466 + test(generatedForeign==_L8("\x4b\x4c\x4d\x4e\x4f\x50"));
1.467 +
1.468 + // test even number of foreign bytes - pass 4
1.469 + result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.470 + KUnicodeBufferOdd15BE.Right(result),
1.471 + indicesOfUnconvertibleCharacters );
1.472 + test(generatedForeign==_L8("\x51\x52\x53\x54\x55\x56"));
1.473 +
1.474 +
1.475 + // test even number of foreign bytes - pass 5
1.476 + result = aCharacterSetConverter.ConvertFromUnicode( generatedForeign,
1.477 + KUnicodeBufferOdd15BE.Right(result),
1.478 + indicesOfUnconvertibleCharacters );
1.479 + test(generatedForeign==_L8("\x57\x58\x59\x5a\x5b\x5c"));
1.480 + test(result==0);
1.481 +
1.482 + INFO_PRINTF1(_L("\nUCS2LEConversionMultiplePassOddBOM - OK"));
1.483 +}
1.484 +/**
1.485 +@SYMTestCaseID SYSLIB-CHARCONV-CT-0559
1.486 +@SYMTestCaseDesc Tests a 16 bit UCS2 to 8 bit & 16 bit UCS2 to 8 bit conversion with empty buffers.
1.487 +@SYMTestPriority Medium
1.488 +@SYMTestActions Attempt for conversion when input and output buffers are small
1.489 +@SYMTestExpectedResults Test must not fail
1.490 +@SYMREQ REQ0000
1.491 +*/
1.492 +void CT_UCS2::TooSmallBufferConversion (CCnvCharacterSetConverter& aCharacterSetConverter)
1.493 + {
1.494 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0559 "));
1.495 + TBuf16<KBufferLength1> generatedUnicode1;
1.496 + TBuf8<KBufferLength1> generatedForeign1;
1.497 +
1.498 + TInt state=CCnvCharacterSetConverter::KStateDefault;
1.499 + TInt numberOfUnconvertibleCharacters=0;
1.500 + TInt indexOfFirstByteOfFirstUnconvertibleCharacter=0;
1.501 +
1.502 + CCnvCharacterSetConverter::TArrayOfAscendingIndices indicesOfUnconvertibleCharacters;
1.503 +
1.504 + // set the default endianness to little Endian
1.505 + aCharacterSetConverter.SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::ELittleEndian);
1.506 +
1.507 + // convert to UCS2 using an output buffer that is too small
1.508 + TInt result = aCharacterSetConverter.ConvertToUnicode(generatedUnicode1, KForeignBufferEven12LE, state, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter);
1.509 + test(generatedUnicode1==_L16("\x4241"));
1.510 + test(result==8);
1.511 + test(numberOfUnconvertibleCharacters==0);
1.512 + test(indexOfFirstByteOfFirstUnconvertibleCharacter==-1);
1.513 + INFO_PRINTF1(_L("\n8bit->UCS2 output buffer size 1 - OK"));
1.514 +
1.515 + INFO_PRINTF1(_L("\nConversionTooSmallBuffer - OK"));
1.516 + }
1.517 +/**
1.518 +@SYMTestCaseID SYSLIB-CHARCONV-CT-0560
1.519 +@SYMTestCaseDesc Conversion tests from UCS2 GUID to MIB
1.520 +@SYMTestPriority Medium
1.521 +@SYMTestActions Tests retreiving the MIB value from the UCS2 GUID
1.522 + Tests retreiving the UCS2 GUID from the MIB value
1.523 +@SYMTestExpectedResults Test must not fail
1.524 +@SYMREQ REQ0000
1.525 +*/
1.526 +void CT_UCS2::CharacterSetValueAndMIBTests(CCnvCharacterSetConverter& aCharacterSetConverter, RFs& aFileServerSession)
1.527 +{
1.528 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0560 "));
1.529 + // check that the character set value of '1000' is converted to the UCS2 GUID (0x101ff492)
1.530 + test(aCharacterSetConverter.ConvertMibEnumOfCharacterSetToIdentifierL(KMibValue,aFileServerSession)==KCharacterSetIdentifierUcs2);
1.531 + INFO_PRINTF1(_L("\nMIB->Char Set GUID - OK"));
1.532 +
1.533 + // check that the UCS2 GUID (0x101ff492) is converted to the character set value of '1000'
1.534 + test(aCharacterSetConverter.ConvertCharacterSetIdentifierToMibEnumL(KCharacterSetIdentifierUcs2,aFileServerSession)==KMibValue);
1.535 + INFO_PRINTF1(_L("\nChar Set GUID->MIB - OK"));
1.536 +}
1.537 +
1.538 +
1.539 +void CT_UCS2::DoE32MainL()
1.540 + {
1.541 + RFs fileServerSession;
1.542 + CleanupClosePushL(fileServerSession);
1.543 + User::LeaveIfError(fileServerSession.Connect());
1.544 + CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
1.545 + CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
1.546 + TInt i;
1.547 + for (i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
1.548 + {
1.549 + const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
1.550 + characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
1.551 + TPtrC charactersSetName(charactersSet.Name());
1.552 + if (charactersSet.NameIsFileName())
1.553 + {
1.554 + charactersSetName.Set(TParsePtrC(charactersSetName).Name());
1.555 + }
1.556 + INFO_PRINTF2(_L(" %S\n"), &charactersSetName);
1.557 + }
1.558 +
1.559 + // test MIB to Character Set ID (and visa versa) conversion
1.560 + CharacterSetValueAndMIBTests(*characterSetConverter, fileServerSession);
1.561 +
1.562 + // prepare for conversion
1.563 + INFO_PRINTF1(_L("\nTesting 8 bit -> UCS2 conversion"));
1.564 + TRAPD( error, characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUcs2, *arrayOfCharacterSetsAvailable, fileServerSession));
1.565 + if ( error != KErrNone )
1.566 + {
1.567 + RDebug::Print(_L("PrepareToConvertToOrFromL failed code:%d\n"),error);
1.568 + RDebug::Print(_L("KCharacterSetIdentifierUcs2 is not available so tests failed\n"));
1.569 + User::LeaveIfError(error);
1.570 + }
1.571 +
1.572 +
1.573 + // *** 8 bit to UCS2 conversion ***
1.574 + INFO_PRINTF1(_L("\n8->UCS2 Little Endian Conversion - Single pass"));
1.575 + LEConversionSinglePassBOM(*characterSetConverter);
1.576 +
1.577 + INFO_PRINTF1(_L("\n8->UCS2 Little Endian Conversion - Multiple pass"));
1.578 + LEConversionMultiplePassBOM(*characterSetConverter);
1.579 +
1.580 + INFO_PRINTF1(_L("\n8->UCS2 Big Endian Conversion - Single pass"));
1.581 + BEConversionSinglePassBOM(*characterSetConverter);
1.582 +
1.583 + INFO_PRINTF1(_L("\n8->UCS2 Big Endian Conversion - Multiple pass"));
1.584 + BEConversionMultiplePassBOM(*characterSetConverter);
1.585 +
1.586 +
1.587 + // *** UCS2 to 8 bit conversion ***
1.588 + INFO_PRINTF1(_L("\nUCS2->8 Big Endian Conversion - Single pass"));
1.589 + UCS2BEConversionSinglePassBOM(*characterSetConverter);
1.590 +
1.591 + INFO_PRINTF1(_L("\nUCS2->8 Big Endian Conversion - Multiple pass"));
1.592 + UCS2BEConversionMultiplePassBOM(*characterSetConverter);
1.593 +
1.594 + // *** attempted conversion when input/output buffers are too small
1.595 + INFO_PRINTF1(_L("\nTooSmallBufferConversion"));
1.596 + TooSmallBufferConversion(*characterSetConverter);
1.597 +
1.598 + INFO_PRINTF1(_L("\n"));
1.599 + CleanupStack::PopAndDestroy(3);// arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
1.600 + }
1.601 +
1.602 +CT_UCS2::CT_UCS2()
1.603 + {
1.604 + SetTestStepName(KTestStep_T_UCS2);
1.605 + }
1.606 +
1.607 +TVerdict CT_UCS2::doTestStepL()
1.608 + {
1.609 + SetTestStepResult(EFail);
1.610 +
1.611 + __UHEAP_MARK;
1.612 + TRAPD(error1, DoE32MainL());
1.613 + __UHEAP_MARKEND;
1.614 +
1.615 + if(error1 == KErrNone)
1.616 + {
1.617 + SetTestStepResult(EPass);
1.618 + }
1.619 +
1.620 + return TestStepResult();
1.621 + }