mirror of
https://github.com/LibreOffice/core.git
synced 2025-07-29 21:00:46 +00:00
sc: add test for changing theme colors and undo/redo
Change-Id: Ieaae64cd6cfd96b8c1627cf1c3935bc546a36617 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154306 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:

committed by
Tomaž Vajngerl

parent
e40f69419e
commit
8e4fb36a69
@ -28,10 +28,13 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_ucalc_document_themes, \
|
||||
comphelper \
|
||||
cppu \
|
||||
cppuhelper \
|
||||
docmodel \
|
||||
editeng \
|
||||
sal \
|
||||
salhelper \
|
||||
sax \
|
||||
sc \
|
||||
svl \
|
||||
scqahelper \
|
||||
sfx \
|
||||
svxcore \
|
||||
|
@ -8,8 +8,19 @@
|
||||
*/
|
||||
|
||||
#include "helper/qahelper.hxx"
|
||||
#include <docsh.hxx>
|
||||
|
||||
#include <docmodel/theme/Theme.hxx>
|
||||
#include <svx/svdpage.hxx>
|
||||
#include <editeng/brushitem.hxx>
|
||||
#include <editeng/colritem.hxx>
|
||||
|
||||
#include <docsh.hxx>
|
||||
#include <patattr.hxx>
|
||||
#include <attrib.hxx>
|
||||
#include <docpool.hxx>
|
||||
#include <scitems.hxx>
|
||||
#include <undomanager.hxx>
|
||||
#include <ThemeColorChanger.hxx>
|
||||
|
||||
using namespace css;
|
||||
|
||||
@ -19,10 +30,11 @@ class DocumentThemesTest : public ScUcalcTestBase
|
||||
|
||||
namespace
|
||||
{
|
||||
CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testThemes)
|
||||
CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testGetTheme)
|
||||
{
|
||||
m_pDoc->InitDrawLayer();
|
||||
m_pDoc->InsertTab(0, "Test");
|
||||
|
||||
ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer();
|
||||
CPPUNIT_ASSERT(pDrawLayer);
|
||||
const SdrPage* pPage(pDrawLayer->GetPage(0));
|
||||
@ -31,6 +43,116 @@ CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testThemes)
|
||||
CPPUNIT_ASSERT(pTheme);
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testChangeTheme)
|
||||
{
|
||||
m_pDoc->InitDrawLayer();
|
||||
m_pDoc->InsertTab(0, "Test");
|
||||
|
||||
ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer();
|
||||
CPPUNIT_ASSERT(pDrawLayer);
|
||||
const SdrPage* pPage(pDrawLayer->GetPage(0));
|
||||
CPPUNIT_ASSERT(pPage);
|
||||
auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
|
||||
CPPUNIT_ASSERT(pTheme);
|
||||
|
||||
Color aBackgroundThemeColor(0xc99c00);
|
||||
Color aCellTextThemeColor(0x0369a3);
|
||||
|
||||
auto eBackgroundThemeType = model::ThemeColorType::Accent5;
|
||||
auto eCellTextThemeType = model::ThemeColorType::Accent2;
|
||||
|
||||
ScPatternAttr aNewPattern(m_pDoc->GetPool());
|
||||
{
|
||||
model::ComplexColor aComplexColor;
|
||||
aComplexColor.setSchemeColor(eBackgroundThemeType);
|
||||
Color aColor = pTheme->getColorSet()->resolveColor(aComplexColor);
|
||||
aNewPattern.GetItemSet().Put(SvxBrushItem(aColor, aComplexColor, ATTR_BACKGROUND));
|
||||
}
|
||||
{
|
||||
model::ComplexColor aComplexColor;
|
||||
aComplexColor.setSchemeColor(eCellTextThemeType);
|
||||
Color aColor = pTheme->getColorSet()->resolveColor(aComplexColor);
|
||||
aNewPattern.GetItemSet().Put(SvxColorItem(aColor, aComplexColor, ATTR_FONT_COLOR));
|
||||
}
|
||||
|
||||
m_pDoc->ApplyPatternAreaTab(2, 2, 4, 4, 0, aNewPattern);
|
||||
|
||||
{
|
||||
const SfxPoolItem* pItem = nullptr;
|
||||
auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0));
|
||||
CPPUNIT_ASSERT(pPattern);
|
||||
|
||||
pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
|
||||
auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
|
||||
CPPUNIT_ASSERT_EQUAL(aBackgroundThemeColor, pBrushItem->GetColor());
|
||||
pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem);
|
||||
auto pColorItem = static_cast<const SvxColorItem*>(pItem);
|
||||
CPPUNIT_ASSERT_EQUAL(aCellTextThemeColor, pColorItem->getColor());
|
||||
}
|
||||
|
||||
auto pColorSet = std::make_shared<model::ColorSet>("TestColorScheme");
|
||||
pColorSet->add(model::ThemeColorType::Dark1, 0x000000);
|
||||
pColorSet->add(model::ThemeColorType::Light1, 0x111111);
|
||||
pColorSet->add(model::ThemeColorType::Dark2, 0x222222);
|
||||
pColorSet->add(model::ThemeColorType::Light2, 0x333333);
|
||||
pColorSet->add(model::ThemeColorType::Accent1, 0x444444);
|
||||
pColorSet->add(model::ThemeColorType::Accent2, 0x555555);
|
||||
pColorSet->add(model::ThemeColorType::Accent3, 0x666666);
|
||||
pColorSet->add(model::ThemeColorType::Accent4, 0x777777);
|
||||
pColorSet->add(model::ThemeColorType::Accent5, 0x888888);
|
||||
pColorSet->add(model::ThemeColorType::Accent6, 0x999999);
|
||||
pColorSet->add(model::ThemeColorType::Hyperlink, 0xaaaaaa);
|
||||
pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xbbbbbb);
|
||||
|
||||
sc::ThemeColorChanger aChanger(*m_xDocShell);
|
||||
aChanger.apply(pColorSet);
|
||||
|
||||
{
|
||||
const SfxPoolItem* pItem = nullptr;
|
||||
auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0));
|
||||
CPPUNIT_ASSERT(pPattern);
|
||||
|
||||
pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
|
||||
auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
|
||||
CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eBackgroundThemeType), pBrushItem->GetColor());
|
||||
pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem);
|
||||
auto pColorItem = static_cast<const SvxColorItem*>(pItem);
|
||||
CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eCellTextThemeType), pColorItem->getColor());
|
||||
}
|
||||
|
||||
// Undo / Redo
|
||||
|
||||
m_pDoc->GetUndoManager()->Undo();
|
||||
|
||||
{
|
||||
const SfxPoolItem* pItem = nullptr;
|
||||
auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0));
|
||||
CPPUNIT_ASSERT(pPattern);
|
||||
|
||||
pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
|
||||
auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
|
||||
CPPUNIT_ASSERT_EQUAL(aBackgroundThemeColor, pBrushItem->GetColor());
|
||||
pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem);
|
||||
auto pColorItem = static_cast<const SvxColorItem*>(pItem);
|
||||
CPPUNIT_ASSERT_EQUAL(aCellTextThemeColor, pColorItem->getColor());
|
||||
}
|
||||
|
||||
m_pDoc->GetUndoManager()->Redo();
|
||||
|
||||
{
|
||||
const SfxPoolItem* pItem = nullptr;
|
||||
auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0));
|
||||
CPPUNIT_ASSERT(pPattern);
|
||||
|
||||
pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem);
|
||||
auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
|
||||
CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eBackgroundThemeType), pBrushItem->GetColor());
|
||||
pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem);
|
||||
auto pColorItem = static_cast<const SvxColorItem*>(pItem);
|
||||
CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eCellTextThemeType), pColorItem->getColor());
|
||||
}
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
@ -10,12 +10,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <scdllapi.h>
|
||||
#include <svx/theme/ThemeColorChanger.hxx>
|
||||
#include "docsh.hxx"
|
||||
|
||||
namespace sc
|
||||
{
|
||||
class ThemeColorChanger : public svx::IThemeColorChanger
|
||||
class SC_DLLPUBLIC ThemeColorChanger : public svx::IThemeColorChanger
|
||||
{
|
||||
ScDocShell& m_rDocShell;
|
||||
|
||||
|
Reference in New Issue
Block a user