diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-07-09 18:03:04 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-07-09 20:04:26 +0200 |
commit | 9d754a59154c40235c240bb0e7f47a2006fa85bd (patch) | |
tree | 24a1811bbcb16f48c1eabbcee4fb926e92a77ad0 /sw/qa/extras/unowriter | |
parent | 5f3914ad67584fc4731c394c969baaa017ba75b7 (diff) |
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.
Change-Id: I0a2b02378dce53c6b79c57780d1b7f14e89242e8
Reviewed-on: https://gerrit.libreoffice.org/57191
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa/extras/unowriter')
-rw-r--r-- | sw/qa/extras/unowriter/unowriter.cxx | 53 |
1 files changed, 53 insertions, 0 deletions
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: */ |