Update contrib.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
18 #include "T_IsolatedFontStore.h"
19 #include "openfontsprivate.h"
26 #include <graphics/openfontconstants.h>
27 #include <graphics/openfontrasterizer.h>
30 LOCAL_C TInt Ptr2Offset(const TAny* aAny, TUint8* aHeapBase)
32 if (aAny && aHeapBase)
34 return (TInt)aAny - (TInt)aHeapBase;
39 //LOCAL_C TAny* Offset2Ptr(const TInt aOffset, TUint8* aHeapBase)
41 // if (aOffset && aHeapBase)
43 // return (TAny*)(aOffset + (TInt)aHeapBase);
48 CTCache::CTCache(CTestStep* aStep):
51 INFO_PRINTF1(_L("FontStore T_Cache test\n"));
52 iHeap=UserHeap::ChunkHeap(NULL,0x1000000,0x1000000);
60 //below code is for unit test and coverage only
62 void CTCache::TFontCache()
65 TFontTableGlyphOutlineCacheMemMonitor mon;
66 CFontTableCache* fontCache = new CFontTableCache(iHeap,mon);
69 TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
70 TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
71 RPointerArray<TCacheUserInfo> userArray;
72 userArray.Append(user1);
73 userArray.Append(user2);
76 CFontTableCacheItem* item1;
78 TAny* content = (iHeap->Alloc(3));
79 TUid iUid = TUid::Uid(123456);
80 item1 = new CFontTableCacheItem(iUid, 0x68656164, Ptr2Offset(content, iHeap->Base()), len);
81 item1->SetUser(userArray);
82 RPointerArray<CFontTableCacheItem> itemArray;
83 itemArray.Append(item1);
86 fontCache->SetFontItem(itemArray);
87 TBool has = fontCache->HasOutstandingRefCount();
89 has = fontCache->HasOutstandingRefCountWithUid(iUid);
91 TUid uid = TUid::Uid(1234);
92 fontCache->HasOutstandingRefCountWithUid(uid); //for coverage
98 TInt err = fontCache->Find(uid, tag, outline, length, &id);
99 TEST(err != KErrNone);
100 err = fontCache->Find(iUid, tag, outline, length, &id);
101 TEST(err != KErrNone);
103 fontCache->Append(uid, tag, content, length);
104 TEST(err != KErrNone);
107 fontCache->CleanupCacheOnFbsSessionTermination(123);
108 TEST(err != KErrNone);
116 void CTCache::TFontCacheItem()
119 TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
120 TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
121 RPointerArray<TCacheUserInfo> userArray;
122 userArray.Append(user1);
123 userArray.Append(user2);
125 CFontTableCacheItem* item1;
126 TAny* content = User::Alloc(4);
127 TUid iUid = TUid::Uid(123456);
128 item1 = new CFontTableCacheItem(iUid, 0x68656164, Ptr2Offset(content, User::Heap().Base()), 3);
131 TInt err = item1->IncRefCount(111);
132 TEST(err == KErrNoMemory);
135 TBool has = item1->HasOutstandingRefCount();
139 item1->SetUser(userArray);
140 has = item1->HasOutstandingRefCount();
144 err = item1->FindUser(333, &id);
145 TEST(err != KErrNone);
147 err = item1->DecRefCount(333);
148 TEST(err == KErrNotFound);
157 void CTCache::TGlyphCacheItem()
161 TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
162 TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
164 RPointerArray<TCacheUserInfo> userArray;
165 userArray.Append(user1);
166 userArray.Append(user2);
168 COutlineCacheItem* item1;
170 TAny* content = User::Alloc(4);
171 item1 = new COutlineCacheItem(Ptr2Offset(content, User::Heap().Base()), len);
174 TInt err = item1->DecRefCount(333);
175 err = item1->IncRefCount(111);
176 TEST(err == KErrNoMemory);
180 item1->SetUser(userArray);
181 err = item1->IncRefCount(333);
182 TEST(err == KErrNone);
189 void CTCache::THintedGlyphCache()
192 TFontTableGlyphOutlineCacheMemMonitor mon;
193 CHintedOutlineCache* hintedCache = new CHintedOutlineCache(iHeap,mon);
194 TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
195 TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
196 RPointerArray<TCacheUserInfo> userArray;
197 userArray.Append(user1);
198 userArray.Append(user2);
199 COutlineCacheItem* item1;
201 //TUint content[] = {1,2,3};
202 TAny* content = User::Alloc(4);
203 item1 = new COutlineCacheItem(Ptr2Offset(content, User::Heap().Base()), len);
204 item1->SetUser(userArray);
205 COpenFont* openFont = NULL;
206 THintedOutlineId hintedId(openFont, 11);
207 hintedCache->SetHintedItem(hintedId, item1);
208 RHashMap<THintedOutlineId, COutlineCacheItem*> map = hintedCache->GetHintedMap();
210 THintedOutlineId hintedId1(openFont, 12);
211 TInt err = hintedCache->IncRefCount(hintedId1, 111);
212 TEST(err != KErrNone);
213 COpenFont* openFont1 = reinterpret_cast<COpenFont*>(0x123);
215 err = hintedCache->CleanupCacheOnOpenFontRemoval(openFont1);
216 TEST(err == KErrNone);
217 //following return value alway KErrNone
218 hintedCache->CleanupCacheOnFbsSessionTermination(111);
219 hintedCache->CleanupCacheOnFbsSessionTermination(333);
224 hintedCache->CacheHintedOutline(hintedId1, &content, len, ptr, size);
227 __RHEAP_FAILNEXT(iHeap, 1);
228 hintedCache->CacheHintedOutline(hintedId1, &content, len, ptr, size);
229 __RHEAP_RESET(iHeap);
232 mon.Inc(KFontTable_GlyphOutline_CacheMaxMem);
233 err = hintedCache->CacheHintedOutline(hintedId1, &content, len, ptr, len);
234 TEST(err == KErrNoMemory);
244 void CTCache::TUnHintedGlyphCache()
247 TFontTableGlyphOutlineCacheMemMonitor mon;
248 CUnhintedOutlineCache* unhintedCache = new CUnhintedOutlineCache(iHeap,mon);
249 TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
250 TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
251 RPointerArray<TCacheUserInfo> userArray;
252 userArray.Append(user1);
253 userArray.Append(user2);
254 COutlineCacheItem* item1;
256 TAny* content = (iHeap->Alloc(3));
257 item1 = new COutlineCacheItem(Ptr2Offset(content, iHeap->Base()), len);
258 item1->SetUser(userArray);
259 TUid uid = TUid::Uid(123);
260 TUnhintedOutlineId unhintedId(uid, 11, 1);
261 unhintedCache->SetUnHintedItem(unhintedId, item1);
262 // RHashMap<TUnhintedOutlineId, COutlineCacheItem*> map = unhintedCache->GetHintedMap();
263 TUnhintedOutlineId unhintedId1(uid, 12, 1);
264 TInt err = unhintedCache->IncRefCount(unhintedId1, 111);
265 TEST(err != KErrNone);
267 unhintedCache->CleanupCacheOnFbsSessionTermination(111);
268 unhintedCache->CleanupCacheOnFbsSessionTermination(333);
273 unhintedCache->CacheUnhintedOutline(unhintedId1, &content, len, ptr, size);
276 __RHEAP_FAILNEXT(iHeap, 1);
277 unhintedCache->CacheUnhintedOutline(unhintedId1, &content, len, ptr, size);
278 __RHEAP_RESET(iHeap);
281 mon.Inc(KFontTable_GlyphOutline_CacheMaxMem);
282 err = unhintedCache->CacheUnhintedOutline(unhintedId1, &content, len, ptr, len);
283 TEST(err == KErrNoMemory);
286 delete unhintedCache;
291 void CTCache::TFontCacheForCov()
294 TFontTableGlyphOutlineCacheMemMonitor mon;
295 CFontTableCache* fontCache = new CFontTableCache(iHeap,mon);
297 TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
298 RPointerArray<TCacheUserInfo> userArray;
299 userArray.Append(user1);
300 CFontTableCacheItem* item1;
302 TAny* content = (iHeap->Alloc(3));
303 TUid iUid = TUid::Uid(123456);
304 item1 = new CFontTableCacheItem(iUid, 0x68656164, Ptr2Offset(content, iHeap->Base()), len);
305 item1->SetUser(userArray);
306 RPointerArray<CFontTableCacheItem> itemArray;
307 itemArray.Append(item1);
308 fontCache->SetFontItem(itemArray);
310 TBool has = fontCache->HasOutstandingRefCount();
312 has = fontCache->HasOutstandingRefCountWithUid(iUid);
316 TUint32 tag = 0x1234;
317 TUid uid = TUid::Uid(1234);
318 mon.Inc(KFontTable_GlyphOutline_CacheMaxMem);
319 TInt err = fontCache->Append(uid, tag, content, length);
320 TEST(err == KErrNoMemory);
328 void CTCache::RunTestCaseL(TInt aCurTestCase)
330 ((CTCacheStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
334 ((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0001"));
335 INFO_PRINTF1(_L("FontStore T_Cache test 1: TFontCacheItem\n"));
340 ((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0002"));
341 INFO_PRINTF1(_L("FontStore T_Cache test 2: TFontCache\n"));
347 ((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0003"));
348 INFO_PRINTF1(_L("FontStore T_Cache test 3: THintedGlyphCacheItem\n"));
353 ((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0004"));
354 INFO_PRINTF1(_L("FontStore T_Cache test 4: THintedGlyphCache\n"));
359 ((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0005"));
360 INFO_PRINTF1(_L("FontStore T_Cache test 5: TUnHintedGlyphCache\n"));
361 TUnHintedGlyphCache();
365 ((CTCacheStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
366 ((CTCacheStep*)iStep)->CloseTMSGraphicsStep();
370 ((CTCacheStep*)iStep)->RecordTestResultL();
374 __CONSTRUCT_STEP__(Cache)