os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/trealut8.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_realut8.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 ///////////////////////////////////////////////////////////////////////////////////////
    42 /**
    43 @SYMTestCaseID          SYSLIB-CHARCONV-CT-0567
    44 @SYMTestCaseDesc        Testing a real UTF8 file's round trip
    45 @SYMTestPriority        Medium
    46 @SYMTestActions        	Tests for CnvUtfConverter::ConvertToUnicodeFromUtf8() function
    47 @SYMTestExpectedResults Test must not fail
    48 @SYMREQ                 REQ0000
    49 */
    50 void CT_REALUT8::TestREALUT8()
    51 	{
    52     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0567 Testing a \"real\" UTF8 file's round trip "));
    53 	RFs fs;
    54 	RFile inputFile;
    55 	test(fs.Connect()== KErrNone);
    56 	TFindFile findFile=fs;
    57 	test(findFile.FindByDir(_L("ETHIOPIC.UT8"), _L("\\system\\data\\"))==KErrNone);
    58 	test(inputFile.Open(fs, findFile.File(), EFileShareExclusive|EFileStream|EFileRead)==KErrNone);
    59 	TInt size=0;
    60 	test(inputFile.Size(size) == KErrNone);
    61 	HBufC8* originalUtf8=HBufC8::New(size);
    62 	HBufC16* generatedUnicode=HBufC16::New(size);
    63 	HBufC8* generatedUtf8=HBufC8::New(size);
    64 	RFile outputFile;
    65 	test(originalUtf8!=NULL);
    66 	test(generatedUnicode!=NULL);
    67 	test(generatedUtf8!=NULL);
    68 	TPtr8 ptr1=originalUtf8->Des();
    69 	test(inputFile.Read(ptr1) == KErrNone);
    70 	test(outputFile.Replace(fs, _L("c:\\ETHIOPIC.UNI"), EFileShareExclusive|EFileStream|EFileWrite)==KErrNone);
    71 	TPtr16 ptr2=generatedUnicode->Des();
    72 	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr2, *originalUtf8)==0);
    73 	TPtr8 ptr3=generatedUtf8->Des();
    74 	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr3, *generatedUnicode)==0);
    75 	test(*generatedUtf8==*originalUtf8);
    76 	test(outputFile.Write(TPtrC8(REINTERPRET_CAST(const TUint8*, generatedUnicode->Ptr()), generatedUnicode->Size()))==KErrNone);
    77 	outputFile.Close();
    78 	delete generatedUtf8;
    79 	delete generatedUnicode;
    80 	delete originalUtf8;
    81 	inputFile.Close();
    82 	fs.Close();
    83 	}
    84 
    85 CT_REALUT8::CT_REALUT8()
    86     {
    87     SetTestStepName(KTestStep_T_REALUT8);
    88     }
    89 
    90 TVerdict CT_REALUT8::doTestStepL()
    91     {
    92     SetTestStepResult(EFail);
    93 
    94     __UHEAP_MARK;
    95 
    96     TRAPD(error1, TestREALUT8());
    97 
    98     __UHEAP_MARKEND;
    99 
   100     if(error1 == KErrNone )
   101         {
   102         SetTestStepResult(EPass);
   103         }
   104 
   105     return TestStepResult();
   106     }