1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/fontstore/tfs/T_Cache.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,377 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +#include "T_IsolatedFontStore.h"
1.22 +#include "openfontsprivate.h"
1.23 +#include <f32file.h>
1.24 +#include <e32test.h>
1.25 +#include <fntstore.h>
1.26 +#include <f32file.h>
1.27 +#include <s32file.h>
1.28 +#include <fbs.h>
1.29 +#include <graphics/openfontconstants.h>
1.30 +#include <graphics/openfontrasterizer.h>
1.31 +#include "T_Cache.H"
1.32 +
1.33 +LOCAL_C TInt Ptr2Offset(const TAny* aAny, TUint8* aHeapBase)
1.34 + {
1.35 + if (aAny && aHeapBase)
1.36 + {
1.37 + return (TInt)aAny - (TInt)aHeapBase;
1.38 + }
1.39 + return 0;
1.40 + }
1.41 +
1.42 +//LOCAL_C TAny* Offset2Ptr(const TInt aOffset, TUint8* aHeapBase)
1.43 +// {
1.44 +// if (aOffset && aHeapBase)
1.45 +// {
1.46 +// return (TAny*)(aOffset + (TInt)aHeapBase);
1.47 +// }
1.48 +// return NULL;
1.49 +// }
1.50 +
1.51 +CTCache::CTCache(CTestStep* aStep):
1.52 + CTGraphicsBase(aStep)
1.53 + {
1.54 + INFO_PRINTF1(_L("FontStore T_Cache test\n"));
1.55 + iHeap=UserHeap::ChunkHeap(NULL,0x1000000,0x1000000);
1.56 + }
1.57 +
1.58 +CTCache::~CTCache()
1.59 + {
1.60 + iHeap->Close();
1.61 + }
1.62 +
1.63 +//below code is for unit test and coverage only
1.64 +
1.65 +void CTCache::TFontCache()
1.66 + {
1.67 +#ifdef _DEBUG
1.68 + TFontTableGlyphOutlineCacheMemMonitor mon;
1.69 + CFontTableCache* fontCache = new CFontTableCache(iHeap,mon);
1.70 +
1.71 + //user array
1.72 + TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
1.73 + TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
1.74 + RPointerArray<TCacheUserInfo> userArray;
1.75 + userArray.Append(user1);
1.76 + userArray.Append(user2);
1.77 +
1.78 + //item array
1.79 + CFontTableCacheItem* item1;
1.80 + TInt len = 3;
1.81 + TAny* content = (iHeap->Alloc(3));
1.82 + TUid iUid = TUid::Uid(123456);
1.83 + item1 = new CFontTableCacheItem(iUid, 0x68656164, Ptr2Offset(content, iHeap->Base()), len);
1.84 + item1->SetUser(userArray);
1.85 + RPointerArray<CFontTableCacheItem> itemArray;
1.86 + itemArray.Append(item1);
1.87 +
1.88 + //font cache
1.89 + fontCache->SetFontItem(itemArray);
1.90 + TBool has = fontCache->HasOutstandingRefCount();
1.91 + TEST(has);
1.92 + has = fontCache->HasOutstandingRefCountWithUid(iUid);
1.93 + TEST(has);
1.94 + TUid uid = TUid::Uid(1234);
1.95 + fontCache->HasOutstandingRefCountWithUid(uid); //for coverage
1.96 +
1.97 + TAny *outline = NULL;
1.98 + TInt length = 3;
1.99 + TInt id = 0;
1.100 + TUint32 tag = 0x1234;
1.101 + TInt err = fontCache->Find(uid, tag, outline, length, &id);
1.102 + TEST(err != KErrNone);
1.103 + err = fontCache->Find(iUid, tag, outline, length, &id);
1.104 + TEST(err != KErrNone);
1.105 + __UHEAP_FAILNEXT(1);
1.106 + fontCache->Append(uid, tag, content, length);
1.107 + TEST(err != KErrNone);
1.108 + __UHEAP_RESET;
1.109 +
1.110 + fontCache->CleanupCacheOnFbsSessionTermination(123);
1.111 + TEST(err != KErrNone);
1.112 +
1.113 + userArray.Close();
1.114 + delete fontCache;
1.115 + itemArray.Close();
1.116 +#endif
1.117 + }
1.118 +
1.119 +void CTCache::TFontCacheItem()
1.120 + {
1.121 +#ifdef _DEBUG
1.122 + TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
1.123 + TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
1.124 + RPointerArray<TCacheUserInfo> userArray;
1.125 + userArray.Append(user1);
1.126 + userArray.Append(user2);
1.127 +
1.128 + CFontTableCacheItem* item1;
1.129 + TAny* content = User::Alloc(4);
1.130 + TUid iUid = TUid::Uid(123456);
1.131 + item1 = new CFontTableCacheItem(iUid, 0x68656164, Ptr2Offset(content, User::Heap().Base()), 3);
1.132 + User::Free(content);
1.133 + __UHEAP_FAILNEXT(1);
1.134 + TInt err = item1->IncRefCount(111);
1.135 + TEST(err == KErrNoMemory);
1.136 + __UHEAP_RESET;
1.137 +
1.138 + TBool has = item1->HasOutstandingRefCount();
1.139 + TEST(!has);
1.140 +
1.141 +
1.142 + item1->SetUser(userArray);
1.143 + has = item1->HasOutstandingRefCount();
1.144 + TEST(has);
1.145 +
1.146 + TInt id = 1;
1.147 + err = item1->FindUser(333, &id);
1.148 + TEST(err != KErrNone);
1.149 +
1.150 + err = item1->DecRefCount(333);
1.151 + TEST(err == KErrNotFound);
1.152 +
1.153 +
1.154 + userArray.Close();
1.155 + delete item1;
1.156 +
1.157 +#endif
1.158 + }
1.159 +
1.160 +void CTCache::TGlyphCacheItem()
1.161 + {
1.162 +#ifdef _DEBUG
1.163 +
1.164 + TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
1.165 + TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
1.166 +
1.167 + RPointerArray<TCacheUserInfo> userArray;
1.168 + userArray.Append(user1);
1.169 + userArray.Append(user2);
1.170 +
1.171 + COutlineCacheItem* item1;
1.172 + TInt len = 3;
1.173 + TAny* content = User::Alloc(4);
1.174 + item1 = new COutlineCacheItem(Ptr2Offset(content, User::Heap().Base()), len);
1.175 + User::Free(content);
1.176 + __UHEAP_FAILNEXT(1);
1.177 + TInt err = item1->DecRefCount(333);
1.178 + err = item1->IncRefCount(111);
1.179 + TEST(err == KErrNoMemory);
1.180 + __UHEAP_RESET;
1.181 +
1.182 +
1.183 + item1->SetUser(userArray);
1.184 + err = item1->IncRefCount(333);
1.185 + TEST(err == KErrNone);
1.186 +
1.187 + userArray.Close();
1.188 + delete item1;
1.189 +#endif
1.190 + }
1.191 +
1.192 +void CTCache::THintedGlyphCache()
1.193 + {
1.194 +#ifdef _DEBUG
1.195 + TFontTableGlyphOutlineCacheMemMonitor mon;
1.196 + CHintedOutlineCache* hintedCache = new CHintedOutlineCache(iHeap,mon);
1.197 + TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
1.198 + TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
1.199 + RPointerArray<TCacheUserInfo> userArray;
1.200 + userArray.Append(user1);
1.201 + userArray.Append(user2);
1.202 + COutlineCacheItem* item1;
1.203 + TInt len = 4;
1.204 + //TUint content[] = {1,2,3};
1.205 + TAny* content = User::Alloc(4);
1.206 + item1 = new COutlineCacheItem(Ptr2Offset(content, User::Heap().Base()), len);
1.207 + item1->SetUser(userArray);
1.208 + COpenFont* openFont = NULL;
1.209 + THintedOutlineId hintedId(openFont, 11);
1.210 + hintedCache->SetHintedItem(hintedId, item1);
1.211 + RHashMap<THintedOutlineId, COutlineCacheItem*> map = hintedCache->GetHintedMap();
1.212 + //for coverage
1.213 + THintedOutlineId hintedId1(openFont, 12);
1.214 + TInt err = hintedCache->IncRefCount(hintedId1, 111);
1.215 + TEST(err != KErrNone);
1.216 + COpenFont* openFont1 = reinterpret_cast<COpenFont*>(0x123);
1.217 + //for coverage
1.218 + err = hintedCache->CleanupCacheOnOpenFontRemoval(openFont1);
1.219 + TEST(err == KErrNone);
1.220 + //following return value alway KErrNone
1.221 + hintedCache->CleanupCacheOnFbsSessionTermination(111);
1.222 + hintedCache->CleanupCacheOnFbsSessionTermination(333);
1.223 +
1.224 + TAny* ptr;
1.225 + TInt size = 0;
1.226 + __UHEAP_FAILNEXT(1);
1.227 + hintedCache->CacheHintedOutline(hintedId1, &content, len, ptr, size);
1.228 + __UHEAP_RESET;
1.229 +
1.230 + __RHEAP_FAILNEXT(iHeap, 1);
1.231 + hintedCache->CacheHintedOutline(hintedId1, &content, len, ptr, size);
1.232 + __RHEAP_RESET(iHeap);
1.233 +
1.234 +
1.235 + mon.Inc(KFontTable_GlyphOutline_CacheMaxMem);
1.236 + err = hintedCache->CacheHintedOutline(hintedId1, &content, len, ptr, len);
1.237 + TEST(err == KErrNoMemory);
1.238 + User::Free(content);
1.239 +
1.240 + map.Close();
1.241 + delete item1;
1.242 + userArray.Close();
1.243 + delete hintedCache;
1.244 +#endif
1.245 + }
1.246 +
1.247 +void CTCache::TUnHintedGlyphCache()
1.248 + {
1.249 +#ifdef _DEBUG
1.250 + TFontTableGlyphOutlineCacheMemMonitor mon;
1.251 + CUnhintedOutlineCache* unhintedCache = new CUnhintedOutlineCache(iHeap,mon);
1.252 + TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
1.253 + TCacheUserInfo* user2 = new TCacheUserInfo(222,1);
1.254 + RPointerArray<TCacheUserInfo> userArray;
1.255 + userArray.Append(user1);
1.256 + userArray.Append(user2);
1.257 + COutlineCacheItem* item1;
1.258 + TInt len = 3;
1.259 + TAny* content = (iHeap->Alloc(3));
1.260 + item1 = new COutlineCacheItem(Ptr2Offset(content, iHeap->Base()), len);
1.261 + item1->SetUser(userArray);
1.262 + TUid uid = TUid::Uid(123);
1.263 + TUnhintedOutlineId unhintedId(uid, 11, 1);
1.264 + unhintedCache->SetUnHintedItem(unhintedId, item1);
1.265 +// RHashMap<TUnhintedOutlineId, COutlineCacheItem*> map = unhintedCache->GetHintedMap();
1.266 + TUnhintedOutlineId unhintedId1(uid, 12, 1);
1.267 + TInt err = unhintedCache->IncRefCount(unhintedId1, 111);
1.268 + TEST(err != KErrNone);
1.269 + //for coverage
1.270 + unhintedCache->CleanupCacheOnFbsSessionTermination(111);
1.271 + unhintedCache->CleanupCacheOnFbsSessionTermination(333);
1.272 +
1.273 + TAny* ptr;
1.274 + TInt size = 0;
1.275 + __UHEAP_FAILNEXT(1);
1.276 + unhintedCache->CacheUnhintedOutline(unhintedId1, &content, len, ptr, size);
1.277 + __UHEAP_RESET;
1.278 +
1.279 + __RHEAP_FAILNEXT(iHeap, 1);
1.280 + unhintedCache->CacheUnhintedOutline(unhintedId1, &content, len, ptr, size);
1.281 + __RHEAP_RESET(iHeap);
1.282 +
1.283 +
1.284 + mon.Inc(KFontTable_GlyphOutline_CacheMaxMem);
1.285 + err = unhintedCache->CacheUnhintedOutline(unhintedId1, &content, len, ptr, len);
1.286 + TEST(err == KErrNoMemory);
1.287 +
1.288 + userArray.Close();
1.289 + delete unhintedCache;
1.290 +
1.291 +#endif
1.292 + }
1.293 +
1.294 +void CTCache::TFontCacheForCov()
1.295 + {
1.296 +#ifdef _DEBUG
1.297 + TFontTableGlyphOutlineCacheMemMonitor mon;
1.298 + CFontTableCache* fontCache = new CFontTableCache(iHeap,mon);
1.299 +
1.300 + TCacheUserInfo* user1 = new TCacheUserInfo(111,0);
1.301 + RPointerArray<TCacheUserInfo> userArray;
1.302 + userArray.Append(user1);
1.303 + CFontTableCacheItem* item1;
1.304 + TInt len = 3;
1.305 + TAny* content = (iHeap->Alloc(3));
1.306 + TUid iUid = TUid::Uid(123456);
1.307 + item1 = new CFontTableCacheItem(iUid, 0x68656164, Ptr2Offset(content, iHeap->Base()), len);
1.308 + item1->SetUser(userArray);
1.309 + RPointerArray<CFontTableCacheItem> itemArray;
1.310 + itemArray.Append(item1);
1.311 + fontCache->SetFontItem(itemArray);
1.312 +
1.313 + TBool has = fontCache->HasOutstandingRefCount();
1.314 + TEST(!has);
1.315 + has = fontCache->HasOutstandingRefCountWithUid(iUid);
1.316 + TEST(!has);
1.317 +
1.318 + TUint length = 3;
1.319 + TUint32 tag = 0x1234;
1.320 + TUid uid = TUid::Uid(1234);
1.321 + mon.Inc(KFontTable_GlyphOutline_CacheMaxMem);
1.322 + TInt err = fontCache->Append(uid, tag, content, length);
1.323 + TEST(err == KErrNoMemory);
1.324 +
1.325 + userArray.Close();
1.326 + delete fontCache;
1.327 + itemArray.Close();
1.328 +#endif
1.329 + }
1.330 +
1.331 +void CTCache::RunTestCaseL(TInt aCurTestCase)
1.332 + {
1.333 + ((CTCacheStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.334 + switch(aCurTestCase)
1.335 + {
1.336 + case 1:
1.337 + ((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0001"));
1.338 + INFO_PRINTF1(_L("FontStore T_Cache test 1: TFontCacheItem\n"));
1.339 + TFontCacheItem();
1.340 + break;
1.341 +
1.342 + case 2:
1.343 + ((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0002"));
1.344 + INFO_PRINTF1(_L("FontStore T_Cache test 2: TFontCache\n"));
1.345 + TFontCache();
1.346 + TFontCacheForCov();
1.347 + break;
1.348 +
1.349 + case 3:
1.350 + ((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0003"));
1.351 + INFO_PRINTF1(_L("FontStore T_Cache test 3: THintedGlyphCacheItem\n"));
1.352 + TGlyphCacheItem();
1.353 + break;
1.354 +
1.355 + case 4:
1.356 + ((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0004"));
1.357 + INFO_PRINTF1(_L("FontStore T_Cache test 4: THintedGlyphCache\n"));
1.358 + THintedGlyphCache();
1.359 + break;
1.360 +
1.361 + case 5:
1.362 + ((CTCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-Cache-0005"));
1.363 + INFO_PRINTF1(_L("FontStore T_Cache test 5: TUnHintedGlyphCache\n"));
1.364 + TUnHintedGlyphCache();
1.365 + break;
1.366 +
1.367 + case 6:
1.368 + ((CTCacheStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.369 + ((CTCacheStep*)iStep)->CloseTMSGraphicsStep();
1.370 + TestComplete();
1.371 + break;
1.372 + }
1.373 + ((CTCacheStep*)iStep)->RecordTestResultL();
1.374 + }
1.375 +
1.376 +//--------------
1.377 +__CONSTRUCT_STEP__(Cache)
1.378 +
1.379 +
1.380 +