os/textandloc/fontservices/fontstore/tfs/T_FontBitmap.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/fontstore/tfs/T_FontBitmap.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,289 @@
     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 +
    1.22 +/**
    1.23 + @file
    1.24 + @test
    1.25 + @internalComponent - Internal Symbian test code 
    1.26 +*/
    1.27 +
    1.28 +#include <s32file.h>
    1.29 +#include <gdi.h>
    1.30 +#include <bautils.h>
    1.31 +
    1.32 +#include "GraphicsTestUtils.h"
    1.33 +#include "FNTBODY_OLD.H"
    1.34 +#include "T_FontBitmap.H"
    1.35 +
    1.36 +
    1.37 +#ifdef __WINS__
    1.38 +_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
    1.39 +#else
    1.40 +_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon.gdr");
    1.41 +#endif
    1.42 +
    1.43 +_LIT(KTSectionFontRAM,"c:\\resource\\fonts\\TSection.gdr");
    1.44 +_LIT(KTSectionFontROM,"z:\\test\\TSection.gdr");
    1.45 +
    1.46 +
    1.47 +class CTFontBitmap : public CTGraphicsBase
    1.48 +	{
    1.49 +public:
    1.50 +	CTFontBitmap(CTestStep* aStep);
    1.51 +	~CTFontBitmap();
    1.52 +
    1.53 +protected:
    1.54 +//from 	CTGraphicsStep
    1.55 +	virtual void RunTestCaseL(TInt aCurTestCase);
    1.56 +	virtual void ConstructL();
    1.57 +
    1.58 +	void ConnectFileSysL ();
    1.59 +	void Test();
    1.60 +private:
    1.61 +	void TestAllL();
    1.62 +
    1.63 +	CFontBitmap* CreateFontNewLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream);
    1.64 +	CFontBitmapOld* CreateFontOldLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream);
    1.65 +
    1.66 +private:
    1.67 +	RHeap* iHeapNew;
    1.68 +	RHeap* iHeapOld;
    1.69 +	RFs iFilesys;
    1.70 +	};
    1.71 +
    1.72 +LOCAL_C void DestroyFontNew(TAny* aPtr)
    1.73 +	{
    1.74 +	CFontBitmap* font = reinterpret_cast <CFontBitmap*> (aPtr);
    1.75 +	font->Release();
    1.76 +	font->Release();
    1.77 +	}
    1.78 +
    1.79 +LOCAL_C void DestroyFontOld(TAny* aPtr)
    1.80 +	{
    1.81 +	CFontBitmapOld* font = reinterpret_cast <CFontBitmapOld*> (aPtr);
    1.82 +	font->Release();
    1.83 +	font->Release();
    1.84 +	}
    1.85 +
    1.86 +TBool operator==(const TBitmapFontCharacterMetrics& l, const TBitmapFontCharacterMetrics& r)
    1.87 +	{
    1.88 +	return (l.iAscentInPixels == r.iAscentInPixels &&
    1.89 +			l.iHeightInPixels == r.iHeightInPixels &&
    1.90 +			l.iLeftAdjustInPixels == r.iLeftAdjustInPixels &&
    1.91 +			l.iMoveInPixels == r.iMoveInPixels &&
    1.92 +			l.iRightAdjustInPixels == r.iRightAdjustInPixels);
    1.93 +	}
    1.94 +
    1.95 +CTFontBitmap::CTFontBitmap(CTestStep* aStep):
    1.96 +	CTGraphicsBase(aStep),
    1.97 +	iHeapNew(NULL),
    1.98 +	iHeapOld(NULL)
    1.99 +	{
   1.100 +	}
   1.101 +
   1.102 +CTFontBitmap::~CTFontBitmap()
   1.103 +	{
   1.104 +	iFilesys.Close();
   1.105 +	iHeapOld->Close();
   1.106 +	iHeapNew->Close();
   1.107 +	}
   1.108 +
   1.109 +void CTFontBitmap::ConstructL()
   1.110 +	{
   1.111 +	iHeapNew = UserHeap::ChunkHeap(NULL,0x80000, 0x80000);
   1.112 +	iHeapOld = UserHeap::ChunkHeap(NULL,0x80000, 0x80000);
   1.113 +
   1.114 +	ConnectFileSysL();
   1.115 +	}
   1.116 +
   1.117 +void CTFontBitmap::RunTestCaseL(TInt aCurTestCase)
   1.118 +	{
   1.119 +	((CTFontBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   1.120 +	switch(aCurTestCase)
   1.121 +		{
   1.122 +	case 1:
   1.123 +		((CTFontBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0028"));
   1.124 +		Test();
   1.125 +		break;	
   1.126 +	case 2:
   1.127 +        	((CTFontBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.128 +		((CTFontBitmapStep*)iStep)->CloseTMSGraphicsStep();
   1.129 +		TestComplete();
   1.130 +		break;	
   1.131 +		}
   1.132 +	((CTFontBitmapStep*)iStep)->RecordTestResultL();
   1.133 +	}
   1.134 +	
   1.135 +void CTFontBitmap::ConnectFileSysL ()
   1.136 +	{
   1.137 +	User::LeaveIfError(iFilesys.Connect());
   1.138 +	}
   1.139 +
   1.140 +void CTFontBitmap::Test()
   1.141 +	{
   1.142 +	INFO_PRINTF1(_L("All bitmap fonts"));
   1.143 +
   1.144 +	iHeapNew->__DbgMarkStart();
   1.145 +	iHeapOld->__DbgMarkStart();
   1.146 +	TRAPD(err, TestAllL());
   1.147 +	TEST(err == KErrNone);
   1.148 +	iHeapNew->__DbgMarkCheck(ETrue, 0, TPtrC8((TText8*)__FILE__), __LINE__);
   1.149 +	iHeapNew->__DbgMarkEnd(0);
   1.150 +	iHeapOld->__DbgMarkCheck(ETrue, 0, TPtrC8((TText8*)__FILE__), __LINE__);
   1.151 +	iHeapOld->__DbgMarkEnd(0);
   1.152 +
   1.153 +	}
   1.154 +
   1.155 +/**
   1.156 +	@SYMTestCaseID
   1.157 +	GRAPHICS-FNTSTORE-0028
   1.158 +
   1.159 +	@SYMTestCaseDesc
   1.160 +	Tests all bitmap fonts. 
   1.161 +
   1.162 +	@SYMTestActions
   1.163 +	1. Creates a CFontStoreFile object from a file placed in ROM.
   1.164 +	2. Copies the file from the Z-drive to the C-drive.
   1.165 +	3. Tries to load the file from the C-drive to create a CFontStoreFile object.
   1.166 +	4. Opens two read streams. One for the old file and one for the new file.
   1.167 +	5. Retrieves the sizes of the files and checks they are the same.
   1.168 +	6. For both files it tries to create a font and allocates memory for them.
   1.169 +	7. Character metrics are compared between the two files.	
   1.170 +	
   1.171 +	@SYMTestExpectedResults
   1.172 +	Test should pass
   1.173 +*/
   1.174 +void CTFontBitmap::TestAllL()
   1.175 +	{
   1.176 +	TParse fileNameParse;
   1.177 +
   1.178 +	User::LeaveIfError(iFilesys.Parse(KEonFontFileName, fileNameParse));
   1.179 +	CFontStoreFile* fontstorefile_new = CFontStoreFile::NewL(fileNameParse, iFilesys);
   1.180 +	CleanupStack::PushL(fontstorefile_new);
   1.181 +	CFontStoreFile* fontstorefile_old = CFontStoreFile::NewL(fileNameParse, iFilesys);
   1.182 +	CleanupStack::PushL(fontstorefile_old);
   1.183 +
   1.184 +	// copy file from z: directory into c:
   1.185 +	TEST( BaflUtils::FileExists(iFilesys, KTSectionFontROM) );	// placed here on WINS by fonts_c.mk or fntstoretest.iby on lubbock
   1.186 +
   1.187 +	RSmlTestUtils testUtil;
   1.188 +	CleanupClosePushL(testUtil);
   1.189 +	testUtil.Connect();
   1.190 +	testUtil.CreateDirectoryL(KTSectionFontRAM);
   1.191 +	testUtil.CopyFileL(KTSectionFontROM, KTSectionFontRAM);
   1.192 +	CleanupStack::PopAndDestroy(&testUtil);
   1.193 +
   1.194 +	TEST( BaflUtils::FileExists(iFilesys, KTSectionFontRAM) );
   1.195 +
   1.196 +	// try to load the from from C: drive
   1.197 +	User::LeaveIfError(iFilesys.Parse(KTSectionFontRAM, fileNameParse));
   1.198 +	CFontStoreFile* fontstorefile_C = CFontStoreFile::NewL(fileNameParse, iFilesys);
   1.199 +	CleanupStack::PushL(fontstorefile_C);
   1.200 +	
   1.201 +	RStoreReadStream stream_new;
   1.202 +	stream_new.OpenLC(*fontstorefile_new->iFileStore, fontstorefile_new->iDataStreamId);
   1.203 +	RStoreReadStream stream_old;
   1.204 +	stream_old.OpenLC(*fontstorefile_old->iFileStore, fontstorefile_old->iDataStreamId);
   1.205 +	TInt i;
   1.206 +	TInt size_new = stream_new.ReadInt32L();
   1.207 +	TInt size_old = stream_old.ReadInt32L();
   1.208 +	TEST(size_new == size_old);
   1.209 +	INFO_PRINTF1(_L(""));
   1.210 +	for (i=0; i<size_new; i++)
   1.211 +		{
   1.212 +		CFontBitmap* font_new = CreateFontNewLC(fontstorefile_new, stream_new);
   1.213 +		CFontBitmapOld* font_old = CreateFontOldLC(fontstorefile_old, stream_old);
   1.214 +		INFO_PRINTF3(_L("Font UID=%X, NumCodeSections=%d\r\n"), font_new->iUid.iUid, font_new->iNumCodeSections);
   1.215 +		TInt alloc_size_new = 0;
   1.216 +		TInt cells_count_new = iHeapNew->AllocSize(alloc_size_new);
   1.217 +		TInt alloc_size_old = 0;
   1.218 +		TInt cells_count_old = iHeapOld->AllocSize(alloc_size_old);
   1.219 +		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);
   1.220 +		INFO_PRINTF2(_L("Profit=%d bytes\r\n"), alloc_size_old - alloc_size_new);
   1.221 +		for(TInt j=0;j<256;j++)
   1.222 +			{
   1.223 +            INFO_PRINTF2(_L("Char code %d"),j);
   1.224 +			const TUint8* bytes_new = NULL;
   1.225 +			const TUint8* bytes_old = NULL;
   1.226 +			TBitmapFontCharacterMetrics metrics_new;
   1.227 +			TBitmapFontCharacterMetrics metrics_old;
   1.228 +			metrics_new = font_new->CharacterMetrics(j, bytes_new);
   1.229 +			metrics_old = font_old->CharacterMetrics(j, bytes_old);
   1.230 +			TEST(bytes_new ? !!bytes_old : !bytes_old);
   1.231 +			TEST(metrics_new == metrics_old);
   1.232 +			if(bytes_new)
   1.233 +				{
   1.234 +				TInt byte_size_new = metrics_new.iMoveInPixels - metrics_new.iLeftAdjustInPixels - metrics_new.iRightAdjustInPixels;
   1.235 +				if(byte_size_new < 8)
   1.236 +					byte_size_new = 8;
   1.237 +				byte_size_new /= 8;
   1.238 +				byte_size_new *= metrics_new.iHeightInPixels;
   1.239 +				TInt byte_size_old = metrics_old.iMoveInPixels - metrics_old.iLeftAdjustInPixels - metrics_old.iRightAdjustInPixels;
   1.240 +				if(byte_size_old < 8)
   1.241 +					byte_size_old = 8;
   1.242 +				byte_size_old /= 8;
   1.243 +				byte_size_old *= metrics_old.iHeightInPixels;
   1.244 +				if(byte_size_new > 0)
   1.245 +					{
   1.246 +					TPtrC8 data_new(bytes_new, byte_size_new);
   1.247 +					TPtrC8 data_old(bytes_old, byte_size_old);
   1.248 +					TInt res = data_new.Compare(data_old);
   1.249 +					TEST(res == 0);
   1.250 +					}
   1.251 +				}
   1.252 +			}
   1.253 +		CleanupStack::PopAndDestroy(2);  //font_new & font_old
   1.254 +		}
   1.255 +	CleanupStack::PopAndDestroy(5);  //fontstorefile & stream - old & new + fontstorefile_C
   1.256 +	}
   1.257 +
   1.258 +const TInt KOldFontVer = 41;
   1.259 +
   1.260 +CFontBitmap* CTFontBitmap::CreateFontNewLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream)
   1.261 +	{
   1.262 +	CFontBitmap* fontbitmap = (CFontBitmap*)iHeapNew->AllocL(sizeof(CFontBitmap));
   1.263 +	new (fontbitmap) CFontBitmap(iHeapNew, aFontStoreFile);
   1.264 +	TRAPD(ret, fontbitmap->InternalizeL(aStream, KOldFontVer));
   1.265 +	if(ret != KErrNone)
   1.266 +		{
   1.267 +		fontbitmap->Release();
   1.268 +		User::Leave(ret);
   1.269 +		}
   1.270 +	CleanupStack::PushL(TCleanupItem(DestroyFontNew, fontbitmap));
   1.271 +	fontbitmap->UseL();
   1.272 +	return fontbitmap;
   1.273 +	}
   1.274 +
   1.275 +CFontBitmapOld* CTFontBitmap::CreateFontOldLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream)
   1.276 +	{
   1.277 +	CFontBitmapOld* fontbitmap = (CFontBitmapOld*)iHeapOld->AllocL(sizeof(CFontBitmapOld));
   1.278 +	new (fontbitmap) CFontBitmapOld(iHeapOld, aFontStoreFile);
   1.279 +	TRAPD(ret, fontbitmap->InternalizeL(aStream));
   1.280 +	if(ret != KErrNone)
   1.281 +		{
   1.282 +		fontbitmap->Release();
   1.283 +		User::Leave(ret);
   1.284 +		}
   1.285 +	CleanupStack::PushL(TCleanupItem(DestroyFontOld, fontbitmap));
   1.286 +	fontbitmap->UseL();
   1.287 +	return fontbitmap;
   1.288 +	}
   1.289 +
   1.290 +//--------------
   1.291 +__CONSTRUCT_STEP__(FontBitmap)
   1.292 +