From 5013ac55090ab7a64b9549df67196aa5c7479542 Mon Sep 17 00:00:00 2001 From: Tobias Lippert Date: Thu, 7 Aug 2014 22:30:58 +0200 Subject: fdo#84061 Fix setting text style sheet listeners in SdrTextObj MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code in SdrTextObj::ImpSetTextStyleSheetListeners is obviously not working correctly. The families of the stylesheets are appended to the name of the family for further usage. An encoded string looks like "STYLE_NAME|3 " The family is then extracted by copying the first (length-6) bytes, e.g., "STYLE_NAME" in this example. Then another copy starting a position 1 is created, e.g., "TYLE_NAME". This string is cast to an Int32. Since this is not possible, 0 is returned, and the originally stored family is lost. This patch corrects this behavior, and adds a unit test. Change-Id: I60c0add6e4b670acbbc264cc77672452f282f737 Reviewed-on: https://gerrit.libreoffice.org/10818 Reviewed-by: Matúš Kukan Tested-by: Matúš Kukan --- svx/qa/unit/svdraw/test_SdrTextObject.cxx | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 svx/qa/unit/svdraw/test_SdrTextObject.cxx (limited to 'svx/qa/unit') diff --git a/svx/qa/unit/svdraw/test_SdrTextObject.cxx b/svx/qa/unit/svdraw/test_SdrTextObject.cxx new file mode 100644 index 000000000000..fe16805ade14 --- /dev/null +++ b/svx/qa/unit/svdraw/test_SdrTextObject.cxx @@ -0,0 +1,48 @@ +/* -*- 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 +#include + +#include +#include +#include +#include + +#include + +class SdrTextObjTest : public CppUnit::TestFixture { +public: + void AllFamiliesCanBeRestoredFromSavedString(); + + CPPUNIT_TEST_SUITE(SdrTextObjTest); + CPPUNIT_TEST(AllFamiliesCanBeRestoredFromSavedString); + CPPUNIT_TEST_SUITE_END(); +}; + +void SdrTextObjTest::AllFamiliesCanBeRestoredFromSavedString() { + std::vector allFamilies; + allFamilies.push_back(SFX_STYLE_FAMILY_CHAR); + allFamilies.push_back(SFX_STYLE_FAMILY_PARA); + allFamilies.push_back(SFX_STYLE_FAMILY_PAGE); + allFamilies.push_back(SFX_STYLE_FAMILY_PSEUDO); + + BOOST_FOREACH(SfxStyleFamily family, allFamilies) { + OUString styleName = "styleName"; + SdrTextObj::AppendFamilyToStyleName(styleName, family); + SfxStyleFamily readFamily = SdrTextObj::ReadFamilyFromStyleName(styleName); + CPPUNIT_ASSERT_EQUAL(family, readFamily); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(SdrTextObjTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit