1 /* |
|
2 * Copyright (c) 2008-2009 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 "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 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 #include <e32test.h> |
|
22 #include <f32file.h> |
|
23 #include <charconv.h> |
|
24 |
|
25 const TUint KCharacterSetIdentifier=KCharacterSetIdentifierTurkishLockingSms7Bit; |
|
26 |
|
27 #ifdef __WINS__ |
|
28 _LIT(KInputUnicodeFilename, "c:\\test\\data\\turkish_locking_gsm7ext_uni_input.dat"); |
|
29 _LIT(KInputForeignFilename, "c:\\test\\data\\turkish_locking_gsm7ext_for_input.dat"); |
|
30 _LIT(KExpectUnicodeFilename, "c:\\test\\data\\turkish_locking_gsm7ext_uni_expect.dat"); |
|
31 _LIT(KExpectForeignFilename, "c:\\test\\data\\turkish_locking_gsm7ext_for_expect.dat"); |
|
32 #else |
|
33 _LIT(KInputUnicodeFilename, "z:\\test\\data\\turkish_locking_gsm7ext_uni_input.dat"); |
|
34 _LIT(KInputForeignFilename, "z:\\test\\data\\turkish_locking_gsm7ext_for_input.dat"); |
|
35 _LIT(KExpectUnicodeFilename, "z:\\test\\data\\turkish_locking_gsm7ext_uni_expect.dat"); |
|
36 _LIT(KExpectForeignFilename, "z:\\test\\data\\turkish_locking_gsm7ext_for_expect.dat"); |
|
37 #endif |
|
38 |
|
39 /////////////////////////////////////////////////////////////////////////////////////// |
|
40 RTest TheTest(_L("TTurkishLocking")); |
|
41 CCnvCharacterSetConverter* characterSetConverter; |
|
42 RFs fileServerSession; |
|
43 TBuf8<970> temp; |
|
44 TBuf16<485> originalUnicode; |
|
45 TBuf8<485> generatedForeign; |
|
46 TBuf16<485> generatedUnicode; |
|
47 |
|
48 /////////////////////////////////////////////////////////////////////////////////////// |
|
49 /////////////////////////////////////////////////////////////////////////////////////// |
|
50 //Tests macroses and functions. |
|
51 //If (!aValue) then the test will be panicked, the test data files will be deleted. |
|
52 static void Check(TInt aValue, TInt aLine) |
|
53 { |
|
54 if(!aValue) |
|
55 { |
|
56 TheTest(EFalse, aLine); |
|
57 } |
|
58 } |
|
59 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted. |
|
60 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
61 { |
|
62 if(aValue != aExpected) |
|
63 { |
|
64 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
65 TheTest(EFalse, aLine); |
|
66 } |
|
67 } |
|
68 //Use these to test conditions. |
|
69 #define TEST(arg) ::Check((arg), __LINE__) |
|
70 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
71 |
|
72 |
|
73 static void ReadDescL(TDes8& aDes, const TDesC& aFilename, RFs& aFs) |
|
74 { |
|
75 RFile file; |
|
76 TInt err = file.Open(aFs, aFilename, EFileRead); |
|
77 TEST2(err, KErrNone); |
|
78 CleanupClosePushL(file); |
|
79 err = file.Read(aDes); |
|
80 TEST2(err, KErrNone); |
|
81 CleanupStack::PopAndDestroy(&file); |
|
82 } |
|
83 |
|
84 //translate from unicode big endian TDesC8 to TDes16 |
|
85 static void Unicode_Big(TDesC8& aSource, TDes16& aTarget) |
|
86 { |
|
87 TInt length = aSource.Length(); |
|
88 TInt i = 0; |
|
89 for(i=0;i<length-1;i++) |
|
90 { |
|
91 TInt32 temp = *(aSource.Ptr()+(i))*16*16 + *(aSource.Ptr()+i+1); |
|
92 aTarget.Append(temp); |
|
93 i++; |
|
94 } |
|
95 } |
|
96 |
|
97 /** |
|
98 @SYMTestCaseID SYSLIB-CHARCONV-UT-4015 |
|
99 @SYMTestCaseDesc Testcase to test new converter name can be listed |
|
100 @SYMTestPriority High |
|
101 @SYMTestActions Test for CreateArrayOfCharacterSetsAvailableLC() |
|
102 @SYMTestExpectedResults The test passed, if Available character sets are listed in epocwind.out |
|
103 @SYMPREQ PREQ22265 |
|
104 @SYMREQ REQ10670 |
|
105 */ |
|
106 void ListAlltheConvertersL() |
|
107 { |
|
108 CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\ |
|
109 CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession); |
|
110 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4015 Available:\n ")); |
|
111 for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i) |
|
112 { |
|
113 const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i]; |
|
114 TPtrC charactersSetName(charactersSet.Name()); |
|
115 if (charactersSet.NameIsFileName()) |
|
116 { |
|
117 charactersSetName.Set(TParsePtrC(charactersSetName).Name()); |
|
118 } |
|
119 TheTest.Printf(_L(" %S\n"), &charactersSetName); |
|
120 } |
|
121 CleanupStack::PopAndDestroy(arrayOfCharacterSetsAvailable); |
|
122 } |
|
123 |
|
124 /** |
|
125 @SYMTestCaseID SYSLIB-CHARCONV-UT-4016 |
|
126 @SYMTestCaseDesc Testcase to test new converter can be prepared |
|
127 @SYMTestPriority High |
|
128 @SYMTestActions Test for PrepareToConvertToOrFromL() |
|
129 @SYMTestExpectedResults The test passed, If EAvailable is returned |
|
130 @SYMPREQ PREQ22265 |
|
131 @SYMREQ REQ10670 |
|
132 */ |
|
133 void PrepareNewConverterL() |
|
134 { |
|
135 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4016 Testing new converter can be prepared ")); |
|
136 CCnvCharacterSetConverter::TAvailability avaible = characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifier, fileServerSession); |
|
137 TEST( CCnvCharacterSetConverter::EAvailable == avaible ); |
|
138 } |
|
139 |
|
140 /** |
|
141 @SYMTestCaseID SYSLIB-CHARCONV-UT-4017 |
|
142 @SYMTestCaseDesc Convert Unicode code to foreign character set |
|
143 @SYMTestPriority High |
|
144 @SYMTestActions Test for ConvertFromUnicode() |
|
145 @SYMTestExpectedResults Test must not fail |
|
146 @SYMPREQ PREQ22265 |
|
147 @SYMREQ REQ10670 |
|
148 */ |
|
149 LOCAL_C void ConvertFromUnicodeToForeignL() |
|
150 { |
|
151 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4017 Testing encoding from Unicode to Foreign ")); |
|
152 ReadDescL(temp, KInputUnicodeFilename, fileServerSession); |
|
153 Unicode_Big(temp, originalUnicode); |
|
154 TEST(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0); |
|
155 ReadDescL(temp, KExpectForeignFilename, fileServerSession); |
|
156 TEST(generatedForeign == temp); |
|
157 } |
|
158 |
|
159 /** |
|
160 @SYMTestCaseID SYSLIB-CHARCONV-UT-4018 |
|
161 @SYMTestCaseDesc Convert foreign character set to Unicode code |
|
162 @SYMTestPriority High |
|
163 @SYMTestActions Test for ConvertToUnicode() with legal foreign characters, 0x00 - 0x7F |
|
164 @SYMTestExpectedResults Test must not fail |
|
165 @SYMPREQ PREQ22265 |
|
166 @SYMREQ REQ10670 |
|
167 */ |
|
168 LOCAL_C void ConvertFromForeignToUnicodeL() |
|
169 { |
|
170 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4018 Testing encoding from Foreign to Unicode ")); |
|
171 ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession); |
|
172 TInt state=CCnvCharacterSetConverter::KStateDefault; |
|
173 TEST( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state)); |
|
174 ReadDescL(temp, KExpectUnicodeFilename, fileServerSession); |
|
175 originalUnicode.Zero(); |
|
176 Unicode_Big(temp, originalUnicode); |
|
177 TEST(generatedUnicode == originalUnicode); |
|
178 } |
|
179 |
|
180 /** |
|
181 @SYMTestCaseID SYSLIB-CHARCONV-UT-4019 |
|
182 @SYMTestCaseDesc Convert illegal character from foreign character set to unicode |
|
183 @SYMTestPriority High |
|
184 @SYMTestActions Test for ConvertToUnicode() with illegal foreign characters 0x1B |
|
185 @SYMTestExpectedResults Test must not fail |
|
186 @SYMPREQ PREQ22265 |
|
187 @SYMREQ REQ10670 |
|
188 */ |
|
189 LOCAL_C void ConvertIllegalForeignCharacter() |
|
190 { |
|
191 //test 0x1b |
|
192 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4019 Testing EErrorIllFormedInput ")); |
|
193 generatedForeign.SetLength(1); |
|
194 generatedForeign[0] = 0x1b; //the escape character |
|
195 TInt state=CCnvCharacterSetConverter::KStateDefault; |
|
196 TEST( -20 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state)); |
|
197 } |
|
198 |
|
199 /** |
|
200 @SYMTestCaseID SYSLIB-CHARCONV-UT-4020 |
|
201 @SYMTestCaseDesc Convert out of range characters from foreign character set to Unicode |
|
202 @SYMTestPriority High |
|
203 @SYMTestActions Test for ConvertToUnicode() for some out of range foreign characters 0x80 - 0xFF |
|
204 @SYMTestExpectedResults Test must not fail |
|
205 @SYMPREQ PREQ22265 |
|
206 @SYMREQ REQ10670 |
|
207 */ |
|
208 LOCAL_C void ConvertOutOfRangeForeignCharacters() |
|
209 { |
|
210 //test foreign chararcter point which is not in the scope, e.g. 0x80 in GSM03.38, which should always mapped to 0xFFFD |
|
211 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-UT-4020 Testing Characters not in the Scope ")); |
|
212 generatedForeign.SetLength(1); |
|
213 generatedForeign[0] = 0x80; |
|
214 TInt state=CCnvCharacterSetConverter::KStateDefault; |
|
215 _LIT16(KExpected2, "\xfffd"); //the expected foreign |
|
216 TEST( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state)); |
|
217 TEST( generatedUnicode == KExpected2 ); |
|
218 } |
|
219 |
|
220 LOCAL_C void DoE32MainL() |
|
221 { |
|
222 CleanupClosePushL(fileServerSession); |
|
223 User::LeaveIfError(fileServerSession.Connect()); |
|
224 characterSetConverter=CCnvCharacterSetConverter::NewLC(); |
|
225 |
|
226 ListAlltheConvertersL(); |
|
227 PrepareNewConverterL(); |
|
228 ConvertFromUnicodeToForeignL(); |
|
229 ConvertFromForeignToUnicodeL(); |
|
230 ConvertIllegalForeignCharacter(); |
|
231 ConvertOutOfRangeForeignCharacters(); |
|
232 |
|
233 CleanupStack::PopAndDestroy(2); |
|
234 } |
|
235 |
|
236 // Global Functions |
|
237 |
|
238 GLDEF_C TInt E32Main() |
|
239 { |
|
240 __UHEAP_MARK; |
|
241 |
|
242 TheTest.Title(); |
|
243 |
|
244 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
245 TEST(trapCleanup != NULL); |
|
246 |
|
247 TRAPD(error, DoE32MainL()); |
|
248 TEST2(error, KErrNone); |
|
249 |
|
250 delete trapCleanup; |
|
251 |
|
252 TheTest.End(); |
|
253 TheTest.Close(); |
|
254 |
|
255 __UHEAP_MARKEND; |
|
256 return KErrNone; |
|
257 } |
|