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