os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/tcomp7.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/tcomp7.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,140 @@
     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 +#include <utf.h>
    1.24 +#include "utf7.h"
    1.25 +#include "t_comp7.h"
    1.26 +
    1.27 +///////////////////////////////////////////////////////////////////////////////////////
    1.28 +
    1.29 +
    1.30 +#define test(cond)                                  \
    1.31 +    TEST((cond));                                   \
    1.32 +    if (!(cond))                                    \
    1.33 +        {                                           \
    1.34 +        ERR_PRINTF1(_L("ERROR: Test Failed"));      \
    1.35 +        User::Leave(1);                             \
    1.36 +        }
    1.37 +
    1.38 +
    1.39 +
    1.40 +///////////////////////////////////////////////////////////////////////////////////////
    1.41 +///////////////////////////////////////////////////////////////////////////////////////
    1.42 +
    1.43 +enum TPanic
    1.44 +	{
    1.45 +	EPanicNoFreeSpaceAtEndOfBuffer1=1,
    1.46 +	EPanicNoFreeSpaceAtEndOfBuffer2
    1.47 +	};
    1.48 +
    1.49 +LOCAL_C void Panic(TPanic aPanic)
    1.50 +	{
    1.51 +	User::Panic(_L("TCOMP7"), aPanic);
    1.52 +	}
    1.53 +/**
    1.54 +@SYMTestCaseID          SYSLIB-CHARCONV-CT-0565
    1.55 +@SYMTestCaseDesc        Comparing behaviour with the Unicode CD-ROM UTF-7 sample code
    1.56 +@SYMTestPriority        Medium
    1.57 +@SYMTestActions        	Tests for CnvUtfConverter::ConvertToUnicodeFromUtf7() function
    1.58 +@SYMTestExpectedResults Test must not fail
    1.59 +@SYMREQ                 REQ0000
    1.60 +*/
    1.61 +void CT_COMP7::TestCOMP7()
    1.62 +	{
    1.63 +    INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0565 Comparing behaviour with the Unicode CD-ROM UTF-7 sample code "));
    1.64 +	TDes16* originalUnicode=new TBuf16<512>;
    1.65 +	TDes8* generatedUtf7=new TBuf8<1024>;
    1.66 +	TDes8* otherGeneratedUtf7=new TBuf8<1024>;
    1.67 +	TDes16* generatedUnicode=new TBuf16<512>;
    1.68 +	TDes16* otherGeneratedUnicode=new TBuf16<512>;
    1.69 +	TInt state=CnvUtfConverter::KStateDefault;
    1.70 +	//
    1.71 +	*originalUnicode=_L16("");
    1.72 +	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);
    1.73 +	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);
    1.74 +	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);
    1.75 +	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);
    1.76 +	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);
    1.77 +	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);
    1.78 +	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);
    1.79 +	originalUnicode->AppendFormat(_L16("Here are some odd bits and pieces: =+-/*?#~'@!\"$%%^&\\|()[]{}<>_;:,. "));
    1.80 +	enum TUtf7Flags
    1.81 +		{
    1.82 +		EUtf7FlagOptional		=0x00000001,
    1.83 +		EUtf7FlagOtherOptional	=0x00000002,
    1.84 +		EUtf7FlagOtherVerbose	=0x00000004,
    1.85 +		EUtf7FlagCrossOver		=0x00000008,
    1.86 +		EUtf7FlagDone			=0x00000010
    1.87 +		};
    1.88 +	INFO_PRINTF1(_L("Round-trips via UTF-7"));
    1.89 +	for (TInt i=0; ~i&EUtf7FlagDone; ++i)
    1.90 +		{
    1.91 +        test(CnvUtfConverter::ConvertFromUnicodeToUtf7(*generatedUtf7, *originalUnicode, i&EUtf7FlagOptional)==0);
    1.92 +		{__ASSERT_ALWAYS(originalUnicode->Length()<originalUnicode->MaxLength(), Panic(EPanicNoFreeSpaceAtEndOfBuffer1));
    1.93 +		TUint16* sourceStart=CONST_CAST(TUint16*, originalUnicode->Ptr());
    1.94 +		TUint16* sourceEnd=sourceStart+originalUnicode->Length();
    1.95 +		char* targetStart=REINTERPRET_CAST(char*, CONST_CAST(TUint8*, otherGeneratedUtf7->Ptr()));
    1.96 +		char* targetEnd=targetStart+(otherGeneratedUtf7->MaxLength()-1);
    1.97 +		test(ConvertUCS2toUTF7(&sourceStart, sourceEnd, &targetStart, targetEnd, i&EUtf7FlagOtherOptional, i&EUtf7FlagOtherVerbose)==ok);
    1.98 +		otherGeneratedUtf7->SetLength(targetStart-REINTERPRET_CAST(char*, CONST_CAST(TUint8*, otherGeneratedUtf7->Ptr())));}
    1.99 +		TDes8& sourceForReturnTrip=(i&EUtf7FlagCrossOver)? *otherGeneratedUtf7: *generatedUtf7;
   1.100 +		TDes8& otherSourceForReturnTrip=(i&EUtf7FlagCrossOver)? *generatedUtf7: *otherGeneratedUtf7;
   1.101 +		test(CnvUtfConverter::ConvertToUnicodeFromUtf7(*generatedUnicode, sourceForReturnTrip, state)==0);
   1.102 +		test(state==CnvUtfConverter::KStateDefault);
   1.103 +		{__ASSERT_ALWAYS(otherSourceForReturnTrip.Length()<otherSourceForReturnTrip.MaxLength(), Panic(EPanicNoFreeSpaceAtEndOfBuffer2));
   1.104 +		char* sourceStart=REINTERPRET_CAST(char*, CONST_CAST(TUint8*, otherSourceForReturnTrip.Ptr()));
   1.105 +		char* sourceEnd=sourceStart+otherSourceForReturnTrip.Length();
   1.106 +		TUint16* targetStart=CONST_CAST(TUint16*, otherGeneratedUnicode->Ptr());
   1.107 +		TUint16* targetEnd=targetStart+(otherGeneratedUnicode->MaxLength()-1);
   1.108 +		test(ConvertUTF7toUCS2(&sourceStart, sourceEnd, &targetStart, targetEnd)==ok);
   1.109 +		otherGeneratedUnicode->SetLength(targetStart-otherGeneratedUnicode->Ptr());}
   1.110 +		test(*generatedUnicode==*originalUnicode);
   1.111 +		test(*generatedUnicode==*otherGeneratedUnicode);
   1.112 +		}
   1.113 +	//
   1.114 +	delete originalUnicode;
   1.115 +	delete generatedUtf7;
   1.116 +	delete otherGeneratedUtf7;
   1.117 +	delete generatedUnicode;
   1.118 +	delete otherGeneratedUnicode;
   1.119 +
   1.120 +	}
   1.121 +
   1.122 +CT_COMP7::CT_COMP7()
   1.123 +    {
   1.124 +    SetTestStepName(KTestStep_T_COMP7);
   1.125 +    }
   1.126 +
   1.127 +TVerdict CT_COMP7::doTestStepL()
   1.128 +    {
   1.129 +    SetTestStepResult(EFail);
   1.130 +
   1.131 +    __UHEAP_MARK;
   1.132 +
   1.133 +    TRAPD(error1, TestCOMP7());
   1.134 +
   1.135 +    __UHEAP_MARKEND;
   1.136 +
   1.137 +    if(error1 == KErrNone )
   1.138 +        {
   1.139 +        SetTestStepResult(EPass);
   1.140 +        }
   1.141 +
   1.142 +    return TestStepResult();
   1.143 +    }