update dev300-m58
[ooovba.git] / cppu / test / env_tester / purpenv.test.cxx
blob0c59af975ef94246060e08ebf5af60f276fef885
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: purpenv.test.cxx,v $
10 * $Revision: 1.3 $
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 ************************************************************************/
31 #include <iostream>
33 #include "sal/main.h"
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)
56 if (g_check)
58 g_comment += g_ustab;
59 g_comment += g_ustab;
60 g_comment += rtl::OUString(pMethod_name);
62 rtl::OUString reason;
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(","));
68 g_comment += reason;
69 g_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]"));
71 if (!valid)
72 g_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - FAILURE"));
74 g_comment += g_usret;
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"));
84 g_comment += g_usret;
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);
95 g_check = 1;
96 g_env.get()->pExtEnv->registerInterface(g_env.get()->pExtEnv,
97 &pObject,
98 id.pData,
99 (struct _typelib_InterfaceTypeDescription *)pRet);
100 g_check = 0;
102 g_env.get()->pExtEnv->revokeInterface(g_env.get()->pExtEnv, pObject);
103 g_env.get()->pExtEnv->releaseInterface(g_env.get()->pExtEnv, pObject);
105 g_env.clear();
107 return g_comment;
110 extern "C" { static void s_freeFunc(struct _uno_ExtEnvironment * /*pEnv*/, void * /*pProxy*/ )
112 if (g_check)
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(","));
124 g_comment += reason;
125 g_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]"));
127 if (!valid)
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);
150 g_check = 1;
151 g_env.get()->pExtEnv->registerProxyInterface(g_env.get()->pExtEnv,
152 &pObject,
153 s_freeFunc,
154 id.pData,
155 (typelib_InterfaceTypeDescription *)pRet);
156 g_check = 0;
158 g_env.get()->pExtEnv->releaseInterface(g_env.get()->pExtEnv, pObject);
159 g_check = 1;
160 g_env.get()->pExtEnv->revokeInterface(g_env.get()->pExtEnv, pObject);
161 g_check = 0;
163 g_env.clear();
166 return g_comment;
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,
186 &pObject,
187 id.pData,
188 (struct _typelib_InterfaceTypeDescription *)pRet);
190 g_check = 1;
191 g_env.get()->pExtEnv->revokeInterface(g_env.get()->pExtEnv, pObject);
192 g_check = 0;
193 g_env.get()->pExtEnv->releaseInterface(g_env.get()->pExtEnv, pObject);
195 g_env.clear();
197 return g_comment;
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;
207 rtl::OUString oId;
208 void * pObject = createObject(envDcp, s_callee);
209 g_check = 1;
210 g_env.get()->pExtEnv->getObjectIdentifier(g_env.get()->pExtEnv, &oId.pData, pObject);
211 g_check = 0;
212 g_env.get()->pExtEnv->releaseInterface(g_env.get()->pExtEnv, pObject);
214 g_env.clear();
216 return g_comment;
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,
237 &pObject,
238 id.pData,
239 (typelib_InterfaceTypeDescription *)pRet);
242 g_check = 1;
243 g_env.get()->pExtEnv->getRegisteredInterface(g_env.get()->pExtEnv, &pObject, id.pData,
244 (typelib_InterfaceTypeDescription *)pRet);
245 g_check = 0;
247 g_env.get()->pExtEnv->releaseInterface(g_env.get()->pExtEnv, pObject);
248 g_env.get()->pExtEnv->revokeInterface(g_env.get()->pExtEnv, pObject);
250 g_env.clear();
252 return g_comment;
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,
273 &pObject,
274 id.pData,
275 (typelib_InterfaceTypeDescription *)pRet);
277 g_check = 1;
278 void ** ppObject;
279 sal_Int32 nCount;
280 g_env.get()->pExtEnv->getRegisteredInterfaces(g_env.get()->pExtEnv, &ppObject, &nCount, rtl_allocateMemory);
281 g_check = 0;
284 if (nCount != 1)
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);
307 g_env.clear();
309 return g_comment;
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;
319 rtl::OUString oId;
320 void * pObject = createObject(envDcp, s_callee);
321 g_check = 1;
322 g_env.get()->pExtEnv->computeObjectIdentifier(g_env.get()->pExtEnv, &oId.pData, pObject);
323 g_check = 0;
324 g_env.get()->pExtEnv->releaseInterface(g_env.get()->pExtEnv, pObject);
326 g_env.clear();
328 return g_comment;
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);
339 g_check = 1;
340 g_env.get()->pExtEnv->acquireInterface(g_env.get()->pExtEnv, pObject);
341 g_check = 0;
343 g_env.get()->pExtEnv->releaseInterface(g_env.get()->pExtEnv, pObject);
344 g_env.get()->pExtEnv->releaseInterface(g_env.get()->pExtEnv, pObject);
345 g_env.clear();
347 return g_comment;
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);
358 g_check = 1;
359 g_env.get()->pExtEnv->releaseInterface(g_env.get()->pExtEnv, pObject);
360 g_check = 0;
362 g_env.clear();
364 return g_comment;
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);
377 result += g_usret;
379 result += s_test_registerProxyInterface(envDcp);
380 result += g_usret;
382 result += s_test_revokeInterface(envDcp);
383 result += g_usret;
385 result += s_test_getObjectIdentifier(envDcp);
386 result += g_usret;
388 result += s_test_getRegisteredInterface(envDcp);
389 result += g_usret;
391 result += s_test_getRegisteredInterfaces(envDcp);
392 result += g_usret;
394 result += s_test_computeObjectIdentifier(envDcp);
395 result += g_usret;
397 result += s_test_acquire(envDcp);
398 result += g_usret;
400 result += s_test_release(envDcp);
401 result += g_usret;
403 return result;