Kaydet (Commit) 80003831 authored tarafından Jens Carl's avatar Jens Carl Kaydeden (comit) Markus Mohrhard

tdf#45904 Move _XSubTotalCalculatable Java tests to C++

Change-Id: I18199a9cc79e6a109c8de0026b37a67f85cf778a
Reviewed-on: https://gerrit.libreoffice.org/42265Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst a060947e
/* -*- 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/.
*/
#ifndef INCLUDED_TEST_SHEET_XSUBTOTALCALCULATABLE_HXX
#define INCLUDED_TEST_SHEET_XSUBTOTALCALCULATABLE_HXX
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <test/testdllapi.hxx>
using namespace css;
using namespace css::uno;
namespace apitest {
class OOO_DLLPUBLIC_TEST XSubTotalCalculatable
{
public:
virtual uno::Reference< css::uno::XInterface > init() = 0;
virtual uno::Reference< css::uno::XInterface > getXSpreadsheet() = 0;
void testCreateSubTotalDescriptor();
void testApplyRemoveSubTotals();
protected:
~XSubTotalCalculatable() {}
};
}
#endif // INCLUDED_TEST_SHEET_XSUBTOTALCALCULATABLE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -632,7 +632,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
qadevOOo/tests/java/ifc/sheet/_XSheetPageBreak \
qadevOOo/tests/java/ifc/sheet/_XSpreadsheet \
qadevOOo/tests/java/ifc/sheet/_XSpreadsheetView \
qadevOOo/tests/java/ifc/sheet/_XSubTotalCalculatable \
qadevOOo/tests/java/ifc/style/_CharacterProperties \
qadevOOo/tests/java/ifc/style/_CharacterPropertiesAsian \
qadevOOo/tests/java/ifc/style/_CharacterPropertiesComplex \
......
......@@ -141,9 +141,6 @@
"ScCellCursorObj";"com::sun::star::table::XCellRange";"getCellByPosition()"
"ScCellCursorObj";"com::sun::star::table::XCellRange";"getCellRangeByPosition()"
"ScCellCursorObj";"com::sun::star::table::XCellRange";"getCellRangeByName()"
"ScCellCursorObj";"com::sun::star::sheet::XSubTotalCalculatable";"createSubTotalDescriptor()"
"ScCellCursorObj";"com::sun::star::sheet::XSubTotalCalculatable";"applySubTotals()"
"ScCellCursorObj";"com::sun::star::sheet::XSubTotalCalculatable";"removeSubTotals()"
"ScCellCursorObj";"com::sun::star::sheet::SheetCellRange";"Position"
"ScCellCursorObj";"com::sun::star::sheet::SheetCellRange";"Size"
"ScCellCursorObj";"com::sun::star::sheet::SheetCellRange";"ConditionalFormat"
......
......@@ -136,9 +136,6 @@
"ScCellRangeObj";"com::sun::star::table::XCellRange";"getCellByPosition()"
"ScCellRangeObj";"com::sun::star::table::XCellRange";"getCellRangeByPosition()"
"ScCellRangeObj";"com::sun::star::table::XCellRange";"getCellRangeByName()"
"ScCellRangeObj";"com::sun::star::sheet::XSubTotalCalculatable";"createSubTotalDescriptor()"
"ScCellRangeObj";"com::sun::star::sheet::XSubTotalCalculatable";"applySubTotals()"
"ScCellRangeObj";"com::sun::star::sheet::XSubTotalCalculatable";"removeSubTotals()"
"ScCellRangeObj";"com::sun::star::sheet::SheetCellRange";"Position"
"ScCellRangeObj";"com::sun::star::sheet::SheetCellRange";"Size"
"ScCellRangeObj";"com::sun::star::sheet::SheetCellRange";"ConditionalFormat"
......
......@@ -167,9 +167,6 @@
"ScTableSheetObj";"com::sun::star::table::XCellRange";"getCellByPosition()"
"ScTableSheetObj";"com::sun::star::table::XCellRange";"getCellRangeByPosition()"
"ScTableSheetObj";"com::sun::star::table::XCellRange";"getCellRangeByName()"
"ScTableSheetObj";"com::sun::star::sheet::XSubTotalCalculatable";"createSubTotalDescriptor()"
"ScTableSheetObj";"com::sun::star::sheet::XSubTotalCalculatable";"applySubTotals()"
"ScTableSheetObj";"com::sun::star::sheet::XSubTotalCalculatable";"removeSubTotals()"
"ScTableSheetObj";"com::sun::star::sheet::SheetCellRange";"Position"
"ScTableSheetObj";"com::sun::star::sheet::SheetCellRange";"Size"
"ScTableSheetObj";"com::sun::star::sheet::SheetCellRange";"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.Status;
import lib.StatusException;
import com.sun.star.sheet.SubTotalColumn;
import com.sun.star.sheet.XSpreadsheet;
import com.sun.star.sheet.XSubTotalCalculatable;
import com.sun.star.sheet.XSubTotalDescriptor;
import com.sun.star.uno.UnoRuntime;
public class _XSubTotalCalculatable extends MultiMethodTest {
public XSubTotalCalculatable oObj;
protected XSubTotalDescriptor desc;
protected XSpreadsheet oSheet;
@Override
protected void before() {
oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET");
if (oSheet == null) {
log.println("Object relation oSheet is missing");
log.println("Trying to query the needed Interface");
oSheet = UnoRuntime.queryInterface(
XSpreadsheet.class, tEnv.getTestObject());
if (oSheet == null) {
throw new StatusException(Status.failed(
"Object relation oSheet is missing"));
}
}
}
public void _applySubTotals() {
requiredMethod("createSubTotalDescriptor()");
boolean res = true;
try {
oSheet.getCellByPosition(0, 0).setFormula("first");
oSheet.getCellByPosition(1, 0).setFormula("second");
oSheet.getCellByPosition(0, 3).setFormula("");
oSheet.getCellByPosition(0, 1).setValue(5);
oSheet.getCellByPosition(0, 2).setValue(5);
oSheet.getCellByPosition(1, 1).setValue(17);
oSheet.getCellByPosition(1, 2).setValue(25);
oObj.applySubTotals(desc, true);
String formula = oSheet.getCellByPosition(0, 3).getFormula();
String expected = "=SUBTOTAL(9;$A$2:$A$3)";
res = formula.equals(expected);
if (!res) {
log.println("getting: " + formula);
log.println("expected: " + expected);
}
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
log.println("Couldn't fill cells" + e.getLocalizedMessage());
res = false;
}
tRes.tested("applySubTotals()", res);
}
public void _createSubTotalDescriptor() {
desc = oObj.createSubTotalDescriptor(true);
SubTotalColumn[] columns = new SubTotalColumn[1];
columns[0] = new SubTotalColumn();
columns[0].Column = 0;
columns[0].Function = com.sun.star.sheet.GeneralFunction.SUM;
desc.addNew(columns, 0);
tRes.tested("createSubTotalDescriptor()", true);
}
public void _removeSubTotals() {
requiredMethod("applySubTotals()");
boolean res = true;
try {
oObj.removeSubTotals();
String formula = oSheet.getCellByPosition(0, 3).getFormula();
String expected = "";
res = formula.equals(expected);
if (!res) {
log.println("getting: " + formula);
log.println("expected: " + expected);
}
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
log.println("Couldn't get cell" + e.getLocalizedMessage());
}
tRes.tested("removeSubTotals()", res);
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@
#include <test/sheet/xcellseries.hxx>
#include <test/sheet/xusedareacursor.hxx>
#include <test/sheet/xuniquecellformatrangessupplier.hxx>
#include <test/sheet/xsubtotalcalculatable.hxx>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
......@@ -21,9 +22,11 @@ using namespace css::uno;
namespace sc_apitest {
#define NUMBER_OF_TESTS 5
#define NUMBER_OF_TESTS 7
class ScCellCursorObj : public CalcUnoApiTest, private apitest::XCellSeries, public apitest::XUsedAreaCursor, public apitest::XUniqueCellFormatRangesSupplier
class ScCellCursorObj : public CalcUnoApiTest,
public apitest::XCellSeries, public apitest::XUsedAreaCursor,
public apitest::XUniqueCellFormatRangesSupplier, public apitest::XSubTotalCalculatable
{
public:
ScCellCursorObj();
......@@ -46,6 +49,10 @@ public:
// XUniqueCellFormatRangesSupplier
CPPUNIT_TEST(testGetUniqueCellFormatRanges);
// XSubTotalCalculatable
CPPUNIT_TEST(testCreateSubTotalDescriptor);
CPPUNIT_TEST(testApplyRemoveSubTotals);
CPPUNIT_TEST_SUITE_END();
private:
......
......@@ -13,6 +13,7 @@
#include <test/sheet/xcellrangesquery.hxx>
#include <test/sheet/xcellseries.hxx>
#include <test/sheet/xuniquecellformatrangessupplier.hxx>
#include <test/sheet/xsubtotalcalculatable.hxx>
#include <test/util/xreplaceable.hxx>
#include <test/util/xsearchable.hxx>
......@@ -28,11 +29,12 @@ using namespace css::uno;
namespace sc_apitest {
#define NUMBER_OF_TESTS 18
#define NUMBER_OF_TESTS 20
class ScCellRangeObj : public CalcUnoApiTest, public apitest::XCellRangesQuery, public apitest::CellProperties,
public apitest::XSearchable, public apitest::XReplaceable, public apitest::XCellRangeData,
public apitest::XCellSeries, public apitest::XUniqueCellFormatRangesSupplier
public apitest::XCellSeries, public apitest::XUniqueCellFormatRangesSupplier,
public apitest::XSubTotalCalculatable
{
public:
ScCellRangeObj();
......@@ -41,6 +43,7 @@ public:
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);
......@@ -80,6 +83,10 @@ public:
// XUniqueCellFormatRangesSupplier
CPPUNIT_TEST(testGetUniqueCellFormatRanges);
// XSubTotalCalculatable
CPPUNIT_TEST(testCreateSubTotalDescriptor);
CPPUNIT_TEST(testApplyRemoveSubTotals);
CPPUNIT_TEST_SUITE_END();
private:
......@@ -118,6 +125,21 @@ uno::Reference< uno::XInterface > ScCellRangeObj::init()
return xReturn;
}
uno::Reference< uno::XInterface > ScCellRangeObj::getXSpreadsheet()
{
OUString aFileURL;
const OUString aFileBase("xcellrangesquery.ods");
createFileURL(aFileBase, aFileURL);
std::cout << OUStringToOString(aFileURL, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
if( !mxComponent.is())
mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument");
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;
}
uno::Reference< uno::XInterface > ScCellRangeObj::getXCellRangeData()
{
OUString aFileURL;
......
......@@ -13,6 +13,7 @@
#include <test/sheet/xuniquecellformatrangessupplier.hxx>
#include <test/util/xreplaceable.hxx>
#include <test/util/xsearchable.hxx>
#include <test/sheet/xsubtotalcalculatable.hxx>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
......@@ -23,9 +24,12 @@ using namespace css::uno;
namespace sc_apitest
{
#define NUMBER_OF_TESTS 10
#define NUMBER_OF_TESTS 12
class ScTableSheetObj : public CalcUnoApiTest, public apitest::XSearchable, public apitest::XReplaceable, public apitest::XPrintAreas, public apitest::XCellSeries, public apitest::XUniqueCellFormatRangesSupplier
class ScTableSheetObj : public CalcUnoApiTest,
public apitest::XSearchable, public apitest::XReplaceable,
public apitest::XPrintAreas, public apitest::XCellSeries,
public apitest::XUniqueCellFormatRangesSupplier, public apitest::XSubTotalCalculatable
{
public:
ScTableSheetObj();
......@@ -34,6 +38,7 @@ public:
virtual void tearDown() override;
virtual uno::Reference< uno::XInterface > init() override;
virtual uno::Reference< uno::XInterface > getXSpreadsheet() override;
CPPUNIT_TEST_SUITE(ScTableSheetObj);
......@@ -57,6 +62,10 @@ public:
// XUniqueCellFormatRangesSupplier
CPPUNIT_TEST(testGetUniqueCellFormatRanges);
// XSubTotalCalculatable
CPPUNIT_TEST(testCreateSubTotalDescriptor);
CPPUNIT_TEST(testApplyRemoveSubTotals);
CPPUNIT_TEST_SUITE_END();
private:
......@@ -90,6 +99,21 @@ uno::Reference< uno::XInterface > ScTableSheetObj::init()
return xSheet;
}
uno::Reference< uno::XInterface > ScTableSheetObj::getXSpreadsheet()
{
OUString aFileURL;
createFileURL("ScTableSheetObj.ods", aFileURL);
if(!mxComponent.is())
mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument");
CPPUNIT_ASSERT(mxComponent.is());
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(1), UNO_QUERY_THROW);
return xSheet;
}
void ScTableSheetObj::setUp()
{
nTest++;
......
......@@ -77,6 +77,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\
test/source/sheet/xviewpane \
test/source/sheet/xviewfreezable \
test/source/sheet/xviewsplitable \
test/source/sheet/xsubtotalcalculatable \
test/source/sheet/xsubtotaldescriptor \
test/source/text/xtext \
test/source/text/xtextfield \
......
/* -*- 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/xsubtotalcalculatable.hxx>
#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/XSubTotalCalculatable.hpp>
#include <com/sun/star/sheet/XSubTotalDescriptor.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 XSubTotalCalculatable::testCreateSubTotalDescriptor()
{
uno::Reference< sheet::XSubTotalCalculatable > xSTC(init(), 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;
CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to create XSubTotalDescriptor", xSTD->addNew(xCols, 1));
}
void XSubTotalCalculatable::testApplyRemoveSubTotals()
{
uno::Reference< sheet::XSpreadsheet > xSheet(getXSpreadsheet(), UNO_QUERY_THROW);
uno::Reference< sheet::XSubTotalCalculatable > xSTC(xSheet, UNO_QUERY_THROW);
uno::Reference< sheet::XSubTotalDescriptor > xSTD = xSTC->createSubTotalDescriptor(true);
uno::Sequence< sheet::SubTotalColumn > xCols;
xCols.realloc(1);
xCols[0].Column = 0;
xCols[0].Function = sheet::GeneralFunction_SUM;
xSTD->addNew(xCols, 0);
xSheet->getCellByPosition(0, 0)->setFormula("first");
xSheet->getCellByPosition(1, 0)->setFormula("second");
xSheet->getCellByPosition(0, 3)->setFormula("");
xSheet->getCellByPosition(0, 1)->setValue(5);
xSheet->getCellByPosition(0, 2)->setValue(5);
xSheet->getCellByPosition(1, 1)->setValue(17);
xSheet->getCellByPosition(1, 2)->setValue(17);
xSTC->applySubTotals(xSTD, true);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to apply SubTotals",
OUString("=SUBTOTAL(9;$A$2:$A$3)"),
xSheet->getCellByPosition(0, 3)->getFormula());
xSTC->removeSubTotals();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove SubTotals",
OUString(""),
xSheet->getCellByPosition(0, 3)->getFormula());
}
}
/* 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