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 sl@0: #include sl@0: #include sl@0: #include "T_LAYDOC.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: sl@0: #define UNUSED_VAR(a) a = a sl@0: sl@0: LOCAL_D TPtrC defaultText(_L("This is default text")); sl@0: LOCAL_D TPtrC comp1(_L("fault text")); sl@0: LOCAL_D TPtrC comp2(_L("t")); sl@0: LOCAL_D TPtrC view(_L("x")); sl@0: sl@0: GLDEF_C void CheckView(TPtrC& aView,TPtrC& aControl) sl@0: // sl@0: // Test that aView matches the contol descriptor in sl@0: // the expected metrics. sl@0: // sl@0: { sl@0: test(aView.Length()==(aControl.Length()+1)); sl@0: TInt index=0; sl@0: for (index=0;indexLdDocumentLength(); sl@0: test(length==0); sl@0: // Insert document content sl@0: doc->InsertL(0,defaultText); sl@0: length=doc->LdDocumentLength(); sl@0: test(length==20); sl@0: sl@0: delete doc; sl@0: delete paraLayer; sl@0: delete charLayer; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: GLDEF_C void TestRead(CEditableText::TDocumentStorage aStorage) sl@0: // sl@0: // Test this class' GetChars method sl@0: // functions as predicted. sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: // Make the global format layers... sl@0: CParaFormatLayer* paraLayer=CParaFormatLayer::NewL(); sl@0: CCharFormatLayer* charLayer=CCharFormatLayer::NewL(); sl@0: sl@0: // Create Document sl@0: CGlobalText* doc=CGlobalText::NewL(paraLayer,charLayer,aStorage); sl@0: TRAPD(ret,doc->InsertL(0,defaultText)); sl@0: UNUSED_VAR(ret); sl@0: sl@0: // Create LayDoc sl@0: TCharFormat format; sl@0: TPtrC view; sl@0: sl@0: INFO_PRINTF1(_L("Sensing at start")); sl@0: doc->GetChars(view,format,0); sl@0: CheckView(view,defaultText); sl@0: sl@0: INFO_PRINTF1(_L("Sensing from char.pos.10")); sl@0: doc->GetChars(view,format,10); sl@0: CheckView(view,comp1); sl@0: sl@0: INFO_PRINTF1(_L("Sensing from end-1")); sl@0: doc->GetChars(view,format,19); sl@0: CheckView(view,comp2); sl@0: sl@0: INFO_PRINTF1(_L("Sensing from end")); sl@0: doc->GetChars(view,format,20); sl@0: test(*view.Ptr()==CEditableText::EParagraphDelimiter); sl@0: sl@0: sl@0: delete doc; sl@0: delete paraLayer; sl@0: delete charLayer; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: GLDEF_C void 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: GLDEF_C void 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: GLDEF_C void DoParagraphStart(TInt aStartPos,TInt aLength,MLayDoc* aLayout) sl@0: // sl@0: // Parametric testing of the ParagraphStart method of the sl@0: // document class hierarchy. sl@0: // sl@0: { sl@0: User::Heap().Check(); sl@0: TInt tempPos=0; sl@0: TInt charsSkipped=0; sl@0: for (TInt charPos=aStartPos;charPosLdToParagraphStart(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: User::Heap().Check(); sl@0: } sl@0: sl@0: sl@0: GLDEF_C void TestParagraphStart(CEditableText::TDocumentStorage aStorage) sl@0: // sl@0: // Tests the ParagraphStart method. sl@0: // sl@0: { sl@0: User::Heap().Check(); sl@0: __UHEAP_MARK; sl@0: // Make the global format layers... sl@0: CParaFormatLayer* paraLayer=CParaFormatLayer::NewL(); sl@0: CCharFormatLayer* charLayer=CCharFormatLayer::NewL(); sl@0: sl@0: TBuf<128> content; sl@0: content.Append(_L("Paragraph one. Complete with sentence and word breaks.")); sl@0: content.Append(CEditableText::EParagraphDelimiter); sl@0: content.Append(_L("This is paragraph two.")); sl@0: content.Append(CEditableText::EParagraphDelimiter); sl@0: content.Append(_L("This is paragraph 3")); sl@0: // Create document. sl@0: CGlobalText* document=CGlobalText::NewL(paraLayer,charLayer,aStorage); 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: sl@0: delete paraLayer; sl@0: delete charLayer; sl@0: delete document; sl@0: sl@0: __UHEAP_MARKEND; sl@0: User::Heap().Check(); sl@0: } sl@0: sl@0: sl@0: GLDEF_C void TestGetParagraphFormatL(CEditableText::TDocumentStorage aStorage) sl@0: // sl@0: // sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: User::Heap().Check(); sl@0: // Make the global format layers... sl@0: CParaFormatLayer* paraLayer=CParaFormatLayer::NewL(); sl@0: CCharFormatLayer* charLayer=CCharFormatLayer::NewL(); sl@0: sl@0: CGlobalText* globalDoc=CGlobalText::NewL(paraLayer,charLayer,aStorage); sl@0: sl@0: CParaFormat* format=CParaFormat::NewL(); sl@0: CParaFormat* control=CParaFormat::NewL(); sl@0: TParaFormatMask cMask; sl@0: control->iLeftMarginInTwips=1440; cMask.SetAttrib(EAttLeftMargin); sl@0: TTabStop tab1; sl@0: tab1.iTwipsPosition=1440; tab1.iType=TTabStop::ERightTab; sl@0: control->StoreTabL(tab1); cMask.SetAttrib(EAttTabStop); sl@0: sl@0: TParaBorder border; sl@0: border.iLineStyle=TParaBorder::ESolid; sl@0: border.iThickness=1; sl@0: control->SetParaBorderL(CParaFormat::EParaBorderTop,border); cMask.SetAttrib(EAttTopBorder); sl@0: control->iKeepTogether=ETrue; cMask.SetAttrib(EAttKeepTogether); sl@0: CParaFormatLayer* layer=CParaFormatLayer::NewL(control,cMask); sl@0: globalDoc->SetGlobalParaFormat(layer); sl@0: sl@0: globalDoc->GetParagraphFormatL(format,0); sl@0: TInt c1=format->TabCount(); sl@0: TInt c2=control->TabCount(); sl@0: test(c1==c2); sl@0: test(format->IsEqual(*control)); sl@0: sl@0: __UHEAP_MARK; sl@0: delete layer; sl@0: delete control; sl@0: delete format; sl@0: __UHEAP_MARKEND; sl@0: delete globalDoc; sl@0: delete charLayer; sl@0: delete paraLayer; sl@0: User::Heap().Check(); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: GLDEF_C void TestRegister(CEditableText::TDocumentStorage aStorage) sl@0: // sl@0: // Checks all declared base class methods have been provided. sl@0: // sl@0: { sl@0: User::Heap().Check(); sl@0: __UHEAP_MARK; sl@0: // Make the global format layers... sl@0: CParaFormatLayer* paraLayer=CParaFormatLayer::NewL(); sl@0: CCharFormatLayer* charLayer=CCharFormatLayer::NewL(); sl@0: sl@0: // Create a para format layer sl@0: CParaFormat* format=CParaFormat::NewL(); sl@0: TParaFormatMask mask; sl@0: mask.SetAttrib(EAttLeftMargin); sl@0: mask.SetAttrib(EAttRightMargin); sl@0: CParaFormatLayer* layer=CParaFormatLayer::NewL(format,mask); sl@0: // Create global text document to layout sl@0: CGlobalText* doc=NULL; sl@0: TRAPD(ret,doc=CGlobalText::NewL(paraLayer,charLayer,aStorage)); sl@0: UNUSED_VAR(ret); sl@0: TInt pos=0; sl@0: doc->SetGlobalParaFormat(layer); sl@0: sl@0: // Check constructor sl@0: INFO_PRINTF1(_L("Constructor")); sl@0: sl@0: // Check DocumentLength sl@0: INFO_PRINTF1(_L("DocumentLength()")); sl@0: doc->LdDocumentLength(); sl@0: sl@0: // Check ParagraphStart sl@0: INFO_PRINTF1(_L("ParagraphStart()")); sl@0: doc->LdToParagraphStart(pos); sl@0: sl@0: // Check GetParagraphFormatL sl@0: INFO_PRINTF1(_L("GetParagraphFormatL()")); sl@0: doc->GetParagraphFormatL(format,pos); sl@0: sl@0: // Check GetChars sl@0: INFO_PRINTF1(_L("GetChars()")); sl@0: TPtrC view; sl@0: TCharFormat charFormat; sl@0: doc->GetChars(view,charFormat,pos); sl@0: sl@0: // check EnquirePage sl@0: INFO_PRINTF1(_L("EnquirePageBreak()")); sl@0: doc->EnquirePageBreak(pos,0); sl@0: sl@0: delete paraLayer; sl@0: delete charLayer; sl@0: delete doc; sl@0: delete layer; sl@0: delete format; sl@0: sl@0: __UHEAP_MARKEND; sl@0: User::Heap().Check(); sl@0: } sl@0: sl@0: GLDEF_C void Test() sl@0: // sl@0: // Run the tests sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("Checking all methods present")); sl@0: TestRegister(CEditableText::EFlatStorage); sl@0: sl@0: INFO_PRINTF1(_L("DocumentLength()")); sl@0: TestDocumentLength(CEditableText::EFlatStorage); sl@0: sl@0: INFO_PRINTF1(_L("EnquirePage()")); sl@0: INFO_PRINTF1(_L("Always returns 0")); sl@0: sl@0: sl@0: INFO_PRINTF1(_L("ParagraphStart()")); sl@0: TestParagraphStart(CEditableText::EFlatStorage); sl@0: sl@0: INFO_PRINTF1(_L("GetParagraphFormatL()")); sl@0: TestGetParagraphFormatL(CEditableText::EFlatStorage); sl@0: sl@0: INFO_PRINTF1(_L("GetChars")); sl@0: TestRead(CEditableText::EFlatStorage); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: GLDEF_C void TestSeg() sl@0: // sl@0: // Run the tests sl@0: // sl@0: { sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("Checking all methods present")); sl@0: TestRegister(CEditableText::ESegmentedStorage); sl@0: sl@0: INFO_PRINTF1(_L("DocumentLength()")); sl@0: TestDocumentLength(CEditableText::ESegmentedStorage); sl@0: sl@0: INFO_PRINTF1(_L("EnquirePage()")); sl@0: INFO_PRINTF1(_L("Always returns 0")); sl@0: sl@0: sl@0: INFO_PRINTF1(_L("ParagraphStart()")); sl@0: TestParagraphStart(CEditableText::ESegmentedStorage); sl@0: sl@0: INFO_PRINTF1(_L("SenseParagraphFormatL()")); sl@0: TestGetParagraphFormatL(CEditableText::ESegmentedStorage); sl@0: sl@0: INFO_PRINTF1(_L("GetChars")); sl@0: //TestRead(); sl@0: // sl@0: INFO_PRINTF1(_L("Test not yet implemented")); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: CT_LAYDOC::CT_LAYDOC() sl@0: { sl@0: SetTestStepName(KTestStep_T_LAYDOC); sl@0: pTestStep = this; sl@0: } sl@0: sl@0: TVerdict CT_LAYDOC::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: sl@0: INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_LAYDOC-0001 MLayDoc - Using Flat document ")); sl@0: sl@0: __UHEAP_MARK; sl@0: TRAPD(ret1,Test()); sl@0: __UHEAP_MARKEND; sl@0: sl@0: INFO_PRINTF1(_L("MLaydoc - Using Segmented document")); sl@0: __UHEAP_MARK; sl@0: TRAPD(ret2,TestSeg()); sl@0: __UHEAP_MARKEND; sl@0: sl@0: delete cleanup; sl@0: sl@0: if (ret1 == KErrNone && ret2 == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: }