sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2000-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_replacement.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
#define test(cond) \
|
sl@0
|
27 |
{ \
|
sl@0
|
28 |
TBool __bb = (cond); \
|
sl@0
|
29 |
TEST(__bb); \
|
sl@0
|
30 |
if (!__bb) \
|
sl@0
|
31 |
{ \
|
sl@0
|
32 |
ERR_PRINTF1(_L("ERROR: Test Failed")); \
|
sl@0
|
33 |
User::Leave(1); \
|
sl@0
|
34 |
} \
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
/**
|
sl@0
|
38 |
@SYMTestCaseID SYSLIB-CHARCONV-CT-0546
|
sl@0
|
39 |
@SYMTestCaseDesc Tests for the conversion of uncovertible Unicode characters
|
sl@0
|
40 |
@SYMTestPriority Medium
|
sl@0
|
41 |
@SYMTestActions Tests for the replacement of uncovertible Unicode characters
|
sl@0
|
42 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
43 |
@SYMREQ REQ0000
|
sl@0
|
44 |
*/
|
sl@0
|
45 |
void CT_REPLACEMENT::DoE32MainL()
|
sl@0
|
46 |
{
|
sl@0
|
47 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0546 "));
|
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 |
characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGb2312, *arrayOfCharacterSetsAvailable, fileServerSession);
|
sl@0
|
66 |
INFO_PRINTF1(_L("Testing various values for iReplacementForUnconvertibleUnicodeCharacters"));
|
sl@0
|
67 |
//
|
sl@0
|
68 |
INFO_PRINTF1(_L("Testing iReplacementForUnconvertibleUnicodeCharacters being long"));
|
sl@0
|
69 |
{
|
sl@0
|
70 |
TBuf16<50> originalUnicode;
|
sl@0
|
71 |
originalUnicode.Format(_L16("Here is a Georgian character - %c"), 0x10da);
|
sl@0
|
72 |
characterSetConverter->SetReplacementForUnconvertibleUnicodeCharactersL(_L8("[something quite long]"));
|
sl@0
|
73 |
const TInt KLengthOfForeignBuffer=100;
|
sl@0
|
74 |
TUint8 foreignBuffer[KLengthOfForeignBuffer];
|
sl@0
|
75 |
for (TInt i=31; ; ++i)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
test(i<=KLengthOfForeignBuffer);
|
sl@0
|
78 |
TPtr8 generatedForeign(foreignBuffer, i);
|
sl@0
|
79 |
TInt numberOfUnconvertibleCharacters;
|
sl@0
|
80 |
TInt indexOfFirstUnconvertibleCharacter;
|
sl@0
|
81 |
const TInt returnValue=characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode, numberOfUnconvertibleCharacters, indexOfFirstUnconvertibleCharacter);
|
sl@0
|
82 |
if (i==53)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
test(returnValue==0);
|
sl@0
|
85 |
test(generatedForeign==_L8("Here is a Georgian character - [something quite long]"));
|
sl@0
|
86 |
test(numberOfUnconvertibleCharacters==1);
|
sl@0
|
87 |
test(indexOfFirstUnconvertibleCharacter==31);
|
sl@0
|
88 |
break;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
test(returnValue==1);
|
sl@0
|
91 |
test(generatedForeign==_L8("Here is a Georgian character - "));
|
sl@0
|
92 |
test(numberOfUnconvertibleCharacters==0);
|
sl@0
|
93 |
test(indexOfFirstUnconvertibleCharacter==-1); // not something that the API guarantees (it's undefined if numberOfUnconvertibleCharacters==0), but we'll check it any
|
sl@0
|
94 |
}
|
sl@0
|
95 |
}
|
sl@0
|
96 |
INFO_PRINTF1(_L("Testing lots of unconvertible Unicode characters"));
|
sl@0
|
97 |
{
|
sl@0
|
98 |
characterSetConverter->SetReplacementForUnconvertibleUnicodeCharactersL(_L8("?Q"));
|
sl@0
|
99 |
TInt numberOfUnconvertibleCharacters;
|
sl@0
|
100 |
TInt indexOfFirstUnconvertibleCharacter;
|
sl@0
|
101 |
TInt i;
|
sl@0
|
102 |
TPtr16 originalUnicode(HBufC16::NewMaxLC(10+(sizeof(CCnvCharacterSetConverter::TArrayOfAscendingIndices)/sizeof(TUint16)))->Des());
|
sl@0
|
103 |
TPtr8 generatedForeign(HBufC8::NewLC(originalUnicode.Length()*sizeof(TUint16))->Des());
|
sl@0
|
104 |
originalUnicode.Fill(0x7535);
|
sl@0
|
105 |
test(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode, numberOfUnconvertibleCharacters, indexOfFirstUnconvertibleCharacter)==0);
|
sl@0
|
106 |
test(generatedForeign.Length()>0);
|
sl@0
|
107 |
test(generatedForeign.Length()==originalUnicode.Length()*STATIC_CAST(TInt, sizeof(TUint16)));
|
sl@0
|
108 |
test(numberOfUnconvertibleCharacters==0);
|
sl@0
|
109 |
for (i=generatedForeign.Length()-1; i>=0; i-=2)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
test(generatedForeign[i-1]==0xb5);
|
sl@0
|
112 |
test(generatedForeign[i]==0xe7);
|
sl@0
|
113 |
}
|
sl@0
|
114 |
originalUnicode.Fill(0x0f0a); // a Tibetan character, not in GB 2312-80
|
sl@0
|
115 |
const TInt returnValue=characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode, numberOfUnconvertibleCharacters, indexOfFirstUnconvertibleCharacter);
|
sl@0
|
116 |
test(returnValue==0);
|
sl@0
|
117 |
test(generatedForeign.Length()>0);
|
sl@0
|
118 |
test(generatedForeign.Length()==(originalUnicode.Length()-returnValue)*STATIC_CAST(TInt, sizeof(TUint16)));
|
sl@0
|
119 |
test(numberOfUnconvertibleCharacters==25);
|
sl@0
|
120 |
test(indexOfFirstUnconvertibleCharacter==0);
|
sl@0
|
121 |
for (i=generatedForeign.Length()-1; i>=0; i-=2)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
test(generatedForeign[i-1]=='?');
|
sl@0
|
124 |
test(generatedForeign[i]=='Q');
|
sl@0
|
125 |
}
|
sl@0
|
126 |
CleanupStack::PopAndDestroy(2); // generatedForeign and originalUnicode
|
sl@0
|
127 |
}
|
sl@0
|
128 |
CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
CT_REPLACEMENT::CT_REPLACEMENT()
|
sl@0
|
132 |
{
|
sl@0
|
133 |
SetTestStepName(KTestStep_T_REPLACEMENT);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
TVerdict CT_REPLACEMENT::doTestStepL()
|
sl@0
|
137 |
{
|
sl@0
|
138 |
SetTestStepResult(EFail);
|
sl@0
|
139 |
|
sl@0
|
140 |
__UHEAP_MARK;
|
sl@0
|
141 |
TRAPD(error1, DoE32MainL());
|
sl@0
|
142 |
__UHEAP_MARKEND;
|
sl@0
|
143 |
|
sl@0
|
144 |
if(error1 == KErrNone)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
SetTestStepResult(EPass);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
return TestStepResult();
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|