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: Map.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"
37 #include "cppu/Map.hxx"
38 #include "cppu/EnvGuards.hxx"
40 #include "../ObjectFactory/ObjectFactory.hxx"
43 using namespace com::sun::star
;
46 static rtl::OUString s_comment
;
47 static uno::Environment s_env
;
50 static void s_callee_in(rtl_uString
* pMethod_name
)
52 rtl::OUString
method_name(pMethod_name
);
54 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\ts_callee_in method:\""));
55 s_comment
+= method_name
;
57 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" env: \""));
58 s_comment
+= uno::Environment::getCurrent().getTypeName();
59 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""));
63 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - FAILURE: s_env not set"));
68 int valid
= s_env
.isValid(&reason
);
71 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
75 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - FAILURE: "));
77 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
81 static void s_callee_out(rtl_uString
* pMethod_name
)
83 rtl::OUString
method_name(pMethod_name
);
85 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\ts_callee_out method:\""));
86 s_comment
+= method_name
;
88 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" env: \""));
89 s_comment
+= uno::Environment::getCurrent().getTypeName();
90 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""));
94 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - FAILURE: s_env not set"));
99 int valid
= s_env
.isValid(&reason
);
102 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
105 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - FAILURE: is in\n"));
109 static uno::Reference
<uno::XInterface
> s_get_envObject(void)
111 cppu::EnvGuard
envGuard(s_env
);
113 uno::XInterface
* pObject
= reinterpret_cast<uno::XInterface
*>(
114 createObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV
))),
117 return uno::Reference
<uno::XInterface
>(pObject
, SAL_NO_ACQUIRE
);
120 static uno::XInterface
* s_x_get_flatObject(void)
122 uno::XInterface
* pObject
= reinterpret_cast<uno::XInterface
*>(
123 createObject(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV
))),
129 static uno::Reference
<uno::XInterface
> s_get_flatObject(void)
131 return uno::Reference
<uno::XInterface
>(s_x_get_flatObject(), SAL_NO_ACQUIRE
);
135 static void s_test__mapOut(void)
137 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__mapOut:\n"));
139 uno::Reference
<uno::XInterface
> obj
;
142 cppu::EnvGuard
envGuard(s_env
);
143 obj
.set(cppu::mapOut(s_get_envObject().get(),
144 uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
)))),
152 static void s_test__mapIn(void)
154 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__unshield:\n"));
156 uno::Reference
<uno::XInterface
> obj
;
159 cppu::EnvGuard
envGuard(s_env
);
160 uno::XInterface
* pObj
= s_x_get_flatObject();
161 obj
.set(cppu::mapIn(pObj
,
162 uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
)))),
171 cppu::EnvGuard
envGuard(s_env
);
176 static void s_test__mapOutAny(void)
178 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__shieldAny:\n"));
183 cppu::EnvGuard
envGuard(s_env
);
185 any
<<= s_get_envObject();
188 uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
))));
191 uno::Reference
<uno::XInterface
> obj
;
198 static void s_test__mapInAny(void)
200 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__unshieldAny:\n"));
204 uno::Any
any(s_get_flatObject());
207 cppu::EnvGuard
envGuard(s_env
);
210 uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
))));
215 cppu::EnvGuard
envGuard(s_env
);
217 uno::Reference
<uno::XInterface
> obj
;
225 SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv
)
227 uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
))).enter();
229 s_env
= uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("uno:unsafe")));
239 uno_Environment_enter(NULL
);
243 if (s_comment
.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILURE"))) == -1)
245 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n"));
250 s_comment
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n"));
257 << rtl::OUStringToOString(s_comment
, RTL_TEXTENCODING_ASCII_US
).getStr()