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