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.
22 @internalComponent - Internal Symbian test code
29 #include "GraphicsTestUtils.h"
30 #include "FNTBODY_OLD.H"
31 #include "T_FontBitmap.H"
35 _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
37 _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon.gdr");
40 _LIT(KTSectionFontRAM,"c:\\resource\\fonts\\TSection.gdr");
41 _LIT(KTSectionFontROM,"z:\\test\\TSection.gdr");
44 class CTFontBitmap : public CTGraphicsBase
47 CTFontBitmap(CTestStep* aStep);
52 virtual void RunTestCaseL(TInt aCurTestCase);
53 virtual void ConstructL();
55 void ConnectFileSysL ();
60 CFontBitmap* CreateFontNewLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream);
61 CFontBitmapOld* CreateFontOldLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream);
69 LOCAL_C void DestroyFontNew(TAny* aPtr)
71 CFontBitmap* font = reinterpret_cast <CFontBitmap*> (aPtr);
76 LOCAL_C void DestroyFontOld(TAny* aPtr)
78 CFontBitmapOld* font = reinterpret_cast <CFontBitmapOld*> (aPtr);
83 TBool operator==(const TBitmapFontCharacterMetrics& l, const TBitmapFontCharacterMetrics& r)
85 return (l.iAscentInPixels == r.iAscentInPixels &&
86 l.iHeightInPixels == r.iHeightInPixels &&
87 l.iLeftAdjustInPixels == r.iLeftAdjustInPixels &&
88 l.iMoveInPixels == r.iMoveInPixels &&
89 l.iRightAdjustInPixels == r.iRightAdjustInPixels);
92 CTFontBitmap::CTFontBitmap(CTestStep* aStep):
93 CTGraphicsBase(aStep),
99 CTFontBitmap::~CTFontBitmap()
106 void CTFontBitmap::ConstructL()
108 iHeapNew = UserHeap::ChunkHeap(NULL,0x80000, 0x80000);
109 iHeapOld = UserHeap::ChunkHeap(NULL,0x80000, 0x80000);
114 void CTFontBitmap::RunTestCaseL(TInt aCurTestCase)
116 ((CTFontBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
120 ((CTFontBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0028"));
124 ((CTFontBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
125 ((CTFontBitmapStep*)iStep)->CloseTMSGraphicsStep();
129 ((CTFontBitmapStep*)iStep)->RecordTestResultL();
132 void CTFontBitmap::ConnectFileSysL ()
134 User::LeaveIfError(iFilesys.Connect());
137 void CTFontBitmap::Test()
139 INFO_PRINTF1(_L("All bitmap fonts"));
141 iHeapNew->__DbgMarkStart();
142 iHeapOld->__DbgMarkStart();
143 TRAPD(err, TestAllL());
144 TEST(err == KErrNone);
145 iHeapNew->__DbgMarkCheck(ETrue, 0, TPtrC8((TText8*)__FILE__), __LINE__);
146 iHeapNew->__DbgMarkEnd(0);
147 iHeapOld->__DbgMarkCheck(ETrue, 0, TPtrC8((TText8*)__FILE__), __LINE__);
148 iHeapOld->__DbgMarkEnd(0);
154 GRAPHICS-FNTSTORE-0028
157 Tests all bitmap fonts.
160 1. Creates a CFontStoreFile object from a file placed in ROM.
161 2. Copies the file from the Z-drive to the C-drive.
162 3. Tries to load the file from the C-drive to create a CFontStoreFile object.
163 4. Opens two read streams. One for the old file and one for the new file.
164 5. Retrieves the sizes of the files and checks they are the same.
165 6. For both files it tries to create a font and allocates memory for them.
166 7. Character metrics are compared between the two files.
168 @SYMTestExpectedResults
171 void CTFontBitmap::TestAllL()
173 TParse fileNameParse;
175 User::LeaveIfError(iFilesys.Parse(KEonFontFileName, fileNameParse));
176 CFontStoreFile* fontstorefile_new = CFontStoreFile::NewL(fileNameParse, iFilesys);
177 CleanupStack::PushL(fontstorefile_new);
178 CFontStoreFile* fontstorefile_old = CFontStoreFile::NewL(fileNameParse, iFilesys);
179 CleanupStack::PushL(fontstorefile_old);
181 // copy file from z: directory into c:
182 TEST( BaflUtils::FileExists(iFilesys, KTSectionFontROM) ); // placed here on WINS by fonts_c.mk or fntstoretest.iby on lubbock
184 RSmlTestUtils testUtil;
185 CleanupClosePushL(testUtil);
187 testUtil.CreateDirectoryL(KTSectionFontRAM);
188 testUtil.CopyFileL(KTSectionFontROM, KTSectionFontRAM);
189 CleanupStack::PopAndDestroy(&testUtil);
191 TEST( BaflUtils::FileExists(iFilesys, KTSectionFontRAM) );
193 // try to load the from from C: drive
194 User::LeaveIfError(iFilesys.Parse(KTSectionFontRAM, fileNameParse));
195 CFontStoreFile* fontstorefile_C = CFontStoreFile::NewL(fileNameParse, iFilesys);
196 CleanupStack::PushL(fontstorefile_C);
198 RStoreReadStream stream_new;
199 stream_new.OpenLC(*fontstorefile_new->iFileStore, fontstorefile_new->iDataStreamId);
200 RStoreReadStream stream_old;
201 stream_old.OpenLC(*fontstorefile_old->iFileStore, fontstorefile_old->iDataStreamId);
203 TInt size_new = stream_new.ReadInt32L();
204 TInt size_old = stream_old.ReadInt32L();
205 TEST(size_new == size_old);
206 INFO_PRINTF1(_L(""));
207 for (i=0; i<size_new; i++)
209 CFontBitmap* font_new = CreateFontNewLC(fontstorefile_new, stream_new);
210 CFontBitmapOld* font_old = CreateFontOldLC(fontstorefile_old, stream_old);
211 INFO_PRINTF3(_L("Font UID=%X, NumCodeSections=%d\r\n"), font_new->iUid.iUid, font_new->iNumCodeSections);
212 TInt alloc_size_new = 0;
213 TInt cells_count_new = iHeapNew->AllocSize(alloc_size_new);
214 TInt alloc_size_old = 0;
215 TInt cells_count_old = iHeapOld->AllocSize(alloc_size_old);
216 INFO_PRINTF5(_L("CellsCntNew=%d, AllocSizeNew=%d CellsCntOld=%d, AllocSizeOld=%d\r\n"), cells_count_new, alloc_size_new, cells_count_old, alloc_size_old);
217 INFO_PRINTF2(_L("Profit=%d bytes\r\n"), alloc_size_old - alloc_size_new);
218 for(TInt j=0;j<256;j++)
220 INFO_PRINTF2(_L("Char code %d"),j);
221 const TUint8* bytes_new = NULL;
222 const TUint8* bytes_old = NULL;
223 TBitmapFontCharacterMetrics metrics_new;
224 TBitmapFontCharacterMetrics metrics_old;
225 metrics_new = font_new->CharacterMetrics(j, bytes_new);
226 metrics_old = font_old->CharacterMetrics(j, bytes_old);
227 TEST(bytes_new ? !!bytes_old : !bytes_old);
228 TEST(metrics_new == metrics_old);
231 TInt byte_size_new = metrics_new.iMoveInPixels - metrics_new.iLeftAdjustInPixels - metrics_new.iRightAdjustInPixels;
232 if(byte_size_new < 8)
235 byte_size_new *= metrics_new.iHeightInPixels;
236 TInt byte_size_old = metrics_old.iMoveInPixels - metrics_old.iLeftAdjustInPixels - metrics_old.iRightAdjustInPixels;
237 if(byte_size_old < 8)
240 byte_size_old *= metrics_old.iHeightInPixels;
241 if(byte_size_new > 0)
243 TPtrC8 data_new(bytes_new, byte_size_new);
244 TPtrC8 data_old(bytes_old, byte_size_old);
245 TInt res = data_new.Compare(data_old);
250 CleanupStack::PopAndDestroy(2); //font_new & font_old
252 CleanupStack::PopAndDestroy(5); //fontstorefile & stream - old & new + fontstorefile_C
255 const TInt KOldFontVer = 41;
257 CFontBitmap* CTFontBitmap::CreateFontNewLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream)
259 CFontBitmap* fontbitmap = (CFontBitmap*)iHeapNew->AllocL(sizeof(CFontBitmap));
260 new (fontbitmap) CFontBitmap(iHeapNew, aFontStoreFile);
261 TRAPD(ret, fontbitmap->InternalizeL(aStream, KOldFontVer));
264 fontbitmap->Release();
267 CleanupStack::PushL(TCleanupItem(DestroyFontNew, fontbitmap));
272 CFontBitmapOld* CTFontBitmap::CreateFontOldLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream)
274 CFontBitmapOld* fontbitmap = (CFontBitmapOld*)iHeapOld->AllocL(sizeof(CFontBitmapOld));
275 new (fontbitmap) CFontBitmapOld(iHeapOld, aFontStoreFile);
276 TRAPD(ret, fontbitmap->InternalizeL(aStream));
279 fontbitmap->Release();
282 CleanupStack::PushL(TCleanupItem(DestroyFontOld, fontbitmap));
288 __CONSTRUCT_STEP__(FontBitmap)