os/textandloc/fontservices/fontstore/tfs/T_FontBitmap.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @test
sl@0
    22
 @internalComponent - Internal Symbian test code 
sl@0
    23
*/
sl@0
    24
sl@0
    25
#include <s32file.h>
sl@0
    26
#include <gdi.h>
sl@0
    27
#include <bautils.h>
sl@0
    28
sl@0
    29
#include "GraphicsTestUtils.h"
sl@0
    30
#include "FNTBODY_OLD.H"
sl@0
    31
#include "T_FontBitmap.H"
sl@0
    32
sl@0
    33
sl@0
    34
#ifdef __WINS__
sl@0
    35
_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
sl@0
    36
#else
sl@0
    37
_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon.gdr");
sl@0
    38
#endif
sl@0
    39
sl@0
    40
_LIT(KTSectionFontRAM,"c:\\resource\\fonts\\TSection.gdr");
sl@0
    41
_LIT(KTSectionFontROM,"z:\\test\\TSection.gdr");
sl@0
    42
sl@0
    43
sl@0
    44
class CTFontBitmap : public CTGraphicsBase
sl@0
    45
	{
sl@0
    46
public:
sl@0
    47
	CTFontBitmap(CTestStep* aStep);
sl@0
    48
	~CTFontBitmap();
sl@0
    49
sl@0
    50
protected:
sl@0
    51
//from 	CTGraphicsStep
sl@0
    52
	virtual void RunTestCaseL(TInt aCurTestCase);
sl@0
    53
	virtual void ConstructL();
sl@0
    54
sl@0
    55
	void ConnectFileSysL ();
sl@0
    56
	void Test();
sl@0
    57
private:
sl@0
    58
	void TestAllL();
sl@0
    59
sl@0
    60
	CFontBitmap* CreateFontNewLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream);
sl@0
    61
	CFontBitmapOld* CreateFontOldLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream);
sl@0
    62
sl@0
    63
private:
sl@0
    64
	RHeap* iHeapNew;
sl@0
    65
	RHeap* iHeapOld;
sl@0
    66
	RFs iFilesys;
sl@0
    67
	};
sl@0
    68
sl@0
    69
LOCAL_C void DestroyFontNew(TAny* aPtr)
sl@0
    70
	{
sl@0
    71
	CFontBitmap* font = reinterpret_cast <CFontBitmap*> (aPtr);
sl@0
    72
	font->Release();
sl@0
    73
	font->Release();
sl@0
    74
	}
sl@0
    75
sl@0
    76
LOCAL_C void DestroyFontOld(TAny* aPtr)
sl@0
    77
	{
sl@0
    78
	CFontBitmapOld* font = reinterpret_cast <CFontBitmapOld*> (aPtr);
sl@0
    79
	font->Release();
sl@0
    80
	font->Release();
sl@0
    81
	}
sl@0
    82
sl@0
    83
TBool operator==(const TBitmapFontCharacterMetrics& l, const TBitmapFontCharacterMetrics& r)
sl@0
    84
	{
sl@0
    85
	return (l.iAscentInPixels == r.iAscentInPixels &&
sl@0
    86
			l.iHeightInPixels == r.iHeightInPixels &&
sl@0
    87
			l.iLeftAdjustInPixels == r.iLeftAdjustInPixels &&
sl@0
    88
			l.iMoveInPixels == r.iMoveInPixels &&
sl@0
    89
			l.iRightAdjustInPixels == r.iRightAdjustInPixels);
sl@0
    90
	}
sl@0
    91
sl@0
    92
CTFontBitmap::CTFontBitmap(CTestStep* aStep):
sl@0
    93
	CTGraphicsBase(aStep),
sl@0
    94
	iHeapNew(NULL),
sl@0
    95
	iHeapOld(NULL)
sl@0
    96
	{
sl@0
    97
	}
sl@0
    98
sl@0
    99
CTFontBitmap::~CTFontBitmap()
sl@0
   100
	{
sl@0
   101
	iFilesys.Close();
sl@0
   102
	iHeapOld->Close();
sl@0
   103
	iHeapNew->Close();
sl@0
   104
	}
sl@0
   105
sl@0
   106
void CTFontBitmap::ConstructL()
sl@0
   107
	{
sl@0
   108
	iHeapNew = UserHeap::ChunkHeap(NULL,0x80000, 0x80000);
sl@0
   109
	iHeapOld = UserHeap::ChunkHeap(NULL,0x80000, 0x80000);
sl@0
   110
sl@0
   111
	ConnectFileSysL();
sl@0
   112
	}
sl@0
   113
sl@0
   114
void CTFontBitmap::RunTestCaseL(TInt aCurTestCase)
sl@0
   115
	{
sl@0
   116
	((CTFontBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
   117
	switch(aCurTestCase)
sl@0
   118
		{
sl@0
   119
	case 1:
sl@0
   120
		((CTFontBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0028"));
sl@0
   121
		Test();
sl@0
   122
		break;	
sl@0
   123
	case 2:
sl@0
   124
        	((CTFontBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   125
		((CTFontBitmapStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   126
		TestComplete();
sl@0
   127
		break;	
sl@0
   128
		}
sl@0
   129
	((CTFontBitmapStep*)iStep)->RecordTestResultL();
sl@0
   130
	}
sl@0
   131
	
sl@0
   132
void CTFontBitmap::ConnectFileSysL ()
sl@0
   133
	{
sl@0
   134
	User::LeaveIfError(iFilesys.Connect());
sl@0
   135
	}
sl@0
   136
sl@0
   137
void CTFontBitmap::Test()
sl@0
   138
	{
sl@0
   139
	INFO_PRINTF1(_L("All bitmap fonts"));
sl@0
   140
sl@0
   141
	iHeapNew->__DbgMarkStart();
sl@0
   142
	iHeapOld->__DbgMarkStart();
sl@0
   143
	TRAPD(err, TestAllL());
sl@0
   144
	TEST(err == KErrNone);
sl@0
   145
	iHeapNew->__DbgMarkCheck(ETrue, 0, TPtrC8((TText8*)__FILE__), __LINE__);
sl@0
   146
	iHeapNew->__DbgMarkEnd(0);
sl@0
   147
	iHeapOld->__DbgMarkCheck(ETrue, 0, TPtrC8((TText8*)__FILE__), __LINE__);
sl@0
   148
	iHeapOld->__DbgMarkEnd(0);
sl@0
   149
sl@0
   150
	}
sl@0
   151
sl@0
   152
/**
sl@0
   153
	@SYMTestCaseID
sl@0
   154
	GRAPHICS-FNTSTORE-0028
sl@0
   155
sl@0
   156
	@SYMTestCaseDesc
sl@0
   157
	Tests all bitmap fonts. 
sl@0
   158
sl@0
   159
	@SYMTestActions
sl@0
   160
	1. Creates a CFontStoreFile object from a file placed in ROM.
sl@0
   161
	2. Copies the file from the Z-drive to the C-drive.
sl@0
   162
	3. Tries to load the file from the C-drive to create a CFontStoreFile object.
sl@0
   163
	4. Opens two read streams. One for the old file and one for the new file.
sl@0
   164
	5. Retrieves the sizes of the files and checks they are the same.
sl@0
   165
	6. For both files it tries to create a font and allocates memory for them.
sl@0
   166
	7. Character metrics are compared between the two files.	
sl@0
   167
	
sl@0
   168
	@SYMTestExpectedResults
sl@0
   169
	Test should pass
sl@0
   170
*/
sl@0
   171
void CTFontBitmap::TestAllL()
sl@0
   172
	{
sl@0
   173
	TParse fileNameParse;
sl@0
   174
sl@0
   175
	User::LeaveIfError(iFilesys.Parse(KEonFontFileName, fileNameParse));
sl@0
   176
	CFontStoreFile* fontstorefile_new = CFontStoreFile::NewL(fileNameParse, iFilesys);
sl@0
   177
	CleanupStack::PushL(fontstorefile_new);
sl@0
   178
	CFontStoreFile* fontstorefile_old = CFontStoreFile::NewL(fileNameParse, iFilesys);
sl@0
   179
	CleanupStack::PushL(fontstorefile_old);
sl@0
   180
sl@0
   181
	// copy file from z: directory into c:
sl@0
   182
	TEST( BaflUtils::FileExists(iFilesys, KTSectionFontROM) );	// placed here on WINS by fonts_c.mk or fntstoretest.iby on lubbock
sl@0
   183
sl@0
   184
	RSmlTestUtils testUtil;
sl@0
   185
	CleanupClosePushL(testUtil);
sl@0
   186
	testUtil.Connect();
sl@0
   187
	testUtil.CreateDirectoryL(KTSectionFontRAM);
sl@0
   188
	testUtil.CopyFileL(KTSectionFontROM, KTSectionFontRAM);
sl@0
   189
	CleanupStack::PopAndDestroy(&testUtil);
sl@0
   190
sl@0
   191
	TEST( BaflUtils::FileExists(iFilesys, KTSectionFontRAM) );
sl@0
   192
sl@0
   193
	// try to load the from from C: drive
sl@0
   194
	User::LeaveIfError(iFilesys.Parse(KTSectionFontRAM, fileNameParse));
sl@0
   195
	CFontStoreFile* fontstorefile_C = CFontStoreFile::NewL(fileNameParse, iFilesys);
sl@0
   196
	CleanupStack::PushL(fontstorefile_C);
sl@0
   197
	
sl@0
   198
	RStoreReadStream stream_new;
sl@0
   199
	stream_new.OpenLC(*fontstorefile_new->iFileStore, fontstorefile_new->iDataStreamId);
sl@0
   200
	RStoreReadStream stream_old;
sl@0
   201
	stream_old.OpenLC(*fontstorefile_old->iFileStore, fontstorefile_old->iDataStreamId);
sl@0
   202
	TInt i;
sl@0
   203
	TInt size_new = stream_new.ReadInt32L();
sl@0
   204
	TInt size_old = stream_old.ReadInt32L();
sl@0
   205
	TEST(size_new == size_old);
sl@0
   206
	INFO_PRINTF1(_L(""));
sl@0
   207
	for (i=0; i<size_new; i++)
sl@0
   208
		{
sl@0
   209
		CFontBitmap* font_new = CreateFontNewLC(fontstorefile_new, stream_new);
sl@0
   210
		CFontBitmapOld* font_old = CreateFontOldLC(fontstorefile_old, stream_old);
sl@0
   211
		INFO_PRINTF3(_L("Font UID=%X, NumCodeSections=%d\r\n"), font_new->iUid.iUid, font_new->iNumCodeSections);
sl@0
   212
		TInt alloc_size_new = 0;
sl@0
   213
		TInt cells_count_new = iHeapNew->AllocSize(alloc_size_new);
sl@0
   214
		TInt alloc_size_old = 0;
sl@0
   215
		TInt cells_count_old = iHeapOld->AllocSize(alloc_size_old);
sl@0
   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);
sl@0
   217
		INFO_PRINTF2(_L("Profit=%d bytes\r\n"), alloc_size_old - alloc_size_new);
sl@0
   218
		for(TInt j=0;j<256;j++)
sl@0
   219
			{
sl@0
   220
            INFO_PRINTF2(_L("Char code %d"),j);
sl@0
   221
			const TUint8* bytes_new = NULL;
sl@0
   222
			const TUint8* bytes_old = NULL;
sl@0
   223
			TBitmapFontCharacterMetrics metrics_new;
sl@0
   224
			TBitmapFontCharacterMetrics metrics_old;
sl@0
   225
			metrics_new = font_new->CharacterMetrics(j, bytes_new);
sl@0
   226
			metrics_old = font_old->CharacterMetrics(j, bytes_old);
sl@0
   227
			TEST(bytes_new ? !!bytes_old : !bytes_old);
sl@0
   228
			TEST(metrics_new == metrics_old);
sl@0
   229
			if(bytes_new)
sl@0
   230
				{
sl@0
   231
				TInt byte_size_new = metrics_new.iMoveInPixels - metrics_new.iLeftAdjustInPixels - metrics_new.iRightAdjustInPixels;
sl@0
   232
				if(byte_size_new < 8)
sl@0
   233
					byte_size_new = 8;
sl@0
   234
				byte_size_new /= 8;
sl@0
   235
				byte_size_new *= metrics_new.iHeightInPixels;
sl@0
   236
				TInt byte_size_old = metrics_old.iMoveInPixels - metrics_old.iLeftAdjustInPixels - metrics_old.iRightAdjustInPixels;
sl@0
   237
				if(byte_size_old < 8)
sl@0
   238
					byte_size_old = 8;
sl@0
   239
				byte_size_old /= 8;
sl@0
   240
				byte_size_old *= metrics_old.iHeightInPixels;
sl@0
   241
				if(byte_size_new > 0)
sl@0
   242
					{
sl@0
   243
					TPtrC8 data_new(bytes_new, byte_size_new);
sl@0
   244
					TPtrC8 data_old(bytes_old, byte_size_old);
sl@0
   245
					TInt res = data_new.Compare(data_old);
sl@0
   246
					TEST(res == 0);
sl@0
   247
					}
sl@0
   248
				}
sl@0
   249
			}
sl@0
   250
		CleanupStack::PopAndDestroy(2);  //font_new & font_old
sl@0
   251
		}
sl@0
   252
	CleanupStack::PopAndDestroy(5);  //fontstorefile & stream - old & new + fontstorefile_C
sl@0
   253
	}
sl@0
   254
sl@0
   255
const TInt KOldFontVer = 41;
sl@0
   256
sl@0
   257
CFontBitmap* CTFontBitmap::CreateFontNewLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream)
sl@0
   258
	{
sl@0
   259
	CFontBitmap* fontbitmap = (CFontBitmap*)iHeapNew->AllocL(sizeof(CFontBitmap));
sl@0
   260
	new (fontbitmap) CFontBitmap(iHeapNew, aFontStoreFile);
sl@0
   261
	TRAPD(ret, fontbitmap->InternalizeL(aStream, KOldFontVer));
sl@0
   262
	if(ret != KErrNone)
sl@0
   263
		{
sl@0
   264
		fontbitmap->Release();
sl@0
   265
		User::Leave(ret);
sl@0
   266
		}
sl@0
   267
	CleanupStack::PushL(TCleanupItem(DestroyFontNew, fontbitmap));
sl@0
   268
	fontbitmap->UseL();
sl@0
   269
	return fontbitmap;
sl@0
   270
	}
sl@0
   271
sl@0
   272
CFontBitmapOld* CTFontBitmap::CreateFontOldLC(CFontStoreFile* aFontStoreFile, RReadStream &aStream)
sl@0
   273
	{
sl@0
   274
	CFontBitmapOld* fontbitmap = (CFontBitmapOld*)iHeapOld->AllocL(sizeof(CFontBitmapOld));
sl@0
   275
	new (fontbitmap) CFontBitmapOld(iHeapOld, aFontStoreFile);
sl@0
   276
	TRAPD(ret, fontbitmap->InternalizeL(aStream));
sl@0
   277
	if(ret != KErrNone)
sl@0
   278
		{
sl@0
   279
		fontbitmap->Release();
sl@0
   280
		User::Leave(ret);
sl@0
   281
		}
sl@0
   282
	CleanupStack::PushL(TCleanupItem(DestroyFontOld, fontbitmap));
sl@0
   283
	fontbitmap->UseL();
sl@0
   284
	return fontbitmap;
sl@0
   285
	}
sl@0
   286
sl@0
   287
//--------------
sl@0
   288
__CONSTRUCT_STEP__(FontBitmap)
sl@0
   289