summaryrefslogtreecommitdiff
path: root/postprocess/qa/services.cxx
blob: 7e3207ee85721593b1f5dccdf2c1080f87e2c551 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* -*- 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 <algorithm>
#include <vector>

#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/XServiceTypeDescription2.hpp>
#include <test/bootstrapfixture.hxx>
#include <vcl/svapp.hxx>

using namespace css::container;
using namespace css::reflection;
using namespace css::uno;

namespace {

class ServicesTest: public test::BootstrapFixture
{
public:
    void test();

    CPPUNIT_TEST_SUITE(ServicesTest);
    CPPUNIT_TEST(test);
    CPPUNIT_TEST_SUITE_END();
};

void ServicesTest::test()
{
    std::vector<OUString> blacklist;

    // On Windows, blacklist the com.sun.star.report.ReportDefinition service,
    // as its reportdesign::OReportDefinition implementation (in
    // reportdesign/source/core/api/ReportDefinition.cxx) spawns a thread that
    // forever blocks in SendMessageW when no VCL event loop is running
    // (reportdesign::<anon>::FactoryLoader::execute ->
    // framework::Desktop::findFrame -> framework::TaskCreator::createTask ->
    // <anon>::TaskCreatorService::createInstanceWithArguments ->
    // <anon>::TaskCreatorService::impls_createContainerWindow ->
    // <anon>::VCLXToolkit::createWindow ->
    // <anon>::VCLXToolkit::ImplCreateWindow ->
    // <anon>::VCLXToolkit::ImplCreateWindow -> WorkWindow::WorkWindow ->
    // WorkWindow::ImplInit -> ImplBorderWindow::ImplBorderWindow ->
    // ImplBorderWindow::ImplInit -> Window::ImplInit ->
    // WinSalInstance::CreateFrame -> ImplSendMessage -> SendMessageW):
    blacklist.push_back("com.sun.star.report.ReportDefinition");

    Reference< XHierarchicalNameAccess > xTypeManager(
            m_xContext->getValueByName(
                "/singletons/com.sun.star.reflection.theTypeDescriptionManager"),
            UNO_QUERY_THROW );
    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++)
    {
        if (std::find(blacklist.begin(), blacklist.end(), s[i])
            != blacklist.end())
        {
            continue;
        }
        if (!xTypeManager->hasByHierarchicalName(s[i]))
        {
            SAL_WARN(
                "postprocess.cppunit",
                "fantasy service name \"" << s[i] << "\"");
            continue;
        }
        SAL_WARN(
                "postprocess.cppunit",
                "trying (index: " << i << ") \"" << s[i] << "\"");
        Reference< XServiceTypeDescription2 > xDesc(
            xTypeManager->getByHierarchicalName(s[i]), UNO_QUERY_THROW);
        Sequence< Reference< XServiceConstructorDescription > > xseq = xDesc->getConstructors();
        SAL_WARN_IF(xseq.getLength() == 0, "postprocess.cppunit", "not tested because there is no constructor");
        for (sal_Int32 c = 0; c < xseq.getLength(); c++)
            if (!xseq[c]->getParameters().hasElements())
            {
                Reference< XInterface > instance;
                try
                {
                    OString message = OUStringToOString(s[i], RTL_TEXTENCODING_UTF8);
                    bool bDefConstructor = xseq[c]->isDefaultConstructor();
                    Reference< css::lang::XMultiComponentFactory > serviceManager = m_xContext->getServiceManager();

                    if( bDefConstructor )
                        instance = serviceManager->createInstanceWithContext(s[i], m_xContext);
                    else
                        instance = serviceManager->createInstanceWithArgumentsAndContext(
                                                    s[i], css::uno::Sequence<css::uno::Any>(), m_xContext);

                    CPPUNIT_ASSERT_MESSAGE( message.getStr(), instance.is() );
                }
                catch(const Exception & e)
                {
                    OString exc = "Exception thrown while creating " +
                        OUStringToOString(s[i] + ": " + e.Message, RTL_TEXTENCODING_UTF8);
                    CPPUNIT_FAIL(exc.getStr());
                }
                css::uno::Reference<css::lang::XComponent> comp(
                    instance, css::uno::UNO_QUERY);
                if (comp.is()) {
                    comps.push_back(comp);
                }
            }
    }
    SolarMutexReleaser rel;
    for (std::vector< css::uno::Reference<css::lang::XComponent> >::iterator i(
             comps.begin());
         i != comps.end(); ++i)
    {
        (*i)->dispose();
    }
}

CPPUNIT_TEST_SUITE_REGISTRATION(ServicesTest);

}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */