os/textandloc/fontservices/fontstore/tfs/T_FontBitmap.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @test
    22  @internalComponent - Internal Symbian test code 
    23 */
    24 
    25 #include <s32file.h>
    26 #include <gdi.h>
    27 #include <bautils.h>
    28 
    29 #include "GraphicsTestUtils.h"
    30 #include "FNTBODY_OLD.H"
    31 #include "T_FontBitmap.H"
    32 
    33 
    34 #ifdef __WINS__
    35 _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
    36 #else
    37 _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon.gdr");
    38 #endif
    39 
    40 _LIT(KTSectionFontRAM,"c:\\resource\\fonts\\TSection.gdr");
    41 _LIT(KTSectionFontROM,"z:\\test\\TSection.gdr");
    42 
    43 
    44 class CTFontBitmap : public CTGraphicsBase
    45 	{
    46 public:
    47 	CTFontBitmap(CTestStep* aStep);
    48 	~CTFontBitmap();
    49 
    50 protected:
    51 //from 	CTGraphicsStep
    52 	virtual void RunTestCaseL(TInt aCurTestCase);
    53 	virtual void ConstructL();
    54 
    55 	void ConnectFileSysL ();
    56 	void Test();
    57 private:
    58 	void TestAllL();
    59 
    60 	CFontBitmap* CreateFontNewLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream);
    61 	CFontBitmapOld* CreateFontOldLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream);
    62 
    63 private:
    64 	RHeap* iHeapNew;
    65 	RHeap* iHeapOld;
    66 	RFs iFilesys;
    67 	};
    68 
    69 LOCAL_C void DestroyFontNew(TAny* aPtr)
    70 	{
    71 	CFontBitmap* font = reinterpret_cast <CFontBitmap*> (aPtr);
    72 	font->Release();
    73 	font->Release();
    74 	}
    75 
    76 LOCAL_C void DestroyFontOld(TAny* aPtr)
    77 	{
    78 	CFontBitmapOld* font = reinterpret_cast <CFontBitmapOld*> (aPtr);
    79 	font->Release();
    80 	font->Release();
    81 	}
    82 
    83 TBool operator==(const TBitmapFontCharacterMetrics& l, const TBitmapFontCharacterMetrics& r)
    84 	{
    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);
    90 	}
    91 
    92 CTFontBitmap::CTFontBitmap(CTestStep* aStep):
    93 	CTGraphicsBase(aStep),
    94 	iHeapNew(NULL),
    95 	iHeapOld(NULL)
    96 	{
    97 	}
    98 
    99 CTFontBitmap::~CTFontBitmap()
   100 	{
   101 	iFilesys.Close();
   102 	iHeapOld->Close();
   103 	iHeapNew->Close();
   104 	}
   105 
   106 void CTFontBitmap::ConstructL()
   107 	{
   108 	iHeapNew = UserHeap::ChunkHeap(NULL,0x80000, 0x80000);
   109 	iHeapOld = UserHeap::ChunkHeap(NULL,0x80000, 0x80000);
   110 
   111 	ConnectFileSysL();
   112 	}
   113 
   114 void CTFontBitmap::RunTestCaseL(TInt aCurTestCase)
   115 	{
   116 	((CTFontBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   117 	switch(aCurTestCase)
   118 		{
   119 	case 1:
   120 		((CTFontBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0028"));
   121 		Test();
   122 		break;	
   123 	case 2:
   124         	((CTFontBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   125 		((CTFontBitmapStep*)iStep)->CloseTMSGraphicsStep();
   126 		TestComplete();
   127 		break;	
   128 		}
   129 	((CTFontBitmapStep*)iStep)->RecordTestResultL();
   130 	}
   131 	
   132 void CTFontBitmap::ConnectFileSysL ()
   133 	{
   134 	User::LeaveIfError(iFilesys.Connect());
   135 	}
   136 
   137 void CTFontBitmap::Test()
   138 	{
   139 	INFO_PRINTF1(_L("All bitmap fonts"));
   140 
   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);
   149 
   150 	}
   151 
   152 /**
   153 	@SYMTestCaseID
   154 	GRAPHICS-FNTSTORE-0028
   155 
   156 	@SYMTestCaseDesc
   157 	Tests all bitmap fonts. 
   158 
   159 	@SYMTestActions
   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.	
   167 	
   168 	@SYMTestExpectedResults
   169 	Test should pass
   170 */
   171 void CTFontBitmap::TestAllL()
   172 	{
   173 	TParse fileNameParse;
   174 
   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);
   180 
   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
   183 
   184 	RSmlTestUtils testUtil;
   185 	CleanupClosePushL(testUtil);
   186 	testUtil.Connect();
   187 	testUtil.CreateDirectoryL(KTSectionFontRAM);
   188 	testUtil.CopyFileL(KTSectionFontROM, KTSectionFontRAM);
   189 	CleanupStack::PopAndDestroy(&testUtil);
   190 
   191 	TEST( BaflUtils::FileExists(iFilesys, KTSectionFontRAM) );
   192 
   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);
   197 	
   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);
   202 	TInt i;
   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++)
   208 		{
   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++)
   219 			{
   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);
   229 			if(bytes_new)
   230 				{
   231 				TInt byte_size_new = metrics_new.iMoveInPixels - metrics_new.iLeftAdjustInPixels - metrics_new.iRightAdjustInPixels;
   232 				if(byte_size_new < 8)
   233 					byte_size_new = 8;
   234 				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)
   238 					byte_size_old = 8;
   239 				byte_size_old /= 8;
   240 				byte_size_old *= metrics_old.iHeightInPixels;
   241 				if(byte_size_new > 0)
   242 					{
   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);
   246 					TEST(res == 0);
   247 					}
   248 				}
   249 			}
   250 		CleanupStack::PopAndDestroy(2);  //font_new & font_old
   251 		}
   252 	CleanupStack::PopAndDestroy(5);  //fontstorefile & stream - old & new + fontstorefile_C
   253 	}
   254 
   255 const TInt KOldFontVer = 41;
   256 
   257 CFontBitmap* CTFontBitmap::CreateFontNewLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream)
   258 	{
   259 	CFontBitmap* fontbitmap = (CFontBitmap*)iHeapNew->AllocL(sizeof(CFontBitmap));
   260 	new (fontbitmap) CFontBitmap(iHeapNew, aFontStoreFile);
   261 	TRAPD(ret, fontbitmap->InternalizeL(aStream, KOldFontVer));
   262 	if(ret != KErrNone)
   263 		{
   264 		fontbitmap->Release();
   265 		User::Leave(ret);
   266 		}
   267 	CleanupStack::PushL(TCleanupItem(DestroyFontNew, fontbitmap));
   268 	fontbitmap->UseL();
   269 	return fontbitmap;
   270 	}
   271 
   272 CFontBitmapOld* CTFontBitmap::CreateFontOldLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream)
   273 	{
   274 	CFontBitmapOld* fontbitmap = (CFontBitmapOld*)iHeapOld->AllocL(sizeof(CFontBitmapOld));
   275 	new (fontbitmap) CFontBitmapOld(iHeapOld, aFontStoreFile);
   276 	TRAPD(ret, fontbitmap->InternalizeL(aStream));
   277 	if(ret != KErrNone)
   278 		{
   279 		fontbitmap->Release();
   280 		User::Leave(ret);
   281 		}
   282 	CleanupStack::PushL(TCleanupItem(DestroyFontOld, fontbitmap));
   283 	fontbitmap->UseL();
   284 	return fontbitmap;
   285 	}
   286 
   287 //--------------
   288 __CONSTRUCT_STEP__(FontBitmap)
   289