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 "T_CPLAIN.h" sl@0: sl@0: LOCAL_D CTestStep *pTestStep = NULL; sl@0: #define test(cond) \ sl@0: { \ sl@0: TBool __bb = (cond); \ sl@0: pTestStep->TEST(__bb); \ sl@0: if (!__bb) \ sl@0: { \ sl@0: pTestStep->ERR_PRINTF1(_L("ERROR: Test Failed")); \ sl@0: User::Leave(1); \ sl@0: } \ sl@0: } sl@0: #undef INFO_PRINTF1 sl@0: #undef INFO_PRINTF2 sl@0: // copy from tefexportconst.h sl@0: #define INFO_PRINTF1(p1) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1)) sl@0: #define INFO_PRINTF2(p1, p2) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2)) sl@0: sl@0: const TBool KPictureIsDelimiter=EFalse; sl@0: const TBool KPunctuationIsDelimiter=ETrue; sl@0: sl@0: template sl@0: class TestCPlainText : public CPlainText sl@0: { sl@0: public: sl@0: static TestCPlainText* NewL(); sl@0: void TestL(); // Controls testing of the Flat storage usage. sl@0: void TestSegmentedL(); // Controls testing of the segmented storage usage. sl@0: void CheckDocLength(TInt aLength); sl@0: void CheckDocLength(CPlainText* aDocument,TInt aLength); sl@0: void CheckContent(const TDesC& aOriginal,TPtrC& aControl); sl@0: void CheckContent(const TDesC& aOriginal,TDes& aControl); sl@0: void CheckContent(CPlainText* aDocument,TPtrC& aControl); sl@0: void CheckParagraphStart(TInt aCalculated,TInt aExpected); sl@0: void CheckCharsSkipped(TInt aCalculated,TInt aExpected); sl@0: void DoParagraphStart(TInt aStartPos,TInt aLength,CPlainText* aDocument); sl@0: void InsertL(TInt aPos,const TDesC& aBuf); sl@0: void CPlainTest0L(); // Checks all methods are present. sl@0: void CPlainTest1L(); // Test construction under different memory conditions. sl@0: void CPlainTest2L(); // Read method tests sl@0: void CPlainTest3L(); sl@0: void CPlainTest4L(); sl@0: void CPlainTest5L(); sl@0: void CPlainTest5aL(); // Added to test the word info method. sl@0: void CPlainTest5bL(); // Added to test the CharPosOfParagraph method. sl@0: void CPlainTest5cL(); // Added to test the ParagraphNumberForPos method. sl@0: void DoCharPosOfParagraph(CPlainText* aText,TInt aParaN,TInt aPosCheck,TInt aLengthCheck); sl@0: void DoParagraphNumberForPos(CPlainText* aText,TInt aPos,TInt aParaCheck,TInt aPosCheck); sl@0: void CPlainTest6L(); sl@0: void CPlainTest7L(); sl@0: void CPlainTest8L(); sl@0: void DefectsL(); sl@0: void INC070807L(); sl@0: private: sl@0: TestCPlainText(); sl@0: TestCPlainText(const TestCPlainText& aTestCPlainText); sl@0: TestCPlainText& operator=(const TestCPlainText& aTestCPlainText); sl@0: private: sl@0: static TPtrC iDefaultDoc; sl@0: static TPtrC iInBuf; sl@0: static TPtrC iOutBuf; sl@0: static TPtrC iOutBufComp; sl@0: static TPtrC iInBuf2; sl@0: static TPtrC iOutBuf2; sl@0: static TPtrC iDummy; sl@0: static TPtrC iComp1; sl@0: static TPtrC iComp2; sl@0: static TPtrC iComp3; sl@0: static TPtrC iComp4; sl@0: static TPtrC iComp5; sl@0: static TPtrC iInsertBuf; sl@0: static TPtrC iTestBuf1; sl@0: static TPtrC iTestBuf2; sl@0: static TPtrC iTestBuf2a; sl@0: static TPtrC iTestBuf3; sl@0: }; sl@0: sl@0: template<> TPtrC TestCPlainText::iDefaultDoc(_L("A default constructor has been used to build this text in a new document that is newly created.")); sl@0: template<> TPtrC TestCPlainText::iComp1(_L("A default constructor has been used to build this text in a new document that is newly created.")); sl@0: template<> TPtrC TestCPlainText::iComp2(_L("this text in a new document that is newly created.")); sl@0: template<> TPtrC TestCPlainText::iComp3(_L("d.")); sl@0: template<> TPtrC TestCPlainText::iComp4(_L(".")); sl@0: template<> TPtrC TestCPlainText::iComp5(_L("")); sl@0: template<> TPtrC TestCPlainText::iDummy(_L("a")); sl@0: template<> TPtrC TestCPlainText::iInBuf(_L("AAAAAAAAAA")); sl@0: template<> TPtrC TestCPlainText::iOutBuf(_L("")); sl@0: template<> TPtrC TestCPlainText::iInBuf2(_L("OOOO")); sl@0: template<> TPtrC TestCPlainText::iOutBufComp(_L("AAAAAAAAAA")); sl@0: template<> TPtrC TestCPlainText::iOutBuf2(_L("")); sl@0: template<> TPtrC TestCPlainText::iTestBuf1(_L("abcdefINLINE_TEXTghijklmnopqrstuvwxyz")); sl@0: template<> TPtrC TestCPlainText::iInsertBuf(_L("abcdefghijklmnopqrstuvwxyz")); sl@0: template<> TPtrC TestCPlainText::iTestBuf2(_L("klmnopqrstuvwxyz")); sl@0: template<> TPtrC TestCPlainText::iTestBuf2a(_L("klmnopqrst")); sl@0: template<> TPtrC TestCPlainText::iTestBuf3(_L("efghi")); sl@0: sl@0: template<> TPtrC TestCPlainText::iDefaultDoc(_L("A default constructor has been used to build this text in a new document that is newly created.")); sl@0: template<> TPtrC TestCPlainText::iComp1(_L("A default constructor has been used to build this text in a new document that is newly created.")); sl@0: template<> TPtrC TestCPlainText::iComp2(_L("this text in a new document that is newly created.")); sl@0: template<> TPtrC TestCPlainText::iComp3(_L("d.")); sl@0: template<> TPtrC TestCPlainText::iComp4(_L(".")); sl@0: template<> TPtrC TestCPlainText::iComp5(_L("")); sl@0: template<> TPtrC TestCPlainText::iDummy(_L("a")); sl@0: template<> TPtrC TestCPlainText::iInBuf(_L("AAAAAAAAAA")); sl@0: template<> TPtrC TestCPlainText::iOutBuf(_L("")); sl@0: template<> TPtrC TestCPlainText::iInBuf2(_L("OOOO")); sl@0: template<> TPtrC TestCPlainText::iOutBufComp(_L("AAAAAAAAAA")); sl@0: template<> TPtrC TestCPlainText::iOutBuf2(_L("")); sl@0: sl@0: #if ((defined (__GCC32__)) && (!defined (__X86GCC__)) ) sl@0: template class TestCPlainText; sl@0: template class TestCPlainText; sl@0: #endif sl@0: sl@0: sl@0: template sl@0: TestCPlainText* TestCPlainText::NewL() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: TestCPlainText* tmp=new(ELeave)TestCPlainText; sl@0: tmp->ConstructL(D); sl@0: return tmp; sl@0: } sl@0: sl@0: sl@0: template sl@0: TestCPlainText::TestCPlainText() sl@0: // sl@0: // Default constructor. sl@0: // sl@0: {} sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CheckDocLength(TInt aLength) sl@0: // sl@0: // Test the current document length == aLength sl@0: // sl@0: { sl@0: TInt docLength=DocumentLength(); sl@0: test(docLength==aLength); sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CheckDocLength(CPlainText* aDocument,TInt aLength) sl@0: // sl@0: // Test that the length of document aDocument==aLength sl@0: // sl@0: { sl@0: test(aDocument->DocumentLength()==aLength); sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CheckContent(const TDesC& aOriginal,TPtrC& aControl) sl@0: // sl@0: // Check that document content is what you expect sl@0: // sl@0: { sl@0: test(aOriginal.Length()==aControl.Length()); sl@0: for (TInt offset=0;offset sl@0: void TestCPlainText::CheckContent(const TDesC& aOriginal,TDes& aControl) sl@0: // sl@0: // Check that document content is what you expect sl@0: // sl@0: { sl@0: test(aOriginal.Length()==aControl.Length()); sl@0: for (TInt offset=0;offset sl@0: void TestCPlainText::CheckContent(CPlainText* aDocument,TPtrC& aControl) sl@0: // sl@0: // Check that document content is what you expect sl@0: // sl@0: { sl@0: test(aDocument->DocumentLength()==aControl.Length()); sl@0: TPtrC view(iDummy); sl@0: for (TInt offset=0;offsetDocumentLength();offset++) sl@0: { sl@0: view.Set(aDocument->Read(offset).Ptr(),aDocument->Read(offset).Length()); sl@0: test(*view.Ptr()==aControl[offset]); sl@0: } sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CheckParagraphStart(TInt aCalculated,TInt aExpected) sl@0: // sl@0: // Checks the value returned from ParagraphStart(aPos) is what sl@0: // it is expected to be. sl@0: // sl@0: { sl@0: test(aCalculated==aExpected); sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CheckCharsSkipped(TInt aCalculated,TInt aExpected) sl@0: // sl@0: // Check the number of characters skipped following a ParagraphStart() sl@0: // is as expected. sl@0: // sl@0: { sl@0: test(aCalculated==aExpected); sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::InsertL(TInt aPos,const TDesC& aBuf) sl@0: // sl@0: {CPlainText::InsertL(aPos,aBuf);} sl@0: sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::DoParagraphStart(TInt aStartPos,TInt aLength,CPlainText* aDocument) sl@0: // sl@0: // Parametric testing of the ParagraphStart method of the sl@0: // document class hierarchy. sl@0: // sl@0: { sl@0: TInt tempPos=0; sl@0: TInt charsSkipped=0; sl@0: for (TInt charPos=aStartPos;charPosToParagraphStart(charPos); sl@0: // charPos is updated to paragraph start character position. sl@0: CheckParagraphStart(charPos,aStartPos); sl@0: charPos=tempPos; // Reset charPos following it's update. sl@0: CheckCharsSkipped(charsSkipped,charPos-aStartPos); sl@0: } sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest0L() sl@0: // sl@0: // Tests that all published methods exist. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: CPlainText* doc=CPlainText::NewL(D); sl@0: doc->DocumentLength(); sl@0: doc->InsertL(0,iDefaultDoc); sl@0: TChar character('X'); sl@0: doc->InsertL(0,character); sl@0: TInt pos=3; sl@0: doc->ToParagraphStart(pos); sl@0: doc->DeleteL(3,1); sl@0: doc->Read(2); sl@0: doc->Read(2,2); sl@0: TBuf<128> buf; sl@0: doc->Extract(buf); sl@0: TInt startPos,length; sl@0: doc->GetWordInfo(13,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: doc->WordCount(); sl@0: doc->ParagraphCount(); sl@0: doc->Reset(); sl@0: delete doc; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest1L() sl@0: // sl@0: // PlainText document construction. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: test(iByteStore!=NULL); sl@0: CheckDocLength(0); sl@0: sl@0: INFO_PRINTF1(_L("NewL()")); sl@0: CPlainText* document=CPlainText::NewL(D); sl@0: document->InsertL(0,iDefaultDoc); sl@0: test(document->DocumentLength()==95); sl@0: delete document; sl@0: #ifdef _DEBUG sl@0: INFO_PRINTF1(_L("NewL() failing on OOM")); sl@0: TInt flag=0; sl@0: __UHEAP_FAILNEXT(1); sl@0: TRAPD(ret, (void)CPlainText::NewL(D)); sl@0: if (ret!=KErrNone) sl@0: { sl@0: flag++; sl@0: } sl@0: // seems __UHEAP_FAILNEXT does not work well in platsim. sl@0: // below test does not pass in platsim. sl@0: // test(flag!=0); sl@0: #endif sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest2L() sl@0: // sl@0: // Tests the Read method. sl@0: // Does alter the state of the object. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: CPlainText* document=CPlainText::NewL(D); sl@0: document->InsertL(0,iDefaultDoc); sl@0: sl@0: INFO_PRINTF1(_L("sense from start")); sl@0: /*TPtrC dummy=*/document->Read(0); sl@0: CheckDocLength(document,95); sl@0: CheckContent(document,iComp1); sl@0: sl@0: INFO_PRINTF1(_L("sense from n")); sl@0: TPtrC dummy2=document->Read(45); sl@0: //iDummy.Set(document->Read(45).Ptr(),document->Read(45).Length()); sl@0: CPlainText* doc2=CPlainText::NewL(D); sl@0: doc2->InsertL(0,dummy2); sl@0: doc2->DeleteL(50,1); // We need a debug copy constructor here. The origianl sl@0: // document has an oed character, and when we construct a new doucment sl@0: // based on the original, we get our own eod character plus the one that is sl@0: // part of the original, = 2 eod characters. sl@0: // This breaks the following tests. So in the short term I have elected to delete this sl@0: // trailing, unwanted eod character. sl@0: CheckDocLength(doc2,50); sl@0: CheckContent(doc2,iComp2); sl@0: delete doc2; sl@0: sl@0: INFO_PRINTF1(_L("sense from last-1")); sl@0: iDummy.Set(document->Read(93).Ptr(),document->Read(93).Length()); sl@0: CPlainText* doc3=CPlainText::NewL(D); sl@0: doc3->InsertL(0,iDummy); sl@0: doc3->DeleteL(2,1); sl@0: CheckDocLength(doc3,2); sl@0: CheckContent(doc3,iComp3); sl@0: delete doc3; sl@0: sl@0: INFO_PRINTF1(_L("sense from last")); sl@0: iDummy.Set(document->Read(94).Ptr(),document->Read(94).Length()); sl@0: CPlainText* doc4=CPlainText::NewL(D); sl@0: doc4->InsertL(0,iDummy); sl@0: doc4->DeleteL(1,1); sl@0: CheckDocLength(doc4,1); sl@0: CheckContent(doc4,iComp4); sl@0: delete doc4; sl@0: sl@0: INFO_PRINTF1(_L("sense from last+1")); sl@0: iDummy.Set(document->Read(95).Ptr(),document->Read(95).Length()); sl@0: CPlainText* doc5=CPlainText::NewL(D); sl@0: doc5->InsertL(0,iDummy); sl@0: doc5->DeleteL(0,1); sl@0: CheckDocLength(doc5,0); sl@0: CheckContent(doc5,iComp5); sl@0: delete doc5; sl@0: sl@0: delete document; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest3L() sl@0: // sl@0: // Tests correct execution of insert and delete sl@0: // on default document content. The document sl@0: // content should be left unchanged. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: // Create document with 'AAAAAAAAAA' sl@0: TChar character('Y'); sl@0: CPlainText* document=CPlainText::NewL(D); sl@0: document->InsertL(0,iInBuf); sl@0: iOutBuf.Set(document->Read(0)); sl@0: CheckDocLength(document,10); sl@0: CheckContent(document,iOutBufComp); sl@0: sl@0: INFO_PRINTF1(_L("Inverting at start")); sl@0: document->InsertL(0,iInBuf2); sl@0: document->InsertL(0,character); sl@0: document->DeleteL(0,1); sl@0: CheckDocLength(document,14); sl@0: document->DeleteL(0,4); sl@0: iOutBuf2.Set(document->Read(0)); sl@0: CheckDocLength(document,10); sl@0: CheckContent(document,iOutBufComp); sl@0: sl@0: INFO_PRINTF1(_L("Inverting in middle")); sl@0: document->InsertL(4,iInBuf2); sl@0: document->InsertL(5,character); sl@0: document->DeleteL(5,1); sl@0: CheckDocLength(document,14); sl@0: document->DeleteL(4,4); sl@0: iOutBuf2.Set(document->Read(0)); sl@0: CheckDocLength(document,10); sl@0: CheckContent(document,iOutBufComp); sl@0: sl@0: INFO_PRINTF1(_L("Inverting at end")); sl@0: document->InsertL(10,iInBuf2); sl@0: document->InsertL(11,character); sl@0: document->DeleteL(11,1); sl@0: CheckDocLength(document,14); sl@0: document->DeleteL(10,4); sl@0: iOutBuf2.Set(document->Read(0)); sl@0: CheckDocLength(document,10); sl@0: CheckContent(document,iOutBufComp); sl@0: sl@0: document->DeleteL(0,10); sl@0: CheckDocLength(0); sl@0: delete document; sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest4L() sl@0: // sl@0: // Test scan method combinations sl@0: // sl@0: { sl@0: // Create document content for test. sl@0: TBuf<128> content; sl@0: content.Append(_L("Paragraph one. Complete with sentence and word breaks.")); sl@0: content.Append(EParagraphDelimiter); sl@0: // Para 1 is 55 characters incl. delimiter. sl@0: content.Append(_L("This is paragraph two.")); sl@0: content.Append(EParagraphDelimiter); sl@0: // Para 2 is 23 characters incl. delimiter. sl@0: content.Append(_L("This is paragraph 3")); sl@0: content.Append(EParagraphDelimiter); sl@0: // Para 3 is 20 characters incl. delimiter. sl@0: content.Append(EParagraphDelimiter); sl@0: // Para 4 is 1 character incl. delimiter. sl@0: content.Append(EParagraphDelimiter); sl@0: content.Append(EParagraphDelimiter); sl@0: // Create document. sl@0: CPlainText* document=CPlainText::NewL(D); sl@0: TPtrC body(content); sl@0: document->InsertL(0,body); sl@0: // Now do the tests. sl@0: INFO_PRINTF1(_L("Paragraph 1")); sl@0: DoParagraphStart(0,55,document); // Paragraph 1 sl@0: INFO_PRINTF1(_L("Paragraph 2")); sl@0: DoParagraphStart(55,23,document); // Paragraph 2 sl@0: INFO_PRINTF1(_L("Paragraph 3")); sl@0: DoParagraphStart(78,20,document); // Paragraph 3 sl@0: INFO_PRINTF1(_L("Paragraph 4->2 consecutive delimiters, posshould not change")); sl@0: DoParagraphStart(99,1,document); // Paragraph 6 sl@0: sl@0: delete document; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest5L() sl@0: // sl@0: // Tests the extract method. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: CPlainText* doc=CPlainText::NewL(D); sl@0: doc->InsertL(0,iDefaultDoc); sl@0: sl@0: INFO_PRINTF1(_L("Extract(buf)")); sl@0: TBuf<128> buf; sl@0: doc->Extract(buf); sl@0: CheckContent(iDefaultDoc,buf); sl@0: sl@0: INFO_PRINTF1(_L("Extract(buf,pos)")); sl@0: TInt pos=45; sl@0: doc->Extract(buf,pos); sl@0: CheckContent(iComp2,buf); sl@0: sl@0: INFO_PRINTF1(_L("Extract(buf) from multiple segments")); sl@0: TBuf<256> bigBuf(_L("abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ")); sl@0: CPlainText* segDoc=CPlainText::NewL(ESegmentedStorage); sl@0: segDoc->InsertL(0,bigBuf); sl@0: segDoc->Extract(buf); sl@0: CheckContent(bigBuf,buf); sl@0: delete segDoc; sl@0: sl@0: delete doc; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest5aL() sl@0: // sl@0: // Tests the WordInfo() method. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: TPtrC content(_L(" some testing a texty content")); sl@0: sl@0: CPlainText* doc=CPlainText::NewL(D); sl@0: doc->InsertL(0,content); sl@0: sl@0: INFO_PRINTF1(_L("WordInfo()")); sl@0: TInt currentPos,startPos,length; sl@0: currentPos=0; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==0); test(length==0); sl@0: currentPos=1; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==1); test(length==0); sl@0: currentPos=2; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==2); test(length==0); sl@0: sl@0: currentPos=3; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==3); test(length==4); sl@0: sl@0: currentPos=5; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==3); test(length==4); sl@0: sl@0: currentPos=7; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==3); test(length==4); sl@0: sl@0: currentPos=8; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==8); test(length==0); sl@0: sl@0: currentPos=9; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==9); test(length==0); sl@0: sl@0: currentPos=10; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==10); test(length==7); sl@0: sl@0: currentPos=18; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==18); test(length==0); sl@0: sl@0: currentPos=19; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==19); test(length==1); sl@0: sl@0: currentPos=20; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==19); test(length==1); sl@0: sl@0: currentPos=21; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos==21); test(length==0); sl@0: sl@0: currentPos=38; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos=32); test(length==7); sl@0: sl@0: currentPos=39; sl@0: doc->GetWordInfo(currentPos,startPos,length,KPictureIsDelimiter,KPunctuationIsDelimiter); sl@0: test(startPos=32); test(length==7); sl@0: sl@0: delete doc; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest5bL() sl@0: // sl@0: // Tests the CharPosOfParagraph() method. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: TPtrC para1(_L("para1")); sl@0: TPtrC para2(_L("para22")); sl@0: TPtrC para3(_L("para333")); sl@0: TPtrC para4(_L("para4444")); sl@0: CPlainText* doc=CPlainText::NewL(D); sl@0: doc->InsertL(0,para1); sl@0: TChar delim(EParagraphDelimiter); sl@0: doc->InsertL(5,delim); sl@0: doc->InsertL(6,para2); sl@0: doc->InsertL(12,delim); sl@0: doc->InsertL(13,para3); sl@0: doc->InsertL(20,delim); sl@0: doc->InsertL(21,para4); sl@0: // sl@0: TInt paraN=0; sl@0: // sl@0: DoCharPosOfParagraph(doc,paraN,0,6); sl@0: paraN++; sl@0: DoCharPosOfParagraph(doc,paraN,6,7); sl@0: paraN++; sl@0: DoCharPosOfParagraph(doc,paraN,13,8); sl@0: paraN++; sl@0: DoCharPosOfParagraph(doc,paraN,21,9); sl@0: paraN++; sl@0: DoCharPosOfParagraph(doc,paraN,CPlainText::EScanEndOfData,-1); sl@0: // sl@0: doc->InsertL(0,delim); sl@0: doc->InsertL(0,delim); sl@0: paraN=0; sl@0: DoCharPosOfParagraph(doc,paraN,0,1); sl@0: doc->InsertL(doc->DocumentLength(),delim); sl@0: // There are now 6 paras. sl@0: TInt paraCount=doc->ParagraphCount(); sl@0: test(paraCount==7); sl@0: paraN=5; sl@0: DoCharPosOfParagraph(doc,paraN,23,9); sl@0: paraN++; sl@0: DoCharPosOfParagraph(doc,paraN,32,1); sl@0: delete doc; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::DoCharPosOfParagraph(CPlainText* aText,TInt aParaN,TInt aPosCheck,TInt aLengthCheck) sl@0: // sl@0: // sl@0: // sl@0: { sl@0: TInt length=0; sl@0: TInt pos=-1; sl@0: pos=aText->CharPosOfParagraph(length,aParaN); sl@0: test(pos==aPosCheck); sl@0: if (aLengthCheck!=-1) sl@0: test(length==aLengthCheck); sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest5cL() sl@0: // sl@0: // Tests the ParagraphNumberForPos() method. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: TPtrC para1(_L("para1")); sl@0: TPtrC para2(_L("para22")); sl@0: TPtrC para3(_L("para333")); sl@0: TPtrC para4(_L("para4444")); sl@0: CPlainText* doc=CPlainText::NewL(D); sl@0: doc->InsertL(0,para1); sl@0: TChar delim(EParagraphDelimiter); sl@0: doc->InsertL(5,delim); sl@0: doc->InsertL(6,para2); sl@0: doc->InsertL(12,delim); sl@0: doc->InsertL(13,para3); sl@0: doc->InsertL(20,delim); sl@0: doc->InsertL(21,para4); sl@0: // sl@0: TInt pos=0; sl@0: // sl@0: for (;pos<6;pos++) sl@0: DoParagraphNumberForPos(doc,pos,0,0); sl@0: for (pos=6;pos<13;pos++) sl@0: DoParagraphNumberForPos(doc,pos,1,6); sl@0: for (pos=13;pos<21;pos++) sl@0: DoParagraphNumberForPos(doc,pos,2,13); sl@0: for (pos=21;pos<30;pos++) sl@0: DoParagraphNumberForPos(doc,pos,3,21); sl@0: // sl@0: doc->InsertL(0,delim); sl@0: doc->InsertL(0,delim); sl@0: pos=0; sl@0: DoParagraphNumberForPos(doc,pos,0,0); sl@0: pos=1; sl@0: DoParagraphNumberForPos(doc,pos,1,1); sl@0: doc->InsertL(doc->DocumentLength(),delim); sl@0: // There are now 7 paras. sl@0: TInt paraCount=doc->ParagraphCount(); sl@0: test(paraCount==7); sl@0: pos=32; sl@0: DoParagraphNumberForPos(doc,pos,6,32); sl@0: delete doc; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::DoParagraphNumberForPos(CPlainText* aText,TInt aPos,TInt aParaCheck,TInt aPosCheck) sl@0: // sl@0: // sl@0: // sl@0: { sl@0: TInt para=-1; sl@0: para=aText->ParagraphNumberForPos(aPos); sl@0: test(para==aParaCheck); sl@0: test(aPos==aPosCheck); sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest6L() sl@0: // sl@0: // Tests the word count method. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: CPlainText* doc=CPlainText::NewL(D); sl@0: TInt count=doc->WordCount(); sl@0: test(count==0); sl@0: sl@0: TPtrC buf(_L("This has four words")); sl@0: doc->InsertL(0,buf); sl@0: count=doc->WordCount(); sl@0: test(count==4); sl@0: delete doc; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest7L() sl@0: // sl@0: // Tests the paragraph count method. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: CPlainText* doc=CPlainText::NewL(D); sl@0: TPtrC buf(_L("This has four words")); sl@0: doc->InsertL(0,buf); sl@0: TInt count=doc->ParagraphCount(); sl@0: test(count==1); sl@0: delete doc; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::CPlainTest8L() sl@0: // sl@0: // Tests the reset method behave as specified. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("1st Reset")); sl@0: CPlainText* doc=CPlainText::NewL(D); sl@0: doc->InsertL(0,iDefaultDoc); sl@0: test(doc->DocumentLength()==95); sl@0: doc->Reset(); sl@0: test(doc->DocumentLength()==0); sl@0: sl@0: // Test multiple resets work. sl@0: // This defect was highlighted by DavidW 13.10.95. sl@0: // It arises because I have added an assert length>0 in the delete method. sl@0: // Clearly on a second reset the length is zero, hence the failure. sl@0: // Defect fixed 13.10.95 by DuncanS and included in the tests below. sl@0: INFO_PRINTF1(_L("2nd Reset - defect - DavidW 13.10.95")); sl@0: doc->Reset(); sl@0: sl@0: delete doc; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-ETEXT-UT-1574 sl@0: @SYMTestCaseDesc Tests for the removal of inline text when inline text removal flag is set. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Inserts some inline text into a section of text, tests to make sure it was inserts sl@0: then it removes the inline text and tests to make sure it was all removed correctly. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF INC070807 sl@0: */ sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::INC070807L() sl@0: // sl@0: // Tests whether inline text is removed when the EExcludeInlineEditedText flag is set. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: TInt textLengthFifty = 50; sl@0: TInt textLengthTen = 10; sl@0: TInt startingPositionZero = 0; sl@0: TInt startingPositionTen = 10; sl@0: TInt NumberDeleted, NumberInserted, PositionOfInsertion, NewPositionOfInsertion = 0; sl@0: TBool HasChangedFormat = NULL; sl@0: TInt NumberToHide = 0; sl@0: MFepInlineTextFormatRetriever* InlineTextFormatRetriever = NULL; sl@0: TBufC<20> InitialInlineText =_L("INLINE_TEXT"); // inline text to be inserted sl@0: TBuf<50> outputBuf; sl@0: sl@0: INFO_PRINTF1(_L("Return all the text")); sl@0: CPlainText* doc=CPlainText::NewL(D); sl@0: doc->DocumentLength(); sl@0: doc->InsertL(0,iInsertBuf); // insert "abcdefghijklmnopqrstuvwxyz" sl@0: sl@0: sl@0: TInt PosOfInlineText = 6; sl@0: sl@0: doc->StartFepInlineEditL(HasChangedFormat,NumberDeleted,NumberInserted,PositionOfInsertion,NewPositionOfInsertion,InitialInlineText,PosOfInlineText,NumberToHide,*InlineTextFormatRetriever); sl@0: sl@0: doc->Extract(outputBuf, startingPositionZero, textLengthFifty); // Returns all the text sl@0: test (iTestBuf1 == outputBuf); // testing outputBuf, making sure it contains the inline text - "abcdefINLINE_TEXTghijklmnopqrstuvwxyz" sl@0: sl@0: INFO_PRINTF1(_L("Extract and discard only the inline text, from Pos0 returning the rest")); sl@0: doc->ExtractSelectively(outputBuf, startingPositionZero, textLengthFifty, EExcludeInlineEditedText); // Returns only non-inline text sl@0: test (iInsertBuf == outputBuf); // testing outputBuf, making sure the inline text has been extracted correctly - "abcdefghijklmnopqrstuvwxyz" sl@0: delete doc; sl@0: sl@0: sl@0: CPlainText* doc2=CPlainText::NewL(D); sl@0: doc2->DocumentLength(); sl@0: doc2->InsertL(0,iInsertBuf); // insert "abcdefghijklmnopqrstuvwxyz" sl@0: sl@0: INFO_PRINTF1(_L("Extract upto 50 character, from Pos10, within the range (no inline editting set)")); sl@0: // Returns upto 50 characters starting from Pos10 sl@0: doc2->ExtractSelectively(outputBuf, startingPositionTen, textLengthFifty, EExcludeInlineEditedText); sl@0: test (iTestBuf2 == outputBuf); // "klmnopqrstuvwxyz" sl@0: sl@0: INFO_PRINTF1(_L("Extract upto 10 characters, from Pos10, within the range (no inline editting set)")); sl@0: // Returns upto 10 characters starting from Pos10 sl@0: doc2->ExtractSelectively(outputBuf, startingPositionTen, textLengthTen, EExcludeInlineEditedText); sl@0: test (iTestBuf2a == outputBuf); // "klmnopqrst" sl@0: sl@0: INFO_PRINTF1(_L("Extract upto 50 character, from Pos0, 'EExtractAll' flag selected")); sl@0: // Returns upto 50 characters starting from Pos0. sl@0: doc2->ExtractSelectively(outputBuf, startingPositionZero, textLengthFifty, EExtractAll); sl@0: test (iInsertBuf == outputBuf); // "abcdefghijklmnopqrstuvwxyz" sl@0: delete doc2; sl@0: sl@0: sl@0: CPlainText* doc3=CPlainText::NewL(D); sl@0: doc3->DocumentLength(); sl@0: doc3->InsertL(0,iInsertBuf); // insert "abcdefghijklmnopqrstuvwxyz" sl@0: sl@0: PosOfInlineText = 4; sl@0: sl@0: doc3->StartFepInlineEditL(HasChangedFormat,NumberDeleted,NumberInserted,PositionOfInsertion,NewPositionOfInsertion,InitialInlineText,PosOfInlineText,NumberToHide,*InlineTextFormatRetriever); sl@0: sl@0: INFO_PRINTF1(_L("Extract all the non-inline text, from Pos10, within the range (inline editting on)")); sl@0: doc3->ExtractSelectively(outputBuf, startingPositionTen, textLengthTen, EExcludeInlineEditedText); // Returns only non-inline text. sl@0: test (iTestBuf3 == outputBuf); // testing outputBuf, making sure the inline text has been extracted correctly - "efghi". sl@0: delete doc3; sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::TestSegmentedL() sl@0: // sl@0: // Controls testing of the segmented storage case. sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("All methods")); sl@0: CPlainTest0L(); sl@0: INFO_PRINTF1(_L("Construction")); sl@0: CPlainTest1L(); sl@0: INFO_PRINTF1(_L("Read")); sl@0: INFO_PRINTF1(_L("Not yet implemented")); sl@0: sl@0: INFO_PRINTF1(_L("Inverse Testing using InsertL&Delete: content left intact")); sl@0: CPlainTest3L(); sl@0: INFO_PRINTF1(_L("Paragraph Start")); sl@0: CPlainTest4L(); sl@0: INFO_PRINTF1(_L("Extract")); sl@0: CPlainTest5L(); sl@0: INFO_PRINTF1(_L("WordInfo")); sl@0: CPlainTest5aL(); sl@0: INFO_PRINTF1(_L("CharPosOfParagraph")); sl@0: CPlainTest5bL(); sl@0: INFO_PRINTF1(_L("ParagraphNumberForPos")); sl@0: CPlainTest5cL(); sl@0: INFO_PRINTF1(_L("CountWords")); sl@0: CPlainTest6L(); sl@0: INFO_PRINTF1(_L("CountParas")); sl@0: CPlainTest7L(); sl@0: INFO_PRINTF1(_L("Reset")); sl@0: CPlainTest8L(); sl@0: } sl@0: sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::TestL() sl@0: // sl@0: // Test the CPlainText methods sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("All methods")); sl@0: CPlainTest0L(); sl@0: INFO_PRINTF1(_L("Construction")); sl@0: CPlainTest1L(); sl@0: INFO_PRINTF1(_L("Read")); sl@0: CPlainTest2L(); sl@0: INFO_PRINTF1(_L("Inverse Testing using InsertL&Delete: content left intact")); sl@0: CPlainTest3L(); sl@0: INFO_PRINTF1(_L("Paragraph Start")); sl@0: CPlainTest4L(); sl@0: INFO_PRINTF1(_L("Extract")); sl@0: CPlainTest5L(); sl@0: INFO_PRINTF1(_L("WordInfo")); sl@0: CPlainTest5aL(); sl@0: INFO_PRINTF1(_L("CharPosOfParagraph")); sl@0: CPlainTest5bL(); sl@0: INFO_PRINTF1(_L("ParagraphNumberForPos")); sl@0: CPlainTest5cL(); sl@0: INFO_PRINTF1(_L("CountWords")); sl@0: CPlainTest6L(); sl@0: INFO_PRINTF1(_L("CountParas")); sl@0: CPlainTest7L(); sl@0: INFO_PRINTF1(_L("Reset")); sl@0: CPlainTest8L(); sl@0: } sl@0: sl@0: sl@0: sl@0: template sl@0: void TestCPlainText::DefectsL() sl@0: // sl@0: // Defect Fixes sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-UT-1574 INC070807 ")); sl@0: INC070807L(); sl@0: } sl@0: sl@0: CT_CPLAIN::CT_CPLAIN() sl@0: { sl@0: SetTestStepName(KTestStep_T_CPLAIN); sl@0: pTestStep = this; sl@0: } sl@0: sl@0: TVerdict CT_CPLAIN::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: typedef TestCPlainText instance1; sl@0: typedef TestCPlainText instance2; sl@0: typedef TestCPlainText instance3; sl@0: sl@0: instance1* doctest=NULL; sl@0: sl@0: TRAPD(ret1, doctest=instance1::NewL()); sl@0: sl@0: INFO_PRINTF1(_L("CPlainText - Flat")); sl@0: TRAPD(ret2, doctest->TestL()); sl@0: delete doctest; sl@0: sl@0: INFO_PRINTF1(_L("CPlainText - Segmented")); sl@0: instance2* doctest1=NULL; sl@0: TRAPD(ret3, doctest1=instance2::NewL()); sl@0: TRAPD(ret4, doctest1->TestSegmentedL()); sl@0: delete doctest1; sl@0: sl@0: INFO_PRINTF1(_L("Defect...")); sl@0: instance3* doctest2=NULL; sl@0: TRAPD(ret5, doctest2=instance3::NewL()); sl@0: TRAPD(ret6, doctest2->DefectsL()); sl@0: delete doctest2; sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: delete cleanup; sl@0: sl@0: if (ret1 == KErrNone && ret2 == KErrNone && ret3 == KErrNone && ret4 == KErrNone && ret5 == KErrNone && ret6 == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: }