1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/tsimple8.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,208 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <e32std.h>
1.23 +
1.24 +#include <utf.h>
1.25 +#include "t_simple8.h"
1.26 +///////////////////////////////////////////////////////////////////////////////////////
1.27 +
1.28 +#define test(cond) \
1.29 + TEST((cond)); \
1.30 + if (!(cond)) \
1.31 + { \
1.32 + ERR_PRINTF1(_L("ERROR: Test Failed")); \
1.33 + User::Leave(1); \
1.34 + }
1.35 +
1.36 +///////////////////////////////////////////////////////////////////////////////////////
1.37 +///////////////////////////////////////////////////////////////////////////////////////
1.38 +
1.39 +/**
1.40 +@SYMTestCaseID SYSLIB-CHARCONV-CT-4002
1.41 +@SYMTestCaseDesc Test conversion of a UTF-8 BOM between Unicode and 8-bit
1.42 + encoding.
1.43 +@SYMTestPriority Medium
1.44 +@SYMTestActions Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8(),
1.45 + CnvUtfConverter::ConvertToUnicodeFromUtf8L() function
1.46 +@SYMTestExpectedResults Tests must not fail
1.47 +@SYMREQ REQ0000
1.48 +*/
1.49 +//INC118714L
1.50 +void CT_SIMPLE8::TestForUtf8BomL()
1.51 + {
1.52 + INFO_PRINTF1(_L("@SYMTestCaseID:SYSLIB-CHARCONV-CT-4002 Testing converting to and from UTF-8 BOM."));
1.53 +
1.54 + TBuf8<100> generatedUtf8NoGKBWithBom(_L8("\xef\xbb\xbf\x7F\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64"));
1.55 +
1.56 + //convert to unicode and verify BOM converted properly.
1.57 + INFO_PRINTF1(_L("BOM, valid UTF-8 to Unicode conversion test."));
1.58 + TBuf16<256> generatedUnicode;
1.59 + test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8NoGKBWithBom)==0);
1.60 + test(generatedUnicode==_L16("\xFEFF\x007fHello World"));
1.61 +
1.62 + INFO_PRINTF1(_L("BOM, valid Unicode to UTF-8 conversion test."));
1.63 + TBuf8<256> generatedUtf8;
1.64 + test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, generatedUnicode)==0);
1.65 + test(generatedUtf8==generatedUtf8NoGKBWithBom);
1.66 +
1.67 + }
1.68 +
1.69 +
1.70 +/**
1.71 +@SYMTestCaseID SYSLIB-CHARCONV-CT-0563
1.72 +@SYMTestCaseDesc Conversion tests from Unicode to UTF-8 character set
1.73 +@SYMTestPriority Medium
1.74 +@SYMTestActions Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8(),
1.75 + CnvUtfConverter::ConvertToUnicodeFromUtf8L() function
1.76 +@SYMTestExpectedResults Test must not fail
1.77 +@SYMREQ REQ0000
1.78 +*/
1.79 +void CT_SIMPLE8::TestSimple8()
1.80 + {
1.81 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0563 Testing simple UTF-8 round trips "));
1.82 + TBuf16<256> originalUnicode;
1.83 + TBuf8<256> generatedUtf8;
1.84 + TBuf16<256> generatedUnicode;
1.85 + //
1.86 + INFO_PRINTF1(_L("Empty descriptor"));
1.87 + originalUnicode=_L16("");
1.88 + test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
1.89 + test(generatedUtf8==_L8(""));
1.90 + test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
1.91 + test(generatedUnicode==originalUnicode);
1.92 + // Testing the new API
1.93 + HBufC8* testbuffer8;
1.94 + HBufC* testbuffer;
1.95 + testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
1.96 + TPtr8 comparebuffer8 = testbuffer8->Des();
1.97 + test(comparebuffer8==generatedUtf8);
1.98 + testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
1.99 + TPtr compareBuffer = testbuffer->Des();
1.100 + test(compareBuffer == originalUnicode);
1.101 + delete testbuffer8;
1.102 + delete testbuffer;
1.103 +
1.104 + INFO_PRINTF1(_L("English \"Hello!\""));
1.105 + originalUnicode=_L16("Hello!");
1.106 + test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
1.107 + test(generatedUtf8==_L8("Hello!"));
1.108 + test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
1.109 + test(generatedUnicode==originalUnicode);
1.110 + // Testing the new API
1.111 + testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
1.112 + comparebuffer8.Set(testbuffer8->Des());
1.113 + test(comparebuffer8==generatedUtf8);
1.114 + testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
1.115 + compareBuffer.Set(testbuffer->Des());
1.116 + test(compareBuffer == originalUnicode);
1.117 + delete testbuffer8;
1.118 + delete testbuffer;
1.119 +
1.120 + INFO_PRINTF1(_L("Russian \"Hello!\""));
1.121 + 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);
1.122 + test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
1.123 + 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"));
1.124 + test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
1.125 + test(generatedUnicode==originalUnicode);
1.126 + // Testing the new API
1.127 + testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
1.128 + comparebuffer8.Set(testbuffer8->Des());
1.129 + test(comparebuffer8==generatedUtf8);
1.130 + testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
1.131 + compareBuffer.Set(testbuffer->Des());
1.132 + test(compareBuffer == originalUnicode);
1.133 + delete testbuffer8;
1.134 + delete testbuffer;
1.135 +
1.136 + INFO_PRINTF1(_L("Greek \"Hello!\""));
1.137 + originalUnicode.Format(_L16("%c%c%c%c%c%c"), 0x0393, 0x03b1, 0x03c3, 0x03bf, 0x03c5, 0x0021);
1.138 + test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
1.139 + test(generatedUtf8==_L8("\xce\x93\xce\xb1\xcf\x83\xce\xbf\xcf\x85\x21"));
1.140 + test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
1.141 + test(generatedUnicode==originalUnicode);
1.142 + // Testing the new API
1.143 + testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
1.144 + comparebuffer8.Set(testbuffer8->Des());
1.145 + test(comparebuffer8==generatedUtf8);
1.146 + testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
1.147 + compareBuffer.Set(testbuffer->Des());
1.148 + test(compareBuffer == originalUnicode);
1.149 + delete testbuffer8;
1.150 + delete testbuffer;
1.151 +
1.152 + INFO_PRINTF1(_L("Chinese \"Hello!\""));
1.153 + originalUnicode.Format(_L16("%c%c%c"), 0x4f60, 0x597d, 0x0021);
1.154 + test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
1.155 + test(generatedUtf8==_L8("\xe4\xbd\xa0\xe5\xa5\xbd\x21"));
1.156 + test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
1.157 + test(generatedUnicode==originalUnicode);
1.158 + // Testing the new API
1.159 + testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
1.160 + comparebuffer8.Set(testbuffer8->Des());
1.161 + test(comparebuffer8==generatedUtf8);
1.162 + testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
1.163 + compareBuffer.Set(testbuffer->Des());
1.164 + test(compareBuffer == originalUnicode);
1.165 + delete testbuffer8;
1.166 + delete testbuffer;
1.167 +
1.168 + INFO_PRINTF1(_L("Japanese \"Hello!\""));
1.169 + originalUnicode.Format(_L16("%c%c%c%c"), 0x4eca, 0x65e5, 0x306f, 0x0021);
1.170 + test(CnvUtfConverter::ConvertFromUnicodeToUtf8(generatedUtf8, originalUnicode)==0);
1.171 + test(generatedUtf8==_L8("\xe4\xbb\x8a\xe6\x97\xa5\xe3\x81\xaf\x21"));
1.172 + test(CnvUtfConverter::ConvertToUnicodeFromUtf8(generatedUnicode, generatedUtf8)==0);
1.173 + test(generatedUnicode==originalUnicode);
1.174 + // Testing the new API
1.175 + testbuffer8= CnvUtfConverter::ConvertFromUnicodeToUtf8L(originalUnicode);
1.176 + comparebuffer8.Set(testbuffer8->Des());
1.177 + test(comparebuffer8==generatedUtf8);
1.178 + testbuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(generatedUtf8);
1.179 + compareBuffer.Set(testbuffer->Des());
1.180 + test(compareBuffer == originalUnicode);
1.181 + delete testbuffer8;
1.182 + delete testbuffer;
1.183 +
1.184 +
1.185 + }
1.186 +
1.187 +CT_SIMPLE8::CT_SIMPLE8()
1.188 + {
1.189 + SetTestStepName(KTestStep_T_SIMPLE8);
1.190 + }
1.191 +
1.192 +TVerdict CT_SIMPLE8::doTestStepL()
1.193 + {
1.194 + SetTestStepResult(EFail);
1.195 +
1.196 + __UHEAP_MARK;
1.197 +
1.198 + TRAPD(error1, TestSimple8());
1.199 + TRAPD(error2, TestForUtf8BomL());
1.200 +
1.201 +
1.202 + __UHEAP_MARKEND;
1.203 +
1.204 + if(error1 == KErrNone && error2 == KErrNone)
1.205 + {
1.206 + SetTestStepResult(EPass);
1.207 + }
1.208 +
1.209 + return TestStepResult();
1.210 + }
1.211 +