summaryrefslogtreecommitdiff
path: root/sw/qa/extras/unowriter
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2019-11-19 17:33:05 +0100
committerMichael Stahl <michael.stahl@cib.de>2019-11-20 16:51:38 +0100
commit3073a6de85d5d7fd8837d1ae25306d03e857f8d7 (patch)
tree5d7dea6754ae0e51c80f05157d1ce73aac04a597 /sw/qa/extras/unowriter
parentc57e759cb7729896271c0bc521d5cb9626c2c570 (diff)
sw: revert change in expanding hints in SwXText::insertTextContent()
The SwXText implementation for inserting text works like this: * XTextPortionAppend methods appendTextPortion()/insertTextPortion() get the text properties passed as a parameter, and they should apply only those properties to the inserted text, not expand any existing formatting hints at the insert position. * XSimpleText method insertString() does expand existing formatting at the insert position, just like editing in the UI does For inserting XTextContent: * XTextContentAppend methods appendTextContent()/insertTextContentWithProperties() with properties parameter, similar to XTextPortionAppend * XTextContent::insertTextContent(), without properties So arguably, by analogy to inserting text, the methods that take properties should not expand hints, and the insertTextContent() should follow the insertString and expand hints. Commit 18cbb8fe699131a234355e1d00fa917fede6ac46 is an important bugfix for writerfilter import, but the problem is, it added the DontExpandFormat() call to insertTextContent(), whereas the regression it was fixing (from commit 232ad2f2588beff50cb5c1f3b689c581ba317583) was that the call was removed from insertTextContentWithProperties(). So restore the state before 232ad2f2588beff50cb5c1f3b689c581ba317583. Turns out that SwUiWriterTest2::testTdf126206 was checking how a bookmark-start is formatted instead of how the text is formatted. Change-Id: If524409f88a1a36aa062b6e132996d3f9c1bb571 Reviewed-on: https://gerrit.libreoffice.org/83223 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de> (cherry picked from commit 635bd7fbcb1d131627ba98fd9085dd2b11e0d33c) Reviewed-on: https://gerrit.libreoffice.org/83292
Diffstat (limited to 'sw/qa/extras/unowriter')
-rw-r--r--sw/qa/extras/unowriter/unowriter.cxx91
1 files changed, 91 insertions, 0 deletions
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index f1b2b7671cdf..577a4b50db89 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -12,6 +12,8 @@
#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <com/sun/star/text/AutoTextContainer.hpp>
#include <com/sun/star/text/XAutoTextGroup.hpp>
+#include <com/sun/star/text/XTextPortionAppend.hpp>
+#include <com/sun/star/text/XTextContentAppend.hpp>
#include <com/sun/star/rdf/URI.hpp>
#include <com/sun/star/rdf/URIs.hpp>
#include <com/sun/star/awt/XDevice.hpp>
@@ -115,6 +117,95 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testDefaultCharStyle)
getProperty<awt::FontSlant>(xCursorProps, "CharPosture"));
}
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testInsertStringExpandsHints)
+{
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<text::XTextDocument> const xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> const xText(xTextDocument->getText());
+ uno::Reference<text::XTextCursor> const xCursor(xText->createTextCursor());
+ uno::Reference<beans::XPropertySet> const xProps(xCursor, uno::UNO_QUERY);
+
+ xText->insertString(xCursor, "ab", false);
+ xCursor->gotoStart(false);
+ xCursor->goRight(1, true);
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+ xProps->setPropertyValue("CharPosture", uno::Any(awt::FontSlant_ITALIC));
+ xCursor->collapseToEnd();
+ xText->insertString(xCursor, "x", false);
+ xCursor->goLeft(1, true);
+ CPPUNIT_ASSERT_EQUAL(OUString("x"), xCursor->getString());
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+}
+
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testInsertTextPortionNotExpandsHints)
+{
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<text::XTextDocument> const xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> const xText(xTextDocument->getText());
+ uno::Reference<text::XTextPortionAppend> const xTextA(xText, uno::UNO_QUERY);
+ uno::Reference<text::XTextCursor> const xCursor(xText->createTextCursor());
+ uno::Reference<beans::XPropertySet> const xProps(xCursor, uno::UNO_QUERY);
+
+ xText->insertString(xCursor, "ab", false);
+ xCursor->gotoStart(false);
+ xCursor->goRight(1, true);
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+ xProps->setPropertyValue("CharPosture", uno::Any(awt::FontSlant_ITALIC));
+ xCursor->collapseToEnd();
+ xTextA->insertTextPortion("x", uno::Sequence<beans::PropertyValue>(), xCursor);
+ xCursor->goLeft(1, true);
+ CPPUNIT_ASSERT_EQUAL(OUString("x"), xCursor->getString());
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+}
+
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testInsertTextContentExpandsHints)
+{
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<text::XTextDocument> const xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<lang::XMultiServiceFactory> const xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> const xText(xTextDocument->getText());
+ uno::Reference<text::XTextCursor> const xCursor(xText->createTextCursor());
+ uno::Reference<beans::XPropertySet> const xProps(xCursor, uno::UNO_QUERY);
+
+ xText->insertString(xCursor, "ab", false);
+ xCursor->gotoStart(false);
+ xCursor->goRight(1, true);
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+ xProps->setPropertyValue("CharPosture", uno::Any(awt::FontSlant_ITALIC));
+ xCursor->collapseToEnd();
+ uno::Reference<text::XTextContent> const xContent(
+ xFactory->createInstance("com.sun.star.text.Footnote"), uno::UNO_QUERY);
+ xText->insertTextContent(xCursor, xContent, false);
+ xCursor->goLeft(1, true);
+ CPPUNIT_ASSERT_EQUAL(OUString("1"), xCursor->getString());
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+}
+
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testInsertTextContentWithPropertiesNotExpandsHints)
+{
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<text::XTextDocument> const xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<lang::XMultiServiceFactory> const xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> const xText(xTextDocument->getText());
+ uno::Reference<text::XTextContentAppend> const xTextA(xText, uno::UNO_QUERY);
+ uno::Reference<text::XTextCursor> const xCursor(xText->createTextCursor());
+ uno::Reference<beans::XPropertySet> const xProps(xCursor, uno::UNO_QUERY);
+
+ xText->insertString(xCursor, "ab", false);
+ xCursor->gotoStart(false);
+ xCursor->goRight(1, true);
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+ xProps->setPropertyValue("CharPosture", uno::Any(awt::FontSlant_ITALIC));
+ xCursor->collapseToEnd();
+ uno::Reference<text::XTextContent> const xContent(
+ xFactory->createInstance("com.sun.star.text.Footnote"), uno::UNO_QUERY);
+ xTextA->insertTextContentWithProperties(xContent, uno::Sequence<beans::PropertyValue>(),
+ xCursor);
+ xCursor->goLeft(1, true);
+ CPPUNIT_ASSERT_EQUAL(OUString("1"), xCursor->getString());
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+}
+
CPPUNIT_TEST_FIXTURE(SwUnoWriter, testGraphicDesciptorURL)
{
loadURL("private:factory/swriter", nullptr);