sl@0: /* sl@0: * Copyright (c) 1997-2010 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 sl@0: #include "TSTCLIPB.H" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "../incp/T_PMLPAR.H" sl@0: #include "T_RICHOOM.h" sl@0: sl@0: #define test(cond) \ sl@0: { \ sl@0: TBool __bb = (cond); \ sl@0: TEST(__bb); \ sl@0: if (!__bb) \ sl@0: { \ sl@0: ERR_PRINTF1(_L("ERROR: Test Failed")); \ sl@0: User::Leave(1); \ sl@0: } \ sl@0: } sl@0: sl@0: const TInt KTestCleanupStack=0x500; sl@0: sl@0: LOCAL_D RFs theFs; sl@0: LOCAL_D CParaFormatLayer* GlobalParaFormatLayer; sl@0: LOCAL_D CCharFormatLayer* GlobalCharFormatLayer; sl@0: LOCAL_D MPictureFactory* GlobalPictureFactory; sl@0: LOCAL_D CTrapCleanup* TheTrapCleanup; sl@0: LOCAL_D CParser* TheParser; sl@0: LOCAL_D RFs TheSession; sl@0: sl@0: sl@0: CRichText* CT_RICHOOM::LoadIntoTextL(TFileName& aFileName) sl@0: // sl@0: { sl@0: TRAPD(ret, sl@0: TheParser=CParser::NewL()); sl@0: CRichText* text=NULL; sl@0: TRAP(ret, sl@0: text=TheParser->ParseL(aFileName)); sl@0: delete GlobalParaFormatLayer; sl@0: delete GlobalCharFormatLayer; sl@0: GlobalParaFormatLayer=(CParaFormatLayer*)text->GlobalParaFormatLayer(); sl@0: GlobalCharFormatLayer=(CCharFormatLayer*)text->GlobalCharFormatLayer(); sl@0: delete TheParser; sl@0: TheParser=NULL; sl@0: return text; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::ConstructOOM() sl@0: // Test CRichText construction, (and index), forcing a leave error at each sl@0: // possible stage of the process. sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("Construction under low memory conditions")); sl@0: sl@0: CParaFormatLayer* paraLayer=CParaFormatLayer::NewL(); sl@0: CCharFormatLayer* charLayer=CCharFormatLayer::NewL(); sl@0: TInt failRate=0; sl@0: CRichText* doc=NULL; sl@0: for (failRate=1;;failRate++) sl@0: { sl@0: __UHEAP_RESET; sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,failRate); sl@0: __UHEAP_MARK; sl@0: TRAPD(ret,doc=CRichText::NewL(paraLayer,charLayer)); sl@0: if (ret!=KErrNone) sl@0: { sl@0: __UHEAP_MARKEND; sl@0: test(doc==NULL); sl@0: } sl@0: else sl@0: { sl@0: test(doc!=NULL); sl@0: // test(!doc->HasMarkupData()); sl@0: delete doc; sl@0: __UHEAP_MARKEND; sl@0: break; sl@0: } sl@0: } sl@0: __UHEAP_RESET; sl@0: delete paraLayer; sl@0: delete charLayer; sl@0: TBuf<36> answer; sl@0: answer.Format(_L(" #allocs for full c'tion: %d\n"),failRate-1); sl@0: INFO_PRINTF1(answer); sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::CopyPasteOOM() sl@0: { sl@0: // Set up the framework sl@0: INFO_PRINTF1(_L("Copy/Paste OOM")); sl@0: CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: TFileName file=_L("z:\\test\\app-framework\\etext\\climb.txt"); sl@0: /*TInt count=*/richText1->ImportTextFileL(0,file,CPlainText::EOrganiseByParagraph); sl@0: // sl@0: // Insert some picture components sl@0: CXzePicture* pic1=CXzePicture::NewL('p'); sl@0: CXzePicture* pic2=CXzePicture::NewL('l'); sl@0: CXzePicture* pic3=CXzePicture::NewL('l'); sl@0: TPictureHeader hdr1; sl@0: TPictureHeader hdr2; sl@0: TPictureHeader hdr3; sl@0: hdr1.iPictureType = KUidXzePictureType; sl@0: hdr2.iPictureType = KUidXzePictureType; sl@0: hdr3.iPictureType = KUidXzePictureType; sl@0: hdr1.iPicture = pic1; sl@0: hdr2.iPicture = pic2; sl@0: hdr3.iPicture = pic3; sl@0: richText1->InsertL(richText1->DocumentLength(),hdr3); sl@0: richText1->InsertL(richText1->DocumentLength(),hdr2); sl@0: richText1->InsertL(richText1->DocumentLength(),hdr1); sl@0: // sl@0: // Apply some random formatting sl@0: TCharFormat charFormat; TCharFormatMask charMask; sl@0: charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); sl@0: charMask.SetAttrib(EAttFontStrokeWeight); sl@0: richText1->ApplyCharFormatL(charFormat,charMask,10,37); sl@0: // sl@0: // Copy to clipboard normally. sl@0: INFO_PRINTF1(_L("Copy Normally")); sl@0: User::LeaveIfError(TheSession.Connect()); sl@0: CClipboard* writeBoard=CClipboard::NewForWritingLC(TheSession); sl@0: richText1->CopyToStoreL(writeBoard->Store(),writeBoard->StreamDictionary(),0,richText1->DocumentLength()-1); // forces virtual trailing phrase sl@0: writeBoard->CommitL(); sl@0: CleanupStack::PopAndDestroy(); // writeboard sl@0: writeBoard=NULL; sl@0: delete richText1; sl@0: richText1=NULL; sl@0: // sl@0: // Paste from clipboard normally. sl@0: INFO_PRINTF1(_L("Paste Normally")); sl@0: __UHEAP_MARK; sl@0: CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: MDemPictureFactory pictureFactory; sl@0: empty->SetPictureFactory(&pictureFactory,NULL); sl@0: CClipboard* readBoard=CClipboard::NewForReadingLC(TheSession); sl@0: TRAPD(ret, sl@0: empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),0)); sl@0: test(ret==KErrNone); sl@0: delete empty; sl@0: empty=NULL; sl@0: CleanupStack::PopAndDestroy(); // readBoard sl@0: readBoard=NULL; sl@0: __UHEAP_MARKEND; sl@0: // sl@0: // Paste from clipboard with OOM sl@0: INFO_PRINTF1(_L("Paste with OOM")); sl@0: INFO_PRINTF1(_L("...please wait")); sl@0: __UHEAP_MARK; sl@0: empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: for (TInt ii=1; ;ii++) sl@0: { sl@0: readBoard=CClipboard::NewForReadingLC(TheSession); sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,ii); sl@0: TRAP(ret,empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),0)); sl@0: __UHEAP_RESET; sl@0: empty->Reset(); sl@0: CleanupStack::PopAndDestroy(); sl@0: if (ret==KErrNone) sl@0: break; sl@0: } sl@0: readBoard=NULL; sl@0: sl@0: // sl@0: delete empty; sl@0: empty=NULL; sl@0: TheSession.Close(); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::CopyPasteOOM2() sl@0: // Test case for defect HA-282 - simple case sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: // Set up the framework sl@0: INFO_PRINTF1(_L("Copy/Paste OOM 2")); sl@0: CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: richText1->InsertL(0,_L("HelloHello")); sl@0: richText1->InsertL(5,CEditableText::EParagraphDelimiter); sl@0: // sl@0: // Format the first paragraph sl@0: TCharFormat charFormat; TCharFormatMask charMask; sl@0: charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); sl@0: charMask.SetAttrib(EAttFontStrokeWeight); sl@0: richText1->ApplyCharFormatL(charFormat,charMask,0,6); sl@0: // sl@0: // Copy to clipboard normally. sl@0: INFO_PRINTF1(_L("Copy Normally")); sl@0: User::LeaveIfError(TheSession.Connect()); sl@0: CClipboard* writeBoard=CClipboard::NewForWritingLC(TheSession); sl@0: richText1->CopyToStoreL(writeBoard->Store(),writeBoard->StreamDictionary(),2,6); // forces virtual trailing phrase sl@0: writeBoard->CommitL(); sl@0: CleanupStack::PopAndDestroy(); // writeboard sl@0: writeBoard=NULL; sl@0: // sl@0: // Paste from clipboard normally. sl@0: INFO_PRINTF1(_L("Paste Normally")); sl@0: // __UHEAP_MARK; sl@0: CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: empty->AppendTakingSolePictureOwnershipL(*richText1); sl@0: CClipboard* readBoard=CClipboard::NewForReadingLC(TheSession); sl@0: TRAPD(ret, sl@0: empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),empty->DocumentLength())); sl@0: test(ret==KErrNone); sl@0: delete empty; sl@0: empty=NULL; sl@0: CleanupStack::PopAndDestroy(); // readBoard sl@0: readBoard=NULL; sl@0: // __UHEAP_MARKEND; sl@0: // sl@0: // Paste from clipboard with OOM sl@0: INFO_PRINTF1(_L("Paste with OOM")); sl@0: INFO_PRINTF1(_L("...please wait")); sl@0: __UHEAP_MARK; sl@0: empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: empty->AppendTakingSolePictureOwnershipL(*richText1); sl@0: delete richText1; sl@0: richText1=NULL; sl@0: for (TInt ii=1; ;ii++) sl@0: { sl@0: readBoard=CClipboard::NewForReadingLC(TheSession); sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,ii); sl@0: TRAP(ret,empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),empty->DocumentLength())); sl@0: __UHEAP_RESET; sl@0: // empty->Reset(); sl@0: CleanupStack::PopAndDestroy(); sl@0: if (ret==KErrNone) sl@0: break; sl@0: } sl@0: readBoard=NULL; sl@0: // sl@0: delete empty; sl@0: empty=NULL; sl@0: __UHEAP_MARKEND; sl@0: TheSession.Close(); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::WriteInlineL(RWriteStream& aStream,CRichText* aRichText) sl@0: { sl@0: aRichText->ExternalizeStyleDataL(aStream); sl@0: aRichText->ExternalizeMarkupDataL(aStream); sl@0: aRichText->ExternalizePlainTextL(aStream); sl@0: } sl@0: sl@0: void CT_RICHOOM::ReadInlineL(RReadStream& aStream,CRichText* aRichText) sl@0: { sl@0: aRichText->InternalizeStyleDataL(aStream); sl@0: aRichText->InternalizeMarkupDataL(aStream); sl@0: aRichText->InternalizePlainTextL(aStream); sl@0: } sl@0: sl@0: sl@0: CStyleList* CT_RICHOOM::CreatePopulatedStyleList() sl@0: // sl@0: { sl@0: // sl@0: // Create style aswell. sl@0: CStyleList* list=CStyleList::NewL(); sl@0: CParagraphStyle* style1=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer); sl@0: CParagraphStyle* style2=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer); sl@0: CParagraphStyle* style3=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer); sl@0: RParagraphStyleInfo info1(style1); sl@0: RParagraphStyleInfo info2(style2); sl@0: RParagraphStyleInfo info3(style3); sl@0: list->AppendL(&info1); sl@0: list->AppendL(&info2); sl@0: list->AppendL(&info3); sl@0: return list; sl@0: } sl@0: _LIT(KTRichOutputFile,"c:\\etext\\TRICH.DAT"); sl@0: sl@0: void CT_RICHOOM::SaveLoadOOM() sl@0: { sl@0: // Set up the framework sl@0: theFs.Delete(KTRichOutputFile); sl@0: theFs.MkDirAll(KTRichOutputFile); sl@0: CFileStore* store = CPermanentFileStore::CreateLC(theFs,KTRichOutputFile,EFileRead|EFileWrite); sl@0: store->SetTypeL(store->Layout()); sl@0: CStyleList* list=CreatePopulatedStyleList(); sl@0: CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list); sl@0: TBool hasMarkupData=richText1->HasMarkupData(); sl@0: test(hasMarkupData); // because of owned style list. sl@0: richText1->InsertL(0,_L("hello")); sl@0: richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter); sl@0: richText1->InsertL(richText1->DocumentLength(),_L("there")); sl@0: sl@0: RStoreWriteStream out; sl@0: TStreamId id1 = out.CreateLC(*store); sl@0: sl@0: INFO_PRINTF1(_L("Store/Restore OOM")); sl@0: INFO_PRINTF1(_L("Writing Inline noramlly")); sl@0: // Write out inline normally sl@0: WriteInlineL(out,richText1); sl@0: delete richText1; sl@0: out.CommitL(); sl@0: CleanupStack::PopAndDestroy(); // out sl@0: store->CommitL(); sl@0: RStoreReadStream in; sl@0: in.OpenLC(*store,id1); sl@0: CRichText* empty = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: sl@0: INFO_PRINTF1(_L("Reading Inline noramlly")); sl@0: // Read in inline normally: sl@0: TRAPD(ret,ReadInlineL(in,empty)); sl@0: test(ret==KErrNone); sl@0: CleanupStack::PopAndDestroy(); // in sl@0: delete empty; sl@0: empty=NULL; sl@0: sl@0: INFO_PRINTF1(_L("Reading Inline with OOM")); sl@0: // Read in inline with OOM: sl@0: empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: sl@0: for (TInt jj = 1; ;++jj) sl@0: { sl@0: RStoreReadStream in2; sl@0: in2.OpenLC(*store,id1); sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,jj); sl@0: TRAPD(ret,ReadInlineL(in2,empty)); sl@0: __UHEAP_RESET; sl@0: CleanupStack::PopAndDestroy(); // in2 sl@0: if (ret!=KErrNone) sl@0: empty->Reset(); sl@0: else sl@0: { sl@0: test(empty->HasMarkupData()); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("Writing Inline with OOM")); sl@0: // Write out inline with OOM: sl@0: CStyleList* list2=CreatePopulatedStyleList(); sl@0: CRichText* richText2 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list2); sl@0: richText2->InsertL(0,_L("hello")); sl@0: TStreamId i = store->ExtendL(); sl@0: for (TInt ii = 1; ;++ii) sl@0: { sl@0: RStoreWriteStream out2; sl@0: out2.ReplaceLC(*store,i); sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,ii); sl@0: TRAP(ret,WriteInlineL(out2,richText2)); sl@0: __UHEAP_RESET; sl@0: if (ret==KErrNone) sl@0: { sl@0: out2.CommitL(); sl@0: CleanupStack::PopAndDestroy(); // out2 sl@0: delete richText2; sl@0: break; sl@0: } sl@0: else sl@0: CleanupStack::PopAndDestroy(); // out2 sl@0: } sl@0: store->CommitL(); sl@0: sl@0: INFO_PRINTF1(_L("Reading Inline after OOM write")); sl@0: // Read in inline normally following a write out with OOM sl@0: RStoreReadStream in3; sl@0: in3.OpenLC(*store,i); sl@0: empty->Reset(); sl@0: TRAP(ret,ReadInlineL(in3,empty)); // unhandled exception sl@0: test(ret==KErrNone); sl@0: CleanupStack::PopAndDestroy(); sl@0: empty->Reset(); sl@0: sl@0: // sl@0: // sl@0: // sl@0: sl@0: // Set up new component framework sl@0: CXzePicture* pic1=CXzePicture::NewL('p'); sl@0: CXzePicture* pic2=CXzePicture::NewL('l'); sl@0: CXzePicture* pic3=CXzePicture::NewL('l'); sl@0: TPictureHeader hdr1; sl@0: TPictureHeader hdr2; sl@0: TPictureHeader hdr3; sl@0: hdr1.iPictureType = KUidXzePictureType; sl@0: hdr2.iPictureType = KUidXzePictureType; sl@0: hdr3.iPictureType = KUidXzePictureType; sl@0: hdr1.iPicture = pic1; sl@0: hdr2.iPicture = pic2; sl@0: hdr3.iPicture = pic3; sl@0: CRichText* richText3 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: richText3->InsertL(0,hdr3); sl@0: richText3->InsertL(0,hdr2); sl@0: richText3->InsertL(0,hdr1); sl@0: richText3->InsertL(2,_L("hello")); sl@0: sl@0: INFO_PRINTF1(_L("Writing Outline noramlly")); sl@0: // Write outline normally: sl@0: TStreamId id2 = richText3->StoreL(*store); sl@0: store->CommitL(); sl@0: delete richText3; sl@0: sl@0: INFO_PRINTF1(_L("Reading Outline noramlly")); sl@0: // Read outline normally: sl@0: empty->Reset(); sl@0: TRAP(ret,empty->RestoreL(*store,id2)); sl@0: test(ret==KErrNone); sl@0: empty->Reset(); sl@0: sl@0: INFO_PRINTF1(_L("Reading Outline with OOM")); sl@0: // Read outline with OOM: sl@0: CRichText* inText2=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: for (TInt kk = 1; ;++kk) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,kk); sl@0: // sl@0: TRAP(ret,inText2->RestoreL(*store,id2)); sl@0: // sl@0: __UHEAP_RESET; sl@0: if (ret!=KErrNone) sl@0: inText2->Reset(); sl@0: else sl@0: { sl@0: delete inText2; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: CRichText* richText4 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: CXzePicture* pic4=CXzePicture::NewL('P'); sl@0: CXzePicture* pic5=CXzePicture::NewL('P'); sl@0: CXzePicture* pic6=CXzePicture::NewL('P'); sl@0: TPictureHeader hdr4; sl@0: TPictureHeader hdr5; sl@0: TPictureHeader hdr6; sl@0: hdr4.iPictureType=KUidXzePictureType; sl@0: hdr5.iPictureType=KUidXzePictureType; sl@0: hdr6.iPictureType=KUidXzePictureType; sl@0: hdr4.iPicture=pic4; sl@0: hdr5.iPicture=pic5; sl@0: hdr6.iPicture=pic6; sl@0: richText4->InsertL(0,hdr4); sl@0: richText4->InsertL(0,hdr5); sl@0: richText4->InsertL(0,hdr6); sl@0: richText4->InsertL(1,_L("hello")); sl@0: sl@0: INFO_PRINTF1(_L("Writing Outline with OOM")); sl@0: // Wtite outline with OOM: sl@0: TStreamId id3(0); sl@0: for (TInt mm=1; ;++mm) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,mm); sl@0: TRAPD(ret,id3 = richText4->StoreL(*store)); sl@0: if (ret==KErrNone) sl@0: { sl@0: __UHEAP_RESET; sl@0: delete richText4; sl@0: store->CommitL(); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("Reading Outline after OOM write")); sl@0: // Read outline normally folliwng a write with OOM: sl@0: empty->Reset(); sl@0: TRAP(ret,empty->RestoreL(*store,id3)); sl@0: test(ret==KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(); // store sl@0: delete empty; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::CheckTextIntegrity(const CRichText* aText) sl@0: // Simply invokes a method to run the text (& component's) onvariants. sl@0: // sl@0: { sl@0: __UHEAP_RESET; sl@0: CParaFormat* paraFormat=CParaFormat::NewLC(); sl@0: aText->GetParagraphFormatL(paraFormat,0); // forces CRichTextIndex::__DbgTextInvariant() to run. sl@0: CleanupStack::PopAndDestroy(); // paraFormat sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::BasicEditOOM() sl@0: // Tests basic editing functions under OOM conditions. sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("Basic Editing methods under OOM")); sl@0: INFO_PRINTF1(_L("InsertL(TChar)")); sl@0: // sl@0: // Insert a single character sl@0: const TInt insertCharLoop=10; sl@0: const TInt KSmallTextBufferSize=1; sl@0: CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); sl@0: richText1->SetPictureFactory(NULL,NULL); // forces index generation sl@0: for (TInt mm=1;mm<=insertCharLoop;mm++) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,mm); sl@0: for (TInt nn=1;nn<=insertCharLoop;nn++) sl@0: { sl@0: TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),'x')); sl@0: if (ret!=KErrNone) sl@0: { sl@0: test(richText1->DocumentLength()+1==nn); sl@0: CheckTextIntegrity(richText1); sl@0: break; sl@0: } sl@0: } sl@0: __UHEAP_RESET; sl@0: richText1->Reset(); sl@0: } sl@0: __UHEAP_RESET; sl@0: delete richText1; sl@0: // sl@0: // sl@0: INFO_PRINTF1(_L("InsertL(TDesC&)")); sl@0: // sl@0: // Insert a descriptor sl@0: const TInt insertDescriptorLoop=10; sl@0: richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); sl@0: richText1->SetPictureFactory(NULL,NULL); // forces index generation sl@0: TPtrC buf(_L("1234567890")); sl@0: sl@0: for (TInt nn=1;nn<=insertDescriptorLoop+1;nn++) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,nn); sl@0: TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),buf)); sl@0: if (ret!=KErrNone) sl@0: { sl@0: test(richText1->DocumentLength()==0); sl@0: } sl@0: else sl@0: { sl@0: test(richText1->DocumentLength()==buf.Length()); sl@0: } sl@0: CheckTextIntegrity(richText1); sl@0: richText1->Reset(); sl@0: } sl@0: __UHEAP_RESET; sl@0: delete richText1; sl@0: sl@0: // sl@0: // sl@0: INFO_PRINTF1(_L("InsertL(TPictureHeader&)")); sl@0: // sl@0: // Insert a picture header sl@0: richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); sl@0: // sl@0: for (TInt ii=18; ;ii++) sl@0: { sl@0: // create the picture header sl@0: __UHEAP_RESET; sl@0: CXzePicture* pic1=CXzePicture::NewL('o'); sl@0: TPictureHeader hdr1; sl@0: hdr1.iPictureType=KUidXzePictureType; sl@0: hdr1.iPicture=pic1; sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,ii); sl@0: TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),hdr1)); sl@0: if (ret!=KErrNone) sl@0: { sl@0: test(richText1->DocumentLength()==0); sl@0: // if (ii<19) sl@0: // delete pic1; sl@0: /* sl@0: THE ABOVE 2 LINES ARE WRONG NOW, SINCE THE PICTURE IS DELETED AUTOMATICALLY, IF THE INSERTION FAILS. sl@0: sl@0: */ sl@0: richText1->Reset(); sl@0: } sl@0: else sl@0: { sl@0: test(richText1->DocumentLength()==1); sl@0: break; sl@0: } sl@0: } sl@0: __UHEAP_RESET; sl@0: delete richText1; sl@0: sl@0: __UHEAP_RESET; sl@0: // delete richText1; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::AppendTest1L() sl@0: { sl@0: // Insert a single character sl@0: const TInt insertDescriptorLoop=10; sl@0: const TInt KSmallTextBufferSize=1; sl@0: CRichText* source=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); sl@0: CRichText* target=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); sl@0: source->InsertL(source->DocumentLength(),_L("1234567890")); sl@0: target->InsertL(target->DocumentLength(),_L("abcdef")); sl@0: TInt targetStartLength=target->DocumentLength(); sl@0: for (TInt nn=1;nn<=insertDescriptorLoop+2;nn++) // +1 for the last para delim, +1 to force a suceed sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,nn); sl@0: TRAPD(ret,target->AppendTakingSolePictureOwnershipL(*source)); sl@0: if (ret!=KErrNone) sl@0: { sl@0: test(target->DocumentLength()==targetStartLength); sl@0: } sl@0: else sl@0: { sl@0: TInt targetLength=target->DocumentLength(); sl@0: test(targetLength==targetStartLength+source->DocumentLength()+1); sl@0: break; sl@0: } sl@0: CheckTextIntegrity(target); sl@0: } sl@0: __UHEAP_RESET; sl@0: delete target; sl@0: delete source; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::AppendTest2L(CRichText* aTarget) sl@0: { sl@0: __UHEAP_RESET; sl@0: const TInt KSmallTextBufferSize=1; sl@0: TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml"); sl@0: CRichText* source=LoadIntoTextL(filename); sl@0: if (!aTarget) sl@0: aTarget=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); sl@0: TInt targetStartLength=aTarget->DocumentLength(); sl@0: for (TInt ii = 1; ;++ii) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,ii); sl@0: TRAPD(ret, sl@0: aTarget->AppendTakingSolePictureOwnershipL(*source)); sl@0: __UHEAP_RESET; sl@0: if (ret!=KErrNone) sl@0: { sl@0: test(aTarget->DocumentLength()==targetStartLength); sl@0: } sl@0: else sl@0: {// We have succeeded in appending the document. sl@0: TInt paraDelimiter=(targetStartLength>0) ? 1 : 0; sl@0: test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength()); sl@0: break; sl@0: } sl@0: } sl@0: delete source; sl@0: delete aTarget; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::AppendTestNewL(CRichText* aTarget) sl@0: { sl@0: const TInt KSmallTextBufferSize=4; sl@0: TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml"); sl@0: CRichText* source=LoadIntoTextL(filename); sl@0: if (!aTarget) sl@0: { sl@0: aTarget=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); sl@0: aTarget->InsertL(0,_L("This is paragraph number one")); sl@0: aTarget->InsertL(1,CEditableText::EParagraphDelimiter); sl@0: } sl@0: TInt targetStartLength=aTarget->DocumentLength(); sl@0: for (TInt ii = 1; ;++ii) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,ii); sl@0: TRAPD(ret, sl@0: aTarget->AppendTakingSolePictureOwnershipL(*source)); sl@0: __UHEAP_RESET; sl@0: if (ret!=KErrNone) sl@0: { sl@0: test(aTarget->DocumentLength()==targetStartLength); sl@0: } sl@0: else sl@0: {// We have succeeded in appending the document. sl@0: TInt paraDelimiter=(targetStartLength>0) ? 1 : 0; sl@0: test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength()); sl@0: break; sl@0: } sl@0: } sl@0: delete source; sl@0: delete aTarget; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::AppendTest3L(CRichText* aTarget) sl@0: { sl@0: const TInt KSmallTextBufferSize=31; sl@0: TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml"); sl@0: CRichText* source=LoadIntoTextL(filename); sl@0: if (!aTarget) sl@0: aTarget=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize); sl@0: TInt targetStartLength=aTarget->DocumentLength(); sl@0: for (TInt ii = 1; ;++ii) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,ii); sl@0: TRAPD(ret, sl@0: aTarget->AppendTakingSolePictureOwnershipL(*source)); sl@0: __UHEAP_RESET; sl@0: if (ret!=KErrNone) sl@0: { sl@0: test(aTarget->DocumentLength()==targetStartLength); sl@0: } sl@0: else sl@0: {// We have succeeded in appending the document. sl@0: TInt paraDelimiter=(targetStartLength>0) ? 1 : 0; sl@0: test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength()); sl@0: break; sl@0: } sl@0: } sl@0: delete source; sl@0: delete aTarget; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::AppendTakingSolePictureOwnershipOOM() sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("AppendTakingSolePictureOwnershipL() under OOM")); sl@0: // sl@0: INFO_PRINTF1(_L("Plain text only")); sl@0: TRAPD(ret, sl@0: AppendTest1L()); sl@0: test(ret==KErrNone); sl@0: // sl@0: INFO_PRINTF1(_L("Plain text + phrase markup, with empty target")); sl@0: TRAP(ret, sl@0: AppendTest2L(STATIC_CAST(CRichText*,NULL))); sl@0: test(ret==KErrNone); sl@0: // sl@0: INFO_PRINTF1(_L("Plain text + phrase markup, with non-empty target")); sl@0: TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml"); sl@0: CRichText* target=LoadIntoTextL(filename); sl@0: TRAP(ret, sl@0: AppendTest2L(target)); sl@0: test(ret==KErrNone); sl@0: // sl@0: // INFO_PRINTF1(_L("Plain text + shared markup, with empty target")); sl@0: // TRAP(ret, sl@0: // AppendTest3L(STATIC_CAST(CRichText*,NULL))); sl@0: // test(ret==KErrNone); sl@0: // sl@0: INFO_PRINTF1(_L("Plain text + shared markup, non-empty target")); sl@0: TRAP(ret, sl@0: AppendTestNewL(STATIC_CAST(CRichText*,NULL))); sl@0: test(ret==KErrNone); sl@0: // sl@0: INFO_PRINTF1(_L("Plain text + shared markup, with non-empty target")); sl@0: filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml"); sl@0: target=LoadIntoTextL(filename); sl@0: TRAP(ret, sl@0: AppendTest3L(target)); sl@0: test(ret==KErrNone); sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::DoAppendParagraphOOM(CRichText* aRichText,TBool aUnderOOM,TInt aReplicas) sl@0: { sl@0: if (!aUnderOOM) sl@0: { sl@0: aRichText->AppendParagraphL(aReplicas); sl@0: return; sl@0: } sl@0: // sl@0: // Append testing for OOM sl@0: TInt charCount=aRichText->DocumentLength(); sl@0: TInt paraCount=aRichText->ParagraphCount(); sl@0: for (TInt jj = 1; ;++jj) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,jj); sl@0: TRAPD(ret, sl@0: aRichText->AppendParagraphL(aReplicas)); sl@0: __UHEAP_RESET; sl@0: TInt newCharCount=aRichText->DocumentLength(); sl@0: TInt newParaCount=aRichText->ParagraphCount(); sl@0: if (ret!=KErrNone) sl@0: { sl@0: test(newCharCount==charCount); sl@0: test(newParaCount==paraCount); sl@0: } sl@0: else sl@0: { sl@0: test(newCharCount==charCount+aReplicas); sl@0: test(newParaCount==paraCount+aReplicas); sl@0: TBuf<30> buf; sl@0: buf.Format(_L(" allocs=%d\n"),jj); sl@0: INFO_PRINTF1(buf); sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::AppendParagraphOOM() sl@0: // sl@0: { sl@0: TInt manyParas=5; sl@0: TInt singlePara=1; sl@0: INFO_PRINTF1(_L("AppendParagraphL() under OOM")); sl@0: // sl@0: INFO_PRINTF1(_L("appending normally - text has markup - single para")); sl@0: TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml"); sl@0: CRichText* text=LoadIntoTextL(filename); sl@0: DoAppendParagraphOOM(text,EFalse,singlePara); sl@0: delete text; sl@0: text=NULL; sl@0: sl@0: INFO_PRINTF1(_L("appending with OOM - text has markup - single para")); sl@0: text=LoadIntoTextL(filename); sl@0: DoAppendParagraphOOM(text,ETrue,singlePara); sl@0: delete text; sl@0: text=NULL; sl@0: sl@0: INFO_PRINTF1(_L("appending normally - text has markup - many paras")); sl@0: text=LoadIntoTextL(filename); sl@0: DoAppendParagraphOOM(text,EFalse,manyParas); sl@0: delete text; sl@0: text=NULL; sl@0: sl@0: INFO_PRINTF1(_L("appending with OOM - text has markup - many paras")); sl@0: text=LoadIntoTextL(filename); sl@0: DoAppendParagraphOOM(text,ETrue,manyParas); sl@0: delete text; sl@0: text=NULL; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::ApplyCharFormatOOM1() sl@0: { sl@0: // Set up the framework sl@0: INFO_PRINTF1(_L("ApplyCharFormatL() OOM - no markup")); sl@0: CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: richText1->InsertL(0,_L("SOME VERY FINE TEXT")); sl@0: sl@0: // Apply some random formatting sl@0: TCharFormat charFormat; TCharFormatMask charMask; sl@0: charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); sl@0: charMask.SetAttrib(EAttFontStrokeWeight); sl@0: sl@0: for (TInt jj=1; ;jj++) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,jj); sl@0: TRAPD(ret, sl@0: richText1->ApplyCharFormatL(charFormat,charMask,5,11)); sl@0: __UHEAP_RESET; sl@0: TPtrC buf; sl@0: if (ret==KErrNone) sl@0: { sl@0: TCharFormat newFormat; sl@0: richText1->GetChars(buf,newFormat,5); sl@0: test(newFormat.IsEqual(charFormat,charMask)); sl@0: test(buf.Length() < richText1->DocumentLength()); sl@0: break; sl@0: } sl@0: else sl@0: { sl@0: sl@0: } sl@0: sl@0: } sl@0: delete richText1; sl@0: richText1=NULL; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::ApplyCharFormatOOM2() sl@0: { sl@0: // Set up the framework sl@0: INFO_PRINTF1(_L("ApplyCharFormatL() OOM - with markup")); sl@0: CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer); sl@0: richText1->InsertL(0,_L("SOME TEXT")); sl@0: sl@0: // Generate some markup sl@0: TCharFormat cF; sl@0: TCharFormatMask cM; sl@0: cF.iFontSpec.iFontStyle.SetPosture(EPostureItalic); sl@0: cM.SetAttrib(EAttFontPosture); sl@0: richText1->ApplyCharFormatL(cF,cM,3,3); sl@0: sl@0: // Apply some random formatting sl@0: TCharFormat charFormat; TCharFormatMask charMask; sl@0: charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); sl@0: charMask.SetAttrib(EAttFontStrokeWeight); sl@0: sl@0: for (TInt jj=1; ;jj++) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic,jj); sl@0: TRAPD(ret, sl@0: richText1->ApplyCharFormatL(charFormat,charMask,3,3)); sl@0: __UHEAP_RESET; sl@0: TPtrC buf; sl@0: if (ret==KErrNone) sl@0: { sl@0: TCharFormat newFormat; sl@0: richText1->GetChars(buf,newFormat,3); sl@0: test(newFormat.iFontSpec.iFontStyle.Posture()==EPostureItalic); sl@0: test(newFormat.iFontSpec.iFontStyle.StrokeWeight()==EStrokeWeightBold); sl@0: test(buf.Length()==3); sl@0: break; sl@0: } sl@0: else sl@0: { sl@0: sl@0: } sl@0: sl@0: } sl@0: delete richText1; sl@0: richText1=NULL; sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::doMainL() sl@0: { sl@0: sl@0: GlobalPictureFactory=new(ELeave) MDemPictureFactory; sl@0: GlobalParaFormatLayer=CParaFormatLayer::NewL(); sl@0: GlobalCharFormatLayer=CCharFormatLayer::NewL(); sl@0: theFs.Connect(); sl@0: // sl@0: TRAPD(ret,ConstructOOM()); sl@0: test(ret==KErrNone); sl@0: TRAP(ret,SaveLoadOOM()); sl@0: test(ret==KErrNone); sl@0: TRAP(ret,CopyPasteOOM()); sl@0: test(ret==KErrNone); sl@0: TRAP(ret,BasicEditOOM()); sl@0: test(ret==KErrNone); sl@0: TRAP(ret,AppendTakingSolePictureOwnershipOOM()); sl@0: test(ret==KErrNone); sl@0: TRAP(ret,CopyPasteOOM2()); sl@0: test(ret==KErrNone); sl@0: TRAP(ret,AppendParagraphOOM()); sl@0: test(ret==KErrNone); sl@0: TRAP(ret,ApplyCharFormatOOM1()); sl@0: test(ret==KErrNone); sl@0: TRAP(ret,ApplyCharFormatOOM2()); sl@0: test(ret==KErrNone); sl@0: // sl@0: delete GlobalPictureFactory; sl@0: delete GlobalParaFormatLayer; sl@0: delete GlobalCharFormatLayer; sl@0: theFs.Close(); sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::setupCleanup() sl@0: // sl@0: // Initialise the cleanup stack. sl@0: // sl@0: { sl@0: TheTrapCleanup=CTrapCleanup::New(); sl@0: test(TheTrapCleanup!=NULL); sl@0: TRAPD(r,\ sl@0: {\ sl@0: for (TInt i=KTestCleanupStack;i>0;i--)\ sl@0: CleanupStack::PushL((TAny*)0);\ sl@0: CleanupStack::Pop(KTestCleanupStack);\ sl@0: }); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: void CT_RICHOOM::DeleteDataFile(const TDesC& aFullName) sl@0: { sl@0: RFs fsSession; sl@0: TInt err = fsSession.Connect(); sl@0: if(err == KErrNone) sl@0: { sl@0: TEntry entry; sl@0: if(fsSession.Entry(aFullName, entry) == KErrNone) sl@0: { sl@0: RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName); sl@0: err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); sl@0: } sl@0: err = fsSession.Delete(aFullName); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); sl@0: } sl@0: } sl@0: fsSession.Close(); sl@0: } sl@0: else sl@0: { sl@0: RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); sl@0: } sl@0: } sl@0: sl@0: CT_RICHOOM::CT_RICHOOM() sl@0: { sl@0: SetTestStepName(KTestStep_T_RICHOOM); sl@0: } sl@0: sl@0: TVerdict CT_RICHOOM::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: setupCleanup(); sl@0: sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TRICHOOM-0001 RichText OOM Testing ")); sl@0: TRAPD(error1, doMainL()); sl@0: sl@0: delete TheTrapCleanup; sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if(error1 == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: }