1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/charconvfw/charconv_fw/test/rtest/tsrc/utf/trealuni.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_realuni.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 +@SYMTestCaseID SYSLIB-CHARCONV-CT-0568
1.45 +@SYMTestCaseDesc Testing a real Unicode file's round trip
1.46 +@SYMTestPriority Medium
1.47 +@SYMTestActions Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8() function
1.48 +@SYMTestExpectedResults Test must not fail
1.49 +@SYMREQ REQ0000
1.50 +*/
1.51 +void CT_REALUNI::TestREALUNI()
1.52 + {
1.53 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0568 Testing a \"real\" Unicode file's round trip "));
1.54 + RFs fs;
1.55 + RFile file;
1.56 + test(fs.Connect() == KErrNone);
1.57 + TFindFile findFile=fs;
1.58 + test(findFile.FindByDir(_L("DAXUE.UNI"), _L("\\system\\data\\"))==KErrNone);
1.59 + test(file.Open(fs, findFile.File(), EFileShareExclusive|EFileStream|EFileRead)==KErrNone);
1.60 + TInt size=0;
1.61 + test(file.Size(size) == KErrNone);
1.62 + test((size>0) && (size%2==0));
1.63 + HBufC16* originalUnicode=HBufC16::New(size/2);
1.64 + HBufC8* generatedUtf8=HBufC8::New(size*2);
1.65 + HBufC16* generatedUnicode=HBufC16::New(size/2);
1.66 + test(originalUnicode!=NULL);
1.67 + test(generatedUtf8!=NULL);
1.68 + test(generatedUnicode!=NULL);
1.69 + TPtr8 ptr1(REINTERPRET_CAST(TUint8*, CONST_CAST(TUint16*, originalUnicode->Ptr())), 0, size);
1.70 + test(file.Read(ptr1) == KErrNone);
1.71 + test(ptr1.Length()==size);
1.72 + TPtr16 ptr2=originalUnicode->Des();
1.73 + ptr2.SetLength(size/2);
1.74 + test(originalUnicode->Size()==size);
1.75 + TPtr8 ptr3=generatedUtf8->Des();
1.76 + test(CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr3, *originalUnicode)==0);
1.77 + TPtr16 ptr4=generatedUnicode->Des();
1.78 + test(CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr4, *generatedUtf8)==0);
1.79 + test(*generatedUnicode==*originalUnicode);
1.80 + delete originalUnicode;
1.81 + delete generatedUtf8;
1.82 + delete generatedUnicode;
1.83 + file.Close();
1.84 + fs.Close();
1.85 +
1.86 + }
1.87 +
1.88 +CT_REALUNI::CT_REALUNI()
1.89 + {
1.90 + SetTestStepName(KTestStep_T_REALUNI);
1.91 + }
1.92 +
1.93 +TVerdict CT_REALUNI::doTestStepL()
1.94 + {
1.95 + SetTestStepResult(EFail);
1.96 +
1.97 + __UHEAP_MARK;
1.98 +
1.99 + TRAPD(error1, TestREALUNI());
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 + }