20 @test |
20 @test |
21 @internalComponent Internal Symbian test code |
21 @internalComponent Internal Symbian test code |
22 */ |
22 */ |
23 |
23 |
24 #include "FNTSTORE.H" |
24 #include "FNTSTORE.H" |
25 #include "OPENFONT.H" |
|
26 #include "FNTBODY.H" |
|
27 #include "FNTSTD.H" |
|
28 #include "t_fontsessioncache.h" |
25 #include "t_fontsessioncache.h" |
29 #include <hal.h> |
26 #include "T_IsolatedFontStore.h" |
30 #include <s32file.h> |
|
31 #include <graphics/shapeimpl.h> |
|
32 |
27 |
33 _LIT(KWorkerProcess,"tfontsessioncacheproc"); |
28 _LIT(KWorkerProcess,"tfontsessioncacheproc"); |
|
29 _LIT(KSharedChunk,"TestSharedChunk_T_FontSessionCache"); |
34 |
30 |
35 const TInt KNumOfProc = 4; |
31 const TInt KNumOfProc = 4; |
36 const TInt KRunningTime = 1000 * 1000 * 5; |
32 const TInt KRunningTime = 1000 * 1000 * 5; |
37 |
33 |
38 class CTFontSessionCache : public CTGraphicsBase |
34 //Make sure font is large enough that font and session caches are used sufficiently. |
39 { |
35 const TInt KFontHeight = 250; |
40 public: |
|
41 CTFontSessionCache(CTestStep* aStep); |
|
42 ~CTFontSessionCache(); |
|
43 |
|
44 static void TimerCleanup(TAny *); |
|
45 protected: |
|
46 // From CTGraphicsStep |
|
47 virtual void RunTestCaseL(TInt aCurTestCase); |
|
48 private: |
|
49 void TestOpenFontForQtL(); |
|
50 void RunMultiWorkerProcessL(); |
|
51 }; |
|
52 |
36 |
53 // This class is a data mirror to CBitmapFont in order to check its private |
37 // This class is a data mirror to CBitmapFont in order to check its private |
54 // member iOpenFont. It is only used by TestOpenFontForQtL(). |
38 // member iOpenFont. It is only used by TestOpenFontForQtL(). |
55 class CBitmapFontDummy:public CFont |
39 class CBitmapFontDummy:public CFont |
56 { |
40 { |
62 COpenFont* iOpenFont; |
46 COpenFont* iOpenFont; |
63 TUint32 iReserved; |
47 TUint32 iReserved; |
64 TUint32 iUniqueFontId; |
48 TUint32 iUniqueFontId; |
65 }; |
49 }; |
66 |
50 |
67 class CFbsFontUtil:public CFbsFont |
51 class CTFontSessionCache : public CTGraphicsBase |
68 { |
52 { |
69 public: |
53 public: |
70 static CBitmapFontDummy *getBitmapFont(CFbsFont *aFbsfont) |
54 CTFontSessionCache(CTestStep* aStep); |
71 { |
55 ~CTFontSessionCache(); |
72 return reinterpret_cast<CBitmapFontDummy*>(static_cast<CFbsFontUtil*>(aFbsfont)->Address()); |
56 TInt Base(); |
73 } |
57 |
|
58 protected: |
|
59 // From CTGraphicsStep |
|
60 virtual void RunTestCaseL(TInt aCurTestCase); |
|
61 virtual void ConstructL(); |
|
62 private: |
|
63 void TestOpenFontForQtL(); |
|
64 void RunMultiWorkerProcessL(); |
|
65 |
|
66 void FlushCaches(); |
|
67 |
|
68 private: |
|
69 CTIsolatedFontStore *iIFontStore; |
|
70 RHeap *iSharedHeap; |
|
71 RChunk iChunk; |
|
72 CFont *iFont; |
74 }; |
73 }; |
75 |
|
76 |
74 |
77 CTFontSessionCache::CTFontSessionCache(CTestStep* aStep) |
75 CTFontSessionCache::CTFontSessionCache(CTestStep* aStep) |
78 : CTGraphicsBase(aStep) |
76 : CTGraphicsBase(aStep) |
79 { |
77 { |
80 |
78 |
81 } |
79 } |
82 |
80 |
83 CTFontSessionCache::~CTFontSessionCache() |
81 CTFontSessionCache::~CTFontSessionCache() |
84 { |
82 { |
85 // no action needed |
83 iIFontStore->iFs->ReleaseFont(iFont); |
86 } |
84 delete iIFontStore; |
87 |
85 iChunk.Close(); |
88 void CTFontSessionCache::TimerCleanup(TAny *aTimer) |
86 } |
89 { |
87 |
90 ((RTimer*)aTimer)->Cancel(); |
88 inline TInt CTFontSessionCache::Base() |
|
89 { |
|
90 return reinterpret_cast<TInt>(iChunk.Base()); |
|
91 } |
|
92 |
|
93 void CTFontSessionCache::ConstructL() |
|
94 { |
|
95 User::LeaveIfError(iChunk.CreateGlobal(KNullDesC,500,500)); |
|
96 iSharedHeap = UserHeap::ChunkHeap(iChunk,0x10000,0x1000,0x10000,0,EFalse,0); |
|
97 if(iSharedHeap == NULL) |
|
98 { |
|
99 RDebug::Print(_L("iSharedHeap = NULL")); |
|
100 User::Leave(KErrNoMemory); |
|
101 } |
|
102 iIFontStore = CTIsolatedFontStore::NewL(iSharedHeap); |
|
103 iIFontStore->LoadRasterizersL(); |
|
104 iIFontStore->iFs->LoadFontsAtStartupL(); |
|
105 |
|
106 _LIT(KTypefaceName, "DejaVu Sans Condensed"); |
|
107 TFontSpec spec(KTypefaceName, KFontHeight); |
|
108 |
|
109 TInt ret = iIFontStore->iFs->GetNearestFontToDesignHeightInPixels(iFont,spec); |
|
110 TEST(ret == KErrNone); |
|
111 |
|
112 } |
|
113 |
|
114 void CTFontSessionCache::FlushCaches() |
|
115 { |
|
116 TText ch; |
|
117 TOpenFontGlyphData *glyphData = NULL; |
|
118 for (TInt sHandle = 0; sHandle < KNumOfProc; sHandle++) |
|
119 { |
|
120 for (ch = 'A'; ch <= 'z'; ch++) |
|
121 { |
|
122 static_cast<CBitmapFont*> (iFont)->Rasterize(sHandle, ch, glyphData); |
|
123 } |
|
124 } |
91 } |
125 } |
92 |
126 |
93 /** |
127 /** |
94 Qt needs the last bit of iOpenFont to be set 1 as a workaround to maintain |
128 @SYMTestCaseID |
95 its compatibility across difference Symbian OS versions. |
129 TI18N-FNTSTORE-UT--4003 |
96 */ |
130 |
|
131 @SYMTestCaseDesc |
|
132 Qt needs the last bit of iOpenFont to be set 1 as a workaround to maintain |
|
133 its compatibility across difference Symbian OS versions. |
|
134 |
|
135 @SYMTestActions |
|
136 1. Get a CBitmapFont in the constructor |
|
137 2. Check the LSB of its iOpenFont by using CBitmapFontDummy |
|
138 |
|
139 @SYMTestExpectedResults |
|
140 Test should pass |
|
141 */ |
|
142 |
97 void CTFontSessionCache::TestOpenFontForQtL() |
143 void CTFontSessionCache::TestOpenFontForQtL() |
98 { |
144 { |
99 _LIT(KTypefaceName, "DejaVu Sans Condensed"); |
145 TEST(reinterpret_cast<TInt>(reinterpret_cast<CBitmapFontDummy*>(iFont)->iOpenFont) & 1); |
100 TFontSpec spec(KTypefaceName, 15); |
146 } |
101 CFbsTypefaceStore *tfs = CFbsTypefaceStore::NewL(NULL); |
147 |
102 |
148 /** |
103 CFont* font = NULL; |
149 @SYMTestCaseID |
104 TInt ret = tfs->GetNearestFontToDesignHeightInPixels(font,spec); |
150 TI18N-FNTSTORE-CIT-4002 |
105 TEST(ret == KErrNone); |
151 |
106 |
152 @SYMTestCaseDesc |
107 CFbsFont *fbs_font = static_cast<CFbsFont*>(font); |
153 This case is to test the safty of actions over the shared heap. |
108 TEST(reinterpret_cast<TInt>((CFbsFontUtil::getBitmapFont(fbs_font))->iOpenFont) & 1); |
154 |
109 |
155 @SYMTestActions |
110 tfs->ReleaseFont(font); |
156 1. Shared heap is initialised in the constructor |
111 delete tfs; |
157 2. Run rasterizing function to Flush the font caches(glyph tree and session cache). |
112 } |
158 3. Launch KNumOfProc worker processes running with random latency at beginning, which |
113 |
159 is to seach the cache from different processes. The globle chunk and font handles are |
114 /* |
160 passed via process environment variables. |
115 * Launch 4 worker processes running with random latency at beginning. |
161 4. Each one lasts about 1 sec. Within duration of 5 sec, if one terminates, re-launch it. |
116 * Each one lasts about 1 sec. Within duration of 5 sec, if one terminates, |
162 |
117 * re-launch it. |
163 @SYMTestExpectedResults |
118 * |
164 Test should pass without any Panic. |
119 */ |
165 */ |
120 void CTFontSessionCache::RunMultiWorkerProcessL() |
166 void CTFontSessionCache::RunMultiWorkerProcessL() |
121 { |
167 { |
122 RProcess ProcArray[KNumOfProc]; |
168 RProcess ProcArray[KNumOfProc]; |
123 TRequestStatus *completeStatus[KNumOfProc]; |
169 TRequestStatus *completeStatus[KNumOfProc]; |
124 |
170 |
|
171 FlushCaches(); |
|
172 |
125 for (TInt i = 0; i < KNumOfProc; i++) |
173 for (TInt i = 0; i < KNumOfProc; i++) |
126 { |
174 { |
127 RDebug::Print(_L(">>> Launching %d..."),i); |
175 RDebug::Print(_L(">>> Launching %d..."),i); |
128 TInt err; |
176 TInt err; |
129 err = ProcArray[i].Create(KWorkerProcess, KNullDesC); |
177 err = ProcArray[i].Create(KWorkerProcess, KNullDesC); |
130 User::LeaveIfError(err); |
178 User::LeaveIfError(err); |
131 |
179 |
|
180 TInt FontOffset = reinterpret_cast<TInt>(iFont) - Base(); |
|
181 ProcArray[i].SetParameter(1,iChunk); |
|
182 ProcArray[i].SetParameter(2,FontOffset); |
|
183 ProcArray[i].SetParameter(3,i); |
|
184 |
132 completeStatus[i] = new(ELeave) TRequestStatus; |
185 completeStatus[i] = new(ELeave) TRequestStatus; |
133 CleanupStack::PushL(completeStatus[i]); |
186 CleanupStack::PushL(completeStatus[i]); |
134 *completeStatus[i] = KRequestPending; |
187 *completeStatus[i] = KRequestPending; |
135 |
188 |
136 ProcArray[i].Logon(*completeStatus[i]); |
189 ProcArray[i].Logon(*completeStatus[i]); |