os/graphics/graphicsdeviceinterface/gdi/tgdi/TTFSTORE.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/tgdi/TTFSTORE.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,205 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "TGraphicsContext.h"
    1.20 +#include "TTYPES.H"
    1.21 +
    1.22 +
    1.23 +CTestTypefaceStore::CTestTypefaceStore(CTTypes* aTest) :
    1.24 +	iTest(aTest)
    1.25 +	{
    1.26 +	}
    1.27 +
    1.28 +void CTestTypefaceStore::ConstructTestL()
    1.29 +	{
    1.30 +	ConstructL();
    1.31 +	}
    1.32 +
    1.33 +TInt CTestTypefaceStore::AccessCount(TInt aIndex)
    1.34 +	{
    1.35 +	return(iFontAccess->At(aIndex).iAccessCount);
    1.36 +	}
    1.37 +
    1.38 +TInt CTestTypefaceStore::Count()
    1.39 +	{
    1.40 +	return(iFontAccess->Count());
    1.41 +	}
    1.42 +
    1.43 +void CTestTypefaceStore::AddFont(CFont* aFont)
    1.44 +	{
    1.45 +	TRAPD(ret,AddFontL(aFont));
    1.46 +	iTest->TEST2(ret, KErrNone);
    1.47 +	}
    1.48 +
    1.49 +void CTestTypefaceStore::OpenFont(CFont* aFont)
    1.50 +	{
    1.51 +	TInt numfonts=Count();
    1.52 +	for(TInt count=0;count<numfonts;count++)
    1.53 +		{
    1.54 +		if(iFontAccess->At(count).iFont==aFont)
    1.55 +			{
    1.56 +			iFontAccess->At(count).iAccessCount++;
    1.57 +			return;
    1.58 +			}
    1.59 +		}
    1.60 +	}
    1.61 +
    1.62 +TestTFStore::TestTFStore(CTTypes* aTest) :
    1.63 +	iTTFStore(aTest),
    1.64 +	iTest(aTest)
    1.65 +	{
    1.66 +	
    1.67 +	}
    1.68 +
    1.69 +/** 
    1.70 +	TestTFStore::Test
    1.71 +	
    1.72 +	Method to test the functionality associated with CTypeFaceStore (abstract base) class
    1.73 +	The implementation is contained within CTestTypeFaceStore
    1.74 +	Called from the TTypes test script
    1.75 +*/
    1.76 +void TestTFStore::Test()
    1.77 +	{
    1.78 +	CFont* f1=new CTestFont;
    1.79 +	CFont* f2=new CTestFont;
    1.80 +	CFont* f3=new CTestFont;
    1.81 +	CFont* f4=new CTestFont;
    1.82 +	CFont* f5=new CTestFont;
    1.83 +
    1.84 +	TRAPD(errCode, iTTFStore.ConstructTestL());
    1.85 +	iTest->TEST2(errCode, KErrNone);
    1.86 +	iTTFStore.AddFont(f1);
    1.87 +	iTest->TEST(iTTFStore.Count()==1);
    1.88 +	iTest->TEST(iTTFStore.AccessCount(0)==1);
    1.89 +	iTTFStore.AddFont(f2);
    1.90 +	iTest->TEST(iTTFStore.Count()==2);
    1.91 +	iTest->TEST(iTTFStore.AccessCount(0)==1);
    1.92 +	iTest->TEST(iTTFStore.AccessCount(1)==1);
    1.93 +	iTTFStore.AddFont(f3);
    1.94 +	iTest->TEST(iTTFStore.Count()==3);
    1.95 +	iTest->TEST(iTTFStore.AccessCount(0)==1);
    1.96 +	iTest->TEST(iTTFStore.AccessCount(1)==1);
    1.97 +	iTest->TEST(iTTFStore.AccessCount(2)==1);
    1.98 +	iTTFStore.AddFont(f4);
    1.99 +	iTest->TEST(iTTFStore.Count()==4);
   1.100 +	iTest->TEST(iTTFStore.AccessCount(0)==1);
   1.101 +	iTest->TEST(iTTFStore.AccessCount(1)==1);
   1.102 +	iTest->TEST(iTTFStore.AccessCount(2)==1);
   1.103 +	iTest->TEST(iTTFStore.AccessCount(3)==1);
   1.104 +	iTTFStore.OpenFont(f1);
   1.105 +	iTest->TEST(iTTFStore.Count()==4);
   1.106 +	iTest->TEST(iTTFStore.AccessCount(0)==2);
   1.107 +	iTest->TEST(iTTFStore.AccessCount(1)==1);
   1.108 +	iTest->TEST(iTTFStore.AccessCount(2)==1);
   1.109 +	iTest->TEST(iTTFStore.AccessCount(3)==1);
   1.110 +	iTTFStore.OpenFont(f4);
   1.111 +	iTest->TEST(iTTFStore.Count()==4);
   1.112 +	iTest->TEST(iTTFStore.AccessCount(0)==2);
   1.113 +	iTest->TEST(iTTFStore.AccessCount(1)==1);
   1.114 +	iTest->TEST(iTTFStore.AccessCount(2)==1);
   1.115 +	iTest->TEST(iTTFStore.AccessCount(3)==2);
   1.116 +	iTTFStore.AddFont(f5);
   1.117 +	iTest->TEST(iTTFStore.Count()==5);
   1.118 +	iTest->TEST(iTTFStore.AccessCount(0)==2);
   1.119 +	iTest->TEST(iTTFStore.AccessCount(1)==1);
   1.120 +	iTest->TEST(iTTFStore.AccessCount(2)==1);
   1.121 +	iTest->TEST(iTTFStore.AccessCount(3)==2);
   1.122 +	iTest->TEST(iTTFStore.AccessCount(4)==1);
   1.123 +	iTTFStore.OpenFont(f5);
   1.124 +	iTest->TEST(iTTFStore.Count()==5);
   1.125 +	iTest->TEST(iTTFStore.AccessCount(0)==2);
   1.126 +	iTest->TEST(iTTFStore.AccessCount(1)==1);
   1.127 +	iTest->TEST(iTTFStore.AccessCount(2)==1);
   1.128 +	iTest->TEST(iTTFStore.AccessCount(3)==2);
   1.129 +	iTest->TEST(iTTFStore.AccessCount(4)==2);
   1.130 +	iTTFStore.OpenFont(f4);
   1.131 +	iTest->TEST(iTTFStore.Count()==5);
   1.132 +	iTest->TEST(iTTFStore.AccessCount(0)==2);
   1.133 +	iTest->TEST(iTTFStore.AccessCount(1)==1);
   1.134 +	iTest->TEST(iTTFStore.AccessCount(2)==1);
   1.135 +	iTest->TEST(iTTFStore.AccessCount(3)==3);
   1.136 +	iTest->TEST(iTTFStore.AccessCount(4)==2);
   1.137 +//
   1.138 +	iTTFStore.ReleaseFont(f1);
   1.139 +	iTTFStore.ReleaseFont(f2);
   1.140 +	iTTFStore.ReleaseFont(f4);
   1.141 +	iTTFStore.ReleaseFont(f4);
   1.142 +	iTTFStore.ReleaseFont(f3);
   1.143 +	iTTFStore.ReleaseFont(f5);
   1.144 +	iTTFStore.ReleaseFont(f4);
   1.145 +	iTTFStore.ReleaseFont(f1);
   1.146 +	iTTFStore.ReleaseFont(f5);
   1.147 +	}
   1.148 +
   1.149 +TestFontCache::TestFontCache(CTTypes* aTest):
   1.150 +	iTest(aTest)
   1.151 +	{
   1.152 +	
   1.153 +	}
   1.154 +
   1.155 +/** 
   1.156 +	TestFontCache::Test()
   1.157 +	
   1.158 +	Method to test the functionality within the CFontCache class
   1.159 +	Called from the TTypes test script
   1.160 +*/
   1.161 +void TestFontCache::Test()
   1.162 +	{
   1.163 +	TRAPD(ret,TestL());
   1.164 +	iTest->TEST2(ret, KErrNone);
   1.165 +	}
   1.166 +
   1.167 +/** 
   1.168 +	TestFontCache::TestL()
   1.169 +	
   1.170 +	Method to test the functionality within the CFontCache class
   1.171 +	Test the creation of CFontCache instance & the adding/removal of CFont fonts to the cache
   1.172 +	Confirm no memory leaks occur
   1.173 +	
   1.174 +*/
   1.175 +void TestFontCache::TestL()
   1.176 +	{
   1.177 +	User::Heap().__DbgMarkStart();
   1.178 +
   1.179 +	iCache = new(ELeave) CFontCache;
   1.180 +	CFont* font = NULL;
   1.181 +	CFont* discard = NULL;
   1.182 +	TFontSpec fs;
   1.183 +
   1.184 +	for (TInt count1 = 0; count1 < KMaxFontCacheEntries; count1++)
   1.185 +		{
   1.186 +		font = (CFont*)(count1 + 1);
   1.187 +		discard = iCache->AddEntryL(font,fs);
   1.188 +		iTest->TEST(discard==NULL);
   1.189 +		}
   1.190 +
   1.191 +	font = (CFont*)KMaxFontCacheEntries;
   1.192 +	discard = iCache->AddEntryL(font,fs);
   1.193 +	iTest->TEST(discard==(CFont*)0x1);
   1.194 +	delete iCache;
   1.195 +	iCache = NULL;
   1.196 +
   1.197 +	iCache = new(ELeave) CFontCache;
   1.198 +
   1.199 +	for (TInt count2 = 0; count2 <= KMaxFontCacheEntries; count2++)
   1.200 +		{
   1.201 +		iCache->AddEntryL(NULL,fs);
   1.202 +		iCache->RemoveFirstEntry();
   1.203 +		}
   1.204 +
   1.205 +	delete iCache;
   1.206 +
   1.207 +	User::Heap().__DbgMarkEnd(0);
   1.208 +	}