From 95f40ec1cdfe5c9db3e86c1092538dba8a129a72 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Mon, 7 Jun 2021 14:30:10 +0200 Subject: uiwriter: keep CPPUNIT_TEST_FIXTURE tests together Change-Id: I19162c6e6868dc9eb57444f5b33dc2bad299c230 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116783 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sw/qa/extras/uiwriter/uiwriter.cxx | 263 ---------------------------------- sw/qa/extras/uiwriter/uiwriter2.cxx | 274 ++++++++++++++++++++++++++++++++++++ 2 files changed, 274 insertions(+), 263 deletions(-) (limited to 'sw/qa/extras') diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index c47e5402304e..a70cab6cd394 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -1182,116 +1182,6 @@ void SwUiWriterTest::testWatermarkDOCX() CPPUNIT_ASSERT_EQUAL(sal_Int16(50), pWatermark->GetTransparency()); } -CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf134252) -{ - load(DATA_DIRECTORY, "tdf134252.fodt"); - - SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pTextDoc); - - uno::Reference xModel(mxComponent, uno::UNO_QUERY); - uno::Reference xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY); - uno::Reference xCursor(xTextViewCursorSupplier->getViewCursor()); - uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); - uno::Reference xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY); - - // select all with section - dispatchCommand(mxComponent, ".uno:SelectAll", {}); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString("bar" SAL_NEWLINE_STRING "baz" SAL_NEWLINE_STRING), xCursor->getString()); - - dispatchCommand(mxComponent, ".uno:Delete", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString(""), xCursor->getString()); - - // this would crash - dispatchCommand(mxComponent, ".uno:Undo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString("bar" SAL_NEWLINE_STRING "baz" SAL_NEWLINE_STRING), xCursor->getString()); - - dispatchCommand(mxComponent, ".uno:Redo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString(""), xCursor->getString()); - - dispatchCommand(mxComponent, ".uno:Undo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString("bar" SAL_NEWLINE_STRING "baz" SAL_NEWLINE_STRING), xCursor->getString()); - - dispatchCommand(mxComponent, ".uno:Redo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString(""), xCursor->getString()); -} - -CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf136453) -{ - load(DATA_DIRECTORY, "tdf136453.fodt"); - - SwXTextDocument *const pTextDoc(dynamic_cast(mxComponent.get())); - CPPUNIT_ASSERT(pTextDoc); - SwDoc* const pDoc(pTextDoc->GetDocShell()->GetDoc()); - SwWrtShell *const pWrtShell(pDoc->GetDocShell()->GetWrtShell()); - - sal_uLong const nNodes(pDoc->GetNodes().Count()); - - pWrtShell->SttEndDoc(false); - pWrtShell->SetMark(); - pWrtShell->Up(true, 1); - pWrtShell->SttPara(true); - pWrtShell->Delete(); - - // one paragraph deleted, section is gone - CPPUNIT_ASSERT_EQUAL(nNodes - 3, pDoc->GetNodes().Count()); - - pWrtShell->Undo(); - - CPPUNIT_ASSERT_EQUAL(nNodes, pDoc->GetNodes().Count()); - - // check that every node has 1 frame - xmlDocUniquePtr pXmlDoc = parseLayoutDump(); - assertXPath(pXmlDoc, "/root/page[1]/body/txt", 3); - assertXPath(pXmlDoc, "/root/page[1]/body/section", 1); - assertXPath(pXmlDoc, "/root/page[1]/body/section/txt", 1); - - pWrtShell->Redo(); - - // one paragraph deleted, section is gone - CPPUNIT_ASSERT_EQUAL(nNodes - 3, pDoc->GetNodes().Count()); - - discardDumpedLayout(); - pXmlDoc = parseLayoutDump(); - assertXPath(pXmlDoc, "/root/page[1]/body/txt", 3); - assertXPath(pXmlDoc, "/root/page[1]/body/section", 0); - - pWrtShell->Undo(); - - CPPUNIT_ASSERT_EQUAL(nNodes, pDoc->GetNodes().Count()); - - discardDumpedLayout(); - pXmlDoc = parseLayoutDump(); - assertXPath(pXmlDoc, "/root/page[1]/body/txt", 3); - assertXPath(pXmlDoc, "/root/page[1]/body/section", 1); - assertXPath(pXmlDoc, "/root/page[1]/body/section/txt", 1); -} - void SwUiWriterTest::testWatermarkPosition() { // tdf#108494 Watermark inserted in the document with page break was outside the first page @@ -1369,78 +1259,6 @@ void SwUiWriterTest::testWatermarkPosition() } } -CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf134250) -{ - load(DATA_DIRECTORY, "tdf134250.fodt"); - - SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pTextDoc); - - uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xTables(xTextTablesSupplier->getTextTables(), - uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - - uno::Reference xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - - uno::Reference xTextContent(xSections->getByIndex(0), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("foo" SAL_NEWLINE_STRING "bar"), - xTextContent->getAnchor()->getString()); - - // select all with table at start -> 3 times - dispatchCommand(mxComponent, ".uno:SelectAll", {}); - dispatchCommand(mxComponent, ".uno:SelectAll", {}); - dispatchCommand(mxComponent, ".uno:SelectAll", {}); - - // .uno:Copy without touching shared clipboard - SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); - rtl::Reference xTransfer = new SwTransferable(*pWrtShell); - xTransfer->Copy(); - - // .uno:Paste without touching shared clipboard - TransferableDataHelper aHelper(xTransfer); - SwTransferable::Paste(*pWrtShell, aHelper); - - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - - // this would crash in 2 different ways - dispatchCommand(mxComponent, ".uno:Undo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - - // Without the fix in place, section's content would have been gone after undo - CPPUNIT_ASSERT_EQUAL(OUString("foo" SAL_NEWLINE_STRING "bar"), - xTextContent->getAnchor()->getString()); - - dispatchCommand(mxComponent, ".uno:Redo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - - dispatchCommand(mxComponent, ".uno:Undo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString("foo" SAL_NEWLINE_STRING "bar"), - xTextContent->getAnchor()->getString()); - - dispatchCommand(mxComponent, ".uno:Redo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); -} - void SwUiWriterTest::testFdo74981() { // create a document with an input field @@ -5836,87 +5654,6 @@ void SwUiWriterTest::testRedlineCopyPaste() CPPUNIT_ASSERT_EQUAL(OUString("abcdefgh"), pTextNode->GetText()); } -CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf134436) -{ - load(DATA_DIRECTORY, "tdf134436.fodt"); - - SwXTextDocument* pXTextDocument = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pXTextDocument); - SwDoc * pDoc = pXTextDocument->GetDocShell()->GetDoc(); - CPPUNIT_ASSERT(pDoc); - SwWrtShell * pWrtShell = pDoc->GetDocShell()->GetWrtShell(); - CPPUNIT_ASSERT(pWrtShell); - - uno::Reference xModel(mxComponent, uno::UNO_QUERY); - uno::Reference xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY); - uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); - uno::Reference xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY); - - // select all 3 times, table at the start - dispatchCommand(mxComponent, ".uno:SelectAll", {}); - dispatchCommand(mxComponent, ".uno:SelectAll", {}); - dispatchCommand(mxComponent, ".uno:SelectAll", {}); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - // the stupid SwXTextView::getString doesn't work "for symmetry" so use CursorShell - CPPUNIT_ASSERT_EQUAL(OUString("a\nb\n"), pWrtShell->GetCursor()->GetText()); - - // first, the section doesn't get deleted - dispatchCommand(mxComponent, ".uno:Delete", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString(""), pWrtShell->GetCursor()->GetText()); - - dispatchCommand(mxComponent, ".uno:Undo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString("a\nb\n"), pWrtShell->GetCursor()->GetText()); - - // second, the section does get deleted because point is at the end - dispatchCommand(mxComponent, ".uno:Delete", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString(""), pWrtShell->GetCursor()->GetText()); - - dispatchCommand(mxComponent, ".uno:Undo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString("a\nb\n"), pWrtShell->GetCursor()->GetText()); - - // the problem was that the section was not deleted on Redo - dispatchCommand(mxComponent, ".uno:Redo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString(""), pWrtShell->GetCursor()->GetText()); - - dispatchCommand(mxComponent, ".uno:Undo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString("a\nb\n"), pWrtShell->GetCursor()->GetText()); - - dispatchCommand(mxComponent, ".uno:Redo", {}); - Scheduler::ProcessEventsToIdle(); - - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSections->getCount()); - CPPUNIT_ASSERT_EQUAL(OUString(""), pWrtShell->GetCursor()->GetText()); -} - void SwUiWriterTest::testTdf135260() { SwDoc* pDoc = createDoc(); diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index de0c06f5d6bb..c87d0bdd19a9 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -378,6 +379,279 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf136704) getProperty(getParagraph(1), "ParaStyleName")); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf134250) +{ + load(DATA_DIRECTORY, "tdf134250.fodt"); + + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + + uno::Reference xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xSections(xTextSectionsSupplier->getTextSections(), + uno::UNO_QUERY); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + + uno::Reference xTextContent(xSections->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("foo" SAL_NEWLINE_STRING "bar"), + xTextContent->getAnchor()->getString()); + + // select all with table at start -> 3 times + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + + // .uno:Copy without touching shared clipboard + SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + rtl::Reference xTransfer = new SwTransferable(*pWrtShell); + xTransfer->Copy(); + + // .uno:Paste without touching shared clipboard + TransferableDataHelper aHelper(xTransfer); + SwTransferable::Paste(*pWrtShell, aHelper); + + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + + // this would crash in 2 different ways + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + + // Without the fix in place, section's content would have been gone after undo + CPPUNIT_ASSERT_EQUAL(OUString("foo" SAL_NEWLINE_STRING "bar"), + xTextContent->getAnchor()->getString()); + + dispatchCommand(mxComponent, ".uno:Redo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString("foo" SAL_NEWLINE_STRING "bar"), + xTextContent->getAnchor()->getString()); + + dispatchCommand(mxComponent, ".uno:Redo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); +} + +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf134436) +{ + load(DATA_DIRECTORY, "tdf134436.fodt"); + + SwXTextDocument* pXTextDocument = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pXTextDocument); + SwDoc* pDoc = pXTextDocument->GetDocShell()->GetDoc(); + CPPUNIT_ASSERT(pDoc); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + uno::Reference xTextViewCursorSupplier( + xModel->getCurrentController(), uno::UNO_QUERY); + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xSections(xTextSectionsSupplier->getTextSections(), + uno::UNO_QUERY); + + // select all 3 times, table at the start + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + // the stupid SwXTextView::getString doesn't work "for symmetry" so use CursorShell + CPPUNIT_ASSERT_EQUAL(OUString("a\nb\n"), pWrtShell->GetCursor()->GetText()); + + // first, the section doesn't get deleted + dispatchCommand(mxComponent, ".uno:Delete", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString(""), pWrtShell->GetCursor()->GetText()); + + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString("a\nb\n"), pWrtShell->GetCursor()->GetText()); + + // second, the section does get deleted because point is at the end + dispatchCommand(mxComponent, ".uno:Delete", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString(""), pWrtShell->GetCursor()->GetText()); + + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString("a\nb\n"), pWrtShell->GetCursor()->GetText()); + + // the problem was that the section was not deleted on Redo + dispatchCommand(mxComponent, ".uno:Redo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString(""), pWrtShell->GetCursor()->GetText()); + + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString("a\nb\n"), pWrtShell->GetCursor()->GetText()); + + dispatchCommand(mxComponent, ".uno:Redo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString(""), pWrtShell->GetCursor()->GetText()); +} + +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf134252) +{ + load(DATA_DIRECTORY, "tdf134252.fodt"); + + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + uno::Reference xTextViewCursorSupplier( + xModel->getCurrentController(), uno::UNO_QUERY); + uno::Reference xCursor(xTextViewCursorSupplier->getViewCursor()); + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xSections(xTextSectionsSupplier->getTextSections(), + uno::UNO_QUERY); + + // select all with section + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString("bar" SAL_NEWLINE_STRING "baz" SAL_NEWLINE_STRING), + xCursor->getString()); + + dispatchCommand(mxComponent, ".uno:Delete", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString(""), xCursor->getString()); + + // this would crash + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString("bar" SAL_NEWLINE_STRING "baz" SAL_NEWLINE_STRING), + xCursor->getString()); + + dispatchCommand(mxComponent, ".uno:Redo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString(""), xCursor->getString()); + + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString("bar" SAL_NEWLINE_STRING "baz" SAL_NEWLINE_STRING), + xCursor->getString()); + + dispatchCommand(mxComponent, ".uno:Redo", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(OUString(""), xCursor->getString()); +} + +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf136453) +{ + load(DATA_DIRECTORY, "tdf136453.fodt"); + + SwXTextDocument* const pTextDoc(dynamic_cast(mxComponent.get())); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* const pDoc(pTextDoc->GetDocShell()->GetDoc()); + SwWrtShell* const pWrtShell(pDoc->GetDocShell()->GetWrtShell()); + + sal_uLong const nNodes(pDoc->GetNodes().Count()); + + pWrtShell->SttEndDoc(false); + pWrtShell->SetMark(); + pWrtShell->Up(true, 1); + pWrtShell->SttPara(true); + pWrtShell->Delete(); + + // one paragraph deleted, section is gone + CPPUNIT_ASSERT_EQUAL(nNodes - 3, pDoc->GetNodes().Count()); + + pWrtShell->Undo(); + + CPPUNIT_ASSERT_EQUAL(nNodes, pDoc->GetNodes().Count()); + + // check that every node has 1 frame + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + assertXPath(pXmlDoc, "/root/page[1]/body/txt", 3); + assertXPath(pXmlDoc, "/root/page[1]/body/section", 1); + assertXPath(pXmlDoc, "/root/page[1]/body/section/txt", 1); + + pWrtShell->Redo(); + + // one paragraph deleted, section is gone + CPPUNIT_ASSERT_EQUAL(nNodes - 3, pDoc->GetNodes().Count()); + + discardDumpedLayout(); + pXmlDoc = parseLayoutDump(); + assertXPath(pXmlDoc, "/root/page[1]/body/txt", 3); + assertXPath(pXmlDoc, "/root/page[1]/body/section", 0); + + pWrtShell->Undo(); + + CPPUNIT_ASSERT_EQUAL(nNodes, pDoc->GetNodes().Count()); + + discardDumpedLayout(); + pXmlDoc = parseLayoutDump(); + assertXPath(pXmlDoc, "/root/page[1]/body/txt", 3); + assertXPath(pXmlDoc, "/root/page[1]/body/section", 1); + assertXPath(pXmlDoc, "/root/page[1]/body/section/txt", 1); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf137245) { SwDoc* const pDoc(createDoc()); -- cgit v1.2.3