textrendering/textformatting/test/src/TCustomCharMapping.cpp
branchRCL_3
changeset 16 748ec5531811
parent 0 1fb32624e06b
child 17 336bee5c2d35
equal deleted inserted replaced
10:f902e87c146f 16:748ec5531811
     1 /*
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 *
    13 *
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
       
    19 #include "TGraphicsContext.h"
       
    20 #include <e32std.h>
    18 #include <e32std.h>
    21 #include <e32test.h>
    19 #include <e32test.h>
    22 #include <frmtlay.h>
    20 #include <frmtlay.h>
    23 #include <frmtview.h>
    21 #include <frmtview.h>
    24 #include <frmconst.h>
    22 #include <frmconst.h>
    25 #include <txtlaydc.h>
    23 #include <txtlaydc.h>
    26 #include <txtetext.h>
    24 #include <txtetext.h>
    27 #include <w32std.h>
    25 #include <w32std.h>
    28 
    26 #include "TGraphicsContext.h"
    29 namespace LocalToFile
    27 #include "tcustomcharmapping.h"
       
    28 
       
    29 namespace LocalToTCustomCharMapping
    30 {
    30 {
    31 
       
    32 _LIT(KTCustomCharMapping, "TCustomCharMapping");
       
    33 const TInt KDisplayWidth = 202;
       
    34 const TInt KDisplayHeight = 100;
       
    35 const TInt KPictureCharacter = 0xFFFC;
       
    36 RTest test(KTCustomCharMapping);
       
    37 
       
    38 enum TTestNum
       
    39 	{
       
    40 	EDefaultBehaviourInvisible = 0,
       
    41 	EDefaultBehaviourVisible = 1,
       
    42 	ECustomRemappingInvisible = 2,
       
    43 	ECustomRemappingVisible = 3,
       
    44 	ENewTest = 4  //Test remapping with no custom remapper and some flags explicitly set to invisible
       
    45 	};
       
    46 
       
    47 
       
    48 class CPinkSquare : public CPicture
    31 class CPinkSquare : public CPicture
    49 	{
    32 	{
    50 public:
    33 public:
    51 	// Size of square in twips.
    34 	// Size of square in twips.
    52 	// 600 is 15 pixels using the standard test graphics device at
    35 	// 600 is 15 pixels using the standard test graphics device at
   149 private:
   132 private:
   150 	const TDesC* iDes;
   133 	const TDesC* iDes;
   151 	CParaFormat* iParagraphFormat;
   134 	CParaFormat* iParagraphFormat;
   152 	};
   135 	};
   153 }
   136 }
   154 using namespace LocalToFile;
   137 using namespace LocalToTCustomCharMapping;
   155 
   138 
   156 class CTestTextView	// slightly naughty
   139 class CTestTextView	// slightly naughty
   157 	{
   140 	{
   158 public:
   141 public:
   159 	static void SetContextForFlickerFreeRedraw(CTextView* aView, CBitmapContext* aContext)
   142 	static void SetContextForFlickerFreeRedraw(CTextView* aView, CBitmapContext* aContext)
   263 
   246 
   264 	CCustomRemapper::CCustomRemapper()
   247 	CCustomRemapper::CCustomRemapper()
   265 		{
   248 		{
   266 		}
   249 		}
   267 
   250 
   268 void DoTestL(TDes& aText, CTextLayout* /*aLayout*/, CTestGraphicsDevice* aDevice, CTextView* aView, TTestNum aTestNum)
   251 void CTCustomCharMappingStep::DoTestL(TDes& aText, CTextLayout* /*aLayout*/, CTestGraphicsDevice* aDevice, CTextView* aView, TTestNum aTestNum)
   269 	{
   252 	{
   270 	aText = KTestStrings[aTestNum][0];
   253 	aText = KTestStrings[aTestNum][0];
   271 	aDevice->LineArray().ResetLineArray();
   254 	aDevice->LineArray().ResetLineArray();
   272 	aView->HandleGlobalChangeL();
   255 	aView->HandleGlobalChangeL();
   273 	const TTestGCDisplayLine* line1 = &(aDevice->LineArray().Line(0));
   256 	const TTestGCDisplayLine* line1 = &(aDevice->LineArray().Line(0));
   274 	const TTestGCDisplayLine* line2 = aDevice->LineArray().Find(KTestStrings[aTestNum][1]);
   257 	const TTestGCDisplayLine* line2 = aDevice->LineArray().Find(KTestStrings[aTestNum][1]);
   275 	test(0 != line1);
   258 	TEST(0 != line1);
   276 	test(0 != line2);
   259 	TEST(0 != line2);
   277 	// Can't always do a direct comparison of lines because same string
   260 	// Can't always do a direct comparison of lines because same string
   278 	// may appear in more than one line, so compare contents
   261 	// may appear in more than one line, so compare contents
   279 	test(line1->iLineData.Compare(line2->iLineData) == 0);
   262 	TEST(line1->iLineData.Compare(line2->iLineData) == 0);
   280 	}
   263 	}
   281 
   264 
   282 
   265 
   283 /**
   266 /**
   284 @SYMTestCaseID SYSLIB-FORM-CT-0147
   267 @SYMTestCaseID SYSLIB-FORM-CT-0147
   286 @SYMTestPriority High
   269 @SYMTestPriority High
   287 @SYMTestActions  Test installation and deinstallation of custom remapper
   270 @SYMTestActions  Test installation and deinstallation of custom remapper
   288 @SYMTestExpectedResults The test must not fail.
   271 @SYMTestExpectedResults The test must not fail.
   289 @SYMPREQ 1128 Placeholders for invisible characers in rich text shall be customizable
   272 @SYMPREQ 1128 Placeholders for invisible characers in rich text shall be customizable
   290 */
   273 */
   291 void RunInstallationTestsL()
   274 void CTCustomCharMappingStep::RunInstallationTestsL()
   292 	{
   275 	{
   293 	// Note: If you need to move these heap checks any further "in" to focus
   276 	// Note: If you need to move these heap checks any further "in" to focus
   294 	// on a specific test then you will have to move all the setup code in as
   277 	// on a specific test then you will have to move all the setup code in as
   295 	// well - and still preserve the two different display widths in use
   278 	// well - and still preserve the two different display widths in use
   296 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-CT-0147 "));
   279     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FORM-CT-0147 "));
   297 	__UHEAP_MARK;
   280 	__UHEAP_MARK;
   298 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   281 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   299 	CleanupStack::PushL(scheduler);
   282 	CleanupStack::PushL(scheduler);
   300 	CActiveScheduler::Install(scheduler);
   283 	CActiveScheduler::Install(scheduler);
   301 	TBuf<100> text;
   284 	TBuf<100> text;
   315 
   298 
   316 	// OK, let's get down to testing
   299 	// OK, let's get down to testing
   317 	MFormCustomInvisibleCharacterRemapper* remapper;
   300 	MFormCustomInvisibleCharacterRemapper* remapper;
   318 	// read what the ptr is set to - check it is null
   301 	// read what the ptr is set to - check it is null
   319 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   302 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   320 	test.Next(_L("Test uninstalled"));
   303 	INFO_PRINTF1(_L("Test uninstalled"));
   321 	test(remapper == NULL);
   304 	TEST(remapper == NULL);
   322 
   305 
   323 	// install a custom remapper - get the ptr - check it is set
   306 	// install a custom remapper - get the ptr - check it is set
   324 	MFormCustomInvisibleCharacterRemapper* customRemapper = CCustomRemapper::NewL();
   307 	MFormCustomInvisibleCharacterRemapper* customRemapper = CCustomRemapper::NewL();
   325 	layout->SetCustomInvisibleCharacterRemapper(customRemapper);
   308 	layout->SetCustomInvisibleCharacterRemapper(customRemapper);
   326 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   309 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   327 	test.Next(_L("Test installed"));
   310 	INFO_PRINTF1(_L("Test installed"));
   328 	test(remapper == customRemapper);
   311 	TEST(remapper == customRemapper);
   329 
   312 
   330 	// set the ptr back to null (deinstall) - get the ptr - check it is null
   313 	// set the ptr back to null (deinstall) - get the ptr - check it is null
   331 	layout->SetCustomInvisibleCharacterRemapper(NULL);
   314 	layout->SetCustomInvisibleCharacterRemapper(NULL);
   332 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   315 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   333 	test.Next(_L("Test uninstalled again"));
   316 	INFO_PRINTF1(_L("Test uninstalled again"));
   334 	test(remapper == NULL);
   317 	TEST(remapper == NULL);
   335 
   318 
   336 	delete customRemapper;
   319 	delete customRemapper;
   337 
   320 
   338 	CleanupStack::PopAndDestroy(offScreenContext);
   321 	CleanupStack::PopAndDestroy(offScreenContext);
   339 	CleanupStack::PopAndDestroy(view);
   322 	CleanupStack::PopAndDestroy(view);
   350 @SYMTestPriority High
   333 @SYMTestPriority High
   351 @SYMTestActions  Test behaviour without custom remapper installed
   334 @SYMTestActions  Test behaviour without custom remapper installed
   352 @SYMTestExpectedResults The test must not fail.
   335 @SYMTestExpectedResults The test must not fail.
   353 @SYMPREQ 1128 Placeholders for invisible characers in rich text shall be customizable
   336 @SYMPREQ 1128 Placeholders for invisible characers in rich text shall be customizable
   354 */
   337 */
   355 void RunDefaultBehaviourTestsL()
   338 void CTCustomCharMappingStep::RunDefaultBehaviourTestsL()
   356 	{
   339 	{
   357 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-CT-0148 "));
   340     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FORM-CT-0148 "));
   358 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   341 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   359 	CleanupStack::PushL(scheduler);
   342 	CleanupStack::PushL(scheduler);
   360 	CActiveScheduler::Install(scheduler);
   343 	CActiveScheduler::Install(scheduler);
   361 	TBuf<100> text;
   344 	TBuf<100> text;
   362 	TDocModel docModel(text);
   345 	TDocModel docModel(text);
   374 	CTestTextView::SetContextForFlickerFreeRedraw(view, offScreenContext);
   357 	CTestTextView::SetContextForFlickerFreeRedraw(view, offScreenContext);
   375 
   358 
   376 	// Start by making sure no custom remapper is installed
   359 	// Start by making sure no custom remapper is installed
   377 	MFormCustomInvisibleCharacterRemapper* remapper;
   360 	MFormCustomInvisibleCharacterRemapper* remapper;
   378 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   361 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   379 	test(remapper == NULL);
   362 	TEST(remapper == NULL);
   380 
   363 
   381 	// Set all invisible characters to be invisible
   364 	// Set all invisible characters to be invisible
   382 	TNonPrintingCharVisibility visibility;
   365 	TNonPrintingCharVisibility visibility;
   383 	visibility.SetNoneVisible();
   366 	visibility.SetNoneVisible();
   384 	layout->SetNonPrintingCharsVisibility(visibility);
   367 	layout->SetNonPrintingCharsVisibility(visibility);
   385 
   368 
   386 	// Test remapping with no custom remapper and flags set to invisible
   369 	// Test remapping with no custom remapper and flags set to invisible
   387 	test.Next(_L("Test uninstalled behaviour - flags invisible"));
   370 	INFO_PRINTF1(_L("Test uninstalled behaviour - flags invisible"));
   388 	DoTestL(text, layout, device, view, EDefaultBehaviourInvisible);
   371 	DoTestL(text, layout, device, view, EDefaultBehaviourInvisible);
   389 
   372 
   390 	// Now set all invisible characters to be visible
   373 	// Now set all invisible characters to be visible
   391 	visibility.SetAllVisible();
   374 	visibility.SetAllVisible();
   392 	layout->SetNonPrintingCharsVisibility(visibility);
   375 	layout->SetNonPrintingCharsVisibility(visibility);
   393 
   376 
   394 	// Test remapping with no custom remapper and flags set to visible
   377 	// Test remapping with no custom remapper and flags set to visible
   395 	test.Next(_L("Test uninstalled behaviour - flags visible"));
   378 	INFO_PRINTF1(_L("Test uninstalled behaviour - flags visible"));
   396 	DoTestL(text, layout, device, view, EDefaultBehaviourVisible);
   379 	DoTestL(text, layout, device, view, EDefaultBehaviourVisible);
   397 
   380 
   398 	// Test remapping with no custom remapper and some flags explicitly set to invisible
   381 	// Test remapping with no custom remapper and some flags explicitly set to invisible
   399 	test.Next(_L("Test uninstalled behaviour - some flags invisible"));
   382 	INFO_PRINTF1(_L("Test uninstalled behaviour - some flags invisible"));
   400 	//Set all invisible characters to be visible
   383 	//Set all invisible characters to be visible
   401 	visibility.SetAllVisible();
   384 	visibility.SetAllVisible();
   402 	//Set some attributes explicitly to be invisible
   385 	//Set some attributes explicitly to be invisible
   403 	visibility.SetSpacesVisible(EFalse);
   386 	visibility.SetSpacesVisible(EFalse);
   404 	visibility.SetTabsVisible(EFalse);
   387 	visibility.SetTabsVisible(EFalse);
   426 @SYMTestPriority High
   409 @SYMTestPriority High
   427 @SYMTestActions  Test behaviour with custom remapper installed
   410 @SYMTestActions  Test behaviour with custom remapper installed
   428 @SYMTestExpectedResults The test must not fail.
   411 @SYMTestExpectedResults The test must not fail.
   429 @SYMPREQ 1128 Placeholders for invisible characers in rich text shall be customizable
   412 @SYMPREQ 1128 Placeholders for invisible characers in rich text shall be customizable
   430 */
   413 */
   431 void RunCustomBehaviourTestsL()
   414 void CTCustomCharMappingStep::RunCustomBehaviourTestsL()
   432 	{
   415 	{
   433 	// Note: If you need to move these heap checks any further "in" to focus
   416 	// Note: If you need to move these heap checks any further "in" to focus
   434 	// on a specific test then you will have to move all the setup code in as
   417 	// on a specific test then you will have to move all the setup code in as
   435 	// well - and still preserve the two different display widths in use
   418 	// well - and still preserve the two different display widths in use
   436 	test.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-CT-0149 "));
   419     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FORM-CT-0149 "));
   437 	__UHEAP_MARK;
   420 	__UHEAP_MARK;
   438 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   421 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   439 	CleanupStack::PushL(scheduler);
   422 	CleanupStack::PushL(scheduler);
   440 	CActiveScheduler::Install(scheduler);
   423 	CActiveScheduler::Install(scheduler);
   441 	TBuf<100> text;
   424 	TBuf<100> text;
   456 	// We need to install a custom remapper
   439 	// We need to install a custom remapper
   457 	MFormCustomInvisibleCharacterRemapper* remapper;
   440 	MFormCustomInvisibleCharacterRemapper* remapper;
   458 	MFormCustomInvisibleCharacterRemapper* customRemapper = CCustomRemapper::NewL();
   441 	MFormCustomInvisibleCharacterRemapper* customRemapper = CCustomRemapper::NewL();
   459 	layout->SetCustomInvisibleCharacterRemapper(customRemapper);
   442 	layout->SetCustomInvisibleCharacterRemapper(customRemapper);
   460 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   443 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   461 	test(remapper == customRemapper);
   444 	TEST(remapper == customRemapper);
   462 
   445 
   463 	// Set all invisible characters to be invisible
   446 	// Set all invisible characters to be invisible
   464 	TNonPrintingCharVisibility visibility;
   447 	TNonPrintingCharVisibility visibility;
   465 	visibility.SetNoneVisible();
   448 	visibility.SetNoneVisible();
   466 	layout->SetNonPrintingCharsVisibility(visibility);
   449 	layout->SetNonPrintingCharsVisibility(visibility);
   467 
   450 
   468 	// Test remapping with custom remapper and flags set to invisible
   451 	// Test remapping with custom remapper and flags set to invisible
   469 	test.Next(_L("Test installed behaviour - flags invisible"));
   452 	INFO_PRINTF1(_L("Test installed behaviour - flags invisible"));
   470 	DoTestL(text, layout, device, view, ECustomRemappingInvisible);
   453 	DoTestL(text, layout, device, view, ECustomRemappingInvisible);
   471 
   454 
   472 	// Now set all invisible characters to be visible
   455 	// Now set all invisible characters to be visible
   473 	visibility.SetAllVisible();
   456 	visibility.SetAllVisible();
   474 	layout->SetNonPrintingCharsVisibility(visibility);
   457 	layout->SetNonPrintingCharsVisibility(visibility);
   475 
   458 
   476 	// Test remapping with custom remapper and flags set to visible
   459 	// Test remapping with custom remapper and flags set to visible
   477 	test.Next(_L("Test installed behaviour - flags visible"));
   460 	INFO_PRINTF1(_L("Test installed behaviour - flags visible"));
   478 	DoTestL(text, layout, device, view, ECustomRemappingVisible);
   461 	DoTestL(text, layout, device, view, ECustomRemappingVisible);
   479 
   462 
   480 	// Now we are finished deinstall and delete it
   463 	// Now we are finished deinstall and delete it
   481 	layout->SetCustomInvisibleCharacterRemapper(NULL);
   464 	layout->SetCustomInvisibleCharacterRemapper(NULL);
   482 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   465 	remapper = layout->GetCustomInvisibleCharacterRemapper();
   483 	test(remapper == NULL);
   466 	TEST(remapper == NULL);
   484 	delete customRemapper;
   467 	delete customRemapper;
   485 
   468 
   486 	CleanupStack::PopAndDestroy(offScreenContext);
   469 	CleanupStack::PopAndDestroy(offScreenContext);
   487 	CleanupStack::PopAndDestroy(view);
   470 	CleanupStack::PopAndDestroy(view);
   488 	CleanupStack::PopAndDestroy(device);
   471 	CleanupStack::PopAndDestroy(device);
   489 	CleanupStack::PopAndDestroy(layout);
   472 	CleanupStack::PopAndDestroy(layout);
   490 	CleanupStack::PopAndDestroy(scheduler);
   473 	CleanupStack::PopAndDestroy(scheduler);
   491 	__UHEAP_MARKEND;
   474 	__UHEAP_MARKEND;
   492 	}
   475 	}
   493 
   476 
   494 
   477 CTCustomCharMappingStep::CTCustomCharMappingStep()
   495 TInt E32Main()
   478     {
   496 	{
   479     
   497 	__UHEAP_MARK;
   480     }
   498 	test.Title();
   481 
   499 	static CTrapCleanup* TrapCleanup = CTrapCleanup::New();
   482 TVerdict CTCustomCharMappingStep::doTestStepL()
   500 	test.Start(_L("Test installation/deinstallatiion"));
   483     {
   501 	TInt error = RFbsSession::Connect();
   484     SetTestStepResult(EPass);
   502 	if (error == KErrNotFound)
   485     INFO_PRINTF1(_L("Test installation/deinstallatiion"));
   503 		{
   486     TInt error = RFbsSession::Connect();
   504 		FbsStartup();
   487     if (error == KErrNotFound)
   505 		error = RFbsSession::Connect();
   488         {
   506 		}
   489         FbsStartup();
   507 	test(error == KErrNone);
   490         error = RFbsSession::Connect();
   508 	TRAP(error, RunInstallationTestsL());
   491         }
   509 	test(error == KErrNone);
   492     TEST(error == KErrNone);
   510 	test.Next(_L("Test uninstalled behaviour"));
   493     TRAP(error, RunInstallationTestsL());
   511 	TRAP(error, RunDefaultBehaviourTestsL());
   494     TEST(error == KErrNone);
   512 	test(error == KErrNone);
   495     INFO_PRINTF1(_L("Test uninstalled behaviour"));
   513 	test.Next(_L("Test behaviour with custom remapper installed"));
   496     TRAP(error, RunDefaultBehaviourTestsL());
   514 	TRAP(error, RunCustomBehaviourTestsL());
   497     TEST(error == KErrNone);
   515 	test(error == KErrNone);
   498     INFO_PRINTF1(_L("Test behaviour with custom remapper installed"));
   516 	RFbsSession::Disconnect();
   499     TRAP(error, RunCustomBehaviourTestsL());
   517 	test.End();
   500     TEST(error == KErrNone);
   518 	delete TrapCleanup;
   501     RFbsSession::Disconnect();
   519 	test.Close();
   502     return TestStepResult();
   520 	__UHEAP_MARKEND;
   503     }
   521 	User::Heap().Check();
       
   522 	return error;
       
   523 	}
       
   524 
       
   525 
       
   526 #if defined(__WINS__)
       
   527 EXPORT_C TInt EntryPoint(TAny*) {return E32Main();}
       
   528 #endif
       
   529