sl@0: /* sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_realuni.h" sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: sl@0: #define test(cond) \ sl@0: { \ sl@0: TBool __bb = (cond); \ sl@0: TEST(__bb); \ sl@0: if (!__bb) \ sl@0: { \ sl@0: ERR_PRINTF1(_L("ERROR: Test Failed")); \ sl@0: User::Leave(1); \ sl@0: } \ sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CHARCONV-CT-0568 sl@0: @SYMTestCaseDesc Testing a real Unicode file's round trip sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Tests for CnvUtfConverter::ConvertFromUnicodeToUtf8() function sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void CT_REALUNI::TestREALUNI() sl@0: { sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0568 Testing a \"real\" Unicode file's round trip ")); sl@0: RFs fs; sl@0: RFile file; sl@0: test(fs.Connect() == KErrNone); sl@0: TFindFile findFile=fs; sl@0: test(findFile.FindByDir(_L("DAXUE.UNI"), _L("\\system\\data\\"))==KErrNone); sl@0: test(file.Open(fs, findFile.File(), EFileShareExclusive|EFileStream|EFileRead)==KErrNone); sl@0: TInt size=0; sl@0: test(file.Size(size) == KErrNone); sl@0: test((size>0) && (size%2==0)); sl@0: HBufC16* originalUnicode=HBufC16::New(size/2); sl@0: HBufC8* generatedUtf8=HBufC8::New(size*2); sl@0: HBufC16* generatedUnicode=HBufC16::New(size/2); sl@0: test(originalUnicode!=NULL); sl@0: test(generatedUtf8!=NULL); sl@0: test(generatedUnicode!=NULL); sl@0: TPtr8 ptr1(REINTERPRET_CAST(TUint8*, CONST_CAST(TUint16*, originalUnicode->Ptr())), 0, size); sl@0: test(file.Read(ptr1) == KErrNone); sl@0: test(ptr1.Length()==size); sl@0: TPtr16 ptr2=originalUnicode->Des(); sl@0: ptr2.SetLength(size/2); sl@0: test(originalUnicode->Size()==size); sl@0: TPtr8 ptr3=generatedUtf8->Des(); sl@0: test(CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr3, *originalUnicode)==0); sl@0: TPtr16 ptr4=generatedUnicode->Des(); sl@0: test(CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr4, *generatedUtf8)==0); sl@0: test(*generatedUnicode==*originalUnicode); sl@0: delete originalUnicode; sl@0: delete generatedUtf8; sl@0: delete generatedUnicode; sl@0: file.Close(); sl@0: fs.Close(); sl@0: sl@0: } sl@0: sl@0: CT_REALUNI::CT_REALUNI() sl@0: { sl@0: SetTestStepName(KTestStep_T_REALUNI); sl@0: } sl@0: sl@0: TVerdict CT_REALUNI::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: TRAPD(error1, TestREALUNI()); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if(error1 == KErrNone ) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: }