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

tdf#45904 Move _DatabaseImportDescriptor Java tests to C++

Change-Id: I53e9a449cb18c26187f3b1676f8ab67918128499
Reviewed-on: https://gerrit.libreoffice.org/47447Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJens Carl <j.carl43@gmx.de>
üst c8fbce43
/* -*- 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_DATABASEIMPORTDESCRIPTOR_HXX
#define INCLUDED_TEST_SHEET_DATABASEIMPORTDESCRIPTOR_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 DatabaseImportDescriptor
{
public:
virtual css::uno::Reference<css::uno::XInterface> init() = 0;
virtual css::uno::Reference<css::uno::XInterface> getXImportable() = 0;
void testDatabaseImportDescriptorProperties();
protected:
~DatabaseImportDescriptor() {}
};
}
#endif // INCLUDED_TEST_SHEET_DATABASEIMPORTDESCRIPTOR_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -563,7 +563,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\ ...@@ -563,7 +563,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/_DatabaseImportDescriptor \
qadevOOo/tests/java/ifc/sheet/_DocumentSettings \ qadevOOo/tests/java/ifc/sheet/_DocumentSettings \
qadevOOo/tests/java/ifc/sheet/_FunctionDescription \ qadevOOo/tests/java/ifc/sheet/_FunctionDescription \
qadevOOo/tests/java/ifc/sheet/_GlobalSheetSettings \ qadevOOo/tests/java/ifc/sheet/_GlobalSheetSettings \
...@@ -1029,7 +1028,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\ ...@@ -1029,7 +1028,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
qadevOOo/tests/java/mod/_sc/ScHeaderFieldsObj \ qadevOOo/tests/java/mod/_sc/ScHeaderFieldsObj \
qadevOOo/tests/java/mod/_sc/ScHeaderFooterTextCursor \ qadevOOo/tests/java/mod/_sc/ScHeaderFooterTextCursor \
qadevOOo/tests/java/mod/_sc/ScHeaderFooterTextObj \ qadevOOo/tests/java/mod/_sc/ScHeaderFooterTextObj \
qadevOOo/tests/java/mod/_sc/ScImportDescriptorBase \
qadevOOo/tests/java/mod/_sc/ScIndexEnumeration_CellAnnotationsEnumeration \ qadevOOo/tests/java/mod/_sc/ScIndexEnumeration_CellAnnotationsEnumeration \
qadevOOo/tests/java/mod/_sc/ScIndexEnumeration_CellAreaLinksEnumeration \ qadevOOo/tests/java/mod/_sc/ScIndexEnumeration_CellAreaLinksEnumeration \
qadevOOo/tests/java/mod/_sc/ScIndexEnumeration_DatabaseRangesEnumeration \ qadevOOo/tests/java/mod/_sc/ScIndexEnumeration_DatabaseRangesEnumeration \
......
/*
* 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.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.util.XImportable;
/**
* Testing <code>com.sun.star.sheet.DatabaseImportDescriptor</code>
* service properties:
* <ul>
* <li><code>DatabaseName</code></li>
* <li><code>SourceObject</code></li>
* <li><code>SourceType</code></li>
* </ul> <p>
* @see com.sun.star.sheet.DatabaseImportDescriptor
*/
public class _DatabaseImportDescriptor extends MultiMethodTest {
public XPropertySet oObj = null;
public XImportable xIMP = null;
public PropertyValue[] props = null;
public void _DatabaseName() {
xIMP = (XImportable) tEnv.getObjRelation("xIMP");
props = xIMP.createImportDescriptor(true);
changeProp("DatabaseName",0);
}
public void _SourceObject() {
changeProp("SourceObject",2);
}
public void _SourceType() {
changeProp("SourceType",1);
}
public void changeProp(String name, int nr) {
Object gValue = null;
Object sValue = null;
Object ValueToSet = null;
if ( ! name.equals(props[nr].Name) ) {
log.println("Property '"+props[nr].Name+"' is tested");
log.println("But the status is for '"+name+"'");
}
try {
gValue = props[nr].Value;
ValueToSet = ValueChanger.changePValue(gValue);
props[nr].Value=ValueToSet;
sValue = props[nr].Value;
//check get-set methods
if ( (gValue.equals(sValue)) || (sValue == null) ) {
log.println("Value for '"+name+"' hasn't changed");
tRes.tested(name, false);
}
else {
log.println("Property '"+name+"' OK");
tRes.tested(name, true);
}
} catch (Exception e) {
log.println("Exception occurred while testing property '" +
name + "'");
e.printStackTrace(log);
tRes.tested(name, false);
}
}// end of changeProp
} // finish class _DatabaseImportDescriptor
/*
* 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.lang.XComponent;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.sheet.XSpreadsheets;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import com.sun.star.util.XImportable;
/**
*
* initial description
* @see com.sun.star.sheet.DatabaseImportDescriptor
*
*/
public class ScImportDescriptorBase extends TestCase {
XSpreadsheetDocument xSpreadsheetDoc;
/**
* in general this method creates a testdocument
*
* @param tParam class which contains additional test parameters
* @param log class to log the test state and result
*
*
* @see TestParameters
* @see PrintWriter
*
*/
@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);
}
/**
* in general this method disposes the testenvironment and document
*
* @param tParam class which contains additional test parameters
* @param log class to log the test state and result
*
*
* @see TestParameters
* @see PrintWriter
*
*/
@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
*
* @param tParam class which contains additional test parameters
* @param log class to log the test state and result
*
* @return Status class
*
* @see TestParameters
* @see PrintWriter
*/
@Override
public TestEnvironment createTestEnvironment( TestParameters tParam,
PrintWriter log )
throws Exception {
XInterface oObj = null;
XImportable xIMP = null;
// creation of testobject here
// first we write what we are intend to do to log file
log.println( "creating a test environment" );
// create testobject here
log.println("getting sheets");
XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets();
if (xSpreadsheets == null) log.println("FAILED"); else log.println("OK");
log.println("getting a sheet");
XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
oObj = UnoRuntime.queryInterface(XInterface.class,oIndexAccess.getByIndex(0));
xIMP = UnoRuntime.queryInterface(XImportable.class,oObj);
TestEnvironment tEnv = new TestEnvironment(oObj);
tEnv.addObjRelation("xIMP",xIMP);
return tEnv;
} // finish method getTestEnvironment
} // finish class ScImportDescriptorBase
# -*- 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_importdescriptorbaseobj))
$(eval $(call gb_CppunitTest_use_external,sc_importdescriptorbaseobj,boost_headers))
$(eval $(call gb_CppunitTest_add_exception_objects,sc_importdescriptorbaseobj, \
sc/qa/extras/scimportdescriptorbaseobj \
))
$(eval $(call gb_CppunitTest_use_libraries,sc_importdescriptorbaseobj, \
basegfx \
comphelper \
cppu \
cppuhelper \
drawinglayer \
editeng \
for \
forui \
i18nlangtag \
msfilter \
oox \
sal \
salhelper \
sax \
sb \
sc \
sfx \
sot \
subsequenttest \
svl \
svt \
svx \
svxcore \
test \
tk \
tl \
ucbhelper \
unotest \
utl \
vbahelper \
vcl \
xo \
))
$(eval $(call gb_CppunitTest_set_include,sc_importdescriptorbaseobj,\
-I$(SRCDIR)/sc/source/ui/inc \
-I$(SRCDIR)/sc/inc \
$$(INCLUDE) \
))
$(eval $(call gb_CppunitTest_use_sdk_api,sc_importdescriptorbaseobj))
$(eval $(call gb_CppunitTest_use_ure,sc_importdescriptorbaseobj))
$(eval $(call gb_CppunitTest_use_vcl,sc_importdescriptorbaseobj))
$(eval $(call gb_CppunitTest_use_components,sc_importdescriptorbaseobj,\
basic/util/sb \
comphelper/util/comphelp \
configmgr/source/configmgr \
dbaccess/util/dba \
filter/source/config/cache/filterconfig1 \
filter/source/storagefilterdetect/storagefd \
forms/util/frm \
framework/util/fwk \
i18npool/util/i18npool \
linguistic/source/lng \
oox/util/oox \
package/source/xstor/xstor \
package/util/package2 \
sax/source/expatwrap/expwrap \
scripting/source/basprov/basprov \
scripting/util/scriptframe \
sc/util/sc \
sc/util/scd \
sc/util/scfilt \
$(call gb_Helper_optional,SCRIPTING, \
sc/util/vbaobj) \
sfx2/util/sfx \
sot/util/sot \
svl/source/fsstor/fsstorage \
toolkit/util/tk \
ucb/source/core/ucb1 \
ucb/source/ucp/file/ucpfile1 \
ucb/source/ucp/tdoc/ucptdoc1 \
unotools/util/utl \
unoxml/source/rdf/unordf \
unoxml/source/service/unoxml \
uui/util/uui \
xmloff/util/xo \
svtools/util/svt \
))
$(eval $(call gb_CppunitTest_use_configuration,sc_importdescriptorbaseobj))
# vim: set noet sw=4 ts=4:
...@@ -149,6 +149,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\ ...@@ -149,6 +149,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\
CppunitTest_sc_consolidationdescriptorobj \ CppunitTest_sc_consolidationdescriptorobj \
CppunitTest_sc_chart2dataprovider \ CppunitTest_sc_chart2dataprovider \
CppunitTest_sc_autoformatobj \ CppunitTest_sc_autoformatobj \
CppunitTest_sc_importdescriptorbaseobj \
)) ))
$(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/databaseimportdescriptor.hxx>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
#include <com/sun/star/sheet/XSpreadsheets.hpp>
#include <com/sun/star/util/XImportable.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/uno/Reference.hxx>
using namespace css;
using namespace css::uno;
using namespace com::sun::star;
namespace sc_apitest
{
#define NUMBER_OF_TESTS 1
class ScImportDescriptorBaseObj : public CalcUnoApiTest, public apitest::DatabaseImportDescriptor
{
public:
ScImportDescriptorBaseObj();
virtual uno::Reference<uno::XInterface> init() override;
virtual uno::Reference<uno::XInterface> getXImportable() override;
virtual void setUp() override;
virtual void tearDown() override;
CPPUNIT_TEST_SUITE(ScImportDescriptorBaseObj);
// DatabaseImportDescriptor
CPPUNIT_TEST(testDatabaseImportDescriptorProperties);
CPPUNIT_TEST_SUITE_END();
private:
static sal_Int32 nTest;
static uno::Reference<lang::XComponent> mxComponent;
};
sal_Int32 ScImportDescriptorBaseObj::nTest = 0;
uno::Reference<lang::XComponent> ScImportDescriptorBaseObj::mxComponent;
ScImportDescriptorBaseObj::ScImportDescriptorBaseObj()
: CalcUnoApiTest("/sc/qa/extras/testdocuments")
{
}
uno::Reference<uno::XInterface> ScImportDescriptorBaseObj::init()
{
// create a calc document
if (!mxComponent.is())
mxComponent = loadFromDesktop("private:factory/scalc");
uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_QUERY_THROW);
uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW);
uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW);
return xSheet;
}
uno::Reference<uno::XInterface> ScImportDescriptorBaseObj::getXImportable()
{
// create a calc document
if (!mxComponent.is())
mxComponent = loadFromDesktop("private:factory/scalc");
uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_QUERY_THROW);
uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW);
uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW);
uno::Reference<util::XImportable> XImportable(xSheet, UNO_QUERY_THROW);
return XImportable;
}
void ScImportDescriptorBaseObj::setUp()
{
nTest++;
CPPUNIT_ASSERT(nTest <= NUMBER_OF_TESTS);
CalcUnoApiTest::setUp();
}
void ScImportDescriptorBaseObj::tearDown()
{
if (nTest == NUMBER_OF_TESTS)
{
closeDocument(mxComponent);
mxComponent.clear();
}
CalcUnoApiTest::tearDown();
}
CPPUNIT_TEST_SUITE_REGISTRATION(ScImportDescriptorBaseObj);
} // end namespace
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -44,6 +44,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ ...@@ -44,6 +44,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\
test/source/container/xnamed \ test/source/container/xnamed \
test/source/sheet/cellarealink \ test/source/sheet/cellarealink \
test/source/sheet/cellproperties \ test/source/sheet/cellproperties \
test/source/sheet/databaseimportdescriptor \
test/source/sheet/databaserange \ test/source/sheet/databaserange \
test/source/sheet/datapilotfield \ test/source/sheet/datapilotfield \
test/source/sheet/datapilotitem \ test/source/sheet/datapilotitem \
......
/* -*- 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/databaseimportdescriptor.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/sheet/DataImportMode.hpp>
#include <com/sun/star/util/XImportable.hpp>
#include <com/sun/star/uno/Any.hxx>
#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 DatabaseImportDescriptor::testDatabaseImportDescriptorProperties()
{
uno::Reference<beans::XPropertySet> xDatabaseImportDescriptor(init(), UNO_QUERY_THROW);
uno::Reference<util::XImportable> xImportable(getXImportable(), UNO_QUERY_THROW);
uno::Sequence<beans::PropertyValue> aPropValues = xImportable->createImportDescriptor(true);
for (auto i = 0; i < aPropValues.getLength(); i++)
{
uno::Any aOldValue;
uno::Any aNewValue;
if (aPropValues[i].Name == "DatabaseName" || aPropValues[i].Name == "SourceObject"
|| aPropValues[i].Name == "ConnectionResource")
{
OUString aValue;
aOldValue = aPropValues[i].Value;
aOldValue >>= aValue;
OString aMsgGet = "Unable to get PropertyValue "
+ OUStringToOString(aPropValues[i].Name, RTL_TEXTENCODING_UTF8);
CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgGet.getStr(), OUString(""), aValue);
aNewValue <<= OUString("New");
aPropValues[i].Value = aNewValue;
aOldValue = aPropValues[i].Value;
aOldValue >>= aValue;
OString aMsgSet = "Unable to set PropertyValue "
+ OUStringToOString(aPropValues[i].Name, RTL_TEXTENCODING_UTF8);
CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgSet.getStr(), OUString("New"), aValue);
}
else if (aPropValues[i].Name == "IsNative")
{
bool aValue = true;
aOldValue = aPropValues[i].Value;
aOldValue >>= aValue;
OString aMsgGet = "Unable to get PropertyValue "
+ OUStringToOString(aPropValues[i].Name, RTL_TEXTENCODING_UTF8);
CPPUNIT_ASSERT_MESSAGE(aMsgGet.getStr(), !aValue);
aNewValue <<= true;
aPropValues[i].Value = aNewValue;
aOldValue = aPropValues[i].Value;
aOldValue >>= aValue;
OString aMsgSet = "Unable to set PropertyValue "
+ OUStringToOString(aPropValues[i].Name, RTL_TEXTENCODING_UTF8);
CPPUNIT_ASSERT_MESSAGE(aMsgSet.getStr(), aValue);
}
else if (aPropValues[i].Name == "SourceType")
{
sheet::DataImportMode aValue;
aOldValue = aPropValues[i].Value;
aOldValue >>= aValue;
OString aMsgGet = "Unable to get PropertyValue "
+ OUStringToOString(aPropValues[i].Name, RTL_TEXTENCODING_UTF8);
CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgGet.getStr(), sheet::DataImportMode_NONE, aValue);
aNewValue <<= sheet::DataImportMode_SQL;
aPropValues[i].Value = aNewValue;
aOldValue = aPropValues[i].Value;
aOldValue >>= aValue;
OString aMsgSet = "Unable to set PropertyValue "
+ OUStringToOString(aPropValues[i].Name, RTL_TEXTENCODING_UTF8);
CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgSet.getStr(), sheet::DataImportMode_SQL, aValue);
}
else
{
OString aMsg = "Unsupported PropertyValue "
+ OUStringToOString(aPropValues[i].Name, RTL_TEXTENCODING_UTF8);
CPPUNIT_FAIL(aMsg.getStr());
}
}
}
}
/* 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