First public contribution.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include "t_simple8.h"
23 ///////////////////////////////////////////////////////////////////////////////////////
29 ERR_PRINTF1(_L("ERROR: Test Failed")); \
33 ///////////////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////////////
37 @SYMTestCaseID SYSLIB-CHARCONV-CT-4002
38 @SYMTestCaseDesc Test conversion of a UTF-8 BOM between Unicode and 8-bit
40 @SYMTestPriority Medium
41 @SYMTestActions Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8(),
42 CnvUtfConverter::ConvertToUnicodeFromUtf8L() function
43 @SYMTestExpectedResults Tests must not fail
47 void CT_SIMPLE8::TestForUtf8BomL()
49 INFO_PRINTF1(_L("@SYMTestCaseID:SYSLIB-CHARCONV-CT-4002 Testing converting to and from UTF-8 BOM."));
51 TBuf8<100> generatedUtf8NoGKBWithBom(_L8("\xef\xbb\xbf\x7F\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64"));
53 //convert to unicode and verify BOM converted properly.
54 INFO_PRINTF1(_L("BOM, valid UTF-8 to Unicode conversion test."));
55 TBuf16<256> generatedUnicode;
56 test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8NoGKBWithBom)==0);
57 test(generatedUnicode==_L16("\xFEFF\x007fHello World"));
59 INFO_PRINTF1(_L("BOM, valid Unicode to UTF-8 conversion test."));
60 TBuf8<256> generatedUtf8;
61 test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, generatedUnicode)==0);
62 test(generatedUtf8==generatedUtf8NoGKBWithBom);
68 @SYMTestCaseID SYSLIB-CHARCONV-CT-0563
69 @SYMTestCaseDesc Conversion tests from Unicode to UTF-8 character set
70 @SYMTestPriority Medium
71 @SYMTestActions Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8(),
72 CnvUtfConverter::ConvertToUnicodeFromUtf8L() function
73 @SYMTestExpectedResults Test must not fail
76 void CT_SIMPLE8::TestSimple8()
78 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0563 Testing simple UTF-8 round trips "));
79 TBuf16<256> originalUnicode;
80 TBuf8<256> generatedUtf8;
81 TBuf16<256> generatedUnicode;
83 INFO_PRINTF1(_L("Empty descriptor"));
84 originalUnicode=_L16("");
85 test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
86 test(generatedUtf8==_L8(""));
87 test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
88 test(generatedUnicode==originalUnicode);
89 // Testing the new API
92 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
93 TPtr8 comparebuffer8 = testbuffer8->Des();
94 test(comparebuffer8==generatedUtf8);
95 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
96 TPtr compareBuffer = testbuffer->Des();
97 test(compareBuffer == originalUnicode);
101 INFO_PRINTF1(_L("English \"Hello!\""));
102 originalUnicode=_L16("Hello!");
103 test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
104 test(generatedUtf8==_L8("Hello!"));
105 test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
106 test(generatedUnicode==originalUnicode);
107 // Testing the new API
108 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
109 comparebuffer8.Set(testbuffer8->Des());
110 test(comparebuffer8==generatedUtf8);
111 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
112 compareBuffer.Set(testbuffer->Des());
113 test(compareBuffer == originalUnicode);
117 INFO_PRINTF1(_L("Russian \"Hello!\""));
118 originalUnicode.Format(_L16("%c%c%c%c%c%c%c%c%c%c%c%c%c"), 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, 0x0439, 0x0442, 0x0435, 0x0021);
119 test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
120 test(generatedUtf8==_L8("\xd0\x97\xd0\xb4\xd1\x80\xd0\xb0\xd0\xb2\xd1\x81\xd1\x82\xd0\xb2\xd1\x83\xd0\xb9\xd1\x82\xd0\xb5\x21"));
121 test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
122 test(generatedUnicode==originalUnicode);
123 // Testing the new API
124 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
125 comparebuffer8.Set(testbuffer8->Des());
126 test(comparebuffer8==generatedUtf8);
127 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
128 compareBuffer.Set(testbuffer->Des());
129 test(compareBuffer == originalUnicode);
133 INFO_PRINTF1(_L("Greek \"Hello!\""));
134 originalUnicode.Format(_L16("%c%c%c%c%c%c"), 0x0393, 0x03b1, 0x03c3, 0x03bf, 0x03c5, 0x0021);
135 test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
136 test(generatedUtf8==_L8("\xce\x93\xce\xb1\xcf\x83\xce\xbf\xcf\x85\x21"));
137 test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
138 test(generatedUnicode==originalUnicode);
139 // Testing the new API
140 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
141 comparebuffer8.Set(testbuffer8->Des());
142 test(comparebuffer8==generatedUtf8);
143 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
144 compareBuffer.Set(testbuffer->Des());
145 test(compareBuffer == originalUnicode);
149 INFO_PRINTF1(_L("Chinese \"Hello!\""));
150 originalUnicode.Format(_L16("%c%c%c"), 0x4f60, 0x597d, 0x0021);
151 test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
152 test(generatedUtf8==_L8("\xe4\xbd\xa0\xe5\xa5\xbd\x21"));
153 test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
154 test(generatedUnicode==originalUnicode);
155 // Testing the new API
156 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
157 comparebuffer8.Set(testbuffer8->Des());
158 test(comparebuffer8==generatedUtf8);
159 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
160 compareBuffer.Set(testbuffer->Des());
161 test(compareBuffer == originalUnicode);
165 INFO_PRINTF1(_L("Japanese \"Hello!\""));
166 originalUnicode.Format(_L16("%c%c%c%c"), 0x4eca, 0x65e5, 0x306f, 0x0021);
167 test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
168 test(generatedUtf8==_L8("\xe4\xbb\x8a\xe6\x97\xa5\xe3\x81\xaf\x21"));
169 test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
170 test(generatedUnicode==originalUnicode);
171 // Testing the new API
172 testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
173 comparebuffer8.Set(testbuffer8->Des());
174 test(comparebuffer8==generatedUtf8);
175 testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
176 compareBuffer.Set(testbuffer->Des());
177 test(compareBuffer == originalUnicode);
184 CT_SIMPLE8::CT_SIMPLE8()
186 SetTestStepName(KTestStep_T_SIMPLE8);
189 TVerdict CT_SIMPLE8::doTestStepL()
191 SetTestStepResult(EFail);
195 TRAPD(error1, TestSimple8());
196 TRAPD(error2, TestForUtf8BomL());
201 if(error1 == KErrNone && error2 == KErrNone)
203 SetTestStepResult(EPass);
206 return TestStepResult();