textrendering/texthandling/ttext/TEtextDefect.cpp
changeset 32 8b9155204a54
parent 0 1fb32624e06b
child 51 a7c938434754
equal deleted inserted replaced
31:b9ad20498fb4 32:8b9155204a54
       
     1 /*
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32test.h>
       
    20 #include <charconv.h>
       
    21 #include <gdi.h>
       
    22 #include <conpics.h>
       
    23 #include <txtrich.h>
       
    24 #include <apadef.h>
       
    25 
       
    26 #include "TXTPLAIN.H"
       
    27 #include "TxtWriter.h"
       
    28 
       
    29 //Used for supressing warning in OOM tests
       
    30  #define __UNUSED_VAR(var) var = var
       
    31 
       
    32 // this fixes a MSVC link warning
       
    33 #ifdef __VC32__
       
    34 #pragma comment (linker, "/opt:noref") 
       
    35 #endif
       
    36 
       
    37 _LIT(KTestName, "Start of Tests...");
       
    38 RTest theTest(KTestName);
       
    39 
       
    40 ///////////////////////////////////////////////////////////////////////////////////////
       
    41 ///////////////////////////////////////////////////////////////////////////////////////
       
    42 //Test macroses and functions
       
    43 LOCAL_C void Check(TInt aValue, TInt aLine)
       
    44 	{
       
    45 	if(!aValue)
       
    46 		{
       
    47 		theTest(EFalse, aLine);
       
    48 		}
       
    49 	}
       
    50 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
       
    51 	{
       
    52 	if(aValue != aExpected)
       
    53 		{
       
    54 		theTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    55 		theTest(EFalse, aLine);
       
    56 		}
       
    57 	}
       
    58 #define TEST(arg) ::Check((arg), __LINE__)
       
    59 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    60 
       
    61 
       
    62 LOCAL_C void Inc049456L()
       
    63 	{
       
    64    	theTest.Next(_L("Inc049456L"));
       
    65 
       
    66 	CPlainTextConverter* converter = CPlainTextConverter::NewLC();
       
    67 	CleanupStack::PopAndDestroy(converter);
       
    68 	}
       
    69 	
       
    70 LOCAL_C void OOM049456L()
       
    71 	{
       
    72    	theTest.Next(_L("OOM049456L"));
       
    73 
       
    74 	TInt tryCount=0;
       
    75  	TInt error = KErrNone;
       
    76  	__UNUSED_VAR(tryCount);
       
    77  	
       
    78  	do
       
    79  		{
       
    80  		__UHEAP_MARK;
       
    81  
       
    82  		// find out the number of open handles
       
    83  		TInt startProcessHandleCount;
       
    84  		TInt startThreadHandleCount;
       
    85  		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
    86  		
       
    87  		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
    88  	
       
    89  		TRAP(error,Inc049456L()); 	
       
    90  								
       
    91  		__UHEAP_SETFAIL(RHeap::ENone,0);
       
    92  		
       
    93  		// check that no handles have leaked
       
    94  		TInt endProcessHandleCount;
       
    95  		TInt endThreadHandleCount;
       
    96  		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
    97  
       
    98  		TEST(startProcessHandleCount == endProcessHandleCount);
       
    99  		TEST(startThreadHandleCount  == endThreadHandleCount);
       
   100  				
       
   101  		__UHEAP_MARKEND;
       
   102  		
       
   103  		}while(error==KErrNoMemory);
       
   104  		
       
   105  	TEST2(error, KErrNone);
       
   106  	theTest.Printf(_L("- server succeeded at heap failure rate of %i\n"),tryCount);		
       
   107 	}
       
   108 
       
   109 
       
   110 
       
   111 
       
   112 LOCAL_C void Inc051360L()
       
   113 	{
       
   114    	theTest.Next(_L("Inc051360L"));
       
   115    	
       
   116 	// Test data to force a remainder of 2 from the charconv unicode conversion.
       
   117 	// The etext buffer is 1024 bytes that truncates the last utf-8 character.
       
   118 	// It needs three bytes but only has two, hence remainder 2.
       
   119 	const TUint8 KUtf8TextJapanese [] = 
       
   120 	{
       
   121 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   122 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   123 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   124 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   125 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   126 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   127 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   128 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   129 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   130 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   131 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   132 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   133 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   134 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   135 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   136 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   137 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   138 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   139 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   140 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   141 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   142 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   143 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   144 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   145 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   146 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   147 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   148 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   149 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   150 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   151 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   152 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   153 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   154 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   155 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   156 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   157 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   158 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   159 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   160 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   161 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   162 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   163 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   164 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   165 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   166 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   167 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   168 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   169 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
       
   170 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // 1000 bytes
       
   171 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // 1020
       
   172 	0x20, 0x20, 0xE3, 0x81, 0x82, 0xE3, 0x81, 0x8B, // total 1028
       
   173 	}; //                   ^ 1025, will not be read on first pass
       
   174 	
       
   175 	// Need to know the data length for our buffers.
       
   176 	const TUint KBufferSize = 1028;
       
   177 
       
   178 	// Copy the raw data into an 8-bit descriptor
       
   179 	TBuf8<KBufferSize> textBuffer;
       
   180 	textBuffer.Copy (KUtf8TextJapanese, KBufferSize);
       
   181 
       
   182 	// The unicode conversion of the result expected
       
   183 	const TUint16 KUnicodeTextJapaneseResult [] = {0x3042, 0x304B,};
       
   184 
       
   185 	TBuf16 <2> unicodeConversion;
       
   186 	unicodeConversion.Copy (KUnicodeTextJapaneseResult, 2);
       
   187 		
       
   188 	// The converter
       
   189 	CPlainTextConverter* plainText = CPlainTextConverter::NewLC();
       
   190 
       
   191 	// The input buffer
       
   192 	CBufFlat* inbuffer = CBufFlat::NewL(KBufferSize);
       
   193 	CleanupStack::PushL (inbuffer);
       
   194 	
       
   195 	inbuffer->InsertL (0, textBuffer);
       
   196 	
       
   197 	// The input stream
       
   198 	RBufReadStream inputStr (*inbuffer, 0);
       
   199 	CleanupClosePushL (inputStr);
       
   200 
       
   201 	// The output buffer
       
   202 	CBufFlat* outbuffer = CBufFlat::NewL(KBufferSize);
       
   203 	CleanupStack::PushL (outbuffer);
       
   204 	
       
   205 	// The output stream
       
   206 	RBufWriteStream outputStr (*outbuffer, 0);
       
   207 	CleanupClosePushL (outputStr);
       
   208 	
       
   209 	// Input specifications
       
   210 	CPlainText::TImportExportParam param;
       
   211 	param.iOutputInternal  = TRUE; // force output to internal format
       
   212 	param.iForeignEncoding = KCharacterSetIdentifierUtf8;
       
   213 	
       
   214 	// The result of the operation
       
   215 	CPlainText::TImportExportResult result;
       
   216 	
       
   217 	// Translate the data
       
   218 	TPlainTextReader::TranslateL(param, result, outputStr, inputStr);
       
   219 	
       
   220 	// Get the 8-bit data into a 16-bit buffer.
       
   221 	// Can't use Copy as this will store each byte on a word boundary!
       
   222 	TPtr8 ptr8 (outbuffer->Ptr(outbuffer->Size()-4));
       
   223 	const TUint16* ptr = (TUint16*) (ptr8.Ptr());
       
   224 	TPtrC16 des16 (ptr, 2);
       
   225 
       
   226 	TEST(unicodeConversion == des16);
       
   227 	
       
   228 	CleanupStack::PopAndDestroy (&outputStr);	
       
   229 	CleanupStack::PopAndDestroy (outbuffer);	
       
   230 	CleanupStack::PopAndDestroy (&inputStr);	
       
   231 	CleanupStack::PopAndDestroy (inbuffer);	
       
   232 	CleanupStack::PopAndDestroy (plainText);
       
   233 	}
       
   234 	
       
   235 LOCAL_C void OOM051360L()
       
   236 	{
       
   237    	theTest.Next(_L("OOM051360L"));
       
   238 
       
   239 	TInt tryCount=0;
       
   240  	TInt error = KErrNone;
       
   241  	__UNUSED_VAR(tryCount);
       
   242  	
       
   243  	do
       
   244  		{
       
   245  		__UHEAP_MARK;
       
   246  
       
   247  		// find out the number of open handles
       
   248  		TInt startProcessHandleCount;
       
   249  		TInt startThreadHandleCount;
       
   250  		RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
       
   251  		
       
   252  		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   253  	
       
   254  		TRAP(error,Inc051360L()); 	
       
   255  								
       
   256  		__UHEAP_SETFAIL(RHeap::ENone,0);
       
   257  		
       
   258  		// check that no handles have leaked
       
   259  		TInt endProcessHandleCount;
       
   260  		TInt endThreadHandleCount;
       
   261  		RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
   262  
       
   263  		TEST(startProcessHandleCount == endProcessHandleCount);
       
   264  		TEST(startThreadHandleCount  == endThreadHandleCount);
       
   265  				
       
   266  		__UHEAP_MARKEND;
       
   267  		
       
   268  		}while(error==KErrNoMemory);
       
   269  		
       
   270  	TEST2(error, KErrNone);
       
   271  	theTest.Printf(_L("- server succeeded at heap failure rate of %i\n"),tryCount);		
       
   272 	}
       
   273 	
       
   274 LOCAL_C void OOM056552L()
       
   275 	{
       
   276 	theTest.Next(_L("OOM056552L"));
       
   277 
       
   278 	TInt tryCount=0;
       
   279  	TInt error = KErrNone;
       
   280  	__UNUSED_VAR(tryCount);
       
   281  	
       
   282  	do
       
   283  		{
       
   284  		__UHEAP_MARK;
       
   285  	
       
   286  	    CParaFormatLayer* paraLayer=CParaFormatLayer::NewL();
       
   287 	    CCharFormatLayer* charLayer=CCharFormatLayer::NewL();
       
   288    	    CRichText* richText = CRichText::NewL(paraLayer,charLayer);
       
   289    	    CXzePicture* pic=CXzePicture::NewL('x');
       
   290    	    TPictureHeader header;
       
   291    	    header.iPictureType = KUidPictureTypeDoor;
       
   292    	    header.iPicture=pic;
       
   293  		
       
   294  		__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
       
   295  	
       
   296  		TRAP(error,	richText->InsertL(richText->DocumentLength(), header)); 	
       
   297  								
       
   298  		__UHEAP_SETFAIL(RHeap::ENone,0);
       
   299  		
       
   300  		delete paraLayer; paraLayer = NULL;
       
   301  		delete charLayer; charLayer = NULL;
       
   302  		delete richText; richText = NULL;	
       
   303  		
       
   304  		__UHEAP_MARKEND;
       
   305  		
       
   306  		}while(error==KErrNoMemory);
       
   307  		
       
   308  	theTest(error==KErrNone);
       
   309  	theTest.Printf(_L("	richText->InsertL - succeeded at heap failure rate of %i\n"),tryCount);	
       
   310 	}
       
   311 /////////////////////////////////////////////////////////////////////////////////////////////////
       
   312 // Testing the fix for
       
   313 // "INC055971  NTT - Received MMS with line break "CR" set does not cause line feed."
       
   314 // In order to make the testing easier, MOutputChar, MTextWriter, TSLBTransaltor, 
       
   315 // TParagraphTextWriter, TLineTextWriter production classes are used outside their environment.
       
   316 // TOutputChar test class implements MOutputChar interface. It is used to collect the character
       
   317 // output from the processing of the imput character sequences. Then, the output is tested against
       
   318 // the expected set of output characters.
       
   319 //
       
   320 // The follwing translation rules are tested:
       
   321 // 1) Organising by paragraph
       
   322 //    - 0x0D      - line break;
       
   323 //    - 0x0A      - line break;
       
   324 //    - 0x0D 0x0A - line break;
       
   325 // 2) Organising by line
       
   326 //    - single line break - space;
       
   327 //    - double line break - paragraph delimiter;
       
   328 
       
   329 TBuf<32> TheOutputTestBuf;//Here the output is collected and then asserted
       
   330 
       
   331 class TOutputChar : public MOutputChar
       
   332 	{
       
   333 public:
       
   334 	virtual void OutputCharL(TText aChar)
       
   335 		{
       
   336 		TheOutputTestBuf.Append(aChar);
       
   337 		}
       
   338 	};
       
   339 
       
   340 static void TranslateToEofTestL(TSLBTransaltor& aSLBTranslator, const TDesC& aTestBuf)
       
   341 	{
       
   342 	for(TInt i=0;i<aTestBuf.Length();++i)
       
   343 		{
       
   344 		TText c = aTestBuf[i];
       
   345 		aSLBTranslator.ProcessL(c);
       
   346 		}
       
   347 	aSLBTranslator.FlushL();
       
   348 	}
       
   349 
       
   350 static void INC055971L()
       
   351 	{
       
   352 	TBuf<32> testBuf;
       
   353 	TOutputChar outputChar;
       
   354 
       
   355    	theTest.Next(_L("INC055971L - OrganiseByParagraph test"));
       
   356 
       
   357 		{
       
   358 		TParagraphTextWriter paragraphTextWriter(outputChar);
       
   359 		TSLBTransaltor slbTranslator(paragraphTextWriter);
       
   360 
       
   361 		testBuf = _L("\xD");
       
   362 		TheOutputTestBuf.Zero();
       
   363 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   364 		TEST(TheOutputTestBuf.Length() == 1);
       
   365 		TEST(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
       
   366 
       
   367 		testBuf = _L("\xA");
       
   368 		TheOutputTestBuf.Zero();
       
   369 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   370 		TEST(TheOutputTestBuf.Length() == 1);
       
   371 		TEST(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
       
   372 
       
   373 		testBuf = _L("\xD\xA");
       
   374 		TheOutputTestBuf.Zero();
       
   375 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   376 		TEST(TheOutputTestBuf.Length() == 1);
       
   377 		TEST(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
       
   378 
       
   379 		testBuf = _L("zz\xD\xA\xD\xA\xAz\xD");
       
   380 		TheOutputTestBuf.Zero();
       
   381 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   382 		TEST(TheOutputTestBuf.Length() == 7);
       
   383 		TEST(TheOutputTestBuf[0] == 'z');
       
   384 		TEST(TheOutputTestBuf[1] == 'z');
       
   385 		TEST(TheOutputTestBuf[2] == CEditableText::EParagraphDelimiter);
       
   386 		TEST(TheOutputTestBuf[3] == CEditableText::EParagraphDelimiter);
       
   387 		TEST(TheOutputTestBuf[4] == CEditableText::EParagraphDelimiter);
       
   388 		TEST(TheOutputTestBuf[5] == 'z');
       
   389 		TEST(TheOutputTestBuf[6] == CEditableText::EParagraphDelimiter);
       
   390 
       
   391 		testBuf = _L("This\xDIs\xATest\xD\xAMessage");
       
   392 		TheOutputTestBuf.Zero();
       
   393 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   394 		TEST(TheOutputTestBuf.Length() == 20);
       
   395 		TEST(TheOutputTestBuf[4] == CEditableText::EParagraphDelimiter);
       
   396 		TEST(TheOutputTestBuf[7] == CEditableText::EParagraphDelimiter);
       
   397 		TEST(TheOutputTestBuf[12] == CEditableText::EParagraphDelimiter);
       
   398 		}
       
   399 
       
   400    	theTest.Next(_L("INC055971L - OrganiseByLine test"));
       
   401 
       
   402 		{
       
   403 		TLineTextWriter lineTextWriter(outputChar);
       
   404 		TSLBTransaltor slbTranslator(lineTextWriter);
       
   405 
       
   406 		testBuf = _L("\xD");
       
   407 		TheOutputTestBuf.Zero();
       
   408 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   409 		TEST(TheOutputTestBuf.Length() == 1);
       
   410 		TEST(TheOutputTestBuf[0] == ' ');
       
   411 
       
   412 		testBuf = _L("\xA");
       
   413 		TheOutputTestBuf.Zero();
       
   414 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   415 		TEST(TheOutputTestBuf.Length() == 1);
       
   416 		TEST(TheOutputTestBuf[0] == ' ');
       
   417 
       
   418 		testBuf = _L("\xD\xA");
       
   419 		TheOutputTestBuf.Zero();
       
   420 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   421 		TEST(TheOutputTestBuf.Length() == 1);
       
   422 		TEST(TheOutputTestBuf[0] == ' ');
       
   423 
       
   424 		testBuf = _L("\xD\xA\xD\xA");
       
   425 		TheOutputTestBuf.Zero();
       
   426 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   427 		TEST(TheOutputTestBuf.Length() == 1);
       
   428 		TEST(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
       
   429 
       
   430 		testBuf = _L("\xD\xD");
       
   431 		TheOutputTestBuf.Zero();
       
   432 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   433 		TEST(TheOutputTestBuf.Length() == 1);
       
   434 		TEST(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
       
   435 
       
   436 		testBuf = _L("\xA\xA");
       
   437 		TheOutputTestBuf.Zero();
       
   438 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   439 		TEST(TheOutputTestBuf.Length() == 1);
       
   440 		TEST(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
       
   441 
       
   442 		testBuf = _L("\xA\xD");
       
   443 		TheOutputTestBuf.Zero();
       
   444 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   445 		TEST(TheOutputTestBuf.Length() == 1);
       
   446 		TEST(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
       
   447 
       
   448 		testBuf = _L("\xD\xA\xA");
       
   449 		TheOutputTestBuf.Zero();
       
   450 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   451 		TEST(TheOutputTestBuf.Length() == 1);
       
   452 		TEST(TheOutputTestBuf[0] == CEditableText::EParagraphDelimiter);
       
   453 
       
   454 		testBuf = _L("\xD\xAz\xAzz\xA\xD");
       
   455 		TheOutputTestBuf.Zero();
       
   456 		::TranslateToEofTestL(slbTranslator, testBuf);
       
   457 		TEST(TheOutputTestBuf.Length() == 6);
       
   458 		TEST(TheOutputTestBuf[0] == ' ');
       
   459 		TEST(TheOutputTestBuf[1] == 'z');
       
   460 		TEST(TheOutputTestBuf[2] == ' ');
       
   461 		TEST(TheOutputTestBuf[3] == 'z');
       
   462 		TEST(TheOutputTestBuf[4] == 'z');
       
   463 		TEST(TheOutputTestBuf[5] == CEditableText::EParagraphDelimiter);
       
   464 		}
       
   465 	}
       
   466 
       
   467 /**
       
   468 @SYMTestCaseID SYSLIB-ETEXT-CT-3346
       
   469 @SYMTestCaseDesc Tests the fix for the problem where EOD character was not getting
       
   470 formatted when ApplyCharFormatL() function called, caused text to appear clipped on 
       
   471 MOAP devices.
       
   472 @SYMTestPriority High
       
   473 @SYMTestActions Create CRichText object and insert some text.  Apply font and size
       
   474 formatting to entire text.  Check that EOD character formatting is consistant with rest
       
   475 of the text formatting.
       
   476 @SYMTestExpectedResults Formatting for EOD character should be the same as the rest of
       
   477 the text formatting.
       
   478 @SYMDEF INC097216: When font size is set as small, bottom of a text is clipped on wk38 (MOAP)
       
   479 */
       
   480 LOCAL_C void INC097216L()
       
   481 	{
       
   482 	theTest.Next(_L(" @SYMTestCaseID:SYSLIB-ETEXT-CT-3346 INC097216L - Test EOD character is formatted with rest of text "));
       
   483 	
       
   484 	__UHEAP_MARK;
       
   485 
       
   486     CParaFormatLayer* paraLayer=CParaFormatLayer::NewL();
       
   487     CCharFormatLayer* charLayer=CCharFormatLayer::NewL();
       
   488     CRichText* richText = CRichText::NewL(paraLayer,charLayer);
       
   489 	
       
   490 	_LIT(KTestText, "The quick brown fox jumped over the lazy dog");
       
   491 	
       
   492 	richText->InsertL(0, KTestText);
       
   493 	TCharFormat charFormat(_L("Times"), 100);
       
   494 	TCharFormatMask formatMask;
       
   495 	
       
   496 	formatMask.SetAttrib(EAttFontHeight);
       
   497 	
       
   498 	TInt textLength = richText->DocumentLength();
       
   499 	richText->ApplyCharFormatL(charFormat, formatMask, 0, textLength); 			
       
   500 	
       
   501 	richText->GetCharFormat(charFormat, formatMask, textLength-1, 1); // get format info for last text character
       
   502 	TInt characterFontHeight = charFormat.iFontSpec.iHeight; 
       
   503 	
       
   504 	richText->GetCharFormat(charFormat, formatMask, textLength, 1); // get format info for EOD character
       
   505 	TInt EodFontHeight = charFormat.iFontSpec.iHeight;	
       
   506 	
       
   507 	TEST(characterFontHeight == EodFontHeight);
       
   508 	
       
   509 	delete paraLayer; paraLayer = NULL;
       
   510 	delete charLayer; charLayer = NULL;
       
   511 	delete richText; richText = NULL;	
       
   512 	
       
   513 	__UHEAP_MARKEND;	
       
   514 	}
       
   515 	
       
   516 /**
       
   517 @SYMTestCaseID SYSLIB-ETEXT-CT-3386
       
   518 @SYMTestCaseDesc Tests the fix INC101996:CEikRichTextEditor control don’t support anti-aliasing font 
       
   519 @SYMTestPriority High
       
   520 @SYMTestActions Create CRichText object and insert some text.  Apply  formatting to entire string 
       
   521 				then apply antialiasing formatting to part of the string.
       
   522 				Ensure that the anti-aliasing formatting information is applied as expected.
       
   523 @SYMTestExpectedResults Antialiasing formatting should be applied to the correct part of the string
       
   524  				and the rest of the string should remain unchanged 
       
   525 @SYMDEF INC101996
       
   526 */
       
   527 LOCAL_C void INC101996L()
       
   528 	{
       
   529 	theTest.Next(_L("@SYMTestCaseID:SYSLIB-ETEXT-CT-3386 INC101996 CEikRichTextEditor control don't support anti-aliasing font"));
       
   530 
       
   531 	__UHEAP_MARK;
       
   532 
       
   533     CParaFormatLayer* paraLayer=CParaFormatLayer::NewL();
       
   534     CCharFormatLayer* charLayer=CCharFormatLayer::NewL();
       
   535     CRichText* richText = CRichText::NewL(paraLayer,charLayer);
       
   536 	
       
   537 	_LIT(KTestText, "The quick brown fox jumped over the lazy dog");
       
   538 	_LIT(KDefaulFormattedText, "The quick brown fox ju");
       
   539 	_LIT(KAntiAliasedText, "mped over the lazy dog\x2029");
       
   540 	
       
   541 	//insert the test text into the string
       
   542 	richText->InsertL(0, KTestText);
       
   543 	
       
   544 	TCharFormat defaultCharFormat(_L("Times"), 100);
       
   545 	TCharFormat antiAliasedCharFormat(_L("Times"), 100);
       
   546 	
       
   547 	//Set up antiAliasedCharFormat to allow anti-aliasing 
       
   548 	antiAliasedCharFormat.iFontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
       
   549 	
       
   550 	TCharFormatMask formatMask;
       
   551 	formatMask.SetAttrib(EAttFontTypeface);
       
   552 	
       
   553 	//Format the entire string using default formatting
       
   554 	TInt textLength = richText->DocumentLength();
       
   555 	richText->ApplyCharFormatL(defaultCharFormat, formatMask, 0, textLength); 
       
   556 	
       
   557 	//Change the formatting of the second half of the string to anti-aliased
       
   558 	TInt halfLength = textLength/2;	
       
   559 	richText->ApplyCharFormatL(antiAliasedCharFormat, formatMask, halfLength, halfLength);
       
   560 	
       
   561 	//Get the string portion with default formatting
       
   562 	TPtrC defaultString;
       
   563 	richText->GetChars(defaultString, defaultCharFormat,0);
       
   564 	
       
   565 	TGlyphBitmapType startBitmapType = defaultCharFormat.iFontSpec.iFontStyle.BitmapType(); 
       
   566 	
       
   567 	//Verify the formatting and the contents of the string
       
   568 	TEST2(startBitmapType, EDefaultGlyphBitmap);
       
   569 	TEST(defaultString == KDefaulFormattedText);
       
   570 		
       
   571 	//Get the string portion with antialiased formatting
       
   572 	TPtrC antialiasedString;
       
   573 	richText->GetChars(antialiasedString, antiAliasedCharFormat,halfLength);		
       
   574 
       
   575 	TGlyphBitmapType endBitmapType = antiAliasedCharFormat.iFontSpec.iFontStyle.BitmapType(); 	
       
   576 	
       
   577 	//Verify the formatting and the contents of the string
       
   578 	TEST2(endBitmapType,EAntiAliasedGlyphBitmap);
       
   579 	TEST(antialiasedString == KAntiAliasedText);
       
   580 	
       
   581 	delete paraLayer; paraLayer = NULL;
       
   582 	delete charLayer; charLayer = NULL;
       
   583 	delete richText; richText = NULL;	
       
   584 	
       
   585 	__UHEAP_MARKEND;	
       
   586 	}		
       
   587 
       
   588 	
       
   589 /***
       
   590 Invoke the tests
       
   591 */
       
   592 LOCAL_C void DoTestsL()
       
   593 	{
       
   594 	__UHEAP_MARK;
       
   595 		
       
   596 	OOM049456L();
       
   597 	Inc051360L();
       
   598 	OOM051360L();
       
   599     OOM056552L();
       
   600 	INC055971L();
       
   601 	INC097216L();
       
   602 	INC101996L();
       
   603 	
       
   604 	__UHEAP_MARKEND;	
       
   605    	}
       
   606    
       
   607 /***
       
   608 Main
       
   609 */
       
   610 GLDEF_C TInt E32Main()
       
   611 	{
       
   612    	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
   613    
       
   614    	theTest.Start(KTestName);
       
   615 	TRAPD(error, DoTestsL());
       
   616 	TEST2(error, KErrNone);
       
   617  	
       
   618 	delete trapCleanup;
       
   619  	
       
   620 	theTest.End();
       
   621 	theTest.Close();
       
   622 
       
   623    	return KErrNone;
       
   624    	}
       
   625    	
       
   626    	
       
   627    	
       
   628 
       
   629 
       
   630