merge the formfield patch from ooo-build
[ooovba.git] / cppu / test / Map / Map.test.cxx
blob04aba9e51e625fe1b7e2127862cb47d182c16662
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: Map.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"
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;
49 extern "C" {
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("\""));
61 if (!s_env.is())
63 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - FAILURE: s_env not set"));
64 return;
67 rtl::OUString reason;
68 int valid = s_env.isValid(&reason);
70 if (valid)
71 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
73 else
75 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - FAILURE: "));
76 s_comment += reason;
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("\""));
92 if (!s_env.is())
94 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - FAILURE: s_env not set"));
95 return;
98 rtl::OUString reason;
99 int valid = s_env.isValid(&reason);
101 if (!valid)
102 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
104 else
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))),
115 s_callee_in));
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))),
124 s_callee_out));
126 return pObject;
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)))),
145 SAL_NO_ACQUIRE);
148 obj->acquire();
149 obj->release();
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)))),
163 SAL_NO_ACQUIRE);
165 envGuard.clear();
167 pObj->release();
171 cppu::EnvGuard envGuard(s_env);
172 obj.clear();
176 static void s_test__mapOutAny(void)
178 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__shieldAny:\n"));
180 uno::Any out;
183 cppu::EnvGuard envGuard(s_env);
184 uno::Any any;
185 any <<= s_get_envObject();
186 cppu::mapOutAny(any,
187 &out,
188 uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME))));
191 uno::Reference<uno::XInterface> obj;
192 out >>= obj;
194 obj->acquire();
195 obj->release();
198 static void s_test__mapInAny(void)
200 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__unshieldAny:\n"));
202 uno::Any out;
204 uno::Any any(s_get_flatObject());
207 cppu::EnvGuard envGuard(s_env);
208 cppu::mapInAny(any,
209 &out,
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;
218 out >>= obj;
220 obj.clear();
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")));
231 s_test__mapOut();
232 s_test__mapOutAny();
233 s_test__mapIn();
234 s_test__mapInAny();
236 s_env.clear();
239 uno_Environment_enter(NULL);
242 int ret;
243 if (s_comment.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILURE"))) == -1)
245 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n"));
246 ret = 0;
248 else
250 s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n"));
251 ret = -1;
254 std::cerr
255 << argv[0]
256 << std::endl
257 << rtl::OUStringToOString(s_comment, RTL_TEXTENCODING_ASCII_US).getStr()
258 << std::endl;
260 return ret;