From a90a324aa590a94a4091fbfadea67e0b0203767c Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Tue, 6 Apr 2021 10:23:03 +0300 Subject: tdf#136740: add unit test Change-Id: Iaa42bc466de2d3f27db5e9dbb516026d140ee0fc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113622 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- sw/qa/extras/uiwriter/uiwriter3.cxx | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) 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 xFact(mxComponent, + css::uno::UNO_QUERY_THROW); + css::uno::Reference 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(); + CPPUNIT_ASSERT(nDefTab != 0); + + css::uno::Reference 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(), 1); + + // Paste special as RTF + const auto aPropertyValues = comphelper::InitPropertySequence( + { { "SelectedFormat", + css::uno::Any(static_cast(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: + // - Actual : + // 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: */ -- cgit