From f8db2d7533785b89a149e7879d7a3c1909d41e6b Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 2 Jul 2015 16:06:41 +0530 Subject: Add test for tdf#90808 duplicate CrossRefBookmarks Change-Id: I4aad0cbb07c07cfcb80bccbbd55d9a26fae88f73 Reviewed-on: https://gerrit.libreoffice.org/16689 Reviewed-by: Michael Stahl Tested-by: Michael Stahl --- sw/qa/extras/uiwriter/uiwriter.cxx | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 0339860beb67..6138ed2968fd 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -54,6 +54,7 @@ #include "com/sun/star/util/SearchAlgorithms.hpp" #include "com/sun/star/i18n/TransliterationModulesExtra.hpp" #include "com/sun/star/sdbcx/XTablesSupplier.hpp" +#include "com/sun/star/text/XParagraphCursor.hpp" #include static const char* DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/"; @@ -101,6 +102,7 @@ public: void testTdf69282(); void testTdf69282WithMirror(); void testSearchWithTransliterate(); + void testTdf90808(); void testTdf75137(); void testTdf83798(); void testTableBackgroundColor(); @@ -150,6 +152,7 @@ public: CPPUNIT_TEST(testTdf69282); CPPUNIT_TEST(testTdf69282WithMirror); CPPUNIT_TEST(testSearchWithTransliterate); + CPPUNIT_TEST(testTdf90808); CPPUNIT_TEST(testTdf75137); CPPUNIT_TEST(testTdf83798); CPPUNIT_TEST(testTableBackgroundColor); @@ -1180,6 +1183,51 @@ void SwUiWriterTest::testSearchWithTransliterate() CPPUNIT_ASSERT_EQUAL(1,(int)case2); } +void SwUiWriterTest::testTdf90808() +{ + createDoc(); + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xTextRange(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference xText(xTextRange->getText(), uno::UNO_QUERY); + uno::Reference xCrsr(xText->createTextCursor(), uno::UNO_QUERY); + //inserting text into document so that the paragraph is not empty + xText->setString(OUString("Hello World!")); + uno::Reference xFact(mxComponent, uno::UNO_QUERY); + //creating bookmark 1 + uno::Reference type1bookmark1(xFact->createInstance("com.sun.star.text.Bookmark"), uno::UNO_QUERY); + uno::Reference xName1(type1bookmark1, uno::UNO_QUERY); + xName1->setName("__RefHeading__1"); + //moving cursor to the starting of paragraph + xCrsr->gotoStartOfParagraph(false); + //inserting the bookmark in paragraph + xText->insertTextContent(xCrsr, type1bookmark1, true); + //creating bookmark 2 + uno::Reference type1bookmark2(xFact->createInstance("com.sun.star.text.Bookmark"), uno::UNO_QUERY); + uno::Reference xName2(type1bookmark2, uno::UNO_QUERY); + xName2->setName("__RefHeading__2"); + //inserting the bookmark in same paragraph, at the end + //only one bookmark of this type is allowed in each paragraph an exception of com.sun.star.lang.IllegalArgumentException must be thrown when inserting the other bookmark in same paragraph + xCrsr->gotoEndOfParagraph(true); + CPPUNIT_ASSERT_THROW(xText->insertTextContent(xCrsr, type1bookmark2, true), com::sun::star::lang::IllegalArgumentException); + //now testing for __RefNumPara__ + //creating bookmark 1 + uno::Reference type2bookmark1(xFact->createInstance("com.sun.star.text.Bookmark"), uno::UNO_QUERY); + uno::Reference xName3(type2bookmark1, uno::UNO_QUERY); + xName3->setName("__RefNumPara__1"); + //moving cursor to the starting of paragraph + xCrsr->gotoStartOfParagraph(false); + //inserting the bookmark in paragraph + xText->insertTextContent(xCrsr, type2bookmark1, true); + //creating bookmark 2 + uno::Reference type2bookmark2(xFact->createInstance("com.sun.star.text.Bookmark"), uno::UNO_QUERY); + uno::Reference xName4(type2bookmark2, uno::UNO_QUERY); + xName4->setName("__RefNumPara__2"); + //inserting the bookmark in same paragraph, at the end + //only one bookmark of this type is allowed in each paragraph an exception of com.sun.star.lang.IllegalArgumentException must be thrown when inserting the other bookmark in same paragraph + xCrsr->gotoEndOfParagraph(true); + CPPUNIT_ASSERT_THROW(xText->insertTextContent(xCrsr, type2bookmark2, true), com::sun::star::lang::IllegalArgumentException); +} + void SwUiWriterTest::testTdf75137() { SwDoc* pDoc = createDoc(); -- cgit v1.2.3