summaryrefslogtreecommitdiff
path: root/sw/qa/core/frmedt/frmedt.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/qa/core/frmedt/frmedt.cxx')
-rw-r--r--sw/qa/core/frmedt/frmedt.cxx145
1 files changed, 128 insertions, 17 deletions
diff --git a/sw/qa/core/frmedt/frmedt.cxx b/sw/qa/core/frmedt/frmedt.cxx
index 097db6402ae1..b2a53e60db27 100644
--- a/sw/qa/core/frmedt/frmedt.cxx
+++ b/sw/qa/core/frmedt/frmedt.cxx
@@ -23,18 +23,27 @@
#include <unotxdoc.hxx>
#include <docsh.hxx>
#include <swdtflvr.hxx>
-
-constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/frmedt/data/";
+#include <caption.hxx>
+#include <view.hxx>
+#include <formatflysplit.hxx>
+#include <itabenum.hxx>
+#include <frmmgr.hxx>
+#include <UndoManager.hxx>
/// Covers sw/source/core/frmedt/ fixes.
class SwCoreFrmedtTest : public SwModelTestBase
{
+public:
+ SwCoreFrmedtTest()
+ : SwModelTestBase("/sw/qa/core/frmedt/data/")
+ {
+ }
};
CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testTextboxReanchor)
{
// Load a document with a textframe and a textbox(shape+textframe).
- load(DATA_DIRECTORY, "textbox-reanchor.odt");
+ createSwDoc("textbox-reanchor.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
SdrPage* pDrawPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
@@ -51,9 +60,9 @@ CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testTextboxReanchor)
SwFrameFormat* pTextFrameFormat = FindFrameFormat(pTextFrameObj);
CPPUNIT_ASSERT_EQUAL(OUString("Frame2"), pTextFrameFormat->GetName());
SwFrameFormat* pDrawShapeFormat = FindFrameFormat(pDrawShape);
- sal_uLong nOldAnchor = pDrawShapeFormat->GetAnchor().GetContentAnchor()->nNode.GetIndex();
+ SwNodeOffset nOldAnchor = pDrawShapeFormat->GetAnchor().GetAnchorNode()->GetIndex();
pShell->FindAnchorPos(pTextFrameObj->GetLastBoundRect().Center(), true);
- sal_uLong nNewAnchor = pDrawShapeFormat->GetAnchor().GetContentAnchor()->nNode.GetIndex();
+ SwNodeOffset nNewAnchor = pDrawShapeFormat->GetAnchor().GetAnchorNode()->GetIndex();
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 6
// - Actual : 9
@@ -65,25 +74,24 @@ CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testVertPosFromBottomBoundingBox)
{
// Insert a shape and anchor it vertically in a way, so its position is from the top of the page
// bottom margin area.
- mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+ createSwDoc();
uno::Reference<css::lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
uno::Reference<drawing::XShape> xShape(
xFactory->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
xShape->setSize(awt::Size(10000, 10000));
uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
- xShapeProps->setPropertyValue("AnchorType",
- uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
- xShapeProps->setPropertyValue("VertOrient", uno::makeAny(text::VertOrientation::NONE));
+ xShapeProps->setPropertyValue("AnchorType", uno::Any(text::TextContentAnchorType_AT_CHARACTER));
+ xShapeProps->setPropertyValue("VertOrient", uno::Any(text::VertOrientation::NONE));
xShapeProps->setPropertyValue("VertOrientRelation",
- uno::makeAny(text::RelOrientation::PAGE_PRINT_AREA_BOTTOM));
- xShapeProps->setPropertyValue("VertOrientPosition",
- uno::makeAny(static_cast<sal_Int32>(-11000)));
+ uno::Any(text::RelOrientation::PAGE_PRINT_AREA_BOTTOM));
+ xShapeProps->setPropertyValue("VertOrientPosition", uno::Any(static_cast<sal_Int32>(-11000)));
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
xDrawPageSupplier->getDrawPage()->add(xShape);
// Get the absolute position of the top of the page bottom margin area.
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
- SwTwips nPagePrintAreaBottom = getXPath(pXmlDoc, "//page/infos/prtBounds", "bottom").toInt32();
+ SwTwips nPagePrintAreaBottom
+ = getXPath(pXmlDoc, "//page/infos/prtBounds"_ostr, "bottom"_ostr).toInt32();
// Calculate the allowed bounding box of the shape, e.g. the shape's position & size dialog uses
// this to limit the vertical position to sensible values.
@@ -93,13 +101,13 @@ CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testVertPosFromBottomBoundingBox)
RndStdIds eAnchorType = RndStdIds::FLY_AT_CHAR;
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
const auto& rFrameFormats = *pDoc->GetFrameFormats();
- const SwPosition* pContentPos = rFrameFormats[0]->GetAnchor().GetContentAnchor();
+ const SwFormatAnchor* pFormatAhchor = &rFrameFormats[0]->GetAnchor();
sal_Int16 eHoriRelOrient = text::RelOrientation::PAGE_FRAME;
sal_Int16 eVertRelOrient = text::RelOrientation::PAGE_PRINT_AREA_BOTTOM;
bool bFollowTextFlow = false;
bool bMirror = false;
Size aPercentSize;
- pWrtShell->CalcBoundRect(aBoundRect, eAnchorType, eHoriRelOrient, eVertRelOrient, pContentPos,
+ pWrtShell->CalcBoundRect(aBoundRect, eAnchorType, eHoriRelOrient, eVertRelOrient, pFormatAhchor,
bFollowTextFlow, bMirror, nullptr, &aPercentSize);
// Without the accompanying fix in place, this test would have failed with:
@@ -113,7 +121,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testVertPosFromBottomBoundingBox)
CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testPasteFlyInTextBox)
{
// Given a document that contains a textbox, which contains an sw image (fly frame)
- load(DATA_DIRECTORY, "paste-fly-in-textbox.docx");
+ createSwDoc("paste-fly-in-textbox.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
SwDocShell* pDocShell = pTextDoc->GetDocShell();
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
@@ -125,7 +133,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testPasteFlyInTextBox)
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
pTransfer->Cut();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pDoc->GetSpzFrameFormats()->GetFormatCount());
- TransferableDataHelper aHelper(pTransfer.get());
+ TransferableDataHelper aHelper(pTransfer);
// When pasting that to an empty document.
SwTransferable::Paste(*pWrtShell, aHelper);
@@ -139,6 +147,109 @@ CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testPasteFlyInTextBox)
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pDoc->GetSpzFrameFormats()->GetFormatCount());
}
+CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testTextBoxSelectCursorPos)
+{
+ // Given a document with a fly+draw format pair (textbox):
+ createSwDoc("paste-fly-in-textbox.docx");
+
+ // When selecting the fly format:
+ SwDoc* pDoc = getSwDoc();
+ SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
+ SdrObject* pFlyObject = pPage->GetObj(1);
+ SwContact* pFlyContact = static_cast<SwContact*>(pFlyObject->GetUserCall());
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_FLYFRMFMT), pFlyContact->GetFormat()->Which());
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->SelectObj(Point(), 0, pFlyObject);
+
+ // Then make sure the cursor is the anchor of the draw format:
+ SdrObject* pDrawObject = pPage->GetObj(0);
+ SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(pDrawObject->GetUserCall());
+ SwFrameFormat* pDrawFormat = pDrawContact->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_DRAWFRMFMT), pDrawFormat->Which());
+ SwNodeOffset nAnchor = pDrawFormat->GetAnchor().GetContentAnchor()->GetNode().GetIndex();
+ SwNodeOffset nCursor = pWrtShell->GetCurrentShellCursor().GetPointNode().GetIndex();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 15 (anchor of draw format)
+ // - Actual : 6 (in-fly-format position)
+ // i.e. the cursor had a broken position after trying to select the fly format.
+ CPPUNIT_ASSERT_EQUAL(nAnchor, nCursor);
+}
+
+CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testSplitFlyInsertCaption)
+{
+ // Given a document with a full-page floating table:
+ createSwDoc("floating-table-caption.docx");
+
+ // When trying to insert a caption below that table:
+ SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+ pWrtShell->GotoTable("Table1");
+ InsCaptionOpt aOpt;
+ SwView& rView = pWrtShell->GetView();
+ aOpt.SetCategory("Table");
+ aOpt.SetCaption("Numbers English-German");
+ // After, not before.
+ aOpt.SetPos(1);
+ // Without the accompanying fix in place, this call never finished, layout didn't handle content
+ // after the table in a floating table.
+ rView.InsertCaption(&aOpt);
+
+ // Then make sure the insertion finishes and now this is just a plain table-in-frame:
+ SwDoc* pDoc = getSwDoc();
+ sw::SpzFrameFormats& rFlys = *pDoc->GetSpzFrameFormats();
+ sw::SpzFrameFormat* pFly = rFlys[0];
+ CPPUNIT_ASSERT(!pFly->GetAttrSet().GetFlySplit().GetValue());
+}
+
+CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testSplitFlyUnfloat)
+{
+ // Given a document with a floating table:
+ createSwDoc();
+ SwDoc* pDoc = getSwDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc->GetUndoManager().IsUndoEnabled());
+ pDoc->GetUndoManager().EnableUndo(false);
+ sw::FrameFormats<sw::SpzFrameFormat*>& rFlyFormats = *pDoc->GetSpzFrameFormats();
+ CPPUNIT_ASSERT(rFlyFormats.empty());
+ // Insert a table:
+ SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+ SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0);
+ pWrtShell->InsertTable(aTableOptions, /*nRows=*/2, /*nCols=*/1);
+ pWrtShell->MoveTable(GotoPrevTable, fnTableStart);
+ pWrtShell->GoPrevCell();
+ pWrtShell->Insert("A1");
+ pWrtShell->GoNextCell();
+ pWrtShell->Insert("A2");
+ // Select cell:
+ pWrtShell->SelAll();
+ // Select table:
+ pWrtShell->SelAll();
+ // Wrap the table in a text frame:
+ SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr);
+ pWrtShell->StartAllAction();
+ aMgr.InsertFlyFrame(RndStdIds::FLY_AT_PARA, aMgr.GetPos(), aMgr.GetSize());
+ pWrtShell->EndAllAction();
+ CPPUNIT_ASSERT(!rFlyFormats.empty());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDoc->GetTableFrameFormatCount(/*bUsed=*/true));
+ pDoc->GetUndoManager().EnableUndo(true);
+
+ // When marking that frame and unfloating it:
+ selectShape(1);
+ pWrtShell->UnfloatFlyFrame();
+
+ // Then make sure the frame is removed, but the table is still part of the document:
+ // Without the accompanying fix in place (empty SwFEShell::UnfloatFlyFrame()), this test would
+ // have failed, the frame was not removed.
+ CPPUNIT_ASSERT(rFlyFormats.empty());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDoc->GetTableFrameFormatCount(/*bUsed=*/true));
+
+ // When undoing the conversion to inline:
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDoc->GetUndoManager().GetUndoActionCount());
+ pDoc->GetUndoManager().Undo();
+
+ // Then the undo stack had 2 undo actions and undo-all crashed.
+ CPPUNIT_ASSERT(!rFlyFormats.empty());
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDoc->GetTableFrameFormatCount(/*bUsed=*/true));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */