sc/qa/unit/ThemeImportExportTest.cxx | 213 +++++++++- sc/qa/unit/data/xlsx/Test_ThemeColor_Text_Background_Border.xlsx |binary 2 files changed, 208 insertions(+), 5 deletions(-)
New commits: commit f0c8ccaef39dc7cb876e00679f70c36ca60883d9 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Jun 29 16:51:26 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sat Jul 1 08:54:03 2023 +0200 sc: improve import tests for text, background, border theme colors Change-Id: Icdc658e47c0e4fe20b2b38897d31278f058a6a75 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153783 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sc/qa/unit/ThemeImportExportTest.cxx b/sc/qa/unit/ThemeImportExportTest.cxx index 45d29bf7a088..106471f9a816 100644 --- a/sc/qa/unit/ThemeImportExportTest.cxx +++ b/sc/qa/unit/ThemeImportExportTest.cxx @@ -12,9 +12,13 @@ #include <docsh.hxx> #include <scitems.hxx> #include <editeng/brushitem.hxx> +#include <editeng/colritem.hxx> +#include <editeng/borderline.hxx> using namespace css; +namespace +{ class ThemeImportExportTest : public ScModelTestBase { public: @@ -58,12 +62,9 @@ CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testThemeExport) assertXPath(pXmlDoc, "/x:styleSheet/x:fills/x:fill[4]/x:patternFill/x:fgColor", "theme", "4"); } -CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testCellBackgroundThemeColor) +void checkCellBackgroundThemeColor(ScDocument* pDoc) { - loadFromURL(u"xlsx/Test_ThemeColor_Text_Background_Border.xlsx"); - - ScDocument* pDoc = getScDoc(); - + // A1 { const ScPatternAttr* pPattern = pDoc->GetPattern(0, 0, 0); const SfxPoolItem* pItem = nullptr; @@ -77,6 +78,7 @@ CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testCellBackgroundThemeColor) CPPUNIT_ASSERT_EQUAL(size_t(0), aComplexColor.getTransformations().size()); } + // A2 { const ScPatternAttr* pPattern = pDoc->GetPattern(0, 1, 0); const SfxPoolItem* pItem = nullptr; @@ -94,8 +96,209 @@ CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testCellBackgroundThemeColor) CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff, rTransformations[1].meType); CPPUNIT_ASSERT_EQUAL(sal_Int16(7999), rTransformations[1].mnValue); } + + // A3 + { + const ScPatternAttr* pPattern = pDoc->GetPattern(0, 2, 0); + const SfxPoolItem* pItem = nullptr; + pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem); + CPPUNIT_ASSERT(pItem); + + auto* pBrushItem = static_cast<const SvxBrushItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(Color(0x14676b), pBrushItem->GetColor()); + auto aComplexColor = pBrushItem->getComplexColor(); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent3, aComplexColor.getSchemeType()); + auto& rTransformations = aComplexColor.getTransformations(); + CPPUNIT_ASSERT_EQUAL(size_t(1), rTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTransformations[0].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(5000), rTransformations[0].mnValue); + } +} + +CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testCellBackgroundThemeColor) +{ + loadFromURL(u"xlsx/Test_ThemeColor_Text_Background_Border.xlsx"); + checkCellBackgroundThemeColor(getScDoc()); +} + +void checkCellTextThemeColor(ScDocument* pDoc) +{ + // B1 + { + const ScPatternAttr* pPattern = pDoc->GetPattern(1, 0, 0); + const SfxPoolItem* pItem = nullptr; + pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem); + CPPUNIT_ASSERT(pItem); + + auto* pColorItem = static_cast<const SvxColorItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(Color(0x62a39f), pColorItem->getColor()); + auto aComplexColor = pColorItem->getComplexColor(); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent6, aComplexColor.getSchemeType()); + CPPUNIT_ASSERT_EQUAL(size_t(0), aComplexColor.getTransformations().size()); + } + + // B2 + { + const ScPatternAttr* pPattern = pDoc->GetPattern(1, 1, 0); + const SfxPoolItem* pItem = nullptr; + pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem); + CPPUNIT_ASSERT(pItem); + + auto* pColorItem = static_cast<const SvxColorItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(Color(0xa1c8c5), pColorItem->getColor()); + auto aComplexColor = pColorItem->getComplexColor(); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent6, aComplexColor.getSchemeType()); + auto& rTransformations = aComplexColor.getTransformations(); + CPPUNIT_ASSERT_EQUAL(size_t(2), rTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTransformations[0].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(6000), rTransformations[0].mnValue); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff, rTransformations[1].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(3999), rTransformations[1].mnValue); + } + + // B3 + { + const ScPatternAttr* pPattern = pDoc->GetPattern(1, 2, 0); + const SfxPoolItem* pItem = nullptr; + pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem); + CPPUNIT_ASSERT(pItem); + + auto* pColorItem = static_cast<const SvxColorItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(Color(0x305250), pColorItem->getColor()); + auto aComplexColor = pColorItem->getComplexColor(); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent6, aComplexColor.getSchemeType()); + auto& rTransformations = aComplexColor.getTransformations(); + CPPUNIT_ASSERT_EQUAL(size_t(1), rTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTransformations[0].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(5000), rTransformations[0].mnValue); + } } +CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testCellTextThemeColor) +{ + loadFromURL(u"xlsx/Test_ThemeColor_Text_Background_Border.xlsx"); + checkCellTextThemeColor(getScDoc()); +} + +void checkCellBorderThemeColor(ScDocument* pDoc) +{ + // C1 + { + const ScPatternAttr* pPattern = pDoc->GetPattern(2, 0, 0); + const SfxPoolItem* pItem = nullptr; + pPattern->GetItemSet().HasItem(ATTR_BORDER, &pItem); + CPPUNIT_ASSERT(pItem); + + auto* pBoxItem = static_cast<const SvxBoxItem*>(pItem); + CPPUNIT_ASSERT(!pBoxItem->GetLeft()); + CPPUNIT_ASSERT(!pBoxItem->GetRight()); + CPPUNIT_ASSERT(!pBoxItem->GetBottom()); + + { + auto* pTop = pBoxItem->GetTop(); + CPPUNIT_ASSERT(pTop); + CPPUNIT_ASSERT_EQUAL(Color(0x3e8853), pTop->GetColor()); + auto aComplexColor = pTop->getComplexColor(); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent5, aComplexColor.getSchemeType()); + auto& rTransformations = aComplexColor.getTransformations(); + CPPUNIT_ASSERT_EQUAL(size_t(0), rTransformations.size()); + } + } + + // C2 + { + const ScPatternAttr* pPattern = pDoc->GetPattern(2, 1, 0); + const SfxPoolItem* pItem = nullptr; + pPattern->GetItemSet().HasItem(ATTR_BORDER, &pItem); + CPPUNIT_ASSERT(pItem); + + auto* pBoxItem = static_cast<const SvxBoxItem*>(pItem); + CPPUNIT_ASSERT(!pBoxItem->GetTop()); + + { + auto* pTop = pBoxItem->GetLeft(); + CPPUNIT_ASSERT(pTop); + CPPUNIT_ASSERT_EQUAL(Color(0xd4ebdb), pTop->GetColor()); + auto aComplexColor = pTop->getComplexColor(); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent5, aComplexColor.getSchemeType()); + auto& rTransformations = aComplexColor.getTransformations(); + CPPUNIT_ASSERT_EQUAL(size_t(2), rTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTransformations[0].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2000), rTransformations[0].mnValue); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff, rTransformations[1].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(7999), rTransformations[1].mnValue); + } + { + auto* pTop = pBoxItem->GetRight(); + CPPUNIT_ASSERT(pTop); + CPPUNIT_ASSERT_EQUAL(Color(0xd4ebdb), pTop->GetColor()); + auto aComplexColor = pTop->getComplexColor(); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent5, aComplexColor.getSchemeType()); + auto& rTransformations = aComplexColor.getTransformations(); + CPPUNIT_ASSERT_EQUAL(size_t(2), rTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTransformations[0].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2000), rTransformations[0].mnValue); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff, rTransformations[1].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(7999), rTransformations[1].mnValue); + } + { + auto* pTop = pBoxItem->GetBottom(); + CPPUNIT_ASSERT(pTop); + CPPUNIT_ASSERT_EQUAL(Color(0x1f442a), pTop->GetColor()); + auto aComplexColor = pTop->getComplexColor(); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent5, aComplexColor.getSchemeType()); + auto& rTransformations = aComplexColor.getTransformations(); + CPPUNIT_ASSERT_EQUAL(size_t(1), rTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTransformations[0].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(5000), rTransformations[0].mnValue); + } + } + + // C3 + { + const ScPatternAttr* pPattern = pDoc->GetPattern(2, 2, 0); + const SfxPoolItem* pItem = nullptr; + pPattern->GetItemSet().HasItem(ATTR_BORDER, &pItem); + CPPUNIT_ASSERT(pItem); + + auto* pBoxItem = static_cast<const SvxBoxItem*>(pItem); + CPPUNIT_ASSERT(!pBoxItem->GetLeft()); + CPPUNIT_ASSERT(!pBoxItem->GetRight()); + + { + auto* pTop = pBoxItem->GetTop(); + CPPUNIT_ASSERT(pTop); + CPPUNIT_ASSERT_EQUAL(Color(0x1f442a), pTop->GetColor()); + auto aComplexColor = pTop->getComplexColor(); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent5, aComplexColor.getSchemeType()); + auto& rTransformations = aComplexColor.getTransformations(); + CPPUNIT_ASSERT_EQUAL(size_t(1), rTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTransformations[0].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(5000), rTransformations[0].mnValue); + } + + { + auto* pBottom = pBoxItem->GetBottom(); + CPPUNIT_ASSERT(pBottom); + CPPUNIT_ASSERT_EQUAL(Color(0x1f442a), pBottom->GetColor()); + auto aComplexColor = pBottom->getComplexColor(); + CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent5, aComplexColor.getSchemeType()); + auto& rTransformations = aComplexColor.getTransformations(); + CPPUNIT_ASSERT_EQUAL(size_t(1), rTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod, rTransformations[0].meType); + CPPUNIT_ASSERT_EQUAL(sal_Int16(5000), rTransformations[0].mnValue); + } + } +} + +CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testCellBorderThemeColor) +{ + loadFromURL(u"xlsx/Test_ThemeColor_Text_Background_Border.xlsx"); + checkCellBorderThemeColor(getScDoc()); +} + +} // end anonymous namespace + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/data/xlsx/Test_ThemeColor_Text_Background_Border.xlsx b/sc/qa/unit/data/xlsx/Test_ThemeColor_Text_Background_Border.xlsx index 339d7539ecfb..8ffc2fb1b4de 100644 Binary files a/sc/qa/unit/data/xlsx/Test_ThemeColor_Text_Background_Border.xlsx and b/sc/qa/unit/data/xlsx/Test_ThemeColor_Text_Background_Border.xlsx differ