/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /// Third set of tests asserting the behavior of Writer user interface shells. class SwUiWriterTest3 : public SwModelTestBase { public: SwUiWriterTest3() : SwModelTestBase("/sw/qa/extras/uiwriter/data/") { } }; CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf145731) { createSwDoc("tdf145731.odt"); CPPUNIT_ASSERT_EQUAL(9, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Cut", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(0, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(9, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf147199) { createSwDoc("tdf147199.docx"); CPPUNIT_ASSERT_EQUAL(7, getShapes()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Cut", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(0, getShapes()); dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(7, getShapes()); dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(14, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(7, getShapes()); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(0, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(7, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf139843) { createSwDoc("tdf139843.odt"); int nPages = getPages(); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Cut", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getPages()); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(nPages, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf146848) { // Reuse existing document createSwDoc("tdf77014.odt"); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Cut", {}); Scheduler::ProcessEventsToIdle(); uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xFieldsAccess( xTextFieldsSupplier->getTextFields()); uno::Reference xFields(xFieldsAccess->createEnumeration()); CPPUNIT_ASSERT(!xFields->hasMoreElements()); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); xFields = xFieldsAccess->createEnumeration(); int nFieldsCount = 0; while (xFields->hasMoreElements()) { xFields->nextElement(); nFieldsCount++; } CPPUNIT_ASSERT_EQUAL(4, nFieldsCount); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf149507) { createSwDoc("tdf149507.docx"); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Cut", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(0, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(0, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf145321) { createSwDoc("tdf145321.odt"); CPPUNIT_ASSERT_EQUAL(3, getShapes()); CPPUNIT_ASSERT_EQUAL(3, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Cut", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(0, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(3, getShapes()); CPPUNIT_ASSERT_EQUAL(3, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testVariableFieldTableRowSplitHeader) { createSwDoc("variable-field-table-row-split-header.fodt"); SwDoc* const pDoc = getSwDoc(); // finish layout Scheduler::ProcessEventsToIdle(); xmlDocUniquePtr pXmlDoc = parseLayoutDump(); // the fields in cell are: variable-get variable-set variable-get assertXPath( pXmlDoc, "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", 3); assertXPath( pXmlDoc, "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "0"); assertXPath( pXmlDoc, "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]", "expand", "1"); assertXPath( pXmlDoc, "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]", "expand", "1"); assertXPath(pXmlDoc, "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "0"); assertXPath(pXmlDoc, "/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "1"); // here the header had shown the wrong value assertXPath( pXmlDoc, "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "1"); assertXPath( pXmlDoc, "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]", "expand", "2"); assertXPath( pXmlDoc, "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]", "expand", "2"); assertXPath(pXmlDoc, "/root/page[2]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "1"); assertXPath(pXmlDoc, "/root/page[2]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "2"); assertXPath( pXmlDoc, "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "2"); assertXPath( pXmlDoc, "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]", "expand", "3"); assertXPath( pXmlDoc, "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]", "expand", "3"); assertXPath(pXmlDoc, "/root/page[3]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "2"); assertXPath(pXmlDoc, "/root/page[3]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "3"); assertXPath( pXmlDoc, "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "3"); assertXPath( pXmlDoc, "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]", "expand", "4"); assertXPath( pXmlDoc, "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]", "expand", "4"); assertXPath(pXmlDoc, "/root/page[4]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "3"); assertXPath(pXmlDoc, "/root/page[4]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "4"); assertXPath(pXmlDoc, "/root/page[5]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "4"); assertXPath(pXmlDoc, "/root/page[5]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "4"); discardDumpedLayout(); // update and check again pDoc->getIDocumentFieldsAccess().UpdateFields(true); Scheduler::ProcessEventsToIdle(); pXmlDoc = parseLayoutDump(); // the fields in cell are: variable-get variable-set variable-get assertXPath( pXmlDoc, "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", 3); assertXPath( pXmlDoc, "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "0"); assertXPath( pXmlDoc, "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]", "expand", "1"); assertXPath( pXmlDoc, "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]", "expand", "1"); assertXPath(pXmlDoc, "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "0"); assertXPath(pXmlDoc, "/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "1"); // here the header had shown the wrong value assertXPath( pXmlDoc, "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "1"); assertXPath( pXmlDoc, "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]", "expand", "2"); assertXPath( pXmlDoc, "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]", "expand", "2"); assertXPath(pXmlDoc, "/root/page[2]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "1"); assertXPath(pXmlDoc, "/root/page[2]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "2"); assertXPath( pXmlDoc, "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "2"); assertXPath( pXmlDoc, "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]", "expand", "3"); assertXPath( pXmlDoc, "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]", "expand", "3"); assertXPath(pXmlDoc, "/root/page[3]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "2"); assertXPath(pXmlDoc, "/root/page[3]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "3"); assertXPath( pXmlDoc, "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "3"); assertXPath( pXmlDoc, "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]", "expand", "4"); assertXPath( pXmlDoc, "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]", "expand", "4"); assertXPath(pXmlDoc, "/root/page[4]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "3"); assertXPath(pXmlDoc, "/root/page[4]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "4"); assertXPath(pXmlDoc, "/root/page[5]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "4"); assertXPath(pXmlDoc, "/root/page[5]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", "4"); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf147126) { createSwDoc("tdf147126.docx"); CPPUNIT_ASSERT(mxComponent); SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); CPPUNIT_ASSERT(pTextDoc); const auto pLayoutXML1 = parseLayoutDump(); for (auto nFly = 1; nFly < 8; ++nFly) { const auto nFlyLeft = getXPath(pLayoutXML1, OString::Concat("/root/page/body/txt[2]/anchored/fly[") + OString::Concat(OString::number(nFly)) + OString::Concat("]/infos/bounds"), "left") .toInt64(); const auto nFlyRight = getXPath(pLayoutXML1, OString::Concat("/root/page/body/txt[2]/anchored/fly[") + OString::Concat(OString::number(nFly)) + OString::Concat("]/infos/bounds"), "width") .toInt64(); const auto nFlyTop = getXPath(pLayoutXML1, OString::Concat("/root/page/body/txt[2]/anchored/fly[") + OString::Concat(OString::number(nFly)) + OString::Concat("]/infos/bounds"), "top") .toInt64(); const auto nFlyBottom = getXPath(pLayoutXML1, OString::Concat("/root/page/body/txt[2]/anchored/fly[") + OString::Concat(OString::number(nFly)) + OString::Concat("]/infos/bounds"), "height") .toInt64(); const auto sDrawRect = getXPath( pLayoutXML1, OString::Concat("/root/page/body/txt[2]/anchored/SwAnchoredDrawObject/SdrObjGroup/" "SdrObjList/SdrObject[") + OString::Concat(OString::number(nFly)) + OString::Concat("]"), "aOutRect"); const auto nComaPos1 = sDrawRect.indexOf(',', 0); const auto nComaPos2 = sDrawRect.indexOf(',', nComaPos1 + 1); const auto nComaPos3 = sDrawRect.indexOf(',', nComaPos2 + 1); const auto nDraw1 = o3tl::toInt64(sDrawRect.subView(0, nComaPos1)); const auto nDraw2 = o3tl::toInt64(sDrawRect.subView(nComaPos1 + 1, nComaPos2 - nComaPos1)); const auto nDraw3 = o3tl::toInt64(sDrawRect.subView(nComaPos2 + 1, nComaPos3 - nComaPos2)); const auto nDraw4 = o3tl::toInt64( sDrawRect.subView(nComaPos3 + 1, sDrawRect.getLength() - nComaPos3 - 1)); CPPUNIT_ASSERT_GREATER(nDraw1, nFlyLeft); CPPUNIT_ASSERT_GREATER(nDraw2, nFlyTop); CPPUNIT_ASSERT_LESS(nDraw3, nFlyRight); CPPUNIT_ASSERT_LESS(nDraw4, nFlyBottom); } for (auto nLineBreakCount = 0; nLineBreakCount < 4; ++nLineBreakCount) { pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN); Scheduler::ProcessEventsToIdle(); } for (auto nSpaceCount = 0; nSpaceCount < 10; ++nSpaceCount) { pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_SPACE); Scheduler::ProcessEventsToIdle(); } dumpLayout(mxComponent); const auto pLayoutXML2 = parseLayoutDump(); for (auto nFly = 1; nFly < 8; ++nFly) { const auto nFlyLeft = getXPath(pLayoutXML2, OString::Concat("/root/page/body/txt[6]/anchored/fly[") + OString::Concat(OString::number(nFly)) + OString::Concat("]/infos/bounds"), "left") .toInt64(); const auto nFlyRight = getXPath(pLayoutXML2, OString::Concat("/root/page/body/txt[6]/anchored/fly[") + OString::Concat(OString::number(nFly)) + OString::Concat("]/infos/bounds"), "width") .toInt64(); const auto nFlyTop = getXPath(pLayoutXML2, OString::Concat("/root/page/body/txt[6]/anchored/fly[") + OString::Concat(OString::number(nFly)) + OString::Concat("]/infos/bounds"), "top") .toInt64(); const auto nFlyBottom = getXPath(pLayoutXML2, OString::Concat("/root/page/body/txt[6]/anchored/fly[") + OString::Concat(OString::number(nFly)) + OString::Concat("]/infos/bounds"), "height") .toInt64(); const auto sDrawRect = getXPath( pLayoutXML2, OString::Concat("/root/page/body/txt[6]/anchored/SwAnchoredDrawObject/SdrObjGroup/" "SdrObjList/SdrObject[") + OString::Concat(OString::number(nFly)) + OString::Concat("]"), "aOutRect"); const auto nComaPos1 = sDrawRect.indexOf(',', 0); const auto nComaPos2 = sDrawRect.indexOf(',', nComaPos1 + 1); const auto nComaPos3 = sDrawRect.indexOf(',', nComaPos2 + 1); const auto nDraw1 = o3tl::toInt64(sDrawRect.subView(0, nComaPos1)); const auto nDraw2 = o3tl::toInt64(sDrawRect.subView(nComaPos1 + 1, nComaPos2 - nComaPos1)); const auto nDraw3 = o3tl::toInt64(sDrawRect.subView(nComaPos2 + 1, nComaPos3 - nComaPos2)); const auto nDraw4 = o3tl::toInt64( sDrawRect.subView(nComaPos3 + 1, sDrawRect.getLength() - nComaPos3 - 1)); CPPUNIT_ASSERT_GREATER(nDraw1, nFlyLeft); CPPUNIT_ASSERT_GREATER(nDraw2, nFlyTop); CPPUNIT_ASSERT_LESS(nDraw3, nFlyRight); CPPUNIT_ASSERT_LESS(nDraw4, nFlyBottom); } } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf148868) { createSwDoc("tdf148868.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); pWrtShell->EndPg(/*bSelect=*/false); pWrtShell->Left(SwCursorSkipMode::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(SwUiWriterTest3, testTdf129382) { createSwDoc("tdf129382.docx"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(8, getShapes()); CPPUNIT_ASSERT_EQUAL(2, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Cut(); CPPUNIT_ASSERT_EQUAL(3, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(8, getShapes()); CPPUNIT_ASSERT_EQUAL(2, getPages()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(3, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); // without the fix, it crashes dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(8, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf135662) { createSwDoc("tdf135662.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(2, getShapes()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Cut(); CPPUNIT_ASSERT_EQUAL(0, getShapes()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); // Without the fix in place, this test would have failed with // - Expected: 2 // - Actual : 1 CPPUNIT_ASSERT_EQUAL(2, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf134227) { createSwDoc("tdf134227.docx"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(4, getShapes()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:SelectAll", {}); // Without the fix in place, it would have crashed here rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Cut(); CPPUNIT_ASSERT_EQUAL(0, getShapes()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(4, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(0, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(4, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf139638) { createSwDoc("tdf139638.odt"); uno::Reference xIndexSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexes = xIndexSupplier->getDocumentIndexes(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexes->getCount()); uno::Reference xTOCIndex(xIndexes->getByIndex(0), uno::UNO_QUERY); // Without the fix in place, this test would have crashed xTOCIndex->update(); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf135412) { createSwDoc("tdf135412.docx"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(4, getShapes()); uno::Reference xShape(getShape(1), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("X"), xShape->getString()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Cut(); CPPUNIT_ASSERT_EQUAL(0, getShapes()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(4, getShapes()); // Without the fix in place, the text in the shape wouldn't be pasted xShape.set(getShape(1), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("X"), xShape->getString()); //Without the fix in place, it would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(0, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(4, getShapes()); xShape.set(getShape(1), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("X"), xShape->getString()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf138482) { createSwDoc("tdf138482.docx"); CPPUNIT_ASSERT_EQUAL(2, getShapes()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Delete", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(0, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(2, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf134965) { createSwDoc("tdf134965.odt"); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); for (sal_Int32 i = 0; i < 10; ++i) { dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Cut", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); } } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf128375) { for (sal_Int32 i = 0; i < 2; ++i) { createSwDoc("tdf128375.docx"); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); // Without the fix in place, this test would have crashed cutting the second document dispatchCommand(mxComponent, ".uno:Cut", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); } } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf135061) { createSwDoc("tdf135061.odt"); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(4, getShapes()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Copy", {}); Scheduler::ProcessEventsToIdle(); for (sal_Int32 i = 0; i < 5; ++i) { dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); } CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(20, getShapes()); for (sal_Int32 i = 0; i < 5; ++i) { // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); } CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(4, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132911) { createSwDoc("tdf132911.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(4, getShapes()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Cut(); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(0, getShapes()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(4, getShapes()); // Without the fix in place, it would have crashed here SwTransferable::Paste(*pWrtShell, aHelper); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(8, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(4, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(0, getShapes()); SwTransferable::Paste(*pWrtShell, aHelper); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(4, getShapes()); SwTransferable::Paste(*pWrtShell, aHelper); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(8, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(4, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(0, getShapes()); //tdf#135247: Without the fix in place, this would have crashed dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(4, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf61154) { createSwDoc("tdf61154.fodt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); pWrtShell->GotoNextTOXBase(); // show changes pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::ShowDelete | RedlineFlags::ShowInsert); CPPUNIT_ASSERT_MESSAGE("redlining should be off", !pDoc->getIDocumentRedlineAccess().IsRedlineOn()); CPPUNIT_ASSERT_MESSAGE( "redlines should be visible", IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); const SwTOXBase* pTOXBase = pWrtShell->GetCurTOX(); pWrtShell->UpdateTableOf(*pTOXBase); SwCursorShell* pShell(pDoc->GetEditShell()); SwTextNode* pTitleNode = pShell->GetCursor()->GetPointNode().GetTextNode(); SwNodeIndex aIdx(*pTitleNode); // table of contents node shouldn't contain tracked deletion // This was "Text InsertedDeleted\t1" SwTextNode* pNext = static_cast(pDoc->GetNodes().GoNext(&aIdx)); CPPUNIT_ASSERT_EQUAL(OUString("Text Inserted\t1"), pNext->GetText()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf124904) { // don't show deletions in referenced text, // (except if the full text is deleted) createSwDoc("tdf124904.fodt"); SwDoc* pDoc = getSwDoc(); // show changes pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete | RedlineFlags::ShowInsert); CPPUNIT_ASSERT_MESSAGE("redlining should be on", pDoc->getIDocumentRedlineAccess().IsRedlineOn()); CPPUNIT_ASSERT_MESSAGE( "redlines should be visible", IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); // remove the first word "Heading" (with change tracking) to update the referenced text dispatchCommand(mxComponent, ".uno:DelToEndOfWord", {}); Scheduler::ProcessEventsToIdle(); // This was "Reference to Heading of document file" CPPUNIT_ASSERT_EQUAL(OUString("Reference to of example document "), getParagraph(2)->getString()); // don't hide the wholly deleted referenced text dispatchCommand(mxComponent, ".uno:DelToEndOfLine", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(OUString("Reference to Heading of example document file"), getParagraph(2)->getString()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf100691) { createSwDoc("tdf100691.fodt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); pWrtShell->GotoNextTOXBase(); const SwTOXBase* pTOXBase = pWrtShell->GetCurTOX(); pWrtShell->UpdateTableOf(*pTOXBase); SwCursorShell* pShell(pDoc->GetEditShell()); SwTextNode* pTitleNode = pShell->GetCursor()->GetPointNode().GetTextNode(); SwNodeIndex aIdx(*pTitleNode); // table of contents node shouldn't contain invisible text // This was "Text Hidden\t1" SwTextNode* pNext = static_cast(pDoc->GetNodes().GoNext(&aIdx)); CPPUNIT_ASSERT_EQUAL(OUString("Text\t1"), pNext->GetText()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf134404) { createSwDoc("tdf134404.odt"); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:GoToEndOfPage", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:InsertPagebreak", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(2, getPages()); dispatchCommand(mxComponent, ".uno:SwBackspace", {}); Scheduler::ProcessEventsToIdle(); // Without the fix in place, the image would have been deleted CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(2, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf112342) { createSwDoc("tdf112342.docx"); //Get the last para uno::Reference xPara = getParagraph(3); auto xCur = xPara->getText()->createTextCursor(); //Go to the end of it xCur->gotoEnd(false); //And let's remove the last 2 chars (the last para with its char). xCur->goLeft(2, true); xCur->setString(""); //If the second paragraph on the second page, this will be passed. CPPUNIT_ASSERT_EQUAL_MESSAGE("Page break does not match", 2, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132321) { createSwDoc("tdf132321.odt"); CPPUNIT_ASSERT_EQUAL(1, getShapes()); dispatchCommand(mxComponent, ".uno:GoToEndOfPage", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:SwBackspace", {}); Scheduler::ProcessEventsToIdle(); // Without the fix in place, the button form would have also been deleted CPPUNIT_ASSERT_EQUAL(1, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf135056) { createSwDoc("tdf135056.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pWrtShell->GetTOXCount()); const SwTOXBase* pTOX = pWrtShell->GetTOX(0); CPPUNIT_ASSERT(pTOX); //Without the fix in place, it would have hung here pWrtShell->DeleteTOX(*pTOX, true); CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pWrtShell->GetTOXCount()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pWrtShell->GetTOXCount()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132597) { createSwDoc("tdf132597.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); // Paste special as RTF uno::Sequence aPropertyValues = comphelper::InitPropertySequence( { { "SelectedFormat", uno::Any(static_cast(SotClipboardFormatId::RTF)) } }); dispatchCommand(mxComponent, ".uno:ClipboardFormatItems", aPropertyValues); Scheduler::ProcessEventsToIdle(); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf139737) { createSwDoc("tdf139737.fodt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xModel(mxComponent, uno::UNO_QUERY); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); // Paste special as RTF uno::Sequence aPropertyValues = comphelper::InitPropertySequence( { { "SelectedFormat", uno::Any(static_cast(SotClipboardFormatId::RTF)) } }); dispatchCommand(mxComponent, ".uno:ClipboardFormatItems", aPropertyValues); Scheduler::ProcessEventsToIdle(); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf150845) { createSwDoc(); // Insert text box with ctrl key // Without the fix in place, this test would have crashed here uno::Sequence aArgs( comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(KEY_MOD1) } })); dispatchCommand(mxComponent, ".uno:Edit", aArgs); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf147961) { createSwDoc(); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); pWrtShell->Insert("++"); SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); // Without the fix in place, this test would have crashed here pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf147206) { createSwDoc(); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); // insert empty paragraph and heading text pWrtShell->SplitNode(); pWrtShell->Insert("abc"); pWrtShell->SplitNode(); // set one to heading so there will be an entry in the tox pWrtShell->Up(false, 1); uno::Sequence aPropertyValues = comphelper::InitPropertySequence({ { "Style", uno::Any(OUString("Heading 1")) }, { "FamilyName", uno::Any(OUString("ParagraphStyles")) }, }); dispatchCommand(mxComponent, ".uno:StyleApply", aPropertyValues); pWrtShell->EndOfSection(false); // tdf#142423: Without the fix in place, this test would have failed with // - Expected: 18 // - Actual : 18.2 CPPUNIT_ASSERT_EQUAL(18.0f, getProperty(getParagraph(2), "CharHeight")); // insert table of contents SwTOXMgr mgr(pWrtShell); SwTOXDescription desc{ TOX_CONTENT }; mgr.UpdateOrInsertTOX(desc, nullptr, nullptr); // get url of heading cross reference mark IDocumentMarkAccess& rIDMA(*pDoc->getIDocumentMarkAccess()); auto const headingMark = std::find_if(rIDMA.getAllMarksBegin(), rIDMA.getAllMarksEnd(), [](auto const* const it) { return it->GetName().startsWith( IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix()); }); CPPUNIT_ASSERT(headingMark != rIDMA.getAllMarksEnd()); OUString const headingLink("#" + (*headingMark)->GetName()); // select tox entry pWrtShell->SttEndDoc(false); pWrtShell->Up(false, 1); pWrtShell->EndPara(true); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); pWrtShell->SttEndDoc(true); // Paste special as RTF TransferableDataHelper helper(xTransfer); SwTransferable::PasteFormat(*pWrtShell, helper, SotClipboardFormatId::RTF); Scheduler::ProcessEventsToIdle(); // check hyperlinking CPPUNIT_ASSERT_EQUAL( headingLink, getProperty(getRun(getParagraph(1), 1, "abc\t1"), "HyperLinkURL")); CPPUNIT_ASSERT_EQUAL( OUString(), getProperty(getRun(getParagraph(2), 1, OUString()), "HyperLinkURL")); CPPUNIT_ASSERT_EQUAL( OUString(), getProperty(getRun(getParagraph(3), 1, "Table of Contents"), "HyperLinkURL")); CPPUNIT_ASSERT_EQUAL( headingLink, getProperty(getRun(getParagraph(4), 1, "abc\t1"), "HyperLinkURL")); CPPUNIT_ASSERT_EQUAL( OUString(), getProperty(getRun(getParagraph(5), 1, OUString()), "HyperLinkURL")); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf144840) { createSwDoc("tdf144840.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(1, getPages()); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Cut(); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); // Paste special as RTF uno::Sequence aPropertyValues = comphelper::InitPropertySequence( { { "SelectedFormat", uno::Any(static_cast(SotClipboardFormatId::RTF)) } }); dispatchCommand(mxComponent, ".uno:ClipboardFormatItems", aPropertyValues); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); uno::Reference xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY); table::TableBorder2 tableBorder = getProperty(xTextTable, "TableBorder2"); // Without the fix in place, this test would have failed with // - Expected: 4 // - Actual : 0 CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder.TopLine.LineWidth); CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder.LeftLine.LineWidth); CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder.RightLine.LineWidth); CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder.BottomLine.LineWidth); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf131963) { createSwDoc("tdf131963.docx"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(11, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); // Paste special as RTF uno::Sequence aPropertyValues = comphelper::InitPropertySequence( { { "SelectedFormat", uno::Any(static_cast(SotClipboardFormatId::RTF)) } }); dispatchCommand(mxComponent, ".uno:ClipboardFormatItems", aPropertyValues); Scheduler::ProcessEventsToIdle(); // Without the fix in place, this test would have crashed here // tdf#133169: without the fix in place, it would have been 2 instead of 11 CPPUNIT_ASSERT_EQUAL(11, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132596) { createSwDoc("tdf132596.docx"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(2, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); // Paste special as RTF uno::Sequence aPropertyValues = comphelper::InitPropertySequence( { { "SelectedFormat", uno::Any(static_cast(SotClipboardFormatId::RTF)) } }); dispatchCommand(mxComponent, ".uno:ClipboardFormatItems", aPropertyValues); Scheduler::ProcessEventsToIdle(); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(2, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf126626) { createSwDoc("tdf126626.docx"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(2, getShapes()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); CPPUNIT_ASSERT_EQUAL(2, getShapes()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(2, getShapes()); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(4, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(2, getShapes()); // without the fix, it crashes SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(4, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf133967) { createSwDoc("tdf133967.odt"); CPPUNIT_ASSERT_EQUAL(6, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:Cut", {}); Scheduler::ProcessEventsToIdle(); for (sal_Int32 i = 0; i < 10; ++i) { dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Redo", {}); Scheduler::ProcessEventsToIdle(); } // Without the fix in place, this test would have failed with: //- Expected: 1 //- Actual : 45 CPPUNIT_ASSERT_EQUAL(1, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132187) { createSwDoc("tdf132187.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); dispatchCommand(mxComponent, ".uno:GoToEndOfDoc", {}); TransferableDataHelper aHelper(xTransfer); for (sal_Int32 i = 0; i < 10; ++i) { SwTransferable::Paste(*pWrtShell, aHelper); Scheduler::ProcessEventsToIdle(); } //without the fix in place, this test would fail with: //- Expected: 1 //- Actual : 70 CPPUNIT_ASSERT_EQUAL(1, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf130094) { createSwDoc("tdf130094.fodt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(OUString("First"), getParagraph(1)->getString()); CPPUNIT_ASSERT_EQUAL(OUString("Second"), getParagraph(2)->getString()); CPPUNIT_ASSERT_EQUAL(OUString("Third"), getParagraph(3)->getString()); // Select the first and second lines pWrtShell->Down(/*bSelect=*/true); pWrtShell->Down(/*bSelect=*/true); dispatchCommand(mxComponent, ".uno:Copy", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(OUString("First"), getParagraph(1)->getString()); CPPUNIT_ASSERT_EQUAL(OUString("Second"), getParagraph(2)->getString()); CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(3)->getString()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(OUString("First"), getParagraph(1)->getString()); CPPUNIT_ASSERT_EQUAL(OUString("Second"), getParagraph(2)->getString()); CPPUNIT_ASSERT_EQUAL(OUString("Third"), getParagraph(3)->getString()); dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(OUString("First"), getParagraph(1)->getString()); CPPUNIT_ASSERT_EQUAL(OUString("Second"), getParagraph(2)->getString()); // Without the fix in place, this test would have failed with // - Expected: // - Actual : First CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(3)->getString()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf135733) { createSwDoc("tdf135733.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); CPPUNIT_ASSERT_EQUAL(2, getShapes()); //Move the cursor inside the table pWrtShell->Down(/*bSelect=*/false); pWrtShell->Down(/*bSelect=*/false); //Select first column pWrtShell->Down(/*bSelect=*/true); pWrtShell->Down(/*bSelect=*/true); pWrtShell->Down(/*bSelect=*/true); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Cut(); pWrtShell->SttPg(/*bSelect=*/false); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); CPPUNIT_ASSERT_EQUAL(2, getShapes()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); CPPUNIT_ASSERT_EQUAL(0, getShapes()); // without the fix, it crashes dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); CPPUNIT_ASSERT_EQUAL(2, getShapes()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf128739) { createSwDoc("tdf128739.docx"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(OUString("Fehler: Verweis nicht gefunden"), getParagraph(1)->getString()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Cut(); CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(OUString("Fehler: Verweis nicht gefunden"), getParagraph(1)->getString()); // without the fix, it crashes dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf124722) { createSwDoc("tdf124722.rtf"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(22, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); CPPUNIT_ASSERT_EQUAL(22, getPages()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(43, getPages()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(22, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testToxmarkLinks) { createSwDoc("udindex3.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); SwView& rView(*pDoc->GetDocShell()->GetView()); // update indexes for (auto i = pWrtShell->GetTOXCount(); 0 < i;) { --i; pWrtShell->UpdateTableOf(*pWrtShell->GetTOX(i)); } // click on the links... { OUString const tmp("Table of Contents"); pWrtShell->GotoNextTOXBase(&tmp); } { // ToC toxmark pWrtShell->Down(false); SfxItemSet aSet(pWrtShell->GetAttrPool(), svl::Items); pWrtShell->GetCurAttr(aSet); CPPUNIT_ASSERT(aSet.HasItem(RES_TXTATR_INETFMT)); pWrtShell->Push(); OUString const url(aSet.GetItem(RES_TXTATR_INETFMT)->GetValue()); CPPUNIT_ASSERT_EQUAL(OUString("#1%19the%20tocmark%19C%7Ctoxmark"), url); rView.JumpToSwMark(url.subView(1)); // SfxApplication::OpenDocExec_Impl eats the "#" CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_INWORD) + "tocmark"), pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText()); pWrtShell->Pop(SwCursorShell::PopMode::DeleteCurrent); } { // ToC heading pWrtShell->Down(false); SfxItemSet aSet(pWrtShell->GetAttrPool(), svl::Items); pWrtShell->GetCurAttr(aSet); CPPUNIT_ASSERT(aSet.HasItem(RES_TXTATR_INETFMT)); pWrtShell->Push(); OUString const url(aSet.GetItem(RES_TXTATR_INETFMT)->GetValue()); CPPUNIT_ASSERT_EQUAL(OUString("#__RefHeading___Toc105_706348105"), url); rView.JumpToSwMark(url.subView(1)); CPPUNIT_ASSERT_EQUAL(OUString("foo"), pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText()); pWrtShell->Pop(SwCursorShell::PopMode::DeleteCurrent); } { OUString const tmp("User-Defined1"); pWrtShell->GotoNextTOXBase(&tmp); } { // UD1 toxmark 1 pWrtShell->Down(false); SfxItemSet aSet(pWrtShell->GetAttrPool(), svl::Items); pWrtShell->GetCurAttr(aSet); CPPUNIT_ASSERT(aSet.HasItem(RES_TXTATR_INETFMT)); pWrtShell->Push(); OUString const url(aSet.GetItem(RES_TXTATR_INETFMT)->GetValue()); CPPUNIT_ASSERT_EQUAL(OUString("#1%19the%20udmark%19UUser-Defined%7Ctoxmark"), url); rView.JumpToSwMark(url.subView(1)); CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_INWORD) + "udmark the first"), pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText()); pWrtShell->Pop(SwCursorShell::PopMode::DeleteCurrent); } { // UD1 toxmark 2 (with same text) pWrtShell->Down(false); SfxItemSet aSet(pWrtShell->GetAttrPool(), svl::Items); pWrtShell->GetCurAttr(aSet); CPPUNIT_ASSERT(aSet.HasItem(RES_TXTATR_INETFMT)); pWrtShell->Push(); OUString const url(aSet.GetItem(RES_TXTATR_INETFMT)->GetValue()); CPPUNIT_ASSERT_EQUAL(OUString("#2%19the%20udmark%19UUser-Defined%7Ctoxmark"), url); rView.JumpToSwMark(url.subView(1)); CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_INWORD) + "udmark the 2nd"), pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText()); pWrtShell->Pop(SwCursorShell::PopMode::DeleteCurrent); } { // UD heading pWrtShell->Down(false); SfxItemSet aSet(pWrtShell->GetAttrPool(), svl::Items); pWrtShell->GetCurAttr(aSet); CPPUNIT_ASSERT(aSet.HasItem(RES_TXTATR_INETFMT)); pWrtShell->Push(); OUString const url(aSet.GetItem(RES_TXTATR_INETFMT)->GetValue()); CPPUNIT_ASSERT_EQUAL(OUString("#__RefHeading___Toc105_706348105"), url); rView.JumpToSwMark(url.subView(1)); CPPUNIT_ASSERT_EQUAL(OUString("foo"), pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText()); pWrtShell->Pop(SwCursorShell::PopMode::DeleteCurrent); } { OUString const tmp("NewUD!|1"); pWrtShell->GotoNextTOXBase(&tmp); } { // UD2 toxmark, with same text as those in other UD pWrtShell->Down(false); SfxItemSet aSet(pWrtShell->GetAttrPool(), svl::Items); pWrtShell->GetCurAttr(aSet); CPPUNIT_ASSERT(aSet.HasItem(RES_TXTATR_INETFMT)); pWrtShell->Push(); OUString const url(aSet.GetItem(RES_TXTATR_INETFMT)->GetValue()); CPPUNIT_ASSERT_EQUAL(OUString("#1%19the%20udmark%19UNewUD!%7C%7Ctoxmark"), url); rView.JumpToSwMark(url.subView(1)); CPPUNIT_ASSERT_EQUAL(OUString("the udmark"), pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText()); pWrtShell->Pop(SwCursorShell::PopMode::DeleteCurrent); } } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf125261) { createSwDoc("tdf125261.odt"); CPPUNIT_ASSERT_EQUAL(OUString("https://www.example.com/"), getProperty(getRun(getParagraph(1), 1), "HyperLinkURL")); //apply autocorrect StartAutoCorrect dispatchCommand(mxComponent, ".uno:AutoFormatApply", {}); CPPUNIT_ASSERT_EQUAL(OUString("https://www.example.com/"), getProperty(getRun(getParagraph(1), 1), "HyperLinkURL")); // without the fix, it hangs dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(OUString("https://www.example.com/"), getProperty(getRun(getParagraph(1), 1), "HyperLinkURL")); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf141175) { createSwDoc("tdf141175.odt"); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); //Use selectAll 3 times in a row dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:SelectAll", {}); Scheduler::ProcessEventsToIdle(); //Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Cut", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:Paste", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf133990) { createSwDoc("tdf133990.odt"); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); //Use selectAll 3 times in a row dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:Delete", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); //Without the fix in place, it would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf126504) { createSwDoc("tdf126504.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); //Use selectAll 2 times in a row dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); dispatchCommand(mxComponent, ".uno:GoToEndOfPage", {}); Scheduler::ProcessEventsToIdle(); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:Redo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); //Without the fix in place, it would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf133982) { createSwDoc("tdf133982.docx"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); //Use selectAll 3 times in a row dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); //Without the fix in place, it would have crashed here xTransfer->Cut(); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf134253) { createSwDoc("tdf134253.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(6, getPages()); //Use selectAll 3 times in a row dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); //Without the fix in place, it would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(6, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, TestAsCharTextBox) { // Related tickets: // tdf#138598 Replace vertical alignment of As_char textboxes in footer // tdf#140158 Remove horizontal positioning of As_char textboxes, because // the anchor moving does the same for it. createSwDoc("AsCharTxBxTest.docx"); SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); // Add 3x tab to the doc pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); Scheduler::ProcessEventsToIdle(); auto pExportDump = parseLayoutDump(); CPPUNIT_ASSERT(pExportDump); // Check if the texbox fallen apart due to the tabs const double nLeftSideOfShape1 = getXPath(pExportDump, "/root/page/body/txt/anchored/SwAnchoredDrawObject/bounds", "left") .toDouble(); const double nLeftSideOfTxBx1 = getXPath(pExportDump, "/root/page/body/txt/anchored/fly/infos/bounds", "left").toDouble(); CPPUNIT_ASSERT(nLeftSideOfShape1 < nLeftSideOfTxBx1); // Another test is for the tdf#138598: Check footer textbox const double nLeftSideOfShape2 = getXPath(pExportDump, "/root/page[2]/footer/txt/anchored/SwAnchoredDrawObject/bounds", "left") .toDouble(); const double nLeftSideOfTxBx2 = getXPath(pExportDump, "/root/page[2]/footer/txt/anchored/fly/infos/bounds", "left") .toDouble(); CPPUNIT_ASSERT(nLeftSideOfShape2 < nLeftSideOfTxBx2); const double nTopSideOfShape2 = getXPath(pExportDump, "/root/page[2]/footer/txt/anchored/SwAnchoredDrawObject/bounds", "top") .toDouble(); const double nTopSideOfTxBx2 = getXPath(pExportDump, "/root/page[2]/footer/txt/anchored/fly/infos/bounds", "top") .toDouble(); CPPUNIT_ASSERT(nTopSideOfShape2 < nTopSideOfTxBx2); // Without the fix in place the two texboxes has been fallen apart, and asserts will broken. } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf140975) { // Load the bugdoc createSwDoc("tdf140975.docx"); // Set the Anchor of the shape to As_Char dispatchCommand(mxComponent, ".uno:JumpToNextFrame", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:SetAnchorToChar", {}); Scheduler::ProcessEventsToIdle(); // Get the layout of the textbox auto pExportDump = parseLayoutDump(); CPPUNIT_ASSERT(pExportDump); const sal_Int32 nShpTop = getXPath(pExportDump, "/root/page/body/txt[4]/anchored/SwAnchoredDrawObject/bounds", "top") .toInt32(); const sal_Int32 nFrmTop = getXPath(pExportDump, "/root/page/body/txt[4]/anchored/fly/infos/bounds", "top") .toInt32(); // Without the fix in place, the frame has less value for Top than // the shape. This means the frame is outside from the shape. CPPUNIT_ASSERT_GREATER(nShpTop, nFrmTop); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf76636) { createSwDoc("tdf76636.doc"); SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); uno::Reference xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable->getColumns()->getCount()); //go to middle row pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); Scheduler::ProcessEventsToIdle(); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); Scheduler::ProcessEventsToIdle(); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_LEFT | KEY_SHIFT); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_LEFT | KEY_SHIFT); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:MergeCells", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTextTable->getColumns()->getCount()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable->getColumns()->getCount()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf76636_2) { createSwDoc("tdf76636.doc"); SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); uno::Reference xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable->getColumns()->getCount()); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); Scheduler::ProcessEventsToIdle(); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); Scheduler::ProcessEventsToIdle(); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT | KEY_SHIFT); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:MergeCells", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable->getColumns()->getCount()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable->getRows()->getCount()); CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable->getColumns()->getCount()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf140828) { createSwDoc("tdf140828.docx"); CPPUNIT_ASSERT_EQUAL(1, getShapes()); uno::Reference xShp = getShape(1); CPPUNIT_ASSERT(xShp); uno::Reference ShpProps(xShp, uno::UNO_QUERY_THROW); dispatchCommand(mxComponent, ".uno:JumpToNextFrame", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:SetAnchorAtChar", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL( text::TextContentAnchorType::TextContentAnchorType_AT_CHARACTER, ShpProps->getPropertyValue("AnchorType").get()); uno::Reference xTxBx(SwTextBoxHelper::getUnoTextFrame(xShp)); CPPUNIT_ASSERT(xTxBx); uno::Reference TxBxProps(xTxBx, uno::UNO_QUERY_THROW); CPPUNIT_ASSERT_EQUAL(OUString("top left image"), xTxBx->getText()->getString()); CPPUNIT_ASSERT_MESSAGE("Bad Relative Orientation and Position!", TxBxProps->getPropertyValue("HoriOrientRelation").get() != text::RelOrientation::CHAR); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132725) { createSwDoc("tdf132725.odt"); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(OUString("AA"), getParagraph(1)->getString()); dispatchCommand(mxComponent, ".uno:GoToEndOfPara", {}); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:SwBackspace", {}); dispatchCommand(mxComponent, ".uno:SwBackspace", {}); Scheduler::ProcessEventsToIdle(); // tdf#137587 fly is no longer deleted by backspace CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString()); dispatchCommand(mxComponent, ".uno:Undo", {}); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(OUString("AA"), getParagraph(1)->getString()); dispatchCommand(mxComponent, ".uno:Redo", {}); dispatchCommand(mxComponent, ".uno:Redo", {}); Scheduler::ProcessEventsToIdle(); // tdf#137587 fly is no longer deleted by backspace CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString()); //Without the fix in place, it would crash here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(OUString("A"), getParagraph(1)->getString()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf126340) { createSwDoc("tdf126340.odt"); dispatchCommand(mxComponent, ".uno:GoDown", {}); // without the fix, it crashes dispatchCommand(mxComponent, ".uno:Delete", {}); CPPUNIT_ASSERT_EQUAL(OUString("foo"), getParagraph(1)->getString()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(OUString("foo"), getParagraph(1)->getString()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf124397) { createSwDoc("tdf124397.docx"); uno::Reference xTextFramesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:Delete", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); // Without the fix in place, it would crash here dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf108124) { createSwDoc("tdf108124.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xTextGraphicObjectsSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess( xTextGraphicObjectsSupplier->getGraphicObjects(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); uno::Reference xOldShape1(xIndexAccess->getByIndex(0), uno::UNO_QUERY); uno::Reference xOldShape2(xIndexAccess->getByIndex(1), uno::UNO_QUERY); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); uno::Reference xNewShape1(xIndexAccess->getByIndex(0), uno::UNO_QUERY); uno::Reference xNewShape2(xIndexAccess->getByIndex(1), uno::UNO_QUERY); // there should be 2 different objects now but they have the same names, // so rely on the object identity for testing... CPPUNIT_ASSERT(xOldShape1.get() != xNewShape1.get()); CPPUNIT_ASSERT(xOldShape1.get() != xNewShape2.get()); CPPUNIT_ASSERT(xOldShape2.get() != xNewShape1.get()); CPPUNIT_ASSERT(xOldShape2.get() != xNewShape2.get()); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Redo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf107975) { // This test also covers tdf#117185 tdf#110442 createSwDoc("tdf107975.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); uno::Reference xTextGraphicObjectsSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess( xTextGraphicObjectsSupplier->getGraphicObjects(), uno::UNO_QUERY); uno::Reference xShape(xIndexAccess->getByIndex(0), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, getProperty(xShape, "AnchorType")); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); //Position the mouse cursor (caret) after "ABC" below the blue image dispatchCommand(mxComponent, ".uno:GoRight", {}); { TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); } // without the fix, it crashes CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(OUString("ABC"), getParagraph(1)->getString()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:Redo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:Redo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); //try again with anchor at start of doc which is another special case xShape.set(xIndexAccess->getByIndex(0), uno::UNO_QUERY); uno::Reference xShapeContent(xShape, uno::UNO_QUERY); uno::Reference const xStart = pTextDoc->getText()->getStart(); xShapeContent->attach(xStart); CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, getProperty(xShape, "AnchorType")); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); xTransfer.set(new SwTransferable(*pWrtShell)); xTransfer->Copy(); //Position the mouse cursor (caret) after "ABC" below the blue image dispatchCommand(mxComponent, ".uno:GoRight", {}); { TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); } // without the fix, it crashes CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(OUString("ABC"), getParagraph(1)->getString()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:Redo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:Redo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf134021) { createSwDoc("tdf134021.docx"); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(12, getPages()); dispatchCommand(mxComponent, ".uno:JumpToNextTable", {}); dispatchCommand(mxComponent, ".uno:DeleteTable", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); // Without the fix in place, it would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(12, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf136778) { createSwDoc("tdf136778.docx"); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:JumpToNextTable", {}); dispatchCommand(mxComponent, ".uno:DeleteTable", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); // Without the fix in place, it would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf123285) { createSwDoc("tdf123285.odt"); SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); CPPUNIT_ASSERT_EQUAL(true, getParagraph(1)->getString().endsWith( ". Here is a short sentence demonstrating this very peculiar bug" ". Here is a short sentence demonstrating this very peculiar bug.")); dispatchCommand(mxComponent, ".uno:GoToEndOfPage", {}); Scheduler::ProcessEventsToIdle(); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN); Scheduler::ProcessEventsToIdle(); // Without the fix in place, the last "sentence" would have been changed to " entence" CPPUNIT_ASSERT_EQUAL(true, getParagraph(1)->getString().endsWith( ". Here is a short sentence demonstrating this very peculiar bug" ". Here is a short sentence demonstrating this very peculiar bug.")); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf130746) { createSwDoc("tdf130746.odt"); SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:JumpToNextTable", {}); uno::Reference xModel(mxComponent, uno::UNO_QUERY); uno::Reference xTextViewCursorSupplier( xModel->getCurrentController(), uno::UNO_QUERY); uno::Reference xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xCursor->getPage()); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor->getPage()); pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_UP | KEY_MOD2); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor->getPage()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xCursor->getPage()); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf129805) { createSwDoc("tdf129805.docx"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(OUString("x"), getParagraph(1)->getString()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); // without the fix in place, it would crash here xTransfer->Cut(); CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(OUString("x"), getParagraph(1)->getString()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf130685) { createSwDoc("tdf130685.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); CPPUNIT_ASSERT_EQUAL(2, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Cut(); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getPages()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); SwTransferable::Paste(*pWrtShell, aHelper); // Without fix in place, this test would have failed with: //- Expected: 2 //- Actual : 4 Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(2, getPages()); dispatchCommand(mxComponent, ".uno:Undo", {}); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(2, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132944) { createSwDoc("tdf132944.odt"); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:Delete", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); // Without the fix in place, the document would have had 2 pages CPPUNIT_ASSERT_EQUAL(1, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf104649) { createSwDoc("tdf104649.docx"); CPPUNIT_ASSERT_EQUAL(OUString("Test"), getParagraph(1)->getString()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); dispatchCommand(mxComponent, ".uno:Delete", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(1, getPages()); // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT_EQUAL(OUString("Test"), getParagraph(1)->getString()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf134931) { createSwDoc("tdf134931.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); CPPUNIT_ASSERT_EQUAL(1, getPages()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); xTransfer->Copy(); Scheduler::ProcessEventsToIdle(); dispatchCommand(mxComponent, ".uno:GoDown", {}); TransferableDataHelper aHelper(xTransfer); for (sal_Int32 i = 0; i < 10; ++i) { SwTransferable::Paste(*pWrtShell, aHelper); Scheduler::ProcessEventsToIdle(); } CPPUNIT_ASSERT_EQUAL(sal_Int32(11), xIndexAccess->getCount()); // Without the fix in place, this test would have failed with: // - Expected: 4 // - Actual : 1 // Because the tables are pasted but not displayed CPPUNIT_ASSERT_EQUAL(4, getPages()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf130680) { createSwDoc("tdf130680.odt"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(23), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:SelectAll", {}); rtl::Reference xClpDoc(new SwDoc()); xClpDoc->SetClipBoard(true); rtl::Reference xTransfer = new SwTransferable(*pWrtShell); // without the fix, it crashes xTransfer->Cut(); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); TransferableDataHelper aHelper(xTransfer); SwTransferable::Paste(*pWrtShell, aHelper); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); xClpDoc.clear(); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount()); dispatchCommand(mxComponent, ".uno:Undo", {}); CPPUNIT_ASSERT_EQUAL(sal_Int32(23), xIndexAccess->getCount()); } CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */