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: purpenv.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 ************************************************************************/
35 #include "uno/environment.hxx"
36 #include "uno/dispatcher.h"
38 #include "typelib/typedescription.h"
40 #include "com/sun/star/uno/Any.h"
42 #include "../ObjectFactory/ObjectFactory.hxx"
45 using namespace com::sun::star
;
48 static rtl::OUString
g_usret(RTL_CONSTASCII_USTRINGPARAM("\n"));
49 static rtl::OUString
g_ustab(RTL_CONSTASCII_USTRINGPARAM("\t"));
50 static rtl::OUString g_comment
;
51 static uno::Environment g_env
;
52 static bool g_check
= 0;
54 extern "C" { static void s_callee(rtl_uString
* pMethod_name
)
60 g_comment
+= rtl::OUString(pMethod_name
);
63 int valid
= g_env
.isValid(&reason
);
65 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("["));
66 g_comment
+= rtl::OUString::valueOf((sal_Int32
)valid
);
67 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
69 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]"));
72 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - FAILURE"));
79 static rtl::OUString
s_test_registerInterface(rtl::OUString
const & envDcp
)
81 g_env
= uno::Environment(envDcp
);
83 g_comment
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test_registerInterface"));
86 rtl::OUString
id(RTL_CONSTASCII_USTRINGPARAM("blabla"));
88 typelib_TypeDescriptionReference
* type_XInterface
=
89 * typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE
);
91 typelib_TypeDescription
* pRet
= NULL
;
92 typelib_typedescriptionreference_getDescription(&pRet
, type_XInterface
);
94 void * pObject
= createObject(envDcp
, s_callee
);
96 g_env
.get()->pExtEnv
->registerInterface(g_env
.get()->pExtEnv
,
99 (struct _typelib_InterfaceTypeDescription
*)pRet
);
102 g_env
.get()->pExtEnv
->revokeInterface(g_env
.get()->pExtEnv
, pObject
);
103 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, pObject
);
110 extern "C" { static void s_freeFunc(struct _uno_ExtEnvironment
* /*pEnv*/, void * /*pProxy*/ )
114 g_comment
+= g_ustab
;
115 g_comment
+= g_ustab
;
116 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("s_freeFunc"));
118 rtl::OUString reason
;
119 int valid
= g_env
.isValid(&reason
);
121 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("["));
122 g_comment
+= rtl::OUString::valueOf((sal_Int32
)valid
);
123 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
125 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]"));
128 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - FAILURE"));
130 g_comment
+= g_usret
;
134 static rtl::OUString
s_test_registerProxyInterface(rtl::OUString
const & envDcp
)
136 g_env
= uno::Environment(envDcp
);
138 g_comment
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test_registerProxyInterface"));
139 g_comment
+= g_usret
;
141 rtl::OUString
id(RTL_CONSTASCII_USTRINGPARAM("blabla"));
143 typelib_TypeDescriptionReference
* type_XInterface
=
144 * typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE
);
146 typelib_TypeDescription
* pRet
= NULL
;
147 typelib_typedescriptionreference_getDescription(&pRet
, type_XInterface
);
149 void * pObject
= createObject(envDcp
, s_callee
);
151 g_env
.get()->pExtEnv
->registerProxyInterface(g_env
.get()->pExtEnv
,
155 (typelib_InterfaceTypeDescription
*)pRet
);
158 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, pObject
);
160 g_env
.get()->pExtEnv
->revokeInterface(g_env
.get()->pExtEnv
, pObject
);
169 static rtl::OUString
s_test_revokeInterface(rtl::OUString
const & envDcp
)
171 g_env
= uno::Environment(envDcp
);
173 g_comment
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test_revokeInterface"));
174 g_comment
+= g_usret
;
176 rtl::OUString
id(RTL_CONSTASCII_USTRINGPARAM("blabla"));
178 typelib_TypeDescriptionReference
* type_XInterface
=
179 * typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE
);
181 typelib_TypeDescription
* pRet
= NULL
;
182 typelib_typedescriptionreference_getDescription(&pRet
, type_XInterface
);
184 void * pObject
= createObject(envDcp
, s_callee
);
185 g_env
.get()->pExtEnv
->registerInterface(g_env
.get()->pExtEnv
,
188 (struct _typelib_InterfaceTypeDescription
*)pRet
);
191 g_env
.get()->pExtEnv
->revokeInterface(g_env
.get()->pExtEnv
, pObject
);
193 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, pObject
);
200 static rtl::OUString
s_test_getObjectIdentifier(rtl::OUString
const & envDcp
)
202 g_env
= uno::Environment(envDcp
);
204 g_comment
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test_getObjectIdentifier"));
205 g_comment
+= g_usret
;
208 void * pObject
= createObject(envDcp
, s_callee
);
210 g_env
.get()->pExtEnv
->getObjectIdentifier(g_env
.get()->pExtEnv
, &oId
.pData
, pObject
);
212 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, pObject
);
219 static rtl::OUString
s_test_getRegisteredInterface(rtl::OUString
const & envDcp
)
221 g_env
= uno::Environment(envDcp
);
223 g_comment
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test_getRegisteredInterface"));
224 g_comment
+= g_usret
;
226 rtl::OUString
id(RTL_CONSTASCII_USTRINGPARAM("blabla"));
229 typelib_TypeDescriptionReference
* type_XInterface
=
230 * typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE
);
232 typelib_TypeDescription
* pRet
= NULL
;
233 typelib_typedescriptionreference_getDescription(&pRet
, type_XInterface
);
235 void * pObject
= createObject(envDcp
, s_callee
);
236 g_env
.get()->pExtEnv
->registerInterface(g_env
.get()->pExtEnv
,
239 (typelib_InterfaceTypeDescription
*)pRet
);
243 g_env
.get()->pExtEnv
->getRegisteredInterface(g_env
.get()->pExtEnv
, &pObject
, id
.pData
,
244 (typelib_InterfaceTypeDescription
*)pRet
);
247 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, pObject
);
248 g_env
.get()->pExtEnv
->revokeInterface(g_env
.get()->pExtEnv
, pObject
);
255 static rtl::OUString
s_test_getRegisteredInterfaces(rtl::OUString
const & envDcp
)
257 g_env
= uno::Environment(envDcp
);
259 g_comment
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test_getRegisteredInterfaces"));
260 g_comment
+= g_usret
;
262 rtl::OUString
id(RTL_CONSTASCII_USTRINGPARAM("blabla"));
265 typelib_TypeDescriptionReference
* type_XInterface
=
266 * typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE
);
268 typelib_TypeDescription
* pRet
= NULL
;
269 typelib_typedescriptionreference_getDescription(&pRet
, type_XInterface
);
271 void * pObject
= createObject(envDcp
, s_callee
);
272 g_env
.get()->pExtEnv
->registerInterface(g_env
.get()->pExtEnv
,
275 (typelib_InterfaceTypeDescription
*)pRet
);
280 g_env
.get()->pExtEnv
->getRegisteredInterfaces(g_env
.get()->pExtEnv
, &ppObject
, &nCount
, rtl_allocateMemory
);
286 g_comment
+= g_ustab
;
287 g_comment
+= g_ustab
;
288 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("more than one object registered -> FAILURE"));
289 g_comment
+= g_usret
;
292 if (*ppObject
!= pObject
)
294 g_comment
+= g_ustab
;
295 g_comment
+= g_ustab
;
296 g_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("returned object is not the registerd one -> FAILURE"));
297 g_comment
+= g_usret
;
300 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, *ppObject
);
302 g_env
.get()->pExtEnv
->revokeInterface(g_env
.get()->pExtEnv
, pObject
);
303 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, pObject
);
305 rtl_freeMemory(ppObject
);
312 static rtl::OUString
s_test_computeObjectIdentifier(rtl::OUString
const & envDcp
)
314 g_env
= uno::Environment(envDcp
);
316 g_comment
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test_computeObjectIdentifier"));
317 g_comment
+= g_usret
;
320 void * pObject
= createObject(envDcp
, s_callee
);
322 g_env
.get()->pExtEnv
->computeObjectIdentifier(g_env
.get()->pExtEnv
, &oId
.pData
, pObject
);
324 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, pObject
);
331 static rtl::OUString
s_test_acquire(rtl::OUString
const & envDcp
)
333 g_env
= uno::Environment(envDcp
);
335 g_comment
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test_acquire"));
336 g_comment
+= g_usret
;
337 void * pObject
= createObject(envDcp
, s_callee
);
340 g_env
.get()->pExtEnv
->acquireInterface(g_env
.get()->pExtEnv
, pObject
);
343 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, pObject
);
344 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, pObject
);
350 static rtl::OUString
s_test_release(rtl::OUString
const & envDcp
)
352 g_env
= uno::Environment(envDcp
);
354 g_comment
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test_release"));
355 g_comment
+= g_usret
;
356 void * pObject
= createObject(envDcp
, s_callee
);
359 g_env
.get()->pExtEnv
->releaseInterface(g_env
.get()->pExtEnv
, pObject
);
368 rtl::OUString
purpenv_test(rtl::OUString
const & envDcp
)
370 g_env
= uno::Environment(envDcp
);
372 rtl::OUString result
;
373 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("purpenv_test"));
374 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
376 result
+= s_test_registerInterface(envDcp
);
379 result
+= s_test_registerProxyInterface(envDcp
);
382 result
+= s_test_revokeInterface(envDcp
);
385 result
+= s_test_getObjectIdentifier(envDcp
);
388 result
+= s_test_getRegisteredInterface(envDcp
);
391 result
+= s_test_getRegisteredInterfaces(envDcp
);
394 result
+= s_test_computeObjectIdentifier(envDcp
);
397 result
+= s_test_acquire(envDcp
);
400 result
+= s_test_release(envDcp
);