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