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

tdf#45904 Move _FunctionDescription Java tests to C++

Change-Id: Ib4baf75dddb3b63bab25ab13967a20c65d692ce2
Reviewed-on: https://gerrit.libreoffice.org/52613Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJens Carl <j.carl43@gmx.de>
üst 3fb48f0b
/* -*- 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_FUNCTIONDESCRIPTION_HXX
#define INCLUDED_TEST_SHEET_FUNCTIONDESCRIPTION_HXX
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/uno/Sequence.hxx>
#include <test/testdllapi.hxx>
namespace apitest
{
class OOO_DLLPUBLIC_TEST FunctionDescription
{
public:
virtual css::uno::Sequence<css::beans::PropertyValue> init() = 0;
void testFunctionDescriptionProperties();
protected:
~FunctionDescription() {}
};
}
#endif // INCLUDED_TEST_SHEET_FUNCTIONDESCRIPTION_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -562,7 +562,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\ ...@@ -562,7 +562,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryAnalyzer \ qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryAnalyzer \
qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryComposer \ qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryComposer \
qadevOOo/tests/java/ifc/sdb/_XSQLErrorBroadcaster \ qadevOOo/tests/java/ifc/sdb/_XSQLErrorBroadcaster \
qadevOOo/tests/java/ifc/sheet/_FunctionDescription \
qadevOOo/tests/java/ifc/sheet/_SheetSortDescriptor \ qadevOOo/tests/java/ifc/sheet/_SheetSortDescriptor \
qadevOOo/tests/java/ifc/sheet/_SpreadsheetDocument \ qadevOOo/tests/java/ifc/sheet/_SpreadsheetDocument \
qadevOOo/tests/java/ifc/sheet/_TableAutoFormatField \ qadevOOo/tests/java/ifc/sheet/_TableAutoFormatField \
...@@ -1003,7 +1002,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\ ...@@ -1003,7 +1002,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
qadevOOo/tests/java/mod/_sc/ScDrawPageObj \ qadevOOo/tests/java/mod/_sc/ScDrawPageObj \
qadevOOo/tests/java/mod/_sc/ScDrawPagesObj \ qadevOOo/tests/java/mod/_sc/ScDrawPagesObj \
qadevOOo/tests/java/mod/_sc/ScFilterDescriptorBase \ qadevOOo/tests/java/mod/_sc/ScFilterDescriptorBase \
qadevOOo/tests/java/mod/_sc/ScFunctionDescriptionObj \
qadevOOo/tests/java/mod/_sc/ScFunctionListObj \ qadevOOo/tests/java/mod/_sc/ScFunctionListObj \
qadevOOo/tests/java/mod/_sc/ScHeaderFieldObj \ qadevOOo/tests/java/mod/_sc/ScHeaderFieldObj \
qadevOOo/tests/java/mod/_sc/ScHeaderFieldsObj \ qadevOOo/tests/java/mod/_sc/ScHeaderFieldsObj \
......
/*
* 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 util.ValueChanger;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.sheet.FunctionArgument;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
/**
* Testing <code>com.sun.star.sheet.FunctionDescription</code>
* service properties:
* <ul>
* <li><code>Arguments</code></li>
* <li><code>Category</code></li>
* <li><code>Description</code></li>
* <li><code>Id</code></li>
* <li><code>Name</code></li>
* </ul> <p>
* @see com.sun.star.sheet.FunctionDescription
*/
public class _FunctionDescription extends MultiMethodTest {
public XPropertySet oObj = null; // oObj filled by MultiMethodTest
public void _Arguments() {
// check if Service is available
XServiceInfo xInfo = UnoRuntime.queryInterface(XServiceInfo.class, oObj );
if ( ! xInfo.supportsService
( "com.sun.star.sheet.FunctionDescription" ) ) {
log.println( "Service not available !" );
tRes.tested( "Supported", false );
}
try {
XMultiServiceFactory oDocMSF = tParam.getMSF();
XInterface FA = (XInterface)oDocMSF.
createInstance("com.sun.star.sheet.FunctionArgument");
FunctionArgument arg = (FunctionArgument)AnyConverter.toObject
(FunctionArgument.class, FA);
arg.Description = "FunctionDescription argument description" ;
arg.Name = "FunctionDescriptiuon argument name" ;
arg.IsOptional = true ;
Object sValue = oObj.getPropertyValue("Arguments") ;
oObj.setPropertyValue("Arguments", new FunctionArgument[] {arg}) ;
Object nValue = oObj.getPropertyValue("Arguments") ;
if (sValue.equals(nValue)) {
log.println("Property 'Arguments' didn't change: OK") ;
tRes.tested("Arguments", true) ;
} else {
log.println("Readonly property 'Arguments' changed: Failed") ;
tRes.tested("Arguments", false) ;
}
} catch (Exception e) {
log.println(
"Exception occurred while testing property 'Arguments'" );
e.printStackTrace( log );
tRes.tested( "Arguments", false );
}
}
public void _Category() {
tryChangeProp("Category") ;
}
public void _Description() {
tryChangeProp( "Category" );
}
public void _Id() {
tryChangeProp( "Id" );
}
public void _Name() {
tryChangeProp( "Name" );
}
public void tryChangeProp( String name ) {
Object gValue = null;
Object sValue = null;
Object ValueToSet = null;
try {
gValue = oObj.getPropertyValue( name );
ValueToSet = ValueChanger.changePValue( gValue );
oObj.setPropertyValue( name, ValueToSet );
sValue = oObj.getPropertyValue( name );
//check get-set methods
if( gValue.equals( sValue ) ) {
log.println( "Value for '"+name+"' hasn't changed. OK." );
tRes.tested( name, true );
}
else {
log.println( "Property '" + name +
"' changes its value : Failed !" );
tRes.tested( name, false );
}
}
catch ( Exception e ) {
log.println(
"Exception occurred while testing property '" + name + "'" );
e.printStackTrace( log );
tRes.tested( name, false );
}
} // end of changeProp
} //finish class _TextContent
/*
* 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 java.util.Random;
import lib.TestCase;
import lib.TestEnvironment;
import lib.TestParameters;
import util.SOfficeFactory;
import com.sun.star.container.XNameAccess;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
public class ScFunctionDescriptionObj extends TestCase {
private XSpreadsheetDocument xSheetDoc = null;
@Override
protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
log.println( "creating a Spreadsheet document" );
xSheetDoc = SOF.createCalcDoc(null);
}
@Override
protected void cleanup( TestParameters tParam, PrintWriter log ) {
log.println( " disposing xSheetDoc " );
XComponent oComp = UnoRuntime.
queryInterface (XComponent.class, xSheetDoc) ;
util.DesktopTools.closeDoc(oComp);
}
/**
* creating a TestEnvironment for the interfaces to be tested
*/
@Override
public TestEnvironment createTestEnvironment(
TestParameters Param, PrintWriter log )
throws Exception {
XInterface oObj = null;
// creation of testobject here
// first we write what we are intend to do to log file
log.println( "Creating a test environment" );
log.println("Getting test object ") ;
XMultiServiceFactory oDocMSF = Param.getMSF();
XInterface FDs = (XInterface)oDocMSF.
createInstance("com.sun.star.sheet.FunctionDescriptions");
XNameAccess NA = UnoRuntime.queryInterface
(XNameAccess.class, FDs);
String names[] = NA.getElementNames();
Random rnd = new Random();
int idx = rnd.nextInt(names.length);
oObj = (XInterface)NA.getByName(names[idx]);
log.println("Creating object - " +
((oObj == null) ? "FAILED" : "OK"));
TestEnvironment tEnv = new TestEnvironment( oObj );
// Other parameters required for interface tests
return tEnv;
}
}
# -*- 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_functiondescriptionobj))
$(eval $(call gb_CppunitTest_use_external,sc_functiondescriptionobj,boost_headers))
$(eval $(call gb_CppunitTest_add_exception_objects,sc_functiondescriptionobj, \
sc/qa/extras/scfunctiondescriptionobj \
))
$(eval $(call gb_CppunitTest_use_libraries,sc_functiondescriptionobj, \
cppu \
sal \
subsequenttest \
test \
unotest \
))
$(eval $(call gb_CppunitTest_set_include,sc_functiondescriptionobj,\
$$(INCLUDE) \
))
$(eval $(call gb_CppunitTest_use_sdk_api,sc_functiondescriptionobj))
$(eval $(call gb_CppunitTest_use_ure,sc_functiondescriptionobj))
$(eval $(call gb_CppunitTest_use_vcl,sc_functiondescriptionobj))
$(eval $(call gb_CppunitTest_use_components,sc_functiondescriptionobj,\
$(sc_unoapi_common_components) \
))
$(eval $(call gb_CppunitTest_use_configuration,sc_functiondescriptionobj))
# vim: set noet sw=4 ts=4:
...@@ -158,6 +158,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\ ...@@ -158,6 +158,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\
CppunitTest_sc_sheetlinkobj \ CppunitTest_sc_sheetlinkobj \
CppunitTest_sc_spreadsheetsettingsobj \ CppunitTest_sc_spreadsheetsettingsobj \
CppunitTest_sc_ddelinkobj \ CppunitTest_sc_ddelinkobj \
CppunitTest_sc_functiondescriptionobj \
)) ))
$(eval $(call gb_Module_add_perfcheck_targets,sc,\ $(eval $(call gb_Module_add_perfcheck_targets,sc,\
......
/* -*- 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/calc_unoapi_test.hxx>
#include <test/sheet/functiondescription.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/sheet/XFunctionDescriptions.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/uno/Reference.hxx>
using namespace css;
using namespace css::uno;
using namespace com::sun::star;
namespace sc_apitest
{
class ScFunctionDescriptionObj : public CalcUnoApiTest, public apitest::FunctionDescription
{
public:
ScFunctionDescriptionObj();
virtual uno::Sequence<beans::PropertyValue> init() override;
virtual void setUp() override;
virtual void tearDown() override;
CPPUNIT_TEST_SUITE(ScFunctionDescriptionObj);
// FunctionDescription
CPPUNIT_TEST(testFunctionDescriptionProperties);
CPPUNIT_TEST_SUITE_END();
private:
uno::Reference<lang::XComponent> mxComponent;
};
ScFunctionDescriptionObj::ScFunctionDescriptionObj()
: CalcUnoApiTest("/sc/qa/extras/testdocuments")
{
}
uno::Sequence<beans::PropertyValue> ScFunctionDescriptionObj::init()
{
uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW);
uno::Reference<sheet::XFunctionDescriptions> xFDs(
xMSF->createInstance("com.sun.star.sheet.FunctionDescriptions"), UNO_QUERY_THROW);
uno::Reference<container::XNameAccess> xNA(xFDs, UNO_QUERY_THROW);
uno::Sequence<OUString> names = xNA->getElementNames();
uno::Sequence<beans::PropertyValue> sPropertyValues;
CPPUNIT_ASSERT(xNA->getByName(names[0]) >>= sPropertyValues);
return sPropertyValues;
}
void ScFunctionDescriptionObj::setUp()
{
CalcUnoApiTest::setUp();
// create a calc document
mxComponent = loadFromDesktop("private:factory/scalc");
}
void ScFunctionDescriptionObj::tearDown()
{
closeDocument(mxComponent);
CalcUnoApiTest::tearDown();
}
CPPUNIT_TEST_SUITE_REGISTRATION(ScFunctionDescriptionObj);
} // end namespace
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -55,6 +55,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ ...@@ -55,6 +55,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\
test/source/sheet/datapilotfield \ test/source/sheet/datapilotfield \
test/source/sheet/datapilotitem \ test/source/sheet/datapilotitem \
test/source/sheet/documentsettings \ test/source/sheet/documentsettings \
test/source/sheet/functiondescription \
test/source/sheet/globalsheetsettings \ test/source/sheet/globalsheetsettings \
test/source/sheet/scenario \ test/source/sheet/scenario \
test/source/sheet/spreadsheetdocumentsettings \ test/source/sheet/spreadsheetdocumentsettings \
......
/* -*- 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 <vector>
#include <test/sheet/functiondescription.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/sheet/FunctionArgument.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <cppunit/extensions/HelperMacros.h>
using namespace com::sun::star;
using namespace com::sun::star::uno;
namespace apitest
{
void FunctionDescription::testFunctionDescriptionProperties()
{
uno::Sequence<beans::PropertyValue> aFunctionDescription(init());
std::vector<OUString> names;
// Only test the the get/read operation of the values, because set/write operation doesn't
// make any sense. It doesn't trigger any changes.
// See discussion: nabble.documentfoundation.org/Testing-UNO-API-service-properties-td4236286.html.
for (auto& value : aFunctionDescription)
{
if (value.Name == "Id")
{
names.push_back(value.Name);
sal_Int32 nValue = 0;
CPPUNIT_ASSERT(value.Value >>= nValue);
}
else if (value.Name == "Category")
{
names.push_back(value.Name);
sal_Int32 nValue = 0;
CPPUNIT_ASSERT(value.Value >>= nValue);
}
else if (value.Name == "Name")
{
names.push_back(value.Name);
OUString sValue;
CPPUNIT_ASSERT(value.Value >>= sValue);
}
else if (value.Name == "Description")
{
names.push_back(value.Name);
OUString sValue;
CPPUNIT_ASSERT(value.Value >>= sValue);
}
else if (value.Name == "Arguments")
{
names.push_back(value.Name);
uno::Sequence<sheet::FunctionArgument> sArguments;
CPPUNIT_ASSERT(value.Value >>= sArguments);
}
else
{
OString aMsg = "Unsupported PropertyValue: "
+ OUStringToOString(value.Name, RTL_TEXTENCODING_UTF8);
CPPUNIT_FAIL(aMsg.getStr());
}
}
CPPUNIT_ASSERT_MESSAGE("Property Id not found",
std::count(std::begin(names), std::end(names), "Id"));
CPPUNIT_ASSERT_MESSAGE("Property Category not found",
std::count(std::begin(names), std::end(names), "Category"));
CPPUNIT_ASSERT_MESSAGE("Property Name not found",
std::count(std::begin(names), std::end(names), "Name"));
CPPUNIT_ASSERT_MESSAGE("Property Description not found",
std::count(std::begin(names), std::end(names), "Description"));
CPPUNIT_ASSERT_MESSAGE("Property Arguments not found",
std::count(std::begin(names), std::end(names), "Arguments"));
}
} // 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