Bump version to 5.0-14
[LibreOffice.git] / sc / qa / perf / scperfobj.cxx
blobb30a2c28fef461fc02928d02676bd63feffd9034
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
12 #include <rtl/ustring.hxx>
13 #include "cppunit/extensions/HelperMacros.h"
15 #include <com/sun/star/util/XSearchable.hpp>
16 #include <com/sun/star/util/XSearchDescriptor.hpp>
17 #include <com/sun/star/container/XIndexAccess.hpp>
18 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
19 #include <com/sun/star/sheet/XSpreadsheet.hpp>
20 #include <com/sun/star/sheet/XSpreadsheets.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/table/XCellRange.hpp>
24 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
25 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
26 #include <com/sun/star/sheet/XNamedRanges.hpp>
27 #include <com/sun/star/sheet/XNamedRange.hpp>
28 #include <com/sun/star/table/XCell.hpp>
29 #include <com/sun/star/text/XTextRange.hpp>
30 #include <com/sun/star/table/CellAddress.hpp>
31 #include <com/sun/star/table/CellRangeAddress.hpp>
32 #include <com/sun/star/sheet/Border.hpp>
33 #include <com/sun/star/sheet/NamedRangeFlag.hpp>
35 #include <test/callgrind.hxx>
37 using namespace css;
38 using namespace css::uno;
40 namespace sc_apitest {
42 #define NUMBER_OF_TESTS 3
44 class ScPerfObj : public CalcUnoApiTest
46 public:
48 ScPerfObj();
50 virtual void setUp() SAL_OVERRIDE;
51 virtual void tearDown() SAL_OVERRIDE;
53 uno::Reference< uno::XInterface > init();
55 CPPUNIT_TEST_SUITE(ScPerfObj);
56 CPPUNIT_TEST(testSheetFindAll);
57 CPPUNIT_TEST(testSheetNamedRanges);
58 CPPUNIT_TEST(testSheets);
59 CPPUNIT_TEST_SUITE_END();
61 private:
63 static sal_Int32 nTest;
64 static uno::Reference< lang::XComponent > mxComponent;
66 // tests
67 void testSheetFindAll();
68 void testSheetNamedRanges();
69 void testSheets();
73 sal_Int32 ScPerfObj::nTest = 0;
74 uno::Reference< lang::XComponent > ScPerfObj::mxComponent;
76 ScPerfObj::ScPerfObj()
77 : CalcUnoApiTest("sc/qa/perf/testdocuments/")
81 uno::Reference< uno::XInterface > ScPerfObj::init()
83 if (mxComponent.is())
84 closeDocument(mxComponent);
86 OUString aFileURL;
87 createFileURL(OUString("scBigFile.ods"), aFileURL);
89 mxComponent = loadFromDesktop(aFileURL);
91 CPPUNIT_ASSERT(mxComponent.is());
93 return mxComponent;
96 void ScPerfObj::setUp()
98 nTest++;
99 CalcUnoApiTest::setUp();
102 void ScPerfObj::tearDown()
104 if (nTest == NUMBER_OF_TESTS)
106 if (mxComponent.is())
108 closeDocument(mxComponent);
109 mxComponent.clear();
112 CalcUnoApiTest::tearDown();
115 void ScPerfObj::testSheetFindAll()
118 uno::Reference< sheet::XSpreadsheetDocument > xDoc(init(), UNO_QUERY_THROW);
120 CPPUNIT_ASSERT_MESSAGE("Problem in document loading" , xDoc.is());
122 // get sheet
123 uno::Reference< container::XIndexAccess > xSheetIndex (xDoc->getSheets(), UNO_QUERY_THROW);
124 CPPUNIT_ASSERT_MESSAGE("Problem in xSheetIndex" , xSheetIndex.is());
126 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetIndex->getByIndex(0), UNO_QUERY_THROW);
128 // create descriptor
129 uno::Reference< util::XSearchable > xSearchable(xSheet, UNO_QUERY_THROW);
130 uno::Reference< util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor();
132 // search for a value
133 xSearchDescr->setSearchString(OUString("value_1"));
135 callgrindStart();
137 uno::Reference< container::XIndexAccess > xIndex = xSearchable->findAll(xSearchDescr);
139 callgrindDump("testSheetFindAll-Search value");
141 CPPUNIT_ASSERT(xIndex.is());
143 int nCount = xIndex->getCount();
145 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong Count" , 20000, nCount);
147 // search for style
148 uno::Reference< sheet::XSpreadsheet > xSheet2( xSheetIndex->getByIndex(2), UNO_QUERY_THROW);
149 uno::Reference< util::XSearchable > xSearchableStyle(xSheet2, UNO_QUERY_THROW);
150 xSearchDescr = xSearchableStyle->createSearchDescriptor();
152 uno::Reference< beans::XPropertySet > xSearchProp(xSearchDescr,UNO_QUERY_THROW);
153 xSearchProp->setPropertyValue(OUString("SearchStyles"), makeAny(true));
155 xSearchDescr->setSearchString(OUString("aCellStyle"));
157 callgrindStart();
159 uno::Reference< container::XIndexAccess > xIndex2 = xSearchableStyle->findAll(xSearchDescr);
161 callgrindDump("testSheetFindAll-Search style");
163 CPPUNIT_ASSERT(xIndex2.is());
165 nCount = xIndex2->getCount();
167 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong Count" , 160, nCount);
171 void ScPerfObj::testSheetNamedRanges()
174 uno::Reference< lang::XComponent > xComponent (init(), UNO_QUERY_THROW);
175 uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW);
177 // get NamedRanges
178 uno::Reference< beans::XPropertySet > xPropSet (xComponent, UNO_QUERY_THROW);
179 OUString aNamedRangesPropertyString("NamedRanges");
180 uno::Reference< sheet::XNamedRanges > xNamedRanges(xPropSet->getPropertyValue(aNamedRangesPropertyString), UNO_QUERY_THROW);
181 uno::Reference< container::XIndexAccess > xIndexNamedRanges(xNamedRanges, UNO_QUERY_THROW);
183 // get sheet - named ranges are defined in sheet #1
184 uno::Reference< container::XIndexAccess > xSheetIndex (xDoc->getSheets(), UNO_QUERY_THROW);
185 CPPUNIT_ASSERT_MESSAGE("Problem in xSheetIndex" , xSheetIndex.is());
186 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetIndex->getByIndex(1), UNO_QUERY_THROW);
188 // test removeByName
189 OUString maNameToRemove("namedRange_4999");
190 bool bHasIt = xNamedRanges->hasByName(maNameToRemove);
191 CPPUNIT_ASSERT_MESSAGE("NamedRange initial1 des not exits, can't remove it", bHasIt);
193 if (bHasIt)
195 callgrindStart();
196 xNamedRanges->removeByName(maNameToRemove);
197 callgrindDump("Namedranges-removeByName");
200 // test addNewByName
201 table::CellAddress aBaseAddress = table::CellAddress(0,0,0);
203 sal_Int32 nType = 0;
204 OUString aContent1("B4999");
205 OUString aName1("single_added");
206 callgrindStart();
207 xNamedRanges->addNewByName(aName1, aContent1, aBaseAddress, nType);
208 callgrindDump("Namedranges-addNewByName");
210 //test AddNewFromTitles with some 1000 new named ranges
211 table::CellRangeAddress aCellRangeAddress = table::CellRangeAddress(0,1,0,2,999);
212 callgrindStart();
213 xNamedRanges->addNewFromTitles(aCellRangeAddress, sheet::Border_LEFT);
214 callgrindDump("Namedranges-addNewFromTitles");
218 void ScPerfObj::testSheets()
221 uno::Reference< sheet::XSpreadsheetDocument > xDoc(init(), UNO_QUERY_THROW);
223 CPPUNIT_ASSERT_MESSAGE("Problem in document loading" , xDoc.is());
225 // get getSheets
226 uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_QUERY_THROW);
228 OUString aSheetName = "NewSheet";
230 callgrindStart();
231 xSheets->insertNewByName(aSheetName, 80);
232 callgrindDump("Sheets-insertNewByName");
234 OUString aSourceSheetName = "aSheet_2";
235 OUString aTargetSheetName = "aCopiedSheet";
237 callgrindStart();
238 xSheets->copyByName(aSourceSheetName, aTargetSheetName, 70);
239 callgrindDump("Sheets-copyByName");
241 uno::Reference< sheet::XSpreadsheets > xSheetsNameContainer (xSheets, UNO_QUERY_THROW);
243 callgrindStart();
244 xSheetsNameContainer->removeByName(aSheetName);
245 callgrindDump("Sheets-removeByName");
249 CPPUNIT_TEST_SUITE_REGISTRATION(ScPerfObj);
253 CPPUNIT_PLUGIN_IMPLEMENT();
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */