Kaydet (Commit) 6f29841a authored tarafından Jens Carl's avatar Jens Carl

tdf#45904 Move Java _XSheetCellRangeContainer test to C++

Change-Id: I463fc54aa4139fbc43b6124765bf18ad8c0e6ddc
Reviewed-on: https://gerrit.libreoffice.org/44247Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJens Carl <j.carl43@gmx.de>
üst a5c4b406
/* -*- 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/.
*/
#ifndef INCLUDED_TEST_SHEET_XSHEETCELLRANGECONTAINER_HXX
#define INCLUDED_TEST_SHEET_XSHEETCELLRANGECONTAINER_HXX
#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 <test/testdllapi.hxx>
namespace apitest {
class OOO_DLLPUBLIC_TEST XSheetCellRangeContainer
{
public:
virtual css::uno::Reference< css::uno::XInterface > init() =0;
void testAddRemoveRangeAddress();
void testAddRemoveRangeAddresses();
protected:
~XSheetCellRangeContainer() {}
css::uno::Sequence< com::sun::star::table::CellRangeAddress > createCellRangeAddresses();
};
}
#endif // INCLUDED_TEST_SHEET_XSHEETCELLRANGECONTAINER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -618,7 +618,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\ ...@@ -618,7 +618,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
qadevOOo/tests/java/ifc/sheet/_XSheetAnnotationsSupplier \ qadevOOo/tests/java/ifc/sheet/_XSheetAnnotationsSupplier \
qadevOOo/tests/java/ifc/sheet/_XSheetAuditing \ qadevOOo/tests/java/ifc/sheet/_XSheetAuditing \
qadevOOo/tests/java/ifc/sheet/_XSheetCellCursor \ qadevOOo/tests/java/ifc/sheet/_XSheetCellCursor \
qadevOOo/tests/java/ifc/sheet/_XSheetCellRangeContainer \
qadevOOo/tests/java/ifc/sheet/_XSheetFilterableEx \ qadevOOo/tests/java/ifc/sheet/_XSheetFilterableEx \
qadevOOo/tests/java/ifc/sheet/_XSpreadsheetView \ qadevOOo/tests/java/ifc/sheet/_XSpreadsheetView \
qadevOOo/tests/java/ifc/style/_CharacterProperties \ qadevOOo/tests/java/ifc/style/_CharacterProperties \
......
...@@ -113,10 +113,6 @@ ...@@ -113,10 +113,6 @@
"ScCellRangesObj";"com::sun::star::style::CharacterPropertiesComplex";"CharFontPitchComplex" "ScCellRangesObj";"com::sun::star::style::CharacterPropertiesComplex";"CharFontPitchComplex"
"ScCellRangesObj";"com::sun::star::style::CharacterPropertiesComplex";"CharPostureComplex" "ScCellRangesObj";"com::sun::star::style::CharacterPropertiesComplex";"CharPostureComplex"
"ScCellRangesObj";"com::sun::star::style::CharacterPropertiesComplex";"CharLocaleComplex" "ScCellRangesObj";"com::sun::star::style::CharacterPropertiesComplex";"CharLocaleComplex"
"ScCellRangesObj";"com::sun::star::sheet::XSheetCellRangeContainer";"addRangeAddress()"
"ScCellRangesObj";"com::sun::star::sheet::XSheetCellRangeContainer";"removeRangeAddress()"
"ScCellRangesObj";"com::sun::star::sheet::XSheetCellRangeContainer";"addRangeAddresses()"
"ScCellRangesObj";"com::sun::star::sheet::XSheetCellRangeContainer";"removeRangeAddresses()"
"ScCellRangesObj";"com::sun::star::sheet::XFormulaQuery";"queryDependents()" "ScCellRangesObj";"com::sun::star::sheet::XFormulaQuery";"queryDependents()"
"ScCellRangesObj";"com::sun::star::sheet::XFormulaQuery";"queryPrecedents()" "ScCellRangesObj";"com::sun::star::sheet::XFormulaQuery";"queryPrecedents()"
"ScCellRangesObj";"com::sun::star::sheet::SheetCellRanges";"ConditionalFormat" "ScCellRangesObj";"com::sun::star::sheet::SheetCellRanges";"ConditionalFormat"
......
/*
* 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package ifc.sheet;
import lib.MultiMethodTest;
import lib.StatusException;
import com.sun.star.sheet.XSheetCellRangeContainer;
import com.sun.star.table.CellRangeAddress;
/**
* Testing <code>com.sun.star.sheet.XSheetCellRangeContainer</code>
* interface methods :
* <ul>
* <li><code> addRangeAddress() </code></li>
* <li><code> removeRangeAddress() </code></li>
* <li><code> addRangeAddresses() </code></li>
* <li><code> removeRangeAddresses() </code></li>
* </ul> <p>
* Test is <b> NOT </b> multithread compliant. <p>
* @see com.sun.star.sheet.XSheetCellRangeContainer
*/
public class _XSheetCellRangeContainer extends MultiMethodTest {
public XSheetCellRangeContainer oObj = null;
public CellRangeAddress[] rAddr = new CellRangeAddress[3];
/**
* After method called, the new array of structures 'CellRangeAddress'
* is created. Then container is cleared.
*/
@Override
public void before() {
for ( short i=0; i<=2; i++ ) {
rAddr[i] = new CellRangeAddress();
rAddr[i].Sheet = i;
rAddr[i].StartColumn = i;
rAddr[i].StartRow = i;
rAddr[i].EndColumn = i + 3;
rAddr[i].EndRow = i + 3;
try {
oObj.removeRangeAddresses(oObj.getRangeAddresses());
} catch (com.sun.star.uno.Exception e) {
e.printStackTrace(log);
throw new StatusException("Error: Cannot remove "+
"range addresses." ,e);
}
}
}
/**
* The method called. Then new value is added to Container.
* Next we try to obtain back added value and check it. <p>
*
* Has <b> OK </b> status if the range just added presents among
* all ranges in the container.
*/
public void _addRangeAddress() {
boolean result = true;
log.println("Elements before adding: " + oObj.getCount());
oObj.addRangeAddress(rAddr[0], false);
log.println("Elements after adding: " + oObj.getCount());
CellRangeAddress[] addr = oObj.getRangeAddresses();
boolean exist = false ;
for (int i=0; i<=oObj.getCount()-1; i++) {
if ( addr[i].Sheet == rAddr[0].Sheet &&
addr[i].StartColumn == rAddr[0].StartColumn &&
addr[i].StartRow == rAddr[0].StartRow &&
addr[i].EndColumn == rAddr[0].EndColumn &&
addr[i].EndRow == rAddr[0].EndRow) {
exist = true;
}
}
result &= exist ;
tRes.tested("addRangeAddress()" ,result);
}
/**
* The method called. Then a value added before is removed.
* Next we check Container for existence of removed value. <p>
* Has <b> OK </b> status if the range just removed doesn't presents among
* all ranges in the container.
*/
public void _removeRangeAddress() {
boolean result = true;
log.println("Elements before removing: " + oObj.getCount());
try {
oObj.removeRangeAddress(rAddr[0]);
} catch (com.sun.star.container.NoSuchElementException e) {
e.printStackTrace(log);
result = false;
}
log.println("Elements after removing: " + oObj.getCount());
CellRangeAddress[] addr = oObj.getRangeAddresses();
for (int i=0; i<=oObj.getCount()-1; i++) {
if ( (addr[i].Sheet == rAddr[0].Sheet) &&
(addr[i].StartColumn == rAddr[0].StartColumn) &&
(addr[i].StartRow == rAddr[0].StartRow) &&
(addr[i].EndColumn == rAddr[0].EndColumn) &&
(addr[i].EndRow == rAddr[0].EndRow) ) {
result = false;
}
}
tRes.tested("removeRangeAddress()" ,result);
}
/**
* The method called. Then new values are added to Container.
* Next we try to obtain back all added values and check it. <p>
*
* Has <b> OK </b> status if the count of ranges increases by
* number of added ranges - 1 (one of ranges already exists in the
* container). And if all of ranges added exist in the container.
*/
public void _addRangeAddresses() {
executeMethod("addRangeAddress()");
boolean result = true;
int cntBefore = oObj.getCount();
log.println("Elements before adding: " + cntBefore);
oObj.addRangeAddresses(rAddr, false);
log.println("Elements after adding: " + oObj.getCount());
CellRangeAddress[] addr = oObj.getRangeAddresses();
result &= cntBefore + rAddr.length == oObj.getCount();
for (int j = 0; j < rAddr.length; j++) {
boolean exist = false ;
for (int i=0; i < oObj.getCount(); i++) {
if ( addr[i].Sheet == rAddr[j].Sheet &&
addr[i].StartColumn == rAddr[j].StartColumn &&
addr[i].StartRow == rAddr[j].StartRow &&
addr[i].EndColumn == rAddr[j].EndColumn &&
addr[i].EndRow == rAddr[j].EndRow ) {
exist = true;
break;
}
}
result &= exist;
}
tRes.tested("addRangeAddresses()" ,result);
}
/**
* All ranges are remover from container.
*
* Has <b> OK </b> status if there are no more ranges in the container.
*/
public void _removeRangeAddresses() {
boolean result = false;
int cnt;
log.println("Elements before removing: " + oObj.getCount());
try {
oObj.removeRangeAddresses(oObj.getRangeAddresses());
} catch (com.sun.star.container.NoSuchElementException e) {
e.printStackTrace(log);
result = false;
}
if ( (cnt = oObj.getCount()) == 0) {
result = true;
}
log.println("Elements after removing: " + cnt);
tRes.tested("removeRangeAddresses()" ,result);
}
/**
* Forces environment recreation.
*/
@Override
protected void after() {
disposeEnvironment();
}
}
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
*/ */
#include <test/calc_unoapi_test.hxx> #include <test/calc_unoapi_test.hxx>
#include <test/sheet/xsheetoperation.hxx> #include <test/sheet/xsheetcellrangecontainer.hxx>
#include <test/sheet/xsheetcellranges.hxx> #include <test/sheet/xsheetcellranges.hxx>
#include <test/sheet/xsheetoperation.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XIndexAccess.hpp>
...@@ -26,9 +27,10 @@ using namespace css::uno; ...@@ -26,9 +27,10 @@ using namespace css::uno;
namespace sc_apitest { namespace sc_apitest {
#define NUMBER_OF_TESTS 5 #define NUMBER_OF_TESTS 7
class ScCellRangesObj : public CalcUnoApiTest, class ScCellRangesObj : public CalcUnoApiTest,
public apitest::XSheetCellRangeContainer,
public apitest::XSheetCellRanges, public apitest::XSheetCellRanges,
public apitest::XSheetOperation public apitest::XSheetOperation
{ {
...@@ -42,6 +44,10 @@ public: ...@@ -42,6 +44,10 @@ public:
CPPUNIT_TEST_SUITE(ScCellRangesObj); CPPUNIT_TEST_SUITE(ScCellRangesObj);
// XSheetCellRangeContainer
CPPUNIT_TEST(testAddRemoveRangeAddress);
CPPUNIT_TEST(testAddRemoveRangeAddresses);
// XSheetCellRanges // XSheetCellRanges
CPPUNIT_TEST(testGetCells); CPPUNIT_TEST(testGetCells);
CPPUNIT_TEST(testGetRangeAddresses); CPPUNIT_TEST(testGetRangeAddresses);
......
...@@ -70,6 +70,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ ...@@ -70,6 +70,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\
test/source/sheet/xsheetannotation \ test/source/sheet/xsheetannotation \
test/source/sheet/xsheetannotations \ test/source/sheet/xsheetannotations \
test/source/sheet/xsheetannotationshapesupplier \ test/source/sheet/xsheetannotationshapesupplier \
test/source/sheet/xsheetcellrangecontainer \
test/source/sheet/xsheetcellrange \ test/source/sheet/xsheetcellrange \
test/source/sheet/xsheetcellranges \ test/source/sheet/xsheetcellranges \
test/source/sheet/xsheetconditionalentries \ test/source/sheet/xsheetconditionalentries \
......
/* -*- 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/sheet/xsheetcellrangecontainer.hxx>
#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <cppunit/extensions/HelperMacros.h>
using namespace com::sun::star;
using namespace com::sun::star::uno;
CPPUNIT_NS_BEGIN
template<> struct assertion_traits<table::CellRangeAddress>
{
static bool equal(const table::CellRangeAddress& x, const table::CellRangeAddress& y)
{
return x == y;
}
static std::string toString( const table::CellRangeAddress& x )
{
OStringStream ost;
ost << "Sheet: " << x.Sheet << " StartColumn: " << x.StartColumn << " StartRow: " << x.StartRow
<< " EndColumn: " << x.EndColumn << " EndRow: " << x.EndRow;
return ost.str();
}
};
CPPUNIT_NS_END
namespace apitest {
void XSheetCellRangeContainer::testAddRemoveRangeAddress()
{
uno::Reference< sheet::XSheetCellRangeContainer > xSCRC(init(), UNO_QUERY_THROW);
xSCRC->removeRangeAddresses(xSCRC->getRangeAddresses()); // prepare a clean slate
uno::Sequence< table::CellRangeAddress > aAddr = createCellRangeAddresses();
sal_Int32 cnt = xSCRC->getCount();
xSCRC->addRangeAddress(aAddr[0], false);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (count)",
cnt + 1, xSCRC->getCount());
uno::Sequence< table::CellRangeAddress > aAfterAddAddr = xSCRC->getRangeAddresses();
cnt = xSCRC->getCount();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (entry)",
aAddr[0], aAfterAddAddr[cnt - 1]);
xSCRC->removeRangeAddress(aAddr[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove CellRangeAddress (count)",
cnt - 1, xSCRC->getCount());
uno::Sequence< table::CellRangeAddress > aAfterRemoveAddr = xSCRC->getRangeAddresses();
for ( auto const & addr : aAfterRemoveAddr )
{
CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddress (entry)",
aAddr[0] != addr);
}
}
void XSheetCellRangeContainer::testAddRemoveRangeAddresses()
{
uno::Reference< sheet::XSheetCellRangeContainer > xSCRC(init(), UNO_QUERY_THROW);
xSCRC->removeRangeAddresses(xSCRC->getRangeAddresses()); // prepare a clean slate
uno::Sequence< table::CellRangeAddress > aAddr = createCellRangeAddresses();
sal_Int32 cnt = xSCRC->getCount();
xSCRC->addRangeAddresses(aAddr, false);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (count)",
cnt + 2, xSCRC->getCount());
uno::Sequence< table::CellRangeAddress > aAfterAddAddr = xSCRC->getRangeAddresses();
cnt = xSCRC->getCount();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddresses (entry: first)",
aAddr[0], aAfterAddAddr[cnt - 2]);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddresses (entry: second)",
aAddr[1], aAfterAddAddr[cnt - 1]);
xSCRC->removeRangeAddresses(aAddr);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove CellRangeAddresses (count)",
cnt - 2, xSCRC->getCount());
uno::Sequence< table::CellRangeAddress > aAfterRemoveAddr = xSCRC->getRangeAddresses();
for ( auto const & addr : aAfterRemoveAddr )
{
CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddresses (entry: first)",
aAddr[0] != addr);
CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddresses (entry: second)",
aAddr[1] != addr);
}
}
uno::Sequence< table::CellRangeAddress > XSheetCellRangeContainer::createCellRangeAddresses()
{
uno::Sequence< table::CellRangeAddress > aAddr(2);
for ( unsigned int i = 0; i < 2; i++ )
{
aAddr[i].Sheet = i;
aAddr[i].StartColumn = i;
aAddr[i].StartRow = i;
aAddr[i].EndColumn = i + 3;
aAddr[i].EndRow = i + 3;
}
return aAddr;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment