sl@0: /* sl@0: * Copyright (c) 1995-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: #include "T_FNTMEM.H" sl@0: #include "T_FSOPEN.H" sl@0: #include 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: // 'dummy' open fonts, as used by T_FSOPEN sl@0: _LIT(KFontDummy,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy"); sl@0: //_LIT(KFontDummy_b,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_b"); sl@0: //_LIT(KFontDummy_i,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_i"); sl@0: //_LIT(KFontDummy_bi,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_bi"); sl@0: sl@0: sl@0: sl@0: CTFntMem::CTFntMem(CTestStep* aStep): sl@0: CTGraphicsBase(aStep), sl@0: iHeap(NULL) sl@0: { sl@0: iHeap = UserHeap::ChunkHeap(NULL,0x80000,0x80000); sl@0: INFO_PRINTF1(_L("FontStore")); sl@0: } sl@0: sl@0: void CTFntMem::RunTestCaseL(TInt aCurTestCase) sl@0: { sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); sl@0: switch(aCurTestCase) sl@0: { sl@0: case 1: sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0024")); sl@0: TRAPD(err,TestNewL()); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 2: // OOM handling for bitmap fonts sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0025")); sl@0: TRAP(err,TestAddFileL(KEonFontFileName)); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 3: // OOM handling for open fonts sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0025")); sl@0: TRAP(err,TestAddFileL(KFontDummy)); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 5: // OOM handling for second reference to a bitmap font sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0026")); sl@0: TRAP(err,TestAddFileTwiceL(KEonFontFileName)); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 6: // OOM handling for second reference to an open font sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0026")); sl@0: TRAP(err,TestAddFileTwiceL(KFontDummy)); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 7: sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0027")); sl@0: TRAP(err,TestGetNearestFontToDesignHeightInTwipsL()); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 8: sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-NearestOpenFontLeaksDEF095184-0001")); sl@0: TRAP(err,TestGetNearestOpenFontLeaksL()); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 9: sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-CTFbs-TestDuplicateFontFileEntries-0002")); sl@0: TRAP(err,TestDuplicateBitmapFontFileEntriesL()); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 10: sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: ((CTFntMemStep*)iStep)->CloseTMSGraphicsStep(); sl@0: TestComplete(); sl@0: break; sl@0: default: sl@0: ((CTFntMemStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: break; sl@0: } sl@0: ((CTFntMemStep*)iStep)->RecordTestResultL(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FNTSTORE-0024 sl@0: sl@0: @SYMTestCaseDesc sl@0: Simulates out of memory errors of the heap when trying to allocate sl@0: memory for a CFontStore object. sl@0: sl@0: @SYMTestActions sl@0: 1. Cancels simulated heap allocation failure for the current thread's heap. sl@0: 2. Simulates heap allocation failure for the current thread's heap. sl@0: 3. Marks the start of checking the current thread's heap. sl@0: 4. In a loop, tries to create a new CFontStore object with a pointer to sl@0: the heap class used for memory allocation. sl@0: 5. Checking is done to see if the CFontStore was allocated or sl@0: if out of memory. The loop is broken when an object is created correctly. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTFntMem::TestNewL() sl@0: { sl@0: INFO_PRINTF1(_L("NewL")); sl@0: sl@0: TInt ret=KErrGeneral; sl@0: CFontStore *fs=NULL; sl@0: TInt failRate=1; sl@0: sl@0: while (ret!=KErrNone) sl@0: { sl@0: __UHEAP_RESET; sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,failRate); sl@0: __UHEAP_MARK; sl@0: TRAP(ret,fs=CFontStore::NewL(iHeap)); sl@0: RDebug::Print(_L("fs %d failrate %d, error %d\n"),fs,failRate, ret); sl@0: if (ret==KErrNoMemory) sl@0: { sl@0: __UHEAP_MARKEND; sl@0: __UHEAP_RESET; sl@0: TEST(fs==NULL); sl@0: } sl@0: else if(ret==KErrNone) sl@0: { sl@0: delete fs; sl@0: __UHEAP_MARKEND; sl@0: __UHEAP_RESET; sl@0: __UHEAP_SETFAIL(RHeap::ENone,failRate); sl@0: } sl@0: else sl@0: User::Panic(_L("Unknown error"),ret); sl@0: failRate++; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FNTSTORE-0025 sl@0: sl@0: @SYMTestCaseDesc sl@0: Tests the Out Of Memory handling for bitmap- and open fonts. sl@0: sl@0: @SYMTestActions sl@0: 1. Finds or creates a font file object to support a font file. sl@0: If an appropriate font file object exists then no new open font file is created. sl@0: In this case the reference count of the font file object is incremented. sl@0: 2. Allocates the object from the heap and then initialises its contents sl@0: to binary zeroes. sl@0: 3. Installs and takes ownership of an Open Font rasterizer sl@0: 4. Releases a hold on one or all font file objects (COpenFontFiles or CFontStoreFiles) sl@0: If aFileUid identifies a font file object, then the reference count for this sl@0: object is decremented. If this brings the reference count down to zero then sl@0: the font file object is removed from the font store, as well as the fonts sl@0: and typefaces associated with this file. sl@0: If, on the other hand, aFileUid's value is NULL, then all font file objects sl@0: are removed, along with all fonts and typefaces in the font store. sl@0: 5. Simulates heap allocation failure for the current thread's heap. sl@0: 6. Tries to add a font file to the font store and checks for memory allocation errors. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTFntMem::TestAddFileL(const TDesC& aFileName) sl@0: { sl@0: INFO_PRINTF2(_L("AddFileL(\"%S\")"), &aFileName); sl@0: TInt failRate=1; sl@0: CFontStore *fs=CFontStore::NewL(iHeap); sl@0: sl@0: // Install the dummy rasterizer - used for 'Open Font's sl@0: COpenFontRasterizer* r = CDummyRasterizer::NewL(); sl@0: CleanupStack::PushL(r); sl@0: fs->InstallRasterizerL(r); sl@0: CleanupStack::Pop(); sl@0: sl@0: (void)fs->AddFileL(aFileName); sl@0: fs->RemoveFile(KNullUid); sl@0: TInt ret=KErrGeneral; sl@0: sl@0: while (ret!=KErrNone) sl@0: { sl@0: __UHEAP_RESET; sl@0: __UHEAP_MARK; sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,failRate); sl@0: TRAP(ret, (void)fs->AddFileL(aFileName)); sl@0: RDebug::Print(_L("NumTypefaces %d failrate %d, error %d\n"),fs->NumTypefaces(), failRate, ret); sl@0: if (ret==KErrNoMemory) sl@0: { sl@0: fs->RemoveFile(KNullUid); sl@0: __UHEAP_MARKEND; sl@0: __UHEAP_RESET; sl@0: TEST(fs->NumTypefaces()==0); sl@0: } sl@0: else if(ret==KErrNone) sl@0: { sl@0: fs->RemoveFile(KNullUid); sl@0: delete fs; sl@0: __UHEAP_MARKEND; sl@0: __UHEAP_RESET; sl@0: __UHEAP_SETFAIL(RHeap::ENone,failRate); sl@0: } sl@0: else sl@0: User::Panic(_L("Unknown error"),ret); sl@0: failRate++; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FNTSTORE-0026 sl@0: sl@0: @SYMTestCaseDesc sl@0: Tests the Out Of Memory handling for second reference to a bitmap font and open fonts. sl@0: sl@0: @SYMTestActions sl@0: 1. Finds or creates a font file object to support a font file. sl@0: If an appropriate font file object exists then no new open font file is created. sl@0: In this case the reference count of the font file object is incremented. sl@0: 2. Allocates the object from the heap and then initialises its contents. sl@0: to binary zeroes. sl@0: 3. Installs and takes ownership of an Open Font rasterizer. sl@0: 4. Loads a font file. sl@0: 5. Simulates heap allocation failure for the current thread's heap. sl@0: 6. Tries to add a font file a second time to the font store and checks for memory allocation errors. sl@0: 7. Removes all font file objects. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTFntMem::TestAddFileTwiceL(const TDesC& aFileName) sl@0: { sl@0: INFO_PRINTF2(_L("AddFileTwiceL(\"%S\")"), &aFileName); sl@0: TInt failRate=1; sl@0: CFontStore *fs=CFontStore::NewL(iHeap); sl@0: sl@0: // Install the dummy rasterizer - used for 'Open Font's sl@0: COpenFontRasterizer* r = CDummyRasterizer::NewL(); sl@0: CleanupStack::PushL(r); sl@0: fs->InstallRasterizerL(r); sl@0: CleanupStack::Pop(); sl@0: sl@0: // load the font file sl@0: (void)fs->AddFileL(aFileName); sl@0: TInt ret=KErrGeneral; sl@0: sl@0: while (ret!=KErrNone) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,failRate); sl@0: __UHEAP_MARK; sl@0: TRAP(ret, (void)fs->AddFileL(aFileName)); sl@0: RDebug::Print(_L("NumTypefaces %d failrate %d, error %d\n"),fs->NumTypefaces(), failRate, ret); sl@0: sl@0: // neither success or failure should use more memory sl@0: __UHEAP_MARKEND; sl@0: __UHEAP_RESET; sl@0: sl@0: if ( (ret != KErrNoMemory) && (ret != KErrNone) ) sl@0: { sl@0: User::Panic(_L("Unknown error"),ret); sl@0: } sl@0: failRate++; sl@0: } sl@0: sl@0: fs->RemoveFile(KNullUid); sl@0: delete fs; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FNTSTORE-0027 sl@0: sl@0: @SYMTestCaseDesc sl@0: Tests the function GetNearestFontToDesignHeightInTwips in Out Of Memory sl@0: error conditions. sl@0: sl@0: @SYMTestActions sl@0: 1. Creates a new CFontStore object. sl@0: 2. Adds a font file to the font store. sl@0: 3. Creates a bitmap font object. sl@0: 4. Gets the nearest font to design height in twips of the DejaVu Sans Condensed font. sl@0: 5. Releases a hold on one or all font file objects (COpenFontFiles or CFontStoreFiles) sl@0: If aFileUid identifies a font file object, then the reference count for this sl@0: object is decremented. If this brings the reference count down to zero then sl@0: the font file object is removed from the font store, as well as the fonts sl@0: and typefaces associated with this file. sl@0: If, on the other hand, aFileUid's value is NULL, then all font file objects sl@0: are removed, along with all fonts and typefaces in the font store. sl@0: 6. Simulates heap allocation failure for the current thread's heap. sl@0: 7. Tries to get the nearest font to design height in twips for the font and sl@0: checks for memory allocation errors. sl@0: 8. Deallocates the CFontStore object. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTFntMem::TestGetNearestFontToDesignHeightInTwipsL() sl@0: { sl@0: INFO_PRINTF1(_L("GetNearestFontToDesignHeightInTwips")); sl@0: CFontStore *fs=CFontStore::NewL(iHeap); sl@0: (void)fs->AddFileL(KEonFontFileName); sl@0: TInt failRate=1; sl@0: CBitmapFont *font; sl@0: TFontSpec spec(_L("DejaVu Sans Condensed"),200); sl@0: TInt ret; sl@0: ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec); sl@0: TEST(ret==KErrNone); sl@0: if (ret!=KErrNone || font==NULL) sl@0: return; //otherwise the memory faulting test loop will deadlock! sl@0: fs->ReleaseFont(font); sl@0: ret=KErrNoMemory; sl@0: while(ret!=KErrNone) sl@0: { sl@0: __UHEAP_RESET; sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,failRate); sl@0: __UHEAP_MARK; sl@0: __RHEAP_MARK(iHeap); sl@0: font=NULL; sl@0: ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec); sl@0: RDebug::Print(_L("Font %d failrate %d\n"),font,failRate); sl@0: if (ret==KErrNoMemory) sl@0: { sl@0: TEST(font==NULL); sl@0: __RHEAP_MARKEND(iHeap); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: else if(ret==KErrNone) sl@0: { sl@0: fs->ReleaseFont(font); sl@0: font=NULL; sl@0: __RHEAP_MARKEND(iHeap); sl@0: __UHEAP_MARKEND; sl@0: __UHEAP_SETFAIL(RHeap::ENone,failRate); sl@0: } sl@0: else sl@0: User::Panic(_L("Unknown error"),ret); sl@0: failRate++; sl@0: } sl@0: sl@0: delete fs; sl@0: } sl@0: //---------------- sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-NearestOpenFontLeaksDEF095184-0001 sl@0: @SYMTestPriority Med sl@0: @SYMREQ DEF095184 sl@0: sl@0: @SYMTestCaseDesc sl@0: Leak in font finder sl@0: sl@0: @SYMTestActions sl@0: Tests for leak case loading both nearest open and bitmap font. sl@0: The first call to GetNearestFontToDesignHeightInTwips loads the bitmap font. sl@0: The looped calls change the memory fault frequency until this succeeds, sl@0: but the open font is returned instead, and then until the bitmap font is again returned. sl@0: The test fontspec is specially chosen to cause these different results, sl@0: and the test code is not working if the differing results are not fetched. sl@0: sl@0: @SYMTestExpectedResults sl@0: failrate 1: KErrNoMemory sl@0: failrate 2: Same font returned sl@0: failrate 3: Different font returned sl@0: failrate 4: Same font returned sl@0: No leaks. sl@0: Note that the exact results may change fail rates sl@0: if underlying changes are made to the font store. sl@0: sl@0: **/ sl@0: void CTFntMem::TestGetNearestOpenFontLeaksL() sl@0: { sl@0: INFO_PRINTF1(_L("TestGetNearestOpenFontLeaksL")); sl@0: CFontStore *fs=CFontStore::NewL(iHeap); sl@0: CleanupStack::PushL(fs); sl@0: // Install the dummy rasterizer - used for 'Open Font's sl@0: COpenFontRasterizer* r = CDummyRasterizer::NewL(); sl@0: CleanupStack::PushL(r); sl@0: fs->InstallRasterizerL(r); sl@0: //Need one of each font flavour sl@0: (void)fs->AddFileL(KFontDummy); sl@0: (void)fs->AddFileL(KEonFontFileName); sl@0: CleanupStack::Pop(r); sl@0: CleanupStack::Pop(fs); sl@0: bool differentResultFetched=false; sl@0: CBitmapFont *firstFont; sl@0: sl@0: //Manufacture this font so that the bitmap font is favoured sl@0: //Note that the best I could do was get them equal, but that is enough to get bitmap chosen! sl@0: //Blank name is required to allow the dummy open font to be selected by similarity sl@0: TFontSpec reqSpec(_L(""),190); sl@0: reqSpec.iFontStyle.SetBitmapType(EMonochromeGlyphBitmap); sl@0: TFontSpec firstSpec; sl@0: TInt ret; sl@0: //first run - tests that the code actually works before faulting the memory sl@0: ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) firstFont,reqSpec); sl@0: TEST(ret==KErrNone); sl@0: TEST(firstFont!=NULL); sl@0: if (ret!=KErrNone || firstFont==NULL) sl@0: { sl@0: return; //otherwise the memory faulting test loop will deadlock! sl@0: } sl@0: if (firstFont) sl@0: { sl@0: firstSpec=firstFont->FontSpecInTwips(); sl@0: fs->ReleaseFont(firstFont); sl@0: } sl@0: ret=KErrNoMemory; sl@0: TInt failRate=1; sl@0: while(ret!=KErrNone || (failRate<30 && !differentResultFetched)) sl@0: { sl@0: CBitmapFont *font=NULL; sl@0: __UHEAP_RESET; sl@0: __RHEAP_SETFAIL(iHeap,RHeap::EDeterministic,failRate); sl@0: __UHEAP_MARK; sl@0: __RHEAP_MARK(iHeap); sl@0: TFontSpec spec(reqSpec); sl@0: ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,reqSpec); sl@0: if (ret==KErrNoMemory) sl@0: { sl@0: RDebug::Print(_L("failrate %d: KErrNoMemory\n"),failRate); sl@0: TEST(font==NULL); sl@0: } sl@0: else if(ret==KErrNone) sl@0: { sl@0: TEST(font!=NULL); sl@0: if (font) sl@0: { sl@0: TFontSpec spec=font->FontSpecInTwips(); sl@0: if (!(spec==firstSpec)) sl@0: { sl@0: differentResultFetched=true; sl@0: ret=KErrNoMemory; //actually there was a handled memory fault sl@0: RDebug::Print(_L("failrate %d: Different font returned\n"),failRate); sl@0: } sl@0: else sl@0: { sl@0: RDebug::Print(_L("failrate %d: Same font returned\n"),failRate); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: RDebug::Print(_L("failrate %d: Error: NULL font returned\n"),failRate); sl@0: } sl@0: fs->ReleaseFont(font); sl@0: font=NULL; sl@0: } sl@0: else sl@0: { sl@0: User::Panic(_L("Unexpected error"),ret); sl@0: } sl@0: __RHEAP_CHECK(iHeap,0); sl@0: __RHEAP_MARKEND(iHeap); sl@0: __UHEAP_MARKEND; sl@0: __RHEAP_SETFAIL(iHeap,RHeap::ENone,failRate); sl@0: failRate++; sl@0: } sl@0: if (!differentResultFetched) sl@0: { sl@0: INFO_PRINTF1(_L("Test did not return different results under memory stress (unexpected)")); sl@0: } sl@0: delete fs; sl@0: } sl@0: sl@0: sl@0: //The "bad" versions of these standard fonts have been hacked to give specific results sl@0: _LIT(KFBSERVFontFileBitmap, "Z:\\resource\\fonts\\ceurope.GDR"); sl@0: //This file has the master GUID nobbled, but all the guid and typeface entries are duplicates. sl@0: _LIT(KFBSERVFontFileBadBitmap1, "Z:\\PlatTest\\Graphics\\TestData\\uniquified_fonts\\XXeuro.GDR"); sl@0: //This file has the master GUID nobbled, one of the 8 fonts, and one of the typefaces has also been nobbled. sl@0: _LIT(KFBSERVFontFileBadBitmap2, "Z:\\PlatTest\\Graphics\\TestData\\uniquified_fonts\\YYeuro.GDR"); sl@0: enum {KNobbledFontEnum=0x10ff5912}; //official code for LatinBold17 is 0x10005912 sl@0: _LIT(NobbledTypefaceName, "XatinBold17"); sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-CTFbs-TestDuplicateFontFileEntries-0002 sl@0: sl@0: @SYMDEF DEF094692 sl@0: sl@0: @SYMTestCaseDesc If Bitmap fonts are loaded that are marginally unique compared to the sl@0: existing fonts then they are not actually added to the typeface system, and may even be discarded. sl@0: sl@0: @SYMTestPriority Med sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions \n sl@0: The original versions of the Bitmapfonts are first loaded to ensure that they have actually been loaded. sl@0: A version of the bitmap font which is identical except for the file UID should be rejected sl@0: Verify that the unique data for the next test does not already exist sl@0: A version of the bitmap font which has just 1 unique bitmap will be loaded, but only 1 typeface entry will be added. sl@0: Verify that the unique data for the previous test now does exist sl@0: The memory allocations through these steps should be deterministic sl@0: sl@0: API Calls: AddFile\n sl@0: sl@0: @SYMTestExpectedResults The test expects: sl@0: The original versions should load without changing the number of typefaces sl@0: The second load should return the same UID for the font sl@0: The identical fonts should return captured fail codes, and not change the typeface counts sl@0: The semi-identical font should perform a single increase to UIDs and typefaces sl@0: */ sl@0: void CTFntMem::TestDuplicateBitmapFontFileEntriesL() sl@0: { sl@0: sl@0: INFO_PRINTF1(_L("Test Load semi-duplicate bitmap font files")); sl@0: __RHEAP_MARK(iHeap); sl@0: __UHEAP_MARK; sl@0: CFontStore *fs=CFontStore::NewL(iHeap); sl@0: CleanupStack::PushL(fs); sl@0: sl@0: TInt numFacesBefore=fs->NumTypefaces(); sl@0: TUid aIdBitMap1=TUid::Null(); sl@0: TUint numAllocsBefore=iHeap->Count(); sl@0: TUid aIdBitMap2=TUid::Null(); sl@0: TUid aIdBitMap3=TUid::Null(); sl@0: //make sure the originals of these fonts were safely opened sl@0: //both should simply cause a reference-count increase on the originator files. sl@0: TRAPD(err1,aIdBitMap1=fs->AddFileL(KFBSERVFontFileBitmap)); sl@0: TEST(err1==KErrNone); sl@0: if (err1) sl@0: { sl@0: INFO_PRINTF1(_L("One of the expected fonts was missing. Test abandoned.")); sl@0: } sl@0: else sl@0: { sl@0: TInt numFacesAfterLoadOriginals=fs->NumTypefaces(); sl@0: TEST(numFacesBeforeCount(); sl@0: sl@0: sl@0: //This bitmap font file contains no new fonts, so will ultimately be discarded sl@0: //The master UID has been nobbled so the file is not considered identical to its originator sl@0: TRAPD(err3,aIdBitMap2=fs->AddFileL(KFBSERVFontFileBadBitmap1)); sl@0: TEST(err3==KErrAlreadyExists && aIdBitMap2==TUid::Null()); sl@0: if (err3!=KErrAlreadyExists) sl@0: INFO_PRINTF2(_L("Unexpected error code was %d"),err3); sl@0: TInt numFacesAfterLoadBadFile3=fs->NumTypefaces(); sl@0: TEST(numFacesAfterLoadOriginals==numFacesAfterLoadBadFile3); sl@0: TUint numAllocsAfterLoadBadFile3=iHeap->Count(); sl@0: TEST(numAllocsAfterLoadBadFile3==numAllocsAfterLoadOriginals); sl@0: sl@0: //Before loading the next test check that the new data about to be added does not already exist sl@0: CFont *font=NULL; sl@0: TAlgStyle algStyle; sl@0: TFontSpec fontSpec(NobbledTypefaceName,10); sl@0: sl@0: TInt err5a1=fs->GetFontById(font,TUid::Uid(KNobbledFontEnum),algStyle); sl@0: TEST(font==NULL); //the nobbled UID should not already exist sl@0: sl@0: font=NULL; sl@0: sl@0: TInt err5a2=fs->GetNearestFontInPixels(font, fontSpec); sl@0: if (font) sl@0: { sl@0: TFontSpec specNoMatch=font->FontSpecInTwips(); sl@0: TEST(specNoMatch.iTypeface.iName!=NobbledTypefaceName); //Nobbled font name should not be known yet sl@0: fs->ReleaseFont(font); sl@0: } sl@0: sl@0: //This bitmap font file contains one new typeface and font sl@0: //Actually, they are bit file edited versions of existing ones! sl@0: TInt numAllocsBeforeLoadBadFile5 = iHeap->Count(); sl@0: TRAPD(err5,aIdBitMap3=fs->AddFileL(KFBSERVFontFileBadBitmap2)); sl@0: TEST(err5==KErrNone); sl@0: if (err5!=KErrNone) sl@0: INFO_PRINTF2(_L("Unexpected error code was %d"),err5); sl@0: sl@0: //The number of typefaces has now increased sl@0: TInt numFacesAfterLoadBadFile5=fs->NumTypefaces(); sl@0: TEST(numFacesAfterLoadOriginals+1==numFacesAfterLoadBadFile5); sl@0: TUint numAllocsAfterLoadBadFile5=iHeap->Count(); sl@0: TEST(numAllocsAfterLoadBadFile5==numAllocsBeforeLoadBadFile5+2); sl@0: sl@0: sl@0: TInt err5b1=fs->GetFontById(font,TUid::Uid(KNobbledFontEnum),algStyle); sl@0: TEST(err5b1==KErrNone && font!=NULL); //the nobbled UID should now exist sl@0: if (err5b1!=KErrNone) sl@0: INFO_PRINTF2(_L("Unexpected error code was %d"),err5b1); sl@0: sl@0: CFont *font2=NULL; sl@0: TInt err5b2=fs->GetNearestFontInPixels(font2, fontSpec); sl@0: TEST(err5b2==KErrNone && font2!=NULL); sl@0: if (err5b2!=KErrNone) sl@0: INFO_PRINTF2(_L("Unexpected error code was %d"),err5b2); sl@0: if (font2!=NULL) sl@0: { sl@0: TFontSpec specMatches=font->FontSpecInTwips(); sl@0: TEST(specMatches.iTypeface.iName==NobbledTypefaceName); //the nobbled typeface should now exist sl@0: } sl@0: TEST(font==font2); sl@0: if (font) sl@0: fs->ReleaseFont(font); sl@0: if (font2) sl@0: fs->ReleaseFont(font2); sl@0: } sl@0: sl@0: if (aIdBitMap1!=TUid::Null()) fs->RemoveFile(aIdBitMap1); sl@0: if (aIdBitMap2!=TUid::Null()) fs->RemoveFile(aIdBitMap2); sl@0: if (aIdBitMap3!=TUid::Null()) fs->RemoveFile(aIdBitMap3); sl@0: sl@0: //The added typeface should have been uninstalled sl@0: TInt numFacesAfterUninstall=fs->NumTypefaces(); sl@0: TEST(numFacesAfterUninstall==numFacesBefore); sl@0: TUint numAllocsAfterUninstall=iHeap->Count(); sl@0: sl@0: CleanupStack::PopAndDestroy(fs); sl@0: __UHEAP_CHECK(0); sl@0: __UHEAP_MARKEND; sl@0: __RHEAP_CHECK(iHeap,0); sl@0: __RHEAP_MARKEND(iHeap); sl@0: sl@0: } sl@0: sl@0: sl@0: //-------------- sl@0: __CONSTRUCT_STEP__(FntMem) sl@0: sl@0: