os/textandloc/textrendering/textformatting/test/src/TTextView.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2000-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 * TTextView.cpp test file for UndoSystem classes
    16 *
    17 */
    18 
    19 
    20 #include <e32test.h>
    21 
    22 #include <coemain.h>
    23 #include <frmtview.h>
    24 #include <txtrich.h>
    25 #include <conpics.h>
    26 #include <e32math.h>
    27 
    28 #include "form_and_etext_editor.h"
    29 #include "UndoSystem.h"
    30 #include "EditorUndo.h"
    31 #include "FRMPAGE.H"
    32 
    33 _LIT(KHello, "hello world");
    34 const TInt KPaginatePriority = -100;
    35 const TInt KGranularity = 10;
    36 
    37 using namespace UndoSystem;
    38 
    39 LOCAL_C TInt GetNumber(TInt aMin, TInt aMax)
    40 	{
    41 	__ASSERT_ALWAYS(aMin <= aMax, User::Invariant());
    42 
    43 	TInt64 seed = Math::Random();
    44 	TReal randomReal = Math::FRand(seed);
    45 
    46 	TReal maxReal = randomReal * ((aMax-aMin)+1);
    47 	TReal rounded = 0;
    48 	User::LeaveIfError(Math::Round(rounded, maxReal, 0));
    49 
    50 	TInt result = rounded + aMin;
    51 	
    52 	if(result> aMax)
    53 		{
    54 		return aMax;
    55 		}
    56 	return result;
    57 	}
    58 
    59 void ManipulateText(CTextView* aView, CRichText* aText)
    60 	{
    61 	_LIT(KStartText, "The quick brown fox jumped over the lazy dog.");
    62 	aText->InsertL(0, KStartText);
    63 	aView->HandleInsertDeleteL(TCursorSelection(0, KStartText().Length()), 0);
    64 	aText->InsertL(19, TChar(CEditableText::EParagraphDelimiter));
    65 	aView->HandleCharEditL();
    66 	TCharFormat format;
    67 	TCharFormatMask mask;
    68 	format.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
    69 	mask.ClearAll();
    70 	mask.SetAttrib(EAttFontStrokeWeight);
    71 	aText->ApplyCharFormatL(format, mask, 41, 3);
    72 	aView->HandleRangeFormatChangeL(TCursorSelection(41, 44));
    73 	aView->SetDocPosL(42);
    74 	TInt length = aText->DocumentLength();
    75 	aText->DeleteL(0, length);
    76 	aView->HandleInsertDeleteL(TCursorSelection(0, 0), length);
    77 	}
    78 
    79 void ManipulateText1(CTextView* aView, CRichText* aText)
    80 	{
    81 	TInt testaYPos = 0;
    82 	_LIT(KText, "The weather is quite good today, but it's a bit too cold");
    83 	aText->InsertL(0, KText);
    84 	aView->HandleInsertDeleteL(TCursorSelection(0, KText().Length()), 0);
    85 	aView->SetDocPosL(10); //56 is the position of the last character d
    86 	aView->SetViewLineAtTopL(1);
    87 	aView->SetViewL(50, testaYPos);
    88 	aView->HandleAdditionalCharactersAtEndL();
    89 	}
    90 
    91 inline TBool IsSurrogate(TText16 aInt16)
    92 /**
    93 @return True, if aText16 is high surrogate or low surrogate; false, otherwise.
    94 */
    95 	{
    96 	return (aInt16 & 0xF800) == 0xD800;
    97 	}
    98 
    99 class CMyTestPicture : public CPicture
   100 	{
   101 public:
   102 	static CMyTestPicture* NewL(TSize aSize);
   103 	void Draw(CGraphicsContext&,const TPoint&,const TRect&,MGraphicsDeviceMap*) const {}
   104 	void ExternalizeL(RWriteStream& /*aStream*/) const {}
   105 	void GetOriginalSizeInTwips(TSize& aSize) const {aSize=iSizeOfPicture;}
   106 private:
   107 	CMyTestPicture(TSize aSize);
   108 private:
   109 	TSize iSizeOfPicture;
   110 	};
   111 
   112 CMyTestPicture* CMyTestPicture::NewL(TSize aSize)
   113 	{
   114 	return new(ELeave) CMyTestPicture(aSize);
   115 	}
   116 
   117 
   118 CMyTestPicture::CMyTestPicture(TSize aSize):iSizeOfPicture(aSize)
   119 	{}
   120 
   121 
   122 class CTextViewTest : public CBase
   123 	{
   124 public:
   125 	CTextViewTest(CCoeEnv& aEnv)
   126 		: iEnv(aEnv), 	iWindowRect(10, 10, 110, 110), iWindow(aEnv.WsSession()),
   127 		test(_L("TTextView - Some tests for CTextView")) {}
   128 	void ConstructL();
   129 	void InitializeL();
   130 	void AddTextL(const TDesC&);
   131 	void Destroy();
   132 	~CTextViewTest();
   133 	void TestL();
   134 	void Test1L();
   135 	void TestCancelSelectionL();
   136 	void TestHandleAdditionalCharactersAtEndL();
   137 	void TestFinishBackgroundFormattingL();
   138 	void TestSetCursorVisibilityL();
   139 	void TestSetSelectionVisibilityL();
   140 	void TestEnablePictureFrameL();
   141 	void TestSetCursorWidthTypeL();
   142 	void TestParagraphRectL();
   143 	void TestSetDocPosL();
   144 	void TestSetViewLineAtTopL();
   145 	void TestDrawL();
   146 	void TestFormatTextL();
   147 	void TestHandleCharEditL();
   148 	void TestHandleRangeFormatChangeL();
   149 	void TestHandleInsertDeleteL();
   150 	void TestHandleGlobalChangeL();
   151 	void TestHandleGlobalChangeNoRedrawL();
   152 	void TestScrollDisplayL();
   153     void TestScrollDisplayPixelsL();
   154     void TestScrollDisplayPixelsNoLimitBordersL(TInt aOffset);
   155     void TestForDEF142286BounceScrollingL();
   156 	void TestScrollDisplayLinesL();
   157 	void TestScrollDisplayParagraphsL();
   158 	void TestSetViewL();
   159 	void TestMoveCursorL();
   160 	void TestSetSelectionL();
   161 	void TestMatchCursorHeightL();
   162 	void TestCalculateHorizontalExtremesL();
   163 	void TestXyPosToDocPosL();
   164 //	void TestDrawL1();
   165 	void TestGetPictureRectangleL();
   166 	void TestGetPictureRectangle1L();
   167 	void TestSetDisplayContextL();
   168 	void TestGetPictureRectangleDefectL();
   169 	void TestGetLineRectL(); // Test for defect WEP-567K9C Form panics when picture
   170 							 // inserted in CRichText and alignmnent is set to bottom
   171 	void TestForDEF003426L();
   172 	void TestForDEF038488L();
   173 	void InitializeDiffCharFormatL();
   174 	void TestGetParaFormatL();
   175 	// Function to test the Class TFormAndEtextEditor
   176 	void FormAndEtextTestL();
   177 	void TestForINC092725L();
   178 	void TestForPDEF108443L();
   179 	void TestForPDEF113755L();
   180 	void TestForPDEF115165L();
   181 	void TestForPDEF118443L();
   182 	void TestForPDEF121798L();
   183 	void TestForPDEF120239L();
   184 	void TestForDEF124989L();
   185 	void TestForDEF124975L();
   186 	
   187 	struct STestDataTInt4
   188 		{
   189 		TInt iDoc1;
   190 		TInt iDoc2; 
   191 		TInt iPos1;
   192 		TInt iPos2;		
   193 		};
   194 	
   195 private:
   196 	CCoeEnv& iEnv;
   197 	TRect iWindowRect;
   198 	CParaFormatLayer* iParaLayer;
   199 	CCharFormatLayer* iCharLayer;
   200 	CRichText* iEtext;
   201 	CTextLayout* iLayout;
   202 	RWindow iWindow;
   203 	CTextView* iView;
   204 	RTest test;
   205 	TCursorSelection select;
   206 	TInt testDeltaY;
   207 	TInt testDeltaLines;
   208 	TInt testDeltaParas;
   209 	TInt testaYPos;
   210 	TCursorPosition::TMovementType testaMovement;
   211 	TFontSpec testaFontSpec;
   212 	TInt testaLeft;
   213 	TInt testaRight;
   214 	TPoint testaPoint;
   215 	TBool testaCanScaleOrCrop;
   216 	CBitmapContext* testaGc;
   217 	TPoint testaXyPos;
   218 	CBitmapDevice* testaGd;
   219 	RWindowGroup testaGroupWin;
   220 	RWsSession testaSession;
   221 	};
   222 
   223 void CTextViewTest::ConstructL()
   224 	{
   225 	iWindow.Construct(iEnv.RootWin(), 12345);
   226 	iParaLayer = CParaFormatLayer::NewL();
   227 	iCharLayer = CCharFormatLayer::NewL();
   228 	test.Title();
   229 	test.Start(_L("CTextView Tests:"));
   230 	}
   231 
   232 void CTextViewTest::InitializeL()
   233 	{
   234 	Destroy();
   235 	iEtext = CRichText::NewL(iParaLayer, iCharLayer);
   236 	iLayout = CTextLayout::NewL(iEtext, iWindowRect.Width());
   237 	iView = CTextView::NewL(iLayout, iWindowRect, iEnv.ScreenDevice(),
   238 		iEnv.SystemGc().Device(), &iWindow, &iEnv.RootWin(), &iEnv.WsSession());
   239 	testaGd=(CBitmapDevice*) iEnv.SystemGc().Device();
   240 	}
   241 
   242 void CTextViewTest::AddTextL(const TDesC& aText)
   243 	{
   244 	iEtext->InsertL(0, aText);
   245 	TCursorSelection s(0, aText.Length());
   246 	iView->HandleInsertDeleteL(s, 0);
   247 	}
   248 
   249 void CTextViewTest::InitializeDiffCharFormatL()
   250 	{
   251 	Destroy();
   252 	delete iCharLayer;
   253 	iCharLayer=0;
   254 	TCharFormat charFormat;
   255 	TCharFormatMask charFormatMask;
   256 	charFormat.iFontPresentation.iPictureAlignment=TFontPresentation::EAlignBottom;
   257 	charFormatMask.SetAttrib(EAttFontPictureAlignment);
   258 	iCharLayer = CCharFormatLayer::NewL(charFormat,charFormatMask);
   259 	iEtext = CRichText::NewL(iParaLayer, iCharLayer);
   260 	iLayout = CTextLayout::NewL(iEtext, iWindowRect.Width());
   261 	iView = CTextView::NewL(iLayout, iWindowRect, iEnv.ScreenDevice(),
   262 		iEnv.SystemGc().Device(), &iWindow, &iEnv.RootWin(), &iEnv.WsSession());
   263 	testaGd=(CBitmapDevice*) iEnv.SystemGc().Device();
   264 	}
   265 
   266 void CTextViewTest::Destroy()
   267 	{
   268 	delete iView;
   269 	iView = 0;
   270 	delete iLayout;
   271 	iLayout = 0;
   272 	delete iEtext;
   273 	iEtext = 0;
   274 	}
   275 
   276 
   277 void CTextViewTest::TestL()
   278 	{
   279 	// Test for fix to ASR-4UYHZX: ETEXT panic 12 (ECharPosBeyondDocument) when
   280 	// out of memory
   281 	InitializeL();
   282 	ManipulateText(iView, iEtext);
   283 	Destroy();
   284 	TInt consecutiveSuccesses = 0;
   285 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   286 		{
   287 		__UHEAP_MARK;
   288 		InitializeL();
   289 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   290 		TRAPD(err, ManipulateText(iView, iEtext));
   291 		Destroy();
   292 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   293 		__UHEAP_MARKENDC(0);
   294 		if (err == KErrNone)
   295 			++consecutiveSuccesses;
   296 		else
   297 			consecutiveSuccesses = 0;
   298 		}
   299 	}
   300 
   301 
   302 void CTextViewTest::Test1L()
   303 	{
   304 	// testing functions SetViewL, SetViewLineAtTopL,
   305 	// SetDocPosL & HandleAdditionalCharactersAtEndL
   306 	// - should work but need some kind
   307 	// of pre-settings and initialization before they can all be proved
   308 	// that there is no memory leak
   309 	InitializeL();
   310 	ManipulateText1(iView, iEtext); //where all pre-settings have been done
   311 	Destroy();
   312 	TInt consecutiveSuccesses = 0;
   313 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   314 		{
   315 		__UHEAP_MARK;
   316 		InitializeL();
   317 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   318 		TRAPD(err, ManipulateText1(iView, iEtext));
   319 		Destroy();
   320 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   321 		__UHEAP_MARKENDC(0);
   322 		if (err == KErrNone)
   323 			++consecutiveSuccesses;
   324 		else
   325 			consecutiveSuccesses = 0;
   326 		}
   327 	}
   328 
   329 
   330 void CTextViewTest::TestCancelSelectionL()
   331 	{
   332 	InitializeL();
   333 	iView->CancelSelectionL();
   334 	Destroy();
   335 	TInt consecutiveSuccesses = 0;
   336 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   337 		{
   338 		__UHEAP_MARK;
   339 		InitializeL();
   340 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   341 		TRAPD(err, iView->CancelSelectionL());
   342 		Destroy();
   343 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   344 		__UHEAP_MARKENDC(0);
   345 		if (err == KErrNone)
   346 			++consecutiveSuccesses;
   347 		else
   348 			consecutiveSuccesses = 0;
   349 		}
   350 	}
   351 
   352 
   353 void CTextViewTest::TestFinishBackgroundFormattingL()
   354 	{
   355 	InitializeL();
   356 	iView->FinishBackgroundFormattingL();
   357 	Destroy();
   358 	TInt consecutiveSuccesses = 0;
   359 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   360 		{
   361 		__UHEAP_MARK;
   362 		InitializeL();
   363 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   364 		TRAPD(err, iView->FinishBackgroundFormattingL());
   365 		Destroy();
   366 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   367 		__UHEAP_MARKENDC(0);
   368 		if (err == KErrNone)
   369 			++consecutiveSuccesses;
   370 		else
   371 			consecutiveSuccesses = 0;
   372 		}
   373 	}
   374 
   375 
   376 void CTextViewTest::TestFormatTextL()
   377 	{
   378 	InitializeL();
   379 	iView->FormatTextL();
   380 	Destroy();
   381 	TInt consecutiveSuccesses = 0;
   382 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   383 		{
   384 		__UHEAP_MARK;
   385 		InitializeL();
   386 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   387 		TRAPD(err, iView->FormatTextL());
   388 		Destroy();
   389 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   390 		__UHEAP_MARKENDC(0);
   391 		if (err == KErrNone)
   392 			++consecutiveSuccesses;
   393 		else
   394 			consecutiveSuccesses = 0;
   395 		}
   396 	}
   397 
   398 
   399 void CTextViewTest::TestSetCursorVisibilityL()
   400 	{
   401 	InitializeL();
   402 	iView->SetCursorVisibilityL(1,1);
   403 	Destroy();
   404 	TInt consecutiveSuccesses = 0;
   405 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   406 		{
   407 		__UHEAP_MARK;
   408 		InitializeL();
   409 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   410 		TRAPD(err, iView->SetCursorVisibilityL(1,1)); //TInt aLineCursor, TInt aTextCursor
   411 		Destroy();
   412 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   413 		__UHEAP_MARKENDC(0);
   414 		if (err == KErrNone)
   415 			++consecutiveSuccesses;
   416 		else
   417 			consecutiveSuccesses = 0;
   418 		}
   419 	}
   420 
   421 
   422 void CTextViewTest::TestSetSelectionVisibilityL()
   423 	{
   424 	InitializeL();
   425 	iView->SetSelectionVisibilityL(1);
   426 	Destroy();
   427 	TInt consecutiveSuccesses = 0;
   428 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   429 		{
   430 		__UHEAP_MARK;
   431 		InitializeL();
   432 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   433 		TRAPD(err, iView->SetSelectionVisibilityL(1)); //TBool aSelectionVisible
   434 		Destroy();
   435 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   436 		__UHEAP_MARKENDC(0);
   437 		if (err == KErrNone)
   438 			++consecutiveSuccesses;
   439 		else
   440 			consecutiveSuccesses = 0;
   441 		}
   442 	}
   443 
   444 
   445 void CTextViewTest::TestEnablePictureFrameL()
   446 	{
   447 	InitializeL();
   448 	iView->EnablePictureFrameL(1);
   449 	Destroy();
   450 	TInt consecutiveSuccesses = 0;
   451 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   452 		{
   453 		__UHEAP_MARK;
   454 		InitializeL();
   455 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   456 		TRAPD(err, iView->EnablePictureFrameL(1)); //TBool aEnabled
   457 		Destroy();
   458 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   459 		__UHEAP_MARKENDC(0);
   460 		if (err == KErrNone)
   461 			++consecutiveSuccesses;
   462 		else
   463 			consecutiveSuccesses = 0;
   464 		}
   465 	}
   466 
   467 
   468 void CTextViewTest::TestSetCursorWidthTypeL()
   469 	{
   470 	InitializeL();
   471 	iView->SetCursorWidthTypeL(TTextCursor::ETypeRectangle,0);
   472 	Destroy();
   473 	TInt consecutiveSuccesses = 0;
   474 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   475 		{
   476 		__UHEAP_MARK;
   477 		InitializeL();
   478 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   479 		TRAPD(err, iView->SetCursorWidthTypeL(TTextCursor::ETypeRectangle,0)); //TTextCursor::EType aType, TInt aWidth=0
   480 		Destroy();
   481 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   482 		__UHEAP_MARKENDC(0);
   483 		if (err == KErrNone)
   484 			++consecutiveSuccesses;
   485 		else
   486 			consecutiveSuccesses = 0;
   487 		}
   488 	}
   489 
   490 
   491 void CTextViewTest::TestParagraphRectL()
   492 	{
   493 	InitializeL();
   494 	iView->ParagraphRectL(1);
   495 	Destroy();
   496 	TInt consecutiveSuccesses = 0;
   497 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   498 		{
   499 		__UHEAP_MARK;
   500 		InitializeL();
   501 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   502 		TRAPD(err, iView->ParagraphRectL(1)); //TInt aDocPos
   503 		Destroy();
   504 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   505 		__UHEAP_MARKENDC(0);
   506 		if (err == KErrNone)
   507 			++consecutiveSuccesses;
   508 		else
   509 			consecutiveSuccesses = 0;
   510 		}
   511 	}
   512 
   513 
   514 void CTextViewTest::TestDrawL()
   515 	{
   516 	InitializeL();
   517 	iView->DrawL(iWindowRect);
   518 	Destroy();
   519 	TInt consecutiveSuccesses = 0;
   520 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   521 		{
   522 		__UHEAP_MARK;
   523 		InitializeL();
   524 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   525 		TRAPD(err, iView->DrawL(iWindowRect)); //TRect aRect
   526 		Destroy();
   527 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   528 		__UHEAP_MARKENDC(0);
   529 		if (err == KErrNone)
   530 			++consecutiveSuccesses;
   531 		else
   532 			consecutiveSuccesses = 0;
   533 		}
   534 	}
   535 
   536 
   537 void CTextViewTest::TestHandleRangeFormatChangeL()
   538 	{
   539 	InitializeL();
   540 	iView->HandleRangeFormatChangeL(select, EFalse);
   541 	Destroy();
   542 	TInt consecutiveSuccesses = 0;
   543 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   544 		{
   545 		__UHEAP_MARK;
   546 		InitializeL();
   547 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   548 		TRAPD(err, iView->HandleRangeFormatChangeL(select, EFalse));
   549 		Destroy();
   550 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   551 		__UHEAP_MARKENDC(0);
   552 		if (err == KErrNone)
   553 			++consecutiveSuccesses;
   554 		else
   555 			consecutiveSuccesses = 0;
   556 		}
   557 	}
   558 
   559 
   560 void CTextViewTest::TestHandleInsertDeleteL()
   561 	{
   562 	InitializeL();
   563 	iView->HandleInsertDeleteL(select, 1, EFalse);
   564 	Destroy();
   565 	TInt consecutiveSuccesses = 0;
   566 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   567 		{
   568 		__UHEAP_MARK;
   569 		InitializeL();
   570 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   571 		TRAPD(err, iView->HandleInsertDeleteL(select, 1, EFalse));
   572 		Destroy();
   573 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   574 		__UHEAP_MARKENDC(0);
   575 		if (err == KErrNone)
   576 			++consecutiveSuccesses;
   577 		else
   578 			consecutiveSuccesses = 0;
   579 		}
   580 	}
   581 
   582 
   583 void CTextViewTest::TestHandleGlobalChangeL()
   584 	{
   585 	InitializeL();
   586 	iView->HandleGlobalChangeL(TViewYPosQualifier());
   587 	Destroy();
   588 	TInt consecutiveSuccesses = 0;
   589 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   590 		{
   591 		__UHEAP_MARK;
   592 		InitializeL();
   593 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   594 		TRAPD(err, iView->HandleGlobalChangeL(TViewYPosQualifier()));
   595 		Destroy();
   596 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   597 		__UHEAP_MARKENDC(0);
   598 		if (err == KErrNone)
   599 			++consecutiveSuccesses;
   600 		else
   601 			consecutiveSuccesses = 0;
   602 		}
   603 	}
   604 
   605 
   606 void CTextViewTest::TestHandleGlobalChangeNoRedrawL()
   607 	{
   608 	InitializeL();
   609 	iView->HandleGlobalChangeNoRedrawL(TViewYPosQualifier());
   610 	Destroy();
   611 	TInt consecutiveSuccesses = 0;
   612 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   613 		{
   614 		__UHEAP_MARK;
   615 		InitializeL();
   616 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   617 		TRAPD(err, iView->HandleGlobalChangeNoRedrawL(TViewYPosQualifier()));
   618 		Destroy();
   619 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   620 		__UHEAP_MARKENDC(0);
   621 		if (err == KErrNone)
   622 			++consecutiveSuccesses;
   623 		else
   624 			consecutiveSuccesses = 0;
   625 		}
   626 	}
   627 
   628 
   629 void CTextViewTest::TestScrollDisplayL()
   630 	{
   631 	InitializeL();
   632 	iView->ScrollDisplayL(TCursorPosition::EFLeft);
   633 	Destroy();
   634 	TInt consecutiveSuccesses = 0;
   635 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   636 		{
   637 		__UHEAP_MARK;
   638 		InitializeL();
   639 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   640 		TRAPD(err, iView->ScrollDisplayL(TCursorPosition::EFLeft));
   641 		Destroy();
   642 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   643 		__UHEAP_MARKENDC(0);
   644 		if (err == KErrNone)
   645 			++consecutiveSuccesses;
   646 		else
   647 			consecutiveSuccesses = 0;
   648 		}
   649 	}
   650 
   651 
   652 void CTextViewTest::TestScrollDisplayPixelsL()
   653 	{
   654 	InitializeL();
   655 	iView->ScrollDisplayPixelsL(testDeltaY);
   656 	Destroy();
   657 	TInt consecutiveSuccesses = 0;
   658 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   659 		{
   660 		__UHEAP_MARK;
   661 		InitializeL();
   662 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   663 		TRAPD(err, iView->ScrollDisplayPixelsL(testDeltaY));
   664 		Destroy();
   665 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   666 		__UHEAP_MARKENDC(0);
   667 		if (err == KErrNone)
   668 			++consecutiveSuccesses;
   669 		else
   670 			consecutiveSuccesses = 0;
   671 		}
   672 	}
   673 
   674 
   675 void CTextViewTest::TestScrollDisplayPixelsNoLimitBordersL(TInt aOffset)
   676     { 
   677     /*
   678      * This test case is for new added function ScrollDisplayPixelsNoLimitBorderL() which support
   679      * no limit scrolling, using this function text view can be scrolled beyond the top and bottom 
   680      * border.
   681      * Text view will be firstly scrolled to border using ScrollDisplayPixelsL() which can't scroll
   682      * text view beyond the top or bottom border.
   683      * Then text view will be scrolled using ScrollDisplayPixelsNoLimitBorderL() to same direction.
   684      * Code will test this step that if text view is really scrolled beyond the border by checking 
   685      * the iBandTop position before and after the scrolling operation.*/
   686     
   687     InitializeL();
   688     _LIT(KTestParagraph, "This is a piece of text which is used to test the bounce scrolling feature made by s60.");
   689     for (TInt i=0;i<=20;i++)
   690         AddTextL(KTestParagraph);
   691     
   692     TInt firstBandTop, secondBandTop;
   693     TInt offset = aOffset;
   694     while( offset!=0 )
   695         {
   696         iView->ScrollDisplayPixelsL(offset);
   697         }
   698     offset = aOffset;
   699     firstBandTop = iLayout->PixelsAboveBand();
   700     iView->ScrollDisplayPixelsNoLimitBorderL(offset);
   701     secondBandTop = iLayout->PixelsAboveBand();
   702     test(firstBandTop - secondBandTop == offset);
   703 
   704     offset = 0 - aOffset;
   705     while( offset!=0 )
   706         {
   707         iView->ScrollDisplayPixelsL(offset);
   708         }
   709     offset = 0 - aOffset;
   710     firstBandTop = iLayout->PixelsAboveBand();
   711     iView->ScrollDisplayPixelsNoLimitBorderL(offset);
   712     secondBandTop = iLayout->PixelsAboveBand();
   713     test(firstBandTop - secondBandTop == offset);
   714     
   715     Destroy();
   716     }
   717 
   718 
   719 void CTextViewTest::TestScrollDisplayLinesL()
   720 	{
   721 	InitializeL();
   722 	iView->ScrollDisplayLinesL(testDeltaLines);
   723 	Destroy();
   724 	TInt consecutiveSuccesses = 0;
   725 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   726 		{
   727 		__UHEAP_MARK;
   728 		InitializeL();
   729 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   730 		TRAPD(err, iView->ScrollDisplayLinesL(testDeltaLines));
   731 		Destroy();
   732 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   733 		__UHEAP_MARKENDC(0);
   734 		if (err == KErrNone)
   735 			++consecutiveSuccesses;
   736 		else
   737 			consecutiveSuccesses = 0;
   738 		}
   739 	}
   740 
   741 
   742 void CTextViewTest::TestScrollDisplayParagraphsL()
   743 	{
   744 	InitializeL();
   745 	AddTextL(KHello);
   746 	iView->ScrollDisplayParagraphsL(testDeltaParas);
   747 	Destroy();
   748 	TInt consecutiveSuccesses = 0;
   749 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   750 		{
   751 		__UHEAP_MARK;
   752 		InitializeL();
   753 		AddTextL(KHello);
   754 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   755 		TRAPD(err, iView->ScrollDisplayParagraphsL(testDeltaParas));
   756 		Destroy();
   757 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   758 		__UHEAP_MARKENDC(0);
   759 		if (err == KErrNone)
   760 			++consecutiveSuccesses;
   761 		else
   762 			consecutiveSuccesses = 0;
   763 		}
   764 	}
   765 
   766 
   767 void CTextViewTest::TestSetViewL()
   768 	{
   769 	InitializeL();
   770 	iView->SetViewL(1, testaYPos);
   771 	Destroy();
   772 	TInt consecutiveSuccesses = 0;
   773 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   774 		{
   775 		__UHEAP_MARK;
   776 		InitializeL();
   777 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   778 		TRAPD(err, iView->SetViewL(1, testaYPos));
   779 		Destroy();
   780 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   781 		__UHEAP_MARKENDC(0);
   782 		if (err == KErrNone)
   783 			++consecutiveSuccesses;
   784 		else
   785 			consecutiveSuccesses = 0;
   786 		}
   787 	}
   788 
   789 
   790 void CTextViewTest::TestMoveCursorL()
   791 	{
   792 	InitializeL();
   793 	AddTextL(KHello);
   794 	iView->MoveCursorL(testaMovement, EFalse);
   795 	Destroy();
   796 	TInt consecutiveSuccesses = 0;
   797 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   798 		{
   799 		__UHEAP_MARK;
   800 		InitializeL();
   801 		AddTextL(KHello);
   802 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   803 		TRAPD(err, iView->MoveCursorL(testaMovement, EFalse));
   804 		Destroy();
   805 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   806 		__UHEAP_MARKENDC(0);
   807 		if (err == KErrNone)
   808 			++consecutiveSuccesses;
   809 		else
   810 			consecutiveSuccesses = 0;
   811 		}
   812 	}
   813 
   814 
   815 void CTextViewTest::TestSetSelectionL()
   816 	{
   817 	InitializeL();
   818 	iView->SetSelectionL(select);
   819 	Destroy();
   820 	TInt consecutiveSuccesses = 0;
   821 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   822 		{
   823 		__UHEAP_MARK;
   824 		InitializeL();
   825 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   826 		TRAPD(err, iView->SetSelectionL(select));
   827 		Destroy();
   828 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   829 		__UHEAP_MARKENDC(0);
   830 		if (err == KErrNone)
   831 			++consecutiveSuccesses;
   832 		else
   833 			consecutiveSuccesses = 0;
   834 		}
   835 	}
   836 
   837 
   838 void CTextViewTest::TestMatchCursorHeightL()
   839 	{
   840 	InitializeL();
   841 	iView->MatchCursorHeightL(testaFontSpec);
   842 	Destroy();
   843 	TInt consecutiveSuccesses = 0;
   844 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   845 		{
   846 		__UHEAP_MARK;
   847 		InitializeL();
   848 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   849 		TRAPD(err, iView->MatchCursorHeightL(testaFontSpec));
   850 		Destroy();
   851 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   852 		__UHEAP_MARKENDC(0);
   853 		if (err == KErrNone)
   854 			++consecutiveSuccesses;
   855 		else
   856 			consecutiveSuccesses = 0;
   857 		}
   858 	}
   859 
   860 
   861 void CTextViewTest::TestCalculateHorizontalExtremesL()
   862 	{
   863 	InitializeL();
   864 	iView->CalculateHorizontalExtremesL(testaLeft, testaRight, EFalse);
   865 	Destroy();
   866 	TInt consecutiveSuccesses = 0;
   867 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   868 		{
   869 		__UHEAP_MARK;
   870 		InitializeL();
   871 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   872 		TRAPD(err, iView->CalculateHorizontalExtremesL(testaLeft, testaRight, EFalse));
   873 		Destroy();
   874 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   875 		__UHEAP_MARKENDC(0);
   876 		if (err == KErrNone)
   877 			++consecutiveSuccesses;
   878 		else
   879 			consecutiveSuccesses = 0;
   880 		}
   881 	}
   882 
   883 
   884 void CTextViewTest::TestXyPosToDocPosL()
   885 	{
   886 	InitializeL();
   887 	iView->XyPosToDocPosL(testaPoint);
   888 	Destroy();
   889 	TInt consecutiveSuccesses = 0;
   890 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   891 		{
   892 		__UHEAP_MARK;
   893 		InitializeL();
   894 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   895 		TRAPD(err, iView->XyPosToDocPosL(testaPoint));
   896 		Destroy();
   897 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   898 		__UHEAP_MARKENDC(0);
   899 		if (err == KErrNone)
   900 			++consecutiveSuccesses;
   901 		else
   902 			consecutiveSuccesses = 0;
   903 		}
   904 	}
   905 
   906 /*
   907 void CTextViewTest::TestDrawL1()
   908 	{
   909 	InitializeL();
   910 	iView->DrawL(iWindowRect, testaGc);
   911 	Destroy();
   912 	TInt consecutiveSuccesses = 0;
   913 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   914 		{
   915 		__UHEAP_MARK;
   916 		InitializeL();
   917 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   918 		TRAPD(err, iView->DrawL(iWindowRect, testaGc));
   919 		Destroy();
   920 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   921 		__UHEAP_MARKENDC(0);
   922 		if (err == KErrNone)
   923 			++consecutiveSuccesses;
   924 		else
   925 			consecutiveSuccesses = 0;
   926 		}
   927 	}
   928 */
   929 
   930 
   931 void CTextViewTest::TestGetPictureRectangleL()
   932 	{
   933 	InitializeL();
   934 	iView->GetPictureRectangleL(1, iWindowRect, &testaCanScaleOrCrop);
   935 	Destroy();
   936 	TInt consecutiveSuccesses = 0;
   937 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   938 		{
   939 		__UHEAP_MARK;
   940 		InitializeL();
   941 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   942 		TRAPD(err, iView->GetPictureRectangleL(1, iWindowRect, &testaCanScaleOrCrop));
   943 		Destroy();
   944 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   945 		__UHEAP_MARKENDC(0);
   946 		if (err == KErrNone)
   947 			++consecutiveSuccesses;
   948 		else
   949 			consecutiveSuccesses = 0;
   950 		}
   951 	}
   952 
   953 
   954 void CTextViewTest::TestGetPictureRectangle1L()
   955 	{
   956 	InitializeL();
   957 	iView->GetPictureRectangleL(testaXyPos, iWindowRect, &testaCanScaleOrCrop);
   958 	Destroy();
   959 	TInt consecutiveSuccesses = 0;
   960 	for (TInt i = 1; consecutiveSuccesses != 100; ++i)
   961 		{
   962 		__UHEAP_MARK;
   963 		InitializeL();
   964 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   965 		TRAPD(err, iView->GetPictureRectangleL(testaXyPos, iWindowRect, &testaCanScaleOrCrop));
   966 		Destroy();
   967 		__UHEAP_SETFAIL(RHeap::ENone, 0);
   968 		__UHEAP_MARKENDC(0);
   969 		if (err == KErrNone)
   970 			++consecutiveSuccesses;
   971 		else
   972 			consecutiveSuccesses = 0;
   973 		}
   974 	}
   975 
   976 
   977 void CTextViewTest::TestSetDisplayContextL()
   978 	{
   979 	CBitmapContext* atestGc;
   980 	CBitmapContext* anotherGc;
   981 	InitializeL();
   982 	iView->SetDisplayContextL(testaGd, &iWindow, &testaGroupWin, &testaSession);
   983 	Destroy();
   984 	TInt consecutiveSuccesses = 0;
   985 	for (TInt i = 1; consecutiveSuccesses != 1; ++i)
   986 		{
   987 		__UHEAP_MARK;
   988 		InitializeL();
   989 		__UHEAP_SETFAIL(RHeap::EDeterministic, i);
   990 		atestGc=iView->BitmapContext();
   991 		TRAPD(err, iView->SetDisplayContextL(testaGd, &iWindow, &testaGroupWin, &testaSession));
   992 		anotherGc=iView->BitmapContext();
   993 		if (err)
   994 			{
   995 			test(atestGc==anotherGc);
   996 			}
   997 		else
   998 			{
   999 			test(atestGc!=anotherGc);
  1000 			}
  1001 		Destroy();
  1002 		__UHEAP_SETFAIL(RHeap::ENone, 0);
  1003 		__UHEAP_MARKENDC(0);
  1004 		if (err == KErrNone)
  1005 			++consecutiveSuccesses;
  1006 		else
  1007 			consecutiveSuccesses = 0;
  1008 		}
  1009 	}
  1010 
  1011 
  1012 void CTextViewTest::TestGetPictureRectangleDefectL()
  1013 	{
  1014 	/*
  1015 	_LIT(KParagraphAverage,"Some text to test that the Picture returned is in the correct position. The size of this paragraph should be reasonable, not too long not too short.");
  1016 	_LIT(KParagraphBigger,"Moulin Rouge: a film review. I don't know what I was expecting from Oulin Rouge, but what I got came as an even more of a surprise. The movie is a visual feast, a sing along extravaganza. The choices of songs is refreshing, with mix of Nirvan-Smells like teen spirit- to Madonna-Like a virgin-. Who knew that Ewan and Nicole could sing so well together.");
  1017 	_LIT(KParagraphSmall,"CBusBase is an abstract base class for dynamic memory buffers. You can read or write bytes.");
  1018 	InitializeL();
  1019 	TInt length;
  1020 	iEtext->InsertL(0,KParagraphAverage);
  1021 	iView->HandleInsertDeleteL(TCursorSelection(0, KParagraphAverage().Length()), 0);
  1022 	iEtext->InsertL(KParagraphAverage().Length(),TChar(CEditableText::EParagraphDelimiter));
  1023 	iView->HandleCharEditL();
  1024 
  1025 	length=iEtext->LdDocumentLength();
  1026 	iEtext->InsertL(iEtext->LdDocumentLength(),KParagraphBigger);
  1027 	iView->HandleInsertDeleteL(TCursorSelection(length,KParagraphBigger().Length()), 0);
  1028 
  1029 	length=iEtext->LdDocumentLength();
  1030 	iEtext->InsertL(iEtext->LdDocumentLength(),KParagraphSmall);
  1031 	iView->HandleInsertDeleteL(TCursorSelection(length,KParagraphSmall().Length()), 0);
  1032 
  1033 	TSize size(100,100);
  1034 	TPoint xypos;
  1035 	CMyTestPicture* testpicture1 = CMyTestPicture::NewL(size);
  1036 	CMyTestPicture* testpicture2 = CMyTestPicture::NewL(size);
  1037 	CMyTestPicture* testpicture3 = CMyTestPicture::NewL(size);
  1038 	size.SetSize(200,200);
  1039 	CMyTestPicture* testpicture4 = CMyTestPicture::NewL(size);
  1040 	CMyTestPicture* testpicture5 = CMyTestPicture::NewL(size);
  1041 	CMyTestPicture* testpicture6 = CMyTestPicture::NewL(size);
  1042 	TPictureHeader mypic;
  1043 	TPictureHeader mypic2;
  1044 	//mypic.iPictureType = KUidXzePictureType;
  1045 	mypic.iPicture=testpicture1;
  1046 	mypic2.iPicture=testpicture2;
  1047 	// Testing the picture
  1048 
  1049 	iEtext->InsertL(10,mypic2);
  1050 	mypic2.iPicture=testpicture1;
  1051 	iEtext->InsertL(40,mypic2);
  1052 	iView->DocPosToXyPosL(200,xypos);
  1053 	test.Printf(_L("The xy coords are %d & %d\n"),xypos.iX,xypos.iY);
  1054 	xypos.SetXY(78,55);
  1055 	TInt docpos;
  1056 	docpos=iView->XyPosToDocPosL(xypos);
  1057 	test.Printf(_L("The new docpos is %d\n"),docpos);
  1058 	TRect rect;
  1059 	TBool boo;
  1060 	boo=iView->GetPictureRectangleL(40,rect);
  1061 	test.Printf(_L("%d & %d \n"),rect.Size().iHeight,rect.Size().iWidth);
  1062 	if (boo)
  1063 		test.Printf(_L("Yes!"));
  1064 	else
  1065 		test.Printf(_L("Noo!"));
  1066 	*/
  1067 	}
  1068 
  1069 void CTextViewTest::TestGetLineRectL()
  1070 	{
  1071 
  1072 	_LIT(KSomeText,"Empty. Well this text has to now be something else. Maybe this will increase the height of the CTextLayout and if it does then");
  1073 	// calls the initializeDiffCharFormatL to set the new CharFormatLayer
  1074 	// which sets the picture alignment to be Bottom.
  1075 	InitializeDiffCharFormatL();
  1076 	// create test pictures to be inserted into the richtext object
  1077 	TSize size(100,100);
  1078 	CMyTestPicture* testpicture1 = CMyTestPicture::NewL(size);
  1079 	TPictureHeader tPicHeader;
  1080 	tPicHeader.iPictureType = KUidXzePictureType;
  1081 	tPicHeader.iPicture = testpicture1;
  1082 	test.Printf(_L("Created a picture\n"));
  1083 
  1084 	// inserting some text & picture into the richtext object
  1085 	iEtext->InsertL(0,KSomeText);
  1086 	TInt startOfPicture;
  1087 	startOfPicture=iEtext->DocumentLength();
  1088 	iEtext->InsertL(startOfPicture,tPicHeader);
  1089 	test.Printf(_L("Inserted the picture in CRichText object \n"));
  1090 
  1091 	//Call the guilty function
  1092 	TRect resultingRect;
  1093 	TInt endOfDocument = iEtext->DocumentLength();
  1094 	iView->FormatTextL();
  1095 	resultingRect=iLayout->GetLineRectL(startOfPicture,endOfDocument);
  1096 	}
  1097 
  1098 void CTextViewTest::TestGetParaFormatL()
  1099 	{
  1100 	test.Next(_L("Starting GetParaFormatL test"));
  1101 	_LIT(KSomeText,"Empty. Well this text has to now be something else. Maybe this will increase the height of the CTextLayout and if it does then");
  1102 	InitializeL();
  1103 	// create the CParaFormat & TparaFormatMask
  1104 	// and set that in the iParaFormatLayer
  1105 	CParaFormat* paraFormat = CParaFormat::NewL();
  1106 	TParaFormatMask paraFormatMask;
  1107 	iParaLayer->SetL(paraFormat,paraFormatMask);
  1108 	iEtext->SetGlobalParaFormat(iParaLayer);
  1109 	iEtext->InsertL(0,KSomeText);
  1110 	iView->FormatTextL();
  1111 	// Create another CParaFormat & TParaFormatMask and set
  1112 	// some attributes to be different from the default.
  1113 	CParaFormat* anotherParaFormat = CParaFormat::NewL();
  1114 	TParaFormatMask anotherParaFormatMask;
  1115 	anotherParaFormat->iRightMarginInTwips=200;
  1116 	anotherParaFormatMask.SetAttrib(EAttRightMargin);
  1117 	anotherParaFormat->iLeftMarginInTwips=400;
  1118 	anotherParaFormatMask.SetAttrib(EAttLeftMargin);
  1119 	anotherParaFormat->iLineSpacingInTwips=300;
  1120 	anotherParaFormatMask.SetAttrib(EAttLineSpacing);
  1121 	anotherParaFormat->iHorizontalAlignment=CParaFormat::ERightAlign;
  1122 	anotherParaFormatMask.SetAttrib(EAttAlignment);
  1123 
  1124 	//Now call CRichText::GetParaFormat using anotherParaFormat * Mask
  1125 	// and test that it is the same as paraFormat.
  1126  	iEtext->GetParaFormatL(anotherParaFormat,anotherParaFormatMask,0,10);
  1127 
  1128 	TInt result = anotherParaFormat->iRightMarginInTwips;
  1129 	test (result==0);
  1130 
  1131 	result = anotherParaFormat->iLeftMarginInTwips;
  1132 	test (result==0);
  1133 	result = anotherParaFormat->iLineSpacingInTwips;
  1134 	test (result==200); // default value for iLineSpacingInTwips set in paraFormat is 200
  1135 	test (anotherParaFormat->iHorizontalAlignment == CParaFormat::ELeftAlign);
  1136 
  1137 	TBool testresult;
  1138 	testresult=anotherParaFormat->IsEqual(*paraFormat);
  1139 	test(testresult);
  1140 
  1141 	}
  1142 
  1143 
  1144 void CTextViewTest::TestForDEF003426L()
  1145 	{
  1146 	// Initialise CTextViewTest object for next test.
  1147 	InitializeL();
  1148 	test.Next(_L("Verifying CTextView::XyPosToDosPosL() WRT DEF003426"));
  1149 
  1150 	// Insert a one line paragraph into EText object and reformat view.
  1151 	_LIT(KTestParagraph, "This is a piece of text to test the character positioning API based in X,Y cocordinates.");
  1152 	iEtext->InsertL(0, KTestParagraph);
  1153 	TCursorSelection sel(0, KTestParagraph().Length());
  1154 	(void) iView->HandleInsertDeleteL(sel, 0, EFalse);
  1155 
  1156 	// Test XyPosToDocPosL() with coordinates beyond top left corner
  1157 	TInt docPos = -1;
  1158 	docPos = iView->XyPosToDocPosL(testaPoint);
  1159 	test(docPos == 0); // Should give char position of 0
  1160 
  1161 	// Test XyPosToDocPosL() with coordinates beyond bottom right corner
  1162 	TRect viewRect = iView->ViewRect();
  1163 	viewRect.iBr.iX += 300;
  1164 	viewRect.iBr.iY += 111;
  1165     docPos = iView->XyPosToDocPosL(viewRect.iBr);
  1166 	test(docPos != 0); // Should give char position of 88
  1167 
  1168 	// Clean up test object
  1169 	Destroy();
  1170 	}
  1171 
  1172 /*** Test code for DEF038858
  1173 	 " It isn't poss. to set via CTextView a TTmDocPos of iPos = 0; iLeadingEdge=false"
  1174  */
  1175 void CTextViewTest::TestForDEF038488L()
  1176 	{
  1177 	// Initialise CTextViewTest object for next test.
  1178 	InitializeL();
  1179 	test.Next(_L("Verifying CTextView::SetDocPosL() DEF038858"));
  1180 
  1181 	_LIT(KText, "This is the test for DEF038488");
  1182 	iEtext->InsertL(0, KText);
  1183 	iView->HandleInsertDeleteL(TCursorSelection(0, KText().Length()), 0);
  1184 
  1185 	// Test SetDocPosL() with coordinates -1
  1186 	iView->SetDocPosL(-1);
  1187 
  1188 	// check the value of iLeadingEdge
  1189 	TTmDocPos RawDocPos;
  1190 	iView->GetCursorPos(RawDocPos);
  1191 	test(RawDocPos.iLeadingEdge == EFalse);
  1192 
  1193 	}
  1194 
  1195 CTextViewTest::~CTextViewTest()
  1196 	{
  1197 	test.End();
  1198 	test.Close();
  1199 	delete iView;
  1200 	iWindow.Close();
  1201 	delete iLayout;
  1202 	delete iEtext;
  1203 	delete iCharLayer;
  1204 	delete iParaLayer;
  1205 	}
  1206 
  1207 /**
  1208 @SYMTestCaseID          SYSLIB-FORM-UT-1888
  1209 @SYMTestCaseDesc        Testing the Class TFormAndEtextEditor
  1210 @SYMTestPriority        Low
  1211 @SYMTestActions         Tests the API's of TFormAndEtextEditor by inserting the text, applying specific format and style to the text, getting the text,format and style and also deleting the same(text,format and style)
  1212 @SYMTestExpectedResults Tests must not fail
  1213 @SYMREQ                 REQ0000
  1214 */
  1215 void CTextViewTest::FormAndEtextTestL()
  1216 	{
  1217 	InitializeL();
  1218 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-1888 Testing TFormAndEtextEditor "));
  1219 	TCharFormatMask charMask;
  1220     TCharFormat charFormat;
  1221 	charFormat.iFontSpec.iTypeface.iName = _S("Arial");
  1222     charFormat.iFontSpec.iHeight = 240;
  1223     charMask.SetAttrib(EAttFontTypeface);
  1224     charMask.SetAttrib(EAttFontHeight);
  1225     CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
  1226     charFormatLayer->SetL(charFormat,charMask);
  1227 	TParaFormatMask paraFormatMask;
  1228     CParaFormatLayer* paraFormatLayer=CParaFormatLayer::NewL((CParaFormat*)NULL,paraFormatMask);
  1229     CParagraphStyle* paraStyle = CParagraphStyle::NewL(*paraFormatLayer,*charFormatLayer);
  1230     CStyleList* styleList = CStyleList::NewL();
  1231     RParagraphStyleInfo paraStyleInfo(paraStyle,paraStyle);
  1232     paraStyleInfo.iStyle->iName=_L("Arial");
  1233     paraStyleInfo.iStyleForNextPara->iName=_L("Arial");
  1234     // Appending the new style to stylelist
  1235     styleList->AppendL(&paraStyleInfo);
  1236 
  1237 	iEtext->SetStyleListExternallyOwned(*styleList);
  1238 	iEtext->Reset();
  1239 	TFormAndEtextEditor newEditor(*iView,*iEtext);
  1240 
  1241 	TTmCharFormatLayer charLayer;
  1242 	TTmCharFormatLayer charLayer1;
  1243 	TTmCharFormatMask charIMask;
  1244 	TTmCharFormat charI;
  1245 	RTmParFormatLayer parLayer;
  1246 	RTmParFormatLayer parLayer1;
  1247 	TTmParFormatMask parNMask;
  1248 	charIMask.iFlags = TTmCharFormatMask::EItalic;
  1249 	TOpenFontFaceAttribBase attrib;
  1250 	attrib.SetBold(EFalse);
  1251 	charI.iFontSpec.SetAttrib(attrib);
  1252 	parNMask.iFlags = TTmParFormatMask::EKeepWithNext;
  1253 	RTmParFormat parN;
  1254 	parN.iFlags = RTmParFormat::EKeepWithNext;
  1255 	charLayer.iMask = charIMask;
  1256 	charLayer.iFormat = charI;
  1257 	charLayer1=charLayer;
  1258 	parLayer.iMask = parNMask;
  1259 
  1260 	parLayer.iFormat.CopyL(parN);
  1261 	TPtrC ptr1(_L("Arial"));
  1262 	// Inserting the text and applying the style specified(Arial)
  1263 	newEditor.InsertTextL(0, _L("Hello World"),&ptr1);
  1264 
  1265 	// Setting the paragraph and character format explicitly
  1266 	newEditor.SetParFormatL(0,11,parLayer);
  1267 	newEditor.SetCharFormatL(0,11,charLayer);
  1268 
  1269 	MUnifiedEditor::TFormatLevel level = MUnifiedEditor::EEffective;
  1270 	TInt runLen=11;
  1271 	// Getting the paragraph and character format
  1272 	newEditor.GetParFormatL(0,level,parLayer1,runLen);
  1273 	newEditor.GetCharFormat(0,level,charLayer1,runLen);
  1274 
  1275 	// Deleting first 6 characters
  1276 	newEditor.DeleteTextL(0,6);
  1277 	// Deleting the paragraph and character format for the remaining text
  1278 	newEditor.DeleteParFormatL(0,5);
  1279 	newEditor.DeleteCharFormatL(0,5);
  1280 
  1281 	TPtrC ptr;
  1282 	// Get the text into ptr. A paragraph seperator(\x2029) gets appended at the end of text.
  1283 	newEditor.GetText(0,ptr);
  1284 	test(ptr==_L("World\x2029"));
  1285 
  1286 	RTmStyle style1;
  1287 	RParagraphStyleInfo paraStyleInfo1(paraStyle,paraStyle);
  1288 	paraStyleInfo1.iStyle->iName=_L("NewStyle");
  1289 	paraStyleInfo1.iStyleForNextPara->iName=_L("NewStyle");
  1290 	style1.CopyL(paraStyleInfo1);
  1291 	// Creating a new style and changing the current style to the new one.
  1292 	newEditor.StyleSupport()->CreateStyleL(style1);
  1293 	newEditor.StyleSupport()->ChangeStyleL(style1);
  1294 
  1295 	RTmStyle style2;
  1296 	// Get the style by Name
  1297 	TInt retVal = newEditor.StyleSupport()->GetStyleByNameL(_L("Arial"),style2);
  1298 	retVal = newEditor.StyleSupport()->GetStyleByNameL(_L("NewStyle"),style2);
  1299 	// Get the style for a particular length of text
  1300 	newEditor.StyleSupport()->GetStyle(0,ptr,runLen);
  1301 	// Get the style by index
  1302 	retVal = newEditor.StyleSupport()->GetStyleByIndexL(1,style1);
  1303 	// Deleting the style
  1304 	newEditor.StyleSupport()->DeleteStyleL(_L("NewStyle"));
  1305 	retVal = newEditor.StyleCount();
  1306 	test(retVal==1);
  1307 	style1.Close();
  1308 	style2.Close();
  1309 	delete charFormatLayer;
  1310     delete paraFormatLayer;
  1311     delete styleList;
  1312 	}
  1313 
  1314 /**
  1315 @SYMTestCaseID          SYSLIB-FORM-UT-3347
  1316 @SYMTestCaseDesc        Testing the fix for INC092725: RF S60 3.2 Help: Touch and
  1317 						scrolling a topic down closing the program
  1318 @SYMTestPriority        High
  1319 @SYMTestActions         Run affected APIs passing scroll values that would put the display
  1320 						outside the formatted range.
  1321 @SYMTestExpectedResults First of all, the calls should not panic the process.
  1322 						Secondly, that the calls leave with the correct error code.
  1323 @SYMDEF                 INC092725
  1324 */
  1325 void CTextViewTest::TestForINC092725L()
  1326 	{
  1327 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-3347 Testing fix for INC092725 "));
  1328 	TInt err = KErrNone;
  1329 	InitializeL();
  1330 	AddTextL(KHello);
  1331 
  1332 	//Scroll up
  1333 	iLayout->AdjustVerticalAlignment(CParaFormat::EAbsoluteRightAlign);
  1334 	TRAP(err, iView->ScrollDisplayL(TCursorPosition::EFLineUp, CTextLayout::EFAllowScrollingBlankSpace));
  1335 	test(err==CTextLayout::EPosNotFormatted);
  1336 	err=KErrNone;
  1337 
  1338 	//Scroll down
  1339 	iLayout->AdjustVerticalAlignment(CParaFormat::EAbsoluteLeftAlign);
  1340 	TRAP(err, iView->ScrollDisplayL(TCursorPosition::EFLineDown, CTextLayout::EFAllowScrollingBlankSpace));
  1341 	test(err==CTextLayout::EPosNotFormatted);
  1342 	err=KErrNone;
  1343 
  1344 	//Line scroll up
  1345 	TInt i = 105;
  1346 	iLayout->AdjustVerticalAlignment(CParaFormat::EAbsoluteRightAlign);
  1347 	TRAP(err, iView->ScrollDisplayLinesL(i, CTextLayout::EFAllowScrollingBlankSpace));
  1348 	test(err==CTextLayout::EPosNotFormatted);
  1349 	err=KErrNone;
  1350 
  1351 	//Line scroll down
  1352 	i = -105;
  1353 	iLayout->AdjustVerticalAlignment(CParaFormat::EAbsoluteLeftAlign);
  1354 	TRAP(err, iView->ScrollDisplayLinesL(i, CTextLayout::EFAllowScrollingBlankSpace));
  1355 	test(err==CTextLayout::EPosNotFormatted);
  1356 	err=KErrNone;
  1357 
  1358 	//Paragraph scroll up
  1359 	i = 105;
  1360 	iLayout->AdjustVerticalAlignment(CParaFormat::EAbsoluteRightAlign);
  1361 	TRAP(err, iView->ScrollDisplayParagraphsL(i, CTextLayout::EFAllowScrollingBlankSpace));
  1362 	test(err==CTextLayout::EPosNotFormatted);
  1363 	err=KErrNone;
  1364 
  1365 	//Paragraph scroll down
  1366 	i = -105;
  1367 	iLayout->AdjustVerticalAlignment(CParaFormat::EAbsoluteLeftAlign);
  1368 	TRAP(err, iView->ScrollDisplayParagraphsL(i, CTextLayout::EFAllowScrollingBlankSpace));
  1369 	test(err==CTextLayout::EPosNotFormatted);
  1370 	Destroy();
  1371 	}
  1372 
  1373 
  1374 class CTestScreenDevice : public CPrinterDevice
  1375 	{
  1376 public:
  1377     CTestScreenDevice(CWsScreenDevice* aDevice,RDrawableWindow& aWin);
  1378 	TDisplayMode DisplayMode() const {return iDevice->DisplayMode();}
  1379 	TSize SizeInPixels() const {return iDevice->SizeInPixels();}
  1380 	TSize SizeInTwips() const {return iDevice->SizeInTwips();}
  1381     TInt NumTypefaces() const {return iDevice->NumTypefaces();}
  1382     void TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const
  1383 										{iDevice->TypefaceSupport(aTypefaceSupport,aTypefaceIndex);}
  1384 	TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
  1385 									{return iDevice->FontHeightInTwips(aTypefaceIndex,aHeightIndex);}
  1386 	void PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
  1387 												{iDevice->PaletteAttributes(aModifiable,aNumEntries);}
  1388 	void SetPalette(CPalette* aPalette) {iDevice->SetPalette(aPalette);}
  1389 	TInt GetPalette(CPalette*& aPalette) const {return iDevice->GetPalette(aPalette);}
  1390  	TInt CreateContext(CGraphicsContext *&aGc);
  1391 	TInt HorizontalTwipsToPixels(TInt aTwips) const {return iDevice->HorizontalTwipsToPixels(aTwips);};
  1392 	TInt VerticalTwipsToPixels(TInt aTwips) const {return iDevice->VerticalTwipsToPixels(aTwips);};
  1393 	TInt HorizontalPixelsToTwips(TInt aPixels) const {return iDevice->HorizontalPixelsToTwips(aPixels);};
  1394 	TInt VerticalPixelsToTwips(TInt aPixels) const {return iDevice->VerticalPixelsToTwips(aPixels);};
  1395 	TInt GetNearestFontInTwips(CFont*& aFont,const TFontSpec& aFontSpec) {return iDevice->GetNearestFontInTwips(aFont,aFontSpec);};
  1396 	void ReleaseFont(CFont* aFont) {iDevice->ReleaseFont(aFont);};
  1397 	TPrinterModelName ModelName() const {return _L("");}
  1398 	TUid ModelUid() const {TUid dummy; return dummy;}
  1399 	void CreateControlL(CPrinterPort* /*aPrinterPort*/) {}
  1400 	TPrinterModelEntry Model() const {return iModel;}
  1401 	TInt SetModel(const TPrinterModelHeader& /*aModel*/,CStreamStore& /*aStore*/) {return KErrNone;}
  1402 	TBool RequiresPrinterPort() {return EFalse;}
  1403 private:
  1404 	RDrawableWindow& iWin;
  1405 	CWsScreenDevice* iDevice;
  1406 	TPrinterModelEntry iModel;
  1407 	};
  1408 
  1409 CTestScreenDevice::CTestScreenDevice(CWsScreenDevice* aDevice,RDrawableWindow& aWin):
  1410 	iWin(aWin)
  1411 	{
  1412 	iDevice=aDevice;
  1413 	iModel.iUid=TUid::Null();
  1414 	}
  1415 
  1416 TInt CTestScreenDevice::CreateContext(CGraphicsContext*& aGc)
  1417 	{
  1418 
  1419 	TInt ret=iDevice->CreateContext(aGc);
  1420 	((CWindowGc *) aGc)->Activate(iWin);
  1421 	return ret;
  1422 	}
  1423 
  1424 /**
  1425 @SYMTestCaseID          SYSLIB-FORM-UT-3496
  1426 @SYMTestCaseDesc        Testing the fix for PDEF108443: Two same content pages are printed when contact fields are exactly one page long
  1427 @SYMTestPriority        Medium
  1428 @SYMTestActions         Creates text paginators and tests resulting number of pages when there is text to 'full page - 1 line', full page and full page + 1 line of text.
  1429 @SYMTestExpectedResults Results should be 1 page, 1 page and 2 pages respectively.
  1430 @SYMDEF                 PDEF108443
  1431 */
  1432 void CTextViewTest::TestForPDEF108443L()
  1433 	{
  1434 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-3496 Testing fix for PDEF108443 "));
  1435 	CTestScreenDevice* screenDevice = new(ELeave) CTestScreenDevice(iEnv.ScreenDevice(),iWindow);
  1436 
  1437 	TMargins margins;
  1438 	margins.iTop = 1440;
  1439 	margins.iBottom = 1440;
  1440 	margins.iLeft = 1440;
  1441 	margins.iRight = 1440;
  1442 	TSize s(11906,16838);
  1443 	TPageSpec p(TPageSpec::EPortrait, s);
  1444 
  1445 	CArrayFixFlat<TInt>* charsPerPage1 = new(ELeave) CArrayFixFlat<TInt>(KGranularity);
  1446 	CTextPaginator* paginator1 = CTextPaginator::NewL(screenDevice, charsPerPage1, KPaginatePriority);
  1447 	paginator1->SetPageMarginsInTwips(margins);
  1448 	paginator1->SetPageSpecInTwips(p);
  1449 
  1450 	CArrayFixFlat<TInt>* charsPerPage2 = new(ELeave) CArrayFixFlat<TInt>(KGranularity);
  1451 	CTextPaginator* paginator2 = CTextPaginator::NewL(screenDevice, charsPerPage2, KPaginatePriority);
  1452 	paginator2->SetPageMarginsInTwips(margins);
  1453 	paginator2->SetPageSpecInTwips(p);
  1454 
  1455 	CArrayFixFlat<TInt>* charsPerPage3 = new(ELeave) CArrayFixFlat<TInt>(KGranularity);
  1456 	CTextPaginator* paginator3 = CTextPaginator::NewL(screenDevice, charsPerPage3, KPaginatePriority);
  1457 	paginator3->SetPageMarginsInTwips(margins);
  1458 	paginator3->SetPageSpecInTwips(p);
  1459 
  1460 
  1461 	// We need to find out the height of lines and print area of the page.
  1462 	// From this we determine how many lines *should* appear on the page.
  1463 	// This differs between devices(ie. hw and winscw).
  1464 	TRect textRect;
  1465 	textRect.iTl.iX=margins.iLeft;
  1466 	textRect.iTl.iY=margins.iTop;
  1467 	textRect.iBr.iX=s.iWidth-margins.iRight;
  1468 	textRect.iBr.iY=s.iHeight-margins.iBottom;
  1469 	
  1470 	textRect = screenDevice->TwipsToPixels(textRect);  //defect 131765, call the same func as paginator
  1471 	TInt pageHeight =  textRect.Height();
  1472 	_LIT(KDummyString,"AAAAAA");
  1473 	InitializeL();
  1474 	AddTextL(KDummyString);
  1475 	TInt lineHeight = 0;
  1476 	CParaFormat* paraFormat = CParaFormat::NewL();
  1477 	iEtext->GetParagraphFormatL(paraFormat,0);
  1478 	TBool pageBreakChar = EFalse;
  1479 	TInt docPos = 0;
  1480 	iLayout->FormatLineL(paraFormat,docPos,lineHeight,pageBreakChar);
  1481 
  1482 
  1483 	TInt numLines = pageHeight/lineHeight; // Number of lines expected on a page with paginator settings defined above and line height = 21
  1484 	TChar simpleChar('A');
  1485 	TBuf<200> string1;
  1486 	for (TInt i = 0; i < numLines-2; i++) // ...numlines - 1
  1487 		{
  1488 		string1.Append(simpleChar);
  1489 		string1.Append(CEditableText::EParagraphDelimiter);
  1490 		}
  1491 		string1.Append(simpleChar); // final line
  1492 	TBuf<200> string2;
  1493 	for (TInt i = 0; i < numLines-1; i++) // ...numlines
  1494 		{
  1495 		string2.Append(simpleChar);
  1496 		string2.Append(CEditableText::EParagraphDelimiter);
  1497 		}
  1498 		string2.Append(simpleChar); // final line
  1499 	TBuf<200> string3;
  1500 	for (TInt i = 0; i < numLines; i++) // ...numlines + 1
  1501 		{
  1502 		string3.Append(simpleChar);
  1503 		string3.Append(CEditableText::EParagraphDelimiter);
  1504 		}
  1505 		string3.Append(simpleChar); // final line
  1506 
  1507 	InitializeL();
  1508 	AddTextL(string1);
  1509 	paginator1->SetDocumentL(iEtext);
  1510 	docPos=0;
  1511 	paginator1->AppendTextL(docPos);
  1512 	TInt numPages=paginator1->PaginationCompletedL();
  1513 	test(numPages==1);
  1514 	InitializeL();
  1515 	AddTextL(string2);
  1516 	paginator2->SetDocumentL(iEtext);
  1517 	docPos=0;
  1518 	paginator2->AppendTextL(docPos);
  1519 	numPages=paginator2->PaginationCompletedL();
  1520 	test(numPages==1);
  1521 	InitializeL();
  1522 	AddTextL(string3);
  1523 	paginator3->SetDocumentL(iEtext);
  1524 	docPos=0;
  1525 	paginator3->AppendTextL(docPos);
  1526 	numPages=paginator3->PaginationCompletedL();
  1527 	test(numPages==2);
  1528 
  1529 	delete charsPerPage1;
  1530 	delete charsPerPage2;
  1531 	delete charsPerPage3;
  1532 	delete screenDevice;
  1533 	delete paraFormat;
  1534 	Destroy();
  1535 	}
  1536 
  1537 /**
  1538 @SYMTestCaseID          SYSLIB-FORM-UT-4002
  1539 @SYMTestCaseDesc	    Test to ensure the CTextView::SetSelectionVisibilityL will not panic when EFTextVisible
  1540 						is set off.
  1541 @SYMTestPriority 	    Normal
  1542 @SYMTestActions  	    Create a CTextView instance with EFTextVisible set off. Call SetSelectionVisibilityL(ETrue)
  1543 						and SetSelectionVisibilityL(EFalse).
  1544 @SYMTestExpectedResults	Given conditions in test actions, calling SetSelectionVisibilityL should not panic.
  1545 @SYMDEF                 PDEF113755
  1546 */
  1547 void CTextViewTest::TestForPDEF113755L()
  1548 	{
  1549 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-4002 Testing fix for PDEF113755 "));
  1550 	InitializeL();
  1551 
  1552 	TCursorSelection selection(0,8); // length of selection must be >0
  1553 	iView->SetSelectionL(selection);
  1554 
  1555 	iView->MakeVisible(ETrue);	//Test if the EFSelectionVisible flag is set correctly
  1556 	iView->SetSelectionVisibilityL(ETrue);
  1557 	test(iView->SelectionVisible());
  1558 	iView->SetSelectionVisibilityL(EFalse);
  1559 	test(!iView->SelectionVisible());
  1560 
  1561 	iView->MakeVisible(EFalse);
  1562 	iView->SetSelectionVisibilityL(ETrue); //Should never panic form::1200 here
  1563 	iView->SetSelectionVisibilityL(EFalse);
  1564 
  1565 	Destroy();
  1566 	}
  1567 
  1568 /**
  1569 @SYMTestCaseID          SYSLIB-FORM-UT-4004
  1570 @SYMTestCaseDesc	    Test for INC113143, to ensure CTextLayout::GetLineRectL returns the correct rectangle
  1571 						regarding the writting direction of text. Depend on Platform: WINSCW/H4/H6(DEF131765).
  1572 @SYMTestPriority 	    Normal
  1573 @SYMTestActions  	    Tested 16 scenarios that the CTextLayout::GetLineRectL could be call, also tested for
  1574 						edge cases such as 1 char, whole line, DocPos2 < DocPos1, etc..
  1575 @SYMTestExpectedResults CTextLayout::GetLineRectL should return expected rectangles.
  1576 @SYMDEF                 PDEF115165
  1577 */
  1578 void CTextViewTest::TestForPDEF115165L()
  1579 	{
  1580 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-4004 Testing fix for PDEF115165 "));
  1581 	InitializeL();
  1582 
  1583 	TCharFormat charFormat = TCharFormat(_L("Arial"),100);
  1584 	TCharFormatMask charFormatMask;
  1585 	charFormatMask.SetAll();
  1586 	iCharLayer->SetL(charFormat, charFormatMask);
  1587 	iEtext->SetGlobalCharFormat(iCharLayer);
  1588 	_LIT(KLtoRChar,"a");
  1589 	_LIT(KRtoLChar,"\x6B2");
  1590 	_LIT(KLtoRText,"aaa");
  1591 	_LIT(KRtoLText,"\x6B2\x6B2\x6B2");
  1592 	_LIT(KParaSep, "\x2029");
  1593 
  1594 	TRect rect;
  1595 
  1596 //  Test for 16 scenarios of Bidi texts..
  1597 //	Sample text for test
  1598 //	Doc_Pos:    | 0| 1| 2| 5| 4| 3| 6| 7| 8|11|10| 9|
  1599 //	X-Coords:  |0| 5|10|15|20|25|30|35|40|45|50|55|60|  in case w=5
  1600 
  1601 	iEtext->Reset();
  1602 	iEtext->InsertL(0,KLtoRText);
  1603 	iEtext->InsertL(iEtext->DocumentLength(),KRtoLText);
  1604 	iEtext->InsertL(iEtext->DocumentLength(),KLtoRText);
  1605 	iEtext->InsertL(iEtext->DocumentLength(),KRtoLText);
  1606 	iEtext->InsertL(iEtext->DocumentLength(),KParaSep);
  1607 	iView->FormatTextL();
  1608 
  1609 	TPoint point1,point2;
  1610 	iLayout->DocPosToXyPosL(0,point1);
  1611 	iLayout->DocPosToXyPosL(1,point2);
  1612 
  1613 	TInt wLTR = point2.iX - point1.iX;		//It depends on platform. WINSCW/H4 w=5; H6 w=4
  1614 	
  1615 	iLayout->DocPosToXyPosL(5,point1);
  1616 	iLayout->DocPosToXyPosL(4,point2);
  1617 	TInt wRTL = point2.iX - point1.iX;        //It depends on platform. WINSCW/H4 w=5; H6 w=4
  1618 	RDebug::Print(_L("wLTR %d,wRTL %d"), wLTR,wRTL);
  1619 
  1620 	//  DocPos1 is LTR, DocPos1+1 is LTR, DocPos2 is LTR, DocPos2+1 is RTL
  1621     rect = iLayout->GetLineRectL(0,2);
  1622     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1623     test(rect.iTl.iX == 0 && rect.iBr.iX == 3*wLTR);
  1624 
  1625     //  DocPos1 is LTR, DocPos1+1 is LTR, DocPos2 is RTL, DocPos2+1 is RTL
  1626     rect = iLayout->GetLineRectL(0,4);
  1627     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1628     test(rect.iTl.iX == 0 && rect.iBr.iX == 3*wLTR + 2*wRTL);
  1629 
  1630     //  DocPos1 is LTR, DocPos1+1 is LTR, DocPos2 is RTL, DocPos2+1 is LTR
  1631     rect = iLayout->GetLineRectL(0,5);
  1632     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1633     test(rect.iTl.iX == 0 && rect.iBr.iX == 3*wLTR + wRTL);
  1634     
  1635     //	DocPos1 is LTR, DocPos1+1 is LTR, DocPos2 is LTR, DocPos2+1 is LTR
  1636 	rect = iLayout->GetLineRectL(0,7);
  1637     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1638 	test(rect.iTl.iX == 0 && rect.iBr.iX == 3*wLTR + 3*wRTL + 2*wLTR);
  1639 	
  1640 //	DocPos1 is LTR, DocPos1+1 is RTL, DocPos2 is LTR, DocPos2+1 is LTR
  1641 	rect = iLayout->GetLineRectL(2,7);
  1642 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1643 	test(rect.iTl.iX == 2*wLTR && rect.iBr.iX == 3*wLTR + 3*wRTL + 2*wLTR);
  1644 
  1645 //	DocPos1 is LTR, DocPos1+1 is RTL, DocPos2 is LTR, DocPos2+1 is RTL
  1646 	rect = iLayout->GetLineRectL(2,8);
  1647 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1648 	test(rect.iTl.iX == 2*wLTR && rect.iBr.iX == 3*wLTR + 3*wRTL + 3*wLTR);
  1649 
  1650 //	DocPos1 is LTR, DocPos1+1 is RTL, DocPos2 is RTL, DocPos2+1 is LTR
  1651 	rect = iLayout->GetLineRectL(2,5);
  1652 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1653 	test(rect.iTl.iX == 2*wLTR && rect.iBr.iX == 3*wLTR + wRTL);
  1654 
  1655 //	DocPos1 is LTR, DocPos1+1 is RTL, DocPos2 is RTL, DocPos2+1 is RTL
  1656 	rect = iLayout->GetLineRectL(2,4);
  1657 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1658 	test(rect.iTl.iX == 2*wLTR && rect.iBr.iX == 3*wLTR + 2*wRTL);
  1659 
  1660 //	Sample text for test
  1661 //	Doc_Pos:     | 9|10|11| 8| 7| 6| 3| 4| 5| 2| 1| 0|
  1662 //	X-Coords:  |40|45|50|55|60|65|70|75|80|85|90|95|100|     in case w=5
  1663 
  1664 	iEtext->Reset();
  1665 	iEtext->InsertL(0,KRtoLText);
  1666 	iEtext->InsertL(iEtext->DocumentLength(),KLtoRText);
  1667 	iEtext->InsertL(iEtext->DocumentLength(),KRtoLText);
  1668 	iEtext->InsertL(iEtext->DocumentLength(),KLtoRText);
  1669 	iEtext->InsertL(iEtext->DocumentLength(),KParaSep);
  1670 	iView->FormatTextL();
  1671 	
  1672 //	DocPos1 is RTL, DocPos1+1 is LTR, DocPos2 is LTR, DocPos2+1 is LTR
  1673 	rect = iLayout->GetLineRectL(2,4);
  1674 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);	
  1675 	test(rect.iTl.iX == iWindowRect.Width() - 3*wRTL - 2*wLTR && rect.iBr.iX == iWindowRect.Width() - 2*wRTL);
  1676 			
  1677 //	DocPos1 is RTL, DocPos1+1 is LTR, DocPos2 is LTR, DocPos2+1 is RTL
  1678 	rect = iLayout->GetLineRectL(2,5);
  1679 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);	
  1680 	test(rect.iTl.iX == iWindowRect.Width() - 3*wRTL - wLTR && rect.iBr.iX == iWindowRect.Width() - 2*wRTL);
  1681 
  1682 //	DocPos1 is RTL, DocPos1+1 is LTR, DocPos2 is RTL, DocPos2+1 is LTR
  1683 	rect = iLayout->GetLineRectL(2,8);
  1684 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);	
  1685 	test(rect.iTl.iX == iWindowRect.Width() - 3*wRTL - 3*wLTR - 3*wRTL && rect.iBr.iX == iWindowRect.Width() - 2*wRTL);
  1686 
  1687 //	DocPos1 is RTL, DocPos1+1 is LTR, DocPos2 is RTL, DocPos2+1 is RTL
  1688 	rect = iLayout->GetLineRectL(2,7);
  1689 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1690 	test(rect.iTl.iX == iWindowRect.Width() - 3*wRTL - 3*wLTR - 2*wRTL && rect.iBr.iX == iWindowRect.Width() - 2*wRTL);
  1691 
  1692 //	DocPos1 is RTL, DocPos1+1 is RTL, DocPos2 is LTR, DocPos2+1 is LTR
  1693 	rect = iLayout->GetLineRectL(0,4);
  1694 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);	
  1695 	test(rect.iTl.iX == iWindowRect.Width() - 3*wRTL - 2*wLTR && rect.iBr.iX == 100);
  1696 
  1697 //	DocPos1 is RTL, DocPos1+1 is RTL, DocPos2 is LTR, DocPos2+1 is RTL
  1698 	rect = iLayout->GetLineRectL(0,5);
  1699 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1700 	test(rect.iTl.iX == iWindowRect.Width() - 3*wRTL - wLTR && rect.iBr.iX == 100);
  1701 
  1702 //	DocPos1 is RTL, DocPos1+1 is RTL, DocPos2 is RTL, DocPos2+1 is LTR
  1703 	rect = iLayout->GetLineRectL(0,8);
  1704 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);	
  1705 	test(rect.iTl.iX == iWindowRect.Width() - 3*wRTL - 3*wLTR - 3*wRTL && rect.iBr.iX == 100);
  1706 
  1707 //	DocPos1 is RTL, DocPos1+1 is RTL, DocPos2 is RTL, DocPos2+1 is RTL
  1708 	rect = iLayout->GetLineRectL(0,7);
  1709 	RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);	
  1710 	test(rect.iTl.iX == iWindowRect.Width() - 3*wRTL - 3*wLTR - 2*wRTL && rect.iBr.iX == 100);
  1711 	
  1712 
  1713 	
  1714 //	Edge case tests
  1715 //	Sample text
  1716 //	1st Line:    | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|19|18|17|16|15|14|13|12|
  1717 //	X-Coords:  | 0| 5|10|15|20|25|30|35|40|45|50|55|60|65|70|75|80|85|90|95|100|   in case w=5
  1718 //	2nd Line:    |23|22|21|20|
  1719 	
  1720 //	Edge case tests
  1721 //	Sample text
  1722 //	1st Line:    | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|24|23|22|21|20|19|18|17|16|15|
  1723 //	X-Coords:  | 0| 4| 8|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96|100|  w=4
  1724 //	2nd Line:    |29|28|27|26|25|24|23|22|21|20|
  1725 	
  1726 	TInt LtoRLength = (iWindowRect.Width() - 5*wRTL)/wLTR;
  1727 	TInt RtoLLength = 10;
  1728 	TInt RtoLinLine1= (iWindowRect.Width() - LtoRLength * wLTR)/wRTL;
  1729 	TInt Line2Start = LtoRLength + RtoLinLine1;
  1730 	
  1731 	iEtext->Reset();
  1732 	for(TInt i=0;i<LtoRLength;i++)
  1733         {
  1734         iEtext->InsertL(iEtext->DocumentLength(),KLtoRChar);
  1735         }
  1736 	
  1737 	for(TInt i=0;i<RtoLLength;i++)
  1738 	    {
  1739 	    iEtext->InsertL(iEtext->DocumentLength(),KRtoLChar);
  1740 	    }	
  1741 	iEtext->InsertL(iEtext->DocumentLength(),KParaSep);
  1742 	iView->FormatTextL();
  1743 
  1744     for(TInt i=0;i<LtoRLength + RtoLLength;i++)
  1745     {
  1746         rect = iLayout->GetLineRectL(i,i+1);
  1747         RDebug::Print(_L("%d: iTl.iX %d,iY %d, iBr.iX %d,iY %d"), i,rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1748     }          
  1749     
  1750     rect = iLayout->GetLineRectL(0,LtoRLength);
  1751     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);    
  1752     test(rect.iTl.iX == 0 && rect.iBr.iX == LtoRLength*wLTR + RtoLinLine1*wRTL ); //Line 1
  1753   
  1754     rect = iLayout->GetLineRectL(Line2Start, LtoRLength + RtoLLength);
  1755     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1756     test(rect.iTl.iX == 0 && rect.iBr.iX == (RtoLLength - RtoLinLine1)*wRTL); //Line 2
  1757 
  1758     rect = iLayout->GetLineRectL(0,0);
  1759     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);    
  1760     test(rect.iTl.iX == 0 && rect.iBr.iX == wLTR); //first char
  1761     
  1762     //firt char of RTL
  1763     rect = iLayout->GetLineRectL(LtoRLength,LtoRLength);
  1764     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);    
  1765     test(rect.iTl.iX == LtoRLength*wLTR + (RtoLinLine1-1)*wRTL && rect.iBr.iX == LtoRLength*wLTR + RtoLinLine1*wRTL); //end of line 1
  1766 
  1767     //middle of L to R
  1768     rect = iLayout->GetLineRectL(LtoRLength/2,LtoRLength/2);
  1769     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);    
  1770     test(rect.iTl.iX == LtoRLength/2 * wLTR && rect.iBr.iX == (LtoRLength/2+1) * wLTR);
  1771       
  1772     //middle of LTR to first of RTL
  1773     rect = iLayout->GetLineRectL(LtoRLength/2,LtoRLength);
  1774     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);    
  1775     test(rect.iTl.iX == LtoRLength/2 * wLTR && rect.iBr.iX == LtoRLength*wLTR + RtoLinLine1*wRTL);
  1776  
  1777     //second of RTL to start of 2nd line ??
  1778     rect = iLayout->GetLineRectL(LtoRLength+1,Line2Start);
  1779     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);    
  1780     test(rect.iTl.iX == LtoRLength*wLTR + (RtoLinLine1-1)*wRTL && rect.iBr.iX == LtoRLength*wLTR + RtoLinLine1*wRTL); //end of line 1
  1781   
  1782     //middle of L to R
  1783     rect = iLayout->GetLineRectL(LtoRLength/2,LtoRLength/2-1);
  1784     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);    
  1785     test(rect.iTl.iX == LtoRLength/2 * wLTR && rect.iBr.iX == LtoRLength*wLTR + RtoLinLine1*wRTL);
  1786     
  1787 		
  1788 //	Test for edge cases while two lines are in different direction
  1789 //	Sample text
  1790 //	1st Line:    | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15|16|17|18|19|
  1791 //	X-Coords:  | 0| 5|10|15|20|25|30|35|40|45|50|55|60|65|70|75|80|85|90|95|100|  in case w=5
  1792 //	2nd Line:    |39|38|37|36|35|34|33|32|31|30|29|28|27|26|25|24|23|22|21|20|
  1793 		
  1794 //	Test for edge cases while two lines are in different direction
  1795 //  Sample text
  1796 //	1st Line:    | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|
  1797 //	X-Coords:  | 0| 4| 8| 12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96|100|  w=4
  1798 //	2nd Line:    |49|48|47|46|45|44|43|42|41|40|39|38|37|36|35|34|33|32|31|30|29|28|27|26|25|
  1799     
  1800     LtoRLength = iWindowRect.Width()/wLTR;
  1801     RtoLLength = iWindowRect.Width()/wRTL;
  1802         
  1803     iEtext->Reset();
  1804     for(TInt i=0;i<LtoRLength;i++)
  1805         {
  1806         iEtext->InsertL(iEtext->DocumentLength(),KLtoRChar);
  1807         }
  1808     
  1809     for(TInt i=0;i<RtoLLength;i++)
  1810         {
  1811         iEtext->InsertL(iEtext->DocumentLength(),KRtoLChar);
  1812         }       
  1813 	iEtext->InsertL(iEtext->DocumentLength(),KParaSep);
  1814 	iView->FormatTextL();
  1815 
  1816     for(TInt i=0;i<LtoRLength + RtoLLength;i++)
  1817     {
  1818         rect = iLayout->GetLineRectL(i,i+1);
  1819         RDebug::Print(_L("%d: iTl.iX %d,iY %d, iBr.iX %d,iY %d"), i,rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1820     }  
  1821  
  1822     
  1823     //1st line
  1824     rect = iLayout->GetLineRectL(3, LtoRLength-1);
  1825     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1826     test(rect.iTl.iX == 3*wLTR && rect.iBr.iX == LtoRLength*wLTR); //Line 2
  1827 
  1828     //2nd line
  1829     rect = iLayout->GetLineRectL(LtoRLength,LtoRLength + RtoLLength -2);
  1830     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1831     test(rect.iTl.iX == wRTL && rect.iBr.iX == RtoLLength*wRTL); //Line 2
  1832 
  1833     //end of 1st line
  1834     rect = iLayout->GetLineRectL(LtoRLength-1, LtoRLength-1);
  1835     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1836     test(rect.iTl.iX == (LtoRLength-1)*wLTR && rect.iBr.iX == LtoRLength*wLTR); //Line 2
  1837 
  1838     //start of 2nd line
  1839     rect = iLayout->GetLineRectL(LtoRLength, LtoRLength);
  1840     RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1841     test(rect.iTl.iX == (RtoLLength-1)*wRTL && rect.iBr.iX == RtoLLength*wRTL); //Line 2
  1842 
  1843      //1st line to 2nd line
  1844      rect = iLayout->GetLineRectL(LtoRLength-1, LtoRLength);
  1845      RDebug::Print(_L("iTl.iX %d,iY %d, iBr.iX %d,iY %d"), rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
  1846      test(rect.iTl.iX == (LtoRLength-1)*wLTR && rect.iBr.iX == LtoRLength*wLTR); //Line 2
  1847 
  1848 
  1849 	}
  1850 
  1851 /**
  1852 @SYMTestCaseID          SYSLIB-FORM-UT-4007
  1853 @SYMTestCaseDesc	    Test for PDEF118443
  1854 @SYMTestPriority 	    Normal
  1855 @SYMTestActions			Use test cases in form of "text + ZWJ + non-text characters", format the line,
  1856  						then use CTmTextLayout::FindAdjacentChunks() to find text Chunks surrounding
  1857  						the ZWJ. then verify if the text is broken at the correct place.
  1858 @SYMTestExpectedResults CTmTextLayout::FindAdjacentChunks() should return:
  1859 						- Left chunk = "text + ZWJ",
  1860 						- Right chunk = "non-text characters".
  1861 @SYMDEF                 PDEF118443
  1862 */
  1863 void CTextViewTest::TestForPDEF118443L()
  1864 	{
  1865 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-4007 Testing fix for PDEF118443 "));
  1866 	InitializeL();
  1867 
  1868 	TCharFormat charFormat = TCharFormat(_L("ClearlyU"),10);
  1869 	TCharFormatMask charFormatMask;
  1870 	charFormatMask.SetAll();
  1871 	iCharLayer->SetL(charFormat, charFormatMask);
  1872 	iEtext->SetGlobalCharFormat(iCharLayer);
  1873 
  1874 	// Note: a 'W' is added at the front to make the text chunk have side-bearings, so that it won't be amalgamated
  1875 	// with the following chunk. This is to make the test case be as same as the original use case that caused the defect.
  1876 	_LIT(KScriptEndWithZWJ,"W\x0931\x094d\x200d");	// Scripte end with ZWJ (a 'W' in the front)
  1877 	_LIT(KTextTestCase0,"\x2029");	// Paragraph seperator (Bidi Category: B)
  1878 	_LIT(KTextTestCase1,"0");		// Digit 0 (Bidi Category: EN)
  1879 	_LIT(KTextTestCase2,"+");		// Plus sign (Bidi Category: ES)
  1880 	_LIT(KTextTestCase3,"\u00A3");		// Pound symbol (Bidi Category: ET)
  1881 	_LIT(KTextTestCase4,".");		// Period (Bidi Category: CS)
  1882 	_LIT(KTextTestCase5,"\x0009");	// Tab (Bidi Category: S)
  1883 	_LIT(KTextTestCase6,"\x0020");	// Space (Bidi Category: WS)
  1884 	_LIT(KTextTestCase7,"\x000C");	// Form feed (Bidi Category: WS)
  1885 	_LIT(KTextTestCase8,"\x2028");	// Line breaker (Bidi Category: WS)
  1886 
  1887 	TTmDocPosSpec pos(4, TTmDocPosSpec::ETrailing);
  1888 	CTmTextLayout::TTmChunkDescription left;
  1889 	CTmTextLayout::TTmChunkDescription right;
  1890 
  1891 	// Test case 0: ZWJ + Paragraph seperater
  1892 	iEtext->Reset();
  1893 	iEtext->InsertL(0,KScriptEndWithZWJ);
  1894 	iEtext->InsertL(iEtext->DocumentLength(),KTextTestCase0);
  1895 	iView->FormatTextL();
  1896 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  1897 	test(left.iStart == 0);
  1898 	test(left.iEnd == 4);
  1899 	test(left.iRightToLeft == EFalse);
  1900 	test(right.iStart == 4);
  1901 	test(right.iRightToLeft == EFalse);
  1902 
  1903 	// Test case 1: ZWJ + Digit '0'
  1904 	iEtext->Reset();
  1905 	iEtext->InsertL(0,KScriptEndWithZWJ);
  1906 	iEtext->InsertL(iEtext->DocumentLength(),KTextTestCase1);
  1907 	iView->FormatTextL();
  1908 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  1909 	test(left.iStart == 0);
  1910 	test(left.iEnd == 4);
  1911 	test(left.iRightToLeft == EFalse);
  1912 	test(right.iStart == 4);
  1913 	test(right.iRightToLeft == EFalse);
  1914 
  1915 	// Test case 2: ZWJ + Plus sign '+'
  1916 	iEtext->Reset();
  1917 	iEtext->InsertL(0,KScriptEndWithZWJ);
  1918 	iEtext->InsertL(iEtext->DocumentLength(),KTextTestCase2);
  1919 	iView->FormatTextL();
  1920 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  1921 	test(left.iStart == 0);
  1922 	test(left.iEnd == 4);
  1923 	test(left.iRightToLeft == EFalse);
  1924 	test(right.iStart == 4);
  1925 	test(right.iRightToLeft == EFalse);
  1926 
  1927 	// Test case 3: ZWJ + Pound symbol '??'
  1928 	iEtext->Reset();
  1929 	iEtext->InsertL(0,KScriptEndWithZWJ);
  1930 	iEtext->InsertL(iEtext->DocumentLength(),KTextTestCase3);
  1931 	iView->FormatTextL();
  1932 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  1933 	test(left.iStart == 0);
  1934 	test(left.iEnd == 4);
  1935 	test(left.iRightToLeft == EFalse);
  1936 	test(right.iStart == 4);
  1937 	test(right.iRightToLeft == EFalse);
  1938 
  1939 	// Test case 0: ZWJ + Period '.'
  1940 	iEtext->Reset();
  1941 	iEtext->InsertL(0,KScriptEndWithZWJ);
  1942 	iEtext->InsertL(iEtext->DocumentLength(),KTextTestCase4);
  1943 	iView->FormatTextL();
  1944 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  1945 	test(left.iStart == 0);
  1946 	test(left.iEnd == 4);
  1947 	test(left.iRightToLeft == EFalse);
  1948 	test(right.iStart == 4);
  1949 	test(right.iRightToLeft == EFalse);
  1950 
  1951 	// Test case 0: ZWJ + Tab Character
  1952 	iEtext->Reset();
  1953 	iEtext->InsertL(0,KScriptEndWithZWJ);
  1954 	iEtext->InsertL(iEtext->DocumentLength(),KTextTestCase5);
  1955 	iView->FormatTextL();
  1956 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  1957 	test(left.iStart == 0);
  1958 	test(left.iEnd == 4);
  1959 	test(left.iRightToLeft == EFalse);
  1960 	test(right.iStart == 4);
  1961 	test(right.iRightToLeft == EFalse);
  1962 
  1963 	// Test case 0: ZWJ + Space
  1964 	iEtext->Reset();
  1965 	iEtext->InsertL(0,KScriptEndWithZWJ);
  1966 	iEtext->InsertL(iEtext->DocumentLength(),KTextTestCase6);
  1967 	iView->FormatTextL();
  1968 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  1969 	test(left.iStart == 0);
  1970 	test(left.iEnd == 4);
  1971 	test(left.iRightToLeft == EFalse);
  1972 	test(right.iStart == 4);
  1973 	test(right.iRightToLeft == EFalse);
  1974 
  1975 	// Test case 0: ZWJ + Form feed
  1976 	iEtext->Reset();
  1977 	iEtext->InsertL(0,KScriptEndWithZWJ);
  1978 	iEtext->InsertL(iEtext->DocumentLength(),KTextTestCase7);
  1979 	iView->FormatTextL();
  1980 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  1981 	test(left.iStart == 0);
  1982 	test(left.iEnd == 4);
  1983 	test(left.iRightToLeft == EFalse);
  1984 	test(right.iStart == 4);
  1985 	test(right.iRightToLeft == EFalse);
  1986 
  1987 	// Test case 0: ZWJ + Line breaker
  1988 	iEtext->Reset();
  1989 	iEtext->InsertL(0,KScriptEndWithZWJ);
  1990 	iEtext->InsertL(iEtext->DocumentLength(),KTextTestCase8);
  1991 	iView->FormatTextL();
  1992 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  1993 	test(left.iStart == 0);
  1994 	test(left.iEnd == 4);
  1995 	test(left.iRightToLeft == EFalse);
  1996 	test(right.iStart == 4);
  1997 	test(right.iRightToLeft == EFalse);
  1998 
  1999 	Destroy();
  2000 	}
  2001 
  2002 /**
  2003 @SYMTestCaseID          SYSLIB-FORM-UT-4016
  2004 @SYMTestCaseDesc        Testing the fix for PDEF121798 Printing: Email is printed only two pages 
  2005 @SYMTestPriority        Medium
  2006 @SYMTestActions         Paginates random amounts of text and checks whether the correct number of pages are returned from pagination.
  2007 @SYMTestExpectedResults The amount of pages produced by the paginator should match the expected number of pages based on lines of text, page size, etc.
  2008 @SYMDEF                 PDEF121798
  2009 */
  2010 void CTextViewTest::TestForPDEF121798L()
  2011 	{
  2012 	test.Next(_L("Testing fix for PDEF121798"));
  2013 	CTestScreenDevice* screenDevice = new(ELeave) CTestScreenDevice(iEnv.ScreenDevice(),iWindow);
  2014 		
  2015 	TMargins margins;
  2016 	margins.iTop = 1440;
  2017 	margins.iBottom = 1440;
  2018 	margins.iLeft = 1440;
  2019 	margins.iRight = 1440;
  2020 	TSize s(11906,16838);
  2021 	TPageSpec p(TPageSpec::EPortrait, s);
  2022 		
  2023 	// We need to find out the height of lines and print area of the page.
  2024 	// From this we determine how many lines *should* appear on the page.
  2025 	// This differs between devices(ie. hw and winscw).
  2026 	TInt pageHeight = screenDevice->VerticalTwipsToPixels(s.iHeight - margins.iTop - margins.iBottom);
  2027 	_LIT(KDummyString,"this is used by dummy paginator to find out line height and page size");
  2028 	InitializeL();
  2029 	AddTextL(KDummyString);
  2030 	TInt lineHeight = 0;	
  2031 	CParaFormat* paraFormat = CParaFormat::NewL();
  2032 	iEtext->GetParagraphFormatL(paraFormat,0);
  2033 	TBool pageBreakChar = EFalse;
  2034 	TInt docPos = 0;
  2035 	iLayout->FormatLineL(paraFormat,docPos,lineHeight,pageBreakChar);
  2036 	
  2037 	CArrayFixFlat<TInt>* charsPerPage = new(ELeave) CArrayFixFlat<TInt>(KGranularity);
  2038 	TInt numLines = pageHeight/lineHeight; // Number of lines expected on a page with paginator settings defined above and line height.
  2039 	
  2040 	
  2041 	
  2042 	// Perform 50 random pagination tests.
  2043 	for(TInt numTests = 0; numTests < 50; numTests++)
  2044 		{
  2045 		// Generate the number of lines in this document.
  2046 		TBuf<512> testString;
  2047 		TInt randomNum = (Math::Random() % 512);
  2048 		// Calculate the expected number of pages based on page size and line height
  2049 		TInt expectedPages = randomNum/numLines;
  2050 		// If it's not an exact fit there will be another page lost in the integer division.
  2051 		if ((numLines * expectedPages != randomNum) || randomNum == 0)
  2052 			{
  2053 			++expectedPages;
  2054 			}
  2055 		// Append the random number of lines to the test string
  2056 		for (TInt i = 0; i < randomNum-1; i++) // randomNum -1 because we add a character after the loop.
  2057 			{
  2058 			// Empty lines will do.
  2059 			testString.Append(CEditableText::EParagraphDelimiter);
  2060 			}
  2061 		// End the text with a character rather than a paragraph delim.
  2062 		testString.Append(_L("A"));
  2063 		
  2064 		
  2065 		InitializeL();
  2066 		AddTextL(testString);
  2067 		// Set up the paginator.
  2068 		CTextPaginator* paginator = CTextPaginator::NewL(screenDevice, charsPerPage, KPaginatePriority);
  2069 		paginator->SetPageMarginsInTwips(margins);
  2070 		paginator->SetPageSpecInTwips(p);
  2071 		paginator->SetDocumentL(iEtext);
  2072 		docPos=0;
  2073 		paginator->AppendTextL(docPos);
  2074 		TInt numPages=paginator->PaginationCompletedL();
  2075 		RDebug::Printf("%d lines: Expected %d pages, got %d pages", randomNum, expectedPages, numPages);
  2076 		test(expectedPages == numPages);
  2077 		delete paginator;
  2078 		}
  2079 	delete charsPerPage;
  2080 	delete screenDevice;
  2081 	delete paraFormat;
  2082 	Destroy();
  2083 	}
  2084 
  2085 /**
  2086 @SYMTestCaseID          SYSLIB-FORM-UT-4015
  2087 @SYMTestCaseDesc	    Test for PDEF120239
  2088 @SYMTestPriority 	    Normal
  2089 @SYMTestActions			Use text consist of "LTR text + ZWJ + RTL Text", format the line, then:
  2090 						1) use CTmTextLayout::FindAdjacentChunks() to find chunks around overlapped doc pos.
  2091 						2) use CTextView::MoveCursorL to move cursor through out the line.
  2092 @SYMTestExpectedResults 1) FindAdjacentChunks() returns correct chunks
  2093 						2) Cursor should moves Left to Right and Right to Left correctly
  2094 @SYMDEF                 PDEF120239
  2095 */
  2096 void CTextViewTest::TestForPDEF120239L()
  2097 	{
  2098 	test.Next(_L("Testing fix for PDEF120239L"));
  2099 	InitializeL();
  2100 	
  2101 	TCharFormat charFormat = TCharFormat(_L("NewTimes"),10);
  2102 	TCharFormatMask charFormatMask;
  2103 	charFormatMask.SetAll();
  2104 	iCharLayer->SetL(charFormat, charFormatMask);
  2105 	iEtext->SetGlobalCharFormat(iCharLayer);
  2106  	
  2107 	_LIT(KTestScript,"\x0931\x094d\x200d\x684");	// Test script (LTR text + ZWJ + RTL Text)
  2108 	
  2109 	iEtext->Reset();
  2110 	iEtext->InsertL(0,KTestScript);
  2111 	iView->FormatTextL();
  2112 	
  2113 	// 1) use CTmTextLayout::FindAdjacentChunks()
  2114 	CTmTextLayout::TTmChunkDescription left;
  2115 	CTmTextLayout::TTmChunkDescription right;
  2116 	
  2117 	TTmDocPosSpec pos(3, TTmDocPosSpec::ETrailing);
  2118 
  2119 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  2120 	test(left.iStart == 0);
  2121 	test(left.iEnd == 3);
  2122 	test(!left.iRightToLeft);
  2123 	test(right.iStart == 2);
  2124 	test(right.iEnd == 4);
  2125 	test(right.iRightToLeft);
  2126 	
  2127 	pos.iPos = 2;
  2128 	pos.iType = TTmDocPosSpec::ELeading;
  2129 	
  2130 	iLayout->TagmaTextLayout().FindAdjacentChunks(pos, left, right);
  2131 	test(left.iStart == 2);
  2132 	test(left.iEnd == 4);
  2133 	test(left.iRightToLeft);
  2134 	test(right.iStart == 4);
  2135 	test(right.iEnd == 5);
  2136 	test(!right.iRightToLeft);
  2137 	
  2138 	// 2) use CTextView::MoveCursorL to move cursor
  2139 	TTmDocPos cursorPos;
  2140 	TTmDocPos targetPos1 (0, ETrue);
  2141 	TTmDocPos targetPos2 (0, EFalse);
  2142 	TCursorPosition::TMovementType move = TCursorPosition::EFRight;
  2143 	
  2144 	TCursorSelection selection(0,0);
  2145 	iView->SetSelectionL(selection);
  2146 	iView->GetCursorPos(cursorPos);
  2147 	test(cursorPos == targetPos1 || cursorPos == targetPos2);
  2148 	
  2149 	targetPos1.iPos = 3;
  2150 	targetPos1.iLeadingEdge = EFalse;
  2151 	targetPos2.iPos = 4;
  2152 	targetPos2.iLeadingEdge = EFalse;
  2153 	iView->MoveCursorL(move, EFalse);
  2154 	iView->GetCursorPos(cursorPos);
  2155 	test(cursorPos == targetPos1 || cursorPos == targetPos2);
  2156 	
  2157 	targetPos1.iPos = 2;
  2158 	targetPos1.iLeadingEdge = ETrue;
  2159 	targetPos2.iPos = 4;
  2160 	targetPos2.iLeadingEdge = ETrue;
  2161 	iView->MoveCursorL(move, EFalse);
  2162 	iView->GetCursorPos(cursorPos);
  2163 	test(cursorPos == targetPos1 || cursorPos == targetPos2);
  2164 	
  2165 	move = TCursorPosition::EFLeft;
  2166 	
  2167 	targetPos1.iPos = 3;
  2168 	targetPos1.iLeadingEdge = EFalse;
  2169 	targetPos2.iPos = 4;
  2170 	targetPos2.iLeadingEdge = EFalse;
  2171 	iView->MoveCursorL(move, EFalse);
  2172 	iView->GetCursorPos(cursorPos);
  2173 	test(cursorPos == targetPos1 || cursorPos == targetPos2);
  2174 	
  2175 	targetPos1.iPos = 0;
  2176 	targetPos1.iLeadingEdge = EFalse;
  2177 	targetPos2.iPos = 0;
  2178 	targetPos2.iLeadingEdge = ETrue;
  2179 	iView->MoveCursorL(move, EFalse);
  2180 	iView->GetCursorPos(cursorPos);
  2181 	test(cursorPos == targetPos1 || cursorPos == targetPos2);
  2182 
  2183 	Destroy();
  2184 	}
  2185 
  2186 /**
  2187 @SYMTestCaseID          SYSLIB-FORM-UT-4021
  2188 @SYMTestCaseDesc	    Test for DEF124989, to ensure TFormAndEtextEditor::SetStyleHelperL has no 
  2189                         NULL-dereference issue.
  2190 @SYMTestPriority 	    Normal
  2191 @SYMTestActions  	    Call TFormAndEtextEditor::InsertTextL and pass in a style name which could 
  2192 						not be found in styleList.Then a NULL is generated.
  2193 @SYMTestExpectedResults No panic(KERN-EXEC 3) raised from this case.
  2194 @SYMDEF                 DEF124989
  2195 */
  2196 void CTextViewTest::TestForDEF124989L()
  2197 	{
  2198 	// Initialise CTextViewTest object for next test.
  2199 	InitializeL();
  2200 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-4021 Testing fix for DEF124989 "));
  2201 
  2202 	// Insert a one line paragraph into EText object and reformat view.
  2203 	_LIT(KTestParagraph, "This is a piece of text to test the character positioning API based in X,Y cocordinates.");
  2204 	iEtext->InsertL(0, KTestParagraph);
  2205 	
  2206 	TFormAndEtextEditor newEditor(*iView,*iEtext);
  2207 	
  2208 	CStyleList* styleList = CStyleList::NewL();
  2209 	CleanupStack::PushL(styleList);
  2210 	RParagraphStyleInfo paraStyleInfo(NULL,NULL);
  2211 
  2212 	// Appending the new style to stylelist
  2213 	styleList->AppendL(&paraStyleInfo);
  2214 	iEtext->SetStyleListExternallyOwned(*styleList);
  2215 	
  2216 	TPtrC ptr1(_L("Arial3"));
  2217 	// Inserting the text and applying the style specified(Arial3) 
  2218 	// which is not in syleList.  
  2219 	newEditor.InsertTextL(0, _L("Hello World"),&ptr1);
  2220 	
  2221 	// Clean up test object
  2222 	CleanupStack::PopAndDestroy();
  2223 	Destroy();
  2224 	}
  2225 
  2226 /**
  2227 @SYMTestCaseID                      SYSLIB-FORM-UT-4022
  2228 @SYMTestCaseDesc	    Test for DEF124975
  2229 @SYMTestPriority                       Normal
  2230 @SYMTestActions                      1) Call CTextLayout::AdjustVerticalAlignment() when there is no content
  2231                                                    2) Add Some random text and then call CTextLayout::AdjustVerticalAlignment()@SYMTestExpectedResults       There should be no panic during the process
  2232 @SYMDEF                                 DEF124975
  2233 */
  2234 void CTextViewTest::TestForDEF124975L()
  2235 	{
  2236 	test.Next(_L(" @SYMTestCaseID: Testing fix for coverity DEF124975 "));
  2237 	InitializeL();
  2238 	
  2239 	const TInt MaxTestCount = 50;
  2240 	const TInt MaxStringCount = 100;
  2241 	TInt TestCount = GetNumber(1, MaxTestCount);
  2242 	TInt StringCount = GetNumber(1, MaxStringCount);
  2243 	
  2244 	for(TInt i=0; i<TestCount; i++)
  2245 		{
  2246 		iLayout->AdjustVerticalAlignment(CParaFormat::ECustomAlign);
  2247 		}
  2248 	
  2249 	for(TInt i=0; i<TestCount; i++)
  2250 		{
  2251 		RBuf testString;
  2252 		testString.Create(StringCount);
  2253 		for(int i=0; i<testString.MaxLength(); i++)
  2254 			{
  2255 			TInt c = GetNumber(0, 0xffff);
  2256 			while ( IsSurrogate(c) )
  2257 			    c = GetNumber(0, 0xffff);
  2258 			testString.Append( c );
  2259 			}
  2260 		AddTextL(testString);
  2261 		iLayout->AdjustVerticalAlignment(CParaFormat::ECustomAlign);
  2262 		testString.Close();
  2263 		}
  2264 	
  2265 	Destroy();
  2266 	}
  2267 
  2268 void CTextViewTest::TestForDEF142286BounceScrollingL()
  2269     {
  2270     test.Next(_L(" Testing fix for DEF142286 which supports bounce scrolling feature "));
  2271     TestScrollDisplayPixelsNoLimitBordersL(10);
  2272     TestScrollDisplayPixelsNoLimitBordersL(50);
  2273     TestScrollDisplayPixelsNoLimitBordersL(100);
  2274     }
  2275 
  2276 void RunTestsL(CCoeEnv& aEnv)
  2277 	{
  2278 	CTextViewTest* t = new(ELeave) CTextViewTest(aEnv);
  2279 	CleanupStack::PushL(t);
  2280 	t->ConstructL();
  2281 	t->TestL();
  2282 	t->Test1L();
  2283 	t->TestCancelSelectionL();
  2284 	t->TestFinishBackgroundFormattingL();
  2285 	t->TestSetCursorVisibilityL();
  2286 	t->TestSetSelectionVisibilityL();
  2287 	t->TestEnablePictureFrameL();
  2288 	t->TestSetCursorWidthTypeL();
  2289 	t->TestParagraphRectL();
  2290 	t->TestDrawL();
  2291 	t->TestFormatTextL();
  2292 	t->TestHandleRangeFormatChangeL();
  2293 	t->TestHandleInsertDeleteL();
  2294 	t->TestHandleGlobalChangeL();
  2295 	t->TestHandleGlobalChangeNoRedrawL();
  2296 	t->TestScrollDisplayL();
  2297 	t->TestScrollDisplayPixelsL();
  2298 	t->TestScrollDisplayLinesL();
  2299 	t->TestScrollDisplayParagraphsL();
  2300 	t->TestMoveCursorL();
  2301 	t->TestSetSelectionL();
  2302 	t->TestMatchCursorHeightL();
  2303 	t->TestCalculateHorizontalExtremesL();
  2304 	t->TestXyPosToDocPosL();
  2305 	t->TestGetPictureRectangleL();
  2306 	t->TestGetPictureRectangle1L();
  2307 	//t->TestGetPictureRectangleDefectL();
  2308 	t->TestSetDisplayContextL();
  2309 	t->TestGetParaFormatL();
  2310 	t->TestGetLineRectL();
  2311 	t->TestForDEF003426L();
  2312 	t->TestForDEF038488L();
  2313 	t->FormAndEtextTestL();
  2314 	t->TestForINC092725L();
  2315 	t->TestForPDEF108443L();
  2316 	t->TestForPDEF113755L();
  2317 	t->TestForPDEF115165L();
  2318 	t->TestForPDEF118443L();
  2319 	t->TestForPDEF121798L();
  2320 	t->TestForDEF124989L();
  2321 	t->TestForPDEF120239L();
  2322 	t->TestForDEF124975L();
  2323     t->TestForDEF142286BounceScrollingL();
  2324 	CleanupStack::PopAndDestroy(t);
  2325 }
  2326 
  2327 TInt E32Main()
  2328 	{
  2329 	CCoeEnv* env=new CCoeEnv;
  2330 	TRAPD(err,
  2331 		env->ConstructL();
  2332 		RunTestsL(*env);
  2333 		);
  2334 	return err;
  2335 	}
  2336 
  2337 #if defined(__WINS__)
  2338 EXPORT_C TInt EntryPoint(TAny*) {return E32Main();}
  2339 #endif