merge the formfield patch from ooo-build
[ooovba.git] / cppu / test / env_tester / register.test.cxx
blob3ef6cd9651e29c212a7cd309b905f9f449984330
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: register.test.cxx,v $
10 * $Revision: 1.4 $
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"
34 #include "rtl/ustring.hxx"
35 #include "rtl/string.hxx"
36 #include "rtl/alloc.h"
37 #include "uno/environment.hxx"
38 #include "uno/lbnames.h"
40 using namespace com::sun::star;
43 static rtl::OUString s_test_getEnvironment(rtl::OUString const & envDcp, void * pContext)
45 rtl::OUString result(RTL_CONSTASCII_USTRINGPARAM("\ts_test_getEnvironment("));
46 result += envDcp;
47 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(", "));
48 result += rtl::OUString::valueOf((long)pContext);
49 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")\n"));
51 uno::Environment env(envDcp, pContext);
53 if (!env.is())
55 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tFAILURE: couldn't get env.\n"));
56 return result;
59 if (rtl::OUString(env.getTypeName()).compareTo(envDcp))
60 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tFAILURE: got environment has wrong descriptor.\n"));
62 if (env.getContext() != pContext)
63 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tFAILURE: got environment has wrong context.\n"));
66 return result;
69 static rtl::OUString s_test_regetEnvironment(rtl::OUString const & envDcp1,
70 rtl::OUString const & envDcp2 ,
71 void * pContext1, void * pContext2)
73 rtl::OUString result(RTL_CONSTASCII_USTRINGPARAM("\ts_test_regetEnvironment("));
74 result += envDcp1;
75 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(", "));
76 result += envDcp2;
77 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(", "));
78 result += rtl::OUString::valueOf((long)pContext1);
79 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(", " ));
80 result += rtl::OUString::valueOf((long)pContext2);
81 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")\n"));
83 uno::Environment env1(envDcp1, pContext1);
84 uno::Environment env2(envDcp2, pContext2);
86 if (! ((pContext1 == pContext2 && envDcp1 == envDcp2) ? env1.get() == env2.get() : env1.get() != env2.get())
87 && env1.is() && env2.is())
88 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tFAILURE:\n"));
90 return result;
93 static rtl::OUString s_test_regetEnvironment(rtl::OUString const & envDcp, void * pContext)
95 return s_test_regetEnvironment(envDcp, envDcp, pContext, pContext);
98 // static rtl::OUString s_test_regetEnvironment(rtl::OUString const & envDcp, void * pContext1, void * pContext2)
99 // {
100 // return s_test_regetEnvironment(envDcp, envDcp, pContext1, pContext2);
101 // }
103 static rtl::OUString s_test_regetEnvironment(rtl::OUString const & envDcp1, rtl::OUString const & envDcp2, void * pContext)
105 return s_test_regetEnvironment(envDcp1, envDcp2, pContext, pContext);
109 static int s_is_registered(rtl::OUString const & envDcp, void * pContext)
111 int result = 0;
113 uno_Environment ** ppEnvs = NULL;
114 sal_Int32 nLen = 0;
116 uno_getRegisteredEnvironments(&ppEnvs, &nLen, rtl_allocateMemory, envDcp.pData);
117 for (sal_Int32 i = 0; !result && i < nLen; ++ i)
119 result = result || (ppEnvs[i]->pContext == pContext && !rtl::OUString(ppEnvs[i]->pTypeName).compareTo(envDcp));
121 ppEnvs[i]->release(ppEnvs[i]);
123 rtl_freeMemory(ppEnvs);
125 return result;
128 static rtl::OUString s_test_uno_getRegisteredEnvironments_registered(rtl::OUString const & envDcp, void * pContext)
130 rtl::OUString result(RTL_CONSTASCII_USTRINGPARAM("\ts_test_uno_getRegisteredEnvironments_registered("));
131 result += envDcp;
132 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(", "));
133 result += rtl::OUString::valueOf((long)pContext);
134 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")\n"));
136 uno::Environment env(envDcp, pContext);
138 if (!env.is() || !s_is_registered(envDcp, pContext))
139 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tFAILURE:\n"));
141 return result;
144 static rtl::OUString s_test_uno_getRegisteredEnvironments_notRegistered(rtl::OUString const & envDcp, void * pContext)
146 rtl::OUString result(RTL_CONSTASCII_USTRINGPARAM("\ts_test_uno_getRegisteredEnvironments_notRegistered("));
147 result += envDcp;
148 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(", "));
149 result += rtl::OUString::valueOf((long)pContext);
150 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")\n"));
152 uno::Environment env(envDcp, pContext);
154 if (!env.is() && !s_is_registered(envDcp, pContext))
155 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tFAILURE:\n"));
157 return result;
161 static rtl::OUString s_test_uno_createEnvironment(rtl::OUString const & envDcp, void * pContext)
163 rtl::OUString result(RTL_CONSTASCII_USTRINGPARAM("\ts_test_uno_createEnvironment("));
164 result += envDcp;
165 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(", "));
166 result += rtl::OUString::valueOf((long)pContext);
167 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")\n"));
169 uno_Environment * pEnv = NULL;
170 uno_createEnvironment(&pEnv, envDcp.pData, pContext);
172 if (!pEnv && !s_is_registered(envDcp, pContext))
173 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tFAILURE:\n"));
175 if (pEnv)
176 pEnv->release(pEnv);
178 return result;
182 rtl::OUString register_test(rtl::OUString const & envDcp)
184 rtl::OUString env_A(envDcp);
185 env_A += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":purpA"));
187 rtl::OUString env_B(envDcp);
188 env_B += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":purpB"));
190 rtl::OUString result;
192 result = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("registration_test"));
193 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
195 result += s_test_getEnvironment(envDcp, NULL);
196 result += s_test_getEnvironment(env_A, NULL);
197 result += s_test_getEnvironment(env_B, NULL);
199 result += s_test_regetEnvironment(envDcp, NULL);
200 result += s_test_regetEnvironment(envDcp, (void *)0x1);
201 result += s_test_regetEnvironment(env_A, NULL) ;
202 result += s_test_regetEnvironment(env_A, (void *)0x1);
203 result += s_test_regetEnvironment(env_B, NULL) ;
204 result += s_test_regetEnvironment(env_B, (void *)0x1);
206 result += s_test_regetEnvironment(envDcp, env_A, (void *)NULL);
207 result += s_test_regetEnvironment(envDcp, env_A, (void *)0x1) ;
208 result += s_test_regetEnvironment(envDcp, env_B, (void *)NULL);
209 result += s_test_regetEnvironment(envDcp, env_B, (void *)0x1) ;
210 result += s_test_regetEnvironment(env_A, env_B, (void *)NULL);
211 result += s_test_regetEnvironment(env_A, env_B, (void *)0x1) ;
213 result += s_test_regetEnvironment(env_A, env_B, (void *)NULL, (void *)0x1);
215 result += s_test_uno_getRegisteredEnvironments_registered(envDcp, (void *)NULL);
216 result += s_test_uno_getRegisteredEnvironments_registered(envDcp, (void *)0x1) ;
217 result += s_test_uno_getRegisteredEnvironments_registered(env_A, (void *)NULL);
218 result += s_test_uno_getRegisteredEnvironments_registered(env_A, (void *)0x1) ;
219 result += s_test_uno_getRegisteredEnvironments_registered(env_B, (void *)NULL);
220 result += s_test_uno_getRegisteredEnvironments_registered(env_B, (void *)0x1) ;
222 result += s_test_uno_getRegisteredEnvironments_notRegistered(envDcp, NULL) ;
223 result += s_test_uno_getRegisteredEnvironments_notRegistered(envDcp, (void *)0x1);
224 result += s_test_uno_getRegisteredEnvironments_notRegistered(env_A, NULL) ;
225 result += s_test_uno_getRegisteredEnvironments_notRegistered(env_A, (void *)0x1);
226 result += s_test_uno_getRegisteredEnvironments_notRegistered(env_B, NULL) ;
227 result += s_test_uno_getRegisteredEnvironments_notRegistered(env_B, (void *)0x1);
229 result += s_test_uno_createEnvironment(envDcp, NULL) ;
230 result += s_test_uno_createEnvironment(envDcp, (void *)0x1);
231 result += s_test_uno_createEnvironment(env_A, NULL) ;
232 result += s_test_uno_createEnvironment(env_A, (void *)0x1);
233 result += s_test_uno_createEnvironment(env_B, NULL) ;
234 result += s_test_uno_createEnvironment(env_B, (void *)0x1);
236 return result;