sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "T_IsolatedFontStore.h"
|
sl@0
|
19 |
#include "openfontsprivate.h"
|
sl@0
|
20 |
#include <f32file.h>
|
sl@0
|
21 |
#include <e32test.h>
|
sl@0
|
22 |
#include <fntstore.h>
|
sl@0
|
23 |
#include <f32file.h>
|
sl@0
|
24 |
#include <s32file.h>
|
sl@0
|
25 |
#include <fbs.h>
|
sl@0
|
26 |
#include <graphics/openfontconstants.h>
|
sl@0
|
27 |
#include <graphics/openfontrasterizer.h>
|
sl@0
|
28 |
#include "T_Cache.H"
|
sl@0
|
29 |
|
sl@0
|
30 |
LOCAL_C TInt Ptr2Offset(const TAny* aAny, TUint8* aHeapBase)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
if (aAny && aHeapBase)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
return (TInt)aAny - (TInt)aHeapBase;
|
sl@0
|
35 |
}
|
sl@0
|
36 |
return 0;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
//LOCAL_C TAny* Offset2Ptr(const TInt aOffset, TUint8* aHeapBase)
|
sl@0
|
40 |
// {
|
sl@0
|
41 |
// if (aOffset && aHeapBase)
|
sl@0
|
42 |
// {
|
sl@0
|
43 |
// return (TAny*)(aOffset + (TInt)aHeapBase);
|
sl@0
|
44 |
// }
|
sl@0
|
45 |
// return NULL;
|
sl@0
|
46 |
// }
|
sl@0
|
47 |
|
sl@0
|
48 |
CTCache::CTCache(CTestStep* aStep):
|
sl@0
|
49 |
CTGraphicsBase(aStep)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
INFO_PRINTF1(_L("FontStore T_Cache test\n"));
|
sl@0
|
52 |
iHeap=UserHeap::ChunkHeap(NULL,0x1000000,0x1000000);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
CTCache::~CTCache()
|
sl@0
|
56 |
{
|
sl@0
|
57 |
iHeap->Close();
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
//below code is for unit test and coverage only
|
sl@0
|
61 |
|
sl@0
|
62 |
void CTCache::TFontCache()
|
sl@0
|
63 |
{
|
sl@0
|
64 |
#ifdef _DEBUG
|
sl@0
|
65 |
TFontTableGlyphOutlineCacheMemMonitor mon;
|
sl@0
|
66 |
CFontTableCache* fontCache = new CFontTableCache(iHeap,mon);
|
sl@0
|
67 |
|
sl@0
|
68 |
//user array
|
sl@0
|
69 |
TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
|
sl@0
|
70 |
TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
|
sl@0
|
71 |
RPointerArray<TCacheUserInfo> userArray;
|
sl@0
|
72 |
userArray.Append(user1);
|
sl@0
|
73 |
userArray.Append(user2);
|
sl@0
|
74 |
|
sl@0
|
75 |
//item array
|
sl@0
|
76 |
CFontTableCacheItem* item1;
|
sl@0
|
77 |
TInt len = 3;
|
sl@0
|
78 |
TAny* content = (iHeap->Alloc(3));
|
sl@0
|
79 |
TUid iUid = TUid::Uid(123456);
|
sl@0
|
80 |
item1 = new CFontTableCacheItem(iUid, 0x68656164, Ptr2Offset(content, iHeap->Base()), len);
|
sl@0
|
81 |
item1->SetUser(userArray);
|
sl@0
|
82 |
RPointerArray<CFontTableCacheItem> itemArray;
|
sl@0
|
83 |
itemArray.Append(item1);
|
sl@0
|
84 |
|
sl@0
|
85 |
//font cache
|
sl@0
|
86 |
fontCache->SetFontItem(itemArray);
|
sl@0
|
87 |
TBool has = fontCache->HasOutstandingRefCount();
|
sl@0
|
88 |
TEST(has);
|
sl@0
|
89 |
has = fontCache->HasOutstandingRefCountWithUid(iUid);
|
sl@0
|
90 |
TEST(has);
|
sl@0
|
91 |
TUid uid = TUid::Uid(1234);
|
sl@0
|
92 |
fontCache->HasOutstandingRefCountWithUid(uid); //for coverage
|
sl@0
|
93 |
|
sl@0
|
94 |
TAny *outline = NULL;
|
sl@0
|
95 |
TInt length = 3;
|
sl@0
|
96 |
TInt id = 0;
|
sl@0
|
97 |
TUint32 tag = 0x1234;
|
sl@0
|
98 |
TInt err = fontCache->Find(uid, tag, outline, length, &id);
|
sl@0
|
99 |
TEST(err != KErrNone);
|
sl@0
|
100 |
err = fontCache->Find(iUid, tag, outline, length, &id);
|
sl@0
|
101 |
TEST(err != KErrNone);
|
sl@0
|
102 |
__UHEAP_FAILNEXT(1);
|
sl@0
|
103 |
fontCache->Append(uid, tag, content, length);
|
sl@0
|
104 |
TEST(err != KErrNone);
|
sl@0
|
105 |
__UHEAP_RESET;
|
sl@0
|
106 |
|
sl@0
|
107 |
fontCache->CleanupCacheOnFbsSessionTermination(123);
|
sl@0
|
108 |
TEST(err != KErrNone);
|
sl@0
|
109 |
|
sl@0
|
110 |
userArray.Close();
|
sl@0
|
111 |
delete fontCache;
|
sl@0
|
112 |
itemArray.Close();
|
sl@0
|
113 |
#endif
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
void CTCache::TFontCacheItem()
|
sl@0
|
117 |
{
|
sl@0
|
118 |
#ifdef _DEBUG
|
sl@0
|
119 |
TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
|
sl@0
|
120 |
TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
|
sl@0
|
121 |
RPointerArray<TCacheUserInfo> userArray;
|
sl@0
|
122 |
userArray.Append(user1);
|
sl@0
|
123 |
userArray.Append(user2);
|
sl@0
|
124 |
|
sl@0
|
125 |
CFontTableCacheItem* item1;
|
sl@0
|
126 |
TAny* content = User::Alloc(4);
|
sl@0
|
127 |
TUid iUid = TUid::Uid(123456);
|
sl@0
|
128 |
item1 = new CFontTableCacheItem(iUid, 0x68656164, Ptr2Offset(content, User::Heap().Base()), 3);
|
sl@0
|
129 |
User::Free(content);
|
sl@0
|
130 |
__UHEAP_FAILNEXT(1);
|
sl@0
|
131 |
TInt err = item1->IncRefCount(111);
|
sl@0
|
132 |
TEST(err == KErrNoMemory);
|
sl@0
|
133 |
__UHEAP_RESET;
|
sl@0
|
134 |
|
sl@0
|
135 |
TBool has = item1->HasOutstandingRefCount();
|
sl@0
|
136 |
TEST(!has);
|
sl@0
|
137 |
|
sl@0
|
138 |
|
sl@0
|
139 |
item1->SetUser(userArray);
|
sl@0
|
140 |
has = item1->HasOutstandingRefCount();
|
sl@0
|
141 |
TEST(has);
|
sl@0
|
142 |
|
sl@0
|
143 |
TInt id = 1;
|
sl@0
|
144 |
err = item1->FindUser(333, &id);
|
sl@0
|
145 |
TEST(err != KErrNone);
|
sl@0
|
146 |
|
sl@0
|
147 |
err = item1->DecRefCount(333);
|
sl@0
|
148 |
TEST(err == KErrNotFound);
|
sl@0
|
149 |
|
sl@0
|
150 |
|
sl@0
|
151 |
userArray.Close();
|
sl@0
|
152 |
delete item1;
|
sl@0
|
153 |
|
sl@0
|
154 |
#endif
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
void CTCache::TGlyphCacheItem()
|
sl@0
|
158 |
{
|
sl@0
|
159 |
#ifdef _DEBUG
|
sl@0
|
160 |
|
sl@0
|
161 |
TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
|
sl@0
|
162 |
TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
|
sl@0
|
163 |
|
sl@0
|
164 |
RPointerArray<TCacheUserInfo> userArray;
|
sl@0
|
165 |
userArray.Append(user1);
|
sl@0
|
166 |
userArray.Append(user2);
|
sl@0
|
167 |
|
sl@0
|
168 |
COutlineCacheItem* item1;
|
sl@0
|
169 |
TInt len = 3;
|
sl@0
|
170 |
TAny* content = User::Alloc(4);
|
sl@0
|
171 |
item1 = new COutlineCacheItem(Ptr2Offset(content, User::Heap().Base()), len);
|
sl@0
|
172 |
User::Free(content);
|
sl@0
|
173 |
__UHEAP_FAILNEXT(1);
|
sl@0
|
174 |
TInt err = item1->DecRefCount(333);
|
sl@0
|
175 |
err = item1->IncRefCount(111);
|
sl@0
|
176 |
TEST(err == KErrNoMemory);
|
sl@0
|
177 |
__UHEAP_RESET;
|
sl@0
|
178 |
|
sl@0
|
179 |
|
sl@0
|
180 |
item1->SetUser(userArray);
|
sl@0
|
181 |
err = item1->IncRefCount(333);
|
sl@0
|
182 |
TEST(err == KErrNone);
|
sl@0
|
183 |
|
sl@0
|
184 |
userArray.Close();
|
sl@0
|
185 |
delete item1;
|
sl@0
|
186 |
#endif
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
void CTCache::THintedGlyphCache()
|
sl@0
|
190 |
{
|
sl@0
|
191 |
#ifdef _DEBUG
|
sl@0
|
192 |
TFontTableGlyphOutlineCacheMemMonitor mon;
|
sl@0
|
193 |
CHintedOutlineCache* hintedCache = new CHintedOutlineCache(iHeap,mon);
|
sl@0
|
194 |
TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
|
sl@0
|
195 |
TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
|
sl@0
|
196 |
RPointerArray<TCacheUserInfo> userArray;
|
sl@0
|
197 |
userArray.Append(user1);
|
sl@0
|
198 |
userArray.Append(user2);
|
sl@0
|
199 |
COutlineCacheItem* item1;
|
sl@0
|
200 |
TInt len = 4;
|
sl@0
|
201 |
//TUint content[] = {1,2,3};
|
sl@0
|
202 |
TAny* content = User::Alloc(4);
|
sl@0
|
203 |
item1 = new COutlineCacheItem(Ptr2Offset(content, User::Heap().Base()), len);
|
sl@0
|
204 |
item1->SetUser(userArray);
|
sl@0
|
205 |
COpenFont* openFont = NULL;
|
sl@0
|
206 |
THintedOutlineId hintedId(openFont, 11);
|
sl@0
|
207 |
hintedCache->SetHintedItem(hintedId, item1);
|
sl@0
|
208 |
RHashMap<THintedOutlineId, COutlineCacheItem*> map = hintedCache->GetHintedMap();
|
sl@0
|
209 |
//for coverage
|
sl@0
|
210 |
THintedOutlineId hintedId1(openFont, 12);
|
sl@0
|
211 |
TInt err = hintedCache->IncRefCount(hintedId1, 111);
|
sl@0
|
212 |
TEST(err != KErrNone);
|
sl@0
|
213 |
COpenFont* openFont1 = reinterpret_cast<COpenFont*>(0x123);
|
sl@0
|
214 |
//for coverage
|
sl@0
|
215 |
err = hintedCache->CleanupCacheOnOpenFontRemoval(openFont1);
|
sl@0
|
216 |
TEST(err == KErrNone);
|
sl@0
|
217 |
//following return value alway KErrNone
|
sl@0
|
218 |
hintedCache->CleanupCacheOnFbsSessionTermination(111);
|
sl@0
|
219 |
hintedCache->CleanupCacheOnFbsSessionTermination(333);
|
sl@0
|
220 |
|
sl@0
|
221 |
TAny* ptr;
|
sl@0
|
222 |
TInt size = 0;
|
sl@0
|
223 |
__UHEAP_FAILNEXT(1);
|
sl@0
|
224 |
hintedCache->CacheHintedOutline(hintedId1, &content, len, ptr, size);
|
sl@0
|
225 |
__UHEAP_RESET;
|
sl@0
|
226 |
|
sl@0
|
227 |
__RHEAP_FAILNEXT(iHeap, 1);
|
sl@0
|
228 |
hintedCache->CacheHintedOutline(hintedId1, &content, len, ptr, size);
|
sl@0
|
229 |
__RHEAP_RESET(iHeap);
|
sl@0
|
230 |
|
sl@0
|
231 |
|
sl@0
|
232 |
mon.Inc(KFontTable_GlyphOutline_CacheMaxMem);
|
sl@0
|
233 |
err = hintedCache->CacheHintedOutline(hintedId1, &content, len, ptr, len);
|
sl@0
|
234 |
TEST(err == KErrNoMemory);
|
sl@0
|
235 |
User::Free(content);
|
sl@0
|
236 |
|
sl@0
|
237 |
map.Close();
|
sl@0
|
238 |
delete item1;
|
sl@0
|
239 |
userArray.Close();
|
sl@0
|
240 |
delete hintedCache;
|
sl@0
|
241 |
#endif
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
void CTCache::TUnHintedGlyphCache()
|
sl@0
|
245 |
{
|
sl@0
|
246 |
#ifdef _DEBUG
|
sl@0
|
247 |
TFontTableGlyphOutlineCacheMemMonitor mon;
|
sl@0
|
248 |
CUnhintedOutlineCache* unhintedCache = new CUnhintedOutlineCache(iHeap,mon);
|
sl@0
|
249 |
TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
|
sl@0
|
250 |
TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
|
sl@0
|
251 |
RPointerArray<TCacheUserInfo> userArray;
|
sl@0
|
252 |
userArray.Append(user1);
|
sl@0
|
253 |
userArray.Append(user2);
|
sl@0
|
254 |
COutlineCacheItem* item1;
|
sl@0
|
255 |
TInt len = 3;
|
sl@0
|
256 |
TAny* content = (iHeap->Alloc(3));
|
sl@0
|
257 |
item1 = new COutlineCacheItem(Ptr2Offset(content, iHeap->Base()), len);
|
sl@0
|
258 |
item1->SetUser(userArray);
|
sl@0
|
259 |
TUid uid = TUid::Uid(123);
|
sl@0
|
260 |
TUnhintedOutlineId unhintedId(uid, 11, 1);
|
sl@0
|
261 |
unhintedCache->SetUnHintedItem(unhintedId, item1);
|
sl@0
|
262 |
// RHashMap<TUnhintedOutlineId, COutlineCacheItem*> map = unhintedCache->GetHintedMap();
|
sl@0
|
263 |
TUnhintedOutlineId unhintedId1(uid, 12, 1);
|
sl@0
|
264 |
TInt err = unhintedCache->IncRefCount(unhintedId1, 111);
|
sl@0
|
265 |
TEST(err != KErrNone);
|
sl@0
|
266 |
//for coverage
|
sl@0
|
267 |
unhintedCache->CleanupCacheOnFbsSessionTermination(111);
|
sl@0
|
268 |
unhintedCache->CleanupCacheOnFbsSessionTermination(333);
|
sl@0
|
269 |
|
sl@0
|
270 |
TAny* ptr;
|
sl@0
|
271 |
TInt size = 0;
|
sl@0
|
272 |
__UHEAP_FAILNEXT(1);
|
sl@0
|
273 |
unhintedCache->CacheUnhintedOutline(unhintedId1, &content, len, ptr, size);
|
sl@0
|
274 |
__UHEAP_RESET;
|
sl@0
|
275 |
|
sl@0
|
276 |
__RHEAP_FAILNEXT(iHeap, 1);
|
sl@0
|
277 |
unhintedCache->CacheUnhintedOutline(unhintedId1, &content, len, ptr, size);
|
sl@0
|
278 |
__RHEAP_RESET(iHeap);
|
sl@0
|
279 |
|
sl@0
|
280 |
|
sl@0
|
281 |
mon.Inc(KFontTable_GlyphOutline_CacheMaxMem);
|
sl@0
|
282 |
err = unhintedCache->CacheUnhintedOutline(unhintedId1, &content, len, ptr, len);
|
sl@0
|
283 |
TEST(err == KErrNoMemory);
|
sl@0
|
284 |
|
sl@0
|
285 |
userArray.Close();
|
sl@0
|
286 |
delete unhintedCache;
|
sl@0
|
287 |
|
sl@0
|
288 |
#endif
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
void CTCache::TFontCacheForCov()
|
sl@0
|
292 |
{
|
sl@0
|
293 |
#ifdef _DEBUG
|
sl@0
|
294 |
TFontTableGlyphOutlineCacheMemMonitor mon;
|
sl@0
|
295 |
CFontTableCache* fontCache = new CFontTableCache(iHeap,mon);
|
sl@0
|
296 |
|
sl@0
|
297 |
TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
|
sl@0
|
298 |
RPointerArray<TCacheUserInfo> userArray;
|
sl@0
|
299 |
userArray.Append(user1);
|
sl@0
|
300 |
CFontTableCacheItem* item1;
|
sl@0
|
301 |
TInt len = 3;
|
sl@0
|
302 |
TAny* content = (iHeap->Alloc(3));
|
sl@0
|
303 |
TUid iUid = TUid::Uid(123456);
|
sl@0
|
304 |
item1 = new CFontTableCacheItem(iUid, 0x68656164, Ptr2Offset(content, iHeap->Base()), len);
|
sl@0
|
305 |
item1->SetUser(userArray);
|
sl@0
|
306 |
RPointerArray<CFontTableCacheItem> itemArray;
|
sl@0
|
307 |
itemArray.Append(item1);
|
sl@0
|
308 |
fontCache->SetFontItem(itemArray);
|
sl@0
|
309 |
|
sl@0
|
310 |
TBool has = fontCache->HasOutstandingRefCount();
|
sl@0
|
311 |
TEST(!has);
|
sl@0
|
312 |
has = fontCache->HasOutstandingRefCountWithUid(iUid);
|
sl@0
|
313 |
TEST(!has);
|
sl@0
|
314 |
|
sl@0
|
315 |
TUint length = 3;
|
sl@0
|
316 |
TUint32 tag = 0x1234;
|
sl@0
|
317 |
TUid uid = TUid::Uid(1234);
|
sl@0
|
318 |
mon.Inc(KFontTable_GlyphOutline_CacheMaxMem);
|
sl@0
|
319 |
TInt err = fontCache->Append(uid, tag, content, length);
|
sl@0
|
320 |
TEST(err == KErrNoMemory);
|
sl@0
|
321 |
|
sl@0
|
322 |
userArray.Close();
|
sl@0
|
323 |
delete fontCache;
|
sl@0
|
324 |
itemArray.Close();
|
sl@0
|
325 |
#endif
|
sl@0
|
326 |
}
|
sl@0
|
327 |
|
sl@0
|
328 |
void CTCache::RunTestCaseL(TInt aCurTestCase)
|
sl@0
|
329 |
{
|
sl@0
|
330 |
((CTCacheStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
|
sl@0
|
331 |
switch(aCurTestCase)
|
sl@0
|
332 |
{
|
sl@0
|
333 |
case 1:
|
sl@0
|
334 |
((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0001"));
|
sl@0
|
335 |
INFO_PRINTF1(_L("FontStore T_Cache test 1: TFontCacheItem\n"));
|
sl@0
|
336 |
TFontCacheItem();
|
sl@0
|
337 |
break;
|
sl@0
|
338 |
|
sl@0
|
339 |
case 2:
|
sl@0
|
340 |
((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0002"));
|
sl@0
|
341 |
INFO_PRINTF1(_L("FontStore T_Cache test 2: TFontCache\n"));
|
sl@0
|
342 |
TFontCache();
|
sl@0
|
343 |
TFontCacheForCov();
|
sl@0
|
344 |
break;
|
sl@0
|
345 |
|
sl@0
|
346 |
case 3:
|
sl@0
|
347 |
((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0003"));
|
sl@0
|
348 |
INFO_PRINTF1(_L("FontStore T_Cache test 3: THintedGlyphCacheItem\n"));
|
sl@0
|
349 |
TGlyphCacheItem();
|
sl@0
|
350 |
break;
|
sl@0
|
351 |
|
sl@0
|
352 |
case 4:
|
sl@0
|
353 |
((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0004"));
|
sl@0
|
354 |
INFO_PRINTF1(_L("FontStore T_Cache test 4: THintedGlyphCache\n"));
|
sl@0
|
355 |
THintedGlyphCache();
|
sl@0
|
356 |
break;
|
sl@0
|
357 |
|
sl@0
|
358 |
case 5:
|
sl@0
|
359 |
((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0005"));
|
sl@0
|
360 |
INFO_PRINTF1(_L("FontStore T_Cache test 5: TUnHintedGlyphCache\n"));
|
sl@0
|
361 |
TUnHintedGlyphCache();
|
sl@0
|
362 |
break;
|
sl@0
|
363 |
|
sl@0
|
364 |
case 6:
|
sl@0
|
365 |
((CTCacheStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
|
sl@0
|
366 |
((CTCacheStep*)iStep)->CloseTMSGraphicsStep();
|
sl@0
|
367 |
TestComplete();
|
sl@0
|
368 |
break;
|
sl@0
|
369 |
}
|
sl@0
|
370 |
((CTCacheStep*)iStep)->RecordTestResultL();
|
sl@0
|
371 |
}
|
sl@0
|
372 |
|
sl@0
|
373 |
//--------------
|
sl@0
|
374 |
__CONSTRUCT_STEP__(Cache)
|
sl@0
|
375 |
|
sl@0
|
376 |
|
sl@0
|
377 |
|