sl@0: /* sl@0: * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_gb2312.h" sl@0: sl@0: #define test(cond) \ sl@0: { \ sl@0: TBool __bb = (cond); \ sl@0: TEST(__bb); \ sl@0: if (!__bb) \ sl@0: { \ sl@0: ERR_PRINTF1(_L("ERROR: Test Failed")); \ sl@0: User::Leave(1); \ sl@0: } \ sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CHARCONV-CT-0502 sl@0: @SYMTestCaseDesc Tests for converting GB 2312-80 character set to Unicode sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Tests for simple GB 2312-80 round trips, sl@0: Tests for varying the default Endianness sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void CT_GB2312::DoE32MainL() sl@0: { sl@0: RFs fileServerSession; sl@0: CleanupClosePushL(fileServerSession); sl@0: User::LeaveIfError(fileServerSession.Connect()); sl@0: CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC(); sl@0: CArrayFix* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession); sl@0: INFO_PRINTF1(_L("Available:\n")); sl@0: for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i) sl@0: { sl@0: const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i]; sl@0: characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession); sl@0: TPtrC charactersSetName(charactersSet.Name()); sl@0: if (charactersSet.NameIsFileName()) sl@0: { sl@0: charactersSetName.Set(TParsePtrC(charactersSetName).Name()); sl@0: } sl@0: INFO_PRINTF2(_L(" %S\n"), &charactersSetName); sl@0: } sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0502 Testing simple GB 2312-80 round trips ")); sl@0: characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGb2312, *arrayOfCharacterSetsAvailable, fileServerSession); sl@0: TBuf8<256> originalGb2312; sl@0: TBuf16<256> originalUnicode; sl@0: TBuf8<256> generatedGb2312; sl@0: TBuf16<256> generatedUnicode; sl@0: TInt state=CCnvCharacterSetConverter::KStateDefault; sl@0: // sl@0: INFO_PRINTF1(_L("Empty descriptor")); sl@0: originalUnicode=_L16(""); sl@0: test(characterSetConverter->ConvertFromUnicode(generatedGb2312, originalUnicode)==0); sl@0: test(generatedGb2312==_L8("")); sl@0: test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedGb2312, state)==0); sl@0: test(state==CCnvCharacterSetConverter::KStateDefault); sl@0: test(generatedUnicode==originalUnicode); sl@0: INFO_PRINTF1(_L("A couple of sample characters")); sl@0: originalGb2312=_L8("\xb9\xa4\xc8\xcb"); sl@0: test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==0); sl@0: test(state==CCnvCharacterSetConverter::KStateDefault); sl@0: test(generatedUnicode.Length()==2); sl@0: test(generatedUnicode[0]==0x5de5); sl@0: test(generatedUnicode[1]==0x4eba); sl@0: test(characterSetConverter->ConvertFromUnicode(generatedGb2312, generatedUnicode)==0); sl@0: test(generatedGb2312==originalGb2312); sl@0: INFO_PRINTF1(_L("Converting trunctated GB 2312-80 which ends half-way through a multi-byte character")); sl@0: originalGb2312=_L8("\xb9\xa4\xc8"); sl@0: test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==1); sl@0: test(state==CCnvCharacterSetConverter::KStateDefault); sl@0: test(generatedUnicode.Length()==1); sl@0: test(generatedUnicode[0]==0x5de5); sl@0: originalGb2312=_L8("\xc8"); sl@0: test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==CCnvCharacterSetConverter::EErrorIllFormedInput); sl@0: INFO_PRINTF1(_L("Testing varying the default endianness")); sl@0: originalGb2312=_L8("\xb4\xf2"); sl@0: characterSetConverter->SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::ELittleEndian); sl@0: test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==0); sl@0: test(state==CCnvCharacterSetConverter::KStateDefault); sl@0: test(generatedUnicode.Length()==1); sl@0: test(generatedUnicode[0]==0x6253); sl@0: test(characterSetConverter->ConvertFromUnicode(generatedGb2312, generatedUnicode)==0); sl@0: test(generatedGb2312==originalGb2312); sl@0: characterSetConverter->SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian); sl@0: test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==0); sl@0: test(state==CCnvCharacterSetConverter::KStateDefault); sl@0: test(generatedUnicode.Length()==1); sl@0: test(generatedUnicode[0]==0x6253); sl@0: test(characterSetConverter->ConvertFromUnicode(generatedGb2312, generatedUnicode)==0); sl@0: test(generatedGb2312==originalGb2312); sl@0: INFO_PRINTF1(_L("Testing a many-to-one conversion")); sl@0: originalUnicode.SetLength(4); sl@0: originalUnicode[0]=0x30fb; sl@0: originalUnicode[1]=0x00b7; sl@0: originalUnicode[2]=0x2014; sl@0: originalUnicode[3]=0x2015; sl@0: test(characterSetConverter->ConvertFromUnicode(generatedGb2312, originalUnicode)==0); sl@0: test(generatedGb2312==_L8("\xa1\xa4\xa1\xa4\xa1\xaa\xa1\xaa")); sl@0: test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedGb2312, state)==0); sl@0: test(state==CCnvCharacterSetConverter::KStateDefault); sl@0: test(generatedUnicode.Length()==4); sl@0: test(generatedUnicode[0]==0x00b7); sl@0: test(generatedUnicode[1]==0x00b7); sl@0: test(generatedUnicode[2]==0x2015); sl@0: test(generatedUnicode[3]==0x2015); sl@0: INFO_PRINTF1(_L("Testing GB2312 being aliased to GBK")); sl@0: TUint charSetId = characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("GB2312"), fileServerSession); sl@0: test(charSetId==KCharacterSetIdentifierGbk); sl@0: test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("csGB2312"), fileServerSession)==KCharacterSetIdentifierGbk); sl@0: test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("iso-ir-58"), fileServerSession)==KCharacterSetIdentifierGbk); sl@0: test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("chinese"), fileServerSession)==KCharacterSetIdentifierGbk); sl@0: test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("csISO58GB231280"), fileServerSession)==KCharacterSetIdentifierGbk); sl@0: test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(57, fileServerSession)==KCharacterSetIdentifierGbk); sl@0: test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(2025, fileServerSession)==KCharacterSetIdentifierGbk); sl@0: characterSetConverter->PrepareToConvertToOrFromL(charSetId, *arrayOfCharacterSetsAvailable, fileServerSession); sl@0: originalUnicode.SetLength(3); sl@0: originalUnicode[0]=0x9556; // this has a corresponding GB2312 character sl@0: originalUnicode[1]=0x9555; // this has a corresponding GBK character not in GB2312... sl@0: originalUnicode[2]=0x9394; // ... as does this sl@0: test(characterSetConverter->ConvertFromUnicode(generatedGb2312, originalUnicode)==0); sl@0: test(generatedGb2312.Length()==6); sl@0: test(generatedGb2312==_L8("\xef\xda\xe9\x46\xe6\x67")); sl@0: CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession sl@0: } sl@0: sl@0: CT_GB2312::CT_GB2312() sl@0: { sl@0: SetTestStepName(KTestStep_T_GB2312); sl@0: } sl@0: sl@0: TVerdict CT_GB2312::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: __UHEAP_MARK; sl@0: TRAPD(error1, DoE32MainL()); sl@0: __UHEAP_MARKEND; sl@0: sl@0: if(error1 == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: