diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sc/qa/extras | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sc/qa/extras')
159 files changed, 15556 insertions, 0 deletions
diff --git a/sc/qa/extras/anchor.cxx b/sc/qa/extras/anchor.cxx new file mode 100644 index 000000000..ae7bdb010 --- /dev/null +++ b/sc/qa/extras/anchor.cxx @@ -0,0 +1,435 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <sfx2/dispatch.hxx> +#include <svx/svdograf.hxx> +#include <svx/svdpage.hxx> +#include <test/calc_unoapi_test.hxx> + +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/text/XText.hpp> + +#include <attrib.hxx> +#include <docsh.hxx> +#include <drwlayer.hxx> +#include <scitems.hxx> +#include <svx/svdocirc.hxx> +#include <vcl/scheduler.hxx> +#include <tabvwsh.hxx> + +#include <sc.hrc> + +using namespace css; + +namespace sc_apitest +{ +class ScAnchorTest : public CalcUnoApiTest +{ +public: + ScAnchorTest(); + + void testUndoAnchor(); + void testTdf76183(); + void testODFAnchorTypes(); + void testCopyColumnWithImages(); + void testCutWithImages(); + void testTdf121963(); + void testTdf129552(); + void testTdf130556(); + void testTdf134161(); + + CPPUNIT_TEST_SUITE(ScAnchorTest); + CPPUNIT_TEST(testUndoAnchor); + CPPUNIT_TEST(testTdf76183); + CPPUNIT_TEST(testODFAnchorTypes); + CPPUNIT_TEST(testCopyColumnWithImages); + CPPUNIT_TEST(testCutWithImages); + CPPUNIT_TEST(testTdf121963); + CPPUNIT_TEST(testTdf129552); + CPPUNIT_TEST(testTdf130556); + CPPUNIT_TEST(testTdf134161); + CPPUNIT_TEST_SUITE_END(); +}; + +ScAnchorTest::ScAnchorTest() + : CalcUnoApiTest("sc/qa/unit/data/ods") +{ +} + +void ScAnchorTest::testUndoAnchor() +{ + OUString aFileURL; + createFileURL("document_with_linked_graphic.ods", aFileURL); + // open the document with graphic included + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Check whether graphic imported well + ScDocument& rDoc = pDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT(pDrawLayer); + + const SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT(pPage); + + SdrGrafObj* pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(0)); + CPPUNIT_ASSERT(pObject); + CPPUNIT_ASSERT(pObject->IsLinkedGraphic()); + + const GraphicObject& rGraphicObj = pObject->GetGraphicObject(true); + CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType())); + CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes()); + + // Get the document controller + ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pViewShell); + + // Get the draw view of the document + ScDrawView* pDrawView = pViewShell->GetViewData().GetScDrawView(); + CPPUNIT_ASSERT(pDrawView); + + // Select graphic object + pDrawView->MarkNextObj(); + CPPUNIT_ASSERT(pDrawView->AreObjectsMarked()); + + // Set Cell Anchor + ScDrawLayer::SetCellAnchoredFromPosition(*pObject, rDoc, 0, false); + // Check state + ScAnchorType oldType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_CELL, oldType); + + // Change all selected objects to page anchor + pViewShell->GetViewData().GetDispatcher().Execute(SID_ANCHOR_PAGE); + // Check state + ScAnchorType newType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_PAGE, newType); + + // Undo and check its result. + SfxUndoManager* pUndoMgr = rDoc.GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + pUndoMgr->Undo(); + + // Check anchor type + CPPUNIT_ASSERT_EQUAL(oldType, ScDrawLayer::GetAnchorType(*pObject)); + CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType())); + CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes()); + + pUndoMgr->Redo(); + + // Check anchor type + CPPUNIT_ASSERT_EQUAL(newType, ScDrawLayer::GetAnchorType(*pObject)); + CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType())); + CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes()); + + ScDrawLayer::SetPageAnchored(*pObject); + // Check state + oldType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_PAGE, oldType); + + // Change all selected objects to cell anchor + pViewShell->GetViewData().GetDispatcher().Execute(SID_ANCHOR_CELL); + // Check state + newType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_CELL, newType); + + pUndoMgr->Undo(); + + // Check anchor type + CPPUNIT_ASSERT_EQUAL(oldType, ScDrawLayer::GetAnchorType(*pObject)); + CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType())); + CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes()); + + pUndoMgr->Redo(); + + // Check anchor type + CPPUNIT_ASSERT_EQUAL(newType, ScDrawLayer::GetAnchorType(*pObject)); + CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType())); + CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes()); + + xComponent->dispose(); +} + +void ScAnchorTest::testTdf76183() +{ + uno::Reference<lang::XComponent> xComponent = loadFromDesktop("private:factory/scalc"); + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + SdrPage* pPage = pDrawLayer->GetPage(0); + + // Add a circle somewhere below first row. + const tools::Rectangle aOrigRect(1000, 1000, 1200, 1200); + SdrCircObj* pObj = new SdrCircObj(*pDrawLayer, SdrCircKind::Full, aOrigRect); + pPage->InsertObject(pObj); + // Anchor to cell + ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 0, false); + const tools::Rectangle& rNewRect = pObj->GetLogicRect(); + + // Set word wrap to true + rDoc.ApplyAttr(0, 0, 0, ScLineBreakCell(true)); + // Add multi-line text to cell to initiate optimal height change + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<text::XText> xText(xSheet->getCellByPosition(0, 0), uno::UNO_QUERY_THROW); + xText->setString("first\nsecond\nthird"); + + // The resize of first row must have moved the object down after its anchor cell + CPPUNIT_ASSERT(aOrigRect.Top() < rNewRect.Top()); + + pDocSh->DoClose(); +} + +void ScAnchorTest::testODFAnchorTypes() +{ + OUString aFileURL; + createFileURL("3AnchorTypes.ods", aFileURL); + // open the document with graphic included + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Check whether graphic imported well + ScDocument& rDoc = pDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT(pDrawLayer); + + const SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT(pPage); + + // Check 1st object: Page anchored + SdrGrafObj* pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(0)); + CPPUNIT_ASSERT(pObject); + ScAnchorType anchorType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_PAGE, anchorType); + + // Check 2nd object: Cell anchored, resize with cell + pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(1)); + CPPUNIT_ASSERT(pObject); + anchorType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_CELL_RESIZE, anchorType); + + // Check 3rd object: Cell anchored + pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(2)); + CPPUNIT_ASSERT(pObject); + anchorType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_EQUAL(SCA_CELL, anchorType); + + pDocSh->DoClose(); +} + +/// Test that copying a column with an image anchored to it also copies the image +void ScAnchorTest::testCopyColumnWithImages() +{ + OUString aFileURL; + createFileURL("3AnchorTypes.ods", aFileURL); + // open the document with graphic included + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + ScDocument* pDoc = &(pDocSh->GetDocument()); + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + CPPUNIT_ASSERT(pDrawLayer); + + // Get the document controller + ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pViewShell != nullptr); + + ScDocument aClipDoc(SCDOCMODE_CLIP); + + // Copy whole column + { + // 1. Copy source range + ScRange aSrcRange; + aSrcRange.Parse("A1:A11", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, true, false); + + // 2. Paste to target range + ScRange aDstRange; + aDstRange.Parse("D1:D11", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange); + pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc); + + // 3. Make sure the images have been copied too + std::map<SCROW, std::vector<SdrObject*>> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 3, 0, 11); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D3", 1, + static_cast<int>(aRowObjects[2].size())); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D11", 1, + static_cast<int>(aRowObjects[10].size())); + } + + // Copy individual cells + { + // 1. Copy source cells + ScRange aSrcRange; + aSrcRange.Parse("A3:B3", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, true, false); + + // 2. Paste to target cells + ScRange aDstRange; + aDstRange.Parse("G3:H3", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange); + pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc); + + // 3. Make sure the image has been copied too + std::map<SCROW, std::vector<SdrObject*>> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 6, 2, 2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to G3", 1, + static_cast<int>(aRowObjects[2].size())); + } + + pDocSh->DoClose(); +} + +void ScAnchorTest::testCutWithImages() +{ + OUString aFileURL; + createFileURL("3AnchorTypes.ods", aFileURL); + // open the document with graphic included + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + ScDocument* pDoc = &(pDocSh->GetDocument()); + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + CPPUNIT_ASSERT(pDrawLayer); + + // Get the document controller + ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pViewShell != nullptr); + + // Cut whole column + { + // Cut source range + ScRange aSrcRange; + aSrcRange.Parse("A1:A11", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CutToClip(); + + std::map<SCROW, std::vector<SdrObject*>> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 0, 0, 11); + + // Images should have been removed from the cells + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no image anchored to A3", 0, + static_cast<int>(aRowObjects[2].size())); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no image anchored to A11", 0, + static_cast<int>(aRowObjects[10].size())); + } + + // Cut individual cells + { + // Cut source cells + ScRange aSrcRange; + aSrcRange.Parse("A3:B3", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CutToClip(); + + // Image should have been removed from the cell + std::map<SCROW, std::vector<SdrObject*>> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 0, 2, 2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no image anchored to A3", 0, + static_cast<int>(aRowObjects[2].size())); + } + + pDocSh->DoClose(); +} + +void ScAnchorTest::testTdf121963() +{ + OUString aFileURL; + createFileURL("tdf121963.ods", aFileURL); + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Without the accompanying fix in place, this test would have never returned due to an infinite + // invalidation loop, where ScGridWindow::Paint() invalidated itself. + Scheduler::ProcessEventsToIdle(); + + xComponent->dispose(); +} + +void ScAnchorTest::testTdf129552() +{ + OUString aFileURL; + createFileURL("tdf129552.fods", aFileURL); + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Without the accompanying fix in place, this test would have never returned due to an infinite + // invalidation loop, where ScGridWindow::Paint() invalidated itself. + Scheduler::ProcessEventsToIdle(); + + xComponent->dispose(); +} + +void ScAnchorTest::testTdf130556() +{ + OUString aFileURL; + createFileURL("tdf130556.ods", aFileURL); + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Without the accompanying fix in place, this test would have never returned due to an infinite + // invalidation loop, where ScGridWindow::Paint() invalidated itself. + Scheduler::ProcessEventsToIdle(); + + xComponent->dispose(); +} + +void ScAnchorTest::testTdf134161() +{ + OUString aFileURL; + createFileURL("tdf134161.ods", aFileURL); + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Without the accompanying fix in place, this test would have never returned due to an infinite + // invalidation loop + Scheduler::ProcessEventsToIdle(); + + xComponent->dispose(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAnchorTest); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/check_data_pilot_field.cxx b/sc/qa/extras/check_data_pilot_field.cxx new file mode 100644 index 000000000..3445245ad --- /dev/null +++ b/sc/qa/extras/check_data_pilot_field.cxx @@ -0,0 +1,193 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <test/container/xnamed.hxx> +#include <test/beans/xpropertyset.hxx> +//check the DataPilot of Calc. + +using namespace css; +using namespace css::lang; + +namespace sc_apitest { + +class CheckDataPilotField : public CalcUnoApiTest, public apitest::XNamed, public apitest::XPropertySet +{ + public: + CheckDataPilotField(); + + virtual void setUp() override; + virtual void tearDown() override; + + uno::Reference< uno::XInterface > init() override; + + CPPUNIT_TEST_SUITE(CheckDataPilotField); + + // _XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testGetPropertyValue); + + CPPUNIT_TEST_SUITE_END(); + +protected: + + virtual bool isPropertyIgnored(const OUString& rName) override; + +private: + uno::Reference<lang::XComponent> mxComponent; + uno::Reference<uno::XInterface> mxObject; + int mMaxFieldIndex = 6; +}; + +bool CheckDataPilotField::isPropertyIgnored(const OUString& rName) +{ + return rName == "Function" + || rName == "Subtotals" + || rName == "Function2" + || rName == "Subtotals2"; +} + +CheckDataPilotField::CheckDataPilotField() + : CalcUnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XNamed("Col1") +{ +} + +uno::Reference< uno::XInterface > CheckDataPilotField::init() +{ + // create a calc document + if (!mxComponent.is()) + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); + else + return mxObject; + + uno::Reference< sheet::XSpreadsheetDocument > xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + // the cell range + table::CellRangeAddress sCellRangeAdress; + sCellRangeAdress.Sheet = 0; + sCellRangeAdress.StartColumn = 1; + sCellRangeAdress.StartRow = 0; + sCellRangeAdress.EndColumn = mMaxFieldIndex-1; + sCellRangeAdress.EndRow = mMaxFieldIndex - 1; + + // position of the data pilot table + table::CellAddress sCellAdress; + sCellAdress.Sheet = 0; + sCellAdress.Column = 7; + sCellAdress.Row = 8; + // Getting spreadsheet + uno::Reference< sheet::XSpreadsheets > xSpreadsheets = xSheetDoc->getSheets(); + uno::Reference< container::XIndexAccess > oIndexAccess(xSpreadsheets, uno::UNO_QUERY_THROW); + + // Per default there's now just one sheet, make sure we have at least two, then + xSpreadsheets->insertNewByName("Some Sheet", 0); + uno::Any aAny = oIndexAccess->getByIndex(0); + uno::Reference< sheet::XSpreadsheet > oSheet; + CPPUNIT_ASSERT(aAny >>= oSheet); + + uno::Any aAny2 = oIndexAccess->getByIndex(1); + uno::Reference< sheet::XSpreadsheet > oSheet2; + CPPUNIT_ASSERT(aAny2 >>= oSheet2); + + //Filling a table + for (int i = 1; i < mMaxFieldIndex; i++) + { + oSheet->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + oSheet->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + oSheet2->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + oSheet2->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (int i = 1; i < mMaxFieldIndex; i++) + { + for (int j = 1; j < mMaxFieldIndex; j++) + { + oSheet->getCellByPosition(i, j)->setValue(i * (j + 1)); + oSheet2->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + // change a value of a cell and check the change in the data pilot + // cell of data + uno::Any oChangeCell; + oChangeCell<<= oSheet->getCellByPosition(1, 5); + int x = sCellAdress.Column; + int y = sCellAdress.Row + 3; + // cell of the data pilot output + uno::Any oCheckCell; + oCheckCell<<= oSheet->getCellByPosition(x, y); + // create the test objects + uno::Reference< sheet::XDataPilotTablesSupplier> DPTS(oSheet, uno::UNO_QUERY_THROW); + uno::Reference< sheet::XDataPilotTables> DPT = DPTS->getDataPilotTables(); + uno::Reference< sheet::XDataPilotDescriptor> DPDsc = DPT->createDataPilotDescriptor(); + DPDsc->setSourceRange(sCellRangeAdress); + + uno::Any oDataPilotField = DPDsc->getDataPilotFields()->getByIndex(0); + uno::Reference<beans::XPropertySet> fieldPropSet(oDataPilotField, uno::UNO_QUERY_THROW); + + uno::Any sum; + sum<<= sheet::GeneralFunction_SUM; + fieldPropSet->setPropertyValue("Function", sum ); + + uno::Any data; + data<<= sheet::DataPilotFieldOrientation_DATA; + fieldPropSet->setPropertyValue("Orientation", data); + + //Insert the DataPilotTable + if (DPT->hasByName("DataPilotField")) + DPT->removeByName("DataPilotField"); + DPT->insertNewByName("DataPilotTField", sCellAdress, DPDsc); + + uno::Reference< container::XIndexAccess > IA = DPDsc->getDataPilotFields(); + uno::Reference<uno::XInterface> xDataPilotFieldObject; + data = IA->getByIndex(0); + CPPUNIT_ASSERT(data >>= xDataPilotFieldObject); + mxObject = xDataPilotFieldObject; + + return xDataPilotFieldObject; +} + + +void CheckDataPilotField::setUp() +{ + CalcUnoApiTest::setUp(); + init(); +} + +void CheckDataPilotField::tearDown() +{ + closeDocument(mxComponent); + mxComponent.clear(); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CheckDataPilotField); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/qa/extras/check_data_pilot_table.cxx b/sc/qa/extras/check_data_pilot_table.cxx new file mode 100644 index 000000000..f13768ffb --- /dev/null +++ b/sc/qa/extras/check_data_pilot_table.cxx @@ -0,0 +1,188 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <test/container/xnamed.hxx> +#include <test/sheet/xdatapilottable.hxx> +#include <test/sheet/xdatapilotdescriptor.hxx> +#include <test/beans/xpropertyset.hxx> +//check the DataPilot of Calc. + +using namespace css; +using namespace css::lang; + +namespace sc_apitest { + +class CheckDataPilotTable : public CalcUnoApiTest, public apitest::XNamed, public apitest::XDataPilotTable, public apitest::XPropertySet, public apitest::XDataPilotDescriptor +{ +public: + CheckDataPilotTable(); + + virtual void setUp() override; + virtual void tearDown() override; + + uno::Reference< uno::XInterface > init() override; + + CPPUNIT_TEST_SUITE(CheckDataPilotTable); + // _XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // _XDataPilotTable + CPPUNIT_TEST(testGetOutputRange); + + // _XDataPilotDescriptor + CPPUNIT_TEST(testTag); + CPPUNIT_TEST(testGetFilterDescriptor); + CPPUNIT_TEST(testGetDataPilotFields); + CPPUNIT_TEST(testGetColumnFields); + CPPUNIT_TEST(testGetRowFields); + // CPPUNIT_TEST(testGetDataFields); + // CPPUNIT_TEST(testGetHiddenFields); + CPPUNIT_TEST(testGetPageFields); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; + uno::Reference<uno::XInterface> mxObject; + static constexpr int MAX_FIELD_INDEX = 6; +}; + +CheckDataPilotTable::CheckDataPilotTable() + : CalcUnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XNamed("DataPilotTable") +{ +} + +uno::Reference< uno::XInterface > CheckDataPilotTable::init() +{ + // create a calc document + if (!mxComponent.is()) + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); + else + return mxObject; + + uno::Reference< sheet::XSpreadsheetDocument > xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + // the cell range + table::CellRangeAddress sCellRangeAdress; + sCellRangeAdress.Sheet = 0; + sCellRangeAdress.StartColumn = 1; + sCellRangeAdress.StartRow = 0; + sCellRangeAdress.EndColumn = MAX_FIELD_INDEX-1; + sCellRangeAdress.EndRow = MAX_FIELD_INDEX - 1; + + // position of the data pilot table + table::CellAddress sCellAdress; + sCellAdress.Sheet = 0; + sCellAdress.Column = 7; + sCellAdress.Row = 8; + // Getting spreadsheet + uno::Reference< sheet::XSpreadsheets > xSpreadsheets = xSheetDoc->getSheets(); + uno::Reference< container::XIndexAccess > oIndexAccess(xSpreadsheets, uno::UNO_QUERY_THROW); + + // Per default there's now just one sheet, make sure we have at least two, then + xSpreadsheets->insertNewByName("Some Sheet", 0); + uno::Any aAny = oIndexAccess->getByIndex(0); + uno::Reference< sheet::XSpreadsheet > oSheet; + CPPUNIT_ASSERT(aAny >>= oSheet); + + uno::Any aAny2 = oIndexAccess->getByIndex(1); + uno::Reference< sheet::XSpreadsheet > oSheet2; + CPPUNIT_ASSERT(aAny2 >>= oSheet2); + + //Filling a table + for (int i = 1; i < MAX_FIELD_INDEX; i++) + { + oSheet->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + oSheet->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + oSheet2->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + oSheet2->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (int i = 1; i < MAX_FIELD_INDEX; i++) + { + for (int j = 1; j < MAX_FIELD_INDEX; j++) + { + oSheet->getCellByPosition(i, j)->setValue(i * (j + 1)); + oSheet2->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + // change a value of a cell and check the change in the data pilot + // cell of data + uno::Any oChangeCell; + oChangeCell<<= oSheet->getCellByPosition(1, 5); + int x = sCellAdress.Column; + int y = sCellAdress.Row + 3; + // cell of the data pilot output + uno::Any oCheckCell; + oCheckCell<<= oSheet->getCellByPosition(x, y); + // create the test objects + uno::Reference< sheet::XDataPilotTablesSupplier> DPTS(oSheet, uno::UNO_QUERY_THROW); + uno::Reference< sheet::XDataPilotTables> DPT = DPTS->getDataPilotTables(); + uno::Reference< sheet::XDataPilotDescriptor> DPDsc = DPT->createDataPilotDescriptor(); + DPDsc->setSourceRange(sCellRangeAdress); + + uno::Any oDataPilotField = DPDsc->getDataPilotFields()->getByIndex(0); + uno::Reference<beans::XPropertySet> fieldPropSet(oDataPilotField, uno::UNO_QUERY_THROW); + + uno::Any sum; + sum<<= sheet::GeneralFunction_SUM; + fieldPropSet->setPropertyValue("Function", sum ); + + uno::Any data; + data<<= sheet::DataPilotFieldOrientation_DATA; + fieldPropSet->setPropertyValue("Orientation", data); + + //Insert the DataPilotTable + if (DPT->hasByName("DataPilotTable")) + DPT->removeByName("DataPilotTable"); + DPT->insertNewByName("DataPilotTable", sCellAdress, DPDsc); + + uno::Reference<uno::XInterface> xDataPilotTableObject; + data = DPT->getByName( DPT->getElementNames()[0] ); + CPPUNIT_ASSERT(data >>= xDataPilotTableObject); + mxObject = xDataPilotTableObject; + + return xDataPilotTableObject; +} + +void CheckDataPilotTable::setUp() +{ + CalcUnoApiTest::setUp(); + init(); +} + +void CheckDataPilotTable::tearDown() +{ + closeDocument(mxComponent); + mxComponent.clear(); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CheckDataPilotTable); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/qa/extras/check_xcell_ranges_query.cxx b/sc/qa/extras/check_xcell_ranges_query.cxx new file mode 100644 index 000000000..e2d216dc2 --- /dev/null +++ b/sc/qa/extras/check_xcell_ranges_query.cxx @@ -0,0 +1,186 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XCellRangesQuery.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/container/XNamed.hpp> + +using namespace css; +using namespace css::lang; + +namespace sc_apitest { + +class CheckXCellRangesQuery : public CalcUnoApiTest +{ +public: + CheckXCellRangesQuery(); + + virtual void setUp() override; + virtual void tearDown() override; + + uno::Reference< uno::XInterface > init(); + void checkEmptyCell(); + void checkFilledCell(); + + void _queryColumnDifferences(const OUString& expected); + void _queryRowDifferences(const OUString& expected); + void _queryEmptyCells(const OUString& expected); + + CPPUNIT_TEST_SUITE(CheckXCellRangesQuery); + CPPUNIT_TEST(checkEmptyCell); + CPPUNIT_TEST(checkFilledCell); + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; + uno::Reference< sheet::XCellRangesQuery > m_xCell; + OUString sSheetName; +}; + +CheckXCellRangesQuery::CheckXCellRangesQuery() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference< uno::XInterface > CheckXCellRangesQuery::init() +{ + // create a calc document + if (!mxComponent.is()) + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); + + uno::Reference< sheet::XSpreadsheetDocument > xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + // Getting spreadsheet + uno::Reference< sheet::XSpreadsheets > oSheets = xSheetDoc->getSheets(); + uno::Reference< container::XIndexAccess > oIndexSheets(oSheets, uno::UNO_QUERY_THROW); + uno::Any aAny = oIndexSheets->getByIndex(0); + uno::Reference<container::XNamed> xNamed; + CPPUNIT_ASSERT(aAny >>= xNamed); + sSheetName = xNamed->getName(); + + // get the cell + uno::Reference< sheet::XSpreadsheet > xSpreadSheet; + CPPUNIT_ASSERT(aAny >>= xSpreadSheet); + uno::Reference<uno::XInterface> oObj = xSpreadSheet->getCellByPosition(2, 3); + m_xCell = uno::Reference<sheet::XCellRangesQuery>(oObj, uno::UNO_QUERY_THROW); + + // set one value for comparison. + xSpreadSheet->getCellByPosition(1, 1)->setValue(15); + xSpreadSheet->getCellByPosition(1, 3)->setValue(5); + xSpreadSheet->getCellByPosition(2, 1)->setFormula("=B2+B4"); + + return xSpreadSheet; +} + +/** + * Perform some tests on an empty cell: + * <ol> + * <li>compare an empty cell with a cell with a value in the same column</li> + * <li>compare an empty cell with a cell with a value in the same row</li> + * <li>query for empty cells</li> + * <ol> + */ +void CheckXCellRangesQuery::checkEmptyCell() +{ + // compare an empty cell with a cell with a value + _queryColumnDifferences(sSheetName + ".C4"); + // compare an empty cell with a cell with a value + _queryRowDifferences(sSheetName + ".C4"); +} + +/** + * Perform some tests on a filled cell: + * <ol> + * <li>compare a cell with value 5 with a cell with value 15 in the same + * column</li> + * <li>compare a cell with value 5 with a cell with value 15 in the same + * row</li> + * <li>query for an empty cell.</li> + * <ol> + */ + +void CheckXCellRangesQuery::checkFilledCell() +{ + uno::Reference< sheet::XSpreadsheet > xSpreadSheet(init(), uno::UNO_QUERY_THROW); + // fill the cell with a value + xSpreadSheet->getCellByPosition(2, 3)->setValue(15); + + // compare a cell with value 5 with a cell with value 15 + _queryColumnDifferences(sSheetName + ".C4"); + // compare a cell with value 5 with a cell with value 15 + _queryRowDifferences(sSheetName + ".C4"); + // try to get nothing + _queryEmptyCells(""); +} + +/** + * Query column differences between my cell(2,3) and (1,1). + * + * @param expected The expected outcome value. + */ +void CheckXCellRangesQuery::_queryColumnDifferences(const OUString& expected) +{ + //Query column differences + uno::Reference<sheet::XSheetCellRanges> ranges = m_xCell->queryColumnDifferences(table::CellAddress(0, 1, 1)); + OUString getting = ranges->getRangeAddressesAsString(); + + CPPUNIT_ASSERT_EQUAL(expected, getting); +} + +/** + * Query for an empty cell. + * + * @param expected The expected outcome value. + */ +void CheckXCellRangesQuery::_queryEmptyCells(const OUString& expected) +{ + //Query empty cells + uno::Reference<sheet::XSheetCellRanges> ranges = m_xCell->queryEmptyCells(); + OUString getting = ranges->getRangeAddressesAsString(); + + CPPUNIT_ASSERT_EQUAL(expected, getting); +} + +/** + * Query row differences between my cell(2,3) and (1,1). + * + * @param expected The expected outcome value. + */ +void CheckXCellRangesQuery::_queryRowDifferences(const OUString& expected) { + //Query row differences + uno::Reference<sheet::XSheetCellRanges> ranges = m_xCell->queryRowDifferences(table::CellAddress(0, 1, 1)); + OUString getting = ranges->getRangeAddressesAsString(); + + CPPUNIT_ASSERT_EQUAL(expected, getting); +} + +void CheckXCellRangesQuery::setUp() +{ + CalcUnoApiTest::setUp(); + init(); +} + +void CheckXCellRangesQuery::tearDown() +{ + closeDocument(mxComponent); + mxComponent.clear(); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CheckXCellRangesQuery); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/qa/extras/htmlexporttest.cxx b/sc/qa/extras/htmlexporttest.cxx new file mode 100644 index 000000000..d7bbb7038 --- /dev/null +++ b/sc/qa/extras/htmlexporttest.cxx @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <sal/config.h> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/lang/XComponent.hpp> + +#include <test/bootstrapfixture.hxx> +#include <test/htmltesttools.hxx> +#include <test/xmltesttools.hxx> +#include <comphelper/processfactory.hxx> +#include <unotools/mediadescriptor.hxx> +#include <unotools/localfilehelper.hxx> +#include <unotest/macros_test.hxx> + +using namespace css::uno; +using namespace css::lang; +using namespace css::frame; +using namespace utl; + +class ScHTMLExportTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools, public HtmlTestTools +{ + Reference<XComponent> mxComponent; + OUString maFilterOptions; + + void load(const OUString& pDir, const char* pName) + { + if (mxComponent.is()) + mxComponent->dispose(); + mxComponent = loadFromDesktop(m_directories.getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.comp.Calc.SpreadsheetDocument"); + } + + void save(const OUString& aFilterName, TempFile const & rTempFile) + { + Reference<XStorable> xStorable(mxComponent, UNO_QUERY); + MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= aFilterName; + if (!maFilterOptions.isEmpty()) + aMediaDescriptor["FilterOptions"] <<= maFilterOptions; + xStorable->storeToURL(rTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + } + +public: + ScHTMLExportTest() + {} + + virtual void setUp() override + { + test::BootstrapFixture::setUp(); + mxDesktop.set(css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); + } + + virtual void tearDown() override + { + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); + } + + void testHtmlSkipImage() + { + // need a temp dir, because there's an image exported too + TempFile aTempDir(nullptr, true); + OUString const url(aTempDir.GetURL()); + TempFile aTempFile(&url, false); + + htmlDocUniquePtr pDoc; + + load("/sc/qa/extras/testdocuments/", "BaseForHTMLExport.ods"); + save("HTML (StarCalc)", aTempFile); + pDoc = parseHtml(aTempFile); + CPPUNIT_ASSERT (pDoc); + + assertXPath(pDoc, "/html/body", 1); + assertXPath(pDoc, "/html/body/table/tr/td/img", 1); + + load("/sc/qa/extras/testdocuments/", "BaseForHTMLExport.ods"); + maFilterOptions = "SkipImages"; + save("HTML (StarCalc)", aTempFile); + + pDoc = parseHtml(aTempFile); + CPPUNIT_ASSERT (pDoc); + assertXPath(pDoc, "/html/body", 1); + assertXPath(pDoc, "/html/body/table/tr/td/img", 0); + + utl::removeTree(aTempDir.GetURL()); + } + + CPPUNIT_TEST_SUITE(ScHTMLExportTest); + CPPUNIT_TEST(testHtmlSkipImage); + CPPUNIT_TEST_SUITE_END(); + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ScHTMLExportTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx new file mode 100644 index 000000000..05c3fc3da --- /dev/null +++ b/sc/qa/extras/macros-test.cxx @@ -0,0 +1,609 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <sal/config.h> +#include <test/unoapi_test.hxx> +#include <osl/file.hxx> +#include <sal/log.hxx> +#include <unotools/tempfile.hxx> +#include <vcl/svapp.hxx> + +#include <docsh.hxx> +#include <document.hxx> + +#include <com/sun/star/script/XLibraryContainerPassword.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +/* Implementation of Macros test */ + +class ScMacrosTest : public UnoApiTest +{ +public: + ScMacrosTest(); + void saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent, + const OUString& rFilter); + + void testStarBasic(); + void testVba(); + void testMSP(); + void testPasswordProtectedStarBasic(); + void testRowColumn(); + void testPasswordProtectedUnicodeString(); + void testPasswordProtectedArrayInUserType(); + void testTdf131296_legacy(); + void testTdf131296_new(); + + CPPUNIT_TEST_SUITE(ScMacrosTest); + CPPUNIT_TEST(testStarBasic); + CPPUNIT_TEST(testMSP); + CPPUNIT_TEST(testVba); + CPPUNIT_TEST(testPasswordProtectedStarBasic); + CPPUNIT_TEST(testRowColumn); + CPPUNIT_TEST(testPasswordProtectedUnicodeString); + CPPUNIT_TEST(testPasswordProtectedArrayInUserType); + CPPUNIT_TEST(testTdf131296_legacy); + CPPUNIT_TEST(testTdf131296_new); + + CPPUNIT_TEST_SUITE_END(); +}; + +void ScMacrosTest::saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent, + const OUString& rFilter) +{ + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + css::uno::Sequence<css::beans::PropertyValue> aArgs(1); + aArgs[0].Name = "FilterName"; + aArgs[0].Value <<= rFilter; + css::uno::Reference<css::frame::XStorable> xStorable(xComponent, css::uno::UNO_QUERY_THROW); + xStorable->storeAsURL(aTempFile.GetURL(), aArgs); + css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); + + xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.sheet.SpreadsheetDocument"); +} + +// I suppose you could say this test doesn't really belong here, OTOH +// we need a full document to run the test ( it related originally to an +// imported Excel VBA macro ) It's convenient and fast to unit test +// this the problem this way. Perhaps in the future there will be some sort +// of slowcheck tests ( requiring a full document environment in the scripting +// module, we could move the test there then ) - relates to fdo#67547 +void ScMacrosTest::testMSP() +{ + const OUString aFileNameBase("MasterScriptProviderProblem.ods"); + OUString aFileName; + createFileURL(aFileNameBase, aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + CPPUNIT_ASSERT_MESSAGE("Failed to load MasterScriptProviderProblem.ods", xComponent.is()); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh != nullptr); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.TestMSP?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + OUString sResult; + aRet >>= sResult; + + SAL_INFO("sc.qa", "Result is " << sResult ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("TestMSP ( for fdo#67547) failed", OUString("OK"), sResult); + pDocSh->DoClose(); +} + +void ScMacrosTest::testPasswordProtectedStarBasic() +{ + const OUString aFileNameBase("testTypePassword.ods"); + OUString aFileName; + createFileURL(aFileNameBase, aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + CPPUNIT_ASSERT_MESSAGE("Failed to load testTypePassword.ods", xComponent.is()); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + + // User defined types + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.LoadAndExecuteTest?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aValue = rDoc.GetString(0,0,0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("User defined types script did not change the value of Sheet1.A1", OUString("success"), aValue); + + // Big Module + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:MyLibrary.BigModule.bigMethod?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + aValue = rDoc.GetString(1,0,0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Big module script did not change the value of Sheet1.B1", OUString("success"), aValue); + + // far big method tdf#94617 + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:MyLibrary.BigModule.farBigMethod?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + aValue = rDoc.GetString(2,0,0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Far Method script did not change the value of Sheet1.C1", OUString("success"), aValue); + + + pDocSh->DoClose(); +} + +void ScMacrosTest::testStarBasic() +{ + const OUString aFileNameBase("StarBasic.ods"); + OUString aFileName; + createFileURL(aFileNameBase, aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + CPPUNIT_ASSERT_MESSAGE("Failed to load StarBasic.ods", xComponent.is()); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.Macro1?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + double aValue; + rDoc.GetValue(0,0,0,aValue); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("script did not change the value of Sheet1.A1",2.0, aValue, 0.00001); + pDocSh->DoClose(); +} + +void ScMacrosTest::testVba() +{ + TestMacroInfo testInfo[] = { + { + OUString("TestAddress."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("vba."), + OUString("vnd.sun.Star.script:VBAProject.Modul1.Modul1?language=Basic&location=document"), + }, + { + OUString("MiscRangeTests."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("bytearraystring."), + OUString("vnd.sun.Star.script:VBAProject.testMacro.test?language=Basic&location=document") + }, + { + OUString("AutoFilter."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("CalcFont."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("TestIntersection."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("TestUnion."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("range-4."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("Ranges-3."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("TestCalc_Rangetest."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("TestCalc_Rangetest2."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("Ranges-2."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("pagesetup."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("Window."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("window2."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("PageBreaks."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("Shapes."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("Ranges."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("CheckOptionToggleValue."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("GeneratedEventTest."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("MiscControlTests."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("Workbooks."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("Names."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("vba_endFunction."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + { + OUString("vba_findFunction."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, + }; + OUString sTempDir; + OUString sTempDirURL; + osl::FileBase:: getTempDirURL( sTempDirURL ); + osl::FileBase::getSystemPathFromFileURL( sTempDirURL, sTempDir ); + sTempDir += OUStringChar(SAL_PATHDELIMITER); + OUString sTestFileName("My Test WorkBook.xls"); + Sequence< uno::Any > aParams; + for (const auto& rTestInfo : testInfo) + { + OUString aFileName; + createFileURL(rTestInfo.sFileBaseName + "xls", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + OUString sMsg( "Failed to load " + aFileName ); + CPPUNIT_ASSERT_MESSAGE( OUStringToOString( sMsg, RTL_TEXTENCODING_UTF8 ).getStr(), xComponent.is() ); + + // process all events such as OnLoad events etc. + // otherwise the tend to arrive later at a random + // time - while processing other StarBasic methods. + Application::Reschedule(true); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + bool bWorkbooksHandling = rTestInfo.sFileBaseName == "Workbooks." && !sTempDir.isEmpty() ; + + if ( bWorkbooksHandling ) + { + aParams.realloc(2); + aParams[ 0 ] <<= sTempDir; + aParams[ 1 ] <<= sTestFileName; + } + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + SAL_INFO("sc.qa", "about to invoke vba test in " << aFileName << " with url " << rTestInfo.sMacroUrl); + + SfxObjectShell::CallXScript( + xComponent, rTestInfo.sMacroUrl, aParams, aRet, aOutParamIndex, + aOutParam); + OUString aStringRes; + aRet >>= aStringRes; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + OUString("script reported failure in file " + rTestInfo.sFileBaseName + "xls") + .toUtf8() + .getStr(), + OUString("OK"), aStringRes); + pFoundShell->DoClose(); + if ( bWorkbooksHandling ) + { + OUString sFileUrl; + OUString sFilePath = sTempDir + sTestFileName; + osl::FileBase::getFileURLFromSystemPath( sFilePath, sFileUrl ); + if ( !sFileUrl.isEmpty() ) + osl::File::remove( sFileUrl ); + } + } +} + +void ScMacrosTest::testRowColumn() +{ + const OUString aFileNameBase("StarBasic.ods"); + OUString aFileName; + createFileURL(aFileNameBase, aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + CPPUNIT_ASSERT_MESSAGE("Failed to load StarBasic.ods", xComponent.is()); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.Macro_RowHeight?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + sal_uInt16 nHeight = rDoc.GetRowHeight(0, 0) * HMM_PER_TWIPS; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2000), nHeight); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.Macro_ColumnWidth?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + sal_uInt16 nWidth = rDoc.GetColWidth(0, 0) * HMM_PER_TWIPS; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(4000), nWidth); + + pDocSh->DoClose(); +} + +void ScMacrosTest::testPasswordProtectedUnicodeString() +{ + const OUString sCorrectString(u"English Русский 中文"); + const OUString sMacroURL( + "vnd.sun.Star.script:Protected.Module1.TestUnicodeString?language=Basic&location=document"); + const OUString sLibName("Protected"); + + OUString aFileName; + createFileURL("tdf57113.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + CPPUNIT_ASSERT(xComponent); + + // Check that loading password-protected macro image correctly loads Unicode strings + { + Any aRet; + Sequence<sal_Int16> aOutParamIndex; + Sequence<Any> aOutParam; + Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(xComponent, sMacroURL, aParams, aRet, aOutParamIndex, + aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(sCorrectString, aReturnValue); + } + + // Unlock and load the library, to regenerate the image on save + css::uno::Reference<css::document::XEmbeddedScripts> xES(xComponent, UNO_QUERY_THROW); + css::uno::Reference<css::script::XLibraryContainer> xLC(xES->getBasicLibraries(), + UNO_QUERY_THROW); + css::uno::Reference<css::script::XLibraryContainerPassword> xPasswd(xLC, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xPasswd->isLibraryPasswordProtected(sLibName)); + CPPUNIT_ASSERT(!xPasswd->isLibraryPasswordVerified(sLibName)); + CPPUNIT_ASSERT(xPasswd->verifyLibraryPassword(sLibName, "password")); + xLC->loadLibrary(sLibName); + CPPUNIT_ASSERT(xLC->isLibraryLoaded(sLibName)); + + // Now check that saving stores Unicode data correctly in image's string pool + saveAndReload(xComponent, "calc8"); + CPPUNIT_ASSERT(xComponent); + + { + Any aRet; + Sequence<sal_Int16> aOutParamIndex; + Sequence<Any> aOutParam; + Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(xComponent, sMacroURL, aParams, aRet, aOutParamIndex, + aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(sCorrectString, aReturnValue); + } + + css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testPasswordProtectedArrayInUserType() +{ + const OUString sMacroURL( + "vnd.sun.Star.script:Protected.Module1.TestMyType?language=Basic&location=document"); + const OUString sLibName("Protected"); + + OUString aFileName; + createFileURL("ProtectedArrayInCustomType.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + CPPUNIT_ASSERT(xComponent); + + // Check that loading password-protected macro image correctly loads array bounds + { + Any aRet; + Sequence<sal_Int16> aOutParamIndex; + Sequence<Any> aOutParam; + Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(xComponent, sMacroURL, aParams, aRet, aOutParamIndex, + aOutParam); + + sal_Int16 nReturnValue; + aRet >>= nReturnValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nReturnValue); + } + + // Unlock and load the library, to regenerate the image on save + css::uno::Reference<css::document::XEmbeddedScripts> xES(xComponent, UNO_QUERY_THROW); + css::uno::Reference<css::script::XLibraryContainer> xLC(xES->getBasicLibraries(), + UNO_QUERY_THROW); + css::uno::Reference<css::script::XLibraryContainerPassword> xPasswd(xLC, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xPasswd->isLibraryPasswordProtected(sLibName)); + CPPUNIT_ASSERT(!xPasswd->isLibraryPasswordVerified(sLibName)); + CPPUNIT_ASSERT(xPasswd->verifyLibraryPassword(sLibName, "password")); + xLC->loadLibrary(sLibName); + CPPUNIT_ASSERT(xLC->isLibraryLoaded(sLibName)); + + // Now check that saving stores array bounds correctly + saveAndReload(xComponent, "calc8"); + CPPUNIT_ASSERT(xComponent); + + { + Any aRet; + Sequence<sal_Int16> aOutParamIndex; + Sequence<Any> aOutParam; + Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(xComponent, sMacroURL, aParams, aRet, aOutParamIndex, + aOutParam); + + sal_Int16 nReturnValue; + aRet >>= nReturnValue; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nReturnValue); + } + + css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf131296_legacy() +{ + // For legacy password-protected library images, we must correctly get the constants' values, + // and also - for Integer - the type. + const std::vector<std::pair<OUString, OUString>> aTests({ + { "TestIntConst", "Integer: 123" }, + { "TestLongConst", "Double: 123" }, + { "TestSingleConst", "Double: 123" }, + { "TestDoubleConst", "Double: 123" }, + }); + + OUString aFileName; + createFileURL("tdf131296_legacy.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + CPPUNIT_ASSERT(xComponent); + + { + Any aRet; + Sequence<sal_Int16> aOutParamIndex; + Sequence<Any> aOutParam; + Sequence<uno::Any> aParams; + + for (auto& [sTestName, sExpected] : aTests) + { + SfxObjectShell::CallXScript(xComponent, + "vnd.sun.Star.script:Protected.Module1." + sTestName + + "?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue); + } + } + + css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +void ScMacrosTest::testTdf131296_new() +{ + // For new password-protected library images, we must correctly get both the constants' values + // and their types. + const std::vector<std::pair<OUString, OUString>> aTests({ + { "TestIntConst", "Integer: 123" }, + { "TestLongConst", "Long: 123" }, + { "TestSingleConst", "Single: 123" }, + { "TestDoubleConst", "Double: 123" }, + { "TestCurrencyConst", "Currency: 123.0000" }, + }); + + OUString aFileName; + createFileURL("tdf131296_new.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + CPPUNIT_ASSERT(xComponent); + + { + Any aRet; + Sequence<sal_Int16> aOutParamIndex; + Sequence<Any> aOutParam; + Sequence<uno::Any> aParams; + + for (auto& [sTestName, sExpected] : aTests) + { + SfxObjectShell::CallXScript(xComponent, + "vnd.sun.Star.script:Protected.Module1." + sTestName + + "?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue); + } + } + + css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + +ScMacrosTest::ScMacrosTest() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScMacrosTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/new_cond_format.cxx b/sc/qa/extras/new_cond_format.cxx new file mode 100644 index 000000000..caebb4b4a --- /dev/null +++ b/sc/qa/extras/new_cond_format.cxx @@ -0,0 +1,465 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XConditionalFormats.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/DataBarAxis.hpp> +#include <com/sun/star/sheet/XDataBarEntry.hpp> +#include <com/sun/star/sheet/DataBarEntryType.hpp> +#include <com/sun/star/sheet/ColorScaleEntryType.hpp> +#include <com/sun/star/sheet/XColorScaleEntry.hpp> + +using namespace css; + +static std::ostream& operator<<(std::ostream& rStrm, const Color& rColor) +{ + rStrm << "Color: R:" << static_cast<int>(rColor.GetRed()) << " G:" << static_cast<int>(rColor.GetGreen()) << " B: " << static_cast<int>(rColor.GetBlue()); + return rStrm; +} + +namespace sc_apitest { + +class ScConditionalFormatTest : public CalcUnoApiTest +{ +public: + ScConditionalFormatTest(); + + virtual void setUp() override; + virtual void tearDown() override; + + uno::Reference< uno::XInterface > init(sal_Int32 nIndex = 0); + void testRequestCondFormatListFromSheet(); + void testCondFormatListProperties(); + void testCondFormatListFormats(); + void testCondFormatProperties(); + void testCondFormatXIndex(); + void testDataBarProperties(); + void testColorScaleProperties(); + + CPPUNIT_TEST_SUITE(ScConditionalFormatTest); + CPPUNIT_TEST(testRequestCondFormatListFromSheet); + CPPUNIT_TEST(testCondFormatListProperties); + CPPUNIT_TEST(testCondFormatListFormats); + CPPUNIT_TEST(testCondFormatProperties); + CPPUNIT_TEST(testCondFormatXIndex); + CPPUNIT_TEST(testDataBarProperties); + CPPUNIT_TEST(testColorScaleProperties); + CPPUNIT_TEST_SUITE_END(); +private: + + uno::Reference< lang::XComponent > mxComponent; +}; + +ScConditionalFormatTest::ScConditionalFormatTest() + : CalcUnoApiTest("sc/qa/extras/testdocuments/") +{ +} + +uno::Reference< uno::XInterface > ScConditionalFormatTest::init(sal_Int32 nIndex) +{ + // get the first sheet + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(nIndex), uno::UNO_QUERY_THROW); + + return xSheet; +} + +void ScConditionalFormatTest::testRequestCondFormatListFromSheet() +{ + uno::Reference<sheet::XSpreadsheet> xSheet(init(), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xProps(xSheet, uno::UNO_QUERY_THROW); + uno::Any aAny = xProps->getPropertyValue("ConditionalFormats"); + uno::Reference<sheet::XConditionalFormats> xCondFormats; + CPPUNIT_ASSERT(aAny >>= xCondFormats); + CPPUNIT_ASSERT(xCondFormats.is()); +} + +namespace { + +uno::Reference<sheet::XConditionalFormats> getConditionalFormatList(uno::Reference<uno::XInterface> const & xInterface) +{ + uno::Reference<sheet::XSpreadsheet> xSheet(xInterface, uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xProps(xSheet, uno::UNO_QUERY_THROW); + uno::Any aAny = xProps->getPropertyValue("ConditionalFormats"); + uno::Reference<sheet::XConditionalFormats> xCondFormats; + CPPUNIT_ASSERT(aAny >>= xCondFormats); + CPPUNIT_ASSERT(xCondFormats.is()); + + return xCondFormats; +} + +} + +void ScConditionalFormatTest::testCondFormatListProperties() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormat = + getConditionalFormatList(init()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xCondFormat->getLength()); +} + +void ScConditionalFormatTest::testCondFormatListFormats() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormatList = + getConditionalFormatList(init()); + + const uno::Sequence<uno::Reference<sheet::XConditionalFormat> > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xCondFormats.getLength()); + for (auto const & cf : xCondFormats) + { + CPPUNIT_ASSERT(cf.is()); + } +} + +void ScConditionalFormatTest::testCondFormatProperties() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormatList = + getConditionalFormatList(init(1)); + + uno::Sequence<uno::Reference<sheet::XConditionalFormat> > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference<sheet::XConditionalFormat> xCondFormat = xCondFormats[0]; + CPPUNIT_ASSERT(xCondFormat.is()); + uno::Reference<beans::XPropertySet> xPropSet(xCondFormat, uno::UNO_QUERY_THROW); + uno::Any aAny = xPropSet->getPropertyValue("Range"); + uno::Reference<sheet::XSheetCellRanges> xCellRanges; + CPPUNIT_ASSERT(aAny >>= xCellRanges); + CPPUNIT_ASSERT(xCellRanges.is()); + uno::Sequence<table::CellRangeAddress> aRanges = xCellRanges->getRangeAddresses(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRanges.getLength()); + table::CellRangeAddress aRange = aRanges[0]; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), aRange.Sheet); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aRange.StartColumn); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), aRange.StartRow); + CPPUNIT_ASSERT_EQUAL(sal_Int32(7), aRange.EndColumn); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aRange.EndRow); +} + +void ScConditionalFormatTest::testCondFormatXIndex() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormatList = + getConditionalFormatList(init(1)); + + uno::Sequence<uno::Reference<sheet::XConditionalFormat> > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference<sheet::XConditionalFormat> xCondFormat = xCondFormats[0]; + CPPUNIT_ASSERT(xCondFormat.is()); + + uno::Type aType = xCondFormat->getElementType(); + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.beans.XPropertySet"), aType.getTypeName()); + + CPPUNIT_ASSERT(xCondFormat->hasElements()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xCondFormat->getCount()); + + uno::Any aAny = xCondFormat->getByIndex(0); + CPPUNIT_ASSERT(aAny.hasValue()); +} + +namespace { + +void testAxisPosition(uno::Reference<beans::XPropertySet> const & xPropSet, sal_Int32 ePos) +{ + sal_Int32 eAxisPos; + uno::Any aAny = xPropSet->getPropertyValue("AxisPosition"); + CPPUNIT_ASSERT(aAny >>= eAxisPos); + CPPUNIT_ASSERT_EQUAL(ePos, eAxisPos); +} + +void testShowValue(uno::Reference<beans::XPropertySet> const & xPropSet, bool bShowVal) +{ + bool bShow; + uno::Any aAny = xPropSet->getPropertyValue("ShowValue"); + CPPUNIT_ASSERT(aAny >>= bShow); + CPPUNIT_ASSERT_EQUAL(bShowVal, bShow); +} + +void testUseGradient(uno::Reference<beans::XPropertySet> const & xPropSet, bool bUseGradient) +{ + bool bGradient; + uno::Any aAny = xPropSet->getPropertyValue("UseGradient"); + CPPUNIT_ASSERT(aAny >>= bGradient); + CPPUNIT_ASSERT_EQUAL(bUseGradient, bGradient); +} + +void testPositiveColor(uno::Reference<beans::XPropertySet> const & xPropSet, Color aColor) +{ + ::Color nColor; + uno::Any aAny = xPropSet->getPropertyValue("Color"); + CPPUNIT_ASSERT(aAny >>= nColor); + CPPUNIT_ASSERT_EQUAL(aColor, nColor); +} + +void testNegativeColor(uno::Reference<beans::XPropertySet> const & xPropSet, Color aColor) +{ + ::Color nColor; + uno::Any aAny = xPropSet->getPropertyValue("NegativeColor"); + CPPUNIT_ASSERT(aAny >>= nColor); + CPPUNIT_ASSERT_EQUAL(aColor, nColor); +} + +void testAxisColor(uno::Reference<beans::XPropertySet> const & xPropSet, Color aColor) +{ + ::Color nColor; + uno::Any aAny = xPropSet->getPropertyValue("AxisColor"); + CPPUNIT_ASSERT(aAny >>= nColor); + CPPUNIT_ASSERT_EQUAL(aColor, nColor); +} + +void testDataBarEntryValue(uno::Reference<sheet::XDataBarEntry> const & xEntry, + const OUString& rExpectedValue, sal_Int32 nType) +{ + switch (nType) + { + case sheet::DataBarEntryType::DATABAR_VALUE: + case sheet::DataBarEntryType::DATABAR_PERCENT: + case sheet::DataBarEntryType::DATABAR_PERCENTILE: + case sheet::DataBarEntryType::DATABAR_FORMULA: + { + OUString aString = xEntry->getFormula(); + CPPUNIT_ASSERT_EQUAL(rExpectedValue, aString); + } + break; + default: + break; + } +} + +void testDataBarEntries(uno::Reference<beans::XPropertySet> const & xPropSet, + const OUString& rExpectedMinString, sal_Int32 nExpectedMinType, + const OUString& rExpectedMaxString, sal_Int32 nExpectedMaxType) +{ + uno::Any aAny = xPropSet->getPropertyValue("DataBarEntries"); + uno::Sequence<uno::Reference<sheet::XDataBarEntry> > aEntries; + CPPUNIT_ASSERT(aAny >>= aEntries); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aEntries.getLength()); + + sal_Int32 nMinType = aEntries[0]->getType(); + CPPUNIT_ASSERT_EQUAL(nExpectedMinType, nMinType); + + sal_Int32 nMaxType = aEntries[1]->getType(); + CPPUNIT_ASSERT_EQUAL(nExpectedMaxType, nMaxType); + + testDataBarEntryValue(aEntries[0], rExpectedMinString, nMinType); + testDataBarEntryValue(aEntries[1], rExpectedMaxString, nMaxType); +} + +} + +void ScConditionalFormatTest::testDataBarProperties() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormatList = + getConditionalFormatList(init(2)); + + uno::Sequence<uno::Reference<sheet::XConditionalFormat> > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference<sheet::XConditionalFormat> xCondFormat = xCondFormats[0]; + CPPUNIT_ASSERT(xCondFormat.is()); + + uno::Type aType = xCondFormat->getElementType(); + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.beans.XPropertySet"), aType.getTypeName()); + + CPPUNIT_ASSERT(xCondFormat->hasElements()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xCondFormat->getCount()); + + uno::Reference<beans::XPropertySet> xPropSet; + { + uno::Any aAny = xCondFormat->getByIndex(0); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testAxisPosition(xPropSet, sheet::DataBarAxis::AXIS_AUTOMATIC); + testShowValue(xPropSet, true); + testUseGradient(xPropSet, true); + testPositiveColor(xPropSet, COL_LIGHTBLUE); + testNegativeColor(xPropSet, COL_LIGHTRED); + testAxisColor(xPropSet, COL_BLACK); + testDataBarEntries(xPropSet, "", sheet::DataBarEntryType::DATABAR_AUTO, + "", sheet::DataBarEntryType::DATABAR_MAX); + } + { + uno::Any aAny = xCondFormat->getByIndex(1); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testAxisPosition(xPropSet, sheet::DataBarAxis::AXIS_AUTOMATIC); + testShowValue(xPropSet, true); + testUseGradient(xPropSet, true); + testPositiveColor(xPropSet, COL_LIGHTBLUE); + testNegativeColor(xPropSet, COL_LIGHTRED); + testAxisColor(xPropSet, COL_BLACK); + testDataBarEntries(xPropSet, "", sheet::DataBarEntryType::DATABAR_MIN, + "90", sheet::DataBarEntryType::DATABAR_PERCENTILE); + } + { + uno::Any aAny = xCondFormat->getByIndex(2); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testAxisPosition(xPropSet, sheet::DataBarAxis::AXIS_AUTOMATIC); + testShowValue(xPropSet, true); + testUseGradient(xPropSet, true); + testPositiveColor(xPropSet, COL_LIGHTBLUE); + testNegativeColor(xPropSet, COL_LIGHTRED); + testAxisColor(xPropSet, COL_BLACK); + testDataBarEntries(xPropSet, "2", sheet::DataBarEntryType::DATABAR_VALUE, + "80", sheet::DataBarEntryType::DATABAR_PERCENT); + } + { + uno::Any aAny = xCondFormat->getByIndex(3); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testAxisPosition(xPropSet, sheet::DataBarAxis::AXIS_AUTOMATIC); + testShowValue(xPropSet, true); + testUseGradient(xPropSet, true); + testPositiveColor(xPropSet, COL_LIGHTBLUE); + testNegativeColor(xPropSet, COL_LIGHTRED); + testAxisColor(xPropSet, COL_BLACK); + /* + * TODO: implement FORMULA + testDataBarEntries(xPropSet, "=A1", sheet::DataBarEntryType::DATABAR_FORMULA, + "", sheet::DataBarEntryType::DATABAR_AUTO); + */ + } + { + uno::Any aAny = xCondFormat->getByIndex(4); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testAxisPosition(xPropSet, sheet::DataBarAxis::AXIS_MIDDLE); + testShowValue(xPropSet, true); + testUseGradient(xPropSet, false); + testPositiveColor(xPropSet, sal_uInt32(10092390)); + testNegativeColor(xPropSet, sal_uInt32(52428)); + testAxisColor(xPropSet, sal_uInt32(16777113)); + testDataBarEntries(xPropSet, "", sheet::DataBarEntryType::DATABAR_AUTO, + "", sheet::DataBarEntryType::DATABAR_AUTO); + } +} + +namespace { + +void testColorScaleEntry(uno::Reference<sheet::XColorScaleEntry> const & xEntry, + sal_Int32 nType, const OUString& rString, Color nColor) +{ + CPPUNIT_ASSERT_EQUAL(nType, xEntry->getType()); + CPPUNIT_ASSERT_EQUAL(nColor, Color(xEntry->getColor())); + switch (nType) + { + case sheet::ColorScaleEntryType::COLORSCALE_VALUE: + case sheet::ColorScaleEntryType::COLORSCALE_PERCENT: + case sheet::ColorScaleEntryType::COLORSCALE_PERCENTILE: + // case sheet::ColorScaleEntryType::COLORSCALE_FORMULA: + { + CPPUNIT_ASSERT_EQUAL(rString, xEntry->getFormula()); + } + break; + default: + break; + } +} + +void testColorScaleEntries(uno::Reference<beans::XPropertySet> const & xPropSet, sal_Int32 nEntries, + sal_Int32 nMinType, const OUString& rMinString, Color nMinColor, + sal_Int32 nMediumType, const OUString& rMediumString, Color nMediumColor, + sal_Int32 nMaxType, const OUString& rMaxString, Color nMaxColor) +{ + uno::Any aAny = xPropSet->getPropertyValue("ColorScaleEntries"); + CPPUNIT_ASSERT(aAny.hasValue()); + uno::Sequence<uno::Reference<sheet::XColorScaleEntry> > aEntries; + CPPUNIT_ASSERT(aAny >>= aEntries); + + CPPUNIT_ASSERT_EQUAL(nEntries, aEntries.getLength()); + testColorScaleEntry(aEntries[0], nMinType, rMinString, nMinColor); + size_t nMaxEntry = 1; + if (nEntries == 3) + { + nMaxEntry = 2; + testColorScaleEntry(aEntries[1], nMediumType, rMediumString, nMediumColor); + } + testColorScaleEntry(aEntries[nMaxEntry], nMaxType, rMaxString, nMaxColor); +} + +} + +void ScConditionalFormatTest::testColorScaleProperties() +{ + uno::Reference<sheet::XConditionalFormats> xCondFormatList = + getConditionalFormatList(init(3)); + + uno::Sequence<uno::Reference<sheet::XConditionalFormat> > xCondFormats = + xCondFormatList->getConditionalFormats(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xCondFormats.getLength()); + + uno::Reference<sheet::XConditionalFormat> xCondFormat = xCondFormats[0]; + CPPUNIT_ASSERT(xCondFormat.is()); + + uno::Type aType = xCondFormat->getElementType(); + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.beans.XPropertySet"), aType.getTypeName()); + + CPPUNIT_ASSERT(xCondFormat->hasElements()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xCondFormat->getCount()); + + uno::Reference<beans::XPropertySet> xPropSet; + { + uno::Any aAny = xCondFormat->getByIndex(0); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testColorScaleEntries(xPropSet, 3, sheet::ColorScaleEntryType::COLORSCALE_MIN, "", sal_uInt32(16777113), + sheet::ColorScaleEntryType::COLORSCALE_PERCENTILE, "50", sal_uInt32(16737792), + sheet::ColorScaleEntryType::COLORSCALE_MAX, "", sal_uInt32(16724787)); + } + { + uno::Any aAny = xCondFormat->getByIndex(1); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testColorScaleEntries(xPropSet, 3, sheet::ColorScaleEntryType::COLORSCALE_VALUE, "0", sal_uInt32(16711680), + sheet::ColorScaleEntryType::COLORSCALE_PERCENTILE, "50", sal_uInt32(10092390), + sheet::ColorScaleEntryType::COLORSCALE_PERCENT, "90", sal_uInt32(255)); + } + { + uno::Any aAny = xCondFormat->getByIndex(2); + CPPUNIT_ASSERT(aAny.hasValue()); + CPPUNIT_ASSERT(aAny >>= xPropSet); + testColorScaleEntries(xPropSet, 2, sheet::ColorScaleEntryType::COLORSCALE_FORMULA, "=A1", COL_WHITE, + sheet::ColorScaleEntryType::COLORSCALE_PERCENTILE, "not used", sal_uInt32(1), + sheet::ColorScaleEntryType::COLORSCALE_VALUE, "10", COL_BLACK); + } +} + +void ScConditionalFormatTest::setUp() +{ + CalcUnoApiTest::setUp(); + // get the test file + OUString aFileURL; + createFileURL("new_cond_format_api.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL); +} + +void ScConditionalFormatTest::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScConditionalFormatTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/recordchanges-test.cxx b/sc/qa/extras/recordchanges-test.cxx new file mode 100644 index 000000000..357023e0d --- /dev/null +++ b/sc/qa/extras/recordchanges-test.cxx @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/unoapi_test.hxx> + +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <rtl/ustring.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +/* Implementation of calc Record Changes test */ + +class ScRecordChangesTest : public UnoApiTest +{ +public: + ScRecordChangesTest(); + + void testSetRecordChanges(); + void testCheckRecordChangesProtection(); + + CPPUNIT_TEST_SUITE(ScRecordChangesTest); + CPPUNIT_TEST(testSetRecordChanges); + CPPUNIT_TEST(testCheckRecordChangesProtection); + CPPUNIT_TEST_SUITE_END(); + +}; + +void ScRecordChangesTest::testSetRecordChanges() +{ + + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop("private:factory/scalc"); + + uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW); + uno::Reference< beans::XPropertySet > xDocSettingsPropSet (xDoc, UNO_QUERY_THROW); + + bool recordChangesValue = true; + bool protectionValue = true; + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") >>= protectionValue); + + CPPUNIT_ASSERT_MESSAGE("a new document does not record changes", !recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("a new document does not protect record changes", !protectionValue); + + // now activate recording + uno::Any aValue; + aValue <<= true; + xDocSettingsPropSet->setPropertyValue("RecordChanges", aValue); + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("the document should record changes", recordChangesValue); + + closeDocument(xComponent); +} + +void ScRecordChangesTest::testCheckRecordChangesProtection() +{ + // test with protected changes + OUString aFileName; + createFileURL( "RecordChangesProtected.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName); + + uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW); + uno::Reference< beans::XPropertySet > xDocSettingsPropSet (xDoc, UNO_QUERY_THROW); + + bool recordChangesValue = false; + bool protectionValue = false; + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") >>= protectionValue); + + CPPUNIT_ASSERT_MESSAGE("the document should be recording changes", recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("the protection should be active", protectionValue); + + // try to de-activate recording + uno::Any aValue; + aValue <<= false; + xDocSettingsPropSet->setPropertyValue("RecordChanges", aValue); + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") >>= protectionValue); + + // this document should still record changes as protection is set + CPPUNIT_ASSERT_MESSAGE("the document should still be recording changes", recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("the protection should still be active", protectionValue); + + closeDocument(xComponent); +} + +ScRecordChangesTest::ScRecordChangesTest() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScRecordChangesTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/regression-test.cxx b/sc/qa/extras/regression-test.cxx new file mode 100644 index 000000000..27b85ece8 --- /dev/null +++ b/sc/qa/extras/regression-test.cxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <sal/config.h> +#include <test/unoapi_test.hxx> +#include <rtl/strbuf.hxx> +#include <osl/file.hxx> + +#include <sfx2/app.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/sfxmodelfactory.hxx> +#include <svl/intitem.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/table/XTableChartsSupplier.hpp> +#include <com/sun/star/table/XTableCharts.hpp> +#include <com/sun/star/table/XTableChart.hpp> +#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/qa/XDumper.hpp> + +#include <test/xmldiff.hxx> + +#include <basic/sbxdef.hxx> + +#include "docsh.hxx" +#include "patattr.hxx" +#include "scitems.hxx" +#include "document.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace { + +bool checkDumpAgainstFile( const OUString& rDump, const OUString aFilePath, const OUString& rToleranceFile) +{ + OString aOFile = OUStringToOString(aFilePath, RTL_TEXTENCODING_UTF8); + OString aToleranceFile = OUStringToOString(rToleranceFile, RTL_TEXTENCODING_UTF8); + + CPPUNIT_ASSERT_MESSAGE("dump is empty", !rDump.isEmpty()); + + OString aDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8); + return doXMLDiff(aOFile.getStr(), aDump.getStr(), + static_cast<int>(rDump.getLength()), aToleranceFile.getStr()); +} + +} + +class ScChartRegressionTest : public UnoApiTest +{ +public: + ScChartRegressionTest(); + + void test(); + + CPPUNIT_TEST_SUITE(ScChartRegressionTest); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); + +}; + +void ScChartRegressionTest::test() +{ + OUString aFileName; + createFileURL( "testChart.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + CPPUNIT_ASSERT(xComponent.is()); + + uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW); + + uno::Reference< table::XTableChartsSupplier > xChartSupplier( xIA->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference< table::XTableCharts > xCharts = xChartSupplier->getCharts(); + CPPUNIT_ASSERT(xCharts.is()); + + uno::Reference< container::XIndexAccess > xIACharts(xCharts, UNO_QUERY_THROW); + uno::Reference< table::XTableChart > xChart( xIACharts->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference< document::XEmbeddedObjectSupplier > xEmbObjectSupplier(xChart, UNO_QUERY_THROW); + + uno::Reference< lang::XComponent > xChartComp( xEmbObjectSupplier->getEmbeddedObject(), UNO_QUERY_THROW ); + + uno::Reference< chart2::XChartDocument > xChartDoc ( xChartComp, UNO_QUERY_THROW ); + + uno::Reference< qa::XDumper > xDumper( xChartDoc, UNO_QUERY_THROW ); + + OUString aDump = xDumper->dump(); + std::cout << aDump; + bool bCompare = checkDumpAgainstFile( aDump, getPathFromSrc("/chart2/qa/unit/data/reference/testChart.xml"), getPathFromSrc("/chart2/qa/unit/data/tolerance.xml") ); + CPPUNIT_ASSERT(bCompare); +} + +ScChartRegressionTest::ScChartRegressionTest() + : UnoApiTest("/chart2/qa/unit/data/ods") +{ +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScChartRegressionTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scannotationobj.cxx b/sc/qa/extras/scannotationobj.cxx new file mode 100644 index 000000000..a8ee3ecfe --- /dev/null +++ b/sc/qa/extras/scannotationobj.cxx @@ -0,0 +1,147 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xchild.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xsheetannotation.hxx> +#include <test/sheet/xsheetannotationshapesupplier.hxx> +#include <test/text/xsimpletext.hxx> +#include <test/text/xtextrange.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScAnnontationObj : public CalcUnoApiTest, + public apitest::XChild, + public apitest::XServiceInfo, + public apitest::XSheetAnnotation, + public apitest::XSheetAnnotationShapeSupplier, + public apitest::XSimpleText, + public apitest::XTextRange +{ +public: + ScAnnontationObj(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<sheet::XSheetAnnotation> getAnnotation(table::CellAddress&) override; + + CPPUNIT_TEST_SUITE(ScAnnontationObj); + + // XChild + CPPUNIT_TEST(testGetSetParent); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XSheetAnnotation + CPPUNIT_TEST(testGetPosition); + CPPUNIT_TEST(testGetAuthor); + CPPUNIT_TEST(testGetDate); + CPPUNIT_TEST(testGetIsVisible); + CPPUNIT_TEST(testSetIsVisible); + + // XSheetAnnotationShapeSupplier + CPPUNIT_TEST(testGetAnnotationShape); + + // XSimpleText + CPPUNIT_TEST(testCreateTextCursor); + CPPUNIT_TEST(testCreateTextCursorByRange); + CPPUNIT_TEST(testInsertString); + CPPUNIT_TEST(testInsertControlCharacter); + + // XTextRange + CPPUNIT_TEST(testGetEnd); + CPPUNIT_TEST(testGetSetString); + CPPUNIT_TEST(testGetStart); + CPPUNIT_TEST(testGetText); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScAnnontationObj::ScAnnontationObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XServiceInfo("ScAnnotationObj", "com.sun.star.sheet.CellAnnotation") +{ +} + +uno::Reference<sheet::XSheetAnnotation> +ScAnnontationObj::getAnnotation(table::CellAddress& xCellAddress) +{ + // get the sheet + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(xCellAddress.Sheet), + uno::UNO_QUERY_THROW); + + // get the cell + uno::Reference<table::XCell> xCell( + xSheet->getCellByPosition(xCellAddress.Column, xCellAddress.Row), uno::UNO_SET_THROW); + + // get the annotation from cell + uno::Reference<sheet::XSheetAnnotationAnchor> xAnnotationAnchor(xCell, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotation> xSheetAnnotation(xAnnotationAnchor->getAnnotation(), + uno::UNO_SET_THROW); + + return xSheetAnnotation; +} + +uno::Reference<uno::XInterface> ScAnnontationObj::init() +{ + // tested annotation is in sheet 0 cell C2 + table::CellAddress aCellAddress; + aCellAddress.Sheet = 0; + aCellAddress.Row = 1; + aCellAddress.Column = 2; + + return getAnnotation(aCellAddress); +} + +void ScAnnontationObj::setUp() +{ + CalcUnoApiTest::setUp(); + + // get the test file + OUString aFileURL; + createFileURL("ScAnnotationObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL); +} + +void ScAnnontationObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnontationObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scannotationshapeobj.cxx b/sc/qa/extras/scannotationshapeobj.cxx new file mode 100644 index 000000000..5a7a7258e --- /dev/null +++ b/sc/qa/extras/scannotationshapeobj.cxx @@ -0,0 +1,162 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/drawing/captionshape.hxx> +#include <test/drawing/xgluepointssupplier.hxx> +#include <test/drawing/xshape.hxx> +#include <test/drawing/xshapedescriptor.hxx> +#include <test/text/xsimpletext.hxx> +#include <test/text/xtext.hxx> +#include <test/text/xtextrange.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetAnnotation.hpp> +#include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp> +#include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp> +#include <com/sun/star/sheet/XSheetAnnotations.hpp> +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/XSimpleText.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScAnnotationShapeObj : public CalcUnoApiTest, + public apitest::CaptionShape, + public apitest::XGluePointsSupplier, + public apitest::XShape, + public apitest::XShapeDescriptor, + public apitest::XSimpleText, + public apitest::XText, + public apitest::XTextRange +{ +public: + ScAnnotationShapeObj(); + + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<text::XTextContent> getTextContent() override; + + CPPUNIT_TEST_SUITE(ScAnnotationShapeObj); + + // CaptionShape + CPPUNIT_TEST(testCaptionShapeProperties); + + // XGluePointsSupplier + CPPUNIT_TEST(testGetGluePoints); + + // XShape + CPPUNIT_TEST(testGetSetSize); + CPPUNIT_TEST(testGetSetPosition); + + // XShapeDescriptor + CPPUNIT_TEST(testGetShapeType); + + // XSimpleText + CPPUNIT_TEST(testCreateTextCursor); + CPPUNIT_TEST(testCreateTextCursorByRange); + CPPUNIT_TEST(testInsertControlCharacter); + CPPUNIT_TEST(testInsertString); + + // XText + CPPUNIT_TEST(testInsertRemoveTextContent); + + // XTextRange + CPPUNIT_TEST(testGetEnd); + CPPUNIT_TEST(testGetSetString); + CPPUNIT_TEST(testGetStart); + CPPUNIT_TEST(testGetText); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; + static uno::Reference<text::XTextContent> m_xField; +}; + +uno::Reference<text::XTextContent> ScAnnotationShapeObj::m_xField; + +ScAnnotationShapeObj::ScAnnotationShapeObj() + : CalcUnoApiTest("sc/qa/extras/testdocuments") + , XShapeDescriptor("com.sun.star.drawing.CaptionShape") +{ +} + +void ScAnnotationShapeObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAnnotationShapeObj::tearDown() +{ + m_xField.clear(); + closeDocument(m_xComponent); + + CalcUnoApiTest::tearDown(); +} + +uno::Reference<uno::XInterface> ScAnnotationShapeObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + // Use cell A1 for this. + table::CellAddress aNotePos(0, 0, 0); + uno::Reference<sheet::XSheetAnnotationsSupplier> xAnnosSupp(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotations> xAnnos(xAnnosSupp->getAnnotations(), + uno::UNO_SET_THROW); + // non-empty string required by note implementation (real text will be added below) + xAnnos->insertNew(aNotePos, OUString(' ')); + + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0); + uno::Reference<sheet::XSheetAnnotationAnchor> xAnchor(xCell, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotation> xAnnotation(xAnchor->getAnnotation(), + uno::UNO_SET_THROW); + uno::Reference<text::XSimpleText> xAnnoText(xAnnotation, uno::UNO_QUERY_THROW); + xAnnoText->setString("ScAnnotationShapeObj"); + + uno::Reference<sheet::XSheetAnnotationShapeSupplier> xShapeSupp(xAnnotation, + uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape(xShapeSupp->getAnnotationShape(), uno::UNO_SET_THROW); + + return xShape; +} + +uno::Reference<text::XTextContent> ScAnnotationShapeObj::getTextContent() +{ + if (!m_xField.is()) + { + uno::Reference<lang::XMultiServiceFactory> xSM(m_xComponent, uno::UNO_QUERY_THROW); + m_xField.set(xSM->createInstance("com.sun.star.text.TextField.DateTime"), + uno::UNO_QUERY_THROW); + } + return m_xField; +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnotationShapeObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scannotationsobj.cxx b/sc/qa/extras/scannotationsobj.cxx new file mode 100644 index 000000000..72fafc60a --- /dev/null +++ b/sc/qa/extras/scannotationsobj.cxx @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/sheet/xsheetannotations.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetAnnotation.hpp> +#include <com/sun/star/sheet/XSheetAnnotations.hpp> +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScAnnontationsObj : public CalcUnoApiTest, public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XSheetAnnotations +{ +public: + ScAnnontationsObj(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< sheet::XSheetAnnotations > getAnnotations(long nIndex) override; + + CPPUNIT_TEST_SUITE(ScAnnontationsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XSheetAnnotations + CPPUNIT_TEST(testCount); + CPPUNIT_TEST(testIndex); + CPPUNIT_TEST(testInsertNew); + CPPUNIT_TEST(testRemoveByIndex); + + CPPUNIT_TEST_SUITE_END(); + +private: + + uno::Reference< lang::XComponent > mxComponent; +}; + + +ScAnnontationsObj::ScAnnontationsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XSheetAnnotation>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference< sheet::XSheetAnnotations> ScAnnontationsObj::getAnnotations(long nIndex) +{ + // get the sheet + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(nIndex), UNO_QUERY_THROW); + + // get the annotations collection + uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnotationSupplier(xSheet, UNO_QUERY_THROW); + uno::Reference< sheet::XSheetAnnotations > xSheetAnnotations( xAnnotationSupplier->getAnnotations(), UNO_SET_THROW); + + return xSheetAnnotations; +} + +uno::Reference< uno::XInterface > ScAnnontationsObj::init() +{ + return getAnnotations(0); +} + +void ScAnnontationsObj::setUp() +{ + CalcUnoApiTest::setUp(); + + // get the test file + OUString aFileURL; + createFileURL("ScAnnotationObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL); +} + +void ScAnnontationsObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnontationsObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scarealinkobj.cxx b/sc/qa/extras/scarealinkobj.cxx new file mode 100644 index 000000000..ccde1b550 --- /dev/null +++ b/sc/qa/extras/scarealinkobj.cxx @@ -0,0 +1,115 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/sheet/cellarealink.hxx> +#include <test/sheet/xarealink.hxx> +#include <test/util/xrefreshable.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XAreaLink.hpp> +#include <com/sun/star/sheet/XAreaLinks.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScAreaLinkObj : public CalcUnoApiTest, + public apitest::CellAreaLink, + public apitest::XAreaLink, + public apitest::XPropertySet, + public apitest::XRefreshable +{ +public: + ScAreaLinkObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScAreaLinkObj); + + // CellAreaLink + CPPUNIT_TEST(testUrl); + CPPUNIT_TEST(testFilter); + CPPUNIT_TEST(testFilterOptions); + CPPUNIT_TEST(testRefreshDelay); + CPPUNIT_TEST(testRefreshPeriod); + + // XAreaLink + CPPUNIT_TEST(testGetDestArea); + CPPUNIT_TEST(testGetSourceArea); + CPPUNIT_TEST(testSetSourceArea); + CPPUNIT_TEST(testSetDestArea); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScAreaLinkObj::ScAreaLinkObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , CellAreaLink(m_directories.getURLFromSrc("/sc/qa/extras/testdocuments/scarealinkobj.ods")) +{ +} + +uno::Reference<uno::XInterface> ScAreaLinkObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XAreaLinks> xLinks(xPropSet->getPropertyValue("AreaLinks"), + uno::UNO_QUERY_THROW); + + table::CellAddress aCellAddress(1, 2, 3); + xLinks->insertAtPosition( + aCellAddress, m_directories.getURLFromSrc("/sc/qa/extras/testdocuments/scarealinkobj.ods"), + "a2:b5", "", ""); + + uno::Reference<sheet::XAreaLink> xLink(xLinks->getByIndex(0), uno::UNO_QUERY_THROW); + return xLink; +} + +void ScAreaLinkObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAreaLinkObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAreaLinkObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scarealinksobj.cxx b/sc/qa/extras/scarealinksobj.cxx new file mode 100644 index 000000000..6e14ccf22 --- /dev/null +++ b/sc/qa/extras/scarealinksobj.cxx @@ -0,0 +1,108 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/sheet/xarealinks.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XAreaLink.hpp> +#include <com/sun/star/sheet/XAreaLinks.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScAreaLinksObj : public CalcUnoApiTest, + public apitest::XAreaLinks, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess +{ +public: + ScAreaLinksObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScAreaLinksObj); + + // XAreaLinks + CPPUNIT_TEST(testInsertAtPosition); + CPPUNIT_TEST(testRemoveByIndex); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScAreaLinksObj::ScAreaLinksObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XAreaLink>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference<uno::XInterface> ScAreaLinksObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XAreaLinks> xLinks(xPropSet->getPropertyValue("AreaLinks"), + uno::UNO_QUERY_THROW); + + xLinks->insertAtPosition(table::CellAddress(1, 2, 3), "ScAreaLinksObj.ods", "A2:B5", "", ""); + + return xLinks; +} + +void ScAreaLinksObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAreaLinksObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAreaLinksObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scautoformatobj.cxx b/sc/qa/extras/scautoformatobj.cxx new file mode 100644 index 000000000..76db8c6a3 --- /dev/null +++ b/sc/qa/extras/scautoformatobj.cxx @@ -0,0 +1,127 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnamed.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/tableautoformat.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScAutoFormatObj : public CalcUnoApiTest, + public apitest::TableAutoFormat, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScAutoFormatObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScAutoFormatObj); + + // TableAutoFormat + CPPUNIT_TEST(testTableAutoFormatProperties); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScAutoFormatObj::ScAutoFormatObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<beans::XPropertySet>::get()) + , XIndexAccess(16) + , XNamed("Default") + , XServiceInfo("ScAutoFormatObj", "com.sun.star.sheet.TableAutoFormat") +{ +} + +uno::Reference<uno::XInterface> ScAutoFormatObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA( + xMSF->createInstance("com.sun.star.sheet.TableAutoFormats"), uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xTableAutoFormat(xIA->getByIndex(xIA->getCount() - 1), + uno::UNO_QUERY_THROW); + return xTableAutoFormat; +} + +void ScAutoFormatObj::setUp() +{ + CalcUnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAutoFormatObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAutoFormatObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scautoformatsobj.cxx b/sc/qa/extras/scautoformatsobj.cxx new file mode 100644 index 000000000..ed799c018 --- /dev/null +++ b/sc/qa/extras/scautoformatsobj.cxx @@ -0,0 +1,140 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xnamecontainer.hxx> +#include <test/container/xnamereplace.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScAutoFormatsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNameContainer, + public apitest::XNameReplace, + public apitest::XServiceInfo +{ +public: + ScAutoFormatsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScAutoFormatsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNameContainer + CPPUNIT_TEST(testInsertByName); + CPPUNIT_TEST(testInsertByNameEmptyName); + CPPUNIT_TEST(testInsertByNameDuplicate); + CPPUNIT_TEST(testRemoveByName); + CPPUNIT_TEST(testRemoveByNameNoneExistingElement); + + // XNameReplace + CPPUNIT_TEST(testReplaceByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScAutoFormatsObj::ScAutoFormatsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<container::XNamed>::get()) + , XIndexAccess(2) + , XNameAccess("Default") + , XNameContainer("ScAutoFormatsObj") + , XNameReplace("ScAutoFormatsObj") + , XServiceInfo("stardiv.StarCalc.ScAutoFormatsObj", "com.sun.star.sheet.TableAutoFormats") +{ +} + +uno::Reference<uno::XInterface> ScAutoFormatsObj::init() +{ + uno::Reference<lang::XMultiServiceFactory> xMSF(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xTAF( + xMSF->createInstance("com.sun.star.sheet.TableAutoFormats"), uno::UNO_SET_THROW); + + uno::Reference<container::XNameContainer> xNC(xTAF, uno::UNO_QUERY_THROW); + if (!xNC->hasByName("ScAutoFormatsObj")) + { + xNC->insertByName("ScAutoFormatsObj", + uno::makeAny(xMSF->createInstance("com.sun.star.sheet.TableAutoFormat"))); + } + // XNameContainer + XNameContainer::setElement( + uno::makeAny(xMSF->createInstance("com.sun.star.sheet.TableAutoFormat"))); + // XNameReplace + XNameReplace::setElement( + uno::makeAny(xMSF->createInstance("com.sun.star.sheet.TableAutoFormat"))); + + return xTAF; +} + +void ScAutoFormatsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScAutoFormatsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScAutoFormatsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellcursorobj.cxx b/sc/qa/extras/sccellcursorobj.cxx new file mode 100644 index 000000000..9402c8cb2 --- /dev/null +++ b/sc/qa/extras/sccellcursorobj.cxx @@ -0,0 +1,226 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/sheetcellrange.hxx> +#include <test/sheet/xarrayformularange.hxx> +#include <test/sheet/xcellformatrangessupplier.hxx> +#include <test/sheet/xcellrangeaddressable.hxx> +#include <test/sheet/xcellrangedata.hxx> +#include <test/sheet/xcellrangeformula.hxx> +#include <test/sheet/xcellseries.hxx> +#include <test/sheet/xformulaquery.hxx> +#include <test/sheet/xmultipleoperation.hxx> +#include <test/sheet/xsheetcellcursor.hxx> +#include <test/sheet/xsheetcellrange.hxx> +#include <test/sheet/xsheetfilterable.hxx> +#include <test/sheet/xsheetfilterableex.hxx> +#include <test/sheet/xsheetoperation.hxx> +#include <test/sheet/xsubtotalcalculatable.hxx> +#include <test/sheet/xuniquecellformatrangessupplier.hxx> +#include <test/sheet/xusedareacursor.hxx> +#include <test/table/xcellcursor.hxx> +#include <test/table/xcolumnrowrange.hxx> +#include <test/util/xindent.hxx> +#include <test/util/xmergeable.hxx> + +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/XCellCursor.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScCellCursorObj : public CalcUnoApiTest, public apitest::SheetCellRange, + public apitest::XArrayFormulaRange, + public apitest::XCellCursor, + public apitest::XCellFormatRangesSupplier, + public apitest::XCellRangeAddressable, + public apitest::XCellRangeData, + public apitest::XCellRangeFormula, + public apitest::XCellSeries, + public apitest::XColumnRowRange, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XMergeable, + public apitest::XMultipleOperation, + public apitest::XSheetCellCursor, + public apitest::XSheetCellRange, + public apitest::XSheetFilterable, + public apitest::XSheetFilterableEx, + public apitest::XSheetOperation, + public apitest::XSubTotalCalculatable, + public apitest::XUniqueCellFormatRangesSupplier, + public apitest::XUsedAreaCursor +{ +public: + ScCellCursorObj(); + + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< uno::XInterface > getXCellRangeData() override; + virtual uno::Reference< uno::XInterface > getXSpreadsheet() override; + + CPPUNIT_TEST_SUITE(ScCellCursorObj); + + // SheetCellRange + CPPUNIT_TEST(testSheetCellRangeProperties); + + // XArrayFormulaRange + CPPUNIT_TEST(testGetSetArrayFormula); + + // XCellCursor + CPPUNIT_TEST(testGoToNext); + CPPUNIT_TEST(testGoToOffset); + CPPUNIT_TEST(testGoToPrevious); + CPPUNIT_TEST(testGoToStart); + CPPUNIT_TEST(testGoToEnd); + + // XCellFormatRangesSupplier + CPPUNIT_TEST(testGetCellFormatRanges); + + // XCellRangeAddressable + CPPUNIT_TEST(testGetRangeAddress); + + // XCellRangeData + CPPUNIT_TEST(testGetDataArray); + CPPUNIT_TEST(testSetDataArray); + + // XCellRangeFormula + CPPUNIT_TEST(testGetSetFormulaArray); + + // XCellSeries + CPPUNIT_TEST(testFillAuto); + CPPUNIT_TEST(testFillSeries); + + // XColumnRowRange + CPPUNIT_TEST(testGetColumns); + CPPUNIT_TEST(testGetRows); + + // XFormulaQuery + CPPUNIT_TEST(testQueryDependents); + CPPUNIT_TEST(testQueryPrecedents); + + // XIndent + CPPUNIT_TEST(testIncrementIndent); + CPPUNIT_TEST(testDecrementIndent); + + // XMergeable + CPPUNIT_TEST(testGetIsMergedMerge); + + // XMultipleOperation + CPPUNIT_TEST(testSetTableOperation); + + // XSheetCellCursor + CPPUNIT_TEST(testCollapseToCurrentArray); + CPPUNIT_TEST(testCollapseToCurrentRegion); + CPPUNIT_TEST(testCollapseToMergedArea); + CPPUNIT_TEST(testCollapseToSize); + CPPUNIT_TEST(testExpandToEntireColumns); + CPPUNIT_TEST(testExpandToEntireRows); + + // XSheetCellRange + CPPUNIT_TEST(testGetSpreadsheet); + + // XSheetFilterable + CPPUNIT_TEST(testCreateFilterDescriptor); + CPPUNIT_TEST(testFilter); + + // XSheetFilterableEx + CPPUNIT_TEST(testCreateFilterDescriptorByObject); + + // XSheetOperation + CPPUNIT_TEST(testComputeFunction); + CPPUNIT_TEST(testClearContents); + + // XSubTotalCalculatable + CPPUNIT_TEST(testCreateSubTotalDescriptor); + CPPUNIT_TEST(testApplyRemoveSubTotals); + + // XUsedAreaCursor + CPPUNIT_TEST(testGotoStartOfUsedArea); + CPPUNIT_TEST(testGotoEndOfUsedArea); + + // XUniqueCellFormatRangesSupplier + CPPUNIT_TEST(testGetUniqueCellFormatRanges); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference< lang::XComponent > mxComponent; +}; + +ScCellCursorObj::ScCellCursorObj(): + CalcUnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XCellSeries(0, 0), + apitest::XFormulaQuery(table::CellRangeAddress(0, 15, 15, 15, 15), table::CellRangeAddress(0, 0, 15, 0, 15)) +{ +} + +uno::Reference< uno::XInterface > ScCellCursorObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xCellRange = xSheet->getCellRangeByName("$A$1:$D$4"); + uno::Reference<sheet::XSheetCellRange> xSheetCellRange(xCellRange, UNO_QUERY_THROW); + uno::Reference<table::XCellCursor> xCellCursor(xSheet->createCursorByRange(xSheetCellRange), UNO_QUERY_THROW); + + xSheet->getCellByPosition(1, 1)->setValue(1); + xSheet->getCellByPosition(4, 5)->setValue(1); + xSheet->getCellByPosition(3, 2)->setFormula("xTextDoc"); + xSheet->getCellByPosition(3, 3)->setFormula("xTextDoc"); + + return xCellCursor; +} + +uno::Reference< uno::XInterface > ScCellCursorObj::getXCellRangeData() +{ + return init(); +} + +uno::Reference< uno::XInterface > ScCellCursorObj::getXSpreadsheet() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(15, 15)); + + return xSheet; +} + +void ScCellCursorObj::setUp() +{ + CalcUnoApiTest::setUp(); + + OUString aFileURL; + createFileURL("ScCellCursorObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScCellCursorObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellCursorObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sccellfieldsobj.cxx b/sc/qa/extras/sccellfieldsobj.cxx new file mode 100644 index 000000000..98f0db3e2 --- /dev/null +++ b/sc/qa/extras/sccellfieldsobj.cxx @@ -0,0 +1,112 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/util/xrefreshable.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellFieldsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XRefreshable +{ +public: + ScCellFieldsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellFieldsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScCellFieldsObj::ScCellFieldsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<text::XTextField>::get()) +{ +} + +uno::Reference<uno::XInterface> ScCellFieldsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xTC(xMSF->createInstance("com.sun.star.text.TextField.URL"), + uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCell> xCell(xSheet0->getCellByPosition(2, 3), uno::UNO_SET_THROW); + uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW); + xText->insertTextContent(xText->createTextCursor(), xTC, true); + + uno::Reference<text::XTextFieldsSupplier> xTFS(xCell, uno::UNO_QUERY_THROW); + return xTFS->getTextFields(); +} + +void ScCellFieldsObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScCellFieldsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellFieldsObj); +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellformatsenumeration.cxx b/sc/qa/extras/sccellformatsenumeration.cxx new file mode 100644 index 000000000..93e07be16 --- /dev/null +++ b/sc/qa/extras/sccellformatsenumeration.cxx @@ -0,0 +1,91 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellFormatRangesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellFormatsEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScCellFormatsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellFormatsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScCellFormatsEnumeration::ScCellFormatsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScCellFormatsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XCellFormatRangesSupplier> xCFRS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_CFR(xCFRS->getCellFormatRanges(), + uno::UNO_SET_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xIA_CFR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScCellFormatsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScCellFormatsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellFormatsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellformatsobj.cxx b/sc/qa/extras/sccellformatsobj.cxx new file mode 100644 index 000000000..c2d7e91d1 --- /dev/null +++ b/sc/qa/extras/sccellformatsobj.cxx @@ -0,0 +1,104 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellFormatRangesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellFormatsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess +{ +public: + ScCellFormatsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellFormatsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScCellFormatsObj::ScCellFormatsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<table::XCellRange>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference<uno::XInterface> ScCellFormatsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XCellFormatRangesSupplier> xCFRS(xSheet0, uno::UNO_QUERY_THROW); + + return xCFRS->getCellFormatRanges(); +} + +void ScCellFormatsObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScCellFormatsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellFormatsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellobj.cxx b/sc/qa/extras/sccellobj.cxx new file mode 100644 index 000000000..590dad2eb --- /dev/null +++ b/sc/qa/extras/sccellobj.cxx @@ -0,0 +1,152 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/sheet/sheetcell.hxx> +#include <test/sheet/xcelladdressable.hxx> +#include <test/sheet/xformulaquery.hxx> +#include <test/sheet/xsheetannotationanchor.hxx> +#include <test/table/xcell.hxx> +#include <test/table/xcolumnrowrange.hxx> +#include <test/text/xsimpletext.hxx> +#include <test/util/xindent.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/sheet/XSheetAnnotations.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellObj : public CalcUnoApiTest, + public apitest::SheetCell, + public apitest::XCell, + public apitest::XCellAddressable, + public apitest::XColumnRowRange, + public apitest::XEnumerationAccess, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XSheetAnnotationAnchor, + public apitest::XSimpleText +{ +public: + ScCellObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXSpreadsheet() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellObj); + + // SheetCell + CPPUNIT_TEST(testSheetCellProperties); + + // XCell + CPPUNIT_TEST(testGetError); + CPPUNIT_TEST(testGetType); + CPPUNIT_TEST(testSetGetFormula); + CPPUNIT_TEST(testSetGetValue); + + // XCellAddressable + CPPUNIT_TEST(testGetCellAddress); + + // XColumnRowRange + CPPUNIT_TEST(testGetColumns); + CPPUNIT_TEST(testGetRows); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XFormulaQuery + CPPUNIT_TEST(testQueryDependents); + CPPUNIT_TEST(testQueryPrecedents); + + // XIndent + CPPUNIT_TEST(testIncrementIndent); + CPPUNIT_TEST(testDecrementIndent); + + // XSheetAnnotationAnchor + CPPUNIT_TEST(testGetAnnotation); + + // XSimpleText + CPPUNIT_TEST(testCreateTextCursor); + CPPUNIT_TEST(testCreateTextCursorByRange); + CPPUNIT_TEST(testInsertString); + CPPUNIT_TEST(testInsertControlCharacter); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScCellObj::ScCellObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , apitest::XFormulaQuery(table::CellRangeAddress(0, 2, 3, 2, 3), + table::CellRangeAddress(0, 0, 0, 3, 0), 0, 0) +{ +} + +uno::Reference<uno::XInterface> ScCellObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xSheetDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetAnnotationsSupplier> xSheetAnnosSupplier(xSheet, UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotations> xSheetAnnos(xSheetAnnosSupplier->getAnnotations(), + UNO_SET_THROW); + xSheetAnnos->insertNew(table::CellAddress(0, 2, 3), "xSheetAnnotation"); + + return xSheet->getCellByPosition(2, 3); +} + +uno::Reference<uno::XInterface> ScCellObj::getXSpreadsheet() +{ + uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xSheetDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(2, 3)); + + return xSheet; +} + +void ScCellObj::setUp() +{ + CalcUnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sccellrangeobj.cxx b/sc/qa/extras/sccellrangeobj.cxx new file mode 100644 index 000000000..1c0513a9a --- /dev/null +++ b/sc/qa/extras/sccellrangeobj.cxx @@ -0,0 +1,269 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/chart/xchartdata.hxx> +#include <test/sheet/cellproperties.hxx> +#include <test/sheet/sheetcellrange.hxx> +#include <test/sheet/xarrayformularange.hxx> +#include <test/sheet/xcellformatrangessupplier.hxx> +#include <test/sheet/xcellrangeaddressable.hxx> +#include <test/sheet/xcellrangedata.hxx> +#include <test/sheet/xcellrangeformula.hxx> +#include <test/sheet/xcellrangesquery.hxx> +#include <test/sheet/xcellseries.hxx> +#include <test/sheet/xformulaquery.hxx> +#include <test/sheet/xmultipleoperation.hxx> +#include <test/sheet/xsheetcellrange.hxx> +#include <test/sheet/xsheetfilterable.hxx> +#include <test/sheet/xsheetfilterableex.hxx> +#include <test/sheet/xsheetoperation.hxx> +#include <test/sheet/xsubtotalcalculatable.hxx> +#include <test/sheet/xuniquecellformatrangessupplier.hxx> +#include <test/table/xcolumnrowrange.hxx> +#include <test/util/xindent.hxx> +#include <test/util/xmergeable.hxx> +#include <test/util/xreplaceable.hxx> +#include <test/util/xsearchable.hxx> +#include <comphelper/propertysequence.hxx> + +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/util/SortField.hpp> +#include <com/sun/star/util/XSortable.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScCellRangeObj : public CalcUnoApiTest, + public apitest::CellProperties, + public apitest::SheetCellRange, + public apitest::XArrayFormulaRange, + public apitest::XCellFormatRangesSupplier, + public apitest::XCellRangeAddressable, + public apitest::XCellRangeData, + public apitest::XCellRangeFormula, + public apitest::XCellRangesQuery, + public apitest::XCellSeries, + public apitest::XChartData, + public apitest::XColumnRowRange, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XMergeable, + public apitest::XMultipleOperation, + public apitest::XReplaceable, + public apitest::XSearchable, + public apitest::XSheetCellRange, + public apitest::XSheetFilterable, + public apitest::XSheetFilterableEx, + public apitest::XSheetOperation, + public apitest::XSubTotalCalculatable, + public apitest::XUniqueCellFormatRangesSupplier +{ +public: + ScCellRangeObj(); + + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXCellRangeData() override; + virtual uno::Reference<uno::XInterface> getXSpreadsheet() override; + void testSortOOB(); + + CPPUNIT_TEST_SUITE(ScCellRangeObj); + + // CellProperties + CPPUNIT_TEST(testVertJustify); + CPPUNIT_TEST(testRotateReference); + + // SheetCellRange + CPPUNIT_TEST(testSheetCellRangeProperties); + + // XArrayFormulaRange + CPPUNIT_TEST(testGetSetArrayFormula); + + // XCellFormatRangesSupplier + CPPUNIT_TEST(testGetCellFormatRanges); + + // XCellRangeAddressable + CPPUNIT_TEST(testGetRangeAddress); + + // XCellRangeData + CPPUNIT_TEST(testGetDataArray); + CPPUNIT_TEST(testSetDataArray); + + // XCellRangeFormula + CPPUNIT_TEST(testGetSetFormulaArray); + + // XCellRangesQuery + CPPUNIT_TEST(testQueryColumnDifference); + CPPUNIT_TEST(testQueryContentDifference); + CPPUNIT_TEST(testQueryEmptyCells); + //CPPUNIT_TEST(testQueryFormulaCells); + CPPUNIT_TEST(testQueryIntersection); + CPPUNIT_TEST(testQueryRowDifference); + CPPUNIT_TEST(testQueryVisibleCells); + + // XCellSeries + CPPUNIT_TEST(testFillAuto); + CPPUNIT_TEST(testFillSeries); + + // XChartData + CPPUNIT_TEST(testGetNotANumber); + CPPUNIT_TEST(testIsNotANumber); + CPPUNIT_TEST(testChartDataChangeEventListener); + + // XColumnRowRange + CPPUNIT_TEST(testGetColumns); + CPPUNIT_TEST(testGetRows); + + // XFormulaQuery + CPPUNIT_TEST(testQueryDependents); + CPPUNIT_TEST(testQueryPrecedents); + + // XIndent + CPPUNIT_TEST(testIncrementIndent); + CPPUNIT_TEST(testDecrementIndent); + + // XMergeable + CPPUNIT_TEST(testGetIsMergedMerge); + + // XMultipleOperation + CPPUNIT_TEST(testSetTableOperation); + + // XReplaceable + CPPUNIT_TEST(testReplaceAll); + CPPUNIT_TEST(testCreateReplaceDescriptor); + + // XSearchable + CPPUNIT_TEST(testFindAll); + CPPUNIT_TEST(testFindFirst); + + // XSheetCellRange + CPPUNIT_TEST(testGetSpreadsheet); + + // XSheetFilterable + CPPUNIT_TEST(testCreateFilterDescriptor); + CPPUNIT_TEST(testFilter); + + // XSheetFilterableEx + CPPUNIT_TEST(testCreateFilterDescriptorByObject); + + // XSheetOperation + CPPUNIT_TEST(testComputeFunction); + CPPUNIT_TEST(testClearContents); + + // XSubTotalCalculatable + CPPUNIT_TEST(testCreateSubTotalDescriptor); + CPPUNIT_TEST(testApplyRemoveSubTotals); + + // XUniqueCellFormatRangesSupplier + CPPUNIT_TEST(testGetUniqueCellFormatRanges); + + CPPUNIT_TEST(testSortOOB); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScCellRangeObj::ScCellRangeObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XCellSeries(2, 1) + , XFormulaQuery(table::CellRangeAddress(0, 15, 15, 15, 15), + table::CellRangeAddress(0, 0, 15, 0, 15)) + , XReplaceable("15", "35") + , XSearchable("15", 1) +{ +} + +uno::Reference<uno::XInterface> ScCellRangeObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xReturn(xSheet->getCellRangeByPosition(0, 0, 4, 4), + uno::UNO_SET_THROW); + + return xReturn; +} + +uno::Reference<uno::XInterface> ScCellRangeObj::getXSpreadsheet() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(15, 15)); + + return xSheet; +} + +uno::Reference<uno::XInterface> ScCellRangeObj::getXCellRangeData() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(1), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xReturn(xSheet->getCellRangeByPosition(0, 0, 3, 3), + uno::UNO_SET_THROW); + + return xReturn; +} + +void ScCellRangeObj::testSortOOB() +{ + uno::Reference<util::XSortable> xSortable(init(), uno::UNO_QUERY_THROW); + uno::Sequence<beans::PropertyValue> aEmptyDescriptor; + xSortable->sort(aEmptyDescriptor); + + uno::Sequence<util::SortField> aSort(1); + aSort[0].Field = 0xffffff; + aSort[0].SortAscending = true; + + uno::Sequence<beans::PropertyValue> aProps( + comphelper::InitPropertySequence({ { "SortFields", uno::Any(aSort) } })); + + xSortable->sort(aProps); +} + +void ScCellRangeObj::setUp() +{ + CalcUnoApiTest::setUp(); + + OUString aFileURL; + const OUString aFileBase("xcellrangesquery.ods"); + createFileURL(aFileBase, aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScCellRangeObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellRangeObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sccellrangesobj.cxx b/sc/qa/extras/sccellrangesobj.cxx new file mode 100644 index 000000000..174552d9c --- /dev/null +++ b/sc/qa/extras/sccellrangesobj.cxx @@ -0,0 +1,154 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/sheet/sheetcellranges.hxx> +#include <test/sheet/xformulaquery.hxx> +#include <test/sheet/xsheetcellrangecontainer.hxx> +#include <test/sheet/xsheetcellranges.hxx> +#include <test/sheet/xsheetoperation.hxx> +#include <test/util/xindent.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScCellRangesObj : public CalcUnoApiTest, + public apitest::SheetCellRanges, + public apitest::XEnumerationAccess, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XSheetCellRangeContainer, + public apitest::XSheetCellRanges, + public apitest::XSheetOperation +{ +public: + ScCellRangesObj(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference< uno::XInterface > getXSpreadsheet() override; + virtual uno::Reference< uno::XInterface > init() override; + + CPPUNIT_TEST_SUITE(ScCellRangesObj); + + // SheetCellRanges + CPPUNIT_TEST(testSheetCellRangesProperties); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XFormulaQuery + CPPUNIT_TEST(testQueryDependents); + CPPUNIT_TEST(testQueryPrecedents); + + // XIndent + CPPUNIT_TEST(testIncrementIndent); + CPPUNIT_TEST(testDecrementIndent); + + // XSheetCellRangeContainer + CPPUNIT_TEST(testAddRemoveRangeAddress); + CPPUNIT_TEST(testAddRemoveRangeAddresses); + + // XSheetCellRanges + CPPUNIT_TEST(testGetCells); + CPPUNIT_TEST(testGetRangeAddresses); + CPPUNIT_TEST(testGetRangeAddressesAsString); + + // XSheetOperation + CPPUNIT_TEST(testComputeFunction); + CPPUNIT_TEST(testClearContents); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference< lang::XComponent > mxComponent; +}; + +ScCellRangesObj::ScCellRangesObj(): + CalcUnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XFormulaQuery(table::CellRangeAddress(0, 4, 1, 5, 4), table::CellRangeAddress(0, 4, 1, 5, 4)) +{ +} + +uno::Reference< uno::XInterface > ScCellRangesObj::init() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIndexAccess(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference< lang::XMultiServiceFactory > xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference< container::XNameContainer > xRanges(xMSF->createInstance("com.sun.star.sheet.SheetCellRanges"), uno::UNO_QUERY_THROW); + + uno::Any xCellRange; + xCellRange <<= xSheet->getCellRangeByName("C1:D4"); + xRanges->insertByName("Range1", xCellRange); + xCellRange <<= xSheet->getCellRangeByName("E2:F5"); + xRanges->insertByName("Range2", xCellRange); + xCellRange <<= xSheet->getCellRangeByName("G2:H3"); + xRanges->insertByName("Range3", xCellRange); + xCellRange <<= xSheet->getCellRangeByName("I7:J8"); + xRanges->insertByName("Range4", xCellRange); + + for ( int i = 0; i < 10; i++ ) + { + for ( int j = 5; j < 10; j++ ) + { + xSheet->getCellByPosition(i, j)->setValue(i + j); + } + } + + return xRanges; +} + +uno::Reference<uno::XInterface> ScCellRangesObj::getXSpreadsheet() +{ + uno::Reference< sheet::XSpreadsheetDocument > xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets (xSheetDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + setXCell(xSheet->getCellByPosition(15, 15)); + + return xSheet; +} + +void ScCellRangesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellRangesObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellRangesObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sccellsearchobj.cxx b/sc/qa/extras/sccellsearchobj.cxx new file mode 100644 index 000000000..e0ee5c3bb --- /dev/null +++ b/sc/qa/extras/sccellsearchobj.cxx @@ -0,0 +1,111 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/util/searchdescriptor.hxx> +#include <test/util/xreplacedescriptor.hxx> +#include <test/util/xsearchdescriptor.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/util/XSearchable.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScCellSearchObj : public CalcUnoApiTest, + public apitest::SearchDescriptor, + public apitest::XPropertySet, + public apitest::XReplaceDescriptor, + public apitest::XSearchDescriptor, + public apitest::XServiceInfo +{ +public: + ScCellSearchObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellSearchObj); + + // SearchDescriptor + CPPUNIT_TEST(testSearchDescriptorProperties); + + // XPropertSet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XReplaceDescriptor + CPPUNIT_TEST(testGetSetReplaceString); + + // XSearchDescriptor + CPPUNIT_TEST(testGetSetSearchString); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScCellSearchObj::ScCellSearchObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XServiceInfo("ScCellSearchObj", + { "com.sun.star.util.ReplaceDescriptor", "com.sun.star.util.SearchDescriptor" }) +{ +} + +uno::Reference<uno::XInterface> ScCellSearchObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<util::XSearchable> xSearchable(xSheet0, uno::UNO_QUERY_THROW); + return xSearchable->createSearchDescriptor(); +} + +void ScCellSearchObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScCellSearchObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellSearchObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellsenumeration.cxx b/sc/qa/extras/sccellsenumeration.cxx new file mode 100644 index 000000000..1ea47e6f2 --- /dev/null +++ b/sc/qa/extras/sccellsenumeration.cxx @@ -0,0 +1,104 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangesQuery.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellsEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScCellsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScCellsEnumeration::ScCellsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScCellsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xCellRange(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell0(xCellRange->getCellByPosition(0, 0), uno::UNO_SET_THROW); + uno::Reference<text::XTextRange> xTextRange0(xCell0, uno::UNO_QUERY_THROW); + xTextRange0->setString("Test string 1"); + + uno::Reference<table::XCell> xCell1(xCellRange->getCellByPosition(5, 1), uno::UNO_SET_THROW); + xCell1->setValue(15); + + uno::Reference<table::XCell> xCell2(xCellRange->getCellByPosition(3, 9), uno::UNO_SET_THROW); + uno::Reference<text::XTextRange> xTextRange1(xCell2, uno::UNO_QUERY_THROW); + xTextRange1->setString("Test string 2"); + + uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(xCellRange, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xSCR(xCellRangesQuery->queryVisibleCells(), + uno::UNO_SET_THROW); + + return xSCR->getCells()->createEnumeration(); +} + +void ScCellsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScCellsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sccellsobj.cxx b/sc/qa/extras/sccellsobj.cxx new file mode 100644 index 000000000..3fbcd6169 --- /dev/null +++ b/sc/qa/extras/sccellsobj.cxx @@ -0,0 +1,111 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangesQuery.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScCellsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess +{ +public: + ScCellsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScCellsObj); + + // XElementAccess + CPPUNIT_TEST(testHasElements); + CPPUNIT_TEST(testGetElementType); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScCellsObj::ScCellsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<table::XCell>::get()) +{ +} + +uno::Reference<uno::XInterface> ScCellsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCell> xCell0(xCellRange->getCellByPosition(0, 0), uno::UNO_SET_THROW); + uno::Reference<text::XTextRange> xTextRange0(xCell0, uno::UNO_QUERY_THROW); + xTextRange0->setString("ScCellsObj test 1"); + + uno::Reference<table::XCell> xCell1(xCellRange->getCellByPosition(5, 1), uno::UNO_SET_THROW); + xCell1->setValue(15); + + uno::Reference<table::XCell> xCell2(xCellRange->getCellByPosition(3, 9), uno::UNO_SET_THROW); + uno::Reference<text::XTextRange> xTextRange2(xCell2, uno::UNO_QUERY_THROW); + xTextRange2->setString("ScCellsObj test 2"); + + uno::Reference<sheet::XCellRangesQuery> xCRQ(xCellRange, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xSCR(xCRQ->queryVisibleCells(), uno::UNO_SET_THROW); + + return xSCR->getCells(); +} + +void ScCellsObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScCellsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScCellsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scchartobj.cxx b/sc/qa/extras/scchartobj.cxx new file mode 100644 index 000000000..d5cd726f9 --- /dev/null +++ b/sc/qa/extras/scchartobj.cxx @@ -0,0 +1,191 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xnamed.hxx> +#include <test/document/xembeddedobjectsupplier.hxx> +#include <test/table/xtablechart.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XTableChart.hpp> +#include <com/sun/star/table/XTableCharts.hpp> +#include <com/sun/star/table/XTableChartsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScChartObj : public CalcUnoApiTest, + public apitest::XEmbeddedObjectSupplier, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo, + public apitest::XTableChart +{ +public: + ScChartObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScChartObj); + + // XEmbeddedObjectSupplier + CPPUNIT_TEST(testGetEmbeddedObject); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetNameThrowsException); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XTableChart + CPPUNIT_TEST(testGetSetHasColumnHeaders); + CPPUNIT_TEST(testGetSetHasRowHeaders); + CPPUNIT_TEST(testGetSetRanges); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScChartObj::ScChartObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("ScChartObj") + , XServiceInfo("ScChartObj", "com.sun.star.table.TableChart") +{ +} + +uno::Reference<uno::XInterface> ScChartObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(1, 0)->setFormula("JAN"); + xSheet0->getCellByPosition(2, 0)->setFormula("FEB"); + xSheet0->getCellByPosition(3, 0)->setFormula("MAR"); + xSheet0->getCellByPosition(4, 0)->setFormula("APR"); + xSheet0->getCellByPosition(5, 0)->setFormula("MAY"); + xSheet0->getCellByPosition(6, 0)->setFormula("JUN"); + xSheet0->getCellByPosition(7, 0)->setFormula("JUL"); + xSheet0->getCellByPosition(8, 0)->setFormula("AUG"); + xSheet0->getCellByPosition(9, 0)->setFormula("SEP"); + xSheet0->getCellByPosition(10, 0)->setFormula("OCT"); + xSheet0->getCellByPosition(11, 0)->setFormula("NOV"); + xSheet0->getCellByPosition(12, 0)->setFormula("DEC"); + xSheet0->getCellByPosition(13, 0)->setFormula("SUM"); + + xSheet0->getCellByPosition(0, 1)->setFormula("Smith"); + xSheet0->getCellByPosition(1, 1)->setValue(42); + xSheet0->getCellByPosition(2, 1)->setValue(58.9); + xSheet0->getCellByPosition(3, 1)->setValue(-66.5); + xSheet0->getCellByPosition(4, 1)->setValue(43.4); + xSheet0->getCellByPosition(5, 1)->setValue(44.5); + xSheet0->getCellByPosition(6, 1)->setValue(45.3); + xSheet0->getCellByPosition(7, 1)->setValue(-67.3); + xSheet0->getCellByPosition(8, 1)->setValue(30.5); + xSheet0->getCellByPosition(9, 1)->setValue(23.2); + xSheet0->getCellByPosition(10, 1)->setValue(-97.3); + xSheet0->getCellByPosition(11, 1)->setValue(22.4); + xSheet0->getCellByPosition(11, 1)->setValue(23.5); + xSheet0->getCellByPosition(13, 1)->setFormula("SUM(B2:M2"); + + xSheet0->getCellByPosition(0, 2)->setFormula("Jones"); + xSheet0->getCellByPosition(1, 2)->setValue(21); + xSheet0->getCellByPosition(2, 2)->setValue(40.9); + xSheet0->getCellByPosition(3, 2)->setValue(-57.5); + xSheet0->getCellByPosition(4, 2)->setValue(-23.4); + xSheet0->getCellByPosition(5, 2)->setValue(34.5); + xSheet0->getCellByPosition(6, 2)->setValue(59.3); + xSheet0->getCellByPosition(7, 2)->setValue(27.3); + xSheet0->getCellByPosition(8, 2)->setValue(-38.5); + xSheet0->getCellByPosition(9, 2)->setValue(43.2); + xSheet0->getCellByPosition(10, 2)->setValue(57.3); + xSheet0->getCellByPosition(11, 2)->setValue(25.4); + xSheet0->getCellByPosition(11, 2)->setValue(28.5); + xSheet0->getCellByPosition(13, 2)->setFormula("SUM(B3:M3"); + + xSheet0->getCellByPosition(0, 3)->setFormula("Brown"); + xSheet0->getCellByPosition(1, 3)->setValue(31.45); + xSheet0->getCellByPosition(2, 3)->setValue(-20.9); + xSheet0->getCellByPosition(3, 3)->setValue(-117.5); + xSheet0->getCellByPosition(4, 3)->setValue(23.4); + xSheet0->getCellByPosition(5, 3)->setValue(-114.5); + xSheet0->getCellByPosition(6, 3)->setValue(115.3); + xSheet0->getCellByPosition(7, 3)->setValue(-171.3); + xSheet0->getCellByPosition(8, 3)->setValue(89.5); + xSheet0->getCellByPosition(9, 3)->setValue(41.2); + xSheet0->getCellByPosition(10, 3)->setValue(71.3); + xSheet0->getCellByPosition(11, 3)->setValue(25.4); + xSheet0->getCellByPosition(11, 3)->setValue(38.5); + xSheet0->getCellByPosition(13, 3)->setFormula("SUM(A4:L4"); + + uno::Reference<table::XCellRange> xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aCRA(1); + aCRA[0] = xCRA->getRangeAddress(); + + uno::Reference<table::XTableChartsSupplier> xTCS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableCharts> xTC = xTCS->getCharts(); + xTC->addNewByName("ScChartObj", awt::Rectangle(500, 3000, 25000, 11000), aCRA, true, true); + + uno::Reference<container::XNameAccess> xNA(xTC, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableChart> xChart(xNA->getByName("ScChartObj"), uno::UNO_QUERY_THROW); + return xChart; +} + +void ScChartObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScChartObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScChartObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scchartsobj.cxx b/sc/qa/extras/scchartsobj.cxx new file mode 100644 index 000000000..7424e1d68 --- /dev/null +++ b/sc/qa/extras/scchartsobj.cxx @@ -0,0 +1,197 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/table/xtablecharts.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XTableChart.hpp> +#include <com/sun/star/table/XTableCharts.hpp> +#include <com/sun/star/table/XTableChartsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScChartsObj : public CalcUnoApiTest, + public apitest::XEnumerationAccess, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XTableCharts +{ +public: + ScChartsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScChartsObj); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XTableCharts + CPPUNIT_TEST(testAddNewRemoveByName); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScChartsObj::ScChartsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<table::XTableChart>::get()) + , XIndexAccess(1) + , XNameAccess("ScChartsObj") + , XServiceInfo("ScChartsObj", "com.sun.star.table.TableCharts") +{ +} + +uno::Reference<uno::XInterface> ScChartsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(1, 0)->setFormula("JAN"); + xSheet0->getCellByPosition(2, 0)->setFormula("FEB"); + xSheet0->getCellByPosition(3, 0)->setFormula("MAR"); + xSheet0->getCellByPosition(4, 0)->setFormula("APR"); + xSheet0->getCellByPosition(5, 0)->setFormula("MAY"); + xSheet0->getCellByPosition(6, 0)->setFormula("JUN"); + xSheet0->getCellByPosition(7, 0)->setFormula("JUL"); + xSheet0->getCellByPosition(8, 0)->setFormula("AUG"); + xSheet0->getCellByPosition(9, 0)->setFormula("SEP"); + xSheet0->getCellByPosition(10, 0)->setFormula("OCT"); + xSheet0->getCellByPosition(11, 0)->setFormula("NOV"); + xSheet0->getCellByPosition(12, 0)->setFormula("DEC"); + xSheet0->getCellByPosition(13, 0)->setFormula("SUM"); + + xSheet0->getCellByPosition(0, 1)->setFormula("Smith"); + xSheet0->getCellByPosition(1, 1)->setValue(42); + xSheet0->getCellByPosition(2, 1)->setValue(58.9); + xSheet0->getCellByPosition(3, 1)->setValue(-66.5); + xSheet0->getCellByPosition(4, 1)->setValue(43.4); + xSheet0->getCellByPosition(5, 1)->setValue(44.5); + xSheet0->getCellByPosition(6, 1)->setValue(45.3); + xSheet0->getCellByPosition(7, 1)->setValue(-67.3); + xSheet0->getCellByPosition(8, 1)->setValue(30.5); + xSheet0->getCellByPosition(9, 1)->setValue(23.2); + xSheet0->getCellByPosition(10, 1)->setValue(-97.3); + xSheet0->getCellByPosition(11, 1)->setValue(22.4); + xSheet0->getCellByPosition(11, 1)->setValue(23.5); + xSheet0->getCellByPosition(13, 1)->setFormula("SUM(B2:M2"); + + xSheet0->getCellByPosition(0, 2)->setFormula("Jones"); + xSheet0->getCellByPosition(1, 2)->setValue(21); + xSheet0->getCellByPosition(2, 2)->setValue(40.9); + xSheet0->getCellByPosition(3, 2)->setValue(-57.5); + xSheet0->getCellByPosition(4, 2)->setValue(-23.4); + xSheet0->getCellByPosition(5, 2)->setValue(34.5); + xSheet0->getCellByPosition(6, 2)->setValue(59.3); + xSheet0->getCellByPosition(7, 2)->setValue(27.3); + xSheet0->getCellByPosition(8, 2)->setValue(-38.5); + xSheet0->getCellByPosition(9, 2)->setValue(43.2); + xSheet0->getCellByPosition(10, 2)->setValue(57.3); + xSheet0->getCellByPosition(11, 2)->setValue(25.4); + xSheet0->getCellByPosition(11, 2)->setValue(28.5); + xSheet0->getCellByPosition(13, 2)->setFormula("SUM(B3:M3"); + + xSheet0->getCellByPosition(0, 3)->setFormula("Brown"); + xSheet0->getCellByPosition(1, 3)->setValue(31.45); + xSheet0->getCellByPosition(2, 3)->setValue(-20.9); + xSheet0->getCellByPosition(3, 3)->setValue(-117.5); + xSheet0->getCellByPosition(4, 3)->setValue(23.4); + xSheet0->getCellByPosition(5, 3)->setValue(-114.5); + xSheet0->getCellByPosition(6, 3)->setValue(115.3); + xSheet0->getCellByPosition(7, 3)->setValue(-171.3); + xSheet0->getCellByPosition(8, 3)->setValue(89.5); + xSheet0->getCellByPosition(9, 3)->setValue(41.2); + xSheet0->getCellByPosition(10, 3)->setValue(71.3); + xSheet0->getCellByPosition(11, 3)->setValue(25.4); + xSheet0->getCellByPosition(11, 3)->setValue(38.5); + xSheet0->getCellByPosition(13, 3)->setFormula("SUM(A4:L4"); + + uno::Reference<table::XCellRange> xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aCRA(1); + aCRA[0] = xCRA->getRangeAddress(); + + uno::Reference<table::XTableChartsSupplier> xTCS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableCharts> xTC = xTCS->getCharts(); + xTC->addNewByName("ScChartsObj", awt::Rectangle(500, 3000, 25000, 11000), aCRA, true, true); + + return xTC; +} + +void ScChartsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScChartsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScChartsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scconsolidationdescriptorobj.cxx b/sc/qa/extras/scconsolidationdescriptorobj.cxx new file mode 100644 index 000000000..e229ade7e --- /dev/null +++ b/sc/qa/extras/scconsolidationdescriptorobj.cxx @@ -0,0 +1,89 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/xconsolidationdescriptor.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XConsolidatable.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScConsolidationDescriptorObj : public CalcUnoApiTest, public apitest::XConsolidationDescriptor +{ +public: + ScConsolidationDescriptorObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScConsolidationDescriptorObj); + + // XConsolidationDescriptor + CPPUNIT_TEST(testGetFunction); + CPPUNIT_TEST(testSetFunction); + CPPUNIT_TEST(testGetSources); + CPPUNIT_TEST(testSetSources); + CPPUNIT_TEST(testGetStartOutputPosition); + CPPUNIT_TEST(testSetStartOutputPosition); + CPPUNIT_TEST(testGetUseColumnHeaders); + CPPUNIT_TEST(testSetUseColumnHeaders); + CPPUNIT_TEST(testGetUseRowHeaders); + CPPUNIT_TEST(testSetUseRowHeaders); + CPPUNIT_TEST(testGetInsertLinks); + CPPUNIT_TEST(testSetInsertLinks); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScConsolidationDescriptorObj::ScConsolidationDescriptorObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScConsolidationDescriptorObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XConsolidatable> xConsolidatable(xDoc, UNO_QUERY_THROW); + return xConsolidatable->createConsolidationDescriptor(true); +} + +void ScConsolidationDescriptorObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScConsolidationDescriptorObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScConsolidationDescriptorObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatabaserangeobj.cxx b/sc/qa/extras/scdatabaserangeobj.cxx new file mode 100644 index 000000000..d7ffdf80c --- /dev/null +++ b/sc/qa/extras/scdatabaserangeobj.cxx @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/databaserange.hxx> +#include <test/sheet/xcellrangereferrer.hxx> +#include <test/sheet/xdatabaserange.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XCellRangeReferrer.hpp> +#include <com/sun/star/sheet/XDatabaseRange.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScDatabaseRangeObj : public CalcUnoApiTest, + public apitest::DatabaseRange, + public apitest::XCellRangeReferrer, + public apitest::XDatabaseRange +{ +public: + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< uno::XInterface > init( const OUString& rDBName ) override; + + ScDatabaseRangeObj(); + + CPPUNIT_TEST_SUITE(ScDatabaseRangeObj); + + // DatabaseRange + CPPUNIT_TEST(testMoveCells); + CPPUNIT_TEST(testKeepFormats); + CPPUNIT_TEST(testStripData); + CPPUNIT_TEST(testAutoFilter); + CPPUNIT_TEST(testUseFilterCriteriaSource); + CPPUNIT_TEST(testFilterCriteriaSource); + CPPUNIT_TEST(testRefreshPeriod); + CPPUNIT_TEST(testFromSelection); + CPPUNIT_TEST(testTokenIndex); + CPPUNIT_TEST(testTotalsRow); + CPPUNIT_TEST(testContainsHeader); + + // XCellRangeReferrer + CPPUNIT_TEST(testGetReferredCells); + + // XDatabaseRange + CPPUNIT_TEST(testDataArea); + CPPUNIT_TEST(testGetSortDescriptor); + CPPUNIT_TEST(testGetSubtotalDescriptor); + CPPUNIT_TEST(testGetImportDescriptor); + CPPUNIT_TEST(testGetFilterDescriptor); + CPPUNIT_TEST(testRefresh); + + CPPUNIT_TEST_SUITE_END(); +private: + uno::Reference< lang::XComponent > mxComponent; +}; + +ScDatabaseRangeObj::ScDatabaseRangeObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScDatabaseRangeObj::init() +{ + return init("DataArea"); +} + +uno::Reference< uno::XInterface > ScDatabaseRangeObj::init( const OUString& rDBName ) +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference< beans::XPropertySet > xPropSet(xDoc, UNO_QUERY_THROW); + uno::Reference< container::XNameAccess > xNameAccess( xPropSet->getPropertyValue("DatabaseRanges"), UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeReferrer> xCRR(xNameAccess->getByName(rDBName), UNO_QUERY_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRR->getReferredCells(), UNO_QUERY_THROW); + setCellRange(xCRA->getRangeAddress()); + + uno::Reference< sheet::XDatabaseRange > xDBRange( xNameAccess->getByName(rDBName), UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDBRange.is()); + + return xDBRange; +} + +void ScDatabaseRangeObj::setUp() +{ + CalcUnoApiTest::setUp(); + + OUString aFileURL; + createFileURL("ScDatabaseRangeObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); + +} + +void ScDatabaseRangeObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDatabaseRangeObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scdatabaserangesobj.cxx b/sc/qa/extras/scdatabaserangesobj.cxx new file mode 100644 index 000000000..39c190f31 --- /dev/null +++ b/sc/qa/extras/scdatabaserangesobj.cxx @@ -0,0 +1,125 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xdatabaseranges.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDatabaseRange.hpp> +#include <com/sun/star/sheet/XDatabaseRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDatabaseRangesObj : public CalcUnoApiTest, + public apitest::XDatabaseRanges, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDatabaseRangesObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDatabaseRangesObj); + + // XDatabaseRanges + CPPUNIT_TEST(testAddRemoveDbRanges); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScDatabaseRangesObj::ScDatabaseRangesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XDatabaseRange>::get()) + , XIndexAccess(1) + , XNameAccess("DbRange") + , XServiceInfo("ScDatabaseRangesObj", "com.sun.star.sheet.DatabaseRanges") +{ +} + +uno::Reference<uno::XInterface> ScDatabaseRangesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, UNO_QUERY_THROW); + uno::Reference<sheet::XDatabaseRanges> xDbRanges(xPropSet->getPropertyValue("DatabaseRanges"), + UNO_QUERY_THROW); + + if (!xDbRanges->hasByName("DbRange")) + xDbRanges->addNewByName("DbRange", table::CellRangeAddress(0, 2, 4, 5, 6)); + + return xDbRanges; +} + +void ScDatabaseRangesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDatabaseRangesObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDatabaseRangesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotfieldgroupitemobj.cxx b/sc/qa/extras/scdatapilotfieldgroupitemobj.cxx new file mode 100644 index 000000000..e40170e51 --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldgroupitemobj.cxx @@ -0,0 +1,197 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/DataPilotFieldGroupInfo.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotFieldGrouping.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <comphelper/types.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldGroupItemObj : public CalcUnoApiTest, + public apitest::XNamed, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldGroupItemObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDataPilotFieldGroupItemObj); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScDataPilotFieldGroupItemObj::ScDataPilotFieldGroupItemObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("aName") + , XServiceInfo("ScDataPilotFieldGroupItemObj", "com.sun.star.sheet.DataPilotFieldGroupItem") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotFieldGroupItemObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + for (auto j = 1; j < m_nMaxFieldIndex; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + xSheet0->getCellByPosition(1, 1)->setFormula("aName"); + xSheet0->getCellByPosition(1, 2)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 3)->setFormula("una"); + xSheet0->getCellByPosition(1, 4)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 5)->setFormula("somethingelse"); + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference<beans::XPropertySet> xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + xPropertySet0->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_ROW)); + + uno::Reference<beans::XPropertySet> xPropertySet1(xDPD->getDataPilotFields()->getByIndex(1), + uno::UNO_QUERY_THROW); + xPropertySet1->setPropertyValue("Function", uno::makeAny(sheet::GeneralFunction_SUM)); + xPropertySet1->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_DATA)); + + uno::Reference<beans::XPropertySet> xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2), + uno::UNO_QUERY_THROW); + xPropertySet2->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_COLUMN)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference<container::XIndexAccess> xIA_DPT0(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD0(xIA_DPT0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW); + + uno::Reference<sheet::XDataPilotFieldGrouping> xDPFG(xIA_RF0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Sequence<OUString> aElements(2); + aElements[0] = "aName"; + aElements[1] = "otherName"; + xDPFG->createNameGroup(aElements); + + uno::Reference<container::XIndexAccess> xIA_DPT1(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD1(xIA_DPT1->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW); + + sheet::DataPilotFieldGroupInfo aDPFGI; + for (auto i = 0; i < xIA_RF1->getCount(); ++i) + { + uno::Reference<beans::XPropertySet> xPropertySet(xIA_RF1->getByIndex(i), + uno::UNO_QUERY_THROW); + if (::comphelper::getBOOL(xPropertySet->getPropertyValue("IsGroupField"))) + { + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("GroupInfo") >>= aDPFGI); + } + } + + uno::Reference<container::XIndexAccess> xIA_GI(aDPFGI.Groups, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA_GN(xIA_GI->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<uno::XInterface> xReturn(xNA_GN->getByName("aName"), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScDataPilotFieldGroupItemObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotFieldGroupItemObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupItemObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scdatapilotfieldgroupobj.cxx b/sc/qa/extras/scdatapilotfieldgroupobj.cxx new file mode 100644 index 000000000..8fc85a85f --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldgroupobj.cxx @@ -0,0 +1,222 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xnamed.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <comphelper/types.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/DataPilotFieldGroupInfo.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotFieldGrouping.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldGroupObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNamed, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldGroupObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDataPilotFieldGroupObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScDataPilotFieldGroupObj::ScDataPilotFieldGroupObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<container::XNamed>::get()) + , XIndexAccess(2) + , XNameAccess("aName") + , XNamed("Group1") + , XServiceInfo("ScDataPilotFieldGroupObj", "com.sun.star.sheet.DataPilotFieldGroup") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotFieldGroupObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + for (auto j = 1; j < m_nMaxFieldIndex; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + xSheet0->getCellByPosition(1, 1)->setFormula("aName"); + xSheet0->getCellByPosition(1, 2)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 3)->setFormula("una"); + xSheet0->getCellByPosition(1, 4)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 5)->setFormula("somethingelse"); + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference<beans::XPropertySet> xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + xPropertySet0->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_ROW)); + + uno::Reference<beans::XPropertySet> xPropertySet1(xDPD->getDataPilotFields()->getByIndex(1), + uno::UNO_QUERY_THROW); + xPropertySet1->setPropertyValue("Function", uno::makeAny(sheet::GeneralFunction_SUM)); + xPropertySet1->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_DATA)); + + uno::Reference<beans::XPropertySet> xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2), + uno::UNO_QUERY_THROW); + xPropertySet2->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_COLUMN)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference<container::XIndexAccess> xIA_DPT0(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD0(xIA_DPT0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW); + + uno::Reference<sheet::XDataPilotFieldGrouping> xDPFG(xIA_RF0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Sequence<OUString> aElements(2); + aElements[0] = "aName"; + aElements[1] = "otherName"; + xDPFG->createNameGroup(aElements); + + uno::Reference<container::XIndexAccess> xIA_DPT1(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD1(xIA_DPT1->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW); + + sheet::DataPilotFieldGroupInfo aDPFGI; + for (auto i = 0; i < xIA_RF1->getCount(); ++i) + { + uno::Reference<beans::XPropertySet> xPropertySet(xIA_RF1->getByIndex(i), + uno::UNO_QUERY_THROW); + if (::comphelper::getBOOL(xPropertySet->getPropertyValue("IsGroupField"))) + { + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("GroupInfo") >>= aDPFGI); + } + } + + uno::Reference<container::XIndexAccess> xIA_GI(aDPFGI.Groups, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA_GN(xIA_GI->getByIndex(0), uno::UNO_QUERY_THROW); + + return xNA_GN; +} + +void ScDataPilotFieldGroupObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotFieldGroupObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotfieldgroupsobj.cxx b/sc/qa/extras/scdatapilotfieldgroupsobj.cxx new file mode 100644 index 000000000..e742d2328 --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldgroupsobj.cxx @@ -0,0 +1,227 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xnamecontainer.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <comphelper/types.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/DataPilotFieldGroupInfo.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotFieldGrouping.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldGroupsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNameContainer, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldGroupsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDataPilotFieldGroupsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNameContainer + CPPUNIT_TEST(testInsertByName); + CPPUNIT_TEST(testInsertByNameEmptyName); + CPPUNIT_TEST(testRemoveByName); + CPPUNIT_TEST(testRemoveByNameEmptyName); + CPPUNIT_TEST(testRemoveByNameNoneExistingElement); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScDataPilotFieldGroupsObj::ScDataPilotFieldGroupsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<container::XNameAccess>::get()) + , XIndexAccess(1) + , XNameAccess("Group1") + , XNameContainer("Group1") + , XServiceInfo("ScDataPilotFieldGroupsObj", "com.sun.star.sheet.DataPilotFieldGroups") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotFieldGroupsObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + for (auto j = 1; j < m_nMaxFieldIndex; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + xSheet0->getCellByPosition(1, 1)->setFormula("aName"); + xSheet0->getCellByPosition(1, 2)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 3)->setFormula("una"); + xSheet0->getCellByPosition(1, 4)->setFormula("otherName"); + xSheet0->getCellByPosition(1, 5)->setFormula("somethingelse"); + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference<beans::XPropertySet> xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + xPropertySet0->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_ROW)); + + uno::Reference<beans::XPropertySet> xPropertySet1(xDPD->getDataPilotFields()->getByIndex(1), + uno::UNO_QUERY_THROW); + xPropertySet1->setPropertyValue("Function", uno::makeAny(sheet::GeneralFunction_SUM)); + xPropertySet1->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_DATA)); + + uno::Reference<beans::XPropertySet> xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2), + uno::UNO_QUERY_THROW); + xPropertySet2->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_COLUMN)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference<container::XIndexAccess> xIA_DPT0(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD0(xIA_DPT0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW); + + uno::Reference<sheet::XDataPilotFieldGrouping> xDPFG(xIA_RF0->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Sequence<OUString> aElements(2); + aElements[0] = "aName"; + aElements[1] = "otherName"; + xDPFG->createNameGroup(aElements); + + uno::Reference<container::XIndexAccess> xIA_DPT1(xDPTS->getDataPilotTables(), + uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD1(xIA_DPT1->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW); + + sheet::DataPilotFieldGroupInfo aDPFGI; + for (auto i = 0; i < xIA_RF1->getCount(); ++i) + { + uno::Reference<beans::XPropertySet> xPropertySet(xIA_RF1->getByIndex(i), + uno::UNO_QUERY_THROW); + if (::comphelper::getBOOL(xPropertySet->getPropertyValue("IsGroupField"))) + { + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("GroupInfo") >>= aDPFGI); + } + } + + // set element for testing XNameContainer::insertByName() + uno::Any aElement; + setElement(aElement); + + return aDPFGI.Groups; +} + +void ScDataPilotFieldGroupsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotFieldGroupsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotfieldobj.cxx b/sc/qa/extras/scdatapilotfieldobj.cxx new file mode 100644 index 000000000..89ad71dae --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldobj.cxx @@ -0,0 +1,134 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xnamed.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/datapilotfield.hxx> +#include <test/sheet/xdatapilotfield.hxx> +#include <test/sheet/xdatapilotfieldgrouping.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotFieldObj : public CalcUnoApiTest, + public apitest::DataPilotField, + public apitest::XDataPilotField, + public apitest::XDataPilotFieldGrouping, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference<uno::XInterface> init() override; + + ScDataPilotFieldObj(); + + CPPUNIT_TEST_SUITE(ScDataPilotFieldObj); + + // DataPilotField + CPPUNIT_TEST(testSortInfo); + CPPUNIT_TEST(testLayoutInfo); + CPPUNIT_TEST(testAutoShowInfo); + CPPUNIT_TEST(testReference); + CPPUNIT_TEST(testIsGroupField); + + // XDataPilotField + CPPUNIT_TEST(testGetItems); + + // XDataPilotFieldGrouping + CPPUNIT_TEST(testCreateNameGroup); + // see fdo# + //CPPUNIT_TEST(testCreateDateGroup); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScDataPilotFieldObj::ScDataPilotFieldObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("Col1") + , XPropertySet({ "Function", "HasAutoShowInfo", "HasLayoutInfo", "HasSortInfo", "Subtotals", + "Subtotals2" }) + , XServiceInfo("ScDataPilotFieldObj", "com.sun.star.sheet.DataPilotField") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotFieldObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(1), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Sequence<OUString> aElementNames = xDPT->getElementNames(); + (void)aElementNames; + + uno::Reference<sheet::XDataPilotDescriptor> xDPDsc(xDPT->getByName("DataPilot1"), + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDPDsc->getDataPilotFields(), uno::UNO_SET_THROW); + uno::Reference<uno::XInterface> xReturnValue(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + return xReturnValue; +} + +void ScDataPilotFieldObj::setUp() +{ + CalcUnoApiTest::setUp(); + + OUString aFileURL; + createFileURL("scdatapilotfieldobj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScDataPilotFieldObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotfieldsobj.cxx b/sc/qa/extras/scdatapilotfieldsobj.cxx new file mode 100644 index 000000000..54e1df298 --- /dev/null +++ b/sc/qa/extras/scdatapilotfieldsobj.cxx @@ -0,0 +1,139 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <cppu/unotype.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +namespace sc_apitest +{ +class ScDataPilotFieldsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDataPilotFieldsObj(); + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDataPilotFieldsObj); + + // XElementAccess + CPPUNIT_TEST(testHasElements); + CPPUNIT_TEST(testGetElementType); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScDataPilotFieldsObj::ScDataPilotFieldsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<beans::XPropertySet>::get()) + , XIndexAccess(6) + , XNameAccess("") + , XServiceInfo("ScDataPilotFieldsObj", "com.sun.star.sheet.DataPilotFields") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotFieldsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + for (int i = 1; i < 4; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (int i = 1; i < 4; ++i) + { + for (int j = 1; j < 4; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + } + } + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4)); + xDPT->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD); + + return xDPD->getDataPilotFields(); +} + +void ScDataPilotFieldsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotFieldsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotitemobj.cxx b/sc/qa/extras/scdatapilotitemobj.cxx new file mode 100644 index 000000000..217c28267 --- /dev/null +++ b/sc/qa/extras/scdatapilotitemobj.cxx @@ -0,0 +1,140 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/sheet/datapilotitem.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotField.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotItemObj : public CalcUnoApiTest, + public apitest::DataPilotItem, + public apitest::XNamed +{ +public: + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference<uno::XInterface> init() override; + + ScDataPilotItemObj(); + + CPPUNIT_TEST_SUITE(ScDataPilotItemObj); + + // DataPilotItem + CPPUNIT_TEST(testProperties); + + // XNamed + CPPUNIT_TEST(testGetName); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScDataPilotItemObj::ScDataPilotItemObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("2") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotItemObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; i++) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; i++) + for (auto j = 1; j < m_nMaxFieldIndex; j++) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference<beans::XPropertySet> xDataPilotFieldProp( + xDPD->getDataPilotFields()->getByIndex(0), uno::UNO_QUERY_THROW); + xDataPilotFieldProp->setPropertyValue("Function", uno::makeAny(sheet::GeneralFunction_SUM)); + xDataPilotFieldProp->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_DATA)); + + if (xDPT->hasByName("DataPilotTable")) + xDPT->removeByName("DataPilotTable"); + + uno::Reference<container::XIndexAccess> xIA_DPF(xDPD->getDataPilotFields(), uno::UNO_SET_THROW); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + uno::Reference<sheet::XDataPilotField> xDPF(xIA_DPF->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xReturn(xDPF->getItems()->getByIndex(0), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScDataPilotItemObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotItemObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotItemObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdatapilotitemsobj.cxx b/sc/qa/extras/scdatapilotitemsobj.cxx new file mode 100644 index 000000000..dba8e9ac5 --- /dev/null +++ b/sc/qa/extras/scdatapilotitemsobj.cxx @@ -0,0 +1,165 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotField.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDataPilotItemsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDataPilotItemsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDataPilotItemsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScDataPilotItemsObj::ScDataPilotItemsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<beans::XPropertySet>::get()) + , XIndexAccess(5) + , XNameAccess("2") + , XServiceInfo("ScDataPilotItemsObj", "com.sun.star.sheet.DataPilotItems") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotItemsObj::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + for (auto j = 1; j < m_nMaxFieldIndex; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Reference<beans::XPropertySet> xPropertySet(xDPD->getDataPilotFields()->getByIndex(1), + uno::UNO_QUERY_THROW); + xPropertySet->setPropertyValue("Function", uno::makeAny(sheet::GeneralFunction_SUM)); + xPropertySet->setPropertyValue("Orientation", + uno::makeAny(sheet::DataPilotFieldOrientation_DATA)); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference<container::XIndexAccess> xIA_DPF(xDPD->getDataPilotFields(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotField> xDPF(xIA_DPF->getByIndex(0), uno::UNO_QUERY_THROW); + + return xDPF->getItems(); +} + +void ScDataPilotItemsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotItemsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotItemsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scdatapilottableobj.cxx b/sc/qa/extras/scdatapilottableobj.cxx new file mode 100644 index 000000000..b9896862f --- /dev/null +++ b/sc/qa/extras/scdatapilottableobj.cxx @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/sheet/xdatapilotdescriptor.hxx> +#include <test/sheet/xdatapilottable.hxx> +#include <test/sheet/xdatapilottable2.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTable.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScDataPilotTableObj : public CalcUnoApiTest, + public apitest::XDataPilotDescriptor, + public apitest::XDataPilotTable, + public apitest::XDataPilotTable2, + public apitest::XNamed +{ +public: + ScDataPilotTableObj(); + + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< uno::XInterface > initDP2() override; + virtual uno::Reference< uno::XInterface > getSheets() override; + + CPPUNIT_TEST_SUITE(ScDataPilotTableObj); + + // XDataPilotDescriptor + CPPUNIT_TEST(testSourceRange); + CPPUNIT_TEST(testTag); + CPPUNIT_TEST(testGetFilterDescriptor); + CPPUNIT_TEST(testGetDataPilotFields); + CPPUNIT_TEST(testGetColumnFields); + CPPUNIT_TEST(testGetRowFields); + CPPUNIT_TEST(testGetPageFields); + CPPUNIT_TEST(testGetDataFields); + //CPPUNIT_TEST(testGetHiddenFields); + + // XDataPilotTable + CPPUNIT_TEST(testGetOutputRange); + CPPUNIT_TEST(testRefresh); + + // XDataPilotTable2 + CPPUNIT_TEST(testGetDrillDownData); + CPPUNIT_TEST(testInsertDrillDownSheet); + CPPUNIT_TEST(testGetPositionData); + CPPUNIT_TEST(testGetOutputRangeByType); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference< lang::XComponent > mxComponent; +}; + +ScDataPilotTableObj::ScDataPilotTableObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XNamed("DataPilotTable") +{ +} + +uno::Reference< uno::XInterface > ScDataPilotTableObj::init() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW); + + // set variables from xdatapilottable.[ch]xx + xCellForChange = xSheet->getCellByPosition( 1, 5 ); + xCellForCheck = xSheet->getCellByPosition( 7, 11 ); + CPPUNIT_ASSERT(xCellForCheck.is()); + CPPUNIT_ASSERT(xCellForChange.is()); + + CPPUNIT_ASSERT_MESSAGE("Could not create interface of type XSpreadsheet", xSheet.is()); + uno::Reference< sheet::XDataPilotTablesSupplier > xDPTS(xSheet, UNO_QUERY_THROW); + uno::Reference< sheet::XDataPilotTables > xDPT = xDPTS->getDataPilotTables(); + CPPUNIT_ASSERT(xDPT.is()); + + uno::Reference< sheet::XDataPilotTable > xDPTable(xDPT->getByName("DataPilotTable"),UNO_QUERY_THROW); + + return xDPTable; +} + +uno::Reference< uno::XInterface > ScDataPilotTableObj::getSheets() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference< uno::XInterface > xSheets(xDoc->getSheets()); + return xSheets; +} + +uno::Reference< uno::XInterface > ScDataPilotTableObj::initDP2() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW); + + // set variables from xdatapilottable.[ch]xx + xCellForChange = xSheet->getCellByPosition( 1, 5 ); + xCellForCheck = xSheet->getCellByPosition( 7, 11 ); + CPPUNIT_ASSERT(xCellForCheck.is()); + CPPUNIT_ASSERT(xCellForChange.is()); + + CPPUNIT_ASSERT_MESSAGE("Could not create interface of type XSpreadsheet", xSheet.is()); + uno::Reference< sheet::XDataPilotTablesSupplier > xDPTS(xSheet, UNO_QUERY_THROW); + uno::Reference< sheet::XDataPilotTables > xDPT = xDPTS->getDataPilotTables(); + CPPUNIT_ASSERT(xDPT.is()); + + uno::Reference< sheet::XDataPilotTable > xDPTable(xDPT->getByName("DataPilotTable2"),UNO_QUERY_THROW); + + return xDPTable; +} + +void ScDataPilotTableObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL("ScDataPilotTableObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScDataPilotTableObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotTableObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scdatapilottablesobj.cxx b/sc/qa/extras/scdatapilottablesobj.cxx new file mode 100644 index 000000000..3095feee7 --- /dev/null +++ b/sc/qa/extras/scdatapilottablesobj.cxx @@ -0,0 +1,152 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xdatapilottables.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTable2.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDataPilotTablesObj : public CalcUnoApiTest, + public apitest::XDataPilotTables, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDataPilotTablesObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXSpreadsheet() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDataPilotTablesObj); + + // XDataPilotTables + CPPUNIT_TEST(testXDataPilotTables); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScDataPilotTablesObj::ScDataPilotTablesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XDataPilotTable2>::get()) + , XIndexAccess(1) + , XNameAccess("DataPilotTable") + , XServiceInfo("ScDataPilotTablesObj", "com.sun.star.sheet.DataPilotTables") +{ +} + +uno::Reference<uno::XInterface> ScDataPilotTablesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + for (auto i = 1; i < 4; i++) + { + xSheet->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet, UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + UNO_SET_THROW); + xDPD->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4)); + xDPT->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD); + + return xDPT; +} + +uno::Reference<uno::XInterface> ScDataPilotTablesObj::getXSpreadsheet() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + return xSheet; +} + +void ScDataPilotTablesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDataPilotTablesObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotTablesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scddelinkobj.cxx b/sc/qa/extras/scddelinkobj.cxx new file mode 100644 index 000000000..a64104e66 --- /dev/null +++ b/sc/qa/extras/scddelinkobj.cxx @@ -0,0 +1,144 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/sheet/xddelink.hxx> +#include <test/util/xrefreshable.hxx> + +#include <unotools/tempfile.hxx> +#include <vcl/svapp.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDDELink.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +static utl::TempFile createTempCopy(OUString const& url) +{ + utl::TempFile tmp; + tmp.EnableKillingFile(); + auto const e = osl::File::copy(url, tmp.GetURL()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + (OUStringToOString("<" + url + "> -> <" + tmp.GetURL() + ">", RTL_TEXTENCODING_UTF8) + .getStr()), + osl::FileBase::E_None, e); + return tmp; +} + +namespace +{ +struct TempFileBase +{ + utl::TempFile m_TempFile; + explicit TempFileBase(OUString const& url) + : m_TempFile(createTempCopy(url)) + { + } +}; +} + +class ScDDELinkObj : public CalcUnoApiTest, + public TempFileBase, + public apitest::XDDELink, + public apitest::XNamed, + public apitest::XRefreshable +{ +public: + ScDDELinkObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDDELinkObj); + + // XDDELink + CPPUNIT_TEST(testGetApplication); + CPPUNIT_TEST(testGetItem); + CPPUNIT_TEST(testGetTopic); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetNameThrowsException); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScDDELinkObj::ScDDELinkObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , TempFileBase(m_directories.getURLFromSrc("/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods")) + , XDDELink(m_TempFile.GetURL()) + , XNamed("soffice|" + m_TempFile.GetURL() + "!Sheet1.A1") +{ +} + +uno::Reference<uno::XInterface> ScDDELinkObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + + const OUString testdoc = m_TempFile.GetURL(); + + xSheet->getCellByPosition(5, 5)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + xSheet->getCellByPosition(1, 4)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, UNO_QUERY_THROW); + uno::Any aDDELinks = xPropSet->getPropertyValue("DDELinks"); + uno::Reference<container::XNameAccess> xNA(aDDELinks, UNO_QUERY_THROW); + uno::Sequence<OUString> sLinkNames = xNA->getElementNames(); + uno::Reference<sheet::XDDELink> xDDELink(xNA->getByName(sLinkNames[0]), UNO_QUERY_THROW); + return xDDELink; +} + +void ScDDELinkObj::setUp() +{ + Application::SetAppName("soffice"); // Enable DDE + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDDELinkObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDDELinkObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scddelinksobj.cxx b/sc/qa/extras/scddelinksobj.cxx new file mode 100644 index 000000000..a8bd6aff8 --- /dev/null +++ b/sc/qa/extras/scddelinksobj.cxx @@ -0,0 +1,143 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xddelinks.hxx> + +#include <cppu/unotype.hxx> +#include <rtl/ustring.hxx> +#include <vcl/svapp.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDDELink.hpp> +#include <com/sun/star/sheet/XDDELinks.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDDELinksObj : public CalcUnoApiTest, + public apitest::XDDELinks, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScDDELinksObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDDELinksObj); + + // XDDELinks + CPPUNIT_TEST(testAddDDELink); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScDDELinksObj::ScDDELinksObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XDDELinks(m_directories.getURLFromSrc("/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods")) + , XElementAccess(cppu::UnoType<sheet::XDDELink>::get()) + , XIndexAccess(1) + , XNameAccess("soffice|" + + m_directories.getURLFromSrc("/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods") + + "!Sheet1.A1") + , XServiceInfo("ScDDELinksObj", "com.sun.star.sheet.DDELinks") +{ +} + +uno::Reference<uno::XInterface> ScDDELinksObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + const OUString testdoc + = m_directories.getURLFromSrc("/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods"); + + xSheet->getCellByPosition(5, 5)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + xSheet->getCellByPosition(1, 4)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + xSheet->getCellByPosition(2, 0)->setFormula("=DDE(\"soffice\";\"" + testdoc + + "\";\"Sheet1.A1\")"); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Any aDDELinks = xPropSet->getPropertyValue("DDELinks"); + uno::Reference<sheet::XDDELinks> xDDELinks(aDDELinks, uno::UNO_QUERY_THROW); + + return xDDELinks; +} + +void ScDDELinksObj::setUp() +{ + Application::SetAppName("soffice"); // Enable DDE + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDDELinksObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDDELinksObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdocumentconfigurationobj.cxx b/sc/qa/extras/scdocumentconfigurationobj.cxx new file mode 100644 index 000000000..132e9b792 --- /dev/null +++ b/sc/qa/extras/scdocumentconfigurationobj.cxx @@ -0,0 +1,78 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/documentsettings.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScDocumentConfigurationObj : public CalcUnoApiTest, public apitest::DocumentSettings +{ +public: + ScDocumentConfigurationObj(); + + virtual uno::Reference<uno::XInterface> init() override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDocumentConfigurationObj); + + // DocumentSettings + CPPUNIT_TEST(testDocumentSettingsProperties); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScDocumentConfigurationObj::ScDocumentConfigurationObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScDocumentConfigurationObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.DocumentSettings"); +} + +void ScDocumentConfigurationObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDocumentConfigurationObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDocumentConfigurationObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdrawpageobj.cxx b/sc/qa/extras/scdrawpageobj.cxx new file mode 100644 index 000000000..d7f54a086 --- /dev/null +++ b/sc/qa/extras/scdrawpageobj.cxx @@ -0,0 +1,130 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/helper/shape.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/drawing/xshapegrouper.hxx> +#include <test/drawing/xshapes.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScDrawPageObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XServiceInfo, + public apitest::XShapeGrouper, + public apitest::XShapes +{ +public: + ScDrawPageObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDrawPageObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XShapeGrouper + CPPUNIT_TEST(testGroup); + CPPUNIT_TEST(testUngroup); + + // XShapes + CPPUNIT_TEST(testAddRemove); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScDrawPageObj::ScDrawPageObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<drawing::XShape>::get()) + , XIndexAccess(2) + , XServiceInfo("ScPageObj", "com.sun.star.sheet.SpreadsheetDrawPage") +{ +} + +uno::Reference<uno::XInterface> ScDrawPageObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPages> xDP(xDPS->getDrawPages(), uno::UNO_SET_THROW); + xDP->insertNewByIndex(0); + xDP->insertNewByIndex(1); + + uno::Reference<drawing::XDrawPage> xDrawPage(xDP->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShapes> xShapes(xDrawPage, uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XShape> xRectangle0( + apitest::helper::shape::createRectangle(m_xComponent, 7500, 5000, 5000, 3500), + uno::UNO_SET_THROW); + xShapes->add(xRectangle0); + uno::Reference<drawing::XShape> xRectangle1( + apitest::helper::shape::createRectangle(m_xComponent, 5000, 5000, 5000, 5500), + uno::UNO_SET_THROW); + xShapes->add(xRectangle1); + + // needed for XShapeGrouper tests + setDrawPage(xDrawPage); + // needed for XShapes tests + setShape(apitest::helper::shape::createLine(m_xComponent, 7500, 10000, 5000, 3500)); + return xDrawPage; +} + +void ScDrawPageObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDrawPageObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDrawPageObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scdrawpagesobj.cxx b/sc/qa/extras/scdrawpagesobj.cxx new file mode 100644 index 000000000..59a78e618 --- /dev/null +++ b/sc/qa/extras/scdrawpagesobj.cxx @@ -0,0 +1,110 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/drawing/xdrawpages.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScDrawPagesObj : public CalcUnoApiTest, + public apitest::XDrawPages, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XServiceInfo +{ +public: + ScDrawPagesObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScDrawPagesObj); + + // XDrawPages + CPPUNIT_TEST(testInsertNewByIndex); + CPPUNIT_TEST(testRemove); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScDrawPagesObj::ScDrawPagesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<drawing::XDrawPage>::get()) + , XIndexAccess(3) + , XServiceInfo("ScDrawPagesObj", "com.sun.star.drawing.DrawPages") +{ +} + +uno::Reference<uno::XInterface> ScDrawPagesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPages> xDP(xDPS->getDrawPages(), uno::UNO_SET_THROW); + + xDP->insertNewByIndex(1); + xDP->insertNewByIndex(2); + + return xDP; +} + +void ScDrawPagesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScDrawPagesObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScDrawPagesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sceditfieldobj-cell.cxx b/sc/qa/extras/sceditfieldobj-cell.cxx new file mode 100644 index 000000000..53f333269 --- /dev/null +++ b/sc/qa/extras/sceditfieldobj-cell.cxx @@ -0,0 +1,205 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/text/textcontent.hxx> +#include <test/text/xtextfield.hxx> +#include <test/text/xtextcontent.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/text/WrapTextMode.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScEditFieldObj_Cell : public CalcUnoApiTest, + public apitest::TextContent, + public apitest::XPropertySet, + public apitest::XTextContent, + public apitest::XTextField +{ +public: + ScEditFieldObj_Cell(); + + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<text::XTextContent> getTextContent() override; + virtual uno::Reference<text::XTextRange> getTextRange() override; + virtual bool isAttachSupported() override { return true; } + + void testEditFieldProperties(); + + CPPUNIT_TEST_SUITE(ScEditFieldObj_Cell); + + // TextContent + CPPUNIT_TEST(testTextContentProperties); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XTextField + CPPUNIT_TEST(testGetPresentation); + + // XTextContent + CPPUNIT_TEST(testGetAnchor); + CPPUNIT_TEST(testAttach); + + // Tests specific to this service implementation. + CPPUNIT_TEST(testEditFieldProperties); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; + static uno::Reference<text::XTextField> mxField; +}; + +uno::Reference<text::XTextField> ScEditFieldObj_Cell::mxField; + +ScEditFieldObj_Cell::ScEditFieldObj_Cell() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , TextContent(text::TextContentAnchorType_AS_CHARACTER, + text::TextContentAnchorType_AS_CHARACTER, text::WrapTextMode_NONE, + text::WrapTextMode_NONE) +{ +} + +void ScEditFieldObj_Cell::setUp() +{ + CalcUnoApiTest::setUp(); + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScEditFieldObj_Cell::tearDown() +{ + mxField.clear(); + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +namespace +{ +uno::Reference<text::XTextField> getNewField(const uno::Reference<lang::XMultiServiceFactory>& xSM) +{ + uno::Reference<text::XTextField> xField(xSM->createInstance("com.sun.star.text.TextField.URL"), + uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xField, uno::UNO_QUERY_THROW); + xPropSet->setPropertyValue("Representation", uno::makeAny(OUString("LibreOffice"))); + xPropSet->setPropertyValue("URL", uno::makeAny(OUString("http://www.libreoffice.org/"))); + return xField; +} + +} // namespace + +uno::Reference<uno::XInterface> ScEditFieldObj_Cell::init() +{ + // Return a field that's already in the cell. + if (!mxField.is()) + { + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + + // Create a new URL field object, and populate it with name and URL. + mxField = getNewField(xSM); + + // Insert this field into a cell. + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + // Use cell A1 for this. + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0); + uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW); + + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xContent(mxField, uno::UNO_QUERY_THROW); + xText->insertTextContent(xRange, xContent, false); + } + return mxField; +} + +uno::Reference<text::XTextContent> ScEditFieldObj_Cell::getTextContent() +{ + // Return a field object that's not yet inserted. + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + return uno::Reference<text::XTextContent>(getNewField(xSM), uno::UNO_QUERY_THROW); +} + +uno::Reference<text::XTextRange> ScEditFieldObj_Cell::getTextRange() +{ + // Use cell A2 for this. + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 1); + uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW); + + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW); + return xRange; +} + +void ScEditFieldObj_Cell::testEditFieldProperties() +{ + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + + { + // Test properties of date time field. + uno::Reference<text::XTextField> xField( + xSM->createInstance("com.sun.star.text.textfield.DateTime"), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xField, uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo(); + CPPUNIT_ASSERT_MESSAGE("failed to retrieve property set info.", xInfo.is()); + + CPPUNIT_ASSERT_MESSAGE("Calc's date time field should have 'IsFixed' property.", + xInfo->hasPropertyByName("IsFixed")); + } + + { + // Test properties of document title field. + uno::Reference<text::XTextField> xField( + xSM->createInstance("com.sun.star.text.textfield.docinfo.Title"), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xField, uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo(); + CPPUNIT_ASSERT_MESSAGE("failed to retrieve property set info.", xInfo.is()); + + CPPUNIT_ASSERT_MESSAGE("Calc's title field shouldn't have 'IsFixed' property.", + !xInfo->hasPropertyByName("IsFixed")); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Cell); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sceditfieldobj-header.cxx b/sc/qa/extras/sceditfieldobj-header.cxx new file mode 100644 index 000000000..57e4d067f --- /dev/null +++ b/sc/qa/extras/sceditfieldobj-header.cxx @@ -0,0 +1,165 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/text/textcontent.hxx> +#include <test/text/xtextcontent.hxx> +#include <test/text/xtextfield.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XHeaderFooterContent.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/text/WrapTextMode.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScEditFieldObj_Header : public CalcUnoApiTest, + public apitest::TextContent, + public apitest::XPropertySet, + public apitest::XTextContent, + public apitest::XTextField +{ +public: + ScEditFieldObj_Header(); + + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<text::XTextContent> getTextContent() override; + virtual uno::Reference<text::XTextRange> getTextRange() override; + virtual bool isAttachSupported() override { return false; } + + CPPUNIT_TEST_SUITE(ScEditFieldObj_Header); + + // TextContent + CPPUNIT_TEST(testTextContentProperties); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XTextContent + CPPUNIT_TEST(testGetAnchor); + CPPUNIT_TEST(testAttach); + + // XTextField + CPPUNIT_TEST(testGetPresentationEmptyString); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; + static uno::Reference<text::XTextField> mxField; + static uno::Reference<text::XText> mxRightText; +}; + +uno::Reference<text::XTextField> ScEditFieldObj_Header::mxField; +uno::Reference<text::XText> ScEditFieldObj_Header::mxRightText; + +ScEditFieldObj_Header::ScEditFieldObj_Header() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , TextContent(text::TextContentAnchorType_AS_CHARACTER, + text::TextContentAnchorType_AS_CHARACTER, text::WrapTextMode_NONE, + text::WrapTextMode_NONE) +{ +} + +void ScEditFieldObj_Header::setUp() +{ + CalcUnoApiTest::setUp(); + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScEditFieldObj_Header::tearDown() +{ + // Clear these before the component is destroyed. This is important! + mxField.clear(); + mxRightText.clear(); + closeDocument(mxComponent); + + CalcUnoApiTest::tearDown(); +} + +uno::Reference<uno::XInterface> ScEditFieldObj_Header::init() +{ + // Return a field that's already in the header. + if (!mxField.is()) + { + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + + // Create a new URL field object, and populate it with name and URL. + mxField.set(xSM->createInstance("com.sun.star.text.TextField.Time"), uno::UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xStyleFamilies(xSFS->getStyleFamilies(), + uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName("PageStyles"), + uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xPageStyles->getByName("Default"), + uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( + xPropSet->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW); + + // Use the left header text. + uno::Reference<text::XText> xText = xHeaderContent->getLeftText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xContent(mxField, uno::UNO_QUERY_THROW); + xText->insertTextContent(xRange, xContent, false); + + xPropSet->setPropertyValue("RightPageHeaderContent", uno::makeAny(xHeaderContent)); + + mxRightText = xHeaderContent->getRightText(); + } + + return mxField; +} + +uno::Reference<text::XTextContent> ScEditFieldObj_Header::getTextContent() +{ + // Return a field object that's not yet inserted. + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xField( + xSM->createInstance("com.sun.star.text.TextField.Date"), uno::UNO_QUERY_THROW); + return xField; +} + +uno::Reference<text::XTextRange> ScEditFieldObj_Header::getTextRange() +{ + // Use the right header text for this. + uno::Reference<text::XTextRange> xRange(mxRightText, uno::UNO_QUERY_THROW); + return xRange; +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Header); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scfilterdescriptorbase.cxx b/sc/qa/extras/scfilterdescriptorbase.cxx new file mode 100644 index 000000000..7811d6c83 --- /dev/null +++ b/sc/qa/extras/scfilterdescriptorbase.cxx @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/sheetfilterdescriptor.hxx> +#include <test/sheet/xsheetfilterdescriptor.hxx> +#include <test/sheet/xsheetfilterdescriptor2.hxx> +#include <test/sheet/xsheetfilterdescriptor3.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetFilterable.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScFilterDescriptorBase : public CalcUnoApiTest, + public apitest::SheetFilterDescriptor, + public apitest::XPropertySet, + public apitest::XServiceInfo, + public apitest::XSheetFilterDescriptor, + public apitest::XSheetFilterDescriptor2, + public apitest::XSheetFilterDescriptor3 +{ +public: + ScFilterDescriptorBase(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference<uno::XInterface> init() override; + + CPPUNIT_TEST_SUITE(ScFilterDescriptorBase); + + // SheetFilterDescriptor + CPPUNIT_TEST(testSheetFilterDescriptorProperties); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XSheetFilterDescriptor + CPPUNIT_TEST(testGetSetFilterFields); + + // XSheetFilterDescriptor2 + CPPUNIT_TEST(testGetSetFilterFields2); + + // XSheetFilterDescriptor3 + CPPUNIT_TEST(testGetSetFilterFields3); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScFilterDescriptorBase::ScFilterDescriptorBase() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ "Orientation", "OutputPosition" }) + , XServiceInfo("ScFilterDescriptorBase", "com.sun.star.sheet.SheetFilterDescriptor") +{ +} + +uno::Reference<uno::XInterface> ScFilterDescriptorBase::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndexAccess(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 5)->setValue(15); + xSheet->getCellByPosition(1, 4)->setValue(10); + xSheet->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<sheet::XSheetFilterable> xSF(xSheet, uno::UNO_QUERY_THROW); + + return xSF->createFilterDescriptor(true); +} + +void ScFilterDescriptorBase::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScFilterDescriptorBase::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScFilterDescriptorBase); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scfunctiondescriptionobj.cxx b/sc/qa/extras/scfunctiondescriptionobj.cxx new file mode 100644 index 000000000..ee6456be1 --- /dev/null +++ b/sc/qa/extras/scfunctiondescriptionobj.cxx @@ -0,0 +1,90 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/functiondescription.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XFunctionDescriptions.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScFunctionDescriptionObj : public CalcUnoApiTest, public apitest::FunctionDescription +{ +public: + ScFunctionDescriptionObj(); + + virtual uno::Sequence<beans::PropertyValue> init() override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScFunctionDescriptionObj); + + // FunctionDescription + CPPUNIT_TEST(testFunctionDescriptionProperties); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScFunctionDescriptionObj::ScFunctionDescriptionObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Sequence<beans::PropertyValue> ScFunctionDescriptionObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + uno::Reference<sheet::XFunctionDescriptions> xFDs( + xMSF->createInstance("com.sun.star.sheet.FunctionDescriptions"), UNO_QUERY_THROW); + + uno::Reference<container::XNameAccess> xNA(xFDs, UNO_QUERY_THROW); + uno::Sequence<OUString> names = xNA->getElementNames(); + + uno::Sequence<beans::PropertyValue> sPropertyValues; + CPPUNIT_ASSERT(xNA->getByName(names[0]) >>= sPropertyValues); + return sPropertyValues; +} + +void ScFunctionDescriptionObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScFunctionDescriptionObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScFunctionDescriptionObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scfunctionlistobj.cxx b/sc/qa/extras/scfunctionlistobj.cxx new file mode 100644 index 000000000..385ea7d89 --- /dev/null +++ b/sc/qa/extras/scfunctionlistobj.cxx @@ -0,0 +1,117 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xfunctiondescriptions.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScFunctionListObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XFunctionDescriptions, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScFunctionListObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScFunctionListObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XFunctionDescriptions + CPPUNIT_TEST(testGetById); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScFunctionListObj::ScFunctionListObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<uno::Sequence<beans::PropertyValue>>::get()) + , XIndexAccess(395) + , XNameAccess("IF") + , XServiceInfo("stardiv.StarCalc.ScFunctionListObj", "com.sun.star.sheet.FunctionDescriptions") +{ +} + +uno::Reference<uno::XInterface> ScFunctionListObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.FunctionDescriptions"); +} + +void ScFunctionListObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScFunctionListObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScFunctionListObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scheaderfieldsobj.cxx b/sc/qa/extras/scheaderfieldsobj.cxx new file mode 100644 index 000000000..2265fb795 --- /dev/null +++ b/sc/qa/extras/scheaderfieldsobj.cxx @@ -0,0 +1,106 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/util/xrefreshable.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XHeaderFooterContent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScHeaderFieldsObj : public CalcUnoApiTest, + public apitest::XEnumerationAccess, + public apitest::XRefreshable +{ +public: + ScHeaderFieldsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScHeaderFieldsObj); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScHeaderFieldsObj::ScHeaderFieldsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScHeaderFieldsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xNA1(xNA->getByName("PageStyles"), uno::UNO_QUERY_THROW); + uno::Reference<style::XStyle> xStyle(xNA1->getByName("Default"), uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XHeaderFooterContent> xHFC( + xPropertySet->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW); + uno::Reference<text::XText> xText(xHFC->getLeftText(), uno::UNO_SET_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xTC(xMSF->createInstance("com.sun.star.text.TextField.Time"), + uno::UNO_QUERY_THROW); + xText->insertTextContent(xText->createTextCursor(), xTC, false); + xPropertySet->setPropertyValue("RightPageHeaderContent", uno::makeAny(xHFC)); + + uno::Reference<text::XTextFieldsSupplier> xTFS(xText, uno::UNO_QUERY_THROW); + return xTFS->getTextFields(); +} + +void ScHeaderFieldsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScHeaderFieldsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScHeaderFieldsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scheaderfootercontentobj.cxx b/sc/qa/extras/scheaderfootercontentobj.cxx new file mode 100644 index 000000000..454a402da --- /dev/null +++ b/sc/qa/extras/scheaderfootercontentobj.cxx @@ -0,0 +1,104 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/xheaderfootercontent.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XHeaderFooterContent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScHeaderFooterContentObj : public CalcUnoApiTest, public apitest::XHeaderFooterContent +{ +public: + ScHeaderFooterContentObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScHeaderFooterContentObj); + + // XHeaderFooterContent + CPPUNIT_TEST(testGetCenterText); + CPPUNIT_TEST(testGetLeftText); + CPPUNIT_TEST(testGetRightText); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScHeaderFooterContentObj::ScHeaderFooterContentObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScHeaderFooterContentObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamSupp(xDoc, UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xStyleFamiliesNames(xStyleFamSupp->getStyleFamilies(), + UNO_SET_THROW); + uno::Reference<container::XNameAccess> xPageStyles(xStyleFamiliesNames->getByName("PageStyles"), + UNO_QUERY_THROW); + uno::Any aDefaultStyle = xPageStyles->getByName("Default"); + uno::Reference<beans::XPropertySet> xProp(aDefaultStyle, UNO_QUERY_THROW); + + uno::Any aHFC = xProp->getPropertyValue("RightPageHeaderContent"); + uno::Reference<sheet::XHeaderFooterContent> xHFC(aHFC, UNO_QUERY_THROW); + + uno::Reference<text::XText> xTxtCenter = xHFC->getCenterText(); + uno::Reference<text::XText> xTxtLeft = xHFC->getLeftText(); + uno::Reference<text::XText> xTxtRight = xHFC->getRightText(); + + xTxtCenter->setString("CENTER"); + xTxtLeft->setString("LEFT"); + xTxtRight->setString("RIGHT"); + + xProp->setPropertyValue("RightPageHeaderContent", aHFC); + + return xHFC; +} + +void ScHeaderFooterContentObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScHeaderFooterContentObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScHeaderFooterContentObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scimportdescriptorbaseobj.cxx b/sc/qa/extras/scimportdescriptorbaseobj.cxx new file mode 100644 index 000000000..b4812096e --- /dev/null +++ b/sc/qa/extras/scimportdescriptorbaseobj.cxx @@ -0,0 +1,98 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/databaseimportdescriptor.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/util/XImportable.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScImportDescriptorBaseObj : public CalcUnoApiTest, public apitest::DatabaseImportDescriptor +{ +public: + ScImportDescriptorBaseObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXImportable() override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScImportDescriptorBaseObj); + + // DatabaseImportDescriptor + CPPUNIT_TEST(testDatabaseImportDescriptorProperties); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScImportDescriptorBaseObj::ScImportDescriptorBaseObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScImportDescriptorBaseObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + return xSheet; +} + +uno::Reference<uno::XInterface> ScImportDescriptorBaseObj::getXImportable() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference<util::XImportable> XImportable(xSheet, UNO_QUERY_THROW); + return XImportable; +} + +void ScImportDescriptorBaseObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScImportDescriptorBaseObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScImportDescriptorBaseObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_cellannotationsenumeration.cxx b/sc/qa/extras/scindexenumeration_cellannotationsenumeration.cxx new file mode 100644 index 000000000..f5b58c67f --- /dev/null +++ b/sc/qa/extras/scindexenumeration_cellannotationsenumeration.cxx @@ -0,0 +1,97 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetAnnotations.hpp> +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_CellAnnotationsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_CellAnnotationsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_CellAnnotationsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_CellAnnotationsEnumeration::ScIndexEnumeration_CellAnnotationsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_CellAnnotationsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetAnnotationsSupplier> xSAS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotations> xSA(xSAS->getAnnotations(), uno::UNO_SET_THROW); + xSA->insertNew(table::CellAddress(0, 5, 5), "Note"); + + uno::Reference<container::XEnumerationAccess> xEA(xSA, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumeration> xE(xEA->createEnumeration(), uno::UNO_SET_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_CellAnnotationsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_CellAnnotationsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_CellAnnotationsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_cellarealinksenumeration.cxx b/sc/qa/extras/scindexenumeration_cellarealinksenumeration.cxx new file mode 100644 index 000000000..9aab87900 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_cellarealinksenumeration.cxx @@ -0,0 +1,90 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XAreaLinks.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_CellAreaLinksEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_CellAreaLinksEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_CellAreaLinksEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_CellAreaLinksEnumeration::ScIndexEnumeration_CellAreaLinksEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_CellAreaLinksEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XAreaLinks> xAL; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("AreaLinks") >>= xAL); + xAL->insertAtPosition(table::CellAddress(1, 2, 3), + "ScIndexEnumeration_CellAreaLinksEnumeration.ods", "A2:B5", "", ""); + + uno::Reference<container::XEnumerationAccess> xEA(xAL, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_CellAreaLinksEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_CellAreaLinksEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_CellAreaLinksEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_databaserangesenumeration.cxx b/sc/qa/extras/scindexenumeration_databaserangesenumeration.cxx new file mode 100644 index 000000000..4fc328cc5 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_databaserangesenumeration.cxx @@ -0,0 +1,89 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDatabaseRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DatabaseRangesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DatabaseRangesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DatabaseRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_DatabaseRangesEnumeration::ScIndexEnumeration_DatabaseRangesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_DatabaseRangesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDatabaseRanges> xDR; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("DatabaseRanges") >>= xDR); + xDR->addNewByName("DatabaseRange", table::CellRangeAddress(0, 2, 4, 5, 6)); + + uno::Reference<container::XEnumerationAccess> xEA(xDR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DatabaseRangesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_DatabaseRangesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DatabaseRangesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_datapilotfieldsenumeration.cxx b/sc/qa/extras/scindexenumeration_datapilotfieldsenumeration.cxx new file mode 100644 index 000000000..c59291ebc --- /dev/null +++ b/sc/qa/extras/scindexenumeration_datapilotfieldsenumeration.cxx @@ -0,0 +1,111 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DataPilotFieldsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DataPilotFieldsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotFieldsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_DataPilotFieldsEnumeration::ScIndexEnumeration_DataPilotFieldsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_DataPilotFieldsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < 4; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto x = 1; x < 4; ++x) + for (auto y = 1; y < 4; ++y) + xSheet0->getCellByPosition(x, y)->setValue(x * (y + 1)); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + xDPD->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4)); + xDPT->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD); + + uno::Reference<container::XEnumerationAccess> xEA(xDPD->getDataPilotFields(), + uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DataPilotFieldsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_DataPilotFieldsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DataPilotFieldsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_datapilotitemsenumeration.cxx b/sc/qa/extras/scindexenumeration_datapilotitemsenumeration.cxx new file mode 100644 index 000000000..f99e9d78a --- /dev/null +++ b/sc/qa/extras/scindexenumeration_datapilotitemsenumeration.cxx @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotField.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScIndexEnumeration_DataPilotItemsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DataPilotItemsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotItemsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + static const int m_nMaxFieldIndex = 6; + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_DataPilotItemsEnumeration::ScIndexEnumeration_DataPilotItemsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_DataPilotItemsEnumeration::init() +{ + table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1); + table::CellAddress aCellAddress(0, 7, 8); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no document", xDoc.is()); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("Some Sheet", 0); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto i = 1; i < m_nMaxFieldIndex; ++i) + { + for (auto j = 1; j < m_nMaxFieldIndex; ++j) + { + xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1)); + xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2)); + } + } + + xSheet0->getCellByPosition(1, 5); + xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + + xDPD->setSourceRange(aCellRangeAddress); + + uno::Any aValue; + uno::Reference<beans::XPropertySet> xPropertySet(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + aValue <<= sheet::DataPilotFieldOrientation_DATA; + xPropertySet->setPropertyValue("Orientation", aValue); + aValue <<= sheet::GeneralFunction_SUM; + xPropertySet->setPropertyValue("Function", aValue); + + xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD); + + uno::Reference<sheet::XDataPilotField> xDPF(xDPD->getDataPilotFields()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xDPF->getItems(), uno::UNO_QUERY_THROW); + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DataPilotItemsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_DataPilotItemsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DataPilotItemsEnumeration); +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scindexenumeration_datapilottablesenumeration.cxx b/sc/qa/extras/scindexenumeration_datapilottablesenumeration.cxx new file mode 100644 index 000000000..33e5092b1 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_datapilottablesenumeration.cxx @@ -0,0 +1,110 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DataPilotTablesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DataPilotTablesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotTablesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_DataPilotTablesEnumeration::ScIndexEnumeration_DataPilotTablesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_DataPilotTablesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + for (auto i = 1; i < 4; ++i) + { + xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i)); + xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i)); + } + + for (auto x = 1; x < 4; ++x) + for (auto y = 1; y < 4; ++y) + xSheet0->getCellByPosition(x, y)->setValue(x * (y + 1)); + + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW); + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + uno::UNO_SET_THROW); + xDPD->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4)); + xDPT->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD); + + uno::Reference<container::XEnumerationAccess> xEA(xDPT, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DataPilotTablesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_DataPilotTablesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DataPilotTablesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_ddelinksenumeration.cxx b/sc/qa/extras/scindexenumeration_ddelinksenumeration.cxx new file mode 100644 index 000000000..da64bc9a1 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_ddelinksenumeration.cxx @@ -0,0 +1,99 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <sal/types.h> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_DDELinksEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_DDELinksEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_DDELinksEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_DDELinksEnumeration::ScIndexEnumeration_DDELinksEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_DDELinksEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(5, 5)->setFormula( + "=DDE(\"soffice\";\"ScDDELinksObj.ods\";\"Sheet1.A1\""); + xSheet0->getCellByPosition(1, 4)->setFormula( + "=DDE(\"soffice\";\"ScDDELinksObj.ods\";\"Sheet1.A1\""); + xSheet0->getCellByPosition(2, 0)->setFormula( + "=DDE(\"soffice\";\"ScDDELinksObj.ods\";\"Sheet1.A1\""); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + + uno::Reference<container::XEnumerationAccess> xEA(xPropertySet->getPropertyValue("DDELinks"), + uno::UNO_QUERY_THROW); + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_DDELinksEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_DDELinksEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DDELinksEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_functiondescriptionenumeration.cxx b/sc/qa/extras/scindexenumeration_functiondescriptionenumeration.cxx new file mode 100644 index 000000000..33572aa2d --- /dev/null +++ b/sc/qa/extras/scindexenumeration_functiondescriptionenumeration.cxx @@ -0,0 +1,85 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_FunctionDescriptionEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_FunctionDescriptionEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_FunctionDescriptionEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_FunctionDescriptionEnumeration:: + ScIndexEnumeration_FunctionDescriptionEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_FunctionDescriptionEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA( + xMSF->createInstance("com.sun.star.sheet.FunctionDescriptions"), uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_FunctionDescriptionEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_FunctionDescriptionEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_FunctionDescriptionEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_labelrangesenumeration.cxx b/sc/qa/extras/scindexenumeration_labelrangesenumeration.cxx new file mode 100644 index 000000000..1da0b0138 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_labelrangesenumeration.cxx @@ -0,0 +1,91 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XLabelRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_LabelRangesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_LabelRangesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_LabelRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_LabelRangesEnumeration::ScIndexEnumeration_LabelRangesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_LabelRangesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XLabelRanges> xLR; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("ColumnLabelRanges") >>= xLR); + + xLR->addNew(table::CellRangeAddress(0, 0, 1, 0, 6), table::CellRangeAddress(0, 0, 0, 0, 1)); + + uno::Reference<container::XEnumerationAccess> xEA(xLR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_LabelRangesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_LabelRangesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_LabelRangesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_namedrangesenumeration.cxx b/sc/qa/extras/scindexenumeration_namedrangesenumeration.cxx new file mode 100644 index 000000000..2a1b2a8c4 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_namedrangesenumeration.cxx @@ -0,0 +1,96 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_NamedRangesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_NamedRangesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_NamedRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_NamedRangesEnumeration::ScIndexEnumeration_NamedRangesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_NamedRangesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XNamedRanges> xNR; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("NamedRanges") >>= xNR); + + table::CellRangeAddress aCellRangeAddr(0, 0, 0, 2, 2); + table::CellAddress aBaseAddr(aCellRangeAddr.Sheet, aCellRangeAddr.StartColumn, + aCellRangeAddr.StartRow); + xNR->addNewByName("ANamedRange", "A1:B2", aBaseAddr, 0); + xNR->outputList(table::CellAddress(0, 1, 1)); + + uno::Reference<container::XEnumerationAccess> xEA(xNR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_NamedRangesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_NamedRangesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_NamedRangesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_scenariosenumeration.cxx b/sc/qa/extras/scindexenumeration_scenariosenumeration.cxx new file mode 100644 index 000000000..c4ba4fc32 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_scenariosenumeration.cxx @@ -0,0 +1,106 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XScenariosSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_ScenariosEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_ScenariosEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_ScenariosEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_ScenariosEnumeration::ScIndexEnumeration_ScenariosEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_ScenariosEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(5, 5)->setValue(15); + xSheet0->getCellByPosition(1, 4)->setValue(10); + xSheet0->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<sheet::XScenariosSupplier> xScenariosSupplier(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aCRA(1); + aCRA[0] = xCRA->getRangeAddress(); + xScenariosSupplier->getScenarios()->addNewByName("ScScenario", aCRA, "Range"); + uno::Reference<container::XEnumerationAccess> xEA(xScenariosSupplier->getScenarios(), + uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_ScenariosEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_ScenariosEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_ScenariosEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_sheetcellrangesenumeration.cxx b/sc/qa/extras/scindexenumeration_sheetcellrangesenumeration.cxx new file mode 100644 index 000000000..bbd80a382 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_sheetcellrangesenumeration.cxx @@ -0,0 +1,122 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SheetCellRangesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SheetCellRangesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SheetCellRangesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_SheetCellRangesEnumeration::ScIndexEnumeration_SheetCellRangesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_SheetCellRangesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xSCR( + xMSF->createInstance("com.sun.star.sheet.SheetCellRanges"), uno::UNO_QUERY_THROW); + uno::Reference<container::XNameContainer> xNC(xSCR, uno::UNO_QUERY_THROW); + + uno::Any aRange; + + aRange <<= xSheet0->getCellRangeByName("C1:D4"); + xNC->insertByName("Range1", aRange); + aRange <<= xSheet0->getCellRangeByName("E2:F5"); + xNC->insertByName("Range2", aRange); + aRange <<= xSheet0->getCellRangeByName("G2:H3"); + xNC->insertByName("Range3", aRange); + aRange <<= xSheet0->getCellRangeByName("I7:J8"); + xNC->insertByName("Range4", aRange); + + for (auto x = 0; x < 10; ++x) + { + for (auto y = 0; y < 5; ++y) + { + xSheet0->getCellByPosition(x, y)->setFormula("a"); + } + } + for (auto x = 0; x < 10; ++x) + { + for (auto y = 5; y < 10; ++y) + { + xSheet0->getCellByPosition(x, y)->setValue(x + y); + } + } + uno::Reference<container::XEnumerationAccess> xEA(xSCR, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SheetCellRangesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_SheetCellRangesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SheetCellRangesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_sheetlinksenumeration.cxx b/sc/qa/extras/scindexenumeration_sheetlinksenumeration.cxx new file mode 100644 index 000000000..b68f540c2 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_sheetlinksenumeration.cxx @@ -0,0 +1,100 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/SheetLinkMode.hpp> +#include <com/sun/star/sheet/XSheetLinkable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SheetLinksEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SheetLinksEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SheetLinksEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_SheetLinksEnumeration::ScIndexEnumeration_SheetLinksEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_SheetLinksEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetLinkable> xSL(xSheet0, uno::UNO_QUERY_THROW); + xSL->link("ScIndexEnumeration_SheetLinksEnumeration.ods", "Sheet1", "", "", + sheet::SheetLinkMode_VALUE); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xSheetLinks; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("SheetLinks") >>= xSheetLinks); + + uno::Reference<container::XEnumerationAccess> xEA(xSheetLinks, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SheetLinksEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_SheetLinksEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SheetLinksEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_spreadsheetsenumeration.cxx b/sc/qa/extras/scindexenumeration_spreadsheetsenumeration.cxx new file mode 100644 index 000000000..5561f4fda --- /dev/null +++ b/sc/qa/extras/scindexenumeration_spreadsheetsenumeration.cxx @@ -0,0 +1,83 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SpreadsheetsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SpreadsheetsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SpreadsheetsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_SpreadsheetsEnumeration::ScIndexEnumeration_SpreadsheetsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_SpreadsheetsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xSheets, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SpreadsheetsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_SpreadsheetsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SpreadsheetsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_spreadsheetviewpanesenumeration.cxx b/sc/qa/extras/scindexenumeration_spreadsheetviewpanesenumeration.cxx new file mode 100644 index 000000000..ef4c9b052 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_spreadsheetviewpanesenumeration.cxx @@ -0,0 +1,91 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SpreadsheetViewPanesEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SpreadsheetViewPanesEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SpreadsheetViewPanesEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_SpreadsheetViewPanesEnumeration:: + ScIndexEnumeration_SpreadsheetViewPanesEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_SpreadsheetViewPanesEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<frame::XModel> xModel(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<frame::XController> xController(xModel->getCurrentController(), + uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xController, uno::UNO_QUERY_THROW); + xIA->getByIndex(0); + + uno::Reference<container::XEnumerationAccess> xEA(xIA, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SpreadsheetViewPanesEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_SpreadsheetViewPanesEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SpreadsheetViewPanesEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_subtotalfieldsenumeration.cxx b/sc/qa/extras/scindexenumeration_subtotalfieldsenumeration.cxx new file mode 100644 index 000000000..f4ca48888 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_subtotalfieldsenumeration.cxx @@ -0,0 +1,103 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/SubTotalColumn.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XSubTotalCalculatable.hpp> +#include <com/sun/star/sheet/XSubTotalDescriptor.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_SubTotalFieldsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_SubTotalFieldsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_SubTotalFieldsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_SubTotalFieldsEnumeration::ScIndexEnumeration_SubTotalFieldsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_SubTotalFieldsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSubTotalCalculatable> xSTC(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSubTotalDescriptor> xSTD(xSTC->createSubTotalDescriptor(true), + uno::UNO_SET_THROW); + + uno::Sequence<sheet::SubTotalColumn> aSubTotalColumns(1); + aSubTotalColumns[0].Column = 5; + aSubTotalColumns[0].Function = sheet::GeneralFunction_SUM; + xSTD->addNew(aSubTotalColumns, 1); + + uno::Reference<container::XIndexAccess> xIA_STD(xSTD, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xIA_STD, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_SubTotalFieldsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_SubTotalFieldsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SubTotalFieldsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_tableautoformatenumeration.cxx b/sc/qa/extras/scindexenumeration_tableautoformatenumeration.cxx new file mode 100644 index 000000000..c238e3179 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tableautoformatenumeration.cxx @@ -0,0 +1,84 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableAutoFormatEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableAutoFormatEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableAutoFormatEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_TableAutoFormatEnumeration::ScIndexEnumeration_TableAutoFormatEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TableAutoFormatEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA( + xMSF->createInstance("com.sun.star.sheet.TableAutoFormats"), uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableAutoFormatEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_TableAutoFormatEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableAutoFormatEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_tablechartsenumeration.cxx b/sc/qa/extras/scindexenumeration_tablechartsenumeration.cxx new file mode 100644 index 000000000..21bf34abc --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tablechartsenumeration.cxx @@ -0,0 +1,166 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XTableCharts.hpp> +#include <com/sun/star/table/XTableChartsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableChartsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableChartsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableChartsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_TableChartsEnumeration::ScIndexEnumeration_TableChartsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TableChartsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(1, 0)->setFormula("JAN"); + xSheet0->getCellByPosition(2, 0)->setFormula("FEB"); + xSheet0->getCellByPosition(3, 0)->setFormula("MAR"); + xSheet0->getCellByPosition(4, 0)->setFormula("APR"); + xSheet0->getCellByPosition(5, 0)->setFormula("MAY"); + xSheet0->getCellByPosition(6, 0)->setFormula("JUN"); + xSheet0->getCellByPosition(7, 0)->setFormula("JUL"); + xSheet0->getCellByPosition(8, 0)->setFormula("AUG"); + xSheet0->getCellByPosition(9, 0)->setFormula("SEP"); + xSheet0->getCellByPosition(10, 0)->setFormula("OCT"); + xSheet0->getCellByPosition(11, 0)->setFormula("NOV"); + xSheet0->getCellByPosition(12, 0)->setFormula("DEC"); + xSheet0->getCellByPosition(13, 0)->setFormula("SUM"); + + xSheet0->getCellByPosition(0, 1)->setFormula("Smith"); + xSheet0->getCellByPosition(1, 1)->setValue(42); + xSheet0->getCellByPosition(2, 1)->setValue(58.9); + xSheet0->getCellByPosition(3, 1)->setValue(-66.5); + xSheet0->getCellByPosition(4, 1)->setValue(43.4); + xSheet0->getCellByPosition(5, 1)->setValue(44.5); + xSheet0->getCellByPosition(6, 1)->setValue(45.3); + xSheet0->getCellByPosition(7, 1)->setValue(-67.3); + xSheet0->getCellByPosition(8, 1)->setValue(30.5); + xSheet0->getCellByPosition(9, 1)->setValue(23.2); + xSheet0->getCellByPosition(10, 1)->setValue(-97.3); + xSheet0->getCellByPosition(11, 1)->setValue(22.4); + xSheet0->getCellByPosition(11, 1)->setValue(23.5); + xSheet0->getCellByPosition(13, 1)->setFormula("SUM(B2:M2"); + + xSheet0->getCellByPosition(0, 2)->setFormula("Jones"); + xSheet0->getCellByPosition(1, 2)->setValue(21); + xSheet0->getCellByPosition(2, 2)->setValue(40.9); + xSheet0->getCellByPosition(3, 2)->setValue(-57.5); + xSheet0->getCellByPosition(4, 2)->setValue(-23.4); + xSheet0->getCellByPosition(5, 2)->setValue(34.5); + xSheet0->getCellByPosition(6, 2)->setValue(59.3); + xSheet0->getCellByPosition(7, 2)->setValue(27.3); + xSheet0->getCellByPosition(8, 2)->setValue(-38.5); + xSheet0->getCellByPosition(9, 2)->setValue(43.2); + xSheet0->getCellByPosition(10, 2)->setValue(57.3); + xSheet0->getCellByPosition(11, 2)->setValue(25.4); + xSheet0->getCellByPosition(11, 2)->setValue(28.5); + xSheet0->getCellByPosition(13, 2)->setFormula("SUM(B3:M3"); + + xSheet0->getCellByPosition(0, 3)->setFormula("Brown"); + xSheet0->getCellByPosition(1, 3)->setValue(31.45); + xSheet0->getCellByPosition(2, 3)->setValue(-20.9); + xSheet0->getCellByPosition(3, 3)->setValue(-117.5); + xSheet0->getCellByPosition(4, 3)->setValue(23.4); + xSheet0->getCellByPosition(5, 3)->setValue(-114.5); + xSheet0->getCellByPosition(6, 3)->setValue(115.3); + xSheet0->getCellByPosition(7, 3)->setValue(-171.3); + xSheet0->getCellByPosition(8, 3)->setValue(89.5); + xSheet0->getCellByPosition(9, 3)->setValue(41.2); + xSheet0->getCellByPosition(10, 3)->setValue(71.3); + xSheet0->getCellByPosition(11, 3)->setValue(25.4); + xSheet0->getCellByPosition(11, 3)->setValue(38.5); + xSheet0->getCellByPosition(13, 3)->setFormula("SUM(A4:L4"); + + uno::Reference<table::XCellRange> xCellRange0(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange1(xCellRange0->getCellRangeByName("A1:N4"), + uno::UNO_SET_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCellRange1, uno::UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aCRA(1); + aCRA[0] = xCRA->getRangeAddress(); + + uno::Reference<table::XTableChartsSupplier> xTCS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableCharts> xTC = xTCS->getCharts(); + xTC->addNewByName("ScChartObj", awt::Rectangle(500, 3000, 25000, 11000), aCRA, true, false); + + uno::Reference<container::XEnumerationAccess> xEA(xTC, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableChartsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_TableChartsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableChartsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_tablecolumnsenumeration.cxx b/sc/qa/extras/scindexenumeration_tablecolumnsenumeration.cxx new file mode 100644 index 000000000..10f1b129b --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tablecolumnsenumeration.cxx @@ -0,0 +1,94 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableColumns.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableColumnsEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableColumnsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableColumnsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_TableColumnsEnumeration::ScIndexEnumeration_TableColumnsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TableColumnsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xNA->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + uno::Reference<table::XColumnRowRange> xColumnRowRange(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableColumns> xTableColumns(xColumnRowRange->getColumns(), + uno::UNO_SET_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xTableColumns, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableColumnsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_TableColumnsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableColumnsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_tableconditionalentryenumeration.cxx b/sc/qa/extras/scindexenumeration_tableconditionalentryenumeration.cxx new file mode 100644 index 000000000..fd8cd5d8e --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tableconditionalentryenumeration.cxx @@ -0,0 +1,121 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/ConditionOperator.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableConditionalEntryEnumeration : public CalcUnoApiTest, + public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableConditionalEntryEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableConditionalEntryEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_TableConditionalEntryEnumeration:: + ScIndexEnumeration_TableConditionalEntryEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TableConditionalEntryEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet0->getCellByPosition(5, 5)->setValue(15); + xSheet0->getCellByPosition(1, 4)->setValue(10); + xSheet0->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Sequence<beans::PropertyValue> aConditions(5); + aConditions[0].Name = "StyleName"; + aConditions[0].Value <<= OUString("Result2"); + aConditions[1].Name = "Formula1"; + aConditions[1].Value <<= OUString("$Sheet1.$B$5"); + aConditions[2].Name = "Formula2"; + aConditions[2].Value <<= OUString(""); + aConditions[3].Name = "Operator"; + aConditions[3].Value <<= sheet::ConditionOperator_EQUAL; + aConditions[4].Name = "SoucePosition"; + aConditions[4].Value <<= table::CellAddress(0, 1, 5); + + uno::Reference<beans::XPropertySet> xPropertySet(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntries> xSCE( + xPropertySet->getPropertyValue("ConditionalFormat"), uno::UNO_QUERY_THROW); + xSCE->addNew(aConditions); + + uno::Any aProperty; + aProperty <<= xSCE; + xPropertySet->setPropertyValue("ConditionalFormat", aProperty); + + uno::Reference<container::XEnumerationAccess> xEA(xSCE, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableConditionalEntryEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_TableConditionalEntryEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableConditionalEntryEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_tablerowsenumeration.cxx b/sc/qa/extras/scindexenumeration_tablerowsenumeration.cxx new file mode 100644 index 000000000..7a1068a33 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_tablerowsenumeration.cxx @@ -0,0 +1,96 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TableRowsEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TableRowsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableRowsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_TableRowsEnumeration::ScIndexEnumeration_TableRowsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TableRowsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xNA->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + // limit the range the XEnumeration has to walk over (see fdo#45337). + uno::Reference<table::XCellRange> xCR(xSheet0->getCellRangeByName("A1:A4"), uno::UNO_SET_THROW); + + uno::Reference<table::XColumnRowRange> xColRowRange(xCR, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableRows> xTableRows(xColRowRange->getRows(), uno::UNO_SET_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xTableRows, uno::UNO_QUERY_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TableRowsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_TableRowsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableRowsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scindexenumeration_textfieldenumeration.cxx b/sc/qa/extras/scindexenumeration_textfieldenumeration.cxx new file mode 100644 index 000000000..6270ca089 --- /dev/null +++ b/sc/qa/extras/scindexenumeration_textfieldenumeration.cxx @@ -0,0 +1,102 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScIndexEnumeration_TextFieldEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScIndexEnumeration_TextFieldEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScIndexEnumeration_TextFieldEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScIndexEnumeration_TextFieldEnumeration::ScIndexEnumeration_TextFieldEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScIndexEnumeration_TextFieldEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextField> xTF(xMSF->createInstance("com.sun.star.text.TextField.URL"), + uno::UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xTC(xTF, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCell> xCell(xSheet0->getCellByPosition(2, 3), uno::UNO_SET_THROW); + uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW); + xText->insertTextContent(xText->createTextCursor(), xTC, true); + uno::Reference<text::XTextFieldsSupplier> xTFS(xCell, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xTFS->getTextFields(), uno::UNO_SET_THROW); + + return xEA->createEnumeration(); +} + +void ScIndexEnumeration_TextFieldEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScIndexEnumeration_TextFieldEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TextFieldEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sclabelrangeobj.cxx b/sc/qa/extras/sclabelrangeobj.cxx new file mode 100644 index 000000000..15b7ee494 --- /dev/null +++ b/sc/qa/extras/sclabelrangeobj.cxx @@ -0,0 +1,91 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/xlabelrange.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XLabelRange.hpp> +#include <com/sun/star/sheet/XLabelRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScLabelRangeObj : public CalcUnoApiTest, public apitest::XLabelRange +{ +public: + ScLabelRangeObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScLabelRangeObj); + + // XLabelRange + CPPUNIT_TEST(testGetSetDataArea); + CPPUNIT_TEST(testGetSetLabelArea); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScLabelRangeObj::ScLabelRangeObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScLabelRangeObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xProp(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XLabelRanges> xLabelRanges(xProp->getPropertyValue("ColumnLabelRanges"), + uno::UNO_QUERY_THROW); + + table::CellRangeAddress aCellRanageAddr1(0, 0, 1, 0, 6); + table::CellRangeAddress aCellRanageAddr2(0, 0, 0, 0, 1); + xLabelRanges->addNew(aCellRanageAddr1, aCellRanageAddr2); + + uno::Reference<sheet::XLabelRange> xLabelRange(xLabelRanges->getByIndex(0), + uno::UNO_QUERY_THROW); + return xLabelRange; +} + +void ScLabelRangeObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScLabelRangeObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScLabelRangeObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sclabelrangesobj.cxx b/sc/qa/extras/sclabelrangesobj.cxx new file mode 100644 index 000000000..9f720eeaa --- /dev/null +++ b/sc/qa/extras/sclabelrangesobj.cxx @@ -0,0 +1,111 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/sheet/xlabelranges.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XLabelRange.hpp> +#include <com/sun/star/sheet/XLabelRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScLabelRangesObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XLabelRanges +{ +public: + ScLabelRangesObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScLabelRangesObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XLabelRanges + CPPUNIT_TEST(testAddNew); + CPPUNIT_TEST(testRemoveByIndex); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScLabelRangesObj::ScLabelRangesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XLabelRange>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference<uno::XInterface> ScLabelRangesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xProp(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XLabelRanges> xLabelRanges(xProp->getPropertyValue("ColumnLabelRanges"), + uno::UNO_QUERY_THROW); + + table::CellRangeAddress aCellRanageAddr1(0, 0, 1, 0, 6); + table::CellRangeAddress aCellRanageAddr2(0, 0, 0, 0, 1); + xLabelRanges->addNew(aCellRanageAddr1, aCellRanageAddr2); + + return xLabelRanges; +} + +void ScLabelRangesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScLabelRangesObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScLabelRangesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scmodelobj.cxx b/sc/qa/extras/scmodelobj.cxx new file mode 100644 index 000000000..48b050b11 --- /dev/null +++ b/sc/qa/extras/scmodelobj.cxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/unoapi_test.hxx> +#include <test/document/xlinktargetsupplier.hxx> +#include <test/sheet/spreadsheetdocumentsettings.hxx> +#include <test/sheet/xcalculatable.hxx> +#include <test/sheet/xconsolidatable.hxx> +#include <test/sheet/xdocumentauditing.hxx> +#include <test/sheet/xgoalseek.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScModelObj : public UnoApiTest, + public apitest::SpreadsheetDocumentSettings, + public apitest::XCalculatable, + public apitest::XConsolidatable, + public apitest::XDocumentAuditing, + public apitest::XGoalSeek, + public apitest::XLinkTargetSupplier +{ +public: + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< uno::XInterface > getXMSF() override; + virtual uno::Sequence<uno::Reference<table::XCell>> getXCells() override; + + ScModelObj(); + + CPPUNIT_TEST_SUITE(ScModelObj); + + // SpreadsheetDocumentSettings + CPPUNIT_TEST(testSpreadsheetDocumentSettingsProperties); + + // XCalculatable + CPPUNIT_TEST(testCalculate); + CPPUNIT_TEST(testCalculateAll); + CPPUNIT_TEST(testEnableAutomaticCalculation); + + // XConsolidatable + CPPUNIT_TEST(testCreateConsolidationDescriptor); + CPPUNIT_TEST(testConsolidate); + + // XDocumentAuditing + CPPUNIT_TEST(testRefreshArrows); + + // XGoalSeek + CPPUNIT_TEST(testSeekGoal); + + // XLinkTargetSupplier + CPPUNIT_TEST(testGetLinks); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference< lang::XComponent > mxComponent; + uno::Sequence<uno::Reference<table::XCell>> m_xCells; +}; + +ScModelObj::ScModelObj() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference< uno::XInterface > ScModelObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<frame::XModel> xModel(xDoc, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + + m_xCells.realloc(3); + m_xCells[0] = xSheet->getCellByPosition(4, 5); + m_xCells[0]->setValue(15); + m_xCells[1] = xSheet->getCellByPosition(5, 5); + m_xCells[1]->setValue(10); + m_xCells[2] = xSheet->getCellByPosition(6, 5); + m_xCells[2]->setFormula("= E6 * F6"); + + return xModel; +} + +uno::Reference<uno::XInterface> ScModelObj::getXMSF() +{ + return getMultiServiceFactory(); +} + +uno::Sequence<uno::Reference<table::XCell>> ScModelObj::getXCells() +{ + return m_xCells; +} + +void ScModelObj::setUp() +{ + UnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL("ScModelObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScModelObj::tearDown() +{ + closeDocument(mxComponent); + UnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScModelObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scnamedrangeobj.cxx b/sc/qa/extras/scnamedrangeobj.cxx new file mode 100644 index 000000000..710b40bb2 --- /dev/null +++ b/sc/qa/extras/scnamedrangeobj.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/sheet/xnamedrange.hxx> +#include <test/sheet/xcellrangereferrer.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScNamedRangeObj : public CalcUnoApiTest, + public apitest::XCellRangeReferrer, + public apitest::XNamed, + public apitest::XNamedRange +{ +public: + ScNamedRangeObj(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< sheet::XNamedRange > getNamedRange(const OUString& rRangeName) override; + + CPPUNIT_TEST_SUITE(ScNamedRangeObj); + + // XCellRangeReferrer + CPPUNIT_TEST(testGetReferredCells); + + // XNamed + CPPUNIT_TEST(testSetName); + CPPUNIT_TEST(testGetName); + + // XNamedRange + CPPUNIT_TEST(testGetContent); + CPPUNIT_TEST(testSetContent); + CPPUNIT_TEST(testGetType); + CPPUNIT_TEST(testSetType); + CPPUNIT_TEST(testGetReferencePosition); + CPPUNIT_TEST(testSetReferencePosition); + + CPPUNIT_TEST_SUITE_END(); +private: + uno::Reference< sheet::XNamedRanges > init_impl(); + uno::Reference< lang::XComponent > mxComponent; +}; + +ScNamedRangeObj::ScNamedRangeObj(): + CalcUnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XNamed("NamedRange") +{ +} + +uno::Reference< sheet::XNamedRanges > ScNamedRangeObj::init_impl() +{ + CPPUNIT_ASSERT_MESSAGE("no component loaded", mxComponent.is()); + + uno::Reference< beans::XPropertySet > xPropSet (mxComponent, UNO_QUERY_THROW); + uno::Reference< sheet::XNamedRanges > xNamedRanges(xPropSet->getPropertyValue("NamedRanges"), UNO_QUERY_THROW); + CPPUNIT_ASSERT(xNamedRanges.is()); + + setCellRange(table::CellRangeAddress(0, 1, 7, 1, 7)); + + return xNamedRanges; +} + +uno::Reference< sheet::XNamedRange> ScNamedRangeObj::getNamedRange(const OUString& rRangeName) +{ + uno::Reference< container::XNameAccess > xNamedAccess(init_impl(), UNO_QUERY_THROW); + uno::Reference< sheet::XNamedRange > xNamedRange(xNamedAccess->getByName(rRangeName), UNO_QUERY_THROW); + CPPUNIT_ASSERT(xNamedRange.is()); + + return xNamedRange; +} + +uno::Reference< uno::XInterface > ScNamedRangeObj::init() +{ + return getNamedRange("NamedRange"); +} + +void ScNamedRangeObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL("ScNamedRangeObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScNamedRangeObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScNamedRangeObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scnamedrangesobj.cxx b/sc/qa/extras/scnamedrangesobj.cxx new file mode 100644 index 000000000..1b61fa098 --- /dev/null +++ b/sc/qa/extras/scnamedrangesobj.cxx @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/document/xactionlockable.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xnamedranges.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XNamedRange.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScNamedRangesObj : public CalcUnoApiTest, + public apitest::XActionLockable, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNamedRanges, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScNamedRangesObj(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXNamedRanges(sal_Int32 nSheet = 0) override; + + CPPUNIT_TEST_SUITE(ScNamedRangesObj); + + // XActionLockable + CPPUNIT_TEST(testAddRemoveActionLock); + CPPUNIT_TEST(testSetResetActionLock); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNamedRanges + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNamedRanges + CPPUNIT_TEST(testAddNewByName); + CPPUNIT_TEST(testAddNewFromTitles); + //CPPUNIT_TEST_EXCEPTION(testRemoveByName, uno::RuntimeException); + CPPUNIT_TEST(testOutputList); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScNamedRangesObj::ScNamedRangesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XNamedRange>::get()) + , XIndexAccess(4) + , XNameAccess("initial1") + , XServiceInfo("ScNamedRangesObj", "com.sun.star.sheet.NamedRanges") +{ +} + +uno::Reference<uno::XInterface> ScNamedRangesObj::init() +{ + uno::Reference<beans::XPropertySet> xPropSet(mxComponent, UNO_QUERY_THROW); + uno::Reference<sheet::XNamedRanges> xNamedRanges(xPropSet->getPropertyValue("NamedRanges"), + UNO_QUERY_THROW); + + //set value from xnamedranges.hxx + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW); + xSheet.set(xIndexAccess->getByIndex(0), UNO_QUERY_THROW); + + return xNamedRanges; +} + +uno::Reference<uno::XInterface> ScNamedRangesObj::getXNamedRanges(sal_Int32 nSheet) +{ + uno::Reference<beans::XPropertySet> xPropSet(mxComponent, UNO_QUERY_THROW); + uno::Reference<sheet::XNamedRanges> xNamedRanges(xPropSet->getPropertyValue("NamedRanges"), + UNO_QUERY_THROW); + + //set value from xnamedranges.hxx + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW); + xSheet.set(xIndexAccess->getByIndex(nSheet), UNO_QUERY_THROW); + + return xNamedRanges; +} + +void ScNamedRangesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL("ScNamedRangeObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScNamedRangesObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScNamedRangesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scoutlineobj.cxx b/sc/qa/extras/scoutlineobj.cxx new file mode 100644 index 000000000..fba63ff98 --- /dev/null +++ b/sc/qa/extras/scoutlineobj.cxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/xsheetoutline.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest { + +class ScOutlineObj : public CalcUnoApiTest, public apitest::XSheetOutline +{ +public: + ScOutlineObj(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference< uno::XInterface > init() override; + + CPPUNIT_TEST_SUITE(ScOutlineObj); + + // XSheetOutline + CPPUNIT_TEST(testHideDetail); + CPPUNIT_TEST(testShowDetail); + CPPUNIT_TEST(testShowLevel); + CPPUNIT_TEST(testUngroup); + CPPUNIT_TEST(testGroup); + //CPPUNIT_TEST(testAutoOutline); + CPPUNIT_TEST(testClearOutline); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference< lang::XComponent > mxComponent; +}; + +ScOutlineObj::ScOutlineObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference< uno::XInterface > ScOutlineObj::init() +{ + // get the first sheet + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW); + + return xSheet; +} + +void ScOutlineObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL("ScOutlineObj.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL); +} + +void ScOutlineObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScOutlineObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/scpdfexport.cxx b/sc/qa/extras/scpdfexport.cxx new file mode 100644 index 000000000..070721dcd --- /dev/null +++ b/sc/qa/extras/scpdfexport.cxx @@ -0,0 +1,364 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <sal/config.h> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <test/bootstrapfixture.hxx> +#include <unotools/tempfile.hxx> +#include <unotest/macros_test.hxx> +#include <docsh.hxx> +#include <editutil.hxx> +#include <editeng/eeitem.hxx> +#include <editeng/fontitem.hxx> +#include <osl/file.hxx> +#include <comphelper/processfactory.hxx> + +using namespace css::lang; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +class ScPDFExportTest : public test::BootstrapFixture, public unotest::MacrosTest +{ + Reference<XComponent> mxComponent; + Reference<frame::XFrame> xTargetFrame; + +public: + ScPDFExportTest() {} + + virtual void setUp() override final; + virtual void tearDown() override final; + + // helpers +private: + std::shared_ptr<utl::TempFile> exportToPDF(const uno::Reference<frame::XModel>& xModel, + const ScRange& range); + + static bool hasTextInPdf(const std::shared_ptr<utl::TempFile>& pPDFFile, const char* sText, + bool& bFound); + + void setFont(ScFieldEditEngine& rEE, sal_Int32 nStart, sal_Int32 nEnd, + const OUString& rFontName); + + // unit tests +public: + void testExportRange_Tdf120161(); + void testExportFitToPage_Tdf103516(); + + CPPUNIT_TEST_SUITE(ScPDFExportTest); + CPPUNIT_TEST(testExportRange_Tdf120161); + CPPUNIT_TEST(testExportFitToPage_Tdf103516); + CPPUNIT_TEST_SUITE_END(); +}; + +void ScPDFExportTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set( + css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); + + { + uno::Reference<frame::XDesktop2> xDesktop = mxDesktop; + CPPUNIT_ASSERT(xDesktop.is()); + + // Create spreadsheet + uno::Sequence<beans::PropertyValue> args(1); + args[0].Name = "Hidden"; + args[0].Value <<= true; + mxComponent = xDesktop->loadComponentFromURL("private:factory/scalc", "_blank", 0, args); + CPPUNIT_ASSERT(mxComponent.is()); + + // create a frame + xTargetFrame = xDesktop->findFrame("_blank", 0); + CPPUNIT_ASSERT(xTargetFrame.is()); + + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<frame::XModel2> xModel2(xModel, UNO_QUERY); + CPPUNIT_ASSERT(xModel2.is()); + + Reference<frame::XController2> xController + = xModel2->createDefaultViewController(xTargetFrame); + CPPUNIT_ASSERT(xController.is()); + + // introduce model/view/controller to each other + xController->attachModel(xModel2.get()); + xModel2->connectController(xController.get()); + + xTargetFrame->setComponent(xController->getComponentWindow(), xController.get()); + xController->attachFrame(xTargetFrame); + + xModel2->setCurrentController(xController.get()); + } +} + +void ScPDFExportTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +bool ScPDFExportTest::hasTextInPdf(const std::shared_ptr<utl::TempFile>& pPDFFile, + const char* sText, bool& bFound) +{ + SvStream* pStream = pPDFFile->GetStream(StreamMode::STD_READ); + CPPUNIT_ASSERT(pStream); + + // get file size + pStream->Seek(STREAM_SEEK_TO_END); + const std::size_t nFileSize = pStream->Tell(); + if (nFileSize == 0) + return false; + + // read file content + char* pBuffer = new char[nFileSize]; + pStream->Seek(STREAM_SEEK_TO_BEGIN); + const std::size_t nRead = pStream->ReadBytes(pBuffer, nFileSize); + if (nRead == nFileSize) + { + const std::string haystack(pBuffer, pBuffer + nFileSize); + const std::string needle(sText); + const std::size_t n = haystack.find(needle); + bFound = (n != std::string::npos); + } + delete[] pBuffer; + + // close and return the status + pStream = nullptr; + pPDFFile->CloseStream(); + return (nRead == nFileSize); +} + +std::shared_ptr<utl::TempFile> +ScPDFExportTest::exportToPDF(const uno::Reference<frame::XModel>& xModel, const ScRange& range) +{ + // create temp file name + auto pTempFile = std::make_shared<utl::TempFile>(); + pTempFile->EnableKillingFile(); + OUString sFileURL = pTempFile->GetURL(); + // Note: under Windows path path should be with "/" delimiters instead of "\\" + // due to usage of INetURLObject() that converts "\\" to hexadecimal notation. + ::osl::FileBase::getFileURLFromSystemPath(sFileURL, sFileURL); + + // get XSpreadsheet + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> rSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + // select requested cells to print + // query for the XCellRange interface + uno::Reference<table::XCellRange> xCellRange = rSheet->getCellRangeByPosition( + range.aStart.Col(), range.aStart.Row(), range.aEnd.Col(), range.aEnd.Row()); + { + uno::Reference<frame::XController> xController = xModel->getCurrentController(); + CPPUNIT_ASSERT(xController.is()); + + uno::Reference<view::XSelectionSupplier> xSelection(xController, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xSelection.is()); + + uno::Any rCellRangeAny(xCellRange); + xSelection->select(rCellRangeAny); + } + + // init special pdf export params + css::uno::Sequence<css::beans::PropertyValue> aFilterData(3); + aFilterData[0].Name = "Selection"; + aFilterData[0].Value <<= xCellRange; + aFilterData[1].Name = "Printing"; + aFilterData[1].Value <<= sal_Int32(2); + aFilterData[2].Name = "ViewPDFAfterExport"; + aFilterData[2].Value <<= true; + + // init set of params for storeToURL() call + css::uno::Sequence<css::beans::PropertyValue> seqArguments(3); + seqArguments[0].Name = "FilterData"; + seqArguments[0].Value <<= aFilterData; + seqArguments[1].Name = "FilterName"; + seqArguments[1].Value <<= OUString("calc_pdf_Export"); + seqArguments[2].Name = "URL"; + seqArguments[2].Value <<= sFileURL; + + // call storeToURL() + uno::Reference<lang::XComponent> xComponent(mxComponent, UNO_SET_THROW); + uno::Reference<css::frame::XStorable> xStorable(xComponent, UNO_QUERY); + xStorable->storeToURL(sFileURL, seqArguments); + + // return file object with generated PDF + return pTempFile; +} + +void ScPDFExportTest::setFont(ScFieldEditEngine& rEE, sal_Int32 nStart, sal_Int32 nEnd, + const OUString& rFontName) +{ + ESelection aSel; + aSel.nStartPara = aSel.nEndPara = 0; + aSel.nStartPos = nStart; + aSel.nEndPos = nEnd; + + SfxItemSet aItemSet = rEE.GetEmptyItemSet(); + SvxFontItem aItem(FAMILY_MODERN, rFontName, "", PITCH_VARIABLE, RTL_TEXTENCODING_UTF8, + EE_CHAR_FONTINFO); + aItemSet.Put(aItem); + rEE.QuickSetAttribs(aItemSet, aSel); +} + +// Selection was not taken into account during export into PDF +void ScPDFExportTest::testExportRange_Tdf120161() +{ + // create test document + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("First Sheet", 0); + uno::Reference<sheet::XSpreadsheet> rSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + // 2. Setup data + { + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(xDocSh.get() != nullptr); + + // put some content into the first row with default font + ScDocument& rDoc = xDocSh->GetDocument(); + for (unsigned int r = 0; r < 1; ++r) + for (unsigned int c = 0; c < 14; ++c) + rDoc.SetValue(ScAddress(c, r, 0), (r + 1) * (c + 1)); + + // set "Text" to H1 cell with "DejaVuSans" font + ScFieldEditEngine& rEE = rDoc.GetEditEngine(); + rEE.Clear(); + rEE.SetTextCurrentDefaults("Text"); + setFont(rEE, 0, 4, "DejaVuSans"); // set font for first 4 chars + rDoc.SetEditText(ScAddress(7, 0, 0), rEE.CreateTextObject()); + } + + // A1:G1 + { + ScRange range1(0, 0, 0, 6, 0, 0); + std::shared_ptr<utl::TempFile> pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(false, bFound); + } + + // G1:H1 + { + ScRange range1(6, 0, 0, 7, 0, 0); + std::shared_ptr<utl::TempFile> pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // H1:I1 + { + ScRange range1(7, 0, 0, 8, 0, 0); + std::shared_ptr<utl::TempFile> pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } +} + +void ScPDFExportTest::testExportFitToPage_Tdf103516() +{ + // create test document + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex(xSheets, uno::UNO_QUERY_THROW); + xSheets->insertNewByName("First Sheet", 0); + uno::Reference<sheet::XSpreadsheet> rSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + // 2. Setup data + { + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(xDocSh.get() != nullptr); + + // put some content into the table + ScDocument& rDoc = xDocSh->GetDocument(); + for (unsigned int r = 0; r < 80; ++r) + for (unsigned int c = 0; c < 12; ++c) + rDoc.SetValue(ScAddress(c, r, 0), (r + 1) * (c + 1)); + } + + // A1:G50: 2-page export + { + ScRange range1(0, 0, 0, 6, 49, 0); + std::shared_ptr<utl::TempFile> pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 2>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // A1:L80: 4-page export + { + ScRange range1(0, 0, 0, 11, 79, 0); + std::shared_ptr<utl::TempFile> pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 4>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // set fit to page: width=1 page, height=0 (automatic) + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamSupp(xDoc, UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xStyleFamiliesNames(xStyleFamSupp->getStyleFamilies(), + UNO_SET_THROW); + uno::Reference<container::XNameAccess> xPageStyles(xStyleFamiliesNames->getByName("PageStyles"), + UNO_QUERY_THROW); + uno::Any aDefaultStyle = xPageStyles->getByName("Default"); + uno::Reference<beans::XPropertySet> xProp(aDefaultStyle, UNO_QUERY_THROW); + + uno::Any aScaleX, aScaleY; + sal_Int16 nScale; + aScaleX <<= static_cast<sal_Int16>(1); + xProp->setPropertyValue("ScaleToPagesX", aScaleX); + aScaleX = xProp->getPropertyValue("ScaleToPagesX"); + aScaleX >>= nScale; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nScale); + + aScaleY = xProp->getPropertyValue("ScaleToPagesY"); + aScaleY >>= nScale; + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nScale); + + // A1:G50 with fit to page width=1: slightly smaller zoom results only 1-page export + { + ScRange range1(0, 0, 0, 6, 49, 0); + std::shared_ptr<utl::TempFile> pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 1>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } + + // A1:L80 with fit to page width=1: slightly smaller zoom results only 1-page export + { + ScRange range1(0, 0, 0, 11, 79, 0); + std::shared_ptr<utl::TempFile> pPDFFile = exportToPDF(xModel, range1); + bool bFound = false; + CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 1>>", bFound)); + CPPUNIT_ASSERT_EQUAL(true, bFound); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScPDFExportTest); +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/screcentfunctionsobj.cxx b/sc/qa/extras/screcentfunctionsobj.cxx new file mode 100644 index 000000000..84fdc3857 --- /dev/null +++ b/sc/qa/extras/screcentfunctionsobj.cxx @@ -0,0 +1,79 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/xrecentfunctions.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScRecentFunctionsObj : public CalcUnoApiTest, public apitest::XRecentFunctions +{ +public: + ScRecentFunctionsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScRecentFunctionsObj); + + // XRecentFunctions + CPPUNIT_TEST(testGetRecentFunctionIds); + CPPUNIT_TEST(testSetRecentFunctionIds); + CPPUNIT_TEST(testGetMaxRecentFunctions); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScRecentFunctionsObj::ScRecentFunctionsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScRecentFunctionsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.RecentFunctions"); +} + +void ScRecentFunctionsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScRecentFunctionsObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScRecentFunctionsObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scscenariosobj.cxx b/sc/qa/extras/scscenariosobj.cxx new file mode 100644 index 000000000..78e94ae38 --- /dev/null +++ b/sc/qa/extras/scscenariosobj.cxx @@ -0,0 +1,140 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xscenarios.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XScenario.hpp> +#include <com/sun/star/sheet/XScenariosSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <cppu/unotype.hxx> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScScenariosObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XNameAccess, + public apitest::XIndexAccess, + public apitest::XScenarios, + public apitest::XServiceInfo +{ +public: + ScScenariosObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScScenariosObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XScenarios + CPPUNIT_TEST(testAddNewByName); + CPPUNIT_TEST(testRemoveByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScScenariosObj::ScScenariosObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XScenario>::get()) + , XNameAccess("ScScenarios") + , XIndexAccess(1) + , XServiceInfo("ScScenariosObj", "com.sun.star.sheet.Scenarios") +{ +} + +uno::Reference<uno::XInterface> ScScenariosObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 5)->setValue(15); + xSheet->getCellByPosition(1, 4)->setValue(10); + xSheet->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<table::XCellRange> xCellRange(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange2 = xCellRange->getCellRangeByName("A1:N4"); + uno::Reference<sheet::XCellRangeAddressable> xCRAddressable(xCellRange2, uno::UNO_QUERY_THROW); + table::CellRangeAddress aCellRangeAddr = xCRAddressable->getRangeAddress(); + + uno::Sequence<table::CellRangeAddress> aCellRangeAddresses(1); + aCellRangeAddresses[0] = aCellRangeAddr; + uno::Reference<sheet::XScenariosSupplier> xSupplier(xSheet, uno::UNO_QUERY_THROW); + xSupplier->getScenarios()->addNewByName("ScScenarios", aCellRangeAddresses, "Range"); + + return xSupplier->getScenarios(); +} + +void ScScenariosObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScScenariosObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScScenariosObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scshapeobj.cxx b/sc/qa/extras/scshapeobj.cxx new file mode 100644 index 000000000..ef8761a65 --- /dev/null +++ b/sc/qa/extras/scshapeobj.cxx @@ -0,0 +1,135 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/drawing/xgluepointssupplier.hxx> +#include <test/drawing/xshape.hxx> +#include <test/drawing/xshapedescriptor.hxx> +#include <test/lang/xcomponent.hxx> +#include <test/sheet/shape.hxx> + +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScShapeObj : public CalcUnoApiTest, + public apitest::Shape, + public apitest::XComponent, + public apitest::XGluePointsSupplier, + public apitest::XShape, + public apitest::XShapeDescriptor +{ +public: + ScShapeObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXSheetDocument() override; + virtual void triggerDesktopTerminate() override{}; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScShapeObj); + + // Shape + CPPUNIT_TEST(testShapePropertiesAnchor); + CPPUNIT_TEST(testShapePropertiesPosition); + + // XComponent + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testDispose); + CPPUNIT_TEST(testRemoveEventListener); + + // XGluePointsSupplier + CPPUNIT_TEST(testGetGluePoints); + + // XShape + CPPUNIT_TEST(testGetSetPosition); + CPPUNIT_TEST(testGetSetSize); + + // XShapeDescriptor + CPPUNIT_TEST(testGetShapeType); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScShapeObj::ScShapeObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XShapeDescriptor("com.sun.star.drawing.RectangleShape") +{ +} + +uno::Reference<uno::XInterface> ScShapeObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape( + xMSF->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY_THROW); + xShape->setPosition(awt::Point(5000, 3500)); + xShape->setSize(awt::Size(7500, 5000)); + + uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPages> xDrawPages = xDPS->getDrawPages(); + uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShapes> xShapes(xDrawPage, uno::UNO_QUERY_THROW); + xShapes->add(xShape); + + for (auto i = 0; i < 10; i++) + { + xShape->setPosition(awt::Point(5000, 3500)); + xShape->setSize(awt::Size(7510 + 10 * i, 5010 + 10 * i)); + xShapes->add(xShape); + } + + return xShape; +} + +uno::Reference<uno::XInterface> ScShapeObj::getXSheetDocument() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + return xDoc; +} + +void ScShapeObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScShapeObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScShapeObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scsheetlinkobj.cxx b/sc/qa/extras/scsheetlinkobj.cxx new file mode 100644 index 000000000..7b248c0a9 --- /dev/null +++ b/sc/qa/extras/scsheetlinkobj.cxx @@ -0,0 +1,111 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xnamed.hxx> +#include <test/sheet/sheetlink.hxx> +#include <test/util/xrefreshable.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/SheetLinkMode.hpp> +#include <com/sun/star/sheet/XSheetLinkable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScSheetLinkObj : public CalcUnoApiTest, + public apitest::SheetLink, + public apitest::XNamed, + public apitest::XRefreshable +{ +public: + ScSheetLinkObj(); + + virtual uno::Reference<uno::XInterface> init() override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScSheetLinkObj); + + // SheetLink + CPPUNIT_TEST(testSheetLinkProperties); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetNameByScSheetLinkObj); + + // XRefreshable + CPPUNIT_TEST(testRefreshListener); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScSheetLinkObj::ScSheetLinkObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed(m_directories.getURLFromSrc("/sc/qa/extras/testdocuments/ScSheetLinkObj.ods")) +{ +} + +uno::Reference<uno::XInterface> ScSheetLinkObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetLinkable> xSL(xSheet, uno::UNO_QUERY_THROW); + xSL->link(m_directories.getURLFromSrc("/sc/qa/extras/testdocuments/ScSheetLinkObj.ods"), + "Sheet1", "", "", sheet::SheetLinkMode_VALUE); + + uno::Reference<beans::XPropertySet> xPropSet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> sheetLinks; + CPPUNIT_ASSERT(xPropSet->getPropertyValue("SheetLinks") >>= sheetLinks); + CPPUNIT_ASSERT(sheetLinks.is()); + + uno::Any aAny = sheetLinks->getByName(sheetLinks->getElementNames()[0]); + uno::Reference<beans::XPropertySet> sheetLink; + aAny >>= sheetLink; + return sheetLink; +} + +void ScSheetLinkObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSheetLinkObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSheetLinkObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scsheetlinksobj.cxx b/sc/qa/extras/scsheetlinksobj.cxx new file mode 100644 index 000000000..39c45477b --- /dev/null +++ b/sc/qa/extras/scsheetlinksobj.cxx @@ -0,0 +1,125 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> + +#include <cppu/unotype.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/SheetLinkMode.hpp> +#include <com/sun/star/sheet/XSheetLinkable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScSheetLinksObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo +{ +public: + ScSheetLinksObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScSheetLinksObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScSheetLinksObj::ScSheetLinksObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<beans::XPropertySet>::get()) + , XIndexAccess(1) + , XNameAccess(m_directories.getURLFromSrc("/sc/qa/extras/testdocuments/ScSheetLinksObj.ods")) + , XServiceInfo("ScSheetLinksObj", "com.sun.star.sheet.SheetLinks") +{ +} + +uno::Reference<uno::XInterface> ScSheetLinksObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetLinkable> xSL(xSheet0, uno::UNO_QUERY_THROW); + OUString aFileURL; + createFileURL("ScSheetLinksObj.ods", aFileURL); + xSL->link(aFileURL, "Sheet1", "", "", sheet::SheetLinkMode_VALUE); + + uno::Reference<beans::XPropertySet> xPropertySet(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("SheetLinks") >>= xNA); + + return xNA; +} + +void ScSheetLinksObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSheetLinksObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSheetLinksObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scsortdescriptorbaseobj.cxx b/sc/qa/extras/scsortdescriptorbaseobj.cxx new file mode 100644 index 000000000..439e906fa --- /dev/null +++ b/sc/qa/extras/scsortdescriptorbaseobj.cxx @@ -0,0 +1,84 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/sheetsortdescriptor2.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/util/XSortable.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScSortDescriptorBaseObj : public CalcUnoApiTest, public apitest::SheetSortDescriptor2 +{ +public: + ScSortDescriptorBaseObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScSortDescriptorBaseObj); + + // SheetSortDescriptor2 + CPPUNIT_TEST(testSheetSortDescriptor2Properties); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScSortDescriptorBaseObj::ScSortDescriptorBaseObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScSortDescriptorBaseObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference<util::XSortable> xSortable(xSheet, UNO_QUERY_THROW); + return xSortable; +} + +void ScSortDescriptorBaseObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSortDescriptorBaseObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSortDescriptorBaseObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scspreadsheetsettings.cxx b/sc/qa/extras/scspreadsheetsettings.cxx new file mode 100644 index 000000000..a06d65cd5 --- /dev/null +++ b/sc/qa/extras/scspreadsheetsettings.cxx @@ -0,0 +1,97 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/globalsheetsettings.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScSpreadsheetSettings : public CalcUnoApiTest, + public apitest::GlobalSheetSettings, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScSpreadsheetSettings(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScSpreadsheetSettings); + + // GlobalSheetSettings + CPPUNIT_TEST(testGlobalSheetSettingsProperties); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScSpreadsheetSettings::ScSpreadsheetSettings() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ "LinkUpdateMode", "UsePrinterMetrics", "UserLists" }) + , XServiceInfo("stardiv.StarCalc.ScSpreadsheetSettings", + "com.sun.star.sheet.GlobalSheetSettings") +{ +} + +uno::Reference<uno::XInterface> ScSpreadsheetSettings::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + return xMSF->createInstance("com.sun.star.sheet.GlobalSheetSettings"); +} + +void ScSpreadsheetSettings::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSpreadsheetSettings::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSpreadsheetSettings); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scspreadsheetsettingsobj.cxx b/sc/qa/extras/scspreadsheetsettingsobj.cxx new file mode 100644 index 000000000..faf0b5605 --- /dev/null +++ b/sc/qa/extras/scspreadsheetsettingsobj.cxx @@ -0,0 +1,98 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/sheet/spreadsheetdocumentsettings.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScSpreadsheetSettingsObj : public CalcUnoApiTest, + public apitest::SpreadsheetDocumentSettings, + public apitest::XPropertySet +{ +public: + ScSpreadsheetSettingsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScSpreadsheetSettingsObj); + + // SpreadsheetDocumentSettings + CPPUNIT_TEST(testSpreadsheetDocumentSettingsProperties); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScSpreadsheetSettingsObj::ScSpreadsheetSettingsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ + "AreaLinks", + "CharLocale", + "CharLocaleAsian", + "CharLocaleComplex", + "ColumnLabelRanges", + "DDELinks", + "DatabaseRanges", + "ExternalDocLinks", + "InteropGrabBag", + "NamedRanges", + "NullDate", + "RowLabelRanges", + "SheetLinks", + }) +{ +} + +uno::Reference<uno::XInterface> ScSpreadsheetSettingsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + return xDoc; +} + +void ScSpreadsheetSettingsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSpreadsheetSettingsObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSpreadsheetSettingsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scstylefamiliesobj.cxx b/sc/qa/extras/scstylefamiliesobj.cxx new file mode 100644 index 000000000..991334d19 --- /dev/null +++ b/sc/qa/extras/scstylefamiliesobj.cxx @@ -0,0 +1,147 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/style/xstyleloader.hxx> + +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScStyleFamiliesObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XStyleLoader +{ +public: + ScStyleFamiliesObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<sheet::XSpreadsheetDocument> getTargetDoc() override; + virtual uno::Reference<lang::XComponent> getSourceComponent() override; + virtual OUString getTestURL() override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScStyleFamiliesObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XStyleLoader + CPPUNIT_TEST(testLoadStylesFromDocument); + CPPUNIT_TEST(testLoadStylesFromStream); + CPPUNIT_TEST(testLoadStylesFromURL); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; + uno::Reference<lang::XComponent> m_xSrcComponent; +}; + +ScStyleFamiliesObj::ScStyleFamiliesObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<container::XNameContainer>::get()) + , XIndexAccess(2) + , XNameAccess("CellStyles") + , XServiceInfo("ScStyleFamiliesObj", "com.sun.star.style.StyleFamilies") +{ +} + +uno::Reference<uno::XInterface> ScStyleFamiliesObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW); + + return xNA; +} + +uno::Reference<sheet::XSpreadsheetDocument> ScStyleFamiliesObj::getTargetDoc() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + return xDoc; +} + +uno::Reference<lang::XComponent> ScStyleFamiliesObj::getSourceComponent() +{ + return m_xSrcComponent; +} + +OUString ScStyleFamiliesObj::getTestURL() +{ + OUString aFileURL; + createFileURL("ScStyleFamiliesObj.ods", aFileURL); + return aFileURL; +} + +void ScStyleFamiliesObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); + + m_xSrcComponent = loadFromDesktop(getTestURL()); + CPPUNIT_ASSERT_MESSAGE("no src component", m_xSrcComponent.is()); +} + +void ScStyleFamiliesObj::tearDown() +{ + closeDocument(m_xComponent); + closeDocument(m_xSrcComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleFamiliesObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scstylefamilyobj.cxx b/sc/qa/extras/scstylefamilyobj.cxx new file mode 100644 index 000000000..8597d22b0 --- /dev/null +++ b/sc/qa/extras/scstylefamilyobj.cxx @@ -0,0 +1,143 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xnamecontainer.hxx> +#include <test/container/xnamereplace.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScStyleFamilyObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XNameContainer, + public apitest::XNameReplace, + public apitest::XServiceInfo +{ +public: + ScStyleFamilyObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScStyleFamilyObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNameContainer + CPPUNIT_TEST(testInsertByName); + CPPUNIT_TEST(testInsertByNameDuplicate); + CPPUNIT_TEST(testInsertByNameEmptyName); + CPPUNIT_TEST(testRemoveByName); + CPPUNIT_TEST(testRemoveByNameNoneExistingElement); + + // XNameReplace + CPPUNIT_TEST(testReplaceByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +/* TODO: this c/should be derived/defined from the real style count, default + * implemented plus sc/res/xml/styles.xml */ +constexpr sal_Int32 kScStyleFamilyObjCount = 20; + +ScStyleFamilyObj::ScStyleFamilyObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<style::XStyle>::get()) + , XIndexAccess(kScStyleFamilyObjCount) + , XNameAccess("ScStyleFamilyObj") + , XNameContainer("ScStyleFamilyObj") + , XNameReplace("ScStyleFamilyObj") + , XServiceInfo("ScStyleFamilyObj", "com.sun.star.style.StyleFamily") +{ +} + +uno::Reference<uno::XInterface> ScStyleFamilyObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xNA, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA_SF(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xCS(xMSF->createInstance("com.sun.star.style.CellStyle"), + uno::UNO_SET_THROW); + // XNameContainer + XNameContainer::setElement(uno::makeAny(xMSF->createInstance("com.sun.star.style.CellStyle"))); + // XNameReplace + XNameReplace::setElement(uno::makeAny(xMSF->createInstance("com.sun.star.style.CellStyle"))); + + uno::Reference<container::XNameContainer> xNC(xNA_SF, uno::UNO_QUERY_THROW); + xNC->insertByName("ScStyleFamilyObj", uno::makeAny(xCS)); + + return xNA_SF; +} + +void ScStyleFamilyObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScStyleFamilyObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleFamilyObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scstyleobj.cxx b/sc/qa/extras/scstyleobj.cxx new file mode 100644 index 000000000..3ba41df30 --- /dev/null +++ b/sc/qa/extras/scstyleobj.cxx @@ -0,0 +1,128 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xnamed.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScStyleObj : public CalcUnoApiTest, public apitest::XNamed, public apitest::XPropertySet +{ +public: + ScStyleObj(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual uno::Reference<uno::XInterface> init() override; + + CPPUNIT_TEST_SUITE(ScStyleObj); + + // XNamed + CPPUNIT_TEST(testGetName); + CPPUNIT_TEST(testSetName); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScStyleObj::ScStyleObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XNamed("ScStyleObj") + , XPropertySet({ + "BottomBorder", "BottomBorder2", "CellProtection", "CharLocale", + "CharLocaleAsian", "CharLocaleComplex", "CharPosture", "CharPostureAsian", + "CharPostureComplex", "DiagonalBLTR", "DiagonalBLTR2", "DiagonalTLBR", + "DiagonalTLBR2", "HoriJustify", "LeftBorder", "LeftBorder2", + "NumberFormat", "Orientation", "RightBorder", "RightBorder2", + "ShadowFormat", "TableBorder", "TopBorder", "TopBorder2", + "UserDefinedAttributes", + }) +{ +} + +uno::Reference<uno::XInterface> ScStyleObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA_StyleFamilies(xSFS->getStyleFamilies(), + uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA_StyleFamilies(xNA_StyleFamilies, + uno::UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNA_StyleFamily(xIA_StyleFamilies->getByIndex(0), + uno::UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<style::XStyle> xStyle(xMSF->createInstance("com.sun.star.style.CellStyle"), + uno::UNO_QUERY_THROW); + uno::Reference<container::XNameContainer> xNC(xNA_StyleFamily, uno::UNO_QUERY_THROW); + if (xNC->hasByName("ScStyleObj")) + { + xNC->removeByName("ScStyleObj"); + } + xNC->insertByName("ScStyleObj", uno::makeAny(xStyle)); + + uno::Reference<container::XIndexAccess> xIA_sheets(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA_sheets->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell = xSheet0->getCellByPosition(2, 3); + uno::Reference<beans::XPropertySet> xPS(xCell, uno::UNO_QUERY_THROW); + xPS->setPropertyValue("CellStyle", uno::makeAny(xStyle->getName())); + + return xStyle; +} + +void ScStyleObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScStyleObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scsubtotaldescriptorbase.cxx b/sc/qa/extras/scsubtotaldescriptorbase.cxx new file mode 100644 index 000000000..7b2b14365 --- /dev/null +++ b/sc/qa/extras/scsubtotaldescriptorbase.cxx @@ -0,0 +1,138 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/subtotaldescriptor.hxx> +#include <test/sheet/xsubtotaldescriptor.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/SubTotalColumn.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSubTotalCalculatable.hpp> +#include <com/sun/star/sheet/XSubTotalDescriptor.hpp> +#include <com/sun/star/sheet/XSubTotalField.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScSubTotalDescriptorBase : public CalcUnoApiTest, + public apitest::SubTotalDescriptor, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XPropertySet, + public apitest::XServiceInfo, + public apitest::XSubTotalDescriptor +{ +public: + ScSubTotalDescriptorBase(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScSubTotalDescriptorBase); + + // SubTotalDescriptor + CPPUNIT_TEST(testSubTotalDescriptorProperties); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XSubTotalDescriptor + CPPUNIT_TEST(testAddNew); + CPPUNIT_TEST(testClear); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScSubTotalDescriptorBase::ScSubTotalDescriptorBase() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XSubTotalField>::get()) + , XIndexAccess(1) + , XServiceInfo("ScSubTotalDescriptorBase", "com.sun.star.sheet.SubTotalDescriptor") +{ +} + +uno::Reference<uno::XInterface> ScSubTotalDescriptorBase::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSubTotalCalculatable> xSTC(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSubTotalDescriptor> xSTD = xSTC->createSubTotalDescriptor(true); + + uno::Sequence<sheet::SubTotalColumn> xCols; + xCols.realloc(1); + xCols[0].Column = 5; + xCols[0].Function = sheet::GeneralFunction_SUM; + xSTD->addNew(xCols, 10); + + return xSTD; +} + +void ScSubTotalDescriptorBase::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScSubTotalDescriptorBase::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSubTotalDescriptorBase); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scsubtotalfieldobj.cxx b/sc/qa/extras/scsubtotalfieldobj.cxx new file mode 100644 index 000000000..2667f28a4 --- /dev/null +++ b/sc/qa/extras/scsubtotalfieldobj.cxx @@ -0,0 +1,102 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/xsubtotalfield.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/SubTotalColumn.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSubTotalCalculatable.hpp> +#include <com/sun/star/sheet/XSubTotalDescriptor.hpp> +#include <com/sun/star/sheet/XSubTotalField.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest { + +class ScSubTotalFieldObj : public CalcUnoApiTest, public apitest::XSubTotalField +{ +public: + ScSubTotalFieldObj(); + + virtual uno::Reference< uno::XInterface > init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScSubTotalFieldObj); + + // XSubTotalField + CPPUNIT_TEST(testGetSetGroupColumn); + CPPUNIT_TEST(testGetSetTotalColumns); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference< lang::XComponent > mxComponent; + +}; + +ScSubTotalFieldObj::ScSubTotalFieldObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference< uno::XInterface > ScSubTotalFieldObj::init() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference< container::XIndexAccess > xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference< sheet::XSubTotalCalculatable > xSubTotalCalc(xSheet, uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSubTotalDescriptor > xSubTotalDesc = xSubTotalCalc->createSubTotalDescriptor(true); + + uno::Sequence< sheet::SubTotalColumn > xCols; + xCols.realloc(1); + xCols[0].Column = 5; + xCols[0].Function = sheet::GeneralFunction_SUM; + xSubTotalDesc->addNew(xCols, 1); + + uno::Reference< container::XIndexAccess > xDescIndex(xSubTotalDesc, uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSubTotalField > xSTF(xDescIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + return xSTF; +} + +void ScSubTotalFieldObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); + +} + +void ScSubTotalFieldObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScSubTotalFieldObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablecolumnobj.cxx b/sc/qa/extras/sctablecolumnobj.cxx new file mode 100644 index 000000000..0dab1c6ab --- /dev/null +++ b/sc/qa/extras/sctablecolumnobj.cxx @@ -0,0 +1,157 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xnamed.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/table/tablecolumn.hxx> +#include <test/table/xcellrange.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableColumns.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScTableColumnObj : public CalcUnoApiTest, + public apitest::TableColumn, + public apitest::XCellRange, + public apitest::XNamed, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScTableColumnObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScTableColumnObj); + + // TableColumn + CPPUNIT_TEST(testTableColumnProperties); + + // XCellRange + CPPUNIT_TEST(testGetCellByPosition); + CPPUNIT_TEST(testGetCellRangeByName); + CPPUNIT_TEST(testGetCellRangeByPosition); + + // XNamed + CPPUNIT_TEST(testGetName); + // because TableColumnNames are fixed, test for an exception + CPPUNIT_TEST(testSetNameThrowsException); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScTableColumnObj::ScTableColumnObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XCellRange("K1:K1") + , XNamed("K") + , XPropertySet({ + "BottomBorder", + "BottomBorder2", + "CellProtection", + "CharLocale", + "CharLocaleAsian", + "CharLocaleComplex", + "CharPosture", + "CharPostureAsian", + "CharPostureComplex", + "ConditionalFormat", + "ConditionalFormatLocal", + "ConditionalFormatXML", + "DiagonalBLTR", + "DiagonalBLTR2", + "DiagonalTLBR", + "DiagonalTLBR2", + "HoriJustify", + "LeftBorder", + "LeftBorder2", + "NumberingRules", + "Orientation", + "RightBorder", + "RightBorder2", + "ShadowFormat", + "TableBorder", + "TableBorder2", + "TopBorder", + "TopBorder2", + "UserDefinedAttributes", + "Validation", + "ValidationLocal", + "ValidationXML", + "WritingMode", + }) + , XServiceInfo("ScTableColumnObj", "com.sun.star.table.TableColumn") +{ +} + +uno::Reference<uno::XInterface> ScTableColumnObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + setSpreadsheet(xSheet0); + uno::Reference<table::XColumnRowRange> xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableColumns> xTC(xCRR->getColumns(), uno::UNO_SET_THROW); + + uno::Reference<container::XIndexAccess> xIA_TC(xTC, uno::UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xReturn(xIA_TC->getByIndex(10), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScTableColumnObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableColumnObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableColumnObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablecolumnsobj.cxx b/sc/qa/extras/sctablecolumnsobj.cxx new file mode 100644 index 000000000..406e55948 --- /dev/null +++ b/sc/qa/extras/sctablecolumnsobj.cxx @@ -0,0 +1,147 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/table/xtablecolumns.hxx> +#include <cppu/unotype.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableColumns.hpp> +#include <com/sun/star/text/XSimpleText.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScTableColumnsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XTableColumns +{ +public: + ScTableColumnsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScTableColumnsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XTableColumns + CPPUNIT_TEST(testInsertByIndex); + CPPUNIT_TEST(testInsertByIndexWithNegativeIndex); + CPPUNIT_TEST(testInsertByIndexWithNoColumn); + CPPUNIT_TEST(testInsertByIndexWithOutOfBoundIndex); + CPPUNIT_TEST(testRemoveByIndex); + CPPUNIT_TEST(testRemoveByIndexWithNegativeIndex); + CPPUNIT_TEST(testRemoveByIndexWithNoColumn); + CPPUNIT_TEST(testRemoveByIndexWithOutOfBoundIndex); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScTableColumnsObj::ScTableColumnsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<table::XCellRange>::get()) + , XIndexAccess(1024) + , XNameAccess("ABC") + , XServiceInfo("ScTableColumnsObj", "com.sun.star.table.TableColumns") +{ +} + +uno::Reference<uno::XInterface> ScTableColumnsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<table::XColumnRowRange> xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableColumns> xTC(xCRR->getColumns(), uno::UNO_SET_THROW); + setXSpreadsheet(xSheet0); + + uno::Reference<table::XCellRange> xCR(xSheet0, uno::UNO_QUERY_THROW); + for (auto i = 0; i < xTC->getCount() - 1 && i < 3; ++i) + { + uno::Reference<text::XSimpleText> xST0(xCR->getCellByPosition(i, 0), uno::UNO_QUERY_THROW); + xST0->setString(OUString::number(i) + "a"); + uno::Reference<text::XSimpleText> xST1(xCR->getCellByPosition(i, 1), uno::UNO_QUERY_THROW); + xST1->setString(OUString::number(i) + "b"); + } + for (auto i = 3; i < xTC->getCount() - 1 && i < 10; ++i) + { + uno::Reference<text::XSimpleText> xST0(xCR->getCellByPosition(i, 0), uno::UNO_QUERY_THROW); + xST0->setString(""); + uno::Reference<text::XSimpleText> xST1(xCR->getCellByPosition(i, 1), uno::UNO_QUERY_THROW); + xST1->setString(""); + } + return xTC; +} + +void ScTableColumnsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableColumnsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableColumnsObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctableconditionalentryobj.cxx b/sc/qa/extras/sctableconditionalentryobj.cxx new file mode 100644 index 000000000..519ee8fad --- /dev/null +++ b/sc/qa/extras/sctableconditionalentryobj.cxx @@ -0,0 +1,123 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/xsheetconditionalentry.hxx> +#include <test/sheet/xsheetcondition.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/ConditionOperator.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntry.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellAddress.hpp> + +#include <unonames.hxx> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScTableConditionalEntryObj : public CalcUnoApiTest, + public apitest::XSheetConditionalEntry, + public apitest::XSheetCondition +{ +public: + ScTableConditionalEntryObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScTableConditionalEntryObj); + + // XSheetConditionalEntry + CPPUNIT_TEST(testGetSetStyleName); + + // XSheetCondition + CPPUNIT_TEST(testGetSetFormula1); + CPPUNIT_TEST(testGetSetFormula2); + CPPUNIT_TEST(testGetSetOperator); + CPPUNIT_TEST(testGetSetSourcePosition); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScTableConditionalEntryObj::ScTableConditionalEntryObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScTableConditionalEntryObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 5)->setValue(15); + xSheet->getCellByPosition(1, 4)->setValue(10); + xSheet->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<beans::XPropertySet> xPropSet(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntries> xSheetConditionalEntries; + xSheetConditionalEntries.set(xPropSet->getPropertyValue(SC_UNONAME_CONDFMT), + uno::UNO_QUERY_THROW); + + uno::Sequence<beans::PropertyValue> aPropValue(5); + aPropValue[0].Name = SC_UNONAME_STYLENAME; + aPropValue[0].Value <<= OUString("Result2"); + aPropValue[1].Name = SC_UNONAME_FORMULA1; + aPropValue[1].Value <<= OUString("$Sheet1.$B$5"); + aPropValue[2].Name = SC_UNONAME_FORMULA2; + aPropValue[2].Value <<= OUString(""); + aPropValue[3].Name = SC_UNONAME_OPERATOR; + aPropValue[3].Value <<= sheet::ConditionOperator_EQUAL; + aPropValue[4].Name = SC_UNONAME_SOURCEPOS; + aPropValue[4].Value <<= table::CellAddress(0, 1, 5); + xSheetConditionalEntries->addNew(aPropValue); + + uno::Reference<sheet::XSheetConditionalEntry> xSheetConditionalEntry( + xSheetConditionalEntries->getByIndex(0), uno::UNO_QUERY_THROW); + return xSheetConditionalEntry; +} + +void ScTableConditionalEntryObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableConditionalEntryObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableConditionalEntryObj); + +} // end namespace + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctableconditionalformat.cxx b/sc/qa/extras/sctableconditionalformat.cxx new file mode 100644 index 000000000..e26664bf5 --- /dev/null +++ b/sc/qa/extras/sctableconditionalformat.cxx @@ -0,0 +1,160 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xsheetconditionalentries.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/ConditionOperator.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntry.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <unonames.hxx> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScTableConditionalFormat : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess, + public apitest::XServiceInfo, + public apitest::XSheetConditionalEntries +{ +public: + ScTableConditionalFormat(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Sequence<beans::PropertyValue> createCondition(const sal_Int32 nr) override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScTableConditionalFormat); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XSheetConditionalEntries + CPPUNIT_TEST(testAddNew); + CPPUNIT_TEST(testClear); + CPPUNIT_TEST(testRemoveByIndex); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScTableConditionalFormat::ScTableConditionalFormat() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XSheetConditionalEntry>::get()) + , XIndexAccess(2) + , XNameAccess("Entry1") + , XServiceInfo("ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat") +{ +} + +uno::Reference<uno::XInterface> ScTableConditionalFormat::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 5)->setValue(15); + xSheet->getCellByPosition(1, 4)->setValue(10); + xSheet->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<beans::XPropertySet> xPropSet(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntries> xSheetConditionalEntries; + xSheetConditionalEntries.set(xPropSet->getPropertyValue(SC_UNONAME_CONDFMT), + uno::UNO_QUERY_THROW); + + xSheetConditionalEntries->addNew(createCondition(5)); + xSheetConditionalEntries->addNew(createCondition(2)); + + return xSheetConditionalEntries; +} + +uno::Sequence<beans::PropertyValue> ScTableConditionalFormat::createCondition(const sal_Int32 nr) +{ + uno::Sequence<beans::PropertyValue> aPropValue(5); + aPropValue[0].Name = SC_UNONAME_STYLENAME; + aPropValue[0].Value <<= OUString("Result2"); + aPropValue[1].Name = SC_UNONAME_FORMULA1; + aPropValue[1].Value <<= "$Sheet1.$B$" + OUString::number(nr); + aPropValue[2].Name = SC_UNONAME_FORMULA2; + aPropValue[2].Value <<= OUString(""); + aPropValue[3].Name = SC_UNONAME_OPERATOR; + aPropValue[3].Value <<= sheet::ConditionOperator_EQUAL; + aPropValue[4].Name = SC_UNONAME_SOURCEPOS; + aPropValue[4].Value <<= table::CellAddress(0, 1, 5); + + return aPropValue; +} + +void ScTableConditionalFormat::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableConditionalFormat::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableConditionalFormat); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablerowobj.cxx b/sc/qa/extras/sctablerowobj.cxx new file mode 100644 index 000000000..bb377646e --- /dev/null +++ b/sc/qa/extras/sctablerowobj.cxx @@ -0,0 +1,146 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/table/tablerow.hxx> +#include <test/table/xcellrange.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScTableRowObj : public CalcUnoApiTest, + public apitest::TableRow, + public apitest::XCellRange, + public apitest::XPropertySet, + public apitest::XServiceInfo +{ +public: + ScTableRowObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScTableRowObj); + + // TableRow + CPPUNIT_TEST(testTableRowProperties); + + // XCellRange + CPPUNIT_TEST(testGetCellByPosition); + CPPUNIT_TEST(testGetCellRangeByName); + CPPUNIT_TEST(testGetCellRangeByPosition); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScTableRowObj::ScTableRowObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XCellRange("A7:A7") + , XPropertySet({ "BottomBorder", + "BottomBorder2", + "CellProtection", + "CharLocale", + "CharLocaleAsian", + "CharLocaleComplex", + "CharPosture", + "CharPostureAsian", + "CharPostureComplex", + "ConditionalFormat", + "ConditionalFormatLocal", + "ConditionalFormatXML", + "DiagonalBLTR", + "DiagonalBLTR2", + "DiagonalTLBR", + "DiagonalTLBR2", + "HoriJustify", + "LeftBorder", + "LeftBorder2", + "NumberingRules", + "Orientation", + "RightBorder", + "RightBorder2", + "ShadowFormat", + "TableBorder", + "TableBorder2", + "TopBorder", + "TopBorder2", + "UserDefinedAttributes", + "Validation", + "ValidationLocal", + "ValidationXML", + "WritingMode" }) + , XServiceInfo("ScTableRowObj", "com.sun.star.table.TableRow") +{ +} + +uno::Reference<uno::XInterface> ScTableRowObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<table::XColumnRowRange> xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableRows> xTR(xCRR->getRows(), uno::UNO_SET_THROW); + + uno::Reference<container::XIndexAccess> xIA_TR(xTR, uno::UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xReturn(xIA_TR->getByIndex(6), uno::UNO_QUERY_THROW); + return xReturn; +} + +void ScTableRowObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create calc document + m_xComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableRowObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableRowObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablerowsobj.cxx b/sc/qa/extras/sctablerowsobj.cxx new file mode 100644 index 000000000..e92e500b1 --- /dev/null +++ b/sc/qa/extras/sctablerowsobj.cxx @@ -0,0 +1,135 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/table/xtablerows.hxx> + +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScTableRowsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XServiceInfo, + public apitest::XTableRows +{ +public: + ScTableRowsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXCellRange() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScTableRowsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XTableRows + CPPUNIT_TEST(testInsertByIndex); + CPPUNIT_TEST(testRemoveByIndex); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScTableRowsObj::ScTableRowsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<table::XCellRange>::get()) + , XIndexAccess(1048576) + , XServiceInfo("ScTableRowsObj", "com.sun.star.table.TableRows") +{ +} + +uno::Reference<uno::XInterface> ScTableRowsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xSheets->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + uno::Reference<table::XColumnRowRange> xCRR(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<table::XTableRows> xTR(xCRR->getRows(), uno::UNO_SET_THROW); + + return xTR; +} + +uno::Reference<uno::XInterface> ScTableRowsObj::getXCellRange() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xSheets->getByName(xNA->getElementNames()[0]), + uno::UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xCR(xSheet0, uno::UNO_QUERY_THROW); + return xCR; +} + +void ScTableRowsObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScTableRowsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableRowsObj); +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablesheetobj.cxx b/sc/qa/extras/sctablesheetobj.cxx new file mode 100644 index 000000000..46d323f36 --- /dev/null +++ b/sc/qa/extras/sctablesheetobj.cxx @@ -0,0 +1,373 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> +#include <test/sheet/scenario.hxx> +#include <test/sheet/sheetcellrange.hxx> +#include <test/sheet/spreadsheet.hxx> +#include <test/sheet/xarrayformularange.hxx> +#include <test/sheet/xcellformatrangessupplier.hxx> +#include <test/sheet/xcellrangeaddressable.hxx> +#include <test/sheet/xcellrangedata.hxx> +#include <test/sheet/xcellrangeformula.hxx> +#include <test/sheet/xcellrangemovement.hxx> +#include <test/sheet/xcellseries.hxx> +#include <test/sheet/xdatapilottablessupplier.hxx> +#include <test/sheet/xformulaquery.hxx> +#include <test/sheet/xmultipleoperation.hxx> +#include <test/sheet/xprintareas.hxx> +#include <test/sheet/xscenario.hxx> +#include <test/sheet/xscenarioenhanced.hxx> +#include <test/sheet/xscenariossupplier.hxx> +#include <test/sheet/xsheetannotationssupplier.hxx> +#include <test/sheet/xsheetauditing.hxx> +#include <test/sheet/xsheetcellrange.hxx> +#include <test/sheet/xsheetfilterable.hxx> +#include <test/sheet/xsheetfilterableex.hxx> +#include <test/sheet/xsheetlinkable.hxx> +#include <test/sheet/xsheetoperation.hxx> +#include <test/sheet/xsheetpagebreak.hxx> +#include <test/sheet/xspreadsheet.hxx> +#include <test/sheet/xsubtotalcalculatable.hxx> +#include <test/sheet/xuniquecellformatrangessupplier.hxx> +#include <test/table/xcolumnrowrange.hxx> +#include <test/table/xtablechartssupplier.hxx> +#include <test/util/xindent.hxx> +#include <test/util/xmergeable.hxx> +#include <test/util/xreplaceable.hxx> +#include <test/util/xsearchable.hxx> + +#include <com/sun/star/sheet/XScenariosSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ + +class ScTableSheetObj : public CalcUnoApiTest, public apitest::Scenario, + public apitest::SheetCellRange, + public apitest::Spreadsheet, + public apitest::XArrayFormulaRange, + public apitest::XCellFormatRangesSupplier, + public apitest::XCellRangeAddressable, + public apitest::XCellRangeData, + public apitest::XCellRangeFormula, + public apitest::XCellRangeMovement, + public apitest::XCellSeries, + public apitest::XColumnRowRange, + public apitest::XDataPilotTablesSupplier, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XMergeable, + public apitest::XMultipleOperation, + public apitest::XPrintAreas, + public apitest::XReplaceable, + public apitest::XScenario, + public apitest::XScenarioEnhanced, + public apitest::XScenariosSupplier, + public apitest::XSearchable, + public apitest::XSheetAnnotationsSupplier, + public apitest::XSheetAuditing, + public apitest::XSheetCellRange, + public apitest::XSheetFilterable, + public apitest::XSheetFilterableEx, + public apitest::XSheetLinkable, + public apitest::XSheetOperation, + public apitest::XSheetPageBreak, + public apitest::XSpreadsheet, + public apitest::XSubTotalCalculatable, + public apitest::XTableChartsSupplier, + public apitest::XUniqueCellFormatRangesSupplier +{ +public: + ScTableSheetObj(); + + virtual void setUp() override; + virtual void tearDown() override; + + virtual OUString getFileURL() override; + + virtual uno::Reference< uno::XInterface > init() override; + virtual uno::Reference< uno::XInterface > getXCellRangeData() override; + virtual uno::Reference< uno::XInterface > getXSpreadsheetDocument() override; + virtual uno::Reference< uno::XInterface > getXSpreadsheet() override; + virtual uno::Reference< uno::XInterface > getScenarioSpreadsheet() override; + + CPPUNIT_TEST_SUITE(ScTableSheetObj); + + // Scenario + CPPUNIT_TEST(testScenarioProperties); + + // SheetCellRange + CPPUNIT_TEST(testSheetCellRangeProperties); + + // Spreadsheet + CPPUNIT_TEST(testSpreadsheetProperties); + + // XArrayFormulaRange +#if 0 // disable, because it makes no sense to set an ArrayFormula over the whole sheet + CPPUNIT_TEST(testGetSetArrayFormula); +#endif + + // XCellFormatRangesSupplier + CPPUNIT_TEST(testGetCellFormatRanges); + + // XCellRangeAddressable + CPPUNIT_TEST(testGetRangeAddress); + + // XCellRangeData + CPPUNIT_TEST(testGetDataArrayOnTableSheet); + CPPUNIT_TEST(testSetDataArrayOnTableSheet); + + // XCellRangeFormula +#if 0 // disable, because it makes no sense to set a FormulaArray over the whole sheet + CPPUNIT_TEST(testGetSetFormulaArray); +#endif + + // XCellRangeMovement + CPPUNIT_TEST(testInsertCells); + CPPUNIT_TEST(testCopyRange); + CPPUNIT_TEST(testMoveRange); + CPPUNIT_TEST(testRemoveRange); + + // XCellSeries + CPPUNIT_TEST(testFillAuto); + CPPUNIT_TEST(testFillSeries); + + // XColumnRowRange + CPPUNIT_TEST(testGetColumns); + CPPUNIT_TEST(testGetRows); + + // XDataPilotTablesSupplier + CPPUNIT_TEST(testGetDataPilotTables); + + // XFormulaQuery + CPPUNIT_TEST(testQueryDependents); + CPPUNIT_TEST(testQueryPrecedents); + + // XIndent + CPPUNIT_TEST(testIncrementIndent); + CPPUNIT_TEST(testDecrementIndent); + + // XMergeable + CPPUNIT_TEST(testGetIsMergedMerge); + + // XSearchable + CPPUNIT_TEST(testFindAll); + CPPUNIT_TEST(testFindNext); + CPPUNIT_TEST(testFindFirst); + + // XMultipleOperation +#if 0 // disable, because test never finishes (see i87863) + CPPUNIT_TEST(testSetTableOperation); +#endif + + // XPrintAreas + CPPUNIT_TEST(testSetAndGetPrintTitleColumns); + CPPUNIT_TEST(testSetAndGetPrintTitleRows); + + // XReplaceable + CPPUNIT_TEST(testReplaceAll); + CPPUNIT_TEST(testCreateReplaceDescriptor); + + // XScenario + // test was disabled in qadevOOo/tests/java/ifc/sheet/_XScenario.java + CPPUNIT_TEST(testScenario); + + // XScenarioEnhanced + CPPUNIT_TEST(testGetRanges); + + // XScenariosSupplier + CPPUNIT_TEST(testGetScenarios); + + // XSheetAnnotationsSupplier + CPPUNIT_TEST(testGetAnnotations); + + // XSheetAuditing + CPPUNIT_TEST(testShowHideDependents); + CPPUNIT_TEST(testShowHidePrecedents); + CPPUNIT_TEST(testClearArrows); + CPPUNIT_TEST(testShowErrors); + CPPUNIT_TEST(testShowInvalid); + + // XSheetCellRange + CPPUNIT_TEST(testGetSpreadsheet); + + // XSheetFilterable + CPPUNIT_TEST(testCreateFilterDescriptor); + CPPUNIT_TEST(testFilter); + + // XSheetFilterableEx +#if 0 // temporarily disabled, takes too long (see i87876) + CPPUNIT_TEST(testCreateFilterDescriptorByObject); +#endif + + // XSheetLinkable + CPPUNIT_TEST(testSheetLinkable); + + // XSheetOperation + CPPUNIT_TEST(testComputeFunction); + CPPUNIT_TEST(testClearContents); + + // XSheetPageBreak + CPPUNIT_TEST(testGetColumnPageBreaks); + CPPUNIT_TEST(testGetRowPageBreaks); + CPPUNIT_TEST(testRemoveAllManualPageBreaks); + + // XSpreadsheet + CPPUNIT_TEST(testCreateCursor); + CPPUNIT_TEST(testCreateCursorByRange); + + // XSubTotalCalculatable + CPPUNIT_TEST(testCreateSubTotalDescriptor); + CPPUNIT_TEST(testApplyRemoveSubTotals); + + // XTableChartsSupplier + CPPUNIT_TEST(testGetCharts); + + // XUniqueCellFormatRangesSupplier + CPPUNIT_TEST(testGetUniqueCellFormatRanges); + + CPPUNIT_TEST_SUITE_END(); + +private: + OUString maFileURL; + uno::Reference< lang::XComponent > mxComponent; +}; + +ScTableSheetObj::ScTableSheetObj(): + CalcUnoApiTest("/sc/qa/extras/testdocuments"), + apitest::XCellSeries(1, 0), + apitest::XFormulaQuery(table::CellRangeAddress(0, 0, 0, 1023, 1048575), table::CellRangeAddress(0, 0, 0, 1023, 1048575), 0, 0), + apitest::XReplaceable("searchReplaceString", "replaceReplaceString"), + apitest::XSearchable("test", 4) +{ +} + +uno::Reference< uno::XInterface > ScTableSheetObj::init() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + xSheet->getCellByPosition(5 ,5)->setValue(15); + xSheet->getCellByPosition(2 ,0)->setValue(-5.15); + xSheet->getCellByPosition(2 ,0)->setFormula("= B5 + C1"); + + xSheet->getCellByPosition(6, 6)->setValue(3); + xSheet->getCellByPosition(7, 6)->setValue(3); + xSheet->getCellByPosition(8, 6)->setFormula("= SUM(G7:H7)"); + xSheet->getCellByPosition(9, 6)->setFormula("= G7*I7"); + + uno::Sequence<table::CellRangeAddress> aCellRangeAddr(1); + aCellRangeAddr[0] = table::CellRangeAddress(0, 0, 0, 10, 10); + + uno::Reference<sheet::XScenariosSupplier> xScence(xSheet, UNO_QUERY_THROW); + xScence->getScenarios()->addNewByName("Scenario", aCellRangeAddr, "Comment"); + xSheets->getByName("Scenario"); + + return xSheet; +} + +uno::Reference< uno::XInterface > ScTableSheetObj::getXCellRangeData() +{ + return init(); +} + +uno::Reference<uno::XInterface> ScTableSheetObj::getXSpreadsheetDocument() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + return xDoc; +} + +uno::Reference<uno::XInterface> ScTableSheetObj::getScenarioSpreadsheet() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); + + xSheet->getCellByPosition(5 ,5)->setValue(15); + xSheet->getCellByPosition(2 ,0)->setValue(-5.15); + xSheet->getCellByPosition(2 ,0)->setFormula("= B5 + C1"); + + xSheet->getCellByPosition(6, 6)->setValue(3); + xSheet->getCellByPosition(7, 6)->setValue(3); + xSheet->getCellByPosition(8, 6)->setFormula("= SUM(G7:H7)"); + xSheet->getCellByPosition(9, 6)->setFormula("= G7*I7"); + + uno::Sequence<table::CellRangeAddress> aCellRangeAddr(1); + aCellRangeAddr[0] = table::CellRangeAddress(0, 0, 0, 10, 10); + + uno::Reference<sheet::XScenariosSupplier> xScence(xSheet, UNO_QUERY_THROW); + xScence->getScenarios()->addNewByName("Scenario", aCellRangeAddr, "Comment"); + uno::Reference<sheet::XSpreadsheet> sSheet(xSheets->getByName("Scenario"), UNO_QUERY_THROW); + + return sSheet; +} + +uno::Reference< uno::XInterface > ScTableSheetObj::getXSpreadsheet() +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW); + + xSheet->getCellByPosition(5 ,5)->setValue(15); + xSheet->getCellByPosition(2 ,0)->setValue(-5.15); + xSheet->getCellByPosition(2 ,0)->setFormula("= B5 + C1"); + + xSheet->getCellByPosition(6, 6)->setValue(3); + xSheet->getCellByPosition(7, 6)->setValue(3); + xSheet->getCellByPosition(8, 6)->setFormula("= SUM(G7:H7)"); + xSheet->getCellByPosition(9, 6)->setFormula("= G7*I7"); + + uno::Sequence<table::CellRangeAddress> aCellRangeAddr(1); + aCellRangeAddr[0] = table::CellRangeAddress(0, 0, 0, 10, 10); + uno::Reference<sheet::XScenariosSupplier> xScence(xSheet, UNO_QUERY_THROW); + xScence->getScenarios()->addNewByName("Scenario", aCellRangeAddr, "Comment"); + xSheets->getByName("Scenario"); + + setXCell(xSheet->getCellByPosition(15, 15)); + return xSheet; +} + +OUString ScTableSheetObj::getFileURL() +{ + return maFileURL; +} + +void ScTableSheetObj::setUp() +{ + CalcUnoApiTest::setUp(); + createFileURL("ScTableSheetObj.ods", maFileURL); + mxComponent = loadFromDesktop(maFileURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + +void ScTableSheetObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableSheetObj); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sctablesheetsobj.cxx b/sc/qa/extras/sctablesheetsobj.cxx new file mode 100644 index 000000000..a8ffa36b2 --- /dev/null +++ b/sc/qa/extras/sctablesheetsobj.cxx @@ -0,0 +1,173 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> +#include <test/container/xnamecontainer.hxx> +#include <test/container/xnamereplace.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xspreadsheets.hxx> +#include <test/sheet/xspreadsheets2.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScTableSheetsObj : public CalcUnoApiTest, + public ::apitest::XElementAccess, + public ::apitest::XEnumerationAccess, + public ::apitest::XIndexAccess, + public ::apitest::XNameAccess, + public ::apitest::XNameContainer, + public ::apitest::XNameReplace, + public ::apitest::XServiceInfo, + public ::apitest::XSpreadsheets, + public ::apitest::XSpreadsheets2 +{ +public: + ScTableSheetsObj(); + + virtual void setUp() override; + virtual void tearDown() override; + virtual uno::Reference<uno::XInterface> init() override; + + CPPUNIT_TEST_SUITE(ScTableSheetsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XNameAccess + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + + // XNameContainer + CPPUNIT_TEST(testInsertByName); + CPPUNIT_TEST(testInsertByNameEmptyName); + CPPUNIT_TEST(testInsertByNameDuplicate); + CPPUNIT_TEST(testRemoveByName); + CPPUNIT_TEST(testRemoveByNameNoneExistingElement); + + // XNameReplace + CPPUNIT_TEST(testReplaceByName); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XSpreadsheets + CPPUNIT_TEST(testInsertNewByName); + CPPUNIT_TEST(testInsertNewByNameBadName); + CPPUNIT_TEST(testCopyByName); + CPPUNIT_TEST(testMoveByName); + + // XSpreadsheets2 + CPPUNIT_TEST(testImportedSheetNameAndIndex); + CPPUNIT_TEST(testImportString); + CPPUNIT_TEST(testImportValue); + CPPUNIT_TEST(testImportFormulaBasicMath); + CPPUNIT_TEST(testImportFormulaWithNamedRange); + CPPUNIT_TEST(testImportOverExistingNamedRange); + CPPUNIT_TEST(testImportNamedRangeDefinedInSource); + CPPUNIT_TEST(testImportNamedRangeRedefinedInSource); + CPPUNIT_TEST(testImportNewNamedRange); + CPPUNIT_TEST(testImportCellStyle); + CPPUNIT_TEST(testLastAfterInsertCopy); + + CPPUNIT_TEST_SUITE_END(); + + virtual uno::Reference<lang::XComponent> getComponent() override; + virtual void createFileURL(const OUString& rFileBase, OUString& rFileURL) override; + virtual uno::Reference<lang::XComponent> loadFromDesktop(const OUString& rString) override; + +protected: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScTableSheetsObj::ScTableSheetsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , ::apitest::XElementAccess(cppu::UnoType<sheet::XSpreadsheet>::get()) + , ::apitest::XIndexAccess(3) + , ::apitest::XNameAccess("Sheet1") + , ::apitest::XNameContainer("Sheet2") + , ::apitest::XNameReplace("Sheet2") + , ::apitest::XServiceInfo("ScTableSheetsObj", "com.sun.star.sheet.Spreadsheets") +{ +} + +uno::Reference<lang::XComponent> ScTableSheetsObj::getComponent() { return mxComponent; } + +void ScTableSheetsObj::createFileURL(const OUString& rFileBase, OUString& rFileURL) +{ + CalcUnoApiTest::createFileURL(rFileBase, rFileURL); +} + +uno::Reference<lang::XComponent> ScTableSheetsObj::loadFromDesktop(const OUString& rString) +{ + return CalcUnoApiTest::loadFromDesktop(rString); +} + +uno::Reference<uno::XInterface> ScTableSheetsObj::init() +{ + xDocument.set(mxComponent, UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xReturn(xDocument->getSheets(), UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY_THROW); + XNameContainer::setElement( + uno::makeAny(xMSF->createInstance("com.sun.star.sheet.Spreadsheet"))); + // XNameReplace + XNameReplace::setElement(uno::makeAny(xMSF->createInstance("com.sun.star.sheet.Spreadsheet"))); + + return xReturn; +} + +void ScTableSheetsObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + OUString aFileURL; + createFileURL("rangenamessrc.ods", aFileURL); + mxComponent = loadFromDesktop(aFileURL); +} + +void ScTableSheetsObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableSheetsObj); +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctablevalidationobj.cxx b/sc/qa/extras/sctablevalidationobj.cxx new file mode 100644 index 000000000..852738c22 --- /dev/null +++ b/sc/qa/extras/sctablevalidationobj.cxx @@ -0,0 +1,124 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/tablevalidation.hxx> +#include <test/sheet/xsheetcondition.hxx> +#include <test/sheet/xmultiformulatokens.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetCondition.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; +using namespace com::sun::star; + +namespace sc_apitest +{ +class ScTableValidationObj : public CalcUnoApiTest, + public apitest::TableValidation, + public apitest::XMultiFormulaTokens, + public apitest::XPropertySet, + public apitest::XServiceInfo, + public apitest::XSheetCondition +{ +public: + ScTableValidationObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScTableValidationObj); + + // TableValidation + CPPUNIT_TEST(testTableValidationProperties); + + // XMultiFormulaTokens + CPPUNIT_TEST(testGetCount); + CPPUNIT_TEST(testGetSetTokens); + + // XPropertySet + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XSheetCondition + CPPUNIT_TEST(testGetSetFormula1); + CPPUNIT_TEST(testGetSetFormula2); + CPPUNIT_TEST(testGetSetOperator); + CPPUNIT_TEST(testGetSetSourcePosition); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScTableValidationObj::ScTableValidationObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XPropertySet({ "Type", "ErrorAlertStyle" }) + , XServiceInfo("ScTableValidationObj", "com.sun.star.sheet.TableValidation") +{ +} + +uno::Reference<uno::XInterface> ScTableValidationObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 5)->setValue(15); + xSheet->getCellByPosition(1, 4)->setValue(10); + xSheet->getCellByPosition(2, 0)->setValue(-5.15); + + uno::Reference<beans::XPropertySet> xPropSet(xSheet, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCondition> xSheetCondition; + CPPUNIT_ASSERT(xPropSet->getPropertyValue("Validation") >>= xSheetCondition); + + return xSheetCondition; +} + +void ScTableValidationObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTableValidationObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTableValidationObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/sctabviewobj.cxx b/sc/qa/extras/sctabviewobj.cxx new file mode 100644 index 000000000..9fb100388 --- /dev/null +++ b/sc/qa/extras/sctabviewobj.cxx @@ -0,0 +1,143 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/sheet/spreadsheetviewsettings.hxx> +#include <test/sheet/xactivationbroadcaster.hxx> +#include <test/sheet/xcellrangereferrer.hxx> +#include <test/sheet/xspreadsheetview.hxx> +#include <test/sheet/xviewfreezable.hxx> +#include <test/sheet/xviewsplitable.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XViewPane.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScTabViewObj : public CalcUnoApiTest, + public apitest::SpreadsheetViewSettings, + public apitest::XActivationBroadcaster, + public apitest::XCellRangeReferrer, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess, + public apitest::XSpreadsheetView, + public apitest::XViewFreezable, + public apitest::XViewSplitable +{ +public: + ScTabViewObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXSpreadsheet(const sal_Int16 nNumber = 0) override; + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScTabViewObj); + + // SpreadsheetViewSettings + CPPUNIT_TEST(testSpreadsheetViewSettingsProperties); + + // XActivationBroadcaster + CPPUNIT_TEST(testAddRemoveActivationEventListener); + + // XCellRangeReferrer + //Disabled till it's clear why it fails on some machines. + //CPPUNIT_TEST(testGetReferredCells); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + // XSpreadsheetView + CPPUNIT_TEST(testGetSetActiveSheet); + + // XViewFreezable + CPPUNIT_TEST(testFreeze); + + // XViewSplitable + CPPUNIT_TEST(testSplit); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScTabViewObj::ScTabViewObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XViewPane>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference<uno::XInterface> ScTabViewObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<frame::XModel> xModel(xDoc, uno::UNO_QUERY_THROW); + + setCellRange(table::CellRangeAddress(0, 0, 0, 6, 23)); + + return xModel->getCurrentController(); +} + +uno::Reference<uno::XInterface> ScTabViewObj::getXSpreadsheet(const sal_Int16 nNumber) +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + xSheets->insertNewByName("Sheet2", 2); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(nNumber), UNO_QUERY_THROW); + + return xSheet; +} + +void ScTabViewObj::setUp() +{ + CalcUnoApiTest::setUp(); + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScTabViewObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScTabViewObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scuniquecellformatsenumeration.cxx b/sc/qa/extras/scuniquecellformatsenumeration.cxx new file mode 100644 index 000000000..ea6a76e76 --- /dev/null +++ b/sc/qa/extras/scuniquecellformatsenumeration.cxx @@ -0,0 +1,135 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XUniqueCellFormatRangesSupplier.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <sal/types.h> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +namespace +{ +struct RGBColor +{ + int m_nRed; + int m_nGreen; + int m_nBlue; + + RGBColor(int nRed, int nGreen, int nBlue) + : m_nRed(nRed) + , m_nGreen(nGreen) + , m_nBlue(nBlue) + { + } + + sal_Int32 hashCode() const { return (255 << 24) | (m_nRed << 16) | (m_nGreen << 8) | m_nBlue; } +}; +} + +class ScUniqueCellFormatsEnumeration : public CalcUnoApiTest, public apitest::XEnumeration +{ +public: + ScUniqueCellFormatsEnumeration(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScUniqueCellFormatsEnumeration); + + // XEnumeration + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; + void changeColor(const uno::Reference<sheet::XSpreadsheet>& xSheet, const OUString& sRangeName, + const RGBColor& rgb); +}; + +ScUniqueCellFormatsEnumeration::ScUniqueCellFormatsEnumeration() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +uno::Reference<uno::XInterface> ScUniqueCellFormatsEnumeration::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + changeColor(xSheet0, "A1:A5", RGBColor(0, 255, 0)); + changeColor(xSheet0, "A6:B10", RGBColor(255, 0, 0)); + changeColor(xSheet0, "B1:B6", RGBColor(0, 0, 255)); + changeColor(xSheet0, "B7", RGBColor(0, 255, 0)); + changeColor(xSheet0, "B8:B10", RGBColor(0, 0, 255)); + changeColor(xSheet0, "C1:C10", RGBColor(0, 0, 255)); + changeColor(xSheet0, "D1:D10", RGBColor(0, 255, 0)); + + uno::Reference<sheet::XUniqueCellFormatRangesSupplier> xUCFRS(xSheet0, uno::UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA(xUCFRS->getUniqueCellFormatRanges(), + uno::UNO_QUERY_THROW); + return xEA->createEnumeration(); +} + +void ScUniqueCellFormatsEnumeration::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScUniqueCellFormatsEnumeration::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +void ScUniqueCellFormatsEnumeration::changeColor(const uno::Reference<sheet::XSpreadsheet>& xSheet, + const OUString& sRangeName, const RGBColor& rgb) +{ + uno::Reference<table::XCellRange> xCellRange(xSheet->getCellRangeByName(sRangeName), + uno::UNO_SET_THROW); + uno::Reference<beans::XPropertySet> xPropertySet(xCellRange, uno::UNO_QUERY_THROW); + + sal_Int32 nColor = 16777216 + rgb.hashCode(); + uno::Any aValue; + aValue <<= nColor; + xPropertySet->setPropertyValue("CellBackColor", aValue); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScUniqueCellFormatsEnumeration); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scuniquecellformatsobj.cxx b/sc/qa/extras/scuniquecellformatsobj.cxx new file mode 100644 index 000000000..6921ec55c --- /dev/null +++ b/sc/qa/extras/scuniquecellformatsobj.cxx @@ -0,0 +1,102 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xenumerationaccess.hxx> +#include <test/container/xindexaccess.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XUniqueCellFormatRangesSupplier.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppu/unotype.hxx> + +using namespace css; +using namespace css::uno; + +namespace sc_apitest +{ +class ScUniqueCellFormatsObj : public CalcUnoApiTest, + public apitest::XElementAccess, + public apitest::XEnumerationAccess, + public apitest::XIndexAccess +{ +public: + ScUniqueCellFormatsObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScUniqueCellFormatsObj); + + // XElementAccess + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + + // XEnumerationAccess + CPPUNIT_TEST(testCreateEnumeration); + + // XIndexAccess + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetCount); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> m_xComponent; +}; + +ScUniqueCellFormatsObj::ScUniqueCellFormatsObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XElementAccess(cppu::UnoType<sheet::XSheetCellRangeContainer>::get()) + , XIndexAccess(1) +{ +} + +uno::Reference<uno::XInterface> ScUniqueCellFormatsObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is()); + + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XUniqueCellFormatRangesSupplier> xUCFRS(xSheet0, uno::UNO_QUERY_THROW); + return xUCFRS->getUniqueCellFormatRanges(); +} + +void ScUniqueCellFormatsObj::setUp() +{ + CalcUnoApiTest::setUp(); + m_xComponent = loadFromDesktop("private:factory/scalc"); + CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is()); +} + +void ScUniqueCellFormatsObj::tearDown() +{ + closeDocument(m_xComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScUniqueCellFormatsObj); +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/scviewpaneobj.cxx b/sc/qa/extras/scviewpaneobj.cxx new file mode 100644 index 000000000..1956f4d56 --- /dev/null +++ b/sc/qa/extras/scviewpaneobj.cxx @@ -0,0 +1,140 @@ +/* -*- 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 <test/calc_unoapi_test.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/sheet/xcellrangereferrer.hxx> +#include <test/sheet/xviewpane.hxx> +#include <test/view/xcontrolaccess.hxx> +#include <test/view/xformlayeraccess.hxx> +#include <test/helper/form.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/form/XForm.hpp> +#include <com/sun/star/form/XFormsSupplier.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XViewPane.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace sc_apitest +{ +class ScViewPaneObj : public CalcUnoApiTest, + public apitest::XCellRangeReferrer, + public apitest::XControlAccess, + public apitest::XFormLayerAccess, + public apitest::XServiceInfo, + public apitest::XViewPane +{ +public: + ScViewPaneObj(); + + virtual uno::Reference<uno::XInterface> init() override; + virtual uno::Reference<uno::XInterface> getXComponent() override; + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ScViewPaneObj); + + // XCellRangeReferrer + CPPUNIT_TEST(testGetReferredCells); + + // XControlAccess + CPPUNIT_TEST(testGetControl); + + // XFormLayerAccess + CPPUNIT_TEST(testGetFormController); + CPPUNIT_TEST(testIsFormDesignMode); + CPPUNIT_TEST(testSetFormDesignMode); + + // XServiceInfo + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + + // XViewPane + CPPUNIT_TEST(testFirstVisibleColumn); + CPPUNIT_TEST(testFirstVisibleRow); + CPPUNIT_TEST(testVisibleRange); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<lang::XComponent> mxComponent; +}; + +ScViewPaneObj::ScViewPaneObj() + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , XServiceInfo("ScViewPaneObj", "com.sun.star.sheet.SpreadsheetViewPane") +{ +} + +uno::Reference<uno::XInterface> ScViewPaneObj::getXComponent() { return mxComponent; } + +uno::Reference<uno::XInterface> ScViewPaneObj::init() +{ + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + + uno::Reference<frame::XModel> xModel(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<frame::XController> xController(xModel->getCurrentController(), + uno::UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xController, uno::UNO_QUERY_THROW); + uno::Reference<sheet::XViewPane> xViewPane(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDoc, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPages> xDP(xDPS->getDrawPages(), uno::UNO_SET_THROW); + xDP->insertNewByIndex(1); + xDP->insertNewByIndex(2); + + uno::Reference<drawing::XDrawPage> xDrawPage(xDP->getByIndex(0), uno::UNO_QUERY_THROW); + xDrawPage->add( + apitest::helper::form::createCommandButton(mxComponent, 15000, 10000, 3000, 4500)); + + uno::Reference<form::XFormsSupplier> xFS(xDrawPage, uno::UNO_QUERY_THROW); + uno::Reference<container::XNameContainer> xNC(xFS->getForms(), uno::UNO_SET_THROW); + + // XFormLayerAccess + uno::Reference<form::XForm> xForm(xNC->getByName("Form"), uno::UNO_QUERY_THROW); + setForm(xForm); + // XCellRangeReferrer + setCellRange(xViewPane->getVisibleRange()); + + return xViewPane; +} + +void ScViewPaneObj::setUp() +{ + CalcUnoApiTest::setUp(); + // create a calc document + mxComponent = loadFromDesktop("private:factory/scalc"); +} + +void ScViewPaneObj::tearDown() +{ + closeDocument(mxComponent); + CalcUnoApiTest::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScViewPaneObj); + +} // namespace sc_apitest + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sc/qa/extras/testdocuments/AutoFilter.xls b/sc/qa/extras/testdocuments/AutoFilter.xls Binary files differnew file mode 100644 index 000000000..1a8e5e5e9 --- /dev/null +++ b/sc/qa/extras/testdocuments/AutoFilter.xls diff --git a/sc/qa/extras/testdocuments/BaseForHTMLExport.ods b/sc/qa/extras/testdocuments/BaseForHTMLExport.ods Binary files differnew file mode 100644 index 000000000..025b1e480 --- /dev/null +++ b/sc/qa/extras/testdocuments/BaseForHTMLExport.ods diff --git a/sc/qa/extras/testdocuments/CalcFont.xls b/sc/qa/extras/testdocuments/CalcFont.xls Binary files differnew file mode 100644 index 000000000..86304063c --- /dev/null +++ b/sc/qa/extras/testdocuments/CalcFont.xls diff --git a/sc/qa/extras/testdocuments/CheckOptionToggleValue.xls b/sc/qa/extras/testdocuments/CheckOptionToggleValue.xls Binary files differnew file mode 100644 index 000000000..14cf152af --- /dev/null +++ b/sc/qa/extras/testdocuments/CheckOptionToggleValue.xls diff --git a/sc/qa/extras/testdocuments/GeneratedEventTest.xls b/sc/qa/extras/testdocuments/GeneratedEventTest.xls Binary files differnew file mode 100644 index 000000000..9325de32d --- /dev/null +++ b/sc/qa/extras/testdocuments/GeneratedEventTest.xls diff --git a/sc/qa/extras/testdocuments/MasterScriptProviderProblem.ods b/sc/qa/extras/testdocuments/MasterScriptProviderProblem.ods Binary files differnew file mode 100644 index 000000000..35e2b985b --- /dev/null +++ b/sc/qa/extras/testdocuments/MasterScriptProviderProblem.ods diff --git a/sc/qa/extras/testdocuments/MiscControlTests.xls b/sc/qa/extras/testdocuments/MiscControlTests.xls Binary files differnew file mode 100644 index 000000000..3503795b0 --- /dev/null +++ b/sc/qa/extras/testdocuments/MiscControlTests.xls diff --git a/sc/qa/extras/testdocuments/MiscRangeTests.xls b/sc/qa/extras/testdocuments/MiscRangeTests.xls Binary files differnew file mode 100644 index 000000000..c6dffd475 --- /dev/null +++ b/sc/qa/extras/testdocuments/MiscRangeTests.xls diff --git a/sc/qa/extras/testdocuments/Names.xls b/sc/qa/extras/testdocuments/Names.xls Binary files differnew file mode 100644 index 000000000..fcacf9bbd --- /dev/null +++ b/sc/qa/extras/testdocuments/Names.xls diff --git a/sc/qa/extras/testdocuments/PageBreaks.xls b/sc/qa/extras/testdocuments/PageBreaks.xls Binary files differnew file mode 100644 index 000000000..4e6ac0a42 --- /dev/null +++ b/sc/qa/extras/testdocuments/PageBreaks.xls diff --git a/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods b/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods Binary files differnew file mode 100644 index 000000000..5d7b1a4c2 --- /dev/null +++ b/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods diff --git a/sc/qa/extras/testdocuments/Ranges-2.xls b/sc/qa/extras/testdocuments/Ranges-2.xls Binary files differnew file mode 100644 index 000000000..84fdc45c0 --- /dev/null +++ b/sc/qa/extras/testdocuments/Ranges-2.xls diff --git a/sc/qa/extras/testdocuments/Ranges-3.xls b/sc/qa/extras/testdocuments/Ranges-3.xls Binary files differnew file mode 100644 index 000000000..f96620f21 --- /dev/null +++ b/sc/qa/extras/testdocuments/Ranges-3.xls diff --git a/sc/qa/extras/testdocuments/Ranges.xls b/sc/qa/extras/testdocuments/Ranges.xls Binary files differnew file mode 100644 index 000000000..4d5583e04 --- /dev/null +++ b/sc/qa/extras/testdocuments/Ranges.xls diff --git a/sc/qa/extras/testdocuments/RecordChangesProtected.ods b/sc/qa/extras/testdocuments/RecordChangesProtected.ods Binary files differnew file mode 100644 index 000000000..fac012d84 --- /dev/null +++ b/sc/qa/extras/testdocuments/RecordChangesProtected.ods diff --git a/sc/qa/extras/testdocuments/ScAnnotationObj.ods b/sc/qa/extras/testdocuments/ScAnnotationObj.ods Binary files differnew file mode 100644 index 000000000..bed0680b9 --- /dev/null +++ b/sc/qa/extras/testdocuments/ScAnnotationObj.ods diff --git a/sc/qa/extras/testdocuments/ScCellCursorObj.ods b/sc/qa/extras/testdocuments/ScCellCursorObj.ods Binary files differnew file mode 100644 index 000000000..46d8090ec --- /dev/null +++ b/sc/qa/extras/testdocuments/ScCellCursorObj.ods diff --git a/sc/qa/extras/testdocuments/ScDataPilotTableObj.ods b/sc/qa/extras/testdocuments/ScDataPilotTableObj.ods Binary files differnew file mode 100644 index 000000000..e160f5edd --- /dev/null +++ b/sc/qa/extras/testdocuments/ScDataPilotTableObj.ods diff --git a/sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods b/sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods Binary files differnew file mode 100644 index 000000000..48f001ccd --- /dev/null +++ b/sc/qa/extras/testdocuments/ScDatabaseRangeObj.ods diff --git a/sc/qa/extras/testdocuments/ScModelObj.ods b/sc/qa/extras/testdocuments/ScModelObj.ods Binary files differnew file mode 100644 index 000000000..56a25329c --- /dev/null +++ b/sc/qa/extras/testdocuments/ScModelObj.ods diff --git a/sc/qa/extras/testdocuments/ScNamedRangeObj.ods b/sc/qa/extras/testdocuments/ScNamedRangeObj.ods Binary files differnew file mode 100644 index 000000000..39a53b279 --- /dev/null +++ b/sc/qa/extras/testdocuments/ScNamedRangeObj.ods diff --git a/sc/qa/extras/testdocuments/ScOutlineObj.ods b/sc/qa/extras/testdocuments/ScOutlineObj.ods Binary files differnew file mode 100644 index 000000000..bc4642a33 --- /dev/null +++ b/sc/qa/extras/testdocuments/ScOutlineObj.ods diff --git a/sc/qa/extras/testdocuments/ScSheetLinkObj.ods b/sc/qa/extras/testdocuments/ScSheetLinkObj.ods Binary files differnew file mode 100644 index 000000000..7f09e0d97 --- /dev/null +++ b/sc/qa/extras/testdocuments/ScSheetLinkObj.ods diff --git a/sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods b/sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods Binary files differnew file mode 100644 index 000000000..0cc718c98 --- /dev/null +++ b/sc/qa/extras/testdocuments/ScStyleFamiliesObj.ods diff --git a/sc/qa/extras/testdocuments/ScTableSheetObj.ods b/sc/qa/extras/testdocuments/ScTableSheetObj.ods Binary files differnew file mode 100644 index 000000000..a18b1e7d5 --- /dev/null +++ b/sc/qa/extras/testdocuments/ScTableSheetObj.ods diff --git a/sc/qa/extras/testdocuments/Shapes.xls b/sc/qa/extras/testdocuments/Shapes.xls Binary files differnew file mode 100644 index 000000000..dbccf3da3 --- /dev/null +++ b/sc/qa/extras/testdocuments/Shapes.xls diff --git a/sc/qa/extras/testdocuments/StarBasic.ods b/sc/qa/extras/testdocuments/StarBasic.ods Binary files differnew file mode 100644 index 000000000..6b94f0684 --- /dev/null +++ b/sc/qa/extras/testdocuments/StarBasic.ods diff --git a/sc/qa/extras/testdocuments/TestAddress.xls b/sc/qa/extras/testdocuments/TestAddress.xls Binary files differnew file mode 100644 index 000000000..629645c41 --- /dev/null +++ b/sc/qa/extras/testdocuments/TestAddress.xls diff --git a/sc/qa/extras/testdocuments/TestCalc_Rangetest.xls b/sc/qa/extras/testdocuments/TestCalc_Rangetest.xls Binary files differnew file mode 100644 index 000000000..9c00f5522 --- /dev/null +++ b/sc/qa/extras/testdocuments/TestCalc_Rangetest.xls diff --git a/sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls b/sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls Binary files differnew file mode 100644 index 000000000..409459df6 --- /dev/null +++ b/sc/qa/extras/testdocuments/TestCalc_Rangetest2.xls diff --git a/sc/qa/extras/testdocuments/TestIntersection.xls b/sc/qa/extras/testdocuments/TestIntersection.xls Binary files differnew file mode 100644 index 000000000..5872be7ca --- /dev/null +++ b/sc/qa/extras/testdocuments/TestIntersection.xls diff --git a/sc/qa/extras/testdocuments/TestUnion.xls b/sc/qa/extras/testdocuments/TestUnion.xls Binary files differnew file mode 100644 index 000000000..bde207e74 --- /dev/null +++ b/sc/qa/extras/testdocuments/TestUnion.xls diff --git a/sc/qa/extras/testdocuments/Window.xls b/sc/qa/extras/testdocuments/Window.xls Binary files differnew file mode 100644 index 000000000..3daebfb99 --- /dev/null +++ b/sc/qa/extras/testdocuments/Window.xls diff --git a/sc/qa/extras/testdocuments/Workbooks.xls b/sc/qa/extras/testdocuments/Workbooks.xls Binary files differnew file mode 100644 index 000000000..2e8a7e78b --- /dev/null +++ b/sc/qa/extras/testdocuments/Workbooks.xls diff --git a/sc/qa/extras/testdocuments/bytearraystring.xls b/sc/qa/extras/testdocuments/bytearraystring.xls Binary files differnew file mode 100644 index 000000000..22da6de48 --- /dev/null +++ b/sc/qa/extras/testdocuments/bytearraystring.xls diff --git a/sc/qa/extras/testdocuments/cond_format_merge.ods b/sc/qa/extras/testdocuments/cond_format_merge.ods Binary files differnew file mode 100644 index 000000000..43b676d22 --- /dev/null +++ b/sc/qa/extras/testdocuments/cond_format_merge.ods diff --git a/sc/qa/extras/testdocuments/new_cond_format_api.ods b/sc/qa/extras/testdocuments/new_cond_format_api.ods Binary files differnew file mode 100644 index 000000000..06bb1d759 --- /dev/null +++ b/sc/qa/extras/testdocuments/new_cond_format_api.ods diff --git a/sc/qa/extras/testdocuments/pagesetup.xls b/sc/qa/extras/testdocuments/pagesetup.xls Binary files differnew file mode 100644 index 000000000..db1033af7 --- /dev/null +++ b/sc/qa/extras/testdocuments/pagesetup.xls diff --git a/sc/qa/extras/testdocuments/range-4.xls b/sc/qa/extras/testdocuments/range-4.xls Binary files differnew file mode 100644 index 000000000..67d1ad7aa --- /dev/null +++ b/sc/qa/extras/testdocuments/range-4.xls diff --git a/sc/qa/extras/testdocuments/rangenamessrc.ods b/sc/qa/extras/testdocuments/rangenamessrc.ods Binary files differnew file mode 100644 index 000000000..d22702bda --- /dev/null +++ b/sc/qa/extras/testdocuments/rangenamessrc.ods diff --git a/sc/qa/extras/testdocuments/scarealinkobj.ods b/sc/qa/extras/testdocuments/scarealinkobj.ods Binary files differnew file mode 100644 index 000000000..7f09e0d97 --- /dev/null +++ b/sc/qa/extras/testdocuments/scarealinkobj.ods diff --git a/sc/qa/extras/testdocuments/scdatapilotfieldobj.ods b/sc/qa/extras/testdocuments/scdatapilotfieldobj.ods Binary files differnew file mode 100644 index 000000000..8ba12e638 --- /dev/null +++ b/sc/qa/extras/testdocuments/scdatapilotfieldobj.ods diff --git a/sc/qa/extras/testdocuments/tdf131296_legacy.ods b/sc/qa/extras/testdocuments/tdf131296_legacy.ods Binary files differnew file mode 100644 index 000000000..43ebdeb24 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf131296_legacy.ods diff --git a/sc/qa/extras/testdocuments/tdf131296_new.ods b/sc/qa/extras/testdocuments/tdf131296_new.ods Binary files differnew file mode 100644 index 000000000..9c0161c40 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf131296_new.ods diff --git a/sc/qa/extras/testdocuments/tdf57113.ods b/sc/qa/extras/testdocuments/tdf57113.ods Binary files differnew file mode 100644 index 000000000..9768e0de0 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf57113.ods diff --git a/sc/qa/extras/testdocuments/testTypePassword.ods b/sc/qa/extras/testdocuments/testTypePassword.ods Binary files differnew file mode 100644 index 000000000..d75c17ace --- /dev/null +++ b/sc/qa/extras/testdocuments/testTypePassword.ods diff --git a/sc/qa/extras/testdocuments/vba.xls b/sc/qa/extras/testdocuments/vba.xls Binary files differnew file mode 100644 index 000000000..399b1ec20 --- /dev/null +++ b/sc/qa/extras/testdocuments/vba.xls diff --git a/sc/qa/extras/testdocuments/vba_endFunction.xls b/sc/qa/extras/testdocuments/vba_endFunction.xls Binary files differnew file mode 100644 index 000000000..af7fa8625 --- /dev/null +++ b/sc/qa/extras/testdocuments/vba_endFunction.xls diff --git a/sc/qa/extras/testdocuments/vba_findFunction.xls b/sc/qa/extras/testdocuments/vba_findFunction.xls Binary files differnew file mode 100644 index 000000000..bb0f450b1 --- /dev/null +++ b/sc/qa/extras/testdocuments/vba_findFunction.xls diff --git a/sc/qa/extras/testdocuments/window2.xls b/sc/qa/extras/testdocuments/window2.xls Binary files differnew file mode 100644 index 000000000..d1822fa36 --- /dev/null +++ b/sc/qa/extras/testdocuments/window2.xls diff --git a/sc/qa/extras/testdocuments/xcellrangesquery.ods b/sc/qa/extras/testdocuments/xcellrangesquery.ods Binary files differnew file mode 100644 index 000000000..494d79d36 --- /dev/null +++ b/sc/qa/extras/testdocuments/xcellrangesquery.ods |