os/textandloc/fontservices/fontstore/tfs/t_cachedeletionprocess.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-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 * Cache Deletion for fntstore multi-processed test code
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22  @test
    23  @internalComponent - Internal Symbian test code
    24 */
    25 
    26 #include <e32base.h>
    27 #include <e32cons.h>
    28 #include <e32test.h>
    29 #include <e32std.h>
    30 #include <e32debug.h>
    31 #include "FNTSTORE.H"
    32 #include "FNTBODY.H"
    33 #include "FNTSTD.H"
    34 #include <fbs.h>
    35 #include <bitstd.h>
    36 #include <bitdev.h>
    37 
    38 _LIT(KOpenFont, "DejaVu Sans Condensed");
    39 
    40 #ifdef __WINSCW__
    41 //this is used for winscw breakpoints
    42 #define BR _asm( int 3);
    43 #endif
    44 
    45 
    46 /* it is expected that the main in this file will be called to test multiple 
    47 process output at the same time a process is being deleted (font and bitmap server
    48 disconnection.  There are  normally two instances of this process.  Two virtually
    49 identical processes are required to ensure that the session ID is the same.
    50 
    51 The first is with aThirdProcess set. This sets output to run in a loop until
    52 the timeout is completed.  These values  are input via program arguments.
    53 
    54 If aThirdProcess is false then only one font creation, draw text,
    55 font deletion cycle is completed. The test code will then repeatedly run
    56 this process with aThirdProcess set to false.
    57 */
    58 class TRunProc2: public CBase
    59 	{
    60 public:
    61 	static TRunProc2* NewL();
    62 	void RunTestL(TInt aThirdProcess, TInt aTimeout);
    63 	~TRunProc2();
    64 private:
    65 	TRunProc2(){};
    66 	void ConstructL();
    67 	void DrawText();
    68 	void CreateFont();
    69 
    70 private:
    71 	RFbsSession* iFbs;
    72 	CFbsBitGc* iGc;
    73 	CFbsScreenDevice* iDev;
    74 	};
    75 
    76 TRunProc2::~TRunProc2()
    77 	{
    78 	delete iGc;
    79 	delete iDev;
    80 	iFbs->Disconnect();
    81 	}
    82 
    83 void TRunProc2::ConstructL()
    84 	{
    85 	TInt err = RFbsSession::Connect();
    86 	User::LeaveIfError(err);
    87 	iFbs = RFbsSession::GetSession();
    88 	User::LeaveIfNull(iFbs);
    89 
    90 	TDisplayMode mode[13];
    91 	mode[0]=EGray2;
    92 	mode[1]=EGray4;
    93 	mode[2]=EGray16;
    94 	mode[3]=EGray256;
    95 	mode[4]=EColor16;
    96 	mode[5]=EColor256;
    97 	mode[6]=EColor64K;
    98 	mode[7]=EColor16M;
    99 	mode[8]=ERgb;
   100 	mode[9]=EColor4K;
   101 	mode[10]=EColor16MU;
   102 	mode[11]=EColor16MA;
   103 	mode[12]=EColor16MAP;
   104 	
   105 
   106 	TInt count;
   107 	for (count=0;count<13;count++)
   108 		{
   109 		TRAP(err, iDev = CFbsScreenDevice::NewL(KNullDesC, mode[count]));
   110 		if (err!=KErrNotSupported)
   111 			{
   112 			break;
   113 			}
   114 		}
   115 
   116 	User::LeaveIfNull(iDev);
   117 
   118 	if(err == KErrNone)
   119 		{
   120 		iDev->ChangeScreenDevice(NULL);
   121 		iDev->SetAutoUpdate(ETrue);
   122 		iDev->CreateContext(iGc);
   123 		}
   124 	User::LeaveIfNull(iGc);
   125 	}
   126 
   127 TRunProc2* TRunProc2::NewL()
   128 	{
   129 	TRunProc2 *ptr = new (ELeave) TRunProc2;
   130 	CleanupStack::PushL(ptr);
   131 	ptr->ConstructL();
   132 	CleanupStack::Pop();
   133 	return ptr;
   134 	}
   135 
   136 void TRunProc2::CreateFont()
   137 	{
   138 	//make sure that the font is large enough to ensure that the session
   139 	//cache is used.
   140 	TInt height=220;
   141 
   142 	TOpenFontSpec openFontSpec;
   143 	openFontSpec.SetName(KOpenFont);
   144 	openFontSpec.SetHeight(height);
   145 	openFontSpec.SetItalic(EFalse);
   146 	openFontSpec.SetBold(EFalse);
   147 
   148 	TTypeface Typeface;
   149 	Typeface.iName = KOpenFont;
   150 	TFontSpec fs;
   151 	fs.iTypeface = Typeface;
   152 
   153 	fs.iHeight = height;
   154 	CFbsFont* font = NULL;
   155 	TInt err = iDev->GetNearestFontToDesignHeightInPixels(font, fs);
   156 
   157 	User::LeaveIfNull(font);
   158 
   159 	// Use the font
   160 	iGc->UseFont(font);
   161 	iGc->Clear();
   162 	}
   163 
   164 void TRunProc2::RunTestL(TInt aThirdProcess, TInt aTimeout)
   165 	{
   166 	if (aThirdProcess)
   167 		{
   168 		RTimer timer;
   169 
   170 		timer.CreateLocal();
   171 		TRequestStatus timerStatus=KRequestPending;
   172 		TTimeIntervalMicroSeconds32 timeout(aTimeout);
   173 		timer.After(timerStatus, timeout);
   174 
   175 		CreateFont();
   176 		do
   177 			{
   178 			DrawText();
   179 			}
   180 		while (timerStatus==KRequestPending);
   181 		timer.Cancel();
   182 		iGc->DiscardFont();
   183 		RProcess::Rendezvous(10);
   184 		}
   185 	else
   186 		{
   187 		CreateFont();
   188 		DrawText();
   189 		iGc->DiscardFont();
   190 		RProcess::Rendezvous(1);
   191 		}
   192 	}
   193 
   194 void TRunProc2::DrawText()
   195 	{
   196 	TText ch[2];
   197 	ch[1]='\0';
   198 	for (ch[0]='A';ch[0]<='Z';ch[0]++)
   199 		{
   200 		TBufC<2> buf(ch);
   201 		iGc->DrawText(buf,TPoint(10,100));
   202 		}
   203 	for (ch[0]='a';ch[0]<='z';ch[0]++)
   204 		{
   205 		TBufC<2> buf(ch);
   206 		iGc->DrawText(buf,TPoint(10,100));
   207 		}
   208 	}
   209 
   210 void MainL()
   211 	{
   212 	TRunProc2* test= TRunProc2::NewL();
   213 	CleanupStack::PushL(test);
   214 	TInt param;
   215 	TInt timeoutParam;
   216 	User::LeaveIfError(User::GetTIntParameter(1,param));
   217 	User::LeaveIfError(User::GetTIntParameter(2,timeoutParam));
   218 	test->RunTestL(param,timeoutParam);
   219 	CleanupStack::PopAndDestroy();
   220 	}
   221 
   222 // Cleanup stack harness
   223 GLDEF_C TInt E32Main()
   224 	{
   225 	__UHEAP_MARK;
   226 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
   227 	TRAPD(error, MainL());
   228 	_LIT(KTCacheDeletionProcess,"TCacheDeletionProcess");
   229 	__ASSERT_ALWAYS(!error, User::Panic(KTCacheDeletionProcess, error));
   230 	delete cleanupStack;
   231 	__UHEAP_MARKEND;
   232 	return 0;
   233 	}