os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/trealuni.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_realuni.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
@SYMTestCaseID          SYSLIB-CHARCONV-CT-0568
sl@0
    42
@SYMTestCaseDesc        Testing a real Unicode file's round trip
sl@0
    43
@SYMTestPriority        Medium
sl@0
    44
@SYMTestActions        	Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8() function
sl@0
    45
@SYMTestExpectedResults Test must not fail
sl@0
    46
@SYMREQ                 REQ0000
sl@0
    47
*/
sl@0
    48
void CT_REALUNI::TestREALUNI()
sl@0
    49
	{
sl@0
    50
    INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0568 Testing a \"real\" Unicode file's round trip "));
sl@0
    51
	RFs fs;
sl@0
    52
	RFile file;
sl@0
    53
	test(fs.Connect() == KErrNone);
sl@0
    54
	TFindFile findFile=fs;
sl@0
    55
	test(findFile.FindByDir(_L("DAXUE.UNI"), _L("\\system\\data\\"))==KErrNone);
sl@0
    56
	test(file.Open(fs, findFile.File(), EFileShareExclusive|EFileStream|EFileRead)==KErrNone);
sl@0
    57
	TInt size=0;
sl@0
    58
	test(file.Size(size) == KErrNone);
sl@0
    59
	test((size>0) && (size%2==0));
sl@0
    60
	HBufC16* originalUnicode=HBufC16::New(size/2);
sl@0
    61
	HBufC8* generatedUtf8=HBufC8::New(size*2);
sl@0
    62
	HBufC16* generatedUnicode=HBufC16::New(size/2);
sl@0
    63
	test(originalUnicode!=NULL);
sl@0
    64
	test(generatedUtf8!=NULL);
sl@0
    65
	test(generatedUnicode!=NULL);
sl@0
    66
	TPtr8 ptr1(REINTERPRET_CAST(TUint8*, CONST_CAST(TUint16*, originalUnicode->Ptr())), 0, size);
sl@0
    67
	test(file.Read(ptr1) == KErrNone);
sl@0
    68
	test(ptr1.Length()==size);
sl@0
    69
	TPtr16 ptr2=originalUnicode->Des();
sl@0
    70
	ptr2.SetLength(size/2);
sl@0
    71
	test(originalUnicode->Size()==size);
sl@0
    72
	TPtr8 ptr3=generatedUtf8->Des();
sl@0
    73
	test(CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr3, *originalUnicode)==0);
sl@0
    74
	TPtr16 ptr4=generatedUnicode->Des();
sl@0
    75
	test(CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr4, *generatedUtf8)==0);
sl@0
    76
	test(*generatedUnicode==*originalUnicode);
sl@0
    77
	delete originalUnicode;
sl@0
    78
	delete generatedUtf8;
sl@0
    79
	delete generatedUnicode;
sl@0
    80
	file.Close();
sl@0
    81
	fs.Close();
sl@0
    82
sl@0
    83
	}
sl@0
    84
sl@0
    85
CT_REALUNI::CT_REALUNI()
sl@0
    86
    {
sl@0
    87
    SetTestStepName(KTestStep_T_REALUNI);
sl@0
    88
    }
sl@0
    89
sl@0
    90
TVerdict CT_REALUNI::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, TestREALUNI());
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
    }