Add a unit test trying to create every available service with default ctor.
Change-Id: I79e70aeabdb816eaf7a719d2094034d78d11c90b
This commit is contained in:
parent
d8bbae2fd6
commit
ff9614a744
31
postprocess/CppunitTest_services.mk
Normal file
31
postprocess/CppunitTest_services.mk
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# -*- 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,services))
|
||||||
|
|
||||||
|
$(eval $(call gb_CppunitTest_add_exception_objects,services, \
|
||||||
|
postprocess/qa/services \
|
||||||
|
))
|
||||||
|
|
||||||
|
$(eval $(call gb_CppunitTest_use_libraries,services, \
|
||||||
|
cppu \
|
||||||
|
sal \
|
||||||
|
test \
|
||||||
|
$(gb_UWINAPI) \
|
||||||
|
))
|
||||||
|
|
||||||
|
$(eval $(call gb_CppunitTest_use_sdk_api,services))
|
||||||
|
|
||||||
|
$(eval $(call gb_CppunitTest_use_ure,services))
|
||||||
|
|
||||||
|
$(eval $(call gb_CppunitTest_use_rdb,services,services))
|
||||||
|
|
||||||
|
$(eval $(call gb_CppunitTest_use_configuration,services))
|
||||||
|
|
||||||
|
# vim: set noet sw=4 ts=4:
|
@ -28,4 +28,8 @@ $(eval $(call gb_Module_add_targets,postprocess,\
|
|||||||
))
|
))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
$(eval $(call gb_Module_add_check_targets,postprocess,\
|
||||||
|
CppunitTest_services \
|
||||||
|
))
|
||||||
|
|
||||||
# vim: set noet sw=4 ts=4:
|
# vim: set noet sw=4 ts=4:
|
||||||
|
97
postprocess/qa/services.cxx
Normal file
97
postprocess/qa/services.cxx
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* 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 <sal/config.h>
|
||||||
|
|
||||||
|
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
|
||||||
|
#include <com/sun/star/reflection/XServiceConstructorDescription.hpp>
|
||||||
|
#include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
|
||||||
|
#include <test/bootstrapfixture.hxx>
|
||||||
|
|
||||||
|
using namespace css::container;
|
||||||
|
using namespace css::reflection;
|
||||||
|
using namespace css::uno;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class ServicesTest: public test::BootstrapFixture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void setUp();
|
||||||
|
virtual void tearDown();
|
||||||
|
|
||||||
|
void test();
|
||||||
|
|
||||||
|
CPPUNIT_TEST_SUITE(ServicesTest);
|
||||||
|
CPPUNIT_TEST(test);
|
||||||
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
};
|
||||||
|
|
||||||
|
void ServicesTest::setUp()
|
||||||
|
{
|
||||||
|
test::BootstrapFixture::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServicesTest::tearDown()
|
||||||
|
{
|
||||||
|
test::BootstrapFixture::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServicesTest::test()
|
||||||
|
{
|
||||||
|
Reference< XHierarchicalNameAccess > xTypeManager(
|
||||||
|
m_xContext->getValueByName(
|
||||||
|
"/singletons/com.sun.star.reflection.theTypeDescriptionManager"),
|
||||||
|
UNO_QUERY_THROW );
|
||||||
|
Sequence<OUString> seq = m_xContext->getServiceManager()->getAvailableServiceNames();
|
||||||
|
OUString *s = seq.getArray();
|
||||||
|
for (sal_Int32 i = 0; i < seq.getLength(); i++)
|
||||||
|
{
|
||||||
|
if (!xTypeManager->hasByHierarchicalName(s[i]))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Reference< XServiceTypeDescription2 > xDesc(
|
||||||
|
xTypeManager->getByHierarchicalName(s[i]), UNO_QUERY);
|
||||||
|
if (!xDesc.is())
|
||||||
|
{
|
||||||
|
// Does happen for singletons?
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Sequence< Reference< XServiceConstructorDescription > > xseq = xDesc->getConstructors();
|
||||||
|
bool bHasDefault = false;
|
||||||
|
for (sal_Int32 c = 0; c < xseq.getLength(); c++)
|
||||||
|
if (xseq[c]->isDefaultConstructor())
|
||||||
|
bHasDefault = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (bHasDefault
|
||||||
|
&& s[i] != "com.sun.star.deployment.test.SmoketestCommandEnvironment")
|
||||||
|
// TODO: com.sun.star.deployment.test.SmoketestCommandEnvironment throws
|
||||||
|
// "Can not activate the factory for org.libreoffice.smoketest.SmoketestCommandEnvironment
|
||||||
|
// because java.lang.NoClassDefFoundError: com/sun/star/ucb/XCommandEnvironment"
|
||||||
|
m_xContext->getServiceManager()->createInstanceWithContext(s[i], m_xContext);
|
||||||
|
}
|
||||||
|
catch(const Exception & e)
|
||||||
|
{
|
||||||
|
OString exc = "Exception thrown while creating " +
|
||||||
|
OUStringToOString(s[i] + ": " + e.Message, RTL_TEXTENCODING_UTF8);
|
||||||
|
CPPUNIT_FAIL(exc.getStr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CPPUNIT_TEST_SUITE_REGISTRATION(ServicesTest);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
Loading…
x
Reference in New Issue
Block a user