19 @file |
19 @file |
20 @test |
20 @test |
21 @internalComponent - Internal Symbian test code |
21 @internalComponent - Internal Symbian test code |
22 */ |
22 */ |
23 |
23 |
24 #include <e32base.h> |
|
25 #include <e32cons.h> |
|
26 #include <e32test.h> |
|
27 #include <e32std.h> |
|
28 #include <e32debug.h> |
|
29 #include "FNTSTORE.H" |
24 #include "FNTSTORE.H" |
30 #include "FNTBODY.H" |
|
31 #include "FNTSTD.H" |
|
32 #include <fbs.h> |
|
33 #include <bitstd.h> |
|
34 #include <bitdev.h> |
|
35 #include <e32math.h> |
25 #include <e32math.h> |
36 |
26 |
37 _LIT(KOpenFont, "DejaVu Sans Condensed"); |
27 _LIT(KOpenFont, "DejaVu Sans Condensed"); |
38 |
28 |
39 #ifdef __WINSCW__ |
29 #ifdef __WINSCW__ |
40 //this is used for winscw breakpoints |
30 //this is used for winscw breakpoints |
41 #define BR _asm( int 3); |
31 #define BR _asm( int 3); |
42 #endif |
32 #endif |
43 |
33 |
44 const TInt KTimeOut = 1000 * 1000; |
34 const TInt KTimeOut = 1000 * 1000; |
45 //make sure that the font is large enough to ensure that the session |
35 |
46 //cache is used. |
36 |
47 const TInt KTextHight = 220; |
37 _LIT(KTCacheDeletionProcess,"T_fontsessioncacheproc"); |
48 |
38 |
49 /* it is expected that the main in this file will be called to test multiple |
39 /* it is expected that the main in this file will be called to test multiple |
50 process output at the same time a process is being deleted (font and bitmap server |
40 process cache searching which is in the shared heap. |
51 disconnection. There are normally two instances of this process. Two virtually |
|
52 identical processes are required to ensure that the session ID is the same. |
|
53 |
|
54 The first is with aThirdProcess set. This sets output to run in a loop until |
|
55 the timeout is completed. These values are input via program arguments. |
|
56 |
|
57 If aThirdProcess is false then only one font creation, draw text, |
|
58 font deletion cycle is completed. The test code will then repeatedly run |
|
59 this process with aThirdProcess set to false. |
|
60 */ |
41 */ |
61 |
42 |
62 |
43 class CRunProc: public CBase |
63 class TRunProc: public CBase |
|
64 { |
44 { |
65 public: |
45 public: |
66 static TRunProc* NewL(); |
|
67 void RunTestL(); |
46 void RunTestL(); |
68 ~TRunProc(); |
47 CRunProc(); |
|
48 ~CRunProc(); |
|
49 |
|
50 inline void setFont(CFont*); |
|
51 inline void setHandle(TInt); |
69 private: |
52 private: |
70 TRunProc(){}; |
|
71 void ConstructL(); |
|
72 void DrawText(); |
|
73 void CreateFontL(); |
53 void CreateFontL(); |
74 |
54 |
75 private: |
55 private: |
76 RFbsSession* iFbs; |
56 CBitmapFont* iFont; |
77 CFbsBitGc* iGc; |
57 TInt iSessionHandle; |
78 CFbsScreenDevice* iDev; |
|
79 CFbsFont *iFbsFont; |
|
80 }; |
58 }; |
81 |
59 |
82 TRunProc::~TRunProc() |
60 CRunProc::CRunProc() |
83 { |
61 { |
84 delete iGc; |
62 |
85 delete iDev; |
|
86 iFbs->Disconnect(); |
|
87 } |
63 } |
88 |
64 |
89 void TRunProc::ConstructL() |
65 CRunProc::~CRunProc() |
90 { |
66 { |
91 TInt err = RFbsSession::Connect(); |
|
92 User::LeaveIfError(err); |
|
93 iFbs = RFbsSession::GetSession(); |
|
94 User::LeaveIfNull(iFbs); |
|
95 |
67 |
96 const TInt KDisplayMode = 3; |
|
97 TDisplayMode mode[KDisplayMode]; |
|
98 mode[0] = EColor16MA; |
|
99 mode[1] = EColor16MU; |
|
100 mode[2] = EColor64K; |
|
101 |
|
102 TInt count; |
|
103 for (count = 0; count < KDisplayMode; count++) |
|
104 { |
|
105 TRAP(err, iDev = CFbsScreenDevice::NewL(KNullDesC, mode[count])); |
|
106 if (err != KErrNotSupported) |
|
107 { |
|
108 break; |
|
109 } |
|
110 } |
|
111 |
|
112 User::LeaveIfNull(iDev); |
|
113 |
|
114 if(err == KErrNone) |
|
115 { |
|
116 iDev->ChangeScreenDevice(NULL); |
|
117 iDev->SetAutoUpdate(ETrue); |
|
118 iDev->CreateContext(iGc); |
|
119 } |
|
120 User::LeaveIfNull(iGc); |
|
121 } |
68 } |
122 |
69 |
123 TRunProc* TRunProc::NewL() |
70 inline void CRunProc::setFont(CFont* aFont) |
124 { |
71 { |
125 TRunProc *ptr = new (ELeave) TRunProc; |
72 iFont = static_cast<CBitmapFont*>(aFont); |
126 CleanupStack::PushL(ptr); |
|
127 ptr->ConstructL(); |
|
128 CleanupStack::Pop(); |
|
129 return ptr; |
|
130 } |
73 } |
131 |
74 |
132 void TRunProc::CreateFontL() |
75 inline void CRunProc::setHandle(TInt aSessionHandle) |
133 { |
76 { |
134 TOpenFontSpec openFontSpec; |
77 iSessionHandle = aSessionHandle; |
135 openFontSpec.SetName(KOpenFont); |
|
136 openFontSpec.SetHeight(KTextHight); |
|
137 openFontSpec.SetItalic(EFalse); |
|
138 openFontSpec.SetBold(EFalse); |
|
139 |
|
140 TTypeface Typeface; |
|
141 Typeface.iName = KOpenFont; |
|
142 TFontSpec fs; |
|
143 fs.iTypeface = Typeface; |
|
144 |
|
145 fs.iHeight = KTextHight; |
|
146 CFbsFont* font = NULL; |
|
147 TInt err = iDev->GetNearestFontToDesignHeightInPixels(font, fs); |
|
148 |
|
149 User::LeaveIfNull(font); |
|
150 |
|
151 // Use the font |
|
152 iFbsFont = font; |
|
153 iGc->UseFont(font); |
|
154 iGc->Clear(); |
|
155 } |
78 } |
156 |
79 |
157 void TRunProc::RunTestL() |
80 |
|
81 void CRunProc::RunTestL() |
158 { |
82 { |
159 TTime theTime; |
83 TTime theTime; |
160 theTime.UniversalTime(); |
84 theTime.UniversalTime(); |
161 TInt64 randSeed(theTime.Int64()); |
85 TInt64 randSeed(theTime.Int64()); |
162 TInt random(Math::Rand(randSeed) % (1000 * 1000)); |
86 TInt random(Math::Rand(randSeed) % (1000 * 1000)); |
166 timer.CreateLocal(); |
90 timer.CreateLocal(); |
167 TRequestStatus timerStatus = KRequestPending; |
91 TRequestStatus timerStatus = KRequestPending; |
168 TTimeIntervalMicroSeconds32 timeout(KTimeOut); |
92 TTimeIntervalMicroSeconds32 timeout(KTimeOut); |
169 timer.After(timerStatus, timeout); |
93 timer.After(timerStatus, timeout); |
170 |
94 |
171 CreateFontL(); |
|
172 RDebug::Print(_L("DrawText()random=%d"), random); |
|
173 DrawText(); |
|
174 |
|
175 TText ch; |
95 TText ch; |
176 const TUint8 *bitmap; |
96 const TUint8 *bitmap = NULL; |
177 TSize bitmapsize; |
97 TSize bitmapsize; |
178 TOpenFontCharMetrics Metrics; |
98 TOpenFontCharMetrics Metrics; |
179 do |
99 do |
180 { |
100 { |
181 for (ch = 'A'; ch <= 'Z'; ch++) |
101 TInt hitcount = 0; |
|
102 for (ch = 'A'; ch <= 'z'; ch++) |
182 { |
103 { |
183 iFbsFont->GetCharacterData((TInt) ch, Metrics, bitmap,bitmapsize); |
104 if(iFont->GetCharacterData(iSessionHandle, (TInt)ch, Metrics,bitmap)) |
|
105 { |
|
106 //RDebug::Print(_L("%c hit bitmap[0]=%x"),ch,bitmap[0]); |
|
107 TUint8 testbyte = bitmap[0]; |
|
108 testbyte += testbyte; |
|
109 __ASSERT_ALWAYS((testbyte & 0x01) == 0, User::Panic(KTCacheDeletionProcess, KErrGeneral)); |
|
110 hitcount++; |
|
111 } |
|
112 else |
|
113 { |
|
114 //RDebug::Print(_L("%c missed"),ch); |
|
115 } |
184 } |
116 } |
|
117 __ASSERT_ALWAYS(hitcount > 0, User::Panic(KTCacheDeletionProcess, KErrNotFound)); |
185 } |
118 } |
186 while (timerStatus == KRequestPending); |
119 while (timerStatus == KRequestPending); |
187 |
120 |
188 timer.Cancel(); |
121 timer.Cancel(); |
189 iGc->DiscardFont(); |
|
190 timer.Close(); |
122 timer.Close(); |
191 } |
123 } |
192 |
|
193 |
|
194 void TRunProc::DrawText() |
|
195 { |
|
196 TText ch[2]; |
|
197 ch[1] = '\0'; |
|
198 for (ch[0] = 'A';ch[0] <= 'Z';ch[0]++) |
|
199 { |
|
200 TBufC<2> buf(ch); |
|
201 iGc->DrawText(buf,TPoint(10,100)); |
|
202 } |
|
203 for (ch[0] = 'a';ch[0] <= 'z';ch[0]++) |
|
204 { |
|
205 TBufC<2> buf(ch); |
|
206 iGc->DrawText(buf,TPoint(10,100)); |
|
207 } |
|
208 } |
|
209 |
|
210 |
|
211 |
124 |
212 void MainL() |
125 void MainL() |
213 { |
126 { |
214 TRunProc* test = TRunProc::NewL(); |
127 RChunk gChunk; |
|
128 User::LeaveIfError(gChunk.Open(1)); |
|
129 CleanupClosePushL(gChunk); |
|
130 |
|
131 TInt offset; |
|
132 User::LeaveIfError(User::GetTIntParameter(2,offset)); |
|
133 TInt SessionHandle; |
|
134 User::LeaveIfError(User::GetTIntParameter(3,SessionHandle)); |
|
135 |
|
136 CRunProc *test = new (ELeave) CRunProc; |
|
137 |
|
138 test->setFont(reinterpret_cast<CFont*>(offset + reinterpret_cast<TInt>(gChunk.Base()))); |
|
139 test->setHandle(SessionHandle); |
215 CleanupStack::PushL(test); |
140 CleanupStack::PushL(test); |
216 |
141 |
217 RDebug::Print(_L("T_fontsessioncacheproc MainL()")); |
142 RDebug::Print(_L("T_fontsessioncacheproc MainL()")); |
218 test->RunTestL(); |
143 test->RunTestL(); |
219 |
144 |
220 CleanupStack::PopAndDestroy(); |
145 CleanupStack::PopAndDestroy(2); |
221 } |
146 } |
222 |
147 |
223 // Cleanup stack harness |
148 // Cleanup stack harness |
224 GLDEF_C TInt E32Main() |
149 GLDEF_C TInt E32Main() |
225 { |
150 { |
226 __UHEAP_MARK; |
151 __UHEAP_MARK; |
227 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
152 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
228 TRAPD(error, MainL()); |
153 TRAPD(error, MainL()); |
229 _LIT(KTCacheDeletionProcess,"T_fontsessioncacheproc"); |
|
230 __ASSERT_ALWAYS(!error, User::Panic(KTCacheDeletionProcess, error)); |
154 __ASSERT_ALWAYS(!error, User::Panic(KTCacheDeletionProcess, error)); |
231 delete cleanupStack; |
155 delete cleanupStack; |
232 __UHEAP_MARKEND; |
156 __UHEAP_MARKEND; |
233 return 0; |
157 return 0; |
234 } |
158 } |