[Libreoffice-commits] core.git: sw/qa

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 6 08:30:50 UTC 2021


 sw/qa/extras/uiwriter/uiwriter3.cxx |   46 ++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

New commits:
commit a90a324aa590a94a4091fbfadea67e0b0203767c
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Apr 6 10:23:03 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Tue Apr 6 10:30:06 2021 +0200

    tdf#136740: add unit test
    
    Change-Id: Iaa42bc466de2d3f27db5e9dbb516026d140ee0fc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113622
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index 16cb96bf4186..8454b3ed92e4 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -2697,6 +2697,52 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf138897)
     Scheduler::ProcessEventsToIdle();
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf136740)
+{
+    mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+    css::uno::Reference<css::lang::XMultiServiceFactory> xFact(mxComponent,
+                                                               css::uno::UNO_QUERY_THROW);
+    css::uno::Reference<css::beans::XPropertySet> xTextDefaults(
+        xFact->createInstance("com.sun.star.text.Defaults"), css::uno::UNO_QUERY_THROW);
+    const css::uno::Any aOrig = xTextDefaults->getPropertyValue("TabStopDistance");
+    sal_Int32 nDefTab = aOrig.get<sal_Int32>();
+    CPPUNIT_ASSERT(nDefTab != 0);
+
+    css::uno::Reference<css::text::XTextRange> const xParagraph(getParagraphOrTable(1),
+                                                                css::uno::UNO_QUERY_THROW);
+    xParagraph->setString("Foo");
+
+    CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
+    CPPUNIT_ASSERT_EQUAL(OUString("Foo"), xParagraph->getString());
+
+    dispatchCommand(mxComponent, ".uno:SelectAll", {});
+    dispatchCommand(mxComponent, ".uno:Copy", {});
+    dispatchCommand(mxComponent, ".uno:GoToEndOfDoc", {});
+
+    const css::uno::Any aNew(nDefTab * 2);
+    xTextDefaults->setPropertyValue("TabStopDistance", aNew);
+    // it may become slightly different because of conversions, so get the actual value
+    const css::uno::Any aNewCorrected = xTextDefaults->getPropertyValue("TabStopDistance");
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(nDefTab * 2, aNewCorrected.get<sal_Int32>(), 1);
+
+    // Paste special as RTF
+    const auto aPropertyValues = comphelper::InitPropertySequence(
+        { { "SelectedFormat",
+            css::uno::Any(static_cast<sal_uInt32>(SotClipboardFormatId::RTF)) } });
+    dispatchCommand(mxComponent, ".uno:ClipboardFormatItems", aPropertyValues);
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
+    CPPUNIT_ASSERT_EQUAL(OUString("FooFoo"), xParagraph->getString());
+
+    // Without the fix in place, this would fail with
+    //     equality assertion failed
+    //     - Expected: <Any: (long) 2501>
+    //     - Actual  : <Any: (long) 1251>
+    // i.e., pasting RTF would reset the modified default tab stop distance to hardcoded default
+    CPPUNIT_ASSERT_EQUAL(aNewCorrected, xTextDefaults->getPropertyValue("TabStopDistance"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list