summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-09-14 15:30:18 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-09-14 15:31:07 +0100
commit8578e3c80d99da0b47cd450a9be61cef28f411b0 (patch)
tree9d728d45a782ceec405e8ec1af2f26ad502c6b2b /sw/qa
parentc046147142ac08a53ff3fe0dfe59afce69f09cdf (diff)
Related: fdo#40599 add a initial basic test for deleting graphics
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/core/swdoc-test.cxx61
1 files changed, 61 insertions, 0 deletions
diff --git a/sw/qa/core/swdoc-test.cxx b/sw/qa/core/swdoc-test.cxx
index 903b6dd207d3..6c910953a09f 100644
--- a/sw/qa/core/swdoc-test.cxx
+++ b/sw/qa/core/swdoc-test.cxx
@@ -66,9 +66,11 @@
#include "docsh.hxx"
#include "shellres.hxx"
#include "docufld.hxx"
+#include "fmtanchr.hxx"
#include "swscanner.hxx"
#include "swcrsr.hxx"
#include "swmodule.hxx"
+#include "shellio.hxx"
SO2_DECL_REF(SwDocShell)
SO2_IMPL_REF(SwDocShell)
@@ -91,6 +93,7 @@ public:
void testFileNameFields();
void testDocStat();
void testSwScanner();
+ void testGraphicAnchorDeletion();
CPPUNIT_TEST_SUITE(SwDocTest);
CPPUNIT_TEST(randomTest);
@@ -98,6 +101,7 @@ public:
CPPUNIT_TEST(testFileNameFields);
CPPUNIT_TEST(testDocStat);
CPPUNIT_TEST(testSwScanner);
+ CPPUNIT_TEST(testGraphicAnchorDeletion);
CPPUNIT_TEST_SUITE_END();
private:
@@ -237,6 +241,63 @@ void SwDocTest::testSwScanner()
rWorld.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("World")));
}
+//See https://bugs.freedesktop.org/show_bug.cgi?id=40599 for motivation
+void SwDocTest::testGraphicAnchorDeletion()
+{
+ CPPUNIT_ASSERT_MESSAGE("Expected initial 0 count", m_pDoc->GetDocStat().nChar == 0);
+
+ SwNodeIndex aIdx(m_pDoc->GetNodes().GetEndOfContent(), -1);
+ SwPaM aPaM(aIdx);
+
+ m_pDoc->InsertString(aPaM, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Paragraph 1")));
+ m_pDoc->AppendTxtNode(*aPaM.GetPoint());
+
+ m_pDoc->InsertString(aPaM, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("graphic anchor>><<graphic anchor")));
+ SwNodeIndex nPara2 = aPaM.GetPoint()->nNode;
+ m_pDoc->AppendTxtNode(*aPaM.GetPoint());
+
+ m_pDoc->InsertString(aPaM, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Paragraph 3")));
+
+ aPaM.GetPoint()->nNode = nPara2;
+ aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(), RTL_CONSTASCII_LENGTH("graphic anchor>>"));
+
+ //Insert a graphic at X of >>X<< in paragraph 2
+ SfxItemSet aFlySet(m_pDoc->GetAttrPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1);
+ SwFmtAnchor aAnchor(FLY_AS_CHAR);
+ aAnchor.SetAnchor(aPaM.GetPoint());
+ aFlySet.Put(aAnchor);
+ SwFlyFrmFmt *pFrame = m_pDoc->Insert(aPaM, rtl::OUString(), rtl::OUString(), NULL, &aFlySet, NULL, NULL);
+ CPPUNIT_ASSERT_MESSAGE("Expected frame", pFrame != NULL);
+
+ CPPUNIT_ASSERT_MESSAGE("Should be 1 graphic", m_pDoc->GetFlyCount(FLYCNTTYPE_GRF) == 1);
+
+ //Delete >X<
+ aPaM.GetPoint()->nNode = nPara2;
+ aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(),
+ RTL_CONSTASCII_LENGTH("graphic anchor>><")+1);
+ aPaM.SetMark();
+ aPaM.GetPoint()->nNode = nPara2;
+ aPaM.GetPoint()->nContent.Assign(aPaM.GetCntntNode(), RTL_CONSTASCII_LENGTH("graphic anchor>"));
+ m_pDoc->DeleteRange(aPaM);
+
+#ifdef DEBUG_AS_HTML
+ {
+ SvFileStream aPasteDebug(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "cppunitDEBUG.html")), STREAM_WRITE|STREAM_TRUNC);
+ WriterRef xWrt;
+ GetHTMLWriter( String(), String(), xWrt );
+ SwWriter aDbgWrt( aPasteDebug, *m_pDoc );
+ aDbgWrt.Write( xWrt );
+ }
+#endif
+
+ CPPUNIT_ASSERT_MESSAGE("Should be 0 graphics", m_pDoc->GetFlyCount(FLYCNTTYPE_GRF) == 0);
+
+ //Now, if instead we swap FLY_AS_CHAR (inline graphic) to FLY_AT_CHAR (anchored to character)
+ //and repeat the above, graphic is *not* deleted, i.e. it belongs to the paragraph, not the
+ //range to which its anchored, which is annoying.
+}
+
static int
getRand(int modulus)
{