os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/tcomp8.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 1997-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 <utf.h>
    21 #include "utf8.h"
    22 #include "t_comp8.h"
    23 ///////////////////////////////////////////////////////////////////////////////////////
    24 
    25 
    26 #define test(cond)                                  \
    27     TEST((cond));                                   \
    28     if (!(cond))                                    \
    29         {                                           \
    30         ERR_PRINTF1(_L("ERROR: Test Failed"));      \
    31         User::Leave(1);                             \
    32         }
    33 
    34 ///////////////////////////////////////////////////////////////////////////////////////
    35 ///////////////////////////////////////////////////////////////////////////////////////
    36 
    37 enum TPanic
    38 	{
    39 	EPanicNoFreeSpaceAtEndOfBuffer1=1,
    40 	EPanicNoFreeSpaceAtEndOfBuffer2
    41 	};
    42 
    43 LOCAL_C void Panic(TPanic aPanic)
    44 	{
    45 	User::Panic(_L("TCOMP8"), aPanic);
    46 	}
    47 /**
    48 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0566
    49 @SYMTestCaseDesc        Comparing behaviour with the Unicode CD-ROM UTF-8 sample code
    50 @SYMTestPriority        Medium
    51 @SYMTestActions        	Tests for CnvUtfConverter::ConvertToUnicodeFromUtf8() function
    52 @SYMTestExpectedResults Test must not fail
    53 @SYMREQ                 REQ0000
    54 */
    55 void CT_COMP8::TestCOMP8()
    56 	{
    57     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0566 Comparing behaviour with the Unicode CD-ROM UTF-8 sample code "));
    58 	TDes16* originalUnicode=new TBuf16<512>;
    59 	TDes8* generatedUtf8=new TBuf8<1024>;
    60 	TDes8* otherGeneratedUtf8=new TBuf8<1024>;
    61 	TDes16* generatedUnicode=new TBuf16<512>;
    62 	TDes16* otherGeneratedUnicode=new TBuf16<512>;
    63 	//
    64 	*originalUnicode=_L16("");
    65 	originalUnicode->AppendFormat(_L16("Here are some European letters: %c%c%c%c%c%c%c%c%c%c. "), 0x0117, 0x010d, 0x00f1, 0x00df, 0x00d8, 0x0142, 0x0151, 0x016f, 0x0131, 0x00c9);
    66 	originalUnicode->AppendFormat(_L16("Here are some Greek letters: %c%c%c%c%c%c%c%c%c%c. "),    0x03a3, 0x03bf, 0x03bc, 0x03b4, 0x03b5, 0x0345, 0x03a9, 0x0392, 0x0395, 0x03a1);
    67 	originalUnicode->AppendFormat(_L16("Here are some Cyrillic letters: %c%c%c%c%c%c%c%c%c%c. "), 0x0437, 0x0430, 0x0440, 0x0435, 0x0438, 0x0306, 0x0411, 0x041e, 0x0423, 0x0416);
    68 	originalUnicode->AppendFormat(_L16("Here are some Georgian letters: %c%c%c%c%c%c%c%c%c%c. "), 0x10da, 0x10e0, 0x10e9, 0x10ef, 0x10d2, 0x10d7, 0x10e2, 0x10d0, 0x10ed, 0x10e8);
    69 	originalUnicode->AppendFormat(_L16("Here are some Japanese kana: %c%c%c%c%c%c%c%c%c%c. "),    0x30a2, 0x30c0, 0x30d5, 0x30b7, 0x30ba, 0x3091, 0x3093, 0x3055, 0x3074, 0x3080);
    70 	originalUnicode->AppendFormat(_L16("Here are some Han characters: %c%c%c%c%c%c%c%c%c%c. "),   0x7f0c, 0x7a92, 0x6d90, 0x6272, 0x5934, 0x5973, 0x55ce, 0x516c, 0x4ec0, 0x4e00);
    71 	originalUnicode->AppendFormat(_L16("Here are some surrogate pairs: %c%c%c%c%c%c%c%c%c%c. "),   0xd800, 0xdc00, 0xdbff, 0xdfff, 0xdb80, 0xdddd, 0xdbff, 0xdcba, 0xdbeb, 0xdeb0);
    72 	originalUnicode->AppendFormat(_L16("Here are some odd bits and pieces: =+-/*?#~'@!\"$%%^&\\|()[]{}<>_;:,. "));
    73 	INFO_PRINTF1(_L("Round-trips via UTF-8"));
    74 	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(*generatedUtf8, *originalUnicode)==0);
    75 	{__ASSERT_ALWAYS(originalUnicode->Length()<originalUnicode->MaxLength(), Panic(EPanicNoFreeSpaceAtEndOfBuffer1));
    76 	TUint16* sourceStart=CONST_CAST(TUint16*, originalUnicode->Ptr());
    77 	TUint16* sourceEnd=sourceStart+originalUnicode->Length();
    78 	TUint8* targetStart=CONST_CAST(TUint8*, otherGeneratedUtf8->Ptr());
    79 	TUint8* targetEnd=targetStart+(otherGeneratedUtf8->MaxLength()-1);
    80 	test(ConvertUTF16toUTF8(&sourceStart, sourceEnd, &targetStart, targetEnd)==ok);
    81 	otherGeneratedUtf8->SetLength(targetStart-otherGeneratedUtf8->Ptr());}
    82 	test(*generatedUtf8==*otherGeneratedUtf8);
    83 	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(*generatedUnicode, *generatedUtf8)==0);
    84 	{__ASSERT_ALWAYS(otherGeneratedUtf8->Length()<otherGeneratedUtf8->MaxLength(), Panic(EPanicNoFreeSpaceAtEndOfBuffer2));
    85 	TUint8* sourceStart=CONST_CAST(TUint8*, otherGeneratedUtf8->Ptr());
    86 	TUint8* sourceEnd=sourceStart+otherGeneratedUtf8->Length();
    87 	TUint16* targetStart=CONST_CAST(TUint16*, otherGeneratedUnicode->Ptr());
    88 	TUint16* targetEnd=targetStart+(otherGeneratedUnicode->MaxLength()-1);
    89 	test(ConvertUTF8toUTF16(&sourceStart, sourceEnd, &targetStart, targetEnd)==ok);
    90 	otherGeneratedUnicode->SetLength(targetStart-otherGeneratedUnicode->Ptr());}
    91 	test(*generatedUnicode==*originalUnicode);
    92 	test(*generatedUnicode==*otherGeneratedUnicode);
    93 	//
    94 	delete originalUnicode;
    95 	delete generatedUtf8;
    96 	delete otherGeneratedUtf8;
    97 	delete generatedUnicode;
    98 	delete otherGeneratedUnicode;
    99 	}
   100 
   101 
   102 CT_COMP8::CT_COMP8()
   103     {
   104     SetTestStepName(KTestStep_T_COMP8);
   105     }
   106 
   107 TVerdict CT_COMP8::doTestStepL()
   108     {
   109     SetTestStepResult(EFail);
   110 
   111     __UHEAP_MARK;
   112 
   113     TRAPD(error1, TestCOMP8());
   114 
   115     __UHEAP_MARKEND;
   116 
   117     if(error1 == KErrNone )
   118         {
   119         SetTestStepResult(EPass);
   120         }
   121 
   122     return TestStepResult();
   123     }
   124 
   125