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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "TGraphicsContext.h"
20 CTestTypefaceStore::CTestTypefaceStore(CTTypes* aTest) :
25 void CTestTypefaceStore::ConstructTestL()
30 TInt CTestTypefaceStore::AccessCount(TInt aIndex)
32 return(iFontAccess->At(aIndex).iAccessCount);
35 TInt CTestTypefaceStore::Count()
37 return(iFontAccess->Count());
40 void CTestTypefaceStore::AddFont(CFont* aFont)
42 TRAPD(ret,AddFontL(aFont));
43 iTest->TEST2(ret, KErrNone);
46 void CTestTypefaceStore::OpenFont(CFont* aFont)
48 TInt numfonts=Count();
49 for(TInt count=0;count<numfonts;count++)
51 if(iFontAccess->At(count).iFont==aFont)
53 iFontAccess->At(count).iAccessCount++;
59 TestTFStore::TestTFStore(CTTypes* aTest) :
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
73 void TestTFStore::Test()
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;
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);
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);
146 TestFontCache::TestFontCache(CTTypes* aTest):
153 TestFontCache::Test()
155 Method to test the functionality within the CFontCache class
156 Called from the TTypes test script
158 void TestFontCache::Test()
161 iTest->TEST2(ret, KErrNone);
165 TestFontCache::TestL()
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
172 void TestFontCache::TestL()
174 User::Heap().__DbgMarkStart();
176 iCache = new(ELeave) CFontCache;
178 CFont* discard = NULL;
181 for (TInt count1 = 0; count1 < KMaxFontCacheEntries; count1++)
183 font = (CFont*)(count1 + 1);
184 discard = iCache->AddEntryL(font,fs);
185 iTest->TEST(discard==NULL);
188 font = (CFont*)KMaxFontCacheEntries;
189 discard = iCache->AddEntryL(font,fs);
190 iTest->TEST(discard==(CFont*)0x1);
194 iCache = new(ELeave) CFontCache;
196 for (TInt count2 = 0; count2 <= KMaxFontCacheEntries; count2++)
198 iCache->AddEntryL(NULL,fs);
199 iCache->RemoveFirstEntry();
204 User::Heap().__DbgMarkEnd(0);