LCOV - code coverage report
Current view: top level - postprocess/qa - services.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 45 49 91.8 %
Date: 2014-11-03 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <sal/config.h>
      11             : 
      12             : #include <algorithm>
      13             : #include <vector>
      14             : 
      15             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      16             : #include <com/sun/star/lang/XComponent.hpp>
      17             : #include <com/sun/star/reflection/XServiceConstructorDescription.hpp>
      18             : #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
      19             : #include <test/bootstrapfixture.hxx>
      20             : #include <vcl/svapp.hxx>
      21             : 
      22             : using namespace css::container;
      23             : using namespace css::reflection;
      24             : using namespace css::uno;
      25             : 
      26             : namespace {
      27             : 
      28           6 : class ServicesTest: public test::BootstrapFixture
      29             : {
      30             : public:
      31             :     void test();
      32             : 
      33           4 :     CPPUNIT_TEST_SUITE(ServicesTest);
      34           2 :     CPPUNIT_TEST(test);
      35           4 :     CPPUNIT_TEST_SUITE_END();
      36             : };
      37             : 
      38           2 : void ServicesTest::test()
      39             : {
      40           2 :     std::vector<OUString> blacklist;
      41             : 
      42             :     // On Windows, blacklist the com.sun.star.report.ReportDefinition service,
      43             :     // as its reportdesign::OReportDefinition implementation (in
      44             :     // reportdesign/source/core/api/ReportDefinition.cxx) spawns a thread that
      45             :     // forever blocks in SendMessageW when no VCL event loop is running
      46             :     // (reportdesign::<anon>::FactoryLoader::execute ->
      47             :     // framework::Desktop::findFrame -> framework::TaskCreator::createTask ->
      48             :     // <anon>::TaskCreatorService::createInstanceWithArguments ->
      49             :     // <anon>::TaskCreatorService::impls_createContainerWindow ->
      50             :     // <anon>::VCLXToolkit::createWindow ->
      51             :     // <anon>::VCLXToolkit::ImplCreateWindow ->
      52             :     // <anon>::VCLXToolkit::ImplCreateWindow -> WorkWindow::WorkWindow ->
      53             :     // WorkWindow::ImplInit -> ImplBorderWindow::ImplBorderWindow ->
      54             :     // ImplBorderWindow::ImplInit -> Window::ImplInit ->
      55             :     // WinSalInstance::CreateFrame -> ImplSendMessage -> SendMessageW):
      56           2 :     blacklist.push_back("com.sun.star.report.ReportDefinition");
      57             : 
      58             :     Reference< XHierarchicalNameAccess > xTypeManager(
      59           2 :             m_xContext->getValueByName(
      60           2 :                 "/singletons/com.sun.star.reflection.theTypeDescriptionManager"),
      61           4 :             UNO_QUERY_THROW );
      62           4 :     Sequence<OUString> s = m_xContext->getServiceManager()->getAvailableServiceNames();
      63           4 :     std::vector< css::uno::Reference<css::lang::XComponent> > comps;
      64        1982 :     for (sal_Int32 i = 0; i < s.getLength(); i++)
      65             :     {
      66        5940 :         if (std::find(blacklist.begin(), blacklist.end(), s[i])
      67        5940 :             != blacklist.end())
      68             :         {
      69         822 :             continue;
      70             :         }
      71        1978 :         if (!xTypeManager->hasByHierarchicalName(s[i]))
      72             :         {
      73             :             SAL_WARN(
      74             :                 "postprocess.cppunit",
      75             :                 "fantasy service name \"" << s[i] << "\"");
      76         818 :             continue;
      77             :         }
      78             :         SAL_WARN(
      79             :                 "postprocess.cppunit",
      80             :                 "trying (index: " << i << ") \"" << s[i] << "\"");
      81             :         Reference< XServiceTypeDescription2 > xDesc(
      82        1160 :             xTypeManager->getByHierarchicalName(s[i]), UNO_QUERY_THROW);
      83        2320 :         Sequence< Reference< XServiceConstructorDescription > > xseq = xDesc->getConstructors();
      84        1840 :         for (sal_Int32 c = 0; c < xseq.getLength(); c++)
      85         680 :             if (!xseq[c]->getParameters().hasElements())
      86             :             {
      87         476 :                 Reference< XInterface > instance;
      88             :                 try
      89             :                 {
      90         476 :                     OString message = OUStringToOString(s[i], RTL_TEXTENCODING_UTF8);
      91         476 :                     bool bDefConstructor = xseq[c]->isDefaultConstructor();
      92         952 :                     Reference< css::lang::XMultiComponentFactory > serviceManager = m_xContext->getServiceManager();
      93             : 
      94         476 :                     if( bDefConstructor )
      95         426 :                         instance = serviceManager->createInstanceWithContext(s[i], m_xContext);
      96             :                     else
      97         200 :                         instance = serviceManager->createInstanceWithArgumentsAndContext(
      98         150 :                                                     s[i], css::uno::Sequence<css::uno::Any>(), m_xContext);
      99             : 
     100         952 :                     CPPUNIT_ASSERT_MESSAGE( message.getStr(), instance.is() );
     101             :                 }
     102           0 :                 catch(const Exception & e)
     103             :                 {
     104           0 :                     OString exc = "Exception thrown while creating " +
     105           0 :                         OUStringToOString(s[i] + ": " + e.Message, RTL_TEXTENCODING_UTF8);
     106           0 :                     CPPUNIT_FAIL(exc.getStr());
     107             :                 }
     108             :                 css::uno::Reference<css::lang::XComponent> comp(
     109         952 :                     instance, css::uno::UNO_QUERY);
     110         476 :                 if (comp.is()) {
     111         128 :                     comps.push_back(comp);
     112         476 :                 }
     113             :             }
     114        1160 :     }
     115           4 :     SolarMutexReleaser rel;
     116         390 :     for (std::vector< css::uno::Reference<css::lang::XComponent> >::iterator i(
     117           2 :              comps.begin());
     118         260 :          i != comps.end(); ++i)
     119             :     {
     120         128 :         (*i)->dispose();
     121           2 :     }
     122           2 : }
     123             : 
     124           2 : CPPUNIT_TEST_SUITE_REGISTRATION(ServicesTest);
     125             : 
     126             : }
     127             : 
     128           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     129             : 
     130             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10