diff options
Diffstat (limited to 'sw/qa/extras/uiwriter/uiwriter.cxx')
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 230 |
1 files changed, 227 insertions, 3 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 8f6606eb83f5..d01f6260c8fe 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -129,6 +129,9 @@ #include <iodetect.hxx> #include <wrthtml.hxx> #include <dbmgr.hxx> +#include <swdtflvr.hxx> +#include <sortedobjs.hxx> +#include <txtfrm.hxx> namespace { @@ -590,7 +593,7 @@ public: CPPUNIT_TEST(testTdf59666); CPPUNIT_TEST_SUITE_END(); -private: +protected: SwDoc* createDoc(const char* pName = nullptr); std::unique_ptr<SwTextBlocks> readDOCXAutotext(const OUString& sFileName, bool bEmpty = false); }; @@ -4147,11 +4150,213 @@ static void lcl_dispatchCommand(const uno::Reference<lang::XComponent>& xCompone xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf149548) +{ + SwDoc* pDoc = createDoc("forum-mso-en-13192-min.docx"); + + for (SwRangeRedline const*const pRedline : pDoc->getIDocumentRedlineAccess().GetRedlineTable()) + { + if (pRedline->GetType() == RedlineType::Delete) + { + int nLevel(0); + for (SwNodeIndex index = pRedline->Start()->nNode; index <= pRedline->End()->nNode; ++index) + { + switch (index.GetNode().GetNodeType()) + { + case SwNodeType::Start: + case SwNodeType::Table: + case SwNodeType::Section: + ++nLevel; + break; + case SwNodeType::End: + CPPUNIT_ASSERT_MESSAGE("bad overlapping redline", nLevel != 0); + --nLevel; + break; + default: + break; + } + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("bad overlapping redline", int(0), nLevel); + } + } + + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + lcl_dispatchCommand(mxComponent, ".uno:SelectAll", {}); + + rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell); + pTransfer->Copy(); + + TransferableDataHelper aHelper(pTransfer.get()); + // this was a use-after-free on nodes deleted by Copy + SwTransferable::Paste(*pWrtShell, aHelper); +} + +CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf149595) +{ + SwDoc* pDoc = createDoc("demo91.fodt"); + + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + // all 4 shapes are on the 2nd paragraph + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs() == nullptr); + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs() != nullptr); + CPPUNIT_ASSERT_EQUAL(size_t(4), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs()->size()); + + { + pWrtShell->Down(false); + pWrtShell->EndPara(/*bSelect=*/true); + rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell); + pTransfer->Cut(); + + // one shape is anchored in the middle, others at the start/end/at-para + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs() == nullptr); + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs() != nullptr); + CPPUNIT_ASSERT_EQUAL(size_t(3), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs()->size()); + + pWrtShell->Up(false); + TransferableDataHelper aHelper(pTransfer.get()); + SwTransferable::Paste(*pWrtShell, aHelper); + + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs() != nullptr); + CPPUNIT_ASSERT_EQUAL(size_t(1), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs()->size()); + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs() != nullptr); + CPPUNIT_ASSERT_EQUAL(size_t(3), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs()->size()); + + pWrtShell->Undo(); + pWrtShell->Undo(); + + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs() == nullptr); + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs() != nullptr); + CPPUNIT_ASSERT_EQUAL(size_t(4), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs()->size()); + } + + // now try the same with redlining enabled - should be the same result + lcl_dispatchCommand(mxComponent, ".uno:ShowTrackedChanges", {}); + lcl_dispatchCommand(mxComponent, ".uno:TrackChanges", {}); + { + pWrtShell->Down(false); + pWrtShell->SttPara(/*bSelect=*/false); + pWrtShell->EndPara(/*bSelect=*/true); + rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell); + pTransfer->Cut(); + + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs() == nullptr); + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs() != nullptr); + // problem was that this deleted all at-char flys, even at the start/end + CPPUNIT_ASSERT_EQUAL(size_t(3), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs()->size()); + + pWrtShell->Up(false); + TransferableDataHelper aHelper(pTransfer.get()); + SwTransferable::Paste(*pWrtShell, aHelper); + + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs() != nullptr); + CPPUNIT_ASSERT_EQUAL(size_t(1), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs()->size()); + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs() != nullptr); + CPPUNIT_ASSERT_EQUAL(size_t(3), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs()->size()); + + pWrtShell->Undo(); + pWrtShell->Undo(); + + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs() == nullptr); + CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs() != nullptr); + CPPUNIT_ASSERT_EQUAL(size_t(4), pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetNext()->GetDrawObjs()->size()); + } +} + +CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf147220) +{ + SwDoc* pDoc = createDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + pWrtShell->Insert(u"él"); + + // hide and enable + lcl_dispatchCommand(mxComponent, ".uno:ShowTrackedChanges", {}); + lcl_dispatchCommand(mxComponent, ".uno:TrackChanges", {}); + CPPUNIT_ASSERT(pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + CPPUNIT_ASSERT( + IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines()); + + pWrtShell->GoStartSentence(); + pWrtShell->SetMark(); + pWrtShell->GoEndSentence(); + + // this did not remove the original text from the layout + pWrtShell->Replace(u"Él", false); + + // currently the deleted text is before the replacement text, not sure if + // that is really required + CPPUNIT_ASSERT_EQUAL(OUString(u"élÉl"), + pWrtShell->GetCursor()->GetPoint()->nNode.GetNode().GetTextNode()->GetText()); + CPPUNIT_ASSERT_EQUAL(OUString(u"Él"), + static_cast<SwTextFrame const*>(pWrtShell->GetCursor()->GetPoint()->nNode.GetNode().GetTextNode()->getLayoutFrame(nullptr))->GetText()); + + SwRedlineTable const& rRedlines(pDoc->getIDocumentRedlineAccess().GetRedlineTable()); + CPPUNIT_ASSERT_EQUAL(SwRedlineTable::size_type(2), rRedlines.size()); + CPPUNIT_ASSERT_EQUAL(RedlineType::Delete, rRedlines[0]->GetType()); + CPPUNIT_ASSERT_EQUAL(OUString(u"él"), rRedlines[0]->GetText()); + CPPUNIT_ASSERT_EQUAL(RedlineType::Insert, rRedlines[1]->GetType()); + CPPUNIT_ASSERT_EQUAL(OUString(u"Él"), rRedlines[1]->GetText()); +} + +CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf135978) +{ + SwDoc* pDoc = createDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + pWrtShell->Insert("foobar"); + pWrtShell->SplitNode(); + pWrtShell->Insert("bazquux"); + + CPPUNIT_ASSERT(pWrtShell->IsEndOfDoc()); + + SwFormatAnchor anchor(RndStdIds::FLY_AT_CHAR); + anchor.SetAnchor(pWrtShell->GetCursor()->GetPoint()); + SfxItemSet flySet(pDoc->GetAttrPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{}); + flySet.Put(anchor); + SwFlyFrameFormat const* pFly = dynamic_cast<SwFlyFrameFormat const*>( + pWrtShell->NewFlyFrame(flySet, /*bAnchValid=*/true)); + CPPUNIT_ASSERT(pFly != nullptr); + CPPUNIT_ASSERT(pFly->GetFrame() != nullptr); + // move cursor back to body + pWrtShell->SttEndDoc(/*bStt=*/false); + + // hide and enable + lcl_dispatchCommand(mxComponent, ".uno:ShowTrackedChanges", {}); + lcl_dispatchCommand(mxComponent, ".uno:TrackChanges", {}); + + CPPUNIT_ASSERT(pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + CPPUNIT_ASSERT( + IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines()); + + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 4, /*bBasicCall=*/false); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 6, /*bBasicCall=*/false); + pWrtShell->Delete(); + + // now split + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->SplitNode(); + CPPUNIT_ASSERT(pFly->GetFrame() != nullptr); + + // the problem was that undo removed the fly frame from the layout + pWrtShell->Undo(); + CPPUNIT_ASSERT(pFly->GetFrame() != nullptr); + + pWrtShell->Redo(); + CPPUNIT_ASSERT(pFly->GetFrame() != nullptr); + + pWrtShell->Undo(); + CPPUNIT_ASSERT(pFly->GetFrame() != nullptr); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf139843) { load(DATA_DIRECTORY, "tdf139843.odt"); - CPPUNIT_ASSERT_EQUAL(7, getPages()); +// int nPages = getPages(); lcl_dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); @@ -4165,7 +4370,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf139843) lcl_dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); - CPPUNIT_ASSERT_EQUAL(7, getPages()); +//FIXME? CPPUNIT_ASSERT_EQUAL(nPages, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf134252) @@ -7661,6 +7866,25 @@ void SwUiWriterTest::testTdf38394() CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf148868) +{ + SwDoc* pDoc = createDoc("tdf148868.odt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + pWrtShell->EndPg(/*bSelect=*/false); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 5, /*bBasicCall=*/false); + pWrtShell->Insert("X"); + + // Without the fix in place, this test would have failed with + // - Expected: 1 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf134021) { load(DATA_DIRECTORY, "tdf134021.docx"); |