Kaydet (Commit) 4ad3b5cd authored tarafından Jens Carl's avatar Jens Carl

tdf#45904 Move XNameReplace Java tests to C++

Move XNameReplace Java tests to C++ for ScStyleFamilyObj.
Fixes i#23594 by creating a new "com.sun.star.style.CellStyle"
rather then using an existing one.

Change-Id: Ie42e627020aff475173af5bc014bc28d7a11ec56
Reviewed-on: https://gerrit.libreoffice.org/69140
Tested-by: Jenkins
Reviewed-by: 's avatarJens Carl <j.carl43@gmx.de>
üst bea44e5c
......@@ -80,7 +80,6 @@ job88=sc.ScDatabaseRangeObj
job98=sc.ScHeaderFieldObj
job99=sc.ScHeaderFieldsObj
job126=sc.ScSheetLinkObj
job131=sc.ScStyleFamilyObj
job132=sc.ScStyleObj
job134=sc.ScTableColumnObj
job135=sc.ScTableColumnsObj
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
......@@ -11,32 +11,42 @@
#define INCLUDED_TEST_CONTAINER_XNAMEREPLACE_HXX
#include <rtl/ustring.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <test/testdllapi.hxx>
#include <com/sun/star/uno/Any.hxx>
namespace apitest {
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Any.hxx>
namespace apitest
{
class OOO_DLLPUBLIC_TEST XNameReplace
{
public:
XNameReplace(const OUString& rName): maTestReplacementName(rName) {}
virtual css::uno::Reference< css::uno::XInterface > init() = 0;
XNameReplace(const OUString& rName)
: m_aReplacementName(rName)
{
}
virtual css::uno::Reference<css::uno::XInterface> init() = 0;
void testReplaceByName();
virtual css::uno::Any getAnyElementForNameReplace() = 0;
void setReplacmentElement(const css::uno::Any& rElement)
{
m_aReplacementElement = rElement;
}
virtual ~XNameReplace() {}
private:
OUString const maTestReplacementName;
protected:
~XNameReplace() {}
private:
OUString const m_aReplacementName;
css::uno::Any m_aReplacementElement;
};
}
} // namespace apitest
#endif // INCLUDED_TEST_CONTAINER_XNAMEREPLACE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -970,7 +970,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
qadevOOo/tests/java/mod/_sc/ScModelObj \
qadevOOo/tests/java/mod/_sc/ScShapeObj \
qadevOOo/tests/java/mod/_sc/ScSheetLinkObj \
qadevOOo/tests/java/mod/_sc/ScStyleFamilyObj \
qadevOOo/tests/java/mod/_sc/ScStyleObj \
qadevOOo/tests/java/mod/_sc/ScSubTotalDescriptorBase \
qadevOOo/tests/java/mod/_sc/ScTableColumnObj \
......
"ScStyleFamilyObj";"com::sun::star::container::XNameReplace#optional";"replaceByName()"
/*
* 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 mod._sc;
import java.io.PrintWriter;
import lib.TestCase;
import lib.TestEnvironment;
import lib.TestParameters;
import util.SOfficeFactory;
import com.sun.star.container.XIndexAccess;
import com.sun.star.container.XNameAccess;
import com.sun.star.container.XNameContainer;
import com.sun.star.lang.XComponent;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.style.XStyleFamiliesSupplier;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
/**
* Test for object which is represented by service
* <code>com.sun.star.style.StyleFamily</code>. <p>
* Object implements the following interfaces :
* <ul>
* <li> <code>com::sun::star::container::XNameContainer</code></li>
* <li> <code>com::sun::star::container::XNameAccess</code></li>
* <li> <code>com::sun::star::container::XElementAccess</code></li>
* <li> <code>com::sun::star::container::XIndexAccess</code></li>
* <li> <code>com::sun::star::container::XNameReplace</code></li>
* </ul>
* @see com.sun.star.style.StyleFamily
* @see com.sun.star.container.XNameContainer
* @see com.sun.star.container.XNameAccess
* @see com.sun.star.container.XElementAccess
* @see com.sun.star.container.XIndexAccess
* @see com.sun.star.container.XNameReplace
* @see ifc.container._XNameContainer
* @see ifc.container._XNameAccess
* @see ifc.container._XElementAccess
* @see ifc.container._XIndexAccess
* @see ifc.container._XNameReplace
*/
public class ScStyleFamilyObj extends TestCase {
private XSpreadsheetDocument xSpreadsheetDoc = null;
/**
* Creates Spreadsheet document.
*/
@Override
protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
log.println( "creating a Spreadsheet document" );
xSpreadsheetDoc = SOF.createCalcDoc(null);
}
/**
* Disposes Spreadsheet document.
*/
@Override
protected void cleanup( TestParameters tParam, PrintWriter log ) {
log.println( " disposing xSheetDoc " );
XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
util.DesktopTools.closeDoc(oComp);
}
/**
* Creating a TestEnvironment for the interfaces to be tested.
* Retrieves the collection of style families from the document
* using the interface <code>XStyleFamiliesSupplier</code>.
* Obtains style family with index 0 from the collection.
* Creates the two instance of the service <code>com.sun.star.style.CellStyle</code>.
* One of the instance uses for inserting of new style to the obtained style
* family that is the instance of the service
* <code>com.sun.star.style.StyleFamily</code>.
* Object relations created :
* <ul>
* <li> <code>'SecondInstance'</code> for
* {@link ifc.container._XNameContainer}(the second created instance of
* the service <code>com.sun.star.style.CellStyle</code>)</li>
* <li> <code>'XNameReplaceINDEX'</code> for
* {@link ifc.container._XNameContainer}(the number of the current
* running threads multiplied by two)</li>
* <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
* {@link ifc.container._XNameContainer}(the created instances of
* the service <code>com.sun.star.style.CellStyle</code>)</li>
* </ul>
* @see com.sun.star.style.CellStyle
*/
@Override
protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
// creation of testobject here
// first we write what we are intend to do to log file
log.println( "creating a test environment" );
XNameAccess oStyleFamilyNameAccess = null;
// create testobject here
log.println("getting style");
XStyleFamiliesSupplier oStyleFamiliesSupplier = UnoRuntime.queryInterface(
XStyleFamiliesSupplier.class, xSpreadsheetDoc);
XNameAccess oStyleFamilies = oStyleFamiliesSupplier.getStyleFamilies();
XIndexAccess oStyleFamiliesIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, oStyleFamilies);
oStyleFamilyNameAccess = (XNameAccess) AnyConverter.toObject(
new Type(XNameAccess.class),
oStyleFamiliesIndexAccess.getByIndex(0));
SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
XComponent xComp = UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc);
XInterface oInstance = (XInterface)
SOF.createInstance(xComp,"com.sun.star.style.CellStyle");
// insert a Style which can be replaced by name
XNameContainer oContainer = UnoRuntime.queryInterface(
XNameContainer.class, oStyleFamilyNameAccess);
oContainer.insertByName("ScStyleFamilyObj", oInstance);
TestEnvironment tEnv = new TestEnvironment(oStyleFamilyNameAccess);
oInstance = (XInterface)
SOF.createInstance(xComp, "com.sun.star.style.CellStyle");
//second instance for insertByName in XNameContainer
tEnv.addObjRelation("SecondInstance", oInstance);
int THRCNT = 1;
if ((String)tParam.get("THRCNT") != null) {
THRCNT = Integer.parseInt((String)tParam.get("THRCNT"));
}
log.println( "adding XNameReplaceINDEX as mod relation to environment" );
tEnv.addObjRelation("XNameReplaceINDEX", Integer.toString(2*THRCNT));
// INSTANCEn : _XNameContainer; _XNameReplace
log.println( "adding INSTANCEn as mod relation to environment" );
for (int n = 1; n < 2*(THRCNT+1) ;n++ ) {
log.println( "adding INSTANCE" + n +
" as mod relation to environment" );
tEnv.addObjRelation("INSTANCE" + n, SOF.createInstance(
xComp,"com.sun.star.style.CellStyle"));
}
// NAMEREPLACE : _XNameReplace
log.println("adding NAMEREPLACE as mod relation to environment");
String cName = "ScStyleFamilyObj";
tEnv.addObjRelation("NAMEREPLACE", cName);
return tEnv;
} // finish method getTestEnvironment
} // finish class ScStyleFamilyObj
......@@ -12,6 +12,7 @@
#include <test/container/xindexaccess.hxx>
#include <test/container/xnameaccess.hxx>
#include <test/container/xnamecontainer.hxx>
#include <test/container/xnamereplace.hxx>
#include <cppu/unotype.hxx>
#include <com/sun/star/container/XIndexAccess.hpp>
......@@ -34,7 +35,8 @@ class ScStyleFamilyObj : public CalcUnoApiTest,
public apitest::XElementAccess,
public apitest::XIndexAccess,
public apitest::XNameAccess,
public apitest::XNameContainer
public apitest::XNameContainer,
public apitest::XNameReplace
{
public:
ScStyleFamilyObj();
......@@ -65,6 +67,9 @@ public:
CPPUNIT_TEST(testRemoveByName);
CPPUNIT_TEST(testRemoveByNameNoneExistingElement);
// XNameReplace
CPPUNIT_TEST(testReplaceByName);
CPPUNIT_TEST_SUITE_END();
private:
......@@ -77,6 +82,7 @@ ScStyleFamilyObj::ScStyleFamilyObj()
, XIndexAccess(19)
, XNameAccess("Default")
, XNameContainer("Default")
, XNameReplace("Default")
{
}
......@@ -94,6 +100,8 @@ uno::Reference<uno::XInterface> ScStyleFamilyObj::init()
uno::UNO_QUERY_THROW);
// XNameContainer
setElement(uno::makeAny(xMSF->createInstance("com.sun.star.style.CellStyle")));
// XNameReplace
setReplacmentElement(uno::makeAny(xMSF->createInstance("com.sun.star.style.CellStyle")));
uno::Reference<container::XNameContainer> xNC(xNA_SF, uno::UNO_QUERY_THROW);
xNC->insertByName("ScStyleFamilyObj", uno::makeAny(xCS));
......
......@@ -18,4 +18,3 @@
-o sc.ScModelObj
# -o sc.ScShapeObj
# -o sc.ScSheetLinkObj
-o sc.ScStyleFamilyObj
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
......@@ -8,22 +8,30 @@
*/
#include <test/container/xnamereplace.hxx>
#include <com/sun/star/container/XNameReplace.hpp>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <cppunit/extensions/HelperMacros.h>
using namespace css;
using namespace css::uno;
namespace apitest {
namespace apitest
{
void XNameReplace::testReplaceByName()
{
uno::Reference< container::XNameReplace > xNameReplace(init(), UNO_QUERY_THROW);
xNameReplace->replaceByName(maTestReplacementName, getAnyElementForNameReplace());
Any aAny = xNameReplace->getByName( maTestReplacementName );
uno::Reference< uno::XInterface > xElement(aAny, UNO_QUERY_THROW);
}
uno::Reference<container::XNameReplace> xNameReplace(init(), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_NO_THROW(xNameReplace->replaceByName(m_aReplacementName, m_aReplacementElement));
uno::Any aAny = xNameReplace->getByName(m_aReplacementName);
// we deliberately avoid uno::UNO_QUERY_THROW, so a test on .is() can be made
uno::Reference<uno::XInterface> xElement(aAny, uno::UNO_QUERY);
CPPUNIT_ASSERT(xElement.is());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
} // namespace apitest
/* 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