diff options
author | kadertarlan <kadertarlan1@gmail.com> | 2016-02-11 03:01:14 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-02-15 00:27:47 +0000 |
commit | 8c125eca7f8a0dd2d59678cff2574bbccc70e536 (patch) | |
tree | 57589ef1a8b8e9b469d7c2dc5c0573eaf20260e8 | |
parent | 30a36fa3a6451cf27cdec039aba480357d6f1613 (diff) |
tdf#45904 move java based api tests to c++
Change-Id: Ia4eedef6a6cb060d756ee83b3fb82afa68ac2c5a
Reviewed-on: https://gerrit.libreoffice.org/22276
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r-- | sc/CppunitTest_sc_check_xcell_ranges_query.mk | 103 | ||||
-rw-r--r-- | sc/JunitTest_sc_complex.mk | 2 | ||||
-rw-r--r-- | sc/Module_sc.mk | 1 | ||||
-rw-r--r-- | sc/qa/extras/check_xcell_ranges_query.cxx | 191 |
4 files changed, 295 insertions, 2 deletions
diff --git a/sc/CppunitTest_sc_check_xcell_ranges_query.mk b/sc/CppunitTest_sc_check_xcell_ranges_query.mk new file mode 100644 index 000000000000..5ca88d9082c1 --- /dev/null +++ b/sc/CppunitTest_sc_check_xcell_ranges_query.mk @@ -0,0 +1,103 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# 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/. +# +#************************************************************************* +$(eval $(call gb_CppunitTest_CppunitTest,sc_check_xcell_ranges_query)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sc_check_xcell_ranges_query, \ + sc/qa/extras/check_xcell_ranges_query \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sc_check_xcell_ranges_query, \ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + drawinglayer \ + editeng \ + for \ + forui \ + i18nlangtag \ + msfilter \ + oox \ + sal \ + salhelper \ + sax \ + sb \ + sc \ + scqahelper \ + sfx \ + sot \ + subsequenttest \ + svl \ + svt \ + svx \ + svxcore \ + test \ + tk \ + tl \ + ucbhelper \ + unotest \ + utl \ + vbahelper \ + vcl \ + xo \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_CppunitTest_set_include,sc_check_xcell_ranges_query,\ + -I$(SRCDIR)/sc/source/ui/inc \ + -I$(SRCDIR)/sc/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,sc_check_xcell_ranges_query,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sc_check_xcell_ranges_query)) +$(eval $(call gb_CppunitTest_use_vcl,sc_check_xcell_ranges_query)) + +$(eval $(call gb_CppunitTest_use_components,sc_check_xcell_ranges_query,\ + basic/util/sb \ + comphelper/util/comphelp \ + configmgr/source/configmgr \ + dbaccess/util/dba \ + filter/source/config/cache/filterconfig1 \ + forms/util/frm \ + framework/util/fwk \ + i18npool/util/i18npool \ + oox/util/oox \ + package/source/xstor/xstor \ + package/util/package2 \ + sax/source/expatwrap/expwrap \ + scripting/source/basprov/basprov \ + scripting/util/scriptframe \ + sc/util/sc \ + sc/util/scd \ + sc/util/scfilt \ + $(call gb_Helper_optional,SCRIPTING, \ + sc/util/vbaobj) \ + sfx2/util/sfx \ + sot/util/sot \ + svl/source/fsstor/fsstorage \ + toolkit/util/tk \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ + ucb/source/ucp/tdoc/ucptdoc1 \ + unotools/util/utl \ + unoxml/source/rdf/unordf \ + unoxml/source/service/unoxml \ + svtools/util/svt \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sc_check_xcell_ranges_query,)) + +# vim: set noet sw=4 ts=4:
\ No newline at end of file diff --git a/sc/JunitTest_sc_complex.mk b/sc/JunitTest_sc_complex.mk index 8fedb478745a..6e446e8e258f 100644 --- a/sc/JunitTest_sc_complex.mk +++ b/sc/JunitTest_sc_complex.mk @@ -13,7 +13,6 @@ $(eval $(call gb_JunitTest_JunitTest,sc_complex)) # any key after resizing" etc.) $(eval $(call gb_JunitTest_add_classes,sc_complex, \ - complex.cellRanges.CheckXCellRangesQuery \ complex.dataPilot.CheckDataPilot \ complex.sc.CalcRTL \ )) @@ -27,7 +26,6 @@ $(eval $(call gb_JunitTest_use_jars,sc_complex, \ )) $(eval $(call gb_JunitTest_add_sourcefiles,sc_complex, \ - sc/qa/complex/cellRanges/CheckXCellRangesQuery \ sc/qa/complex/dataPilot/CheckDataPilot \ sc/qa/complex/dataPilot/_XDataPilotDescriptor \ sc/qa/complex/dataPilot/_XDataPilotTable \ diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index 1d802f9d934a..c8f9808e5775 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -89,6 +89,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\ CppunitTest_sc_editfieldobj_cell \ CppunitTest_sc_editfieldobj_header \ CppunitTest_sc_modelobj \ + CppunitTest_sc_check_xcell_ranges_query \ )) $(eval $(call gb_Module_add_perfcheck_targets,sc,\ 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 000000000000..77c0bb63e5f4 --- /dev/null +++ b/sc/qa/extras/check_xcell_ranges_query.cxx @@ -0,0 +1,191 @@ +/* -*- 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/lang/XMultiServiceFactory.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/util/XCloseable.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> + +using namespace css; +using namespace css::lang; +using namespace css::frame; + +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 > m_xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("no calc document!", m_xSheetDoc.is()); + + // Getting spreadsheet + uno::Reference< sheet::XSpreadsheets > oSheets = m_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 an cell with value 5 with a cell with value 15 in the same + * column</li> + * <li>compare an 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 > m_xSpreadSheet(init(), uno::UNO_QUERY_THROW); + // fill the cell with a value + m_xSpreadSheet->getCellByPosition(2, 3)->setValue(15); + + // compare an cell with value 5 with a cell with value 15 + _queryColumnDifferences(sSheetName + ".C4"); + // compare an 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(); |