tdf#45904 Move Java _XSheetCellRanges tests to C++

Change-Id: I6f6dcbc5368ce034c25553edf8b88c6669074243
Reviewed-on: https://gerrit.libreoffice.org/44194
Tested-by: Jenkins <[email protected]>
Reviewed-by: Jens Carl <[email protected]>
diff --git a/include/test/sheet/xsheetcellranges.hxx b/include/test/sheet/xsheetcellranges.hxx
new file mode 100644
index 0000000..1827519
--- /dev/null
+++ b/include/test/sheet/xsheetcellranges.hxx
@@ -0,0 +1,38 @@
/* -*- 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_XSHEETCELLRANGES_HXX
#define INCLUDED_TEST_SHEET_XSHEETCELLRANGES_HXX


#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/uno/Reference.hxx>

#include <test/testdllapi.hxx>

namespace apitest {

class OOO_DLLPUBLIC_TEST XSheetCellRanges
{
public:
    virtual css::uno::Reference< css::uno::XInterface > init() =0;

    void testGetCells();
    void testGetRangeAddresses();
    void testGetRangeAddressesAsString();

protected:
    ~XSheetCellRanges() {}
};

}

#endif // INCLUDED_TEST_SHEET_XSHEETCELLRANGES_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/qadevOOo/Jar_OOoRunner.mk b/qadevOOo/Jar_OOoRunner.mk
index aa1ca80..94b198c 100644
--- a/qadevOOo/Jar_OOoRunner.mk
+++ b/qadevOOo/Jar_OOoRunner.mk
@@ -620,7 +620,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
    qadevOOo/tests/java/ifc/sheet/_XSheetCellCursor \
    qadevOOo/tests/java/ifc/sheet/_XSheetCellRange \
    qadevOOo/tests/java/ifc/sheet/_XSheetCellRangeContainer \
    qadevOOo/tests/java/ifc/sheet/_XSheetCellRanges \
    qadevOOo/tests/java/ifc/sheet/_XSheetFilterableEx \
    qadevOOo/tests/java/ifc/sheet/_XSpreadsheetView \
    qadevOOo/tests/java/ifc/style/_CharacterProperties \
diff --git a/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScCellRangesObj.csv b/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScCellRangesObj.csv
index 927dfc3..a17fa72 100644
--- a/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScCellRangesObj.csv
+++ b/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScCellRangesObj.csv
@@ -45,9 +45,6 @@
"ScCellRangesObj";"com::sun::star::style::CharacterPropertiesAsian";"ParaIsHangingPunctuation"
"ScCellRangesObj";"com::sun::star::container::XIndexAccess";"getCount()"
"ScCellRangesObj";"com::sun::star::container::XIndexAccess";"getByIndex()"
"ScCellRangesObj";"com::sun::star::sheet::XSheetCellRanges";"getCells()"
"ScCellRangesObj";"com::sun::star::sheet::XSheetCellRanges";"getRangeAddressesAsString()"
"ScCellRangesObj";"com::sun::star::sheet::XSheetCellRanges";"getRangeAddresses()"
"ScCellRangesObj";"com::sun::star::util::XReplaceable";"createReplaceDescriptor()"
"ScCellRangesObj";"com::sun::star::util::XReplaceable";"replaceAll()"
"ScCellRangesObj";"com::sun::star::chart::XChartData";"addChartDataChangeEventListener()"
diff --git a/qadevOOo/tests/java/ifc/sheet/_XSheetCellRanges.java b/qadevOOo/tests/java/ifc/sheet/_XSheetCellRanges.java
deleted file mode 100644
index c5db09e..0000000
--- a/qadevOOo/tests/java/ifc/sheet/_XSheetCellRanges.java
+++ /dev/null
@@ -1,80 +0,0 @@
/*
 * 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 com.sun.star.container.XEnumeration;
import com.sun.star.sheet.XSheetCellRanges;
import com.sun.star.table.CellRangeAddress;

/**
* Testing <code>com.sun.star.sheet.XSheetCellRanges</code>
* interface methods :
* <ul>
*  <li><code> getCells()</code></li>
*  <li><code> getRangeAddressesAsString()</code></li>
*  <li><code> getRangeAddresses()</code></li>
* </ul> <p>
* @see com.sun.star.sheet.XSheetCellRanges
*/
public class _XSheetCellRanges extends MultiMethodTest{

    public XSheetCellRanges oObj = null;

    /**
    * Test calls the method, creates enumeration of returned value
    * and checks that the enumeration has elements. <p>
    * Has <b> OK </b> status if gained enumeration has elements. <p>
    */
    public void _getCells() {
        log.println("Testing getCells ...");

        XEnumeration oEnum = oObj.getCells().createEnumeration();
        boolean res = oEnum.hasMoreElements();
        if (!res) {
            log.println(
                    "The Enumeration gained via getCells() has no Elements");
        }
        tRes.tested("getCells()", res);
    }

    /**
    * Test calls the method and checks length of returned array. <p>
    * Has <b> OK </b> status if length of returned array is greater than 2.<p>
    */
    public void _getRangeAddresses() {
        log.println("Testing getRangeAddresses ...");
        CellRangeAddress[] oRanges = oObj.getRangeAddresses();
        int howmuch = oRanges.length;
        tRes.tested("getRangeAddresses()", (howmuch > 2) );
    }

    /**
    * Test calls the method and checks returned string. <p>
    * Has <b> OK </b> status if returned string starts from 'Sheet'.<p>
    */
    public void _getRangeAddressesAsString() {
        log.println("Testing getRangeAddressesAsString ...");
        String oRanges = oObj.getRangeAddressesAsString();
        tRes.tested("getRangeAddressesAsString()",oRanges.indexOf("C1:D4")>0);
    }

} // finished class _XSheetCellRanges

diff --git a/sc/qa/extras/sccellrangesobj.cxx b/sc/qa/extras/sccellrangesobj.cxx
index 9e8d287..aaa1fa7 100644
--- a/sc/qa/extras/sccellrangesobj.cxx
+++ b/sc/qa/extras/sccellrangesobj.cxx
@@ -9,6 +9,7 @@

#include <test/calc_unoapi_test.hxx>
#include <test/sheet/xsheetoperation.hxx>
#include <test/sheet/xsheetcellranges.hxx>

#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
@@ -25,9 +26,11 @@ using namespace css::uno;

namespace sc_apitest {

#define NUMBER_OF_TESTS 2
#define NUMBER_OF_TESTS 5

class ScCellRangesObj : public CalcUnoApiTest, public apitest::XSheetOperation
class ScCellRangesObj : public CalcUnoApiTest,
                        public apitest::XSheetCellRanges,
                        public apitest::XSheetOperation
{
public:
    ScCellRangesObj();
@@ -39,6 +42,11 @@ public:

    CPPUNIT_TEST_SUITE(ScCellRangesObj);

    // XSheetCellRanges
    CPPUNIT_TEST(testGetCells);
    CPPUNIT_TEST(testGetRangeAddresses);
    CPPUNIT_TEST(testGetRangeAddressesAsString);

    // XSheetOperation
    CPPUNIT_TEST(testComputeFunction);
    CPPUNIT_TEST(testClearContents);
@@ -72,9 +80,7 @@ uno::Reference< uno::XInterface > ScCellRangesObj::init()
    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::Reference< container::XNameContainer > xRanges(xSheet, uno::UNO_QUERY_THROW);
    uno::Any xCellRange;

    xCellRange <<= xSheet->getCellRangeByName("C1:D4");
    xRanges->insertByName("Range1", xCellRange);
    xCellRange <<= xSheet->getCellRangeByName("E2:F5");
@@ -84,6 +90,13 @@ uno::Reference< uno::XInterface > ScCellRangesObj::init()
    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;
}
diff --git a/test/Library_subsequenttest.mk b/test/Library_subsequenttest.mk
index e6f0c99..0435b96 100644
--- a/test/Library_subsequenttest.mk
+++ b/test/Library_subsequenttest.mk
@@ -70,6 +70,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\
	test/source/sheet/xsheetannotation \
	test/source/sheet/xsheetannotations \
	test/source/sheet/xsheetannotationshapesupplier \
	test/source/sheet/xsheetcellranges \
	test/source/sheet/xsheetconditionalentries \
	test/source/sheet/xsheetconditionalentry \
	test/source/sheet/xsheetcondition \
diff --git a/test/source/sheet/xsheetcellranges.cxx b/test/source/sheet/xsheetcellranges.cxx
new file mode 100644
index 0000000..0b590ad
--- /dev/null
+++ b/test/source/sheet/xsheetcellranges.cxx
@@ -0,0 +1,52 @@
/* -*- 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/xsheetcellranges.hxx>

#include <com/sun/star/container/XEnumeration.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/sheet/XSheetCellRanges.hpp>
#include <com/sun/star/table/CellRangeAddress.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;

namespace apitest {

void XSheetCellRanges::testGetCells()
{
    uno::Reference< sheet::XSheetCellRanges > xSheetCellRanges(init(), UNO_QUERY_THROW);
    uno::Reference< container::XEnumerationAccess > xEA = xSheetCellRanges->getCells();

    CPPUNIT_ASSERT_MESSAGE("Unable to get cells", xEA->hasElements());
}

void XSheetCellRanges::testGetRangeAddresses()
{
    uno::Reference< sheet::XSheetCellRanges > xSheetCellRanges(init(), UNO_QUERY_THROW);
    uno::Sequence< table::CellRangeAddress > aCellRangeAddress = xSheetCellRanges->getRangeAddresses();
    CPPUNIT_ASSERT_MESSAGE("Unable to get RangeAddresses",
                           aCellRangeAddress.getLength() > 2);
}

void XSheetCellRanges::testGetRangeAddressesAsString()
{
    uno::Reference< sheet::XSheetCellRanges > xSheetCellRanges(init(), UNO_QUERY_THROW);
    CPPUNIT_ASSERT_MESSAGE("Unable to get RangeAddresses (string)",
                           xSheetCellRanges->getRangeAddressesAsString().indexOf("C1:D4") > 0);
}

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */