tdf#103331: Add a test case for inherited font weight attributes.

Change-Id: I8ebca3ab492313a3f7aa9019533bbb7eee2e4a89
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127019
Tested-by: Jenkins
Reviewed-by: Kohei Yoshida <kohei@libreoffice.org>
diff --git a/sc/qa/unit/data/xml/styles.xml b/sc/qa/unit/data/xml/styles.xml
index fa5cd27..eb402a0 100644
--- a/sc/qa/unit/data/xml/styles.xml
+++ b/sc/qa/unit/data/xml/styles.xml
@@ -31,4 +31,20 @@
    <style:table-cell-properties style:vertical-align="middle"/>
    <style:paragraph-properties fo:text-align="end"/>
  </style:style>

  <style:style style:name="Accent" style:family="table-cell" style:parent-style-name="Default">
    <style:text-properties fo:font-weight="bold"/>
  </style:style>
  <style:style style:name="Accent 1" style:family="table-cell" style:parent-style-name="Accent">
    <style:table-cell-properties fo:background-color="#000000"/>
    <style:text-properties fo:color="#ffffff"/>
  </style:style>
  <style:style style:name="Accent 2" style:family="table-cell" style:parent-style-name="Accent">
    <style:table-cell-properties fo:background-color="#808080"/>
    <style:text-properties fo:color="#ffffff"/>
  </style:style>
  <style:style style:name="Accent 3" style:family="table-cell" style:parent-style-name="Accent">
    <style:table-cell-properties fo:background-color="#dddddd"/>
  </style:style>

</office:styles>
diff --git a/sc/qa/unit/subsequent_filters_test.cxx b/sc/qa/unit/subsequent_filters_test.cxx
index 3c4939b..39bf4cd 100644
--- a/sc/qa/unit/subsequent_filters_test.cxx
+++ b/sc/qa/unit/subsequent_filters_test.cxx
@@ -2914,7 +2914,8 @@ void ScFiltersTest::testOrcusODSStyleInterface()
    CPPUNIT_ASSERT_MESSAGE("Style Name3 : Doesn't have Attribute Protection, but it should have.",
        pStyleSheet->GetItemSet().HasItem(ATTR_PROTECTION, &pItem));

    CPPUNIT_ASSERT_MESSAGE("Style Name 3 : Error with Protection attribute." ,bool(ScProtectionAttr(true, false, true, true) == *pItem));
    CPPUNIT_ASSERT_MESSAGE("Style Name 3 : Error with Protection attribute.",
        bool(ScProtectionAttr(true, false, true, true) == *pItem));

    /* Test for Style "Name4"
     * Hidden, protected and content is printed.
@@ -2923,20 +2924,22 @@ void ScFiltersTest::testOrcusODSStyleInterface()
    CPPUNIT_ASSERT_MESSAGE("Style Name4 : Doesn't have Attribute Protection, but it should have.",
        pStyleSheet->GetItemSet().HasItem(ATTR_PROTECTION, &pItem));

    CPPUNIT_ASSERT_MESSAGE("Style Name 4 : Error with Protection attribute." ,bool(ScProtectionAttr(true, true, false, false) == *pItem));
    CPPUNIT_ASSERT_MESSAGE("Style Name 4 : Error with Protection attribute.",
        bool(ScProtectionAttr(true, true, false, false) == *pItem));

    /* Test for Style "Name3"
    /* Test for Style "Name5"
     * Hidden, protected and content is printed.
     */
    pStyleSheet = pStyleSheetPool->FindCaseIns("Name5", SfxStyleFamily::Para);
    CPPUNIT_ASSERT_MESSAGE("Style Name5 : Doesn't have Attribute Protection, but it should have.",
        pStyleSheet->GetItemSet().HasItem(ATTR_PROTECTION, &pItem));

    CPPUNIT_ASSERT_MESSAGE("Style Name 5 : Error with Protection attribute." ,bool(ScProtectionAttr(false, false, false, true) == *pItem));
    CPPUNIT_ASSERT_MESSAGE("Style Name5 : Error with Protection attribute.",
        bool(ScProtectionAttr(false, false, false, true) == *pItem));

    CPPUNIT_ASSERT_MESSAGE("Style Name5 : Has Attribute Border, but it shouldn't.",
        !pStyleSheet->GetItemSet().HasItem(ATTR_BORDER, &pItem));
    CPPUNIT_ASSERT_MESSAGE("Style Name5: Has Attribute background, but it shouldn't.",
    CPPUNIT_ASSERT_MESSAGE("Style Name5 : Has Attribute background, but it shouldn't.",
        !pStyleSheet->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem));
    CPPUNIT_ASSERT_MESSAGE("Style Name5 : Has Attribute font, but it shouldn't.",
        !pStyleSheet->GetItemSet().HasItem(ATTR_FONT, &pItem));
@@ -3032,6 +3035,33 @@ void ScFiltersTest::testOrcusODSStyleInterface()
    const SvxVerJustifyItem* pVerJustify = static_cast<const SvxVerJustifyItem*>(pItem);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Style Name10 :Error with ver justify", SvxCellVerJustify::Center, pVerJustify->GetValue());

    auto checkFontWeight = [pStyleSheetPool](const OUString& rName, FontWeight eExpected)
    {
        ScStyleSheet* pStyle = pStyleSheetPool->FindCaseIns(rName, SfxStyleFamily::Para);
        CPPUNIT_ASSERT(pStyle);

        const SfxPoolItem* p = nullptr;

        {
            std::ostringstream os;
            os << "Style named '" << rName << "' does not have a font weight attribute.";
            CPPUNIT_ASSERT_MESSAGE(os.str(), pStyle->GetItemSet().HasItem(ATTR_FONT_WEIGHT, &p));
        }

        const SvxWeightItem* pWeight = static_cast<const SvxWeightItem*>(p);
        FontWeight eActual = pWeight->GetWeight();
        {
            std::ostringstream os;
            os << "Wrong font weight value for style named '" << rName << "': expected="
                << eExpected << "; actual=" << eActual;
            CPPUNIT_ASSERT_EQUAL_MESSAGE(os.str(), eExpected, eActual);
        }
    };

    checkFontWeight("Accent", WEIGHT_BOLD);
    checkFontWeight("Accent 1", WEIGHT_BOLD); // inherits from 'Accent'
    checkFontWeight("Accent 2", WEIGHT_BOLD); // inherits from 'Accent'
    checkFontWeight("Accent 3", WEIGHT_BOLD); // inherits from 'Accent'
}

void ScFiltersTest::testLiteralInFormulaXLS()