diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-09-14 15:30:18 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-09-14 15:31:07 +0100 |
commit | 8578e3c80d99da0b47cd450a9be61cef28f411b0 (patch) | |
tree | 9d728d45a782ceec405e8ec1af2f26ad502c6b2b | |
parent | c046147142ac08a53ff3fe0dfe59afce69f09cdf (diff) |
Related: fdo#40599 add a initial basic test for deleting graphics
-rw-r--r-- | sw/qa/core/swdoc-test.cxx | 61 | ||||
-rwxr-xr-x | sw/source/ui/dochdl/swdtflvr.cxx | 4 |
2 files changed, 63 insertions, 2 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) { diff --git a/sw/source/ui/dochdl/swdtflvr.cxx b/sw/source/ui/dochdl/swdtflvr.cxx index 10c4df3ca6da..9071837531c6 100755 --- a/sw/source/ui/dochdl/swdtflvr.cxx +++ b/sw/source/ui/dochdl/swdtflvr.cxx @@ -724,8 +724,8 @@ sal_Bool SwTransferable::WriteObject( SotStorageStreamRef& xStream, xWrt->SetShowProgress( sal_False ); #if defined(DEBUGPASTE) - SvFileStream aPasteDebug(rtl::OUString::createFromAscii( - "PASTEBUFFER.debug"), STREAM_READWRITE); + SvFileStream aPasteDebug(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "PASTEBUFFER.debug")), STREAM_WRITE|STREAM_TRUNC); SwWriter aDbgWrt( aPasteDebug, *pDoc ); aDbgWrt.Write( xWrt ); #endif |