/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * 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 namespace com::sun::star::lang { class XComponent; } using namespace css; class ScCondFormatMergeTest : public UnoApiTest { public: ScCondFormatMergeTest(); void testCondFormatMerge(); CPPUNIT_TEST_SUITE(ScCondFormatMergeTest); CPPUNIT_TEST(testCondFormatMerge); CPPUNIT_TEST_SUITE_END(); }; ScCondFormatMergeTest::ScCondFormatMergeTest() : UnoApiTest("sc/qa/extras/testdocuments/") { } void ScCondFormatMergeTest::testCondFormatMerge() { loadFromFile(u"cond_format_merge.ods"); // get the first sheet uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); uno::Reference xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); uno::Reference xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); uno::Reference xProps(xSheet, uno::UNO_QUERY_THROW); uno::Any aAny = xProps->getPropertyValue("ConditionalFormats"); uno::Reference xCondFormats; CPPUNIT_ASSERT(aAny >>= xCondFormats); CPPUNIT_ASSERT(xCondFormats.is()); CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xCondFormats->getLength()); uno::Sequence> xCondFormatSeq = xCondFormats->getConditionalFormats(); CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xCondFormatSeq.getLength()); int nRanges = 0; for (sal_Int32 i = 0, n = xCondFormatSeq.getLength(); i < n; ++i) { CPPUNIT_ASSERT(xCondFormatSeq[i].is()); uno::Reference xCondFormat = xCondFormatSeq[i]; CPPUNIT_ASSERT(xCondFormat.is()); uno::Reference xPropSet(xCondFormat, uno::UNO_QUERY_THROW); aAny = xPropSet->getPropertyValue("Range"); uno::Reference xCellRanges; CPPUNIT_ASSERT(aAny >>= xCellRanges); CPPUNIT_ASSERT(xCellRanges.is()); uno::Sequence aRanges = xCellRanges->getRangeAddresses(); CPPUNIT_ASSERT_GREATEREQUAL(sal_Int32(1), aRanges.getLength()); table::CellRangeAddress aRange0 = aRanges[0]; CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aRange0.Sheet); CPPUNIT_ASSERT_EQUAL(aRange0.StartColumn, aRange0.EndColumn); table::CellRangeAddress aRange1; switch (aRange0.StartColumn) { case 3: switch (aRange0.StartRow) { case 0: // D1:D2,D5::D8 nRanges++; CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRange0.EndRow); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aRanges.getLength()); aRange1 = aRanges[1]; CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aRange1.Sheet); CPPUNIT_ASSERT_EQUAL(aRange1.StartColumn, aRange1.EndColumn); CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aRange1.StartColumn); CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange1.StartRow); CPPUNIT_ASSERT_EQUAL(sal_Int32(7), aRange1.EndRow); break; default: CPPUNIT_FAIL("Unexpected range in column D"); } break; case 5: switch (aRange0.StartRow) { case 0: // F1:F2 nRanges++; CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRange0.EndRow); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength()); break; case 2: // F3 nRanges++; CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aRange0.EndRow); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength()); break; case 3: // F4 nRanges++; CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aRange0.EndRow); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength()); break; case 4: // F5 nRanges++; CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange0.EndRow); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength()); break; default: CPPUNIT_FAIL("Unexpected range in column F"); } break; default: CPPUNIT_FAIL("Unexpected range"); } } CPPUNIT_ASSERT_EQUAL(5, nRanges); } CPPUNIT_TEST_SUITE_REGISTRATION(ScCondFormatMergeTest); CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */