os/textandloc/textrendering/texthandling/ttext/TEtextDefect.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/texthandling/ttext/TEtextDefect.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,663 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004-2010 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 <charconv.h>
    1.23 +#include <gdi.h>
    1.24 +#include <conpics.h>
    1.25 +#include <txtrich.h>
    1.26 +#include <apadef.h>
    1.27 +
    1.28 +#include "TXTPLAIN.H"
    1.29 +#include "TxtWriter.h"
    1.30 +#include "TETextDefect.h"
    1.31 +
    1.32 +LOCAL_D CTestStep *pTestStep = NULL;
    1.33 +#define test(cond)								\
    1.34 +	{											\
    1.35 +	TBool __bb = (cond);						\
    1.36 +	pTestStep->TEST(__bb);						\
    1.37 +	if (!__bb)									\
    1.38 +		{										\
    1.39 +		ERR_PRINTF1(_L("ERROR: Test Failed"));	\
    1.40 +		User::Leave(1);							\
    1.41 +		}										\
    1.42 +	}
    1.43 +#define test2(cond, line)										\
    1.44 +	{															\
    1.45 +	TBool __bb = (cond);										\
    1.46 +	pTestStep->TEST(__bb);										\
    1.47 +	if (!__bb)													\
    1.48 +		{														\
    1.49 +		ERR_PRINTF2(_L("Line %d, ERROR: Test Failed"), line);	\
    1.50 +		User::Leave(1);											\
    1.51 +		}														\
    1.52 +	}
    1.53 +#undef INFO_PRINTF1
    1.54 +#undef INFO_PRINTF2
    1.55 +#undef ERR_PRINTF1
    1.56 +#undef ERR_PRINTF2
    1.57 +#undef ERR_PRINTF3
    1.58 +// copy from tefexportconst.h
    1.59 +#define INFO_PRINTF1(p1)        pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1))
    1.60 +#define INFO_PRINTF2(p1, p2)    pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2))
    1.61 +#define ERR_PRINTF1(p1)         pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1)) 
    1.62 +#define ERR_PRINTF2(p1, p2)     pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2)) 
    1.63 +#define ERR_PRINTF3(p1, p2, p3) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3)) ;
    1.64 +
    1.65 +
    1.66 +//Used for supressing warning in OOM tests
    1.67 + #define __UNUSED_VAR(var) var = var
    1.68 +
    1.69 +// this fixes a MSVC link warning
    1.70 +#ifdef __VC32__
    1.71 +#pragma comment (linker, "/opt:noref") 
    1.72 +#endif
    1.73 +
    1.74 +_LIT(KTestName, "Start of Tests...");
    1.75 +
    1.76 +///////////////////////////////////////////////////////////////////////////////////////
    1.77 +///////////////////////////////////////////////////////////////////////////////////////
    1.78 +//Test macroses and functions
    1.79 +LOCAL_C void Check(TInt aValue, TInt aLine)
    1.80 +	{
    1.81 +	if(!aValue)
    1.82 +		{
    1.83 +		test2(EFalse, aLine);
    1.84 +		}
    1.85 +	}
    1.86 +LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.87 +	{
    1.88 +	if(aValue != aExpected)
    1.89 +		{
    1.90 +	    ERR_PRINTF3(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.91 +		test2(EFalse, aLine);
    1.92 +		}
    1.93 +	}
    1.94 +#define CHECK1(arg) ::Check((arg), __LINE__)
    1.95 +#define CHECK2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    1.96 +
    1.97 +
    1.98 +LOCAL_C void Inc049456L()
    1.99 +	{
   1.100 +   	INFO_PRINTF1(_L("Inc049456L"));
   1.101 +
   1.102 +	CPlainTextConverter* converter = CPlainTextConverter::NewLC();
   1.103 +	CleanupStack::PopAndDestroy(converter);
   1.104 +	}
   1.105 +	
   1.106 +LOCAL_C void OOM049456L()
   1.107 +	{
   1.108 +   	INFO_PRINTF1(_L("OOM049456L"));
   1.109 +
   1.110 +	TInt tryCount=0;
   1.111 + 	TInt error = KErrNone;
   1.112 + 	__UNUSED_VAR(tryCount);
   1.113 + 	
   1.114 + 	do
   1.115 + 		{
   1.116 + 		__UHEAP_MARK;
   1.117 + 
   1.118 + 		// find out the number of open handles
   1.119 + 		TInt startProcessHandleCount;
   1.120 + 		TInt startThreadHandleCount;
   1.121 + 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
   1.122 + 		
   1.123 + 		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
   1.124 + 	
   1.125 + 		TRAP(error,Inc049456L()); 	
   1.126 + 								
   1.127 + 		__UHEAP_SETFAIL(RHeap::ENone,0);
   1.128 + 		
   1.129 + 		// check that no handles have leaked
   1.130 + 		TInt endProcessHandleCount;
   1.131 + 		TInt endThreadHandleCount;
   1.132 + 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   1.133 + 
   1.134 + 		CHECK1(startProcessHandleCount == endProcessHandleCount);
   1.135 + 		CHECK1(startThreadHandleCount  == endThreadHandleCount);
   1.136 + 				
   1.137 + 		__UHEAP_MARKEND;
   1.138 + 		
   1.139 + 		}while(error==KErrNoMemory);
   1.140 + 		
   1.141 + 	CHECK2(error, KErrNone);
   1.142 + 	INFO_PRINTF2(_L("- server succeeded at heap failure rate of %i\n"),tryCount);		
   1.143 +	}
   1.144 +
   1.145 +
   1.146 +
   1.147 +
   1.148 +LOCAL_C void Inc051360L()
   1.149 +	{
   1.150 +   	INFO_PRINTF1(_L("Inc051360L"));
   1.151 +   	
   1.152 +	// Test data to force a remainder of 2 from the charconv unicode conversion.
   1.153 +	// The etext buffer is 1024 bytes that truncates the last utf-8 character.
   1.154 +	// It needs three bytes but only has two, hence remainder 2.
   1.155 +	const TUint8 KUtf8TextJapanese [] = 
   1.156 +	{
   1.157 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.158 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.159 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.160 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.161 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.162 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.163 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.164 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.165 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.166 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.167 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.168 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.169 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.170 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.171 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.172 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.173 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.174 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.175 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.176 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.177 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.178 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.179 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.180 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.181 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.182 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.183 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.184 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.185 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.186 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.187 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.188 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.189 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.190 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.191 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.192 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.193 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.194 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.195 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.196 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.197 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.198 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.199 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.200 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.201 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.202 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.203 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.204 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.205 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
   1.206 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // 1000 bytes
   1.207 +	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // 1020
   1.208 +	0x20, 0x20, 0xE3, 0x81, 0x82, 0xE3, 0x81, 0x8B, // total 1028
   1.209 +	}; //                   ^ 1025, will not be read on first pass
   1.210 +	
   1.211 +	// Need to know the data length for our buffers.
   1.212 +	const TUint KBufferSize = 1028;
   1.213 +
   1.214 +	// Copy the raw data into an 8-bit descriptor
   1.215 +	TBuf8<KBufferSize> textBuffer;
   1.216 +	textBuffer.Copy (KUtf8TextJapanese, KBufferSize);
   1.217 +
   1.218 +	// The unicode conversion of the result expected
   1.219 +	const TUint16 KUnicodeTextJapaneseResult [] = {0x3042, 0x304B,};
   1.220 +
   1.221 +	TBuf16 <2> unicodeConversion;
   1.222 +	unicodeConversion.Copy (KUnicodeTextJapaneseResult, 2);
   1.223 +		
   1.224 +	// The converter
   1.225 +	CPlainTextConverter* plainText = CPlainTextConverter::NewLC();
   1.226 +
   1.227 +	// The input buffer
   1.228 +	CBufFlat* inbuffer = CBufFlat::NewL(KBufferSize);
   1.229 +	CleanupStack::PushL (inbuffer);
   1.230 +	
   1.231 +	inbuffer->InsertL (0, textBuffer);
   1.232 +	
   1.233 +	// The input stream
   1.234 +	RBufReadStream inputStr (*inbuffer, 0);
   1.235 +	CleanupClosePushL (inputStr);
   1.236 +
   1.237 +	// The output buffer
   1.238 +	CBufFlat* outbuffer = CBufFlat::NewL(KBufferSize);
   1.239 +	CleanupStack::PushL (outbuffer);
   1.240 +	
   1.241 +	// The output stream
   1.242 +	RBufWriteStream outputStr (*outbuffer, 0);
   1.243 +	CleanupClosePushL (outputStr);
   1.244 +	
   1.245 +	// Input specifications
   1.246 +	CPlainText::TImportExportParam param;
   1.247 +	param.iOutputInternal  = TRUE; // force output to internal format
   1.248 +	param.iForeignEncoding = KCharacterSetIdentifierUtf8;
   1.249 +	
   1.250 +	// The result of the operation
   1.251 +	CPlainText::TImportExportResult result;
   1.252 +	
   1.253 +	// Translate the data
   1.254 +	TPlainTextReader::TranslateL(param, result, outputStr, inputStr);
   1.255 +	
   1.256 +	// Get the 8-bit data into a 16-bit buffer.
   1.257 +	// Can't use Copy as this will store each byte on a word boundary!
   1.258 +	TPtr8 ptr8 (outbuffer->Ptr(outbuffer->Size()-4));
   1.259 +	const TUint16* ptr = (TUint16*) (ptr8.Ptr());
   1.260 +	TPtrC16 des16 (ptr, 2);
   1.261 +
   1.262 +	CHECK1(unicodeConversion == des16);
   1.263 +	
   1.264 +	CleanupStack::PopAndDestroy (&outputStr);	
   1.265 +	CleanupStack::PopAndDestroy (outbuffer);	
   1.266 +	CleanupStack::PopAndDestroy (&inputStr);	
   1.267 +	CleanupStack::PopAndDestroy (inbuffer);	
   1.268 +	CleanupStack::PopAndDestroy (plainText);
   1.269 +	}
   1.270 +	
   1.271 +LOCAL_C void OOM051360L()
   1.272 +	{
   1.273 +   	INFO_PRINTF1(_L("OOM051360L"));
   1.274 +
   1.275 +	TInt tryCount=0;
   1.276 + 	TInt error = KErrNone;
   1.277 + 	__UNUSED_VAR(tryCount);
   1.278 + 	
   1.279 + 	do
   1.280 + 		{
   1.281 + 		__UHEAP_MARK;
   1.282 + 
   1.283 + 		// find out the number of open handles
   1.284 + 		TInt startProcessHandleCount;
   1.285 + 		TInt startThreadHandleCount;
   1.286 + 		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
   1.287 + 		
   1.288 + 		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
   1.289 + 	
   1.290 + 		TRAP(error,Inc051360L()); 	
   1.291 + 								
   1.292 + 		__UHEAP_SETFAIL(RHeap::ENone,0);
   1.293 + 		
   1.294 + 		// check that no handles have leaked
   1.295 + 		TInt endProcessHandleCount;
   1.296 + 		TInt endThreadHandleCount;
   1.297 + 		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
   1.298 + 
   1.299 + 		CHECK1(startProcessHandleCount == endProcessHandleCount);
   1.300 + 		CHECK1(startThreadHandleCount  == endThreadHandleCount);
   1.301 + 				
   1.302 + 		__UHEAP_MARKEND;
   1.303 + 		
   1.304 + 		}while(error==KErrNoMemory);
   1.305 + 		
   1.306 + 	CHECK2(error, KErrNone);
   1.307 + 	INFO_PRINTF2(_L("- server succeeded at heap failure rate of %i\n"),tryCount);		
   1.308 +	}
   1.309 +	
   1.310 +LOCAL_C void OOM056552L()
   1.311 +	{
   1.312 +	INFO_PRINTF1(_L("OOM056552L"));
   1.313 +
   1.314 +	TInt tryCount=0;
   1.315 + 	TInt error = KErrNone;
   1.316 + 	__UNUSED_VAR(tryCount);
   1.317 + 	
   1.318 + 	do
   1.319 + 		{
   1.320 + 		__UHEAP_MARK;
   1.321 + 	
   1.322 + 	    CParaFormatLayer* paraLayer=CParaFormatLayer::NewL();
   1.323 +	    CCharFormatLayer* charLayer=CCharFormatLayer::NewL();
   1.324 +   	    CRichText* richText = CRichText::NewL(paraLayer,charLayer);
   1.325 +   	    CXzePicture* pic=CXzePicture::NewL('x');
   1.326 +   	    TPictureHeader header;
   1.327 +   	    header.iPictureType = KUidPictureTypeDoor;
   1.328 +   	    header.iPicture=pic;
   1.329 + 		
   1.330 + 		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
   1.331 + 	
   1.332 + 		TRAP(error,	richText->InsertL(richText->DocumentLength(), header)); 	
   1.333 + 								
   1.334 + 		__UHEAP_SETFAIL(RHeap::ENone,0);
   1.335 + 		
   1.336 + 		delete paraLayer; paraLayer = NULL;
   1.337 + 		delete charLayer; charLayer = NULL;
   1.338 + 		delete richText; richText = NULL;	
   1.339 + 		
   1.340 + 		__UHEAP_MARKEND;
   1.341 + 		
   1.342 + 		}while(error==KErrNoMemory);
   1.343 + 		
   1.344 + 	test(error==KErrNone);
   1.345 + 	INFO_PRINTF2(_L("	richText->InsertL - succeeded at heap failure rate of %i\n"),tryCount);	
   1.346 +	}
   1.347 +/////////////////////////////////////////////////////////////////////////////////////////////////
   1.348 +// Testing the fix for
   1.349 +// "INC055971  NTT - Received MMS with line break "CR" set does not cause line feed."
   1.350 +// In order to make the testing easier, MOutputChar, MTextWriter, TSLBTransaltor, 
   1.351 +// TParagraphTextWriter, TLineTextWriter production classes are used outside their environment.
   1.352 +// TOutputChar test class implements MOutputChar interface. It is used to collect the character
   1.353 +// output from the processing of the imput character sequences. Then, the output is tested against
   1.354 +// the expected set of output characters.
   1.355 +//
   1.356 +// The follwing translation rules are tested:
   1.357 +// 1) Organising by paragraph
   1.358 +//    - 0x0D      - line break;
   1.359 +//    - 0x0A      - line break;
   1.360 +//    - 0x0D 0x0A - line break;
   1.361 +// 2) Organising by line
   1.362 +//    - single line break - space;
   1.363 +//    - double line break - paragraph delimiter;
   1.364 +
   1.365 +TBuf<32> TheOutputTestBuf;//Here the output is collected and then asserted
   1.366 +
   1.367 +class TOutputChar : public MOutputChar
   1.368 +	{
   1.369 +public:
   1.370 +	virtual void OutputCharL(TText aChar)
   1.371 +		{
   1.372 +		TheOutputTestBuf.Append(aChar);
   1.373 +		}
   1.374 +	};
   1.375 +
   1.376 +static void TranslateToEofTestL(TSLBTransaltor& aSLBTranslator, const TDesC& aTestBuf)
   1.377 +	{
   1.378 +	for(TInt i=0;i<aTestBuf.Length();++i)
   1.379 +		{
   1.380 +		TText c = aTestBuf[i];
   1.381 +		aSLBTranslator.ProcessL(c);
   1.382 +		}
   1.383 +	aSLBTranslator.FlushL();
   1.384 +	}
   1.385 +
   1.386 +static void INC055971L()
   1.387 +	{
   1.388 +	TBuf<32> testBuf;
   1.389 +	TOutputChar outputChar;
   1.390 +
   1.391 +   	INFO_PRINTF1(_L("INC055971L - OrganiseByParagraph test"));
   1.392 +
   1.393 +		{
   1.394 +		TParagraphTextWriter paragraphTextWriter(outputChar);
   1.395 +		TSLBTransaltor slbTranslator(paragraphTextWriter);
   1.396 +
   1.397 +		testBuf = _L("\xD");
   1.398 +		TheOutputTestBuf.Zero();
   1.399 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.400 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.401 +		CHECK1(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
   1.402 +
   1.403 +		testBuf = _L("\xA");
   1.404 +		TheOutputTestBuf.Zero();
   1.405 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.406 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.407 +		CHECK1(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
   1.408 +
   1.409 +		testBuf = _L("\xD\xA");
   1.410 +		TheOutputTestBuf.Zero();
   1.411 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.412 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.413 +		CHECK1(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
   1.414 +
   1.415 +		testBuf = _L("zz\xD\xA\xD\xA\xAz\xD");
   1.416 +		TheOutputTestBuf.Zero();
   1.417 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.418 +		CHECK1(TheOutputTestBuf.Length() == 7);
   1.419 +		CHECK1(TheOutputTestBuf[0] == 'z');
   1.420 +		CHECK1(TheOutputTestBuf[1] == 'z');
   1.421 +		CHECK1(TheOutputTestBuf[2] == CEditableText::EParagraphDelimiter);
   1.422 +		CHECK1(TheOutputTestBuf[3] == CEditableText::EParagraphDelimiter);
   1.423 +		CHECK1(TheOutputTestBuf[4] == CEditableText::EParagraphDelimiter);
   1.424 +		CHECK1(TheOutputTestBuf[5] == 'z');
   1.425 +		CHECK1(TheOutputTestBuf[6] == CEditableText::EParagraphDelimiter);
   1.426 +
   1.427 +		testBuf = _L("This\xDIs\xATest\xD\xAMessage");
   1.428 +		TheOutputTestBuf.Zero();
   1.429 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.430 +		CHECK1(TheOutputTestBuf.Length() == 20);
   1.431 +		CHECK1(TheOutputTestBuf[4] == CEditableText::EParagraphDelimiter);
   1.432 +		CHECK1(TheOutputTestBuf[7] == CEditableText::EParagraphDelimiter);
   1.433 +		CHECK1(TheOutputTestBuf[12] == CEditableText::EParagraphDelimiter);
   1.434 +		}
   1.435 +
   1.436 +   	INFO_PRINTF1(_L("INC055971L - OrganiseByLine test"));
   1.437 +
   1.438 +		{
   1.439 +		TLineTextWriter lineTextWriter(outputChar);
   1.440 +		TSLBTransaltor slbTranslator(lineTextWriter);
   1.441 +
   1.442 +		testBuf = _L("\xD");
   1.443 +		TheOutputTestBuf.Zero();
   1.444 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.445 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.446 +		CHECK1(TheOutputTestBuf[0] == ' ');
   1.447 +
   1.448 +		testBuf = _L("\xA");
   1.449 +		TheOutputTestBuf.Zero();
   1.450 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.451 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.452 +		CHECK1(TheOutputTestBuf[0] == ' ');
   1.453 +
   1.454 +		testBuf = _L("\xD\xA");
   1.455 +		TheOutputTestBuf.Zero();
   1.456 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.457 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.458 +		CHECK1(TheOutputTestBuf[0] == ' ');
   1.459 +
   1.460 +		testBuf = _L("\xD\xA\xD\xA");
   1.461 +		TheOutputTestBuf.Zero();
   1.462 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.463 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.464 +		CHECK1(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
   1.465 +
   1.466 +		testBuf = _L("\xD\xD");
   1.467 +		TheOutputTestBuf.Zero();
   1.468 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.469 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.470 +		CHECK1(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
   1.471 +
   1.472 +		testBuf = _L("\xA\xA");
   1.473 +		TheOutputTestBuf.Zero();
   1.474 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.475 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.476 +		CHECK1(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
   1.477 +
   1.478 +		testBuf = _L("\xA\xD");
   1.479 +		TheOutputTestBuf.Zero();
   1.480 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.481 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.482 +		CHECK1(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
   1.483 +
   1.484 +		testBuf = _L("\xD\xA\xA");
   1.485 +		TheOutputTestBuf.Zero();
   1.486 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.487 +		CHECK1(TheOutputTestBuf.Length() == 1);
   1.488 +		CHECK1(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
   1.489 +
   1.490 +		testBuf = _L("\xD\xAz\xAzz\xA\xD");
   1.491 +		TheOutputTestBuf.Zero();
   1.492 +		::TranslateToEofTestL(slbTranslator, testBuf);
   1.493 +		CHECK1(TheOutputTestBuf.Length() == 6);
   1.494 +		CHECK1(TheOutputTestBuf[0] == ' ');
   1.495 +		CHECK1(TheOutputTestBuf[1] == 'z');
   1.496 +		CHECK1(TheOutputTestBuf[2] == ' ');
   1.497 +		CHECK1(TheOutputTestBuf[3] == 'z');
   1.498 +		CHECK1(TheOutputTestBuf[4] == 'z');
   1.499 +		CHECK1(TheOutputTestBuf[5] == CEditableText::EParagraphDelimiter);
   1.500 +		}
   1.501 +	}
   1.502 +
   1.503 +/**
   1.504 +@SYMTestCaseID SYSLIB-ETEXT-CT-3346
   1.505 +@SYMTestCaseDesc Tests the fix for the problem where EOD character was not getting
   1.506 +formatted when ApplyCharFormatL() function called, caused text to appear clipped on 
   1.507 +MOAP devices.
   1.508 +@SYMTestPriority High
   1.509 +@SYMTestActions Create CRichText object and insert some text.  Apply font and size
   1.510 +formatting to entire text.  Check that EOD character formatting is consistant with rest
   1.511 +of the text formatting.
   1.512 +@SYMTestExpectedResults Formatting for EOD character should be the same as the rest of
   1.513 +the text formatting.
   1.514 +@SYMDEF INC097216: When font size is set as small, bottom of a text is clipped on wk38 (MOAP)
   1.515 +*/
   1.516 +LOCAL_C void INC097216L()
   1.517 +	{
   1.518 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-CT-3346 INC097216L - Test EOD character is formatted with rest of text "));
   1.519 +	
   1.520 +	__UHEAP_MARK;
   1.521 +
   1.522 +    CParaFormatLayer* paraLayer=CParaFormatLayer::NewL();
   1.523 +    CCharFormatLayer* charLayer=CCharFormatLayer::NewL();
   1.524 +    CRichText* richText = CRichText::NewL(paraLayer,charLayer);
   1.525 +	
   1.526 +	_LIT(KTestText, "The quick brown fox jumped over the lazy dog");
   1.527 +	
   1.528 +	richText->InsertL(0, KTestText);
   1.529 +	TCharFormat charFormat(_L("Times"), 100);
   1.530 +	TCharFormatMask formatMask;
   1.531 +	
   1.532 +	formatMask.SetAttrib(EAttFontHeight);
   1.533 +	
   1.534 +	TInt textLength = richText->DocumentLength();
   1.535 +	richText->ApplyCharFormatL(charFormat, formatMask, 0, textLength); 			
   1.536 +	
   1.537 +	richText->GetCharFormat(charFormat, formatMask, textLength-1, 1); // get format info for last text character
   1.538 +	TInt characterFontHeight = charFormat.iFontSpec.iHeight; 
   1.539 +	
   1.540 +	richText->GetCharFormat(charFormat, formatMask, textLength, 1); // get format info for EOD character
   1.541 +	TInt EodFontHeight = charFormat.iFontSpec.iHeight;	
   1.542 +	
   1.543 +	CHECK1(characterFontHeight == EodFontHeight);
   1.544 +	
   1.545 +	delete paraLayer; paraLayer = NULL;
   1.546 +	delete charLayer; charLayer = NULL;
   1.547 +	delete richText; richText = NULL;	
   1.548 +	
   1.549 +	__UHEAP_MARKEND;	
   1.550 +	}
   1.551 +	
   1.552 +/**
   1.553 +@SYMTestCaseID SYSLIB-ETEXT-CT-3386
   1.554 +@SYMTestCaseDesc Tests the fix INC101996:CEikRichTextEditor control don’t support anti-aliasing font 
   1.555 +@SYMTestPriority High
   1.556 +@SYMTestActions Create CRichText object and insert some text.  Apply  formatting to entire string 
   1.557 +				then apply antialiasing formatting to part of the string.
   1.558 +				Ensure that the anti-aliasing formatting information is applied as expected.
   1.559 +@SYMTestExpectedResults Antialiasing formatting should be applied to the correct part of the string
   1.560 + 				and the rest of the string should remain unchanged 
   1.561 +@SYMDEF INC101996
   1.562 +*/
   1.563 +LOCAL_C void INC101996L()
   1.564 +	{
   1.565 +	INFO_PRINTF1(_L("@SYMTestCaseID:SYSLIB-ETEXT-CT-3386 INC101996 CEikRichTextEditor control don't support anti-aliasing font"));
   1.566 +
   1.567 +	__UHEAP_MARK;
   1.568 +
   1.569 +    CParaFormatLayer* paraLayer=CParaFormatLayer::NewL();
   1.570 +    CCharFormatLayer* charLayer=CCharFormatLayer::NewL();
   1.571 +    CRichText* richText = CRichText::NewL(paraLayer,charLayer);
   1.572 +	
   1.573 +	_LIT(KTestText, "The quick brown fox jumped over the lazy dog");
   1.574 +	_LIT(KDefaulFormattedText, "The quick brown fox ju");
   1.575 +	_LIT(KAntiAliasedText, "mped over the lazy dog\x2029");
   1.576 +	
   1.577 +	//insert the test text into the string
   1.578 +	richText->InsertL(0, KTestText);
   1.579 +	
   1.580 +	TCharFormat defaultCharFormat(_L("Times"), 100);
   1.581 +	TCharFormat antiAliasedCharFormat(_L("Times"), 100);
   1.582 +	
   1.583 +	//Set up antiAliasedCharFormat to allow anti-aliasing 
   1.584 +	antiAliasedCharFormat.iFontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
   1.585 +	
   1.586 +	TCharFormatMask formatMask;
   1.587 +	formatMask.SetAttrib(EAttFontTypeface);
   1.588 +	
   1.589 +	//Format the entire string using default formatting
   1.590 +	TInt textLength = richText->DocumentLength();
   1.591 +	richText->ApplyCharFormatL(defaultCharFormat, formatMask, 0, textLength); 
   1.592 +	
   1.593 +	//Change the formatting of the second half of the string to anti-aliased
   1.594 +	TInt halfLength = textLength/2;	
   1.595 +	richText->ApplyCharFormatL(antiAliasedCharFormat, formatMask, halfLength, halfLength);
   1.596 +	
   1.597 +	//Get the string portion with default formatting
   1.598 +	TPtrC defaultString;
   1.599 +	richText->GetChars(defaultString, defaultCharFormat,0);
   1.600 +	
   1.601 +	TGlyphBitmapType startBitmapType = defaultCharFormat.iFontSpec.iFontStyle.BitmapType(); 
   1.602 +	
   1.603 +	//Verify the formatting and the contents of the string
   1.604 +	CHECK2(startBitmapType, EDefaultGlyphBitmap);
   1.605 +	CHECK1(defaultString == KDefaulFormattedText);
   1.606 +		
   1.607 +	//Get the string portion with antialiased formatting
   1.608 +	TPtrC antialiasedString;
   1.609 +	richText->GetChars(antialiasedString, antiAliasedCharFormat,halfLength);		
   1.610 +
   1.611 +	TGlyphBitmapType endBitmapType = antiAliasedCharFormat.iFontSpec.iFontStyle.BitmapType(); 	
   1.612 +	
   1.613 +	//Verify the formatting and the contents of the string
   1.614 +	CHECK2(endBitmapType,EAntiAliasedGlyphBitmap);
   1.615 +	CHECK1(antialiasedString == KAntiAliasedText);
   1.616 +	
   1.617 +	delete paraLayer; paraLayer = NULL;
   1.618 +	delete charLayer; charLayer = NULL;
   1.619 +	delete richText; richText = NULL;	
   1.620 +	
   1.621 +	__UHEAP_MARKEND;	
   1.622 +	}		
   1.623 +
   1.624 +	
   1.625 +/***
   1.626 +Invoke the tests
   1.627 +*/
   1.628 +LOCAL_C void DoTestsL()
   1.629 +	{
   1.630 +	__UHEAP_MARK;
   1.631 +		
   1.632 +	OOM049456L();
   1.633 +	Inc051360L();
   1.634 +	OOM051360L();
   1.635 +    OOM056552L();
   1.636 +	INC055971L();
   1.637 +	INC097216L();
   1.638 +	INC101996L();
   1.639 +	
   1.640 +	__UHEAP_MARKEND;	
   1.641 +   	}
   1.642 +
   1.643 +CTEtextDefect::CTEtextDefect()
   1.644 +    {
   1.645 +    SetTestStepName(KTestStep_TEtextDefect);
   1.646 +    pTestStep = this;
   1.647 +    }
   1.648 +
   1.649 +TVerdict CTEtextDefect::doTestStepL()
   1.650 +    {
   1.651 +    SetTestStepResult(EFail);
   1.652 +
   1.653 +    CTrapCleanup* trapCleanup=CTrapCleanup::New();
   1.654 +   
   1.655 +    INFO_PRINTF1(KTestName);
   1.656 +    TRAPD(error, DoTestsL());
   1.657 +
   1.658 +    delete trapCleanup;
   1.659 +
   1.660 +    if (error == KErrNone)
   1.661 +        {
   1.662 +        SetTestStepResult(EPass);
   1.663 +        }
   1.664 +
   1.665 +    return TestStepResult();
   1.666 +    }