First public contribution.
2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
27 TBool __bb = (cond); \
31 ERR_PRINTF1(_L("ERROR: Test Failed")); \
38 @SYMTestCaseID SYSLIB-CHARCONV-CT-0502
39 @SYMTestCaseDesc Tests for converting GB 2312-80 character set to Unicode
40 @SYMTestPriority Medium
41 @SYMTestActions Tests for simple GB 2312-80 round trips,
42 Tests for varying the default Endianness
43 @SYMTestExpectedResults Test must not fail
46 void CT_GB2312::DoE32MainL()
48 RFs fileServerSession;
49 CleanupClosePushL(fileServerSession);
50 User::LeaveIfError(fileServerSession.Connect());
51 CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
52 CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
53 INFO_PRINTF1(_L("Available:\n"));
54 for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
56 const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
57 characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
58 TPtrC charactersSetName(charactersSet.Name());
59 if (charactersSet.NameIsFileName())
61 charactersSetName.Set(TParsePtrC(charactersSetName).Name());
63 INFO_PRINTF2(_L(" %S\n"), &charactersSetName);
65 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0502 Testing simple GB 2312-80 round trips "));
66 characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGb2312, *arrayOfCharacterSetsAvailable, fileServerSession);
67 TBuf8<256> originalGb2312;
68 TBuf16<256> originalUnicode;
69 TBuf8<256> generatedGb2312;
70 TBuf16<256> generatedUnicode;
71 TInt state=CCnvCharacterSetConverter::KStateDefault;
73 INFO_PRINTF1(_L("Empty descriptor"));
74 originalUnicode=_L16("");
75 test(characterSetConverter->ConvertFromUnicode(generatedGb2312, originalUnicode)==0);
76 test(generatedGb2312==_L8(""));
77 test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedGb2312, state)==0);
78 test(state==CCnvCharacterSetConverter::KStateDefault);
79 test(generatedUnicode==originalUnicode);
80 INFO_PRINTF1(_L("A couple of sample characters"));
81 originalGb2312=_L8("\xb9\xa4\xc8\xcb");
82 test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==0);
83 test(state==CCnvCharacterSetConverter::KStateDefault);
84 test(generatedUnicode.Length()==2);
85 test(generatedUnicode[0]==0x5de5);
86 test(generatedUnicode[1]==0x4eba);
87 test(characterSetConverter->ConvertFromUnicode(generatedGb2312, generatedUnicode)==0);
88 test(generatedGb2312==originalGb2312);
89 INFO_PRINTF1(_L("Converting trunctated GB 2312-80 which ends half-way through a multi-byte character"));
90 originalGb2312=_L8("\xb9\xa4\xc8");
91 test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==1);
92 test(state==CCnvCharacterSetConverter::KStateDefault);
93 test(generatedUnicode.Length()==1);
94 test(generatedUnicode[0]==0x5de5);
95 originalGb2312=_L8("\xc8");
96 test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==CCnvCharacterSetConverter::EErrorIllFormedInput);
97 INFO_PRINTF1(_L("Testing varying the default endianness"));
98 originalGb2312=_L8("\xb4\xf2");
99 characterSetConverter->SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::ELittleEndian);
100 test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==0);
101 test(state==CCnvCharacterSetConverter::KStateDefault);
102 test(generatedUnicode.Length()==1);
103 test(generatedUnicode[0]==0x6253);
104 test(characterSetConverter->ConvertFromUnicode(generatedGb2312, generatedUnicode)==0);
105 test(generatedGb2312==originalGb2312);
106 characterSetConverter->SetDefaultEndiannessOfForeignCharacters(CCnvCharacterSetConverter::EBigEndian);
107 test(characterSetConverter->ConvertToUnicode(generatedUnicode, originalGb2312, state)==0);
108 test(state==CCnvCharacterSetConverter::KStateDefault);
109 test(generatedUnicode.Length()==1);
110 test(generatedUnicode[0]==0x6253);
111 test(characterSetConverter->ConvertFromUnicode(generatedGb2312, generatedUnicode)==0);
112 test(generatedGb2312==originalGb2312);
113 INFO_PRINTF1(_L("Testing a many-to-one conversion"));
114 originalUnicode.SetLength(4);
115 originalUnicode[0]=0x30fb;
116 originalUnicode[1]=0x00b7;
117 originalUnicode[2]=0x2014;
118 originalUnicode[3]=0x2015;
119 test(characterSetConverter->ConvertFromUnicode(generatedGb2312, originalUnicode)==0);
120 test(generatedGb2312==_L8("\xa1\xa4\xa1\xa4\xa1\xaa\xa1\xaa"));
121 test(characterSetConverter->ConvertToUnicode(generatedUnicode, generatedGb2312, state)==0);
122 test(state==CCnvCharacterSetConverter::KStateDefault);
123 test(generatedUnicode.Length()==4);
124 test(generatedUnicode[0]==0x00b7);
125 test(generatedUnicode[1]==0x00b7);
126 test(generatedUnicode[2]==0x2015);
127 test(generatedUnicode[3]==0x2015);
128 INFO_PRINTF1(_L("Testing GB2312 being aliased to GBK"));
129 TUint charSetId = characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("GB2312"), fileServerSession);
130 test(charSetId==KCharacterSetIdentifierGbk);
131 test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("csGB2312"), fileServerSession)==KCharacterSetIdentifierGbk);
132 test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("iso-ir-58"), fileServerSession)==KCharacterSetIdentifierGbk);
133 test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("chinese"), fileServerSession)==KCharacterSetIdentifierGbk);
134 test(characterSetConverter->ConvertStandardNameOfCharacterSetToIdentifierL(_L8("csISO58GB231280"), fileServerSession)==KCharacterSetIdentifierGbk);
135 test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(57, fileServerSession)==KCharacterSetIdentifierGbk);
136 test(characterSetConverter->ConvertMibEnumOfCharacterSetToIdentifierL(2025, fileServerSession)==KCharacterSetIdentifierGbk);
137 characterSetConverter->PrepareToConvertToOrFromL(charSetId, *arrayOfCharacterSetsAvailable, fileServerSession);
138 originalUnicode.SetLength(3);
139 originalUnicode[0]=0x9556; // this has a corresponding GB2312 character
140 originalUnicode[1]=0x9555; // this has a corresponding GBK character not in GB2312...
141 originalUnicode[2]=0x9394; // ... as does this
142 test(characterSetConverter->ConvertFromUnicode(generatedGb2312, originalUnicode)==0);
143 test(generatedGb2312.Length()==6);
144 test(generatedGb2312==_L8("\xef\xda\xe9\x46\xe6\x67"));
145 CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
148 CT_GB2312::CT_GB2312()
150 SetTestStepName(KTestStep_T_GB2312);
153 TVerdict CT_GB2312::doTestStepL()
155 SetTestStepResult(EFail);
158 TRAPD(error1, DoE32MainL());
161 if(error1 == KErrNone)
163 SetTestStepResult(EPass);
166 return TestStepResult();