os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_gb2312.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/charconvfw/charconvplugins/test/rtest/tsrc/main/t_gb2312.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,168 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-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_gb2312.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 +
    1.40 +/**
    1.41 +@SYMTestCaseID          SYSLIB-CHARCONV-CT-0502
    1.42 +@SYMTestCaseDesc        Tests for converting GB 2312-80 character set to Unicode
    1.43 +@SYMTestPriority        Medium
    1.44 +@SYMTestActions         Tests for simple GB 2312-80 round trips,
    1.45 +						Tests for varying the default Endianness
    1.46 +@SYMTestExpectedResults Test must not fail
    1.47 +@SYMREQ                 REQ0000
    1.48 +*/
    1.49 +void CT_GB2312::DoE32MainL()
    1.50 +	{
    1.51 +	RFs fileServerSession;
    1.52 +	CleanupClosePushL(fileServerSession);
    1.53 +	User::LeaveIfError(fileServerSession.Connect());
    1.54 +	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
    1.55 +	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
    1.56 +	INFO_PRINTF1(_L("Available:\n"));
    1.57 +	for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
    1.58 +		{
    1.59 +		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
    1.60 +		characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
    1.61 +		TPtrC charactersSetName(charactersSet.Name());
    1.62 +		if (charactersSet.NameIsFileName())
    1.63 +			{
    1.64 +			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
    1.65 +			}
    1.66 +		INFO_PRINTF2(_L("    %S\n"), &charactersSetName);
    1.67 +		}
    1.68 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0502 Testing simple GB 2312-80 round trips "));
    1.69 +	characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGb2312, *arrayOfCharacterSetsAvailable, fileServerSession);
    1.70 +	TBuf8<256> originalGb2312;
    1.71 +	TBuf16<256> originalUnicode;
    1.72 +	TBuf8<256> generatedGb2312;
    1.73 +	TBuf16<256> generatedUnicode;
    1.74 +	TInt state=CCnvCharacterSetConverter::KStateDefault;
    1.75 +	//
    1.76 +	INFO_PRINTF1(_L("Empty descriptor"));
    1.77 +	originalUnicode=_L16("");
    1.78 +	test(characterSetConverter->ConvertFromUnicode(generatedGb2312, originalUnicode)==0);
    1.79 +	test(generatedGb2312==_L8(""));
    1.80 +	test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedGb2312, state)==0);
    1.81 +	test(state==CCnvCharacterSetConverter::KStateDefault);
    1.82 +	test(generatedUnicode==originalUnicode);
    1.83 +	INFO_PRINTF1(_L("A couple of sample characters"));
    1.84 +	originalGb2312=_L8("\xb9\xa4\xc8\xcb");
    1.85 +	test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==0);
    1.86 +	test(state==CCnvCharacterSetConverter::KStateDefault);
    1.87 +	test(generatedUnicode.Length()==2);
    1.88 +	test(generatedUnicode[0]==0x5de5);
    1.89 +	test(generatedUnicode[1]==0x4eba);
    1.90 +	test(characterSetConverter->ConvertFromUnicode(generatedGb2312, generatedUnicode)==0);
    1.91 +	test(generatedGb2312==originalGb2312);
    1.92 +	INFO_PRINTF1(_L("Converting trunctated GB 2312-80 which ends half-way through a multi-byte character"));
    1.93 +	originalGb2312=_L8("\xb9\xa4\xc8");
    1.94 +	test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==1);
    1.95 +	test(state==CCnvCharacterSetConverter::KStateDefault);
    1.96 +	test(generatedUnicode.Length()==1);
    1.97 +	test(generatedUnicode[0]==0x5de5);
    1.98 +	originalGb2312=_L8("\xc8");
    1.99 +	test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==CCnvCharacterSetConverter::EErrorIllFormedInput);
   1.100 +	INFO_PRINTF1(_L("Testing varying the default endianness"));
   1.101 +	originalGb2312=_L8("\xb4\xf2");
   1.102 +	characterSetConverter->SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::ELittleEndian);
   1.103 +	test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==0);
   1.104 +	test(state==CCnvCharacterSetConverter::KStateDefault);
   1.105 +	test(generatedUnicode.Length()==1);
   1.106 +	test(generatedUnicode[0]==0x6253);
   1.107 +	test(characterSetConverter->ConvertFromUnicode(generatedGb2312, generatedUnicode)==0);
   1.108 +	test(generatedGb2312==originalGb2312);
   1.109 +	characterSetConverter->SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian);
   1.110 +	test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==0);
   1.111 +	test(state==CCnvCharacterSetConverter::KStateDefault);
   1.112 +	test(generatedUnicode.Length()==1);
   1.113 +	test(generatedUnicode[0]==0x6253);
   1.114 +	test(characterSetConverter->ConvertFromUnicode(generatedGb2312, generatedUnicode)==0);
   1.115 +	test(generatedGb2312==originalGb2312);
   1.116 +	INFO_PRINTF1(_L("Testing a many-to-one conversion"));
   1.117 +	originalUnicode.SetLength(4);
   1.118 +	originalUnicode[0]=0x30fb;
   1.119 +	originalUnicode[1]=0x00b7;
   1.120 +	originalUnicode[2]=0x2014;
   1.121 +	originalUnicode[3]=0x2015;
   1.122 +	test(characterSetConverter->ConvertFromUnicode(generatedGb2312, originalUnicode)==0);
   1.123 +	test(generatedGb2312==_L8("\xa1\xa4\xa1\xa4\xa1\xaa\xa1\xaa"));
   1.124 +	test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedGb2312, state)==0);
   1.125 +	test(state==CCnvCharacterSetConverter::KStateDefault);
   1.126 +	test(generatedUnicode.Length()==4);
   1.127 +	test(generatedUnicode[0]==0x00b7);
   1.128 +	test(generatedUnicode[1]==0x00b7);
   1.129 +	test(generatedUnicode[2]==0x2015);
   1.130 +	test(generatedUnicode[3]==0x2015);
   1.131 +	INFO_PRINTF1(_L("Testing GB2312 being aliased to GBK"));
   1.132 +	TUint charSetId = characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("GB2312"), fileServerSession);
   1.133 +	test(charSetId==KCharacterSetIdentifierGbk);
   1.134 +	test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("csGB2312"), fileServerSession)==KCharacterSetIdentifierGbk);
   1.135 +	test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("iso-ir-58"), fileServerSession)==KCharacterSetIdentifierGbk);
   1.136 +	test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("chinese"), fileServerSession)==KCharacterSetIdentifierGbk);
   1.137 +	test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("csISO58GB231280"), fileServerSession)==KCharacterSetIdentifierGbk);
   1.138 +	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(57, fileServerSession)==KCharacterSetIdentifierGbk);
   1.139 +	test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(2025, fileServerSession)==KCharacterSetIdentifierGbk);
   1.140 +	characterSetConverter->PrepareToConvertToOrFromL(charSetId, *arrayOfCharacterSetsAvailable, fileServerSession);
   1.141 +	originalUnicode.SetLength(3);
   1.142 +	originalUnicode[0]=0x9556; // this has a corresponding GB2312 character
   1.143 +	originalUnicode[1]=0x9555; // this has a corresponding GBK character not in GB2312...
   1.144 +	originalUnicode[2]=0x9394; // ... as does this
   1.145 +	test(characterSetConverter->ConvertFromUnicode(generatedGb2312, originalUnicode)==0);
   1.146 +	test(generatedGb2312.Length()==6);
   1.147 +	test(generatedGb2312==_L8("\xef\xda\xe9\x46\xe6\x67"));
   1.148 +	CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
   1.149 +	}
   1.150 +
   1.151 +CT_GB2312::CT_GB2312()
   1.152 +    {
   1.153 +    SetTestStepName(KTestStep_T_GB2312);
   1.154 +    }
   1.155 +
   1.156 +TVerdict CT_GB2312::doTestStepL()
   1.157 +    {
   1.158 +    SetTestStepResult(EFail);
   1.159 +
   1.160 +    __UHEAP_MARK;
   1.161 +    TRAPD(error1, DoE32MainL());    
   1.162 +    __UHEAP_MARKEND;
   1.163 +
   1.164 +    if(error1 == KErrNone)
   1.165 +        {
   1.166 +        SetTestStepResult(EPass);
   1.167 +        }
   1.168 +
   1.169 +    return TestStepResult();
   1.170 +    }
   1.171 +