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_realut8.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: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CHARCONV-CT-0567 sl@0: @SYMTestCaseDesc Testing a real UTF8 file's round trip sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Tests for CnvUtfConverter::ConvertToUnicodeFromUtf8() function sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void CT_REALUT8::TestREALUT8() sl@0: { sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0567 Testing a \"real\" UTF8 file's round trip ")); sl@0: RFs fs; sl@0: RFile inputFile; sl@0: test(fs.Connect()== KErrNone); sl@0: TFindFile findFile=fs; sl@0: test(findFile.FindByDir(_L("ETHIOPIC.UT8"), _L("\\system\\data\\"))==KErrNone); sl@0: test(inputFile.Open(fs, findFile.File(), EFileShareExclusive|EFileStream|EFileRead)==KErrNone); sl@0: TInt size=0; sl@0: test(inputFile.Size(size) == KErrNone); sl@0: HBufC8* originalUtf8=HBufC8::New(size); sl@0: HBufC16* generatedUnicode=HBufC16::New(size); sl@0: HBufC8* generatedUtf8=HBufC8::New(size); sl@0: RFile outputFile; sl@0: test(originalUtf8!=NULL); sl@0: test(generatedUnicode!=NULL); sl@0: test(generatedUtf8!=NULL); sl@0: TPtr8 ptr1=originalUtf8->Des(); sl@0: test(inputFile.Read(ptr1) == KErrNone); sl@0: test(outputFile.Replace(fs, _L("c:\\ETHIOPIC.UNI"), EFileShareExclusive|EFileStream|EFileWrite)==KErrNone); sl@0: TPtr16 ptr2=generatedUnicode->Des(); sl@0: test(CnvUtfConverter::ConvertToUnicodeFromUtf8(ptr2, *originalUtf8)==0); sl@0: TPtr8 ptr3=generatedUtf8->Des(); sl@0: test(CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr3, *generatedUnicode)==0); sl@0: test(*generatedUtf8==*originalUtf8); sl@0: test(outputFile.Write(TPtrC8(REINTERPRET_CAST(const TUint8*, generatedUnicode->Ptr()), generatedUnicode->Size()))==KErrNone); sl@0: outputFile.Close(); sl@0: delete generatedUtf8; sl@0: delete generatedUnicode; sl@0: delete originalUtf8; sl@0: inputFile.Close(); sl@0: fs.Close(); sl@0: } sl@0: sl@0: CT_REALUT8::CT_REALUT8() sl@0: { sl@0: SetTestStepName(KTestStep_T_REALUT8); sl@0: } sl@0: sl@0: TVerdict CT_REALUT8::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: TRAPD(error1, TestREALUT8()); 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: }