os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/trealut8.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/trealut8.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,106 @@
     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 <f32file.h>
    1.24 +#include <utf.h>
    1.25 +#include "t_realut8.h"
    1.26 +
    1.27 +///////////////////////////////////////////////////////////////////////////////////////
    1.28 +
    1.29 +
    1.30 +#define test(cond)                                          \
    1.31 +    {                                                       \
    1.32 +    TBool __bb = (cond);                                    \
    1.33 +    TEST(__bb);                                             \
    1.34 +    if (!__bb)                                              \
    1.35 +        {                                                   \
    1.36 +        ERR_PRINTF1(_L("ERROR: Test Failed"));              \
    1.37 +        User::Leave(1);                                     \
    1.38 +        }                                                   \
    1.39 +    }
    1.40 +
    1.41 +
    1.42 +
    1.43 +///////////////////////////////////////////////////////////////////////////////////////
    1.44 +///////////////////////////////////////////////////////////////////////////////////////
    1.45 +/**
    1.46 +@SYMTestCaseID          SYSLIB-CHARCONV-CT-0567
    1.47 +@SYMTestCaseDesc        Testing a real UTF8 file's round trip
    1.48 +@SYMTestPriority        Medium
    1.49 +@SYMTestActions        	Tests for CnvUtfConverter::ConvertToUnicodeFromUtf8() function
    1.50 +@SYMTestExpectedResults Test must not fail
    1.51 +@SYMREQ                 REQ0000
    1.52 +*/
    1.53 +void CT_REALUT8::TestREALUT8()
    1.54 +	{
    1.55 +    INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0567 Testing a \"real\" UTF8 file's round trip "));
    1.56 +	RFs fs;
    1.57 +	RFile inputFile;
    1.58 +	test(fs.Connect()== KErrNone);
    1.59 +	TFindFile findFile=fs;
    1.60 +	test(findFile.FindByDir(_L("ETHIOPIC.UT8"), _L("\\system\\data\\"))==KErrNone);
    1.61 +	test(inputFile.Open(fs, findFile.File(), EFileShareExclusive|EFileStream|EFileRead)==KErrNone);
    1.62 +	TInt size=0;
    1.63 +	test(inputFile.Size(size) == KErrNone);
    1.64 +	HBufC8* originalUtf8=HBufC8::New(size);
    1.65 +	HBufC16* generatedUnicode=HBufC16::New(size);
    1.66 +	HBufC8* generatedUtf8=HBufC8::New(size);
    1.67 +	RFile outputFile;
    1.68 +	test(originalUtf8!=NULL);
    1.69 +	test(generatedUnicode!=NULL);
    1.70 +	test(generatedUtf8!=NULL);
    1.71 +	TPtr8 ptr1=originalUtf8->Des();
    1.72 +	test(inputFile.Read(ptr1) == KErrNone);
    1.73 +	test(outputFile.Replace(fs, _L("c:\\ETHIOPIC.UNI"), EFileShareExclusive|EFileStream|EFileWrite)==KErrNone);
    1.74 +	TPtr16 ptr2=generatedUnicode->Des();
    1.75 +	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr2, *originalUtf8)==0);
    1.76 +	TPtr8 ptr3=generatedUtf8->Des();
    1.77 +	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr3, *generatedUnicode)==0);
    1.78 +	test(*generatedUtf8==*originalUtf8);
    1.79 +	test(outputFile.Write(TPtrC8(REINTERPRET_CAST(const TUint8*, generatedUnicode->Ptr()), generatedUnicode->Size()))==KErrNone);
    1.80 +	outputFile.Close();
    1.81 +	delete generatedUtf8;
    1.82 +	delete generatedUnicode;
    1.83 +	delete originalUtf8;
    1.84 +	inputFile.Close();
    1.85 +	fs.Close();
    1.86 +	}
    1.87 +
    1.88 +CT_REALUT8::CT_REALUT8()
    1.89 +    {
    1.90 +    SetTestStepName(KTestStep_T_REALUT8);
    1.91 +    }
    1.92 +
    1.93 +TVerdict CT_REALUT8::doTestStepL()
    1.94 +    {
    1.95 +    SetTestStepResult(EFail);
    1.96 +
    1.97 +    __UHEAP_MARK;
    1.98 +
    1.99 +    TRAPD(error1, TestREALUT8());
   1.100 +
   1.101 +    __UHEAP_MARKEND;
   1.102 +
   1.103 +    if(error1 == KErrNone )
   1.104 +        {
   1.105 +        SetTestStepResult(EPass);
   1.106 +        }
   1.107 +
   1.108 +    return TestStepResult();
   1.109 +    }