sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "GraphicsTestUtils.h" sl@0: #include "FNTBODY_OLD.H" sl@0: #include "T_FontBitmap.H" sl@0: sl@0: sl@0: #ifdef __WINS__ sl@0: _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr"); sl@0: #else sl@0: _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon.gdr"); sl@0: #endif sl@0: sl@0: _LIT(KTSectionFontRAM,"c:\\resource\\fonts\\TSection.gdr"); sl@0: _LIT(KTSectionFontROM,"z:\\test\\TSection.gdr"); sl@0: sl@0: sl@0: class CTFontBitmap : public CTGraphicsBase sl@0: { sl@0: public: sl@0: CTFontBitmap(CTestStep* aStep); sl@0: ~CTFontBitmap(); sl@0: sl@0: protected: sl@0: //from CTGraphicsStep sl@0: virtual void RunTestCaseL(TInt aCurTestCase); sl@0: virtual void ConstructL(); sl@0: sl@0: void ConnectFileSysL (); sl@0: void Test(); sl@0: private: sl@0: void TestAllL(); sl@0: sl@0: CFontBitmap* CreateFontNewLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream); sl@0: CFontBitmapOld* CreateFontOldLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream); sl@0: sl@0: private: sl@0: RHeap* iHeapNew; sl@0: RHeap* iHeapOld; sl@0: RFs iFilesys; sl@0: }; sl@0: sl@0: LOCAL_C void DestroyFontNew(TAny* aPtr) sl@0: { sl@0: CFontBitmap* font = reinterpret_cast (aPtr); sl@0: font->Release(); sl@0: font->Release(); sl@0: } sl@0: sl@0: LOCAL_C void DestroyFontOld(TAny* aPtr) sl@0: { sl@0: CFontBitmapOld* font = reinterpret_cast (aPtr); sl@0: font->Release(); sl@0: font->Release(); sl@0: } sl@0: sl@0: TBool operator==(const TBitmapFontCharacterMetrics& l, const TBitmapFontCharacterMetrics& r) sl@0: { sl@0: return (l.iAscentInPixels == r.iAscentInPixels && sl@0: l.iHeightInPixels == r.iHeightInPixels && sl@0: l.iLeftAdjustInPixels == r.iLeftAdjustInPixels && sl@0: l.iMoveInPixels == r.iMoveInPixels && sl@0: l.iRightAdjustInPixels == r.iRightAdjustInPixels); sl@0: } sl@0: sl@0: CTFontBitmap::CTFontBitmap(CTestStep* aStep): sl@0: CTGraphicsBase(aStep), sl@0: iHeapNew(NULL), sl@0: iHeapOld(NULL) sl@0: { sl@0: } sl@0: sl@0: CTFontBitmap::~CTFontBitmap() sl@0: { sl@0: iFilesys.Close(); sl@0: iHeapOld->Close(); sl@0: iHeapNew->Close(); sl@0: } sl@0: sl@0: void CTFontBitmap::ConstructL() sl@0: { sl@0: iHeapNew = UserHeap::ChunkHeap(NULL,0x80000, 0x80000); sl@0: iHeapOld = UserHeap::ChunkHeap(NULL,0x80000, 0x80000); sl@0: sl@0: ConnectFileSysL(); sl@0: } sl@0: sl@0: void CTFontBitmap::RunTestCaseL(TInt aCurTestCase) sl@0: { sl@0: ((CTFontBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); sl@0: switch(aCurTestCase) sl@0: { sl@0: case 1: sl@0: ((CTFontBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0028")); sl@0: Test(); sl@0: break; sl@0: case 2: sl@0: ((CTFontBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: ((CTFontBitmapStep*)iStep)->CloseTMSGraphicsStep(); sl@0: TestComplete(); sl@0: break; sl@0: } sl@0: ((CTFontBitmapStep*)iStep)->RecordTestResultL(); sl@0: } sl@0: sl@0: void CTFontBitmap::ConnectFileSysL () sl@0: { sl@0: User::LeaveIfError(iFilesys.Connect()); sl@0: } sl@0: sl@0: void CTFontBitmap::Test() sl@0: { sl@0: INFO_PRINTF1(_L("All bitmap fonts")); sl@0: sl@0: iHeapNew->__DbgMarkStart(); sl@0: iHeapOld->__DbgMarkStart(); sl@0: TRAPD(err, TestAllL()); sl@0: TEST(err == KErrNone); sl@0: iHeapNew->__DbgMarkCheck(ETrue, 0, TPtrC8((TText8*)__FILE__), __LINE__); sl@0: iHeapNew->__DbgMarkEnd(0); sl@0: iHeapOld->__DbgMarkCheck(ETrue, 0, TPtrC8((TText8*)__FILE__), __LINE__); sl@0: iHeapOld->__DbgMarkEnd(0); sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FNTSTORE-0028 sl@0: sl@0: @SYMTestCaseDesc sl@0: Tests all bitmap fonts. sl@0: sl@0: @SYMTestActions sl@0: 1. Creates a CFontStoreFile object from a file placed in ROM. sl@0: 2. Copies the file from the Z-drive to the C-drive. sl@0: 3. Tries to load the file from the C-drive to create a CFontStoreFile object. sl@0: 4. Opens two read streams. One for the old file and one for the new file. sl@0: 5. Retrieves the sizes of the files and checks they are the same. sl@0: 6. For both files it tries to create a font and allocates memory for them. sl@0: 7. Character metrics are compared between the two files. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTFontBitmap::TestAllL() sl@0: { sl@0: TParse fileNameParse; sl@0: sl@0: User::LeaveIfError(iFilesys.Parse(KEonFontFileName, fileNameParse)); sl@0: CFontStoreFile* fontstorefile_new = CFontStoreFile::NewL(fileNameParse, iFilesys); sl@0: CleanupStack::PushL(fontstorefile_new); sl@0: CFontStoreFile* fontstorefile_old = CFontStoreFile::NewL(fileNameParse, iFilesys); sl@0: CleanupStack::PushL(fontstorefile_old); sl@0: sl@0: // copy file from z: directory into c: sl@0: TEST( BaflUtils::FileExists(iFilesys, KTSectionFontROM) ); // placed here on WINS by fonts_c.mk or fntstoretest.iby on lubbock sl@0: sl@0: RSmlTestUtils testUtil; sl@0: CleanupClosePushL(testUtil); sl@0: testUtil.Connect(); sl@0: testUtil.CreateDirectoryL(KTSectionFontRAM); sl@0: testUtil.CopyFileL(KTSectionFontROM, KTSectionFontRAM); sl@0: CleanupStack::PopAndDestroy(&testUtil); sl@0: sl@0: TEST( BaflUtils::FileExists(iFilesys, KTSectionFontRAM) ); sl@0: sl@0: // try to load the from from C: drive sl@0: User::LeaveIfError(iFilesys.Parse(KTSectionFontRAM, fileNameParse)); sl@0: CFontStoreFile* fontstorefile_C = CFontStoreFile::NewL(fileNameParse, iFilesys); sl@0: CleanupStack::PushL(fontstorefile_C); sl@0: sl@0: RStoreReadStream stream_new; sl@0: stream_new.OpenLC(*fontstorefile_new->iFileStore, fontstorefile_new->iDataStreamId); sl@0: RStoreReadStream stream_old; sl@0: stream_old.OpenLC(*fontstorefile_old->iFileStore, fontstorefile_old->iDataStreamId); sl@0: TInt i; sl@0: TInt size_new = stream_new.ReadInt32L(); sl@0: TInt size_old = stream_old.ReadInt32L(); sl@0: TEST(size_new == size_old); sl@0: INFO_PRINTF1(_L("")); sl@0: for (i=0; iiUid.iUid, font_new->iNumCodeSections); sl@0: TInt alloc_size_new = 0; sl@0: TInt cells_count_new = iHeapNew->AllocSize(alloc_size_new); sl@0: TInt alloc_size_old = 0; sl@0: TInt cells_count_old = iHeapOld->AllocSize(alloc_size_old); sl@0: 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); sl@0: INFO_PRINTF2(_L("Profit=%d bytes\r\n"), alloc_size_old - alloc_size_new); sl@0: for(TInt j=0;j<256;j++) sl@0: { sl@0: INFO_PRINTF2(_L("Char code %d"),j); sl@0: const TUint8* bytes_new = NULL; sl@0: const TUint8* bytes_old = NULL; sl@0: TBitmapFontCharacterMetrics metrics_new; sl@0: TBitmapFontCharacterMetrics metrics_old; sl@0: metrics_new = font_new->CharacterMetrics(j, bytes_new); sl@0: metrics_old = font_old->CharacterMetrics(j, bytes_old); sl@0: TEST(bytes_new ? !!bytes_old : !bytes_old); sl@0: TEST(metrics_new == metrics_old); sl@0: if(bytes_new) sl@0: { sl@0: TInt byte_size_new = metrics_new.iMoveInPixels - metrics_new.iLeftAdjustInPixels - metrics_new.iRightAdjustInPixels; sl@0: if(byte_size_new < 8) sl@0: byte_size_new = 8; sl@0: byte_size_new /= 8; sl@0: byte_size_new *= metrics_new.iHeightInPixels; sl@0: TInt byte_size_old = metrics_old.iMoveInPixels - metrics_old.iLeftAdjustInPixels - metrics_old.iRightAdjustInPixels; sl@0: if(byte_size_old < 8) sl@0: byte_size_old = 8; sl@0: byte_size_old /= 8; sl@0: byte_size_old *= metrics_old.iHeightInPixels; sl@0: if(byte_size_new > 0) sl@0: { sl@0: TPtrC8 data_new(bytes_new, byte_size_new); sl@0: TPtrC8 data_old(bytes_old, byte_size_old); sl@0: TInt res = data_new.Compare(data_old); sl@0: TEST(res == 0); sl@0: } sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(2); //font_new & font_old sl@0: } sl@0: CleanupStack::PopAndDestroy(5); //fontstorefile & stream - old & new + fontstorefile_C sl@0: } sl@0: sl@0: const TInt KOldFontVer = 41; sl@0: sl@0: CFontBitmap* CTFontBitmap::CreateFontNewLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream) sl@0: { sl@0: CFontBitmap* fontbitmap = (CFontBitmap*)iHeapNew->AllocL(sizeof(CFontBitmap)); sl@0: new (fontbitmap) CFontBitmap(iHeapNew, aFontStoreFile); sl@0: TRAPD(ret, fontbitmap->InternalizeL(aStream, KOldFontVer)); sl@0: if(ret != KErrNone) sl@0: { sl@0: fontbitmap->Release(); sl@0: User::Leave(ret); sl@0: } sl@0: CleanupStack::PushL(TCleanupItem(DestroyFontNew, fontbitmap)); sl@0: fontbitmap->UseL(); sl@0: return fontbitmap; sl@0: } sl@0: sl@0: CFontBitmapOld* CTFontBitmap::CreateFontOldLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream) sl@0: { sl@0: CFontBitmapOld* fontbitmap = (CFontBitmapOld*)iHeapOld->AllocL(sizeof(CFontBitmapOld)); sl@0: new (fontbitmap) CFontBitmapOld(iHeapOld, aFontStoreFile); sl@0: TRAPD(ret, fontbitmap->InternalizeL(aStream)); sl@0: if(ret != KErrNone) sl@0: { sl@0: fontbitmap->Release(); sl@0: User::Leave(ret); sl@0: } sl@0: CleanupStack::PushL(TCleanupItem(DestroyFontOld, fontbitmap)); sl@0: fontbitmap->UseL(); sl@0: return fontbitmap; sl@0: } sl@0: sl@0: //-------------- sl@0: __CONSTRUCT_STEP__(FontBitmap) sl@0: