os/textandloc/fontservices/fontstore/tfs/t_cachedeletion.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @test
    22  @internalComponent Internal Symbian test code
    23 */
    24 
    25 #include "FNTSTORE.H"
    26 #include "OPENFONT.H"
    27 #include "FNTBODY.H"
    28 #include "FNTSTD.H"
    29 #include "t_cachedeletion.h"
    30 #include <hal.h>
    31 #include <s32file.h>
    32 #include <graphics/shapeimpl.h>
    33 
    34 _LIT(KSecondProcess,"tcachedeletionprocess");
    35 _LIT(KThirdProcess,"tcachedeletionprocess");
    36 
    37 class CTCacheDeletion : public CTGraphicsBase
    38 	{
    39 public:
    40 	CTCacheDeletion(CTestStep* aStep);
    41 	~CTCacheDeletion();
    42 protected:
    43 // From CTGraphicsStep
    44 	virtual void RunTestCaseL(TInt aCurTestCase);
    45 private:
    46 	void RunProcess2L();
    47 	};
    48 
    49 CTCacheDeletion::CTCacheDeletion(CTestStep* aStep)
    50  :	CTGraphicsBase(aStep)
    51 	{
    52 
    53 	}
    54 
    55 CTCacheDeletion::~CTCacheDeletion()
    56 	{
    57 	// no action needed
    58 	}
    59 
    60 void TimerCleanup(TAny *aTimer)
    61 	{
    62 	((RTimer*)aTimer)->Cancel();
    63 	}
    64 
    65 /**
    66 	@SYMTestCaseID
    67 	GRAPHICS-FNTSTORE-0050
    68 
    69 	@SYMTestCaseDesc
    70 	Tests font and bitmap server disconnection (when a process finishes)
    71 	at the same time a process is outputing.
    72 
    73 	@SYMTestActions
    74 	This function creates two processes.  These processes are called
    75     process 3 and process 2.  Process 3 is created, and run.  There are
    76     parameters input to the process.  The first is an indicator to the
    77     process of the instance (2 or 3) and the second is a timeout.
    78     Process3 runs continually, drawing text for the full timeout period.
    79     Process2 is created and allowed to finish in a loop in this function for
    80     the same timeout period, currently ten seconds.
    81 
    82 	@SYMTestExpectedResults
    83 	Test should pass
    84 */
    85 void CTCacheDeletion::RunProcess2L()
    86 	{
    87 	TInt runForMicroSecs = 1000*1000*10;
    88 
    89 	//create process 3
    90 	RProcess process3;
    91 	TInt err;
    92 	err = process3.Create(KThirdProcess, KNullDesC);
    93 	User::LeaveIfError(err);
    94 	CleanupClosePushL(process3);
    95 
    96 	//run process 3
    97 	process3.SetParameter(1,1);
    98 	process3.SetParameter(2,runForMicroSecs);
    99 	TRequestStatus completeStatus3;
   100 	process3.Logon(completeStatus3);
   101 	TRequestStatus rendezvousStatus3;
   102 	rendezvousStatus3=KRequestPending;
   103 	process3.Rendezvous(rendezvousStatus3);
   104 	process3.Resume(); //start the process
   105 	User::WaitForRequest(rendezvousStatus3);
   106 	
   107 	//create a timer
   108 	RTimer timer;
   109 	timer.CreateLocal();
   110 	TRequestStatus timerStatus=KRequestPending;
   111 	TTimeIntervalMicroSeconds32 timeout(runForMicroSecs);
   112 	timer.After(timerStatus, runForMicroSecs);
   113 
   114 	TCleanupItem cleanup(TimerCleanup,&timer);
   115 	CleanupStack::PushL(cleanup);
   116 
   117 	do
   118 		{
   119 		//run process 2 in a loop
   120 
   121 		//create process 2
   122 		RProcess process2;
   123 		TInt err = process2.Create(KSecondProcess, KNullDesC);
   124 		User::LeaveIfError(err);
   125 		CleanupClosePushL(process2);
   126 
   127 		//start process 2
   128 		process2.SetParameter(1,0);
   129 		process2.SetParameter(2,runForMicroSecs);//not actually used
   130 		TRequestStatus completeStatus2;
   131 		process2.Logon(completeStatus2);
   132 		TRequestStatus rendezvousStatus2;
   133 		rendezvousStatus2=KRequestPending;
   134 		process2.Rendezvous(rendezvousStatus2);
   135 		process2.Resume(); //start the process
   136 
   137 		//rendezvous with 2
   138 		User::WaitForRequest(rendezvousStatus2);
   139 		TInt status = rendezvousStatus2.Int();
   140 		TEST(status ==1);
   141 
   142 		//now let 2 finish
   143 		User::WaitForRequest(completeStatus2);
   144 		TExitType exit = process2.ExitType();
   145 		TEST(exit == EExitKill);
   146 		TInt reason = process2.ExitReason();
   147 		TEST (reason == 0);
   148 
   149 		CleanupStack::PopAndDestroy();
   150 		}
   151 	while (timerStatus==KRequestPending);
   152 	timer.Cancel();
   153 	CleanupStack::Pop();//timer
   154 
   155 	//rendezvous with 3
   156 	User::WaitForRequest(rendezvousStatus3);
   157 	TInt status = rendezvousStatus3.Int();
   158 	TEST(status ==10);
   159 
   160 	//now let 3 finish
   161 	User::WaitForRequest(completeStatus3);
   162 	TExitType exit = process3.ExitType();
   163 	TEST(exit == EExitKill);
   164 	TInt reason = process3.ExitReason();
   165 	TEST (reason == 0);
   166 
   167 	CleanupStack::PopAndDestroy();//process 3 
   168 	}
   169 	
   170 void CTCacheDeletion::RunTestCaseL( TInt aCurTestCase )
   171 	{
   172 #if defined __WINS__ || defined __WINSCW__
   173 	aCurTestCase = aCurTestCase;  //to avoid unused warning
   174 	TestComplete(); //only run test on hardware, always passes on winscw
   175 	return;
   176 #endif
   177 	((CTCacheDeletionStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   178 
   179 	switch ( aCurTestCase )
   180 		{
   181 	case 1:	
   182 		((CTCacheDeletionStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0050"));
   183 		RunProcess2L();
   184 		break;
   185 	case 2:
   186 		((CTCacheDeletionStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   187 		((CTCacheDeletionStep*)iStep)->CloseTMSGraphicsStep();
   188 		TestComplete();
   189 		break;
   190 		}
   191 	((CTCacheDeletionStep*)iStep)->RecordTestResultL();
   192 	}
   193 
   194 // --------------
   195 __CONSTRUCT_STEP__(CacheDeletion)