summaryrefslogtreecommitdiff
path: root/cppuhelper/test/loader/loader.test.cxx
blob: dcd6b34ced687aebc4c6745949279dab799f428e (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#include "sal/main.h"
#include <cppuhelper/shlib.hxx>
#include <cppuhelper/implbase1.hxx>
#include <cppu/EnvDcp.hxx>

#include "../testcmp/TestComponent.hxx"

#include <iostream>
#include <cstring>

#ifndef SAL_DLLPREFIX
# define SAL_DLLPREFIX  ""
#endif


using namespace ::com::sun::star;


class MyKey : public cppu::WeakImplHelper1<registry::XRegistryKey>

{
public:
    virtual rtl::OUString SAL_CALL getKeyName() throw (uno::RuntimeException) { return rtl::OUString(); };

    // Methods
    virtual sal_Bool SAL_CALL isReadOnly(  ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;};
    virtual sal_Bool SAL_CALL isValid(  ) throw (uno::RuntimeException) {return sal_False;};
    virtual registry::RegistryKeyType SAL_CALL getKeyType( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryKeyType_KEY;};
    virtual registry::RegistryValueType SAL_CALL getValueType(  ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryValueType_NOT_DEFINED;};
    virtual sal_Int32 SAL_CALL getLongValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return 0;};
    virtual void SAL_CALL setLongValue( sal_Int32 /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
    virtual uno::Sequence< sal_Int32 > SAL_CALL getLongListValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) { return uno::Sequence<sal_Int32>(); };
    virtual void SAL_CALL setLongListValue( const uno::Sequence< sal_Int32 >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
    virtual rtl::OUString SAL_CALL getAsciiValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();};
    virtual void SAL_CALL setAsciiValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
    virtual uno::Sequence< rtl::OUString > SAL_CALL getAsciiListValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();};
    virtual void SAL_CALL setAsciiListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
    virtual rtl::OUString SAL_CALL getStringValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();};
    virtual void SAL_CALL setStringValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
    virtual uno::Sequence< rtl::OUString > SAL_CALL getStringListValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();};
    virtual void SAL_CALL setStringListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
    virtual uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<sal_Int8>();};
    virtual void SAL_CALL setBinaryValue( const uno::Sequence< sal_Int8 >& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
    virtual uno::Reference< registry::XRegistryKey > SAL_CALL openKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();};
    virtual uno::Reference< registry::XRegistryKey > SAL_CALL createKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();};
    virtual void SAL_CALL closeKey(  ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
    virtual void SAL_CALL deleteKey( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
    virtual uno::Sequence< uno::Reference< registry::XRegistryKey > > SAL_CALL openKeys(  ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<uno::Reference<registry::XRegistryKey> >();};
    virtual uno::Sequence< rtl::OUString > SAL_CALL getKeyNames(  ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();};
    virtual sal_Bool SAL_CALL createLink( const rtl::OUString& /*aLinkName*/, const rtl::OUString& /*aLinkTarget*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;};
    virtual void SAL_CALL deleteLink( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
    virtual rtl::OUString SAL_CALL getLinkTarget( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();};
    virtual rtl::OUString SAL_CALL getResolvedName( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();};
};



static rtl::OUString s_test__cppu_loadSharedLibComponentFactory(char const * pServicePurpose)
{
    rtl::OUString result;

    rtl::OUString servicePurpose = rtl::OUString(pServicePurpose,
                                                 rtl_str_getLength(pServicePurpose),
                                                 RTL_TEXTENCODING_ASCII_US);

    result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_loadSharedLibComponentFactory "));
    result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\""));
    result += servicePurpose;
    result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - "));

    try {
        uno::Reference<uno::XInterface> xObject(
            cppu::loadSharedLibComponentFactory(
                rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)),
                rtl::OUString(),
                rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("impl.test.TestComponent")) + servicePurpose,
                uno::Reference<lang::XMultiServiceFactory>(),
                uno::Reference<registry::XRegistryKey>())
            );

        rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp));
        if (envDcp_purpose == servicePurpose)
            result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n"));

        else
        {
            result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
            result += envDcp_purpose;
            result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
        }
    }
    catch(uno::Exception & exception) {
        result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
        result += exception.Message;
        result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
    }

    return result;
}

static rtl::OUString s_test__cppu_writeSharedLibComponentInfo(char const * pServicePurpose)
{
    rtl::OUString result;

    rtl::OUString servicePurpose = rtl::OUString(pServicePurpose,
                                                 rtl_str_getLength(pServicePurpose),
                                                 RTL_TEXTENCODING_ASCII_US);

    result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_writeSharedLibComponentInfo "));
    result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\""));
    result += servicePurpose;
    result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - "));

    char buff[256];
    strcpy(buff, "TestComponent.uno=");
    strcat(buff, pServicePurpose);

    putenv(buff);

    try {
        cppu::writeSharedLibComponentInfo(
            rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)),
            rtl::OUString(),
            uno::Reference<lang::XMultiServiceFactory>(),
            uno::Reference<registry::XRegistryKey>(new MyKey)
            );

        rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp));
        if (envDcp_purpose == servicePurpose)
            result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n"));

        else
        {
            result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
            result += envDcp_purpose;
            result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
        }
    }
    catch(uno::Exception & exception) {
        result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
        result += exception.Message;
        result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
    }

    return result;
}


SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv)
{
    int result = 0;

    rtl::OUString message;

    message += rtl::OUString(argv[0], rtl_str_getLength(argv[0]), RTL_TEXTENCODING_ASCII_US);
    message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));

    message += s_test__cppu_loadSharedLibComponentFactory(":unsafe");
    message += s_test__cppu_loadSharedLibComponentFactory(":affine");
    message += s_test__cppu_loadSharedLibComponentFactory("");

    message += s_test__cppu_writeSharedLibComponentInfo(":unsafe");
    message += s_test__cppu_writeSharedLibComponentInfo(":affine");
    message += s_test__cppu_writeSharedLibComponentInfo("");

    if (message.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED"))) == -1)
        message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n"));

    else
    {
        message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n"));
        result = -1;
    }

    std::cout << rtl::OUStringToOString(message, RTL_TEXTENCODING_ASCII_US).getStr();

    return result;
}