1 /* |
|
2 * Copyright (c) 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=KCharacterSetIdentifierWin1250; |
|
26 |
|
27 #ifdef __WINS__ |
|
28 _LIT(KInputUnicodeFilename, "c:\\test\\data\\win1250_uni_input.dat"); |
|
29 _LIT(KInputForeignFilename, "c:\\test\\data\\win1250_for_input.dat"); |
|
30 _LIT(KExpectUnicodeFilename, "c:\\test\\data\\win1250_uni_expect.dat"); |
|
31 _LIT(KExpectForeignFilename, "c:\\test\\data\\win1250_for_expect.dat"); |
|
32 #else |
|
33 _LIT(KInputUnicodeFilename, "z:\\test\\data\\win1250_uni_input.dat"); |
|
34 _LIT(KInputForeignFilename, "z:\\test\\data\\win1250_for_input.dat"); |
|
35 _LIT(KExpectUnicodeFilename, "z:\\test\\data\\win1250_uni_expect.dat"); |
|
36 _LIT(KExpectForeignFilename, "z:\\test\\data\\win1250_for_expect.dat"); |
|
37 #endif |
|
38 |
|
39 // Local Functions |
|
40 /////////////////////////////////////////////////////////////////////////////////////// |
|
41 RTest TheTest(_L("TestWin1250")); |
|
42 |
|
43 /////////////////////////////////////////////////////////////////////////////////////// |
|
44 /////////////////////////////////////////////////////////////////////////////////////// |
|
45 //Tests macroses and functions. |
|
46 //If (!aValue) then the test will be panicked, the test data files will be deleted. |
|
47 static void Check(TInt aValue, TInt aLine) |
|
48 { |
|
49 if(!aValue) |
|
50 { |
|
51 TheTest(EFalse, aLine); |
|
52 } |
|
53 } |
|
54 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted. |
|
55 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
56 { |
|
57 if(aValue != aExpected) |
|
58 { |
|
59 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
60 TheTest(EFalse, aLine); |
|
61 } |
|
62 } |
|
63 //Use these to test conditions. |
|
64 #define TEST(arg) ::Check((arg), __LINE__) |
|
65 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
66 |
|
67 static void ReadDescL(TDes8& aDes, const TDesC& aFilename, RFs& aFs) |
|
68 { |
|
69 RFile file; |
|
70 TInt err = file.Open(aFs, aFilename, EFileRead); |
|
71 TEST2(err, KErrNone); |
|
72 CleanupClosePushL(file); |
|
73 err = file.Read(aDes); |
|
74 TEST2(err, KErrNone); |
|
75 CleanupStack::PopAndDestroy(&file); |
|
76 } |
|
77 |
|
78 static void Merge_Big(TDesC8& aSource, TDes16& aTarget) |
|
79 { |
|
80 TInt length = aSource.Length(); |
|
81 TInt i = 0; |
|
82 for(i=0;i<length-1;i++) |
|
83 { |
|
84 TInt64 temp = *(aSource.Ptr()+(i))*16*16 + *(aSource.Ptr()+i+1); |
|
85 aTarget.Append(temp); |
|
86 i++; |
|
87 } |
|
88 } |
|
89 |
|
90 LOCAL_C void DoE32MainL() |
|
91 { |
|
92 RFs fileServerSession; |
|
93 CleanupClosePushL(fileServerSession); |
|
94 User::LeaveIfError(fileServerSession.Connect()); |
|
95 CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC(); |
|
96 CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\ |
|
97 CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession); |
|
98 |
|
99 TheTest.Start(_L("Available:\n")); |
|
100 for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i) |
|
101 { |
|
102 const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i]; |
|
103 characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession); |
|
104 TPtrC charactersSetName(charactersSet.Name()); |
|
105 if (charactersSet.NameIsFileName()) |
|
106 { |
|
107 charactersSetName.Set(TParsePtrC(charactersSetName).Name()); |
|
108 } |
|
109 TheTest.Printf(_L(" %S\n"), &charactersSetName); |
|
110 } |
|
111 |
|
112 TheTest.Next(_L("Encoding from Unicode to Foreign")); |
|
113 characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifier, *arrayOfCharacterSetsAvailable, fileServerSession); |
|
114 TBuf8<512> temp; |
|
115 TBuf16<256> originalUnicode; |
|
116 TBuf8<256> generatedForeign; |
|
117 TBuf16<256> generatedUnicode; |
|
118 ReadDescL(temp, KInputUnicodeFilename, fileServerSession); |
|
119 Merge_Big(temp, originalUnicode); |
|
120 TEST(characterSetConverter->ConvertFromUnicode(generatedForeign, originalUnicode) == 0); |
|
121 ReadDescL(temp, KExpectForeignFilename, fileServerSession); |
|
122 TEST(generatedForeign == temp); |
|
123 |
|
124 TheTest.Next(_L("Encoding from Foreign to Unicode")); |
|
125 ReadDescL(generatedForeign, KInputForeignFilename, fileServerSession); |
|
126 TInt state=CCnvCharacterSetConverter::KStateDefault; |
|
127 TEST( 0 == characterSetConverter->ConvertToUnicode(generatedUnicode, generatedForeign, state)); |
|
128 ReadDescL(temp, KExpectUnicodeFilename, fileServerSession); |
|
129 originalUnicode.Zero(); |
|
130 Merge_Big(temp, originalUnicode); |
|
131 TEST(generatedUnicode == originalUnicode); |
|
132 |
|
133 CleanupStack::PopAndDestroy(3); |
|
134 } |
|
135 |
|
136 // Global Functions |
|
137 |
|
138 GLDEF_C TInt E32Main() |
|
139 { |
|
140 __UHEAP_MARK; |
|
141 |
|
142 TheTest.Title(); |
|
143 |
|
144 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
145 TEST(trapCleanup != NULL); |
|
146 |
|
147 TRAPD(error, DoE32MainL()); |
|
148 TEST2(error, KErrNone); |
|
149 |
|
150 delete trapCleanup; |
|
151 |
|
152 TheTest.End(); |
|
153 TheTest.Close(); |
|
154 |
|
155 __UHEAP_MARKEND; |
|
156 return KErrNone; |
|
157 } |
|