sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2008-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_extendedsms.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
#ifdef __WINS__
|
sl@0
|
26 |
_LIT(KInputUnicodeFilename, "c:\\test\\data\\extendedsms_uni_input.dat");
|
sl@0
|
27 |
_LIT(KInputForeignFilename, "c:\\test\\data\\extendedsms_for_input.dat");
|
sl@0
|
28 |
_LIT(KExpectUnicodeFilename, "c:\\test\\data\\extendedsms_uni_expect.dat");
|
sl@0
|
29 |
_LIT(KExpectForeignFilename, "c:\\test\\data\\extendedsms_for_expect.dat");
|
sl@0
|
30 |
#else
|
sl@0
|
31 |
_LIT(KInputUnicodeFilename, "z:\\test\\data\\extendedsms_uni_input.dat");
|
sl@0
|
32 |
_LIT(KInputForeignFilename, "z:\\test\\data\\extendedsms_for_input.dat");
|
sl@0
|
33 |
_LIT(KExpectUnicodeFilename, "z:\\test\\data\\extendedsms_uni_expect.dat");
|
sl@0
|
34 |
_LIT(KExpectForeignFilename, "z:\\test\\data\\extendedsms_for_expect.dat");
|
sl@0
|
35 |
#endif
|
sl@0
|
36 |
|
sl@0
|
37 |
static CCnvCharacterSetConverter* characterSetConverter;
|
sl@0
|
38 |
static RFs fileServerSession;
|
sl@0
|
39 |
static TBuf8<1254> temp;
|
sl@0
|
40 |
static TBuf16<627> originalUnicode;
|
sl@0
|
41 |
static TBuf8<627> generatedForeign;
|
sl@0
|
42 |
static TBuf16<627> generatedUnicode;
|
sl@0
|
43 |
|
sl@0
|
44 |
#define test(cond) \
|
sl@0
|
45 |
{ \
|
sl@0
|
46 |
TBool __bb = (cond); \
|
sl@0
|
47 |
TEST(__bb); \
|
sl@0
|
48 |
if (!__bb) \
|
sl@0
|
49 |
{ \
|
sl@0
|
50 |
ERR_PRINTF1(_L("ERROR: Test Failed")); \
|
sl@0
|
51 |
User::Leave(1); \
|
sl@0
|
52 |
} \
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
|
sl@0
|
56 |
//read test data from file
|
sl@0
|
57 |
void CT_EXTENDEDSMS::ReadDescL(TDes8& aDes, const TDesC& aFilename, RFs& aFs)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
RFile file;
|
sl@0
|
60 |
TInt err = file.Open(aFs, aFilename, EFileRead);
|
sl@0
|
61 |
test(err == KErrNone);
|
sl@0
|
62 |
CleanupClosePushL(file);
|
sl@0
|
63 |
err = file.Read(aDes);
|
sl@0
|
64 |
test(err == KErrNone);
|
sl@0
|
65 |
CleanupStack::PopAndDestroy(&file);
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
//translate from unicode big endian TDesC8 to TDes16
|
sl@0
|
69 |
void CT_EXTENDEDSMS::Unicode_Big(TDesC8& aSource, TDes16& aTarget)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
TInt length = aSource.Length();
|
sl@0
|
72 |
TInt i = 0;
|
sl@0
|
73 |
for(i=0;i<length-1;i++)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
TInt32 temp = *(aSource.Ptr()+(i))*16*16 + *(aSource.Ptr()+i+1);
|
sl@0
|
76 |
aTarget.Append(temp);
|
sl@0
|
77 |
i++;
|
sl@0
|
78 |
}
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
/**
|
sl@0
|
82 |
@SYMTestCaseID SYSLIB-CHARCONV-UT-4003
|
sl@0
|
83 |
@SYMTestCaseDesc Testcase to test new converter name can be listed
|
sl@0
|
84 |
@SYMTestPriority High
|
sl@0
|
85 |
@SYMTestActions Test for CreateArrayOfCharacterSetsAvailableLC()
|
sl@0
|
86 |
@SYMTestExpectedResults The test passed, if Available character sets are listed in epocwind.out
|
sl@0
|
87 |
@SYMPREQ PREQ2090
|
sl@0
|
88 |
@SYMREQ REQ10364
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
void CT_EXTENDEDSMS::ListAlltheConvertersL()
|
sl@0
|
91 |
{
|
sl@0
|
92 |
CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\
|
sl@0
|
93 |
CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
|
sl@0
|
94 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4003 Available Converters\n "));
|
sl@0
|
95 |
for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
|
sl@0
|
96 |
{
|
sl@0
|
97 |
const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
|
sl@0
|
98 |
TPtrC charactersSetName(charactersSet.Name());
|
sl@0
|
99 |
if (charactersSet.NameIsFileName())
|
sl@0
|
100 |
{
|
sl@0
|
101 |
charactersSetName.Set(TParsePtrC(charactersSetName).Name());
|
sl@0
|
102 |
}
|
sl@0
|
103 |
INFO_PRINTF2(_L(" %S\n"), &charactersSetName);
|
sl@0
|
104 |
}
|
sl@0
|
105 |
CleanupStack::PopAndDestroy(arrayOfCharacterSetsAvailable);
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
/**
|
sl@0
|
109 |
@SYMTestCaseID SYSLIB-CHARCONV-UT-4004
|
sl@0
|
110 |
@SYMTestCaseDesc Testcase to test new converter name can be prepared for converting
|
sl@0
|
111 |
@SYMTestPriority High
|
sl@0
|
112 |
@SYMTestActions Test for PrepareToConvertToOrFromL()
|
sl@0
|
113 |
@SYMTestExpectedResults The test passed, If EAvailable is returned
|
sl@0
|
114 |
@SYMPREQ PREQ2090
|
sl@0
|
115 |
@SYMREQ REQ10364
|
sl@0
|
116 |
*/
|
sl@0
|
117 |
void CT_EXTENDEDSMS::PrepareNewConverterL()
|
sl@0
|
118 |
{
|
sl@0
|
119 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4004 Preparing the new converter "));
|
sl@0
|
120 |
CCnvCharacterSetConverter::TAvailability avaible = characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierExtendedSms7Bit, fileServerSession);
|
sl@0
|
121 |
test( CCnvCharacterSetConverter::EAvailable == avaible );
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
/**
|
sl@0
|
125 |
@SYMTestCaseID SYSLIB-CHARCONV-UT-4005
|
sl@0
|
126 |
@SYMTestCaseDesc Convert Unicode code to foreign character set
|
sl@0
|
127 |
@SYMTestPriority High
|
sl@0
|
128 |
@SYMTestActions Test for ConvertFromUnicode()
|
sl@0
|
129 |
@SYMTestExpectedResults Test is passed if the generated cod and Expected code is same
|
sl@0
|
130 |
@SYMPREQ PREQ2090
|
sl@0
|
131 |
@SYMREQ REQ10364
|
sl@0
|
132 |
*/
|
sl@0
|
133 |
void CT_EXTENDEDSMS::ConvertFromUnicodeToForeignL()
|
sl@0
|
134 |
{
|
sl@0
|
135 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4005 Encoding from Unicode to Foreign "));
|
sl@0
|
136 |
ReadDescL(temp, KInputUnicodeFilename, fileServerSession);
|
sl@0
|
137 |
Unicode_Big(temp, originalUnicode);
|
sl@0
|
138 |
test(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0);
|
sl@0
|
139 |
ReadDescL(temp, KExpectForeignFilename, fileServerSession);
|
sl@0
|
140 |
test(generatedForeign == temp);
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
/**
|
sl@0
|
144 |
@SYMTestCaseID SYSLIB-CHARCONV-UT-4006
|
sl@0
|
145 |
@SYMTestCaseDesc Convert foreign character set to Unicode code
|
sl@0
|
146 |
@SYMTestPriority High
|
sl@0
|
147 |
@SYMTestActions Test for ConvertToUnicode() with legal foreign characters, 0x00 - 0x7F
|
sl@0
|
148 |
@SYMTestExpectedResults Test is passed if contents of generatedUnicode buffer with OriginalUnicode buffer are same.
|
sl@0
|
149 |
@SYMPREQ PREQ2090
|
sl@0
|
150 |
@SYMREQ REQ10364
|
sl@0
|
151 |
*/
|
sl@0
|
152 |
void CT_EXTENDEDSMS::ConvertFromForeignToUnicodeL()
|
sl@0
|
153 |
{
|
sl@0
|
154 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4006 Encoding from Foreign to Unicode "));
|
sl@0
|
155 |
ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession);
|
sl@0
|
156 |
TInt state=CCnvCharacterSetConverter::KStateDefault;
|
sl@0
|
157 |
test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
|
sl@0
|
158 |
ReadDescL(temp, KExpectUnicodeFilename, fileServerSession);
|
sl@0
|
159 |
originalUnicode.Zero();
|
sl@0
|
160 |
Unicode_Big(temp, originalUnicode);
|
sl@0
|
161 |
test(generatedUnicode == originalUnicode);
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
/**
|
sl@0
|
165 |
@SYMTestCaseID SYSLIB-CHARCONV-UT-4007
|
sl@0
|
166 |
@SYMTestCaseDesc Convert out of range characters from foreign character set to Unicode
|
sl@0
|
167 |
@SYMTestPriority High
|
sl@0
|
168 |
@SYMTestActions Test for ConvertToUnicode() for some out of range foreign characters 0x80 - 0xFF
|
sl@0
|
169 |
@SYMTestExpectedResults The test is passed if generated code is same as expected code
|
sl@0
|
170 |
@SYMPREQ PREQ2090
|
sl@0
|
171 |
@SYMREQ REQ10364
|
sl@0
|
172 |
*/
|
sl@0
|
173 |
void CT_EXTENDEDSMS::ConvertOutOfRangeForeignCharacters()
|
sl@0
|
174 |
{
|
sl@0
|
175 |
//test foreign chararcter point which is not in the scope, e.g. 0x80 in GSM03.38, which should always mapped to 0xFFFD
|
sl@0
|
176 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4007 Testing Characters not in the Scope "));
|
sl@0
|
177 |
generatedForeign.SetLength(1);
|
sl@0
|
178 |
generatedForeign[0] = 0x81;
|
sl@0
|
179 |
TInt state=CCnvCharacterSetConverter::KStateDefault;
|
sl@0
|
180 |
_LIT16(KExpected2, "\xfffd"); //the expected foreign
|
sl@0
|
181 |
test( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
|
sl@0
|
182 |
test( generatedUnicode == KExpected2 );
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
/**
|
sl@0
|
186 |
@SYMTestCaseID SYSLIB-CHARCONV-UT-4008
|
sl@0
|
187 |
@SYMTestCaseDesc Convert illegal character from foreign character set to unicode
|
sl@0
|
188 |
@SYMTestPriority High
|
sl@0
|
189 |
@SYMTestActions Test for ConvertToUnicode() with illegal foreign characters 0x1B
|
sl@0
|
190 |
@SYMTestExpectedResults Test is passed if KErrCorrupt is returned
|
sl@0
|
191 |
@SYMPREQ PREQ2090
|
sl@0
|
192 |
@SYMREQ REQ10364
|
sl@0
|
193 |
*/
|
sl@0
|
194 |
void CT_EXTENDEDSMS::ConvertIllegalForeignCharacter()
|
sl@0
|
195 |
{
|
sl@0
|
196 |
//test 0x1b
|
sl@0
|
197 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4008 Testing EErrorIllFormedInput "));
|
sl@0
|
198 |
generatedForeign.SetLength(1);
|
sl@0
|
199 |
generatedForeign[0] = 0x1b; //the escape character
|
sl@0
|
200 |
TInt state=CCnvCharacterSetConverter::KStateDefault;
|
sl@0
|
201 |
test( KErrCorrupt == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state));
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
void CT_EXTENDEDSMS::DoE32MainL()
|
sl@0
|
205 |
{
|
sl@0
|
206 |
CleanupClosePushL(fileServerSession);
|
sl@0
|
207 |
User::LeaveIfError(fileServerSession.Connect());
|
sl@0
|
208 |
characterSetConverter=CCnvCharacterSetConverter::NewLC();
|
sl@0
|
209 |
|
sl@0
|
210 |
ListAlltheConvertersL();
|
sl@0
|
211 |
PrepareNewConverterL();
|
sl@0
|
212 |
ConvertFromUnicodeToForeignL();
|
sl@0
|
213 |
ConvertFromForeignToUnicodeL();
|
sl@0
|
214 |
ConvertOutOfRangeForeignCharacters();
|
sl@0
|
215 |
ConvertIllegalForeignCharacter();
|
sl@0
|
216 |
|
sl@0
|
217 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
218 |
}
|
sl@0
|
219 |
|
sl@0
|
220 |
CT_EXTENDEDSMS::CT_EXTENDEDSMS()
|
sl@0
|
221 |
{
|
sl@0
|
222 |
SetTestStepName(KTestStep_T_EXTENDEDSMS);
|
sl@0
|
223 |
}
|
sl@0
|
224 |
|
sl@0
|
225 |
TVerdict CT_EXTENDEDSMS::doTestStepL()
|
sl@0
|
226 |
{
|
sl@0
|
227 |
SetTestStepResult(EFail);
|
sl@0
|
228 |
|
sl@0
|
229 |
__UHEAP_MARK;
|
sl@0
|
230 |
TRAPD(error1, DoE32MainL());
|
sl@0
|
231 |
__UHEAP_MARKEND;
|
sl@0
|
232 |
|
sl@0
|
233 |
if(error1 == KErrNone)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
SetTestStepResult(EPass);
|
sl@0
|
236 |
}
|
sl@0
|
237 |
|
sl@0
|
238 |
return TestStepResult();
|
sl@0
|
239 |
}
|