1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bootstrap.test.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include "osl/file.hxx"
35 #include "typelib/typedescription.hxx"
37 #include "cppuhelper/bootstrap.hxx"
38 #include "cppuhelper/shlib.hxx"
40 #include <com/sun/star/lang/XComponent.hpp>
42 #include "uno/environment.hxx"
43 #include "cppu/EnvDcp.hxx"
44 #include "cppu/EnvGuards.hxx"
50 # define SAL_DLLPREFIX ""
54 using namespace com::sun::star
;
57 static rtl::OUString s_comment
;
59 static bool s_check_object_is_in(void * pObject
)
61 uno::Environment
currentEnv(uno::Environment::getCurrent());
63 rtl_uString
* pOId
= NULL
;
64 currentEnv
.get()->pExtEnv
->getObjectIdentifier(currentEnv
.get()->pExtEnv
, &pOId
, pObject
);
67 uno::TypeDescription
typeDescription(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface")));
69 void * pRegisteredObject
= NULL
;
70 currentEnv
.get()->pExtEnv
->getRegisteredInterface(currentEnv
.get()->pExtEnv
,
73 (typelib_InterfaceTypeDescription
*)typeDescription
.get());
76 if (pOId
) rtl_uString_release(pOId
);
78 bool result
= pRegisteredObject
!= NULL
;
81 currentEnv
.get()->pExtEnv
->releaseInterface(currentEnv
.get()->pExtEnv
, pRegisteredObject
);
86 static void s_test__loadSharedLibComponentFactory(rtl::OUString
const & clientPurpose
,
87 rtl::OUString
const & servicePurpose
)
89 cppu::EnvGuard
envGuard(uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
))
90 + clientPurpose
, NULL
));
91 if (clientPurpose
.getLength() && !envGuard
.is())
93 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't get purpose env: \""));
94 s_comment
+= clientPurpose
;
95 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
100 rtl::OString
os_clientPurpose(rtl::OUStringToOString(clientPurpose
, RTL_TEXTENCODING_ASCII_US
));
102 uno::Reference
<uno::XInterface
> xItf(
103 cppu::loadSharedLibComponentFactory(
104 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX
"TestComponent.uno" SAL_DLLEXTENSION
)),
106 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("")),
108 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file://../lib/")),
110 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("impl.test.TestComponent")) + servicePurpose
,
111 uno::Reference
<lang::XMultiServiceFactory
>(),
112 uno::Reference
<registry::XRegistryKey
>()
118 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tgot no object - FAILURE\n"));
122 if (!clientPurpose
.equals(servicePurpose
) && !s_check_object_is_in(xItf
.get()))
124 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't find object in current purpose \""));
125 s_comment
+= clientPurpose
;
126 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
129 if (!cppu::EnvDcp::getPurpose(uno::Environment::getCurrent().getTypeName()).equals(clientPurpose
))
131 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tdid not enter client purpose \""));
132 s_comment
+= clientPurpose
;
133 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
137 static void s_test__loadSharedLibComponentFactory__free_free()
139 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__loadSharedLibComponentFactory__free_free\n"));
141 s_test__loadSharedLibComponentFactory(rtl::OUString(), rtl::OUString());
144 static void s_test__loadSharedLibComponentFactory__free_purpose()
146 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__loadSharedLibComponentFactory__free_purpose\n"));
148 s_test__loadSharedLibComponentFactory(rtl::OUString(),
149 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv")));
152 static void s_test__loadSharedLibComponentFactory__purpose_free()
154 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__loadSharedLibComponentFactory__purpose_free\n"));
156 s_test__loadSharedLibComponentFactory(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv")),
160 static void s_test__loadSharedLibComponentFactory__purpose_purpose()
162 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__loadSharedLibComponentFactory__purpose_purpose\n"));
164 s_test__loadSharedLibComponentFactory(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv")),
165 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv")));
168 static rtl::OUString
s_getSDrive(void)
170 rtl::OUString path
;//(RTL_CONSTASCII_USTRINGPARAM("file://"));
172 char const * tmp
= getenv("SOLARVER");
173 path
+= rtl::OUString(tmp
, rtl_str_getLength(tmp
), RTL_TEXTENCODING_ASCII_US
);
174 path
+= rtl::OUString(SAL_PATHDELIMITER
);
176 tmp
= getenv("INPATH");
177 path
+= rtl::OUString(tmp
, rtl_str_getLength(tmp
), RTL_TEXTENCODING_ASCII_US
);
178 path
+= rtl::OUString(SAL_PATHDELIMITER
);
180 path
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bin"));
183 path
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("lib"));
186 tmp
= getenv("UPDMINOREXT");
188 path
+= rtl::OUString(tmp
, rtl_str_getLength(tmp
), RTL_TEXTENCODING_ASCII_US
);
190 osl::FileBase::getFileURLFromSystemPath(path
, path
);
195 static void s_test__createSimpleRegistry(rtl::OUString
const & clientPurpose
)
197 cppu::EnvGuard
envGuard(uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
))
198 + clientPurpose
, NULL
));
199 if (clientPurpose
.getLength() && !envGuard
.is())
201 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't get purpose env: \""));
202 s_comment
+= clientPurpose
;
203 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
208 uno::Reference
<registry::XSimpleRegistry
> registry(cppu::createSimpleRegistry(
213 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tgot no object - FAILURE\n"));
217 if (clientPurpose
.getLength() != 0 && !s_check_object_is_in(registry
.get()))
219 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't find object in current purpose \""));
220 s_comment
+= clientPurpose
;
221 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
225 static void s_test__createSimpleRegistry__free(void)
227 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__createSimpleRegistry__free\n"));
229 s_test__createSimpleRegistry(rtl::OUString());
232 static void s_test__createSimpleRegistry__purpose(void)
234 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__createSimpleRegistry__purpose\n"));
236 s_test__createSimpleRegistry(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv")));
240 static void s_test__bootstrap_InitialComponentContext(rtl::OUString
const & clientPurpose
)
242 cppu::EnvGuard
envGuard(uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
))
243 + clientPurpose
, NULL
));
244 if (clientPurpose
.getLength() && !envGuard
.is())
246 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't get purpose env: \""));
247 s_comment
+= clientPurpose
;
248 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
253 uno::Reference
<uno::XComponentContext
> xContext(
254 cppu::bootstrap_InitialComponentContext(
255 uno::Reference
<registry::XSimpleRegistry
>(),
261 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tgot no object - FAILURE\n"));
265 if (clientPurpose
.getLength() != 0 && !s_check_object_is_in(xContext
.get()))
267 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't find object in current purpose \""));
268 s_comment
+= clientPurpose
;
269 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
272 uno::Reference
<lang::XComponent
> xComponent(xContext
, uno::UNO_QUERY_THROW
);
273 xComponent
->dispose();
276 static void s_test__bootstrap_InitialComponentContext__free(void)
278 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__bootstrap_InitialComponentContext__free\n"));
280 s_test__bootstrap_InitialComponentContext(rtl::OUString());
283 static void s_test__bootstrap_InitialComponentContext__purpose(void)
285 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__bootstrap_InitialComponentContext__purpose\n"));
287 s_test__bootstrap_InitialComponentContext(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv")));
291 SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv
)
293 s_test__createSimpleRegistry__free();
294 s_test__createSimpleRegistry__purpose();
296 s_test__loadSharedLibComponentFactory__free_free();
297 s_test__loadSharedLibComponentFactory__free_purpose();
298 s_test__loadSharedLibComponentFactory__purpose_free();
299 s_test__loadSharedLibComponentFactory__purpose_purpose();
301 s_test__bootstrap_InitialComponentContext__free();
302 s_test__bootstrap_InitialComponentContext__purpose();
305 if (s_comment
.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILURE"))) == -1)
307 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n"));
312 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n"));
319 << rtl::OUStringToOString(s_comment
, RTL_TEXTENCODING_ASCII_US
).getStr()