1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <osl/file.hxx>
24 #include <typelib/typedescription.hxx>
26 #include <cppuhelper/bootstrap.hxx>
27 #include <cppuhelper/shlib.hxx>
29 #include <com/sun/star/lang/XComponent.hpp>
31 #include <uno/environment.hxx>
32 #include <uno/lbnames.h>
33 #include <cppu/EnvDcp.hxx>
34 #include <cppu/EnvGuards.hxx>
40 # define SAL_DLLPREFIX ""
44 using namespace com::sun::star
;
47 static rtl::OUString s_comment
;
49 static bool s_check_object_is_in(void * pObject
)
51 uno::Environment
currentEnv(uno::Environment::getCurrent());
53 rtl_uString
* pOId
= NULL
;
54 currentEnv
.get()->pExtEnv
->getObjectIdentifier(currentEnv
.get()->pExtEnv
, &pOId
, pObject
);
57 uno::TypeDescription
typeDescription(rtl::OUString("com.sun.star.uno.XInterface"));
59 void * pRegisteredObject
= NULL
;
60 currentEnv
.get()->pExtEnv
->getRegisteredInterface(currentEnv
.get()->pExtEnv
,
63 (typelib_InterfaceTypeDescription
*)typeDescription
.get());
66 if (pOId
) rtl_uString_release(pOId
);
68 bool result
= pRegisteredObject
!= NULL
;
71 currentEnv
.get()->pExtEnv
->releaseInterface(currentEnv
.get()->pExtEnv
, pRegisteredObject
);
76 static void s_test__loadSharedLibComponentFactory(rtl::OUString
const & clientPurpose
,
77 rtl::OUString
const & servicePurpose
)
79 cppu::EnvGuard
envGuard(uno::Environment(UNO_LB_UNO
+ clientPurpose
, NULL
));
80 if (!clientPurpose
.isEmpty() && !envGuard
.is())
82 s_comment
+= "\t\tcouldn't get purpose env: \"" + clientPurpose
+ "\" - FAILURE\n";
86 rtl::OString
os_clientPurpose(rtl::OUStringToOString(clientPurpose
, RTL_TEXTENCODING_ASCII_US
));
88 uno::Reference
<uno::XInterface
> xItf(
89 cppu::loadSharedLibComponentFactory(
90 rtl::OUString(SAL_DLLPREFIX
"TestComponent.uno" SAL_DLLEXTENSION
),
96 "impl.test.TestComponent" + servicePurpose
,
97 uno::Reference
<lang::XMultiServiceFactory
>(),
98 uno::Reference
<registry::XRegistryKey
>()
104 s_comment
+= rtl::OUString("\t\tgot no object - FAILURE\n");
108 if (!clientPurpose
.equals(servicePurpose
) && !s_check_object_is_in(xItf
.get()))
110 s_comment
+= "\t\tcouldn't find object in current purpose \"" + clientPurpose
+ "\" - FAILURE\n";
113 if (!cppu::EnvDcp::getPurpose(uno::Environment::getCurrent().getTypeName()).equals(clientPurpose
))
115 s_comment
+= "\t\tdid not enter client purpose \"" + clientPurpose
+ "\" - FAILURE\n";
119 static void s_test__loadSharedLibComponentFactory__free_free()
121 s_comment
+= "\ts_test__loadSharedLibComponentFactory__free_free\n";
123 s_test__loadSharedLibComponentFactory("", "");
126 static void s_test__loadSharedLibComponentFactory__free_purpose()
128 s_comment
+= "\ts_test__loadSharedLibComponentFactory__free_purpose\n";
130 s_test__loadSharedLibComponentFactory("", ":testenv");
133 static void s_test__loadSharedLibComponentFactory__purpose_free()
135 s_comment
+= "\ts_test__loadSharedLibComponentFactory__purpose_free\n";
137 s_test__loadSharedLibComponentFactory(":testenv", "");
140 static void s_test__loadSharedLibComponentFactory__purpose_purpose()
142 s_comment
+= "\ts_test__loadSharedLibComponentFactory__purpose_purpose\n";
144 s_test__loadSharedLibComponentFactory(":testenv", ":testenv");
147 static rtl::OUString
s_getSDrive()
149 rtl::OUString path
;//("file://");
151 // FIXME no more S drive
153 osl::FileBase::getFileURLFromSystemPath(path
, path
);
158 static void s_test__createSimpleRegistry(rtl::OUString
const & clientPurpose
)
160 cppu::EnvGuard
envGuard(uno::Environment(rtl::OUString(UNO_LB_UNO
)
161 + clientPurpose
, NULL
));
162 if (!clientPurpose
.isEmpty() && !envGuard
.is())
164 s_comment
+= "\t\tcouldn't get purpose env: \"" + clientPurpose
+ "\" - FAILURE\n";
168 uno::Reference
<registry::XSimpleRegistry
> registry(cppu::createSimpleRegistry(
173 s_comment
+= "\t\tgot no object - FAILURE\n";
177 if (!clientPurpose
.isEmpty() && !s_check_object_is_in(registry
.get()))
179 s_comment
+= "\t\tcouldn't find object in current purpose \"" + clientPurpose
+ "\" - FAILURE\n";
183 static void s_test__createSimpleRegistry__free()
185 s_comment
+= "\ts_test__createSimpleRegistry__free\n";
187 s_test__createSimpleRegistry(rtl::OUString());
190 static void s_test__createSimpleRegistry__purpose()
192 s_comment
+= "\ts_test__createSimpleRegistry__purpose\n";
194 s_test__createSimpleRegistry(":testenv");
198 static void s_test__bootstrap_InitialComponentContext(rtl::OUString
const & clientPurpose
)
200 cppu::EnvGuard
envGuard(uno::Environment(rtl::OUString(UNO_LB_UNO
)
201 + clientPurpose
, NULL
));
202 if (!clientPurpose
.isEmpty() && !envGuard
.is())
204 s_comment
+= "\t\tcouldn't get purpose env: \"" + clientPurpose
+ "\" - FAILURE\n";
208 uno::Reference
<uno::XComponentContext
> xContext(
209 cppu::bootstrap_InitialComponentContext(
210 uno::Reference
<registry::XSimpleRegistry
>(),
216 s_comment
+= "\t\tgot no object - FAILURE\n";
220 if (!clientPurpose
.isEmpty() && !s_check_object_is_in(xContext
.get()))
222 s_comment
+= "\t\tcouldn't find object in current purpose \"" + clientPurpose
+ "\" - FAILURE\n";
225 uno::Reference
<lang::XComponent
> xComponent(xContext
, uno::UNO_QUERY_THROW
);
226 xComponent
->dispose();
229 static void s_test__bootstrap_InitialComponentContext__free()
231 s_comment
+= "\ts_test__bootstrap_InitialComponentContext__free\n";
233 s_test__bootstrap_InitialComponentContext(rtl::OUString());
236 static void s_test__bootstrap_InitialComponentContext__purpose()
238 s_comment
+= "\ts_test__bootstrap_InitialComponentContext__purpose\n";
240 s_test__bootstrap_InitialComponentContext(":testenv");
244 SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv
)
246 s_test__createSimpleRegistry__free();
247 s_test__createSimpleRegistry__purpose();
249 s_test__loadSharedLibComponentFactory__free_free();
250 s_test__loadSharedLibComponentFactory__free_purpose();
251 s_test__loadSharedLibComponentFactory__purpose_free();
252 s_test__loadSharedLibComponentFactory__purpose_purpose();
254 s_test__bootstrap_InitialComponentContext__free();
255 s_test__bootstrap_InitialComponentContext__purpose();
258 if (s_comment
.indexOf("FAILURE") == -1)
260 s_comment
+= "TESTS PASSED\n";
265 s_comment
+= "TESTS _NOT_ PASSED\n";
272 << rtl::OUStringToOString(s_comment
, RTL_TEXTENCODING_ASCII_US
).getStr()
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */