From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sc/qa/extras/check_xcell_ranges_query.cxx | 186 ++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 sc/qa/extras/check_xcell_ranges_query.cxx (limited to 'sc/qa/extras/check_xcell_ranges_query.cxx') 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 +#include +#include +#include +#include +#include +#include +#include + +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 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 xNamed; + CPPUNIT_ASSERT(aAny >>= xNamed); + sSheetName = xNamed->getName(); + + // get the cell + uno::Reference< sheet::XSpreadsheet > xSpreadSheet; + CPPUNIT_ASSERT(aAny >>= xSpreadSheet); + uno::Reference oObj = xSpreadSheet->getCellByPosition(2, 3); + m_xCell = uno::Reference(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: + *
    + *
  1. compare an empty cell with a cell with a value in the same column
  2. + *
  3. compare an empty cell with a cell with a value in the same row
  4. + *
  5. query for empty cells
  6. + *
      + */ +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: + *
        + *
      1. compare a cell with value 5 with a cell with value 15 in the same + * column
      2. + *
      3. compare a cell with value 5 with a cell with value 15 in the same + * row
      4. + *
      5. query for an empty cell.
      6. + *
          + */ + +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 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 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 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(); -- cgit v1.2.3