xml/xmlfw/test/rtest/tsrc/t_parserucs4test.cpp
changeset 0 e35f40988205
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <charconv.h>
       
    18 
       
    19 #include <xml/parserfeature.h>
       
    20 #include <xml/xmlframeworkerrors.h>
       
    21 #include <xml/plugins/charsetconverter.h>
       
    22 
       
    23 using namespace Xml;
       
    24 
       
    25 static RTest test(_L("t_parserucs4test"));
       
    26 
       
    27 /**
       
    28 @SYMTestCaseID 		 		SYSLIB-XML-UT-3717
       
    29 @SYMTestCaseDesc		    Converting character set.
       
    30 @SYMTestPriority 		    Medium
       
    31 @SYMTestActions  		    Converting the character to unicode.
       
    32 @SYMTestExpectedResults 	The expected conversion result and the actual conversion result match.
       
    33 @SYMREQ 		 		 	REQ0000
       
    34 */
       
    35 static void ParserTestsL()
       
    36 	{
       
    37 	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-UT-3717 ParserTestsL tests... "));
       
    38 
       
    39 	__UHEAP_MARK;
       
    40 
       
    41 
       
    42 	// supplementary character
       
    43 	//    2        9        8        7        6 decimal
       
    44 	// 0010     1001     1000     0111     0110 hex
       
    45 	// 11110000 10101001 10100001 10110110      utf-8
       
    46 	//    F   0    A   9    A   1    B   6
       
    47 
       
    48 	TUint32 ucs4Char = 0x29876;
       
    49 	HBufC8* result = NULL;
       
    50 
       
    51 	CCharSetConverter* charset = CCharSetConverter::NewL();
       
    52 	CleanupStack::PushL(charset);
       
    53 
       
    54 	// read supplementary character and convert to utf8
       
    55 	charset->ConvertUcs4CharactersToEncodingL(&ucs4Char, 1, KCharacterSetIdentifierUtf8, result);
       
    56 
       
    57 	TBuf8<10> compare;
       
    58 	compare.Append(0xF0);
       
    59 	compare.Append(0xA9);
       
    60 	compare.Append(0xA1);
       
    61 	compare.Append(0xB6);
       
    62 
       
    63 	test(*result == compare);
       
    64 
       
    65 	delete result;
       
    66 	CleanupStack::PopAndDestroy(charset);
       
    67 
       
    68 
       
    69 	__UHEAP_MARKEND;
       
    70 	}
       
    71 
       
    72 static void MainL()
       
    73 	{
       
    74 	ParserTestsL();
       
    75 	}
       
    76 
       
    77 TInt E32Main()
       
    78 	{
       
    79 
       
    80 	__UHEAP_MARK;
       
    81 	test.Title();
       
    82 	test.Start(_L("initialising"));
       
    83 
       
    84 	CTrapCleanup* c=CTrapCleanup::New();
       
    85 
       
    86 	// start the loader
       
    87 	RFs fs;
       
    88 	test (fs.Connect()==KErrNone);
       
    89 	fs.Close();
       
    90 
       
    91 	test (c!=0);
       
    92 	TRAPD(r,MainL());
       
    93 	test (r==KErrNone);
       
    94 	delete c;
       
    95 	test.End();
       
    96 	test.Close();
       
    97 	__UHEAP_MARKEND;
       
    98 
       
    99 	return KErrNone;
       
   100 	}
       
   101