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 // Local Functions |
|
26 /////////////////////////////////////////////////////////////////////////////////////// |
|
27 /* |
|
28 Below four plugins all use cp949table.dll, and first three are same converter. |
|
29 cp949 (code page 949) 0x200100FF |
|
30 ksc5601 (Korean) 0x200113CD |
|
31 EUCKR (EUC-KR) 0x2000E526 |
|
32 iso2022kr (Korean) 0x20010101 |
|
33 */ |
|
34 RTest TheTest(_L("TestCP949")); |
|
35 |
|
36 |
|
37 /////////////////////////////////////////////////////////////////////////////////////// |
|
38 /////////////////////////////////////////////////////////////////////////////////////// |
|
39 //Tests macroses and functions. |
|
40 //If (!aValue) then the test will be panicked, the test data files will be deleted. |
|
41 static void Check(TInt aValue, TInt aLine) |
|
42 { |
|
43 if(!aValue) |
|
44 { |
|
45 TheTest(EFalse, aLine); |
|
46 } |
|
47 } |
|
48 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted. |
|
49 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
50 { |
|
51 if(aValue != aExpected) |
|
52 { |
|
53 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
54 TheTest(EFalse, aLine); |
|
55 } |
|
56 } |
|
57 //Use these to test conditions. |
|
58 #define TEST(arg) ::Check((arg), __LINE__) |
|
59 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
60 |
|
61 const TInt KBufferLength=100; |
|
62 |
|
63 LOCAL_C void TestConversionToUnicodeFromCP949(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aExpectedUnicode, const TDesC8& aOriginalCP949, TInt aExpectedResult = 0) |
|
64 { |
|
65 TInt state=CCnvCharacterSetConverter::KStateDefault; |
|
66 TBuf16<KBufferLength> generatedUnicode; |
|
67 const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, aOriginalCP949, state); |
|
68 TEST(returnValue == aExpectedResult ); |
|
69 TEST(generatedUnicode==aExpectedUnicode); |
|
70 } |
|
71 |
|
72 LOCAL_C void TestConversionFromUnicodeToCP949(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aOriginalUnicode, const TDesC8& aExpectedCP949, TInt aExpectedResult = 0) |
|
73 { |
|
74 TBuf8<KBufferLength> generatedCP949; |
|
75 const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedCP949, aOriginalUnicode); |
|
76 TEST(returnValue == aExpectedResult); |
|
77 TEST(generatedCP949==aExpectedCP949); |
|
78 } |
|
79 |
|
80 LOCAL_C void TestConversion( CCnvCharacterSetConverter& aCharacterSetConverter ) |
|
81 { |
|
82 TestConversionFromUnicodeToCP949(aCharacterSetConverter, _L16("\x0079"), _L8("\x79")); |
|
83 TestConversionToUnicodeFromCP949(aCharacterSetConverter, _L16("\x0079"), _L8("\x79")); |
|
84 |
|
85 TestConversionFromUnicodeToCP949(aCharacterSetConverter, _L16("\xAC02"), _L8("\x81\x41")); |
|
86 TestConversionToUnicodeFromCP949(aCharacterSetConverter, _L16("\xAC02"), _L8("\x81\x41")); |
|
87 } |
|
88 |
|
89 LOCAL_C void TestConversionIso2022kr( CCnvCharacterSetConverter& aCharacterSetConverter ) |
|
90 { |
|
91 TestConversionFromUnicodeToCP949(aCharacterSetConverter, _L16("\x0079"), _L8("\x1b\x24\x43\x0f\x79")); |
|
92 TestConversionToUnicodeFromCP949(aCharacterSetConverter, _L16("\x0079"), _L8("\x1b\x24\x43\x0f\x79")); |
|
93 |
|
94 TestConversionFromUnicodeToCP949(aCharacterSetConverter, _L16("\xc7b8"), _L8("\x1b\x24\x43\x0e\x20\x0f\x41")); |
|
95 TestConversionToUnicodeFromCP949(aCharacterSetConverter, _L16("\xc7b8\x0079"), _L8("\x1b\x24\x43\x0f\xa0\x41\x79")); |
|
96 |
|
97 TestConversionFromUnicodeToCP949(aCharacterSetConverter, _L16("\xAC02"), _L8("\x1b\x24\x43\x0f\x81\x41")); |
|
98 TestConversionToUnicodeFromCP949(aCharacterSetConverter, _L16("\xAC02"), _L8("\x1b\x24\x43\x0f\x81\x41")); |
|
99 } |
|
100 |
|
101 LOCAL_C void DoE32MainL() |
|
102 { |
|
103 RFs fileServerSession; |
|
104 CleanupClosePushL(fileServerSession); |
|
105 User::LeaveIfError(fileServerSession.Connect()); |
|
106 CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC(); |
|
107 CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=\ |
|
108 CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession); |
|
109 |
|
110 TheTest.Start(_L("Available:\n")); |
|
111 for (TInt i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i) |
|
112 { |
|
113 const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i]; |
|
114 characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession); |
|
115 TPtrC charactersSetName(charactersSet.Name()); |
|
116 if (charactersSet.NameIsFileName()) |
|
117 { |
|
118 charactersSetName.Set(TParsePtrC(charactersSetName).Name()); |
|
119 } |
|
120 TheTest.Printf(_L(" %S\n"), &charactersSetName); |
|
121 } |
|
122 |
|
123 TheTest.Next(_L("Testing CP949")); |
|
124 characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierCP949, *arrayOfCharacterSetsAvailable, fileServerSession); |
|
125 TestConversion( *characterSetConverter ); |
|
126 |
|
127 TheTest.Next(_L("Testing ksc5601")); |
|
128 characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierKsc5601, *arrayOfCharacterSetsAvailable, fileServerSession); |
|
129 TestConversion( *characterSetConverter ); |
|
130 |
|
131 TheTest.Next(_L("Testing EUCKR")); |
|
132 characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierEUCKR, *arrayOfCharacterSetsAvailable, fileServerSession); |
|
133 TestConversion( *characterSetConverter ); |
|
134 |
|
135 TheTest.Next(_L("Testing Iso2022kr")); |
|
136 characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierIso2022kr, *arrayOfCharacterSetsAvailable, fileServerSession); |
|
137 TestConversionIso2022kr( *characterSetConverter ); |
|
138 |
|
139 CleanupStack::PopAndDestroy(3); |
|
140 } |
|
141 |
|
142 // Global Functions |
|
143 |
|
144 GLDEF_C TInt E32Main() |
|
145 { |
|
146 __UHEAP_MARK; |
|
147 |
|
148 TheTest.Title(); |
|
149 |
|
150 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
151 TEST(trapCleanup != NULL); |
|
152 |
|
153 TRAPD(error, DoE32MainL()); |
|
154 TEST2(error, KErrNone); |
|
155 |
|
156 delete trapCleanup; |
|
157 |
|
158 TheTest.End(); |
|
159 TheTest.Close(); |
|
160 |
|
161 __UHEAP_MARKEND; |
|
162 return KErrNone; |
|
163 } |
|