Kaydet (Commit) 4cacc608 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Make sure to dispose services supporting the XComponent protocol

...to e.g. avoid leftover temp files from instantiating
com.sun.star.comp.report.OReportDefinition.  But dispose all instances only at
the very end, to avoid disposing some single-instance services too early.

Change-Id: I71fc50e80f4b5d1a1ca16e392725903b079ce2d1
üst 3385b0da
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
#include <sal/config.h> #include <sal/config.h>
#include <vector>
#include <com/sun/star/container/XHierarchicalNameAccess.hpp> #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/reflection/XServiceConstructorDescription.hpp> #include <com/sun/star/reflection/XServiceConstructorDescription.hpp>
#include <com/sun/star/reflection/XServiceTypeDescription2.hpp> #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
#include <test/bootstrapfixture.hxx> #include <test/bootstrapfixture.hxx>
...@@ -37,6 +40,7 @@ void ServicesTest::test() ...@@ -37,6 +40,7 @@ void ServicesTest::test()
"/singletons/com.sun.star.reflection.theTypeDescriptionManager"), "/singletons/com.sun.star.reflection.theTypeDescriptionManager"),
UNO_QUERY_THROW ); UNO_QUERY_THROW );
Sequence<OUString> s = m_xContext->getServiceManager()->getAvailableServiceNames(); Sequence<OUString> s = m_xContext->getServiceManager()->getAvailableServiceNames();
std::vector< css::uno::Reference<css::lang::XComponent> > comps;
for (sal_Int32 i = 0; i < s.getLength(); i++) for (sal_Int32 i = 0; i < s.getLength(); i++)
{ {
if (!xTypeManager->hasByHierarchicalName(s[i])) if (!xTypeManager->hasByHierarchicalName(s[i]))
...@@ -54,12 +58,13 @@ void ServicesTest::test() ...@@ -54,12 +58,13 @@ void ServicesTest::test()
Sequence< Reference< XServiceConstructorDescription > > xseq = xDesc->getConstructors(); Sequence< Reference< XServiceConstructorDescription > > xseq = xDesc->getConstructors();
for (sal_Int32 c = 0; c < xseq.getLength(); c++) for (sal_Int32 c = 0; c < xseq.getLength(); c++)
if (!xseq[c]->getParameters().hasElements()) if (!xseq[c]->getParameters().hasElements())
{
Reference< XInterface > instance;
try try
{ {
OString message = OUStringToOString(s[i], RTL_TEXTENCODING_UTF8); OString message = OUStringToOString(s[i], RTL_TEXTENCODING_UTF8);
bool bDefConstructor = xseq[c]->isDefaultConstructor(); bool bDefConstructor = xseq[c]->isDefaultConstructor();
Reference< css::lang::XMultiComponentFactory > serviceManager = m_xContext->getServiceManager(); Reference< css::lang::XMultiComponentFactory > serviceManager = m_xContext->getServiceManager();
Reference< XInterface > instance;
if( bDefConstructor ) if( bDefConstructor )
instance = serviceManager->createInstanceWithContext(s[i], m_xContext); instance = serviceManager->createInstanceWithContext(s[i], m_xContext);
...@@ -75,6 +80,18 @@ void ServicesTest::test() ...@@ -75,6 +80,18 @@ void ServicesTest::test()
OUStringToOString(s[i] + ": " + e.Message, RTL_TEXTENCODING_UTF8); OUStringToOString(s[i] + ": " + e.Message, RTL_TEXTENCODING_UTF8);
CPPUNIT_FAIL(exc.getStr()); CPPUNIT_FAIL(exc.getStr());
} }
css::uno::Reference<css::lang::XComponent> comp(
instance, css::uno::UNO_QUERY);
if (comp.is()) {
comps.push_back(comp);
}
}
}
for (std::vector< css::uno::Reference<css::lang::XComponent> >::iterator i(
comps.begin());
i != comps.end(); ++i)
{
(*i)->dispose();
} }
} }
......
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