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: EnvStack.tester.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/lbnames.h"
36 #include "uno/environment.hxx"
37 #include "cppu/EnvDcp.hxx"
38 #include <com/sun/star/uno/Exception.hpp>
41 #define CPPU_test_EnvStack_tester_IMPL
42 #include "EnvStack.tester.hxx"
45 using namespace com::sun::star
;
48 static rtl::OUString
s_getCurrentEnvDcp(void)
50 uno::Environment
env(uno::Environment::getCurrent());
51 rtl::OUString
env_dcp(env
.getTypeName());
56 extern "C" { static void s_getCurrentEnvDcp_v(va_list * pParam
)
58 rtl_uString
** ppEnvDcp
= va_arg(*pParam
, rtl_uString
**);
60 rtl::OUString
env_dcp(s_getCurrentEnvDcp());
62 rtl_uString_assign(ppEnvDcp
, env_dcp
.pData
);
65 static rtl::OUString
s_test__uno_Environment_invoke(rtl::OUString
const & src_purpose
,
66 rtl::OUString
const & dst_purpose
,
67 rtl::OUString
const & ref
)
70 rtl::OUString target_envDcp
;
72 rtl::OUString
src_envDcp(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
));
73 src_envDcp
+= src_purpose
;
75 rtl::OUString
dst_envDcp(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
));
76 dst_envDcp
+= dst_purpose
;
78 uno::Environment
cur_Env(src_envDcp
.pData
, NULL
);
79 uno_Environment_enter(cur_Env
.get());
82 uno::Environment
dst_Env(dst_envDcp
.pData
, NULL
);
83 uno_Environment_invoke(dst_Env
.get(), s_getCurrentEnvDcp_v
, &target_envDcp
.pData
);
86 uno_Environment_enter(NULL
);
89 if (cppu::EnvDcp::getPurpose(target_envDcp
).equals(dst_purpose
)
90 && g_commentStack
.equals(ref
))
91 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" PASSED\n"));
95 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FAILED -> "));
96 result
+= target_envDcp
;
97 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
98 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\texpected: \""));
100 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
101 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tgot: \""));
102 result
+= g_commentStack
;
103 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
111 static rtl::OUString
s_test__uno_Environment_invoke_v(va_list param
)
113 rtl::OUString
const * pSrc_purpose
= va_arg(param
, rtl::OUString
const *);
114 rtl::OUString
const * pDst_purpose
= va_arg(param
, rtl::OUString
const *);
115 rtl::OUString
const * pRef
= va_arg(param
, rtl::OUString
const *);
118 rtl::OUString result
;
120 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("s_test__uno_Environment_invoke_v"));
121 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - \""));
122 result
+= *pSrc_purpose
;
123 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" -> \""));
124 result
+= *pDst_purpose
;
125 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""));
127 result
+= s_test__uno_Environment_invoke(*pSrc_purpose
, *pDst_purpose
, *pRef
);
132 static rtl::OUString
s_do_a_test(rtl::OUString (* pTest
)(va_list), ...)
134 rtl::OUString result
;
138 va_start(param
, pTest
);
140 result
+= pTest(param
);
142 catch (uno::Exception
& exception
)
144 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FAILED with exception: "));
145 result
+= exception
.Message
;
146 result
+= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
153 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
156 rtl::OString message
;
158 if (argc
>= 4 && argc
<= 5)
160 rtl::OUString
src_purpose(argv
[1], rtl_str_getLength(argv
[1]), RTL_TEXTENCODING_ASCII_US
);
161 rtl::OUString
dst_purpose(argv
[2], rtl_str_getLength(argv
[2]), RTL_TEXTENCODING_ASCII_US
);
162 rtl::OUString
ref (argv
[3], rtl_str_getLength(argv
[3]), RTL_TEXTENCODING_ASCII_US
);
166 rtl::OUString
test_env(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
));
167 test_env
+= rtl::OUString(argv
[4], rtl_str_getLength(argv
[4]), RTL_TEXTENCODING_ASCII_US
);
168 g_env
= uno::Environment(test_env
);
172 message
+= rtl::OUStringToOString(
173 s_do_a_test(s_test__uno_Environment_invoke_v
, &src_purpose
, &dst_purpose
, &ref
),
174 RTL_TEXTENCODING_ASCII_US
);
181 if (message
.indexOf(rtl::OString("FAILED")) == -1)
182 message
+= rtl::OString("TESTS PASSED\n");
186 message
+= rtl::OString("TESTS _NOT_ PASSED\n");
192 message
= "usage: EnvStack.tester <source purpose>"
193 " <destination purpose>"
194 " <reference string>"
195 " [<reference environment>]\n\n";
198 std::cout
<< message
.getStr();