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