os/graphics/graphicsdeviceinterface/gdi/tgdi/TTFSTORE.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 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "TGraphicsContext.h"
    17 #include "TTYPES.H"
    18 
    19 
    20 CTestTypefaceStore::CTestTypefaceStore(CTTypes* aTest) :
    21 	iTest(aTest)
    22 	{
    23 	}
    24 
    25 void CTestTypefaceStore::ConstructTestL()
    26 	{
    27 	ConstructL();
    28 	}
    29 
    30 TInt CTestTypefaceStore::AccessCount(TInt aIndex)
    31 	{
    32 	return(iFontAccess->At(aIndex).iAccessCount);
    33 	}
    34 
    35 TInt CTestTypefaceStore::Count()
    36 	{
    37 	return(iFontAccess->Count());
    38 	}
    39 
    40 void CTestTypefaceStore::AddFont(CFont* aFont)
    41 	{
    42 	TRAPD(ret,AddFontL(aFont));
    43 	iTest->TEST2(ret, KErrNone);
    44 	}
    45 
    46 void CTestTypefaceStore::OpenFont(CFont* aFont)
    47 	{
    48 	TInt numfonts=Count();
    49 	for(TInt count=0;count<numfonts;count++)
    50 		{
    51 		if(iFontAccess->At(count).iFont==aFont)
    52 			{
    53 			iFontAccess->At(count).iAccessCount++;
    54 			return;
    55 			}
    56 		}
    57 	}
    58 
    59 TestTFStore::TestTFStore(CTTypes* aTest) :
    60 	iTTFStore(aTest),
    61 	iTest(aTest)
    62 	{
    63 	
    64 	}
    65 
    66 /** 
    67 	TestTFStore::Test
    68 	
    69 	Method to test the functionality associated with CTypeFaceStore (abstract base) class
    70 	The implementation is contained within CTestTypeFaceStore
    71 	Called from the TTypes test script
    72 */
    73 void TestTFStore::Test()
    74 	{
    75 	CFont* f1=new CTestFont;
    76 	CFont* f2=new CTestFont;
    77 	CFont* f3=new CTestFont;
    78 	CFont* f4=new CTestFont;
    79 	CFont* f5=new CTestFont;
    80 
    81 	TRAPD(errCode, iTTFStore.ConstructTestL());
    82 	iTest->TEST2(errCode, KErrNone);
    83 	iTTFStore.AddFont(f1);
    84 	iTest->TEST(iTTFStore.Count()==1);
    85 	iTest->TEST(iTTFStore.AccessCount(0)==1);
    86 	iTTFStore.AddFont(f2);
    87 	iTest->TEST(iTTFStore.Count()==2);
    88 	iTest->TEST(iTTFStore.AccessCount(0)==1);
    89 	iTest->TEST(iTTFStore.AccessCount(1)==1);
    90 	iTTFStore.AddFont(f3);
    91 	iTest->TEST(iTTFStore.Count()==3);
    92 	iTest->TEST(iTTFStore.AccessCount(0)==1);
    93 	iTest->TEST(iTTFStore.AccessCount(1)==1);
    94 	iTest->TEST(iTTFStore.AccessCount(2)==1);
    95 	iTTFStore.AddFont(f4);
    96 	iTest->TEST(iTTFStore.Count()==4);
    97 	iTest->TEST(iTTFStore.AccessCount(0)==1);
    98 	iTest->TEST(iTTFStore.AccessCount(1)==1);
    99 	iTest->TEST(iTTFStore.AccessCount(2)==1);
   100 	iTest->TEST(iTTFStore.AccessCount(3)==1);
   101 	iTTFStore.OpenFont(f1);
   102 	iTest->TEST(iTTFStore.Count()==4);
   103 	iTest->TEST(iTTFStore.AccessCount(0)==2);
   104 	iTest->TEST(iTTFStore.AccessCount(1)==1);
   105 	iTest->TEST(iTTFStore.AccessCount(2)==1);
   106 	iTest->TEST(iTTFStore.AccessCount(3)==1);
   107 	iTTFStore.OpenFont(f4);
   108 	iTest->TEST(iTTFStore.Count()==4);
   109 	iTest->TEST(iTTFStore.AccessCount(0)==2);
   110 	iTest->TEST(iTTFStore.AccessCount(1)==1);
   111 	iTest->TEST(iTTFStore.AccessCount(2)==1);
   112 	iTest->TEST(iTTFStore.AccessCount(3)==2);
   113 	iTTFStore.AddFont(f5);
   114 	iTest->TEST(iTTFStore.Count()==5);
   115 	iTest->TEST(iTTFStore.AccessCount(0)==2);
   116 	iTest->TEST(iTTFStore.AccessCount(1)==1);
   117 	iTest->TEST(iTTFStore.AccessCount(2)==1);
   118 	iTest->TEST(iTTFStore.AccessCount(3)==2);
   119 	iTest->TEST(iTTFStore.AccessCount(4)==1);
   120 	iTTFStore.OpenFont(f5);
   121 	iTest->TEST(iTTFStore.Count()==5);
   122 	iTest->TEST(iTTFStore.AccessCount(0)==2);
   123 	iTest->TEST(iTTFStore.AccessCount(1)==1);
   124 	iTest->TEST(iTTFStore.AccessCount(2)==1);
   125 	iTest->TEST(iTTFStore.AccessCount(3)==2);
   126 	iTest->TEST(iTTFStore.AccessCount(4)==2);
   127 	iTTFStore.OpenFont(f4);
   128 	iTest->TEST(iTTFStore.Count()==5);
   129 	iTest->TEST(iTTFStore.AccessCount(0)==2);
   130 	iTest->TEST(iTTFStore.AccessCount(1)==1);
   131 	iTest->TEST(iTTFStore.AccessCount(2)==1);
   132 	iTest->TEST(iTTFStore.AccessCount(3)==3);
   133 	iTest->TEST(iTTFStore.AccessCount(4)==2);
   134 //
   135 	iTTFStore.ReleaseFont(f1);
   136 	iTTFStore.ReleaseFont(f2);
   137 	iTTFStore.ReleaseFont(f4);
   138 	iTTFStore.ReleaseFont(f4);
   139 	iTTFStore.ReleaseFont(f3);
   140 	iTTFStore.ReleaseFont(f5);
   141 	iTTFStore.ReleaseFont(f4);
   142 	iTTFStore.ReleaseFont(f1);
   143 	iTTFStore.ReleaseFont(f5);
   144 	}
   145 
   146 TestFontCache::TestFontCache(CTTypes* aTest):
   147 	iTest(aTest)
   148 	{
   149 	
   150 	}
   151 
   152 /** 
   153 	TestFontCache::Test()
   154 	
   155 	Method to test the functionality within the CFontCache class
   156 	Called from the TTypes test script
   157 */
   158 void TestFontCache::Test()
   159 	{
   160 	TRAPD(ret,TestL());
   161 	iTest->TEST2(ret, KErrNone);
   162 	}
   163 
   164 /** 
   165 	TestFontCache::TestL()
   166 	
   167 	Method to test the functionality within the CFontCache class
   168 	Test the creation of CFontCache instance & the adding/removal of CFont fonts to the cache
   169 	Confirm no memory leaks occur
   170 	
   171 */
   172 void TestFontCache::TestL()
   173 	{
   174 	User::Heap().__DbgMarkStart();
   175 
   176 	iCache = new(ELeave) CFontCache;
   177 	CFont* font = NULL;
   178 	CFont* discard = NULL;
   179 	TFontSpec fs;
   180 
   181 	for (TInt count1 = 0; count1 < KMaxFontCacheEntries; count1++)
   182 		{
   183 		font = (CFont*)(count1 + 1);
   184 		discard = iCache->AddEntryL(font,fs);
   185 		iTest->TEST(discard==NULL);
   186 		}
   187 
   188 	font = (CFont*)KMaxFontCacheEntries;
   189 	discard = iCache->AddEntryL(font,fs);
   190 	iTest->TEST(discard==(CFont*)0x1);
   191 	delete iCache;
   192 	iCache = NULL;
   193 
   194 	iCache = new(ELeave) CFontCache;
   195 
   196 	for (TInt count2 = 0; count2 <= KMaxFontCacheEntries; count2++)
   197 		{
   198 		iCache->AddEntryL(NULL,fs);
   199 		iCache->RemoveFirstEntry();
   200 		}
   201 
   202 	delete iCache;
   203 
   204 	User::Heap().__DbgMarkEnd(0);
   205 	}