merge the formfield patch from ooo-build
[ooovba.git] / testtools / source / bridgetest / multi.cxx
blobe2dd958320c4279033fd94cd07abb828855837f2
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: multi.cxx,v $
10 * $Revision: 1.5 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_testtools.hxx"
34 #include "sal/config.h"
36 #include "multi.hxx"
38 #include "rtl/string.hxx"
39 #include "rtl/textenc.h"
40 #include "rtl/ustring.hxx"
42 #include <sstream>
44 namespace css = com::sun::star;
46 namespace {
48 struct CheckFailed {
49 explicit CheckFailed(rtl::OUString const & theMessage): message(theMessage)
52 rtl::OUString message;
55 template< typename T > void checkEqual(T const & value, T const & argument) {
56 if (argument != value) {
57 std::ostringstream s;
58 s << value << " != " << argument;
59 throw CheckFailed(
60 rtl::OStringToOUString(
61 rtl::OString(s.str().c_str()), RTL_TEXTENCODING_UTF8));
67 namespace testtools { namespace bridgetest {
69 rtl::OUString testMulti(
70 com::sun::star::uno::Reference< test::testtools::bridgetest::XMulti >
71 const & multi)
73 try {
74 checkEqual(
75 0.0,
76 css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
77 multi, css::uno::UNO_QUERY_THROW)->getatt1());
78 checkEqual(
79 0.0,
80 static_cast< test::testtools::bridgetest::XMultiBase2 * >(
81 multi.get())->getatt1());
82 checkEqual(
83 0.0,
84 css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
85 multi, css::uno::UNO_QUERY_THROW)->getatt1());
86 checkEqual(
87 0.0,
88 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
89 multi.get())->getatt1());
90 checkEqual(
91 0.0,
92 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
93 multi, css::uno::UNO_QUERY_THROW)->getatt1());
94 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
95 multi, css::uno::UNO_QUERY_THROW)->setatt1(0.1);
96 checkEqual(
97 0.1,
98 css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
99 multi, css::uno::UNO_QUERY_THROW)->getatt1());
100 checkEqual(
101 0.1,
102 static_cast< test::testtools::bridgetest::XMultiBase2 * >(
103 multi.get())->getatt1());
104 checkEqual(
105 0.1,
106 css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
107 multi, css::uno::UNO_QUERY_THROW)->getatt1());
108 checkEqual(
109 0.1,
110 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
111 multi.get())->getatt1());
112 checkEqual(
113 0.1,
114 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
115 multi, css::uno::UNO_QUERY_THROW)->getatt1());
116 checkEqual< sal_Int32 >(
117 11 * 1,
118 css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
119 multi, css::uno::UNO_QUERY_THROW)->fn11(1));
120 checkEqual< sal_Int32 >(
121 11 * 1,
122 static_cast< test::testtools::bridgetest::XMultiBase2 * >(
123 multi.get())->fn11(1));
124 checkEqual< sal_Int32 >(
125 11 * 2,
126 css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
127 multi, css::uno::UNO_QUERY_THROW)->fn11(2));
128 checkEqual< sal_Int32 >(
129 11 * 1,
130 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
131 multi.get())->fn11(1));
132 checkEqual< sal_Int32 >(
133 11 * 5,
134 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
135 multi, css::uno::UNO_QUERY_THROW)->fn11(5));
136 checkEqual(
137 rtl::OUString::createFromAscii("12" "abc"),
138 css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
139 multi, css::uno::UNO_QUERY_THROW)->fn12(
140 rtl::OUString::createFromAscii("abc")));
141 checkEqual(
142 rtl::OUString::createFromAscii("12" "abc-2"),
143 static_cast< test::testtools::bridgetest::XMultiBase2 * >(
144 multi.get())->fn12(rtl::OUString::createFromAscii("abc-2")));
145 checkEqual(
146 rtl::OUString::createFromAscii("12" "abc-2"),
147 css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
148 multi, css::uno::UNO_QUERY_THROW)->fn12(
149 rtl::OUString::createFromAscii("abc-2")));
150 checkEqual(
151 rtl::OUString::createFromAscii("12" "abc-5"),
152 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
153 multi.get())->fn12(rtl::OUString::createFromAscii("abc-5")));
154 checkEqual(
155 rtl::OUString::createFromAscii("12" "abc-5"),
156 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
157 multi, css::uno::UNO_QUERY_THROW)->fn12(
158 rtl::OUString::createFromAscii("abc-5")));
159 checkEqual< sal_Int32 >(21 * 2, multi->fn21(2));
160 checkEqual(
161 rtl::OUString::createFromAscii("22" "de"),
162 multi->fn22(rtl::OUString::createFromAscii("de")));
163 checkEqual< sal_Int32 >(
164 31 * 3,
165 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
166 multi, css::uno::UNO_QUERY_THROW)->fn31(3));
167 checkEqual< sal_Int32 >(
168 31 * 5,
169 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
170 multi.get())->fn31(5));
171 checkEqual< sal_Int32 >(
172 31 * 5,
173 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
174 multi, css::uno::UNO_QUERY_THROW)->fn31(5));
175 checkEqual(
176 0.0,
177 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
178 multi, css::uno::UNO_QUERY_THROW)->getatt3());
179 checkEqual(
180 0.0,
181 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
182 multi.get())->getatt3());
183 checkEqual(
184 0.0,
185 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
186 multi, css::uno::UNO_QUERY_THROW)->getatt3());
187 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
188 multi, css::uno::UNO_QUERY_THROW)->setatt3(0.3);
189 checkEqual(
190 0.3,
191 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
192 multi, css::uno::UNO_QUERY_THROW)->getatt3());
193 checkEqual(
194 0.3,
195 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
196 multi.get())->getatt3());
197 checkEqual(
198 0.3,
199 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
200 multi, css::uno::UNO_QUERY_THROW)->getatt3());
201 checkEqual(
202 rtl::OUString::createFromAscii("32" "f"),
203 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
204 multi, css::uno::UNO_QUERY_THROW)->fn32(
205 rtl::OUString::createFromAscii("f")));
206 checkEqual(
207 rtl::OUString::createFromAscii("32" "f-5"),
208 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
209 multi.get())->fn32(rtl::OUString::createFromAscii("f-5")));
210 checkEqual(
211 rtl::OUString::createFromAscii("32" "f-5"),
212 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
213 multi, css::uno::UNO_QUERY_THROW)->fn32(
214 rtl::OUString::createFromAscii("f-5")));
215 checkEqual< sal_Int32 >(
217 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
218 multi, css::uno::UNO_QUERY_THROW)->fn33());
219 checkEqual< sal_Int32 >(
221 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
222 multi.get())->fn33());
223 checkEqual< sal_Int32 >(
225 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
226 multi, css::uno::UNO_QUERY_THROW)->fn33());
227 checkEqual< sal_Int32 >(41 * 4, multi->fn41(4));
228 checkEqual< sal_Int32 >(61 * 6, multi->fn61(6));
229 checkEqual(
230 rtl::OUString::createFromAscii("62" ""),
231 multi->fn62(rtl::OUString::createFromAscii("")));
232 checkEqual< sal_Int32 >(71 * 7, multi->fn71(7));
233 checkEqual(
234 rtl::OUString::createFromAscii("72" "g"),
235 multi->fn72(rtl::OUString::createFromAscii("g")));
236 checkEqual< sal_Int32 >(73, multi->fn73());
237 } catch (CheckFailed const & f) {
238 return f.message;
240 return rtl::OUString();