os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/trealut8.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <e32std.h>
sl@0
    20
#include <f32file.h>
sl@0
    21
#include <utf.h>
sl@0
    22
#include "t_realut8.h"
sl@0
    23
sl@0
    24
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    25
sl@0
    26
sl@0
    27
#define test(cond)                                          \
sl@0
    28
    {                                                       \
sl@0
    29
    TBool __bb = (cond);                                    \
sl@0
    30
    TEST(__bb);                                             \
sl@0
    31
    if (!__bb)                                              \
sl@0
    32
        {                                                   \
sl@0
    33
        ERR_PRINTF1(_L("ERROR: Test Failed"));              \
sl@0
    34
        User::Leave(1);                                     \
sl@0
    35
        }                                                   \
sl@0
    36
    }
sl@0
    37
sl@0
    38
sl@0
    39
sl@0
    40
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    41
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    42
/**
sl@0
    43
@SYMTestCaseID          SYSLIB-CHARCONV-CT-0567
sl@0
    44
@SYMTestCaseDesc        Testing a real UTF8 file's round trip
sl@0
    45
@SYMTestPriority        Medium
sl@0
    46
@SYMTestActions        	Tests for CnvUtfConverter::ConvertToUnicodeFromUtf8() function
sl@0
    47
@SYMTestExpectedResults Test must not fail
sl@0
    48
@SYMREQ                 REQ0000
sl@0
    49
*/
sl@0
    50
void CT_REALUT8::TestREALUT8()
sl@0
    51
	{
sl@0
    52
    INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0567 Testing a \"real\" UTF8 file's round trip "));
sl@0
    53
	RFs fs;
sl@0
    54
	RFile inputFile;
sl@0
    55
	test(fs.Connect()== KErrNone);
sl@0
    56
	TFindFile findFile=fs;
sl@0
    57
	test(findFile.FindByDir(_L("ETHIOPIC.UT8"), _L("\\system\\data\\"))==KErrNone);
sl@0
    58
	test(inputFile.Open(fs, findFile.File(), EFileShareExclusive|EFileStream|EFileRead)==KErrNone);
sl@0
    59
	TInt size=0;
sl@0
    60
	test(inputFile.Size(size) == KErrNone);
sl@0
    61
	HBufC8* originalUtf8=HBufC8::New(size);
sl@0
    62
	HBufC16* generatedUnicode=HBufC16::New(size);
sl@0
    63
	HBufC8* generatedUtf8=HBufC8::New(size);
sl@0
    64
	RFile outputFile;
sl@0
    65
	test(originalUtf8!=NULL);
sl@0
    66
	test(generatedUnicode!=NULL);
sl@0
    67
	test(generatedUtf8!=NULL);
sl@0
    68
	TPtr8 ptr1=originalUtf8->Des();
sl@0
    69
	test(inputFile.Read(ptr1) == KErrNone);
sl@0
    70
	test(outputFile.Replace(fs, _L("c:\\ETHIOPIC.UNI"), EFileShareExclusive|EFileStream|EFileWrite)==KErrNone);
sl@0
    71
	TPtr16 ptr2=generatedUnicode->Des();
sl@0
    72
	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr2, *originalUtf8)==0);
sl@0
    73
	TPtr8 ptr3=generatedUtf8->Des();
sl@0
    74
	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr3, *generatedUnicode)==0);
sl@0
    75
	test(*generatedUtf8==*originalUtf8);
sl@0
    76
	test(outputFile.Write(TPtrC8(REINTERPRET_CAST(const TUint8*, generatedUnicode->Ptr()), generatedUnicode->Size()))==KErrNone);
sl@0
    77
	outputFile.Close();
sl@0
    78
	delete generatedUtf8;
sl@0
    79
	delete generatedUnicode;
sl@0
    80
	delete originalUtf8;
sl@0
    81
	inputFile.Close();
sl@0
    82
	fs.Close();
sl@0
    83
	}
sl@0
    84
sl@0
    85
CT_REALUT8::CT_REALUT8()
sl@0
    86
    {
sl@0
    87
    SetTestStepName(KTestStep_T_REALUT8);
sl@0
    88
    }
sl@0
    89
sl@0
    90
TVerdict CT_REALUT8::doTestStepL()
sl@0
    91
    {
sl@0
    92
    SetTestStepResult(EFail);
sl@0
    93
sl@0
    94
    __UHEAP_MARK;
sl@0
    95
sl@0
    96
    TRAPD(error1, TestREALUT8());
sl@0
    97
sl@0
    98
    __UHEAP_MARKEND;
sl@0
    99
sl@0
   100
    if(error1 == KErrNone )
sl@0
   101
        {
sl@0
   102
        SetTestStepResult(EPass);
sl@0
   103
        }
sl@0
   104
sl@0
   105
    return TestStepResult();
sl@0
   106
    }