summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/extras/layout/data/image-comment.odtbin0 -> 10445 bytes
-rw-r--r--sw/qa/extras/layout/layout.cxx40
2 files changed, 40 insertions, 0 deletions
diff --git a/sw/qa/extras/layout/data/image-comment.odt b/sw/qa/extras/layout/data/image-comment.odt
new file mode 100644
index 000000000000..d861d3a9aa03
--- /dev/null
+++ b/sw/qa/extras/layout/data/image-comment.odt
Binary files differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 2f69230849e1..1de7bba9d926 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -25,6 +25,11 @@
#include <edtwin.hxx>
#include <view.hxx>
#include <txtfrm.hxx>
+#include <pagefrm.hxx>
+#include <bodyfrm.hxx>
+#include <sortedobjs.hxx>
+#include <anchoredobject.hxx>
+#include <ndtxt.hxx>
static char const DATA_DIRECTORY[] = "/sw/qa/extras/layout/data/";
@@ -2978,6 +2983,41 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTabOverMargin)
assertXPath(pXmlDoc, "/root/page/body/txt[2]/LineBreak", 1);
}
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testImageComment)
+{
+ // Load a document that has "aaa" in it, then a commented image (4th char is the as-char image,
+ // 5th char is the comment anchor).
+ SwDoc* pDoc = createDoc("image-comment.odt");
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+ // Look up a layout position which is on the right of the image.
+ SwRootFrame* pRoot = pWrtShell->GetLayout();
+ CPPUNIT_ASSERT(pRoot->GetLower()->IsPageFrame());
+ SwPageFrame* pPage = static_cast<SwPageFrame*>(pRoot->GetLower());
+ CPPUNIT_ASSERT(pPage->GetLower()->IsBodyFrame());
+ SwBodyFrame* pBody = static_cast<SwBodyFrame*>(pPage->GetLower());
+ CPPUNIT_ASSERT(pBody->GetLower()->IsTextFrame());
+ SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pBody->GetLower());
+ CPPUNIT_ASSERT(pTextFrame->GetDrawObjs());
+ SwSortedObjs& rDrawObjs = *pTextFrame->GetDrawObjs();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rDrawObjs.size());
+ SwAnchoredObject* pDrawObj = rDrawObjs[0];
+ const SwRect& rDrawObjRect = pDrawObj->GetObjRect();
+ Point aPoint = rDrawObjRect.Center();
+ aPoint.setX(aPoint.getX() + rDrawObjRect.Width() / 2);
+
+ // Ask for the doc model pos of this layout point.
+ SwPosition aPosition(*pTextFrame->GetTextNodeForFirstText());
+ pTextFrame->GetCursorOfst(&aPosition, aPoint);
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 5
+ // - Actual : 4
+ // i.e. the cursor got positioned between the image and its comment, so typing extended the
+ // comment, instead of adding content after the commented image.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), aPosition.nContent.GetIndex());
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */