[Libreoffice-commits] core.git: Branch 'distro/vector/vector-5.4' - sw/CppunitTest_sw_unowriter.mk sw/Module_sw.mk sw/qa sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue Jul 10 07:57:13 UTC 2018
sw/CppunitTest_sw_unowriter.mk | 76 +++++++++++++++++++++++++++++++
sw/Module_sw.mk | 1
sw/qa/extras/unowriter/unowriter.cxx | 53 +++++++++++++++++++++
sw/qa/python/check_styles.py | 2
sw/source/core/doc/SwStyleNameMapper.cxx | 15 ++++--
5 files changed, 143 insertions(+), 4 deletions(-)
New commits:
commit 00ce7f92dcb1c0ef7984f6f1eabb720ba65e5b92
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Jul 9 18:03:04 2018 +0200
sw: give the 'Default Style' char style a programmatic name
So that referring to that style is possible from UNO API client code in
a way that is portable across multiple locales.
This also improves consistency between the default para and default char
styles, as the default para style already had this behavior.
Also add a new CppunitTest_sw_unowriter for such tests which assert the
UNO API from cppunit, instead of hacking this into
CppunitTest_sw_uiwriter.
Reviewed-on: https://gerrit.libreoffice.org/57191
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins
(cherry picked from commit 9d754a59154c40235c240bb0e7f47a2006fa85bd)
Conflicts:
sw/Module_sw.mk
sw/source/core/doc/SwStyleNameMapper.cxx
Change-Id: I0a2b02378dce53c6b79c57780d1b7f14e89242e8
diff --git a/sw/CppunitTest_sw_unowriter.mk b/sw/CppunitTest_sw_unowriter.mk
new file mode 100644
index 000000000000..a51f4ac38000
--- /dev/null
+++ b/sw/CppunitTest_sw_unowriter.mk
@@ -0,0 +1,76 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_unowriter))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_unowriter, \
+ sw/qa/extras/unowriter/unowriter \
+))
+
+# note: this links msword only for the reason to have a order dependency,
+# because "make sw.check" will not see the dependency through services.rdb
+$(eval $(call gb_CppunitTest_use_libraries,sw_unowriter, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ editeng \
+ msword \
+ sal \
+ sfx \
+ svl \
+ svt \
+ svxcore \
+ sw \
+ test \
+ unotest \
+ vcl \
+ tl \
+ utl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_unowriter,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_unowriter,\
+ -I$(SRCDIR)/sw/inc \
+ -I$(SRCDIR)/sw/source/core/inc \
+ -I$(SRCDIR)/sw/qa/extras/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_unowriter,\
+ udkapi \
+ offapi \
+ oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_unowriter))
+$(eval $(call gb_CppunitTest_use_vcl,sw_unowriter))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_unowriter,services))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_unowriter))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_unowriter, \
+ modules/swriter \
+))
+
+$(call gb_CppunitTest_get_target,sw_unowriter): \
+ $(call gb_Library_get_target,textconv_dict)
+
+ifneq ($(filter MORE_FONTS,$(BUILD_TYPE)),)
+$(call gb_CppunitTest_get_target,sw_unowriter): \
+ $(call gb_ExternalPackage_get_target,fonts_liberation)
+endif
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 0ab442fb3c7b..6560faab37ae 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -78,6 +78,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_uiwriter \
CppunitTest_sw_mailmerge \
CppunitTest_sw_globalfilter \
+ CppunitTest_sw_unowriter \
))
ifneq ($(ENABLE_HEADLESS),TRUE)
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
new file mode 100644
index 000000000000..59a045586423
--- /dev/null
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+#include <com/sun/star/awt/FontSlant.hpp>
+
+/// Test to assert UNO API call results of Writer.
+class SwUnoWriter : public SwModelTestBase
+{
+public:
+ void testDefaultCharStyle();
+
+ CPPUNIT_TEST_SUITE(SwUnoWriter);
+ CPPUNIT_TEST(testDefaultCharStyle);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void SwUnoWriter::testDefaultCharStyle()
+{
+ // Create a new document, type a character, set its char style to Emphasis
+ // and assert the style was set.
+ loadURL("private:factory/swriter", nullptr);
+
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XSimpleText> xBodyText(xTextDocument->getText(), uno::UNO_QUERY);
+ xBodyText->insertString(xBodyText->getStart(), "x", false);
+
+ uno::Reference<text::XTextCursor> xCursor(xBodyText->createTextCursor());
+ xCursor->goLeft(1, true);
+
+ uno::Reference<beans::XPropertySet> xCursorProps(xCursor, uno::UNO_QUERY);
+ xCursorProps->setPropertyValue("CharStyleName", uno::makeAny(OUString("Emphasis")));
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC,
+ getProperty<awt::FontSlant>(xCursorProps, "CharPosture"));
+
+ // Now reset the char style and assert that the font slant is back to none.
+ // This resulted in a lang.IllegalArgumentException, Standard was not
+ // mapped to 'Default Style'.
+ xCursorProps->setPropertyValue("CharStyleName", uno::makeAny(OUString("Standard")));
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE,
+ getProperty<awt::FontSlant>(xCursorProps, "CharPosture"));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SwUnoWriter);
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/python/check_styles.py b/sw/qa/python/check_styles.py
index 29fddf6433d6..5d7f8326380f 100644
--- a/sw/qa/python/check_styles.py
+++ b/sw/qa/python/check_styles.py
@@ -123,7 +123,7 @@ class CheckStyle(unittest.TestCase):
def test_CharacterFamily(self):
xDoc = CheckStyle._uno.openEmptyWriterDoc()
xCharStyles = xDoc.StyleFamilies["CharacterStyles"]
- vEmptyDocStyles = ['Default Style', 'Footnote Symbol', 'Page Number', 'Caption characters', 'Drop Caps', 'Numbering Symbols', 'Bullet Symbols', 'Internet link', 'Visited Internet Link', 'Placeholder', 'Index Link', 'Endnote Symbol', 'Line numbering', 'Main index entry', 'Footnote anchor', 'Endnote anchor', 'Rubies', 'Vertical Numbering Symbols', 'Emphasis', 'Citation', 'Strong Emphasis', 'Source Text', 'Example', 'User Entry', 'Variable', 'Definition', 'Teletype']
+ vEmptyDocStyles = ['Standard', 'Footnote Symbol', 'Page Number', 'Caption characters', 'Drop Caps', 'Numbering Symbols', 'Bullet Symbols', 'Internet link', 'Visited Internet Link', 'Placeholder', 'Index Link', 'Endnote Symbol', 'Line numbering', 'Main index entry', 'Footnote anchor', 'Endnote anchor', 'Rubies', 'Vertical Numbering Symbols', 'Emphasis', 'Citation', 'Strong Emphasis', 'Source Text', 'Example', 'User Entry', 'Variable', 'Definition', 'Teletype']
self.__test_StyleFamily(xCharStyles, vEmptyDocStyles, "SwXStyle")
self.__test_StyleFamilyIndex(xCharStyles, vEmptyDocStyles, "SwXStyle")
self.__test_StyleFamilyInsert(xDoc, xCharStyles, vEmptyDocStyles, "com.sun.star.style.CharacterStyle", "com.sun.star.style.ParagraphStyle")
diff --git a/sw/source/core/doc/SwStyleNameMapper.cxx b/sw/source/core/doc/SwStyleNameMapper.cxx
index eab9bb0e781d..17d9acbe4a40 100644
--- a/sw/source/core/doc/SwStyleNameMapper.cxx
+++ b/sw/source/core/doc/SwStyleNameMapper.cxx
@@ -24,6 +24,8 @@
#include <tools/resmgr.hxx>
#include <poolfmt.hxx>
#include <rcid.hrc>
+#include <poolfmt.hrc>
+#include <swtypes.hxx>
#ifdef _NEED_TO_DEBUG_MAPPING
#include <stdlib.h>
@@ -604,6 +606,9 @@ void SwStyleNameMapper::FillProgName(
// If we aren't trying to disambiguate, then just do a normal fill
fillNameFromId(nId, rFillName, true);
}
+
+ if (eFlags == SwGetPoolIdFromName::ChrFmt && rName == SwResId(STR_POOLCOLL_STANDARD))
+ rFillName = "Standard";
}
// Get the UI name from the programmatic name in rName and put it into rFillName
@@ -611,11 +616,15 @@ void SwStyleNameMapper::FillUIName(
const OUString& rName, OUString& rFillName,
SwGetPoolIdFromName const eFlags, bool const bDisambiguate)
{
- sal_uInt16 nId = GetPoolIdFromProgName ( rName, eFlags );
+ OUString aName = rName;
+ if (eFlags == SwGetPoolIdFromName::ChrFmt && rName == "Standard")
+ aName = SwResId(STR_POOLCOLL_STANDARD);
+
+ sal_uInt16 nId = GetPoolIdFromProgName ( aName, eFlags );
if ( bDisambiguate && nId == USHRT_MAX )
{
- rFillName = rName;
- // rName isn't in our Prog name table...check if it has a " (user)" suffix, if so remove it
+ rFillName = aName;
+ // aName isn't in our Prog name table...check if it has a " (user)" suffix, if so remove it
lcl_CheckSuffixAndDelete ( rFillName );
}
else
More information about the Libreoffice-commits
mailing list