tdf#45904 Move XNameAccess Java tests to C++

Move XNameAccess Java tests to C++ for ScAutoFormatsObj.

Change-Id: If0ce836f2d0628fa3e4a19f6a1789b74018e0229
Reviewed-on: https://gerrit.libreoffice.org/69329
Tested-by: Jenkins
Reviewed-by: Jens Carl <j.carl43@gmx.de>
diff --git a/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScAutoFormatsObj.csv b/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScAutoFormatsObj.csv
index 048a06f..c96b965 100644
--- a/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScAutoFormatsObj.csv
+++ b/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScAutoFormatsObj.csv
@@ -1,6 +1,3 @@
"ScAutoFormatsObj";"com::sun::star::container::XNameAccess";"getByName()"
"ScAutoFormatsObj";"com::sun::star::container::XNameAccess";"getElementNames()"
"ScAutoFormatsObj";"com::sun::star::container::XNameAccess";"hasByName()"
"ScAutoFormatsObj";"com::sun::star::container::XNameReplace";"replaceByName()"
"ScAutoFormatsObj";"com::sun::star::container::XNameContainer";"insertByName()"
"ScAutoFormatsObj";"com::sun::star::container::XNameContainer";"removeByName()"
diff --git a/sc/CppunitTest_sc_autoformatsobj.mk b/sc/CppunitTest_sc_autoformatsobj.mk
new file mode 100644
index 0000000..d0bc00b
--- /dev/null
+++ b/sc/CppunitTest_sc_autoformatsobj.mk
@@ -0,0 +1,43 @@
# -*- 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_autoformatsobj))

$(eval $(call gb_CppunitTest_use_external,sc_autoformatsobj,boost_headers))

$(eval $(call gb_CppunitTest_add_exception_objects,sc_autoformatsobj, \
    sc/qa/extras/scautoformatsobj \
))

$(eval $(call gb_CppunitTest_use_libraries,sc_autoformatsobj, \
	cppu \
	sal \
	subsequenttest \
	test \
	unotest \
))

$(eval $(call gb_CppunitTest_set_include,sc_autoformatsobj,\
	$$(INCLUDE) \
))

$(eval $(call gb_CppunitTest_use_sdk_api,sc_autoformatsobj))

$(eval $(call gb_CppunitTest_use_ure,sc_autoformatsobj))
$(eval $(call gb_CppunitTest_use_vcl,sc_autoformatsobj))

$(eval $(call gb_CppunitTest_use_components,sc_autoformatsobj,\
    $(sc_unoapi_common_components) \
))

$(eval $(call gb_CppunitTest_use_configuration,sc_autoformatsobj))

# vim: set noet sw=4 ts=4:
diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk
index 3718ad3..2b89b70 100644
--- a/sc/Module_sc.mk
+++ b/sc/Module_sc.mk
@@ -107,6 +107,7 @@
	CppunitTest_sc_arealinkobj \
	CppunitTest_sc_arealinksobj \
	CppunitTest_sc_autoformatobj \
	CppunitTest_sc_autoformatsobj \
	CppunitTest_sc_cellcursorobj \
	CppunitTest_sc_cellfieldsobj \
	CppunitTest_sc_cellformatsenumeration \
diff --git a/sc/qa/extras/scautoformatsobj.cxx b/sc/qa/extras/scautoformatsobj.cxx
new file mode 100644
index 0000000..7ee677a
--- /dev/null
+++ b/sc/qa/extras/scautoformatsobj.cxx
@@ -0,0 +1,79 @@
/* -*- 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/container/xnameaccess.hxx>

#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/uno/XInterface.hpp>

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

using namespace css;

namespace sc_apitest
{
class ScAutoFormatsObj : public CalcUnoApiTest, public apitest::XNameAccess
{
public:
    ScAutoFormatsObj();

    virtual uno::Reference<uno::XInterface> init() override;
    virtual void setUp() override;
    virtual void tearDown() override;

    CPPUNIT_TEST_SUITE(ScAutoFormatsObj);

    // XNameAccess
    CPPUNIT_TEST(testGetByName);
    CPPUNIT_TEST(testGetElementNames);
    CPPUNIT_TEST(testHasByName);

    CPPUNIT_TEST_SUITE_END();

private:
    uno::Reference<lang::XComponent> m_xComponent;
};

ScAutoFormatsObj::ScAutoFormatsObj()
    : CalcUnoApiTest("/sc/qa/extras/testdocuments")
    , XNameAccess("Default")
{
}

uno::Reference<uno::XInterface> ScAutoFormatsObj::init()
{
    uno::Reference<lang::XMultiServiceFactory> xMSF(m_xComponent, uno::UNO_QUERY_THROW);
    uno::Reference<uno::XInterface> xTAF(
        xMSF->createInstance("com.sun.star.sheet.TableAutoFormats"), uno::UNO_QUERY_THROW);

    return xTAF;
}

void ScAutoFormatsObj::setUp()
{
    CalcUnoApiTest::setUp();
    // create calc document
    m_xComponent = loadFromDesktop("private:factory/scalc");
}

void ScAutoFormatsObj::tearDown()
{
    closeDocument(m_xComponent);
    CalcUnoApiTest::tearDown();
}

CPPUNIT_TEST_SUITE_REGISTRATION(ScAutoFormatsObj);

} // namespace sc_apitest

CPPUNIT_PLUGIN_IMPLEMENT();

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