bump product version to 4.1.6.2
[LibreOffice.git] / cppuhelper / test / bootstrap / bootstrap.test.cxx
blob8614910724775540443999419b5fedb310a39b25
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include "sal/main.h"
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 "cppu/EnvDcp.hxx"
33 #include "cppu/EnvGuards.hxx"
35 #include <iostream>
38 #ifndef SAL_DLLPREFIX
39 # define SAL_DLLPREFIX ""
40 #endif
43 using namespace com::sun::star;
46 static rtl::OUString s_comment;
48 static bool s_check_object_is_in(void * pObject)
50 uno::Environment currentEnv(uno::Environment::getCurrent());
52 rtl_uString * pOId = NULL;
53 currentEnv.get()->pExtEnv->getObjectIdentifier(currentEnv.get()->pExtEnv, &pOId, pObject);
56 uno::TypeDescription typeDescription(rtl::OUString("com.sun.star.uno.XInterface"));
58 void * pRegisteredObject = NULL;
59 currentEnv.get()->pExtEnv->getRegisteredInterface(currentEnv.get()->pExtEnv,
60 &pRegisteredObject,
61 pOId,
62 (typelib_InterfaceTypeDescription *)typeDescription.get());
65 if (pOId) rtl_uString_release(pOId);
67 bool result = pRegisteredObject != NULL;
69 if (result)
70 currentEnv.get()->pExtEnv->releaseInterface(currentEnv.get()->pExtEnv, pRegisteredObject);
72 return result;
75 static void s_test__loadSharedLibComponentFactory(rtl::OUString const & clientPurpose,
76 rtl::OUString const & servicePurpose)
78 cppu::EnvGuard envGuard(uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO))
79 + clientPurpose, NULL));
80 if (clientPurpose.getLength() && !envGuard.is())
82 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't get purpose env: \""));
83 s_comment += clientPurpose;
84 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
86 return;
89 rtl::OString os_clientPurpose(rtl::OUStringToOString(clientPurpose, RTL_TEXTENCODING_ASCII_US));
91 uno::Reference<uno::XInterface> xItf(
92 cppu::loadSharedLibComponentFactory(
93 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)),
94 #ifdef WIN32
95 rtl::OUString(""),
96 #else
97 rtl::OUString("file://../lib/"),
98 #endif
99 rtl::OUString("impl.test.TestComponent") + servicePurpose,
100 uno::Reference<lang::XMultiServiceFactory>(),
101 uno::Reference<registry::XRegistryKey>()
105 if (!xItf.is())
107 s_comment += rtl::OUString("\t\tgot no object - FAILURE\n");
108 return;
111 if (!clientPurpose.equals(servicePurpose) && !s_check_object_is_in(xItf.get()))
113 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't find object in current purpose \""));
114 s_comment += clientPurpose;
115 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
118 if (!cppu::EnvDcp::getPurpose(uno::Environment::getCurrent().getTypeName()).equals(clientPurpose))
120 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tdid not enter client purpose \""));
121 s_comment += clientPurpose;
122 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
126 static void s_test__loadSharedLibComponentFactory__free_free()
128 s_comment += rtl::OUString("\ts_test__loadSharedLibComponentFactory__free_free\n");
130 s_test__loadSharedLibComponentFactory(rtl::OUString(), rtl::OUString());
133 static void s_test__loadSharedLibComponentFactory__free_purpose()
135 s_comment += rtl::OUString("\ts_test__loadSharedLibComponentFactory__free_purpose\n");
137 s_test__loadSharedLibComponentFactory(rtl::OUString(),
138 rtl::OUString(":testenv"));
141 static void s_test__loadSharedLibComponentFactory__purpose_free()
143 s_comment += rtl::OUString("\ts_test__loadSharedLibComponentFactory__purpose_free\n");
145 s_test__loadSharedLibComponentFactory(rtl::OUString(":testenv"),
146 rtl::OUString());
149 static void s_test__loadSharedLibComponentFactory__purpose_purpose()
151 s_comment += rtl::OUString("\ts_test__loadSharedLibComponentFactory__purpose_purpose\n");
153 s_test__loadSharedLibComponentFactory(rtl::OUString(":testenv"),
154 rtl::OUString(":testenv"));
157 static rtl::OUString s_getSDrive(void)
159 rtl::OUString path;//(RTL_CONSTASCII_USTRINGPARAM("file://"));
161 char const * tmp = getenv("SOLARVER");
162 path += rtl::OUString(tmp, rtl_str_getLength(tmp), RTL_TEXTENCODING_ASCII_US);
163 path += rtl::OUString(SAL_PATHDELIMITER);
165 tmp = getenv("INPATH");
166 path += rtl::OUString(tmp, rtl_str_getLength(tmp), RTL_TEXTENCODING_ASCII_US);
167 path += rtl::OUString(SAL_PATHDELIMITER);
168 #ifdef WIN32
169 path += rtl::OUString("bin");
171 #else
172 path += rtl::OUString("lib");
173 #endif
175 tmp = getenv("UPDMINOREXT");
176 if (tmp)
177 path += rtl::OUString(tmp, rtl_str_getLength(tmp), RTL_TEXTENCODING_ASCII_US);
179 osl::FileBase::getFileURLFromSystemPath(path, path);
181 return path;
184 static void s_test__createSimpleRegistry(rtl::OUString const & clientPurpose)
186 cppu::EnvGuard envGuard(uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO))
187 + clientPurpose, NULL));
188 if (clientPurpose.getLength() && !envGuard.is())
190 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't get purpose env: \""));
191 s_comment += clientPurpose;
192 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
194 return;
197 uno::Reference<registry::XSimpleRegistry> registry(cppu::createSimpleRegistry(
198 s_getSDrive()));
200 if (!registry.is())
202 s_comment += rtl::OUString("\t\tgot no object - FAILURE\n");
203 return;
206 if (clientPurpose.getLength() != 0 && !s_check_object_is_in(registry.get()))
208 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't find object in current purpose \""));
209 s_comment += clientPurpose;
210 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
214 static void s_test__createSimpleRegistry__free(void)
216 s_comment += rtl::OUString("\ts_test__createSimpleRegistry__free\n");
218 s_test__createSimpleRegistry(rtl::OUString());
221 static void s_test__createSimpleRegistry__purpose(void)
223 s_comment += rtl::OUString("\ts_test__createSimpleRegistry__purpose\n");
225 s_test__createSimpleRegistry(rtl::OUString(":testenv"));
229 static void s_test__bootstrap_InitialComponentContext(rtl::OUString const & clientPurpose)
231 cppu::EnvGuard envGuard(uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO))
232 + clientPurpose, NULL));
233 if (clientPurpose.getLength() && !envGuard.is())
235 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't get purpose env: \""));
236 s_comment += clientPurpose;
237 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
239 return;
242 uno::Reference<uno::XComponentContext> xContext(
243 cppu::bootstrap_InitialComponentContext(
244 uno::Reference<registry::XSimpleRegistry>(),
245 s_getSDrive())
248 if (!xContext.is())
250 s_comment += rtl::OUString("\t\tgot no object - FAILURE\n");
251 return;
254 if (clientPurpose.getLength() != 0 && !s_check_object_is_in(xContext.get()))
256 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't find object in current purpose \""));
257 s_comment += clientPurpose;
258 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n"));
261 uno::Reference<lang::XComponent> xComponent(xContext, uno::UNO_QUERY_THROW);
262 xComponent->dispose();
265 static void s_test__bootstrap_InitialComponentContext__free(void)
267 s_comment += rtl::OUString("\ts_test__bootstrap_InitialComponentContext__free\n");
269 s_test__bootstrap_InitialComponentContext(rtl::OUString());
272 static void s_test__bootstrap_InitialComponentContext__purpose(void)
274 s_comment += rtl::OUString("\ts_test__bootstrap_InitialComponentContext__purpose\n");
276 s_test__bootstrap_InitialComponentContext(rtl::OUString(":testenv"));
280 SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv)
282 s_test__createSimpleRegistry__free();
283 s_test__createSimpleRegistry__purpose();
285 s_test__loadSharedLibComponentFactory__free_free();
286 s_test__loadSharedLibComponentFactory__free_purpose();
287 s_test__loadSharedLibComponentFactory__purpose_free();
288 s_test__loadSharedLibComponentFactory__purpose_purpose();
290 s_test__bootstrap_InitialComponentContext__free();
291 s_test__bootstrap_InitialComponentContext__purpose();
293 int ret;
294 if (s_comment.indexOf("FAILURE") == -1)
296 s_comment += rtl::OUString("TESTS PASSED\n");
297 ret = 0;
299 else
301 s_comment += rtl::OUString("TESTS _NOT_ PASSED\n");
302 ret = -1;
305 std::cerr
306 << argv[0]
307 << std::endl
308 << rtl::OUStringToOString(s_comment, RTL_TEXTENCODING_ASCII_US).getStr()
309 << std::endl;
311 return ret;
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */