32
|
1 |
/*
|
|
2 |
* Copyright (c) 2000-2005 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "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".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
#include <e32std.h>
|
|
26 |
#include <e32base.h>
|
|
27 |
#include <e32test.h>
|
|
28 |
#include <f32file.h>
|
|
29 |
#include <charconv.h>
|
|
30 |
|
|
31 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
32 |
|
|
33 |
RTest TheTest(_L("TReplacement"));
|
|
34 |
|
|
35 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
36 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
37 |
//Tests macroses and functions.
|
|
38 |
//If (!aValue) then the test will be panicked, the test data files will be deleted.
|
|
39 |
static void Check(TInt aValue, TInt aLine)
|
|
40 |
{
|
|
41 |
if(!aValue)
|
|
42 |
{
|
|
43 |
TheTest(EFalse, aLine);
|
|
44 |
}
|
|
45 |
}
|
|
46 |
//If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
|
|
47 |
static void Check(TInt aValue, TInt aExpected, TInt aLine)
|
|
48 |
{
|
|
49 |
if(aValue != aExpected)
|
|
50 |
{
|
|
51 |
RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
|
52 |
TheTest(EFalse, aLine);
|
|
53 |
}
|
|
54 |
}
|
|
55 |
//Use these to test conditions.
|
|
56 |
#define TEST(arg) ::Check((arg), __LINE__)
|
|
57 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
|
58 |
|
|
59 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
60 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
61 |
/**
|
|
62 |
@SYMTestCaseID SYSLIB-CHARCONV-CT-0546
|
|
63 |
@SYMTestCaseDesc Tests for the conversion of uncovertible Unicode characters
|
|
64 |
@SYMTestPriority Medium
|
|
65 |
@SYMTestActions Tests for the replacement of uncovertible Unicode characters
|
|
66 |
@SYMTestExpectedResults Test must not fail
|
|
67 |
@SYMREQ REQ0000
|
|
68 |
*/
|
|
69 |
LOCAL_C void DoE32MainL()
|
|
70 |
{
|
|
71 |
RFs fileServerSession;
|
|
72 |
CleanupClosePushL(fileServerSession);
|
|
73 |
User::LeaveIfError(fileServerSession.Connect());
|
|
74 |
CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
|
|
75 |
CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
|
|
76 |
TheTest.Printf(_L("Available:\n"));
|
|
77 |
for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
|
|
78 |
{
|
|
79 |
const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
|
|
80 |
characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
|
|
81 |
TPtrC charactersSetName(charactersSet.Name());
|
|
82 |
if (charactersSet.NameIsFileName())
|
|
83 |
{
|
|
84 |
charactersSetName.Set(TParsePtrC(charactersSetName).Name());
|
|
85 |
}
|
|
86 |
TheTest.Printf(_L(" %S\n"), &charactersSetName);
|
|
87 |
}
|
|
88 |
characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGb2312, *arrayOfCharacterSetsAvailable, fileServerSession);
|
|
89 |
TheTest.Start(_L("Testing various values for iReplacementForUnconvertibleUnicodeCharacters"));
|
|
90 |
//
|
|
91 |
TheTest.Next(_L("Testing iReplacementForUnconvertibleUnicodeCharacters being long"));
|
|
92 |
{
|
|
93 |
TBuf16<50> originalUnicode;
|
|
94 |
originalUnicode.Format(_L16("Here is a Georgian character - %c"), 0x10da);
|
|
95 |
characterSetConverter->SetReplacementForUnconvertibleUnicodeCharactersL(_L8("[something quite long]"));
|
|
96 |
const TInt KLengthOfForeignBuffer=100;
|
|
97 |
TUint8 foreignBuffer[KLengthOfForeignBuffer];
|
|
98 |
for (TInt i=31; ; ++i)
|
|
99 |
{
|
|
100 |
TEST(i<=KLengthOfForeignBuffer);
|
|
101 |
TPtr8 generatedForeign(foreignBuffer, i);
|
|
102 |
TInt numberOfUnconvertibleCharacters;
|
|
103 |
TInt indexOfFirstUnconvertibleCharacter;
|
|
104 |
const TInt returnValue=characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode, numberOfUnconvertibleCharacters, indexOfFirstUnconvertibleCharacter);
|
|
105 |
if (i==53)
|
|
106 |
{
|
|
107 |
TEST(returnValue==0);
|
|
108 |
TEST(generatedForeign==_L8("Here is a Georgian character - [something quite long]"));
|
|
109 |
TEST(numberOfUnconvertibleCharacters==1);
|
|
110 |
TEST(indexOfFirstUnconvertibleCharacter==31);
|
|
111 |
break;
|
|
112 |
}
|
|
113 |
TEST(returnValue==1);
|
|
114 |
TEST(generatedForeign==_L8("Here is a Georgian character - "));
|
|
115 |
TEST(numberOfUnconvertibleCharacters==0);
|
|
116 |
TEST(indexOfFirstUnconvertibleCharacter==-1); // not something that the API guarantees (it's undefined if numberOfUnconvertibleCharacters==0), but we'll check it any
|
|
117 |
}
|
|
118 |
}
|
|
119 |
TheTest.Next(_L("Testing lots of unconvertible Unicode characters"));
|
|
120 |
{
|
|
121 |
characterSetConverter->SetReplacementForUnconvertibleUnicodeCharactersL(_L8("?Q"));
|
|
122 |
TInt numberOfUnconvertibleCharacters;
|
|
123 |
TInt indexOfFirstUnconvertibleCharacter;
|
|
124 |
TInt i;
|
|
125 |
TPtr16 originalUnicode(HBufC16::NewMaxLC(10+(sizeof(CCnvCharacterSetConverter::TArrayOfAscendingIndices)/sizeof(TUint16)))->Des());
|
|
126 |
TPtr8 generatedForeign(HBufC8::NewLC(originalUnicode.Length()*sizeof(TUint16))->Des());
|
|
127 |
originalUnicode.Fill(0x7535);
|
|
128 |
TEST(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode, numberOfUnconvertibleCharacters, indexOfFirstUnconvertibleCharacter)==0);
|
|
129 |
TEST(generatedForeign.Length()>0);
|
|
130 |
TEST(generatedForeign.Length()==originalUnicode.Length()*STATIC_CAST(TInt, sizeof(TUint16)));
|
|
131 |
TEST(numberOfUnconvertibleCharacters==0);
|
|
132 |
for (i=generatedForeign.Length()-1; i>=0; i-=2)
|
|
133 |
{
|
|
134 |
TEST(generatedForeign[i-1]==0xb5);
|
|
135 |
TEST(generatedForeign[i]==0xe7);
|
|
136 |
}
|
|
137 |
originalUnicode.Fill(0x0f0a); // a Tibetan character, not in GB 2312-80
|
|
138 |
const TInt returnValue=characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode, numberOfUnconvertibleCharacters, indexOfFirstUnconvertibleCharacter);
|
|
139 |
TEST(returnValue>0);
|
|
140 |
TEST(generatedForeign.Length()>0);
|
|
141 |
TEST(generatedForeign.Length()==(originalUnicode.Length()-returnValue)*STATIC_CAST(TInt, sizeof(TUint16)));
|
|
142 |
TEST(numberOfUnconvertibleCharacters==generatedForeign.Length()/2);
|
|
143 |
TEST(indexOfFirstUnconvertibleCharacter==0);
|
|
144 |
for (i=generatedForeign.Length()-1; i>=0; i-=2)
|
|
145 |
{
|
|
146 |
TEST(generatedForeign[i-1]=='?');
|
|
147 |
TEST(generatedForeign[i]=='Q');
|
|
148 |
}
|
|
149 |
CleanupStack::PopAndDestroy(2); // generatedForeign and originalUnicode
|
|
150 |
}
|
|
151 |
CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
|
|
152 |
}
|
|
153 |
|
|
154 |
GLDEF_C TInt E32Main()
|
|
155 |
{
|
|
156 |
__UHEAP_MARK;
|
|
157 |
|
|
158 |
TheTest.Title();
|
|
159 |
|
|
160 |
CTrapCleanup* trapCleanup=CTrapCleanup::New();
|
|
161 |
TEST(trapCleanup != NULL);
|
|
162 |
|
|
163 |
TRAPD(error, DoE32MainL());
|
|
164 |
TEST2(error, KErrNone);
|
|
165 |
|
|
166 |
delete trapCleanup;
|
|
167 |
|
|
168 |
TheTest.End();
|
|
169 |
TheTest.Close();
|
|
170 |
|
|
171 |
__UHEAP_MARKEND;
|
|
172 |
return KErrNone;
|
|
173 |
}
|
|
174 |
|