LCOV - code coverage report
Current view: top level - postprocess/qa - services.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 29 33 87.9 %
Date: 2014-04-11 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 <com/sun/star/container/XHierarchicalNameAccess.hpp>
      13             : #include <com/sun/star/reflection/XServiceConstructorDescription.hpp>
      14             : #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
      15             : #include <test/bootstrapfixture.hxx>
      16             : 
      17             : using namespace css::container;
      18             : using namespace css::reflection;
      19             : using namespace css::uno;
      20             : 
      21             : namespace {
      22             : 
      23           3 : class ServicesTest: public test::BootstrapFixture
      24             : {
      25             : public:
      26             :     void test();
      27             : 
      28           2 :     CPPUNIT_TEST_SUITE(ServicesTest);
      29           1 :     CPPUNIT_TEST(test);
      30           2 :     CPPUNIT_TEST_SUITE_END();
      31             : };
      32             : 
      33           1 : void ServicesTest::test()
      34             : {
      35             :     Reference< XHierarchicalNameAccess > xTypeManager(
      36           1 :             m_xContext->getValueByName(
      37           1 :                 "/singletons/com.sun.star.reflection.theTypeDescriptionManager"),
      38           1 :             UNO_QUERY_THROW );
      39           2 :     Sequence<OUString> s = m_xContext->getServiceManager()->getAvailableServiceNames();
      40         991 :     for (sal_Int32 i = 0; i < s.getLength(); i++)
      41             :     {
      42         990 :         if (!xTypeManager->hasByHierarchicalName(s[i]))
      43             :         {
      44             :             SAL_WARN(
      45             :                 "postprocess.cppunit",
      46             :                 "fantasy service name \"" << s[i] << "\"");
      47         818 :             continue;
      48             :         }
      49             :         SAL_WARN(
      50             :                 "postprocess.cppunit",
      51             :                 "trying (index: " << i << ") \"" << s[i] << "\"");
      52             :         Reference< XServiceTypeDescription2 > xDesc(
      53         581 :             xTypeManager->getByHierarchicalName(s[i]), UNO_QUERY_THROW);
      54        1162 :         Sequence< Reference< XServiceConstructorDescription > > xseq = xDesc->getConstructors();
      55         922 :         for (sal_Int32 c = 0; c < xseq.getLength(); c++)
      56         341 :             if (!xseq[c]->getParameters().hasElements())
      57             :                 try
      58             :                 {
      59         239 :                     OString message = OUStringToOString(s[i], RTL_TEXTENCODING_UTF8);
      60         239 :                     sal_Bool bDefConstructor = xseq[c]->isDefaultConstructor();
      61         478 :                     Reference< css::lang::XMultiComponentFactory > serviceManager = m_xContext->getServiceManager();
      62         478 :                     Reference< XInterface > instance;
      63             : 
      64         239 :                     if( bDefConstructor )
      65         214 :                         instance = serviceManager->createInstanceWithContext(s[i], m_xContext);
      66             :                     else
      67         100 :                         instance = serviceManager->createInstanceWithArgumentsAndContext(
      68          75 :                                                     s[i], css::uno::Sequence<css::uno::Any>(), m_xContext);
      69             : 
      70         478 :                     CPPUNIT_ASSERT_MESSAGE( message.getStr(), instance.is() );
      71             :                 }
      72           0 :                 catch(const Exception & e)
      73             :                 {
      74           0 :                     OString exc = "Exception thrown while creating " +
      75           0 :                         OUStringToOString(s[i] + ": " + e.Message, RTL_TEXTENCODING_UTF8);
      76           0 :                     CPPUNIT_FAIL(exc.getStr());
      77             :                 }
      78         582 :     }
      79           1 : }
      80             : 
      81           1 : CPPUNIT_TEST_SUITE_REGISTRATION(ServicesTest);
      82             : 
      83             : }
      84             : 
      85           4 : CPPUNIT_PLUGIN_IMPLEMENT();
      86             : 
      87             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10