Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / extras / scscenariosobj.cxx
blob78e94ae381db0027ff9a2d17ed34ddecf2da5d0f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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/.
8 */
10 #include <test/calc_unoapi_test.hxx>
11 #include <test/container/xelementaccess.hxx>
12 #include <test/container/xenumerationaccess.hxx>
13 #include <test/container/xnameaccess.hxx>
14 #include <test/container/xindexaccess.hxx>
15 #include <test/lang/xserviceinfo.hxx>
16 #include <test/sheet/xscenarios.hxx>
18 #include <com/sun/star/container/XIndexAccess.hpp>
19 #include <com/sun/star/lang/XComponent.hpp>
20 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
21 #include <com/sun/star/sheet/XScenario.hpp>
22 #include <com/sun/star/sheet/XScenariosSupplier.hpp>
23 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
24 #include <com/sun/star/sheet/XSpreadsheet.hpp>
25 #include <com/sun/star/table/XCellRange.hpp>
26 #include <com/sun/star/table/CellRangeAddress.hpp>
27 #include <com/sun/star/uno/XInterface.hpp>
29 #include <cppu/unotype.hxx>
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
34 using namespace css;
35 using namespace css::uno;
36 using namespace com::sun::star;
38 namespace sc_apitest
40 class ScScenariosObj : public CalcUnoApiTest,
41 public apitest::XElementAccess,
42 public apitest::XEnumerationAccess,
43 public apitest::XNameAccess,
44 public apitest::XIndexAccess,
45 public apitest::XScenarios,
46 public apitest::XServiceInfo
48 public:
49 ScScenariosObj();
51 virtual uno::Reference<uno::XInterface> init() override;
52 virtual void setUp() override;
53 virtual void tearDown() override;
55 CPPUNIT_TEST_SUITE(ScScenariosObj);
57 // XElementAccess
58 CPPUNIT_TEST(testGetElementType);
59 CPPUNIT_TEST(testHasElements);
61 // XEnumerationAccess
62 CPPUNIT_TEST(testCreateEnumeration);
64 // XNameAccess
65 CPPUNIT_TEST(testGetByName);
66 CPPUNIT_TEST(testGetElementNames);
67 CPPUNIT_TEST(testHasByName);
69 // XIndexAccess
70 CPPUNIT_TEST(testGetByIndex);
71 CPPUNIT_TEST(testGetCount);
73 // XScenarios
74 CPPUNIT_TEST(testAddNewByName);
75 CPPUNIT_TEST(testRemoveByName);
77 // XServiceInfo
78 CPPUNIT_TEST(testGetImplementationName);
79 CPPUNIT_TEST(testGetSupportedServiceNames);
80 CPPUNIT_TEST(testSupportsService);
82 CPPUNIT_TEST_SUITE_END();
84 private:
85 uno::Reference<lang::XComponent> mxComponent;
88 ScScenariosObj::ScScenariosObj()
89 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
90 , XElementAccess(cppu::UnoType<sheet::XScenario>::get())
91 , XNameAccess("ScScenarios")
92 , XIndexAccess(1)
93 , XServiceInfo("ScScenariosObj", "com.sun.star.sheet.Scenarios")
97 uno::Reference<uno::XInterface> ScScenariosObj::init()
99 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
101 uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW);
102 uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
104 xSheet->getCellByPosition(5, 5)->setValue(15);
105 xSheet->getCellByPosition(1, 4)->setValue(10);
106 xSheet->getCellByPosition(2, 0)->setValue(-5.15);
108 uno::Reference<table::XCellRange> xCellRange(xSheet, uno::UNO_QUERY_THROW);
109 uno::Reference<table::XCellRange> xCellRange2 = xCellRange->getCellRangeByName("A1:N4");
110 uno::Reference<sheet::XCellRangeAddressable> xCRAddressable(xCellRange2, uno::UNO_QUERY_THROW);
111 table::CellRangeAddress aCellRangeAddr = xCRAddressable->getRangeAddress();
113 uno::Sequence<table::CellRangeAddress> aCellRangeAddresses(1);
114 aCellRangeAddresses[0] = aCellRangeAddr;
115 uno::Reference<sheet::XScenariosSupplier> xSupplier(xSheet, uno::UNO_QUERY_THROW);
116 xSupplier->getScenarios()->addNewByName("ScScenarios", aCellRangeAddresses, "Range");
118 return xSupplier->getScenarios();
121 void ScScenariosObj::setUp()
123 CalcUnoApiTest::setUp();
124 // create a calc document
125 mxComponent = loadFromDesktop("private:factory/scalc");
128 void ScScenariosObj::tearDown()
130 closeDocument(mxComponent);
131 CalcUnoApiTest::tearDown();
134 CPPUNIT_TEST_SUITE_REGISTRATION(ScScenariosObj);
136 } // end namespace
138 CPPUNIT_PLUGIN_IMPLEMENT();
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */