Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / qa / unit / styles.cxx
blob05eeb451ba1b6407b7d1c277c66bb63902a1c7cd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <test/unoapi_test.hxx>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
14 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
15 #include <com/sun/star/text/XTextRange.hpp>
16 #include <docmodel/uno/UnoComplexColor.hxx>
18 using namespace ::com::sun::star;
20 namespace
22 /// Tests for svx/source/styles/ code.
23 class Test : public UnoApiTest
25 public:
26 Test()
27 : UnoApiTest("svx/qa/unit/data/")
32 /// Get the character color of the first text portion in xShape.
33 Color GetShapeTextColor(const uno::Reference<text::XTextRange>& xShape)
35 uno::Reference<container::XEnumerationAccess> xText(xShape->getText(), uno::UNO_QUERY);
36 uno::Reference<container::XEnumerationAccess> xPara(xText->createEnumeration()->nextElement(),
37 uno::UNO_QUERY);
38 uno::Reference<beans::XPropertySet> xPortion(xPara->createEnumeration()->nextElement(),
39 uno::UNO_QUERY);
40 Color nColor{};
41 xPortion->getPropertyValue("CharColor") >>= nColor;
42 return nColor;
45 /// Get the solid fill color of xShape.
46 Color GetShapeFillColor(const uno::Reference<beans::XPropertySet>& xShape)
48 Color nColor{};
49 xShape->getPropertyValue("FillColor") >>= nColor;
50 return nColor;
53 CPPUNIT_TEST_FIXTURE(Test, testThemeChange)
55 // Given a document, with a first slide and blue shape text from theme:
56 loadFromURL(u"theme.pptx");
57 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
58 // The draw page also contains a group shape to make sure we don't crash on group shapes.
59 uno::Reference<drawing::XMasterPageTarget> xDrawPage(
60 xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
61 uno::Reference<drawing::XShapes> xDrawPageShapes(xDrawPage, uno::UNO_QUERY);
62 uno::Reference<text::XTextRange> xShape(xDrawPageShapes->getByIndex(0), uno::UNO_QUERY);
63 // Blue.
64 CPPUNIT_ASSERT_EQUAL(Color(0x4472c4), GetShapeTextColor(xShape));
65 uno::Reference<text::XTextRange> xShape2(xDrawPageShapes->getByIndex(1), uno::UNO_QUERY);
66 // Blue, lighter.
67 CPPUNIT_ASSERT_EQUAL(Color(0xb4c7e7), GetShapeTextColor(xShape2));
68 uno::Reference<text::XTextRange> xShape3(xDrawPageShapes->getByIndex(2), uno::UNO_QUERY);
69 // Blue, darker.
70 CPPUNIT_ASSERT_EQUAL(Color(0x2f5597), GetShapeTextColor(xShape3));
71 // Shape fill:
72 uno::Reference<beans::XPropertySet> xShape4(xDrawPageShapes->getByIndex(4), uno::UNO_QUERY);
73 // Blue.
74 CPPUNIT_ASSERT_EQUAL(Color(0x4472c4), GetShapeFillColor(xShape4));
76 // The theme color of this filled shape is set by the PPTX import:
78 uno::Reference<util::XComplexColor> xComplexColor;
79 CPPUNIT_ASSERT(xShape4->getPropertyValue("FillComplexColor") >>= xComplexColor);
80 CPPUNIT_ASSERT(xComplexColor.is());
81 auto aComplexColor = model::color::getFromXComplexColor(xComplexColor);
82 CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1, aComplexColor.getSchemeType());
84 uno::Reference<beans::XPropertySet> xShape5(xDrawPageShapes->getByIndex(5), uno::UNO_QUERY);
85 // Blue, lighter.
86 CPPUNIT_ASSERT_EQUAL(Color(0xb4c7e7), GetShapeFillColor(xShape5));
87 // The theme index, and effects (lum mod, lum off) are set by the PPTX import:
89 uno::Reference<util::XComplexColor> xComplexColor;
90 CPPUNIT_ASSERT(xShape5->getPropertyValue("FillComplexColor") >>= xComplexColor);
91 CPPUNIT_ASSERT(xComplexColor.is());
92 auto aComplexColor = model::color::getFromXComplexColor(xComplexColor);
93 CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1, aComplexColor.getSchemeType());
94 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod,
95 aComplexColor.getTransformations()[0].meType);
96 CPPUNIT_ASSERT_EQUAL(sal_Int16(4000), aComplexColor.getTransformations()[0].mnValue);
97 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff,
98 aComplexColor.getTransformations()[1].meType);
99 CPPUNIT_ASSERT_EQUAL(sal_Int16(6000), aComplexColor.getTransformations()[1].mnValue);
101 // When changing the master slide of slide 1 to use the theme of the second master slide:
102 uno::Reference<drawing::XMasterPageTarget> xDrawPage2(
103 xDrawPagesSupplier->getDrawPages()->getByIndex(1), uno::UNO_QUERY);
104 uno::Reference<beans::XPropertySet> xMasterPage2(xDrawPage2->getMasterPage(), uno::UNO_QUERY);
105 uno::Any aTheme = xMasterPage2->getPropertyValue("Theme");
106 uno::Reference<beans::XPropertySet> xMasterPage(xDrawPage->getMasterPage(), uno::UNO_QUERY);
107 xMasterPage->setPropertyValue("Theme", aTheme);
109 // Then make sure the shape text color is now green:
110 // Without the accompanying fix in place, this test would have failed with:
111 // - Expected: 9486886 (#90c226, green)
112 // - Actual : 4485828 (#4472c4, blue)
113 // i.e. shape text was not updated on theme change.
114 CPPUNIT_ASSERT_EQUAL(Color(0x90c226), GetShapeTextColor(xShape));
115 // Green, lighter:
116 // Without the accompanying fix in place, this test would have failed with:
117 // - Expected: 14020002 (#d5eda2, light green)
118 // - Actual : 9486886 (#90c226, stock green)
119 // i.e. the "light" effect on green was not applied.
120 CPPUNIT_ASSERT_EQUAL(Color(0xd5eda2), GetShapeTextColor(xShape2));
121 // Green, darker.
122 CPPUNIT_ASSERT_EQUAL(Color(0x6c911d), GetShapeTextColor(xShape3));
123 // Shape fill:
124 // Without the accompanying fix in place, this test would have failed with:
125 // - Expected: 9486886 (#90c226, green)
126 // - Actual : 4485828 (#4472c4, blue)
127 CPPUNIT_ASSERT_EQUAL(Color(0x90c226), GetShapeFillColor(xShape4));
128 // Green, lighter:
129 // Without the accompanying fix in place, this test would have failed with:
130 // - Expected: 14020002 (#d5eda2, light green)
131 // - Actual : 9486886 (#90c226, green)
132 // i.e. the "light" effect on green was not applied.
133 CPPUNIT_ASSERT_EQUAL(Color(0xd5eda2), GetShapeFillColor(xShape5));
137 CPPUNIT_PLUGIN_IMPLEMENT();
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */