diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2013-12-17 10:44:59 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2013-12-18 07:15:50 +0100 |
commit | ff9614a744368f187422b98b40e90ee5231b045f (patch) | |
tree | bb32b1c718575698cda1383c37b21e54a24b81b6 /postprocess | |
parent | d8bbae2fd6786c2647b7b59e54d9dabdd47603d7 (diff) |
Add a unit test trying to create every available service with default ctor.
Change-Id: I79e70aeabdb816eaf7a719d2094034d78d11c90b
Diffstat (limited to 'postprocess')
-rw-r--r-- | postprocess/CppunitTest_services.mk | 31 | ||||
-rw-r--r-- | postprocess/Module_postprocess.mk | 4 | ||||
-rw-r--r-- | postprocess/qa/services.cxx | 97 |
3 files changed, 132 insertions, 0 deletions
diff --git a/postprocess/CppunitTest_services.mk b/postprocess/CppunitTest_services.mk new file mode 100644 index 000000000000..f6da8f61875e --- /dev/null +++ b/postprocess/CppunitTest_services.mk @@ -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: diff --git a/postprocess/Module_postprocess.mk b/postprocess/Module_postprocess.mk index d3d5a95d1a84..5775cfa795e1 100644 --- a/postprocess/Module_postprocess.mk +++ b/postprocess/Module_postprocess.mk @@ -28,4 +28,8 @@ $(eval $(call gb_Module_add_targets,postprocess,\ )) endif +$(eval $(call gb_Module_add_check_targets,postprocess,\ + CppunitTest_services \ +)) + # vim: set noet sw=4 ts=4: diff --git a/postprocess/qa/services.cxx b/postprocess/qa/services.cxx new file mode 100644 index 000000000000..ea21ab5f7989 --- /dev/null +++ b/postprocess/qa/services.cxx @@ -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: */ |