os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_turkishsingle.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_turkishsingle.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,240 @@
1.4 +/*
1.5 +* Copyright (c) 2008-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_turkishsingle.h"
1.27 +
1.28 +const TUint KCharacterSetIdentifier=KCharacterSetIdentifierTurkishSingleSms7Bit;
1.29 +
1.30 +#ifdef __WINS__
1.31 +_LIT(KInputUnicodeFilename, "c:\\test\\data\\gsm7_turkish_single_uni_input.dat");
1.32 +_LIT(KInputForeignFilename, "c:\\test\\data\\gsm7_turkish_single_for_input.dat");
1.33 +_LIT(KExpectUnicodeFilename, "c:\\test\\data\\gsm7_turkish_single_uni_expect.dat");
1.34 +_LIT(KExpectForeignFilename, "c:\\test\\data\\gsm7_turkish_single_for_expect.dat");
1.35 +#else
1.36 +_LIT(KInputUnicodeFilename, "z:\\test\\data\\gsm7_turkish_single_uni_input.dat");
1.37 +_LIT(KInputForeignFilename, "z:\\test\\data\\gsm7_turkish_single_for_input.dat");
1.38 +_LIT(KExpectUnicodeFilename, "z:\\test\\data\\gsm7_turkish_single_uni_expect.dat");
1.39 +_LIT(KExpectForeignFilename, "z:\\test\\data\\gsm7_turkish_single_for_expect.dat");
1.40 +#endif
1.41 +
1.42 +static CCnvCharacterSetConverter* characterSetConverter;
1.43 +static RFs fileServerSession;
1.44 +static TBuf8<974> temp;
1.45 +static TBuf16<487> originalUnicode;
1.46 +static TBuf8<487> generatedForeign;
1.47 +static TBuf16<487> generatedUnicode;
1.48 +
1.49 +#define test(cond) \
1.50 + { \
1.51 + TBool __bb = (cond); \
1.52 + TEST(__bb); \
1.53 + if (!__bb) \
1.54 + { \
1.55 + ERR_PRINTF1(_L("ERROR: Test Failed")); \
1.56 + User::Leave(1); \
1.57 + } \
1.58 + }
1.59 +
1.60 +
1.61 +void CT_TURKISHSINGLE::ReadDescL(TDes8& aDes, const TDesC& aFilename, RFs& aFs)
1.62 + {
1.63 + RFile file;
1.64 + TInt err = file.Open(aFs, aFilename, EFileRead);
1.65 + test(err == KErrNone);
1.66 + CleanupClosePushL(file);
1.67 + err = file.Read(aDes);
1.68 + test(err == KErrNone);
1.69 + CleanupStack::PopAndDestroy(&file);
1.70 + }
1.71 +
1.72 +//translate from unicode big endian TDesC8 to TDes16
1.73 +void CT_TURKISHSINGLE::Unicode_Big(TDesC8& aSource, TDes16& aTarget)
1.74 + {
1.75 + TInt length = aSource.Length();
1.76 + TInt i = 0;
1.77 + for(i=0;i<length-1;i++)
1.78 + {
1.79 + TInt32 temp = *(aSource.Ptr()+(i))*16*16 + *(aSource.Ptr()+i+1);
1.80 + aTarget.Append(temp);
1.81 + i++;
1.82 + }
1.83 + }
1.84 +
1.85 +/**
1.86 +@SYMTestCaseID SYSLIB-CHARCONV-UT-4009
1.87 +@SYMTestCaseDesc Testcase to test new converter name can be listed
1.88 +@SYMTestPriority High
1.89 +@SYMTestActions Test for CreateArrayOfCharacterSetsAvailableLC()
1.90 +@SYMTestExpectedResults The test passed, if Available character sets are listed in epocwind.out
1.91 +@SYMPREQ PREQ22265
1.92 +@SYMREQ REQ10670
1.93 +*/
1.94 +void CT_TURKISHSINGLE::ListAlltheConvertersL()
1.95 + {
1.96 + CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\
1.97 + CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
1.98 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4009 Available:\n "));
1.99 + for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
1.100 + {
1.101 + const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
1.102 + TPtrC charactersSetName(charactersSet.Name());
1.103 + if (charactersSet.NameIsFileName())
1.104 + {
1.105 + charactersSetName.Set(TParsePtrC(charactersSetName).Name());
1.106 + }
1.107 + INFO_PRINTF2(_L(" %S\n"), &charactersSetName);
1.108 + }
1.109 + CleanupStack::PopAndDestroy(arrayOfCharacterSetsAvailable);
1.110 + }
1.111 +
1.112 +/**
1.113 +@SYMTestCaseID SYSLIB-CHARCONV-UT-4010
1.114 +@SYMTestCaseDesc Testcase to test new converter can be prepared
1.115 +@SYMTestPriority High
1.116 +@SYMTestActions Test for PrepareToConvertToOrFromL()
1.117 +@SYMTestExpectedResults The test passed, If EAvailable is returned
1.118 +@SYMPREQ PREQ22265
1.119 +@SYMREQ REQ10670
1.120 +*/
1.121 +void CT_TURKISHSINGLE::PrepareNewConverterL()
1.122 + {
1.123 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4010 Testing new converter can be prepared "));
1.124 + CCnvCharacterSetConverter::TAvailability avaible = characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifier, fileServerSession);
1.125 + test( CCnvCharacterSetConverter::EAvailable == avaible );
1.126 + }
1.127 +
1.128 +/**
1.129 +@SYMTestCaseID SYSLIB-CHARCONV-UT-4011
1.130 +@SYMTestCaseDesc Convert Unicode code to foreign character set
1.131 +@SYMTestPriority High
1.132 +@SYMTestActions Test for ConvertFromUnicode()
1.133 +@SYMTestExpectedResults Test must not fail
1.134 +@SYMPREQ PREQ22265
1.135 +@SYMREQ REQ10670
1.136 +*/
1.137 +void CT_TURKISHSINGLE::ConvertFromUnicodeToForeignL()
1.138 + {
1.139 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4011 Testing encoding from Unicode to Foreign "));
1.140 + ReadDescL(temp, KInputUnicodeFilename, fileServerSession);
1.141 + Unicode_Big(temp, originalUnicode);
1.142 + test(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0);
1.143 + ReadDescL(temp, KExpectForeignFilename, fileServerSession);
1.144 + test(generatedForeign == temp);
1.145 + }
1.146 +
1.147 +/**
1.148 +@SYMTestCaseID SYSLIB-CHARCONV-UT-4012
1.149 +@SYMTestCaseDesc Convert foreign character set to Unicode code
1.150 +@SYMTestPriority High
1.151 +@SYMTestActions Test for ConvertToUnicode() with legal foreign characters, 0x00 - 0x7F
1.152 +@SYMTestExpectedResults Test must not fail
1.153 +@SYMPREQ PREQ22265
1.154 +@SYMREQ REQ10670
1.155 +*/
1.156 +void CT_TURKISHSINGLE::ConvertFromForeignToUnicodeL()
1.157 + {
1.158 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4012 Testing encoding from Foreign to Unicode "));
1.159 + ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession);
1.160 + TInt state=CCnvCharacterSetConverter::KStateDefault;
1.161 + test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
1.162 + ReadDescL(temp, KExpectUnicodeFilename, fileServerSession);
1.163 + originalUnicode.Zero();
1.164 + Unicode_Big(temp, originalUnicode);
1.165 + test(generatedUnicode == originalUnicode);
1.166 + }
1.167 +
1.168 +/**
1.169 +@SYMTestCaseID SYSLIB-CHARCONV-UT-4013
1.170 +@SYMTestCaseDesc Convert illegal character from foreign character set to unicode
1.171 +@SYMTestPriority High
1.172 +@SYMTestActions Test for ConvertToUnicode() with illegal foreign characters 0x1B
1.173 +@SYMTestExpectedResults Test must not fail
1.174 +@SYMPREQ PREQ22265
1.175 +@SYMREQ REQ10670
1.176 +*/
1.177 +void CT_TURKISHSINGLE::ConvertIllegalForeignCharacter()
1.178 + {
1.179 + //test 0x1b
1.180 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4013 Testing EErrorIllFormedInput "));
1.181 + generatedForeign.SetLength(1);
1.182 + generatedForeign[0] = 0x1b; //the escape character
1.183 + TInt state=CCnvCharacterSetConverter::KStateDefault;
1.184 + test( -20 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
1.185 + }
1.186 +
1.187 +/**
1.188 +@SYMTestCaseID SYSLIB-CHARCONV-UT-4014
1.189 +@SYMTestCaseDesc Convert out of range characters from foreign character set to Unicode
1.190 +@SYMTestPriority High
1.191 +@SYMTestActions Test for ConvertToUnicode() for some out of range foreign characters 0x80 - 0xFF
1.192 +@SYMTestExpectedResults Test must not fail
1.193 +@SYMPREQ PREQ22265
1.194 +@SYMREQ REQ10670
1.195 +*/
1.196 +void CT_TURKISHSINGLE::ConvertOutOfRangeForeignCharacters()
1.197 + {
1.198 + //test foreign chararcter point which is not in the scope, e.g. 0x80 in GSM03.38, which should always mapped to 0xFFFD
1.199 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4014 Testing Characters not in the Scope "));
1.200 + generatedForeign.SetLength(1);
1.201 + generatedForeign[0] = 0x80;
1.202 + TInt state=CCnvCharacterSetConverter::KStateDefault;
1.203 + _LIT16(KExpected2, "\xfffd"); //the expected foreign
1.204 + test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
1.205 + test( generatedUnicode == KExpected2 );
1.206 + }
1.207 +
1.208 +void CT_TURKISHSINGLE::DoE32MainL()
1.209 + {
1.210 + CleanupClosePushL(fileServerSession);
1.211 + User::LeaveIfError(fileServerSession.Connect());
1.212 + characterSetConverter=CCnvCharacterSetConverter::NewLC();
1.213 +
1.214 + ListAlltheConvertersL();
1.215 + PrepareNewConverterL();
1.216 + ConvertFromUnicodeToForeignL();
1.217 + ConvertFromForeignToUnicodeL();
1.218 + ConvertIllegalForeignCharacter();
1.219 + ConvertOutOfRangeForeignCharacters();
1.220 +
1.221 + CleanupStack::PopAndDestroy(2);
1.222 + }
1.223 +
1.224 +CT_TURKISHSINGLE::CT_TURKISHSINGLE()
1.225 + {
1.226 + SetTestStepName(KTestStep_T_TURKISHSINGLE);
1.227 + }
1.228 +
1.229 +TVerdict CT_TURKISHSINGLE::doTestStepL()
1.230 + {
1.231 + SetTestStepResult(EFail);
1.232 +
1.233 + __UHEAP_MARK;
1.234 + TRAPD(error1, DoE32MainL());
1.235 + __UHEAP_MARKEND;
1.236 +
1.237 + if(error1 == KErrNone)
1.238 + {
1.239 + SetTestStepResult(EPass);
1.240 + }
1.241 +
1.242 + return TestStepResult();
1.243 + }