1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <test/calc_unoapi_test.hxx>
11 #include <test/container/xenumeration.hxx>
13 #include <com/sun/star/beans/XPropertySet.hpp>
14 #include <com/sun/star/container/XEnumerationAccess.hpp>
15 #include <com/sun/star/container/XIndexAccess.hpp>
16 #include <com/sun/star/lang/XComponent.hpp>
17 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
18 #include <com/sun/star/sheet/XSpreadsheet.hpp>
19 #include <com/sun/star/sheet/XSpreadsheets.hpp>
20 #include <com/sun/star/sheet/XUniqueCellFormatRangesSupplier.hpp>
21 #include <com/sun/star/table/XCellRange.hpp>
22 #include <com/sun/star/uno/XInterface.hpp>
24 #include <com/sun/star/uno/Reference.hxx>
26 #include <sal/types.h>
29 using namespace css::uno
;
41 RGBColor(int nRed
, int nGreen
, int nBlue
)
48 sal_Int32
hashCode() const { return (255 << 24) | (m_nRed
<< 16) | (m_nGreen
<< 8) | m_nBlue
; }
52 class ScUniqueCellFormatsEnumeration
: public CalcUnoApiTest
, public apitest::XEnumeration
55 ScUniqueCellFormatsEnumeration();
57 virtual uno::Reference
<uno::XInterface
> init() override
;
58 virtual void setUp() override
;
59 virtual void tearDown() override
;
61 CPPUNIT_TEST_SUITE(ScUniqueCellFormatsEnumeration
);
64 CPPUNIT_TEST(testHasMoreElements
);
65 CPPUNIT_TEST(testNextElement
);
67 CPPUNIT_TEST_SUITE_END();
70 uno::Reference
<lang::XComponent
> m_xComponent
;
71 void changeColor(const uno::Reference
<sheet::XSpreadsheet
>& xSheet
, const OUString
& sRangeName
,
75 ScUniqueCellFormatsEnumeration::ScUniqueCellFormatsEnumeration()
76 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
80 uno::Reference
<uno::XInterface
> ScUniqueCellFormatsEnumeration::init()
82 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
83 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc
.is());
85 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
86 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
87 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
89 changeColor(xSheet0
, "A1:A5", RGBColor(0, 255, 0));
90 changeColor(xSheet0
, "A6:B10", RGBColor(255, 0, 0));
91 changeColor(xSheet0
, "B1:B6", RGBColor(0, 0, 255));
92 changeColor(xSheet0
, "B7", RGBColor(0, 255, 0));
93 changeColor(xSheet0
, "B8:B10", RGBColor(0, 0, 255));
94 changeColor(xSheet0
, "C1:C10", RGBColor(0, 0, 255));
95 changeColor(xSheet0
, "D1:D10", RGBColor(0, 255, 0));
97 uno::Reference
<sheet::XUniqueCellFormatRangesSupplier
> xUCFRS(xSheet0
, uno::UNO_QUERY_THROW
);
98 uno::Reference
<container::XEnumerationAccess
> xEA(xUCFRS
->getUniqueCellFormatRanges(),
99 uno::UNO_QUERY_THROW
);
100 return xEA
->createEnumeration();
103 void ScUniqueCellFormatsEnumeration::setUp()
105 CalcUnoApiTest::setUp();
106 m_xComponent
= loadFromDesktop("private:factory/scalc");
107 CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent
.is());
110 void ScUniqueCellFormatsEnumeration::tearDown()
112 closeDocument(m_xComponent
);
113 CalcUnoApiTest::tearDown();
116 void ScUniqueCellFormatsEnumeration::changeColor(const uno::Reference
<sheet::XSpreadsheet
>& xSheet
,
117 const OUString
& sRangeName
, const RGBColor
& rgb
)
119 uno::Reference
<table::XCellRange
> xCellRange(xSheet
->getCellRangeByName(sRangeName
),
121 uno::Reference
<beans::XPropertySet
> xPropertySet(xCellRange
, uno::UNO_QUERY_THROW
);
123 sal_Int32 nColor
= 16777216 + rgb
.hashCode();
126 xPropertySet
->setPropertyValue("CellBackColor", aValue
);
129 CPPUNIT_TEST_SUITE_REGISTRATION(ScUniqueCellFormatsEnumeration
);
131 } // namespace sc_apitest
133 CPPUNIT_PLUGIN_IMPLEMENT();
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */