os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/trealuni.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 <f32file.h>
    21 #include <utf.h>
    22 #include "t_realuni.h"
    23 
    24 ///////////////////////////////////////////////////////////////////////////////////////
    25 
    26 
    27 #define test(cond)                                          \
    28     {                                                       \
    29     TBool __bb = (cond);                                    \
    30     TEST(__bb);                                             \
    31     if (!__bb)                                              \
    32         {                                                   \
    33         ERR_PRINTF1(_L("ERROR: Test Failed"));              \
    34         User::Leave(1);                                     \
    35         }                                                   \
    36     }
    37 
    38 ///////////////////////////////////////////////////////////////////////////////////////
    39 ///////////////////////////////////////////////////////////////////////////////////////
    40 /**
    41 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0568
    42 @SYMTestCaseDesc        Testing a real Unicode file's round trip
    43 @SYMTestPriority        Medium
    44 @SYMTestActions        	Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8() function
    45 @SYMTestExpectedResults Test must not fail
    46 @SYMREQ                 REQ0000
    47 */
    48 void CT_REALUNI::TestREALUNI()
    49 	{
    50     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0568 Testing a \"real\" Unicode file's round trip "));
    51 	RFs fs;
    52 	RFile file;
    53 	test(fs.Connect() == KErrNone);
    54 	TFindFile findFile=fs;
    55 	test(findFile.FindByDir(_L("DAXUE.UNI"), _L("\\system\\data\\"))==KErrNone);
    56 	test(file.Open(fs, findFile.File(), EFileShareExclusive|EFileStream|EFileRead)==KErrNone);
    57 	TInt size=0;
    58 	test(file.Size(size) == KErrNone);
    59 	test((size>0) && (size%2==0));
    60 	HBufC16* originalUnicode=HBufC16::New(size/2);
    61 	HBufC8* generatedUtf8=HBufC8::New(size*2);
    62 	HBufC16* generatedUnicode=HBufC16::New(size/2);
    63 	test(originalUnicode!=NULL);
    64 	test(generatedUtf8!=NULL);
    65 	test(generatedUnicode!=NULL);
    66 	TPtr8 ptr1(REINTERPRET_CAST(TUint8*, CONST_CAST(TUint16*, originalUnicode->Ptr())), 0, size);
    67 	test(file.Read(ptr1) == KErrNone);
    68 	test(ptr1.Length()==size);
    69 	TPtr16 ptr2=originalUnicode->Des();
    70 	ptr2.SetLength(size/2);
    71 	test(originalUnicode->Size()==size);
    72 	TPtr8 ptr3=generatedUtf8->Des();
    73 	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr3, *originalUnicode)==0);
    74 	TPtr16 ptr4=generatedUnicode->Des();
    75 	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr4, *generatedUtf8)==0);
    76 	test(*generatedUnicode==*originalUnicode);
    77 	delete originalUnicode;
    78 	delete generatedUtf8;
    79 	delete generatedUnicode;
    80 	file.Close();
    81 	fs.Close();
    82 
    83 	}
    84 
    85 CT_REALUNI::CT_REALUNI()
    86     {
    87     SetTestStepName(KTestStep_T_REALUNI);
    88     }
    89 
    90 TVerdict CT_REALUNI::doTestStepL()
    91     {
    92     SetTestStepResult(EFail);
    93 
    94     __UHEAP_MARK;
    95 
    96     TRAPD(error1, TestREALUNI());
    97 
    98     __UHEAP_MARKEND;
    99 
   100     if(error1 == KErrNone )
   101         {
   102         SetTestStepResult(EPass);
   103         }
   104 
   105     return TestStepResult();
   106     }