1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_testtools.hxx"
26
27 #include "sal/config.h"
28
29 #include "multi.hxx"
30
31 #include "rtl/string.hxx"
32 #include "rtl/textenc.h"
33 #include "rtl/ustring.hxx"
34
35 #include <sstream>
36
operator <<(std::ostream & s,const rtl::OUString r)37 inline std::ostream& operator<<( std::ostream& s, const rtl::OUString r) { return (s << r.getStr()); }
38
39 namespace css = com::sun::star;
40
41 namespace {
42
43 struct CheckFailed {
CheckFailed__anon0518675f0111::CheckFailed44 explicit CheckFailed(rtl::OUString const & theMessage): message(theMessage)
45 {}
46
47 rtl::OUString message;
48 };
49
checkEqual(T const & value,T const & argument)50 template< typename T > void checkEqual(T const & value, T const & argument) {
51 if (argument != value) {
52 std::ostringstream s;
53 s << value << " != " << argument;
54 throw CheckFailed(
55 rtl::OStringToOUString(
56 rtl::OString(s.str().c_str()), RTL_TEXTENCODING_UTF8));
57 }
58 }
59
60 }
61
62 namespace testtools { namespace bridgetest {
63
testMulti(com::sun::star::uno::Reference<test::testtools::bridgetest::XMulti> const & multi)64 rtl::OUString testMulti(
65 com::sun::star::uno::Reference< test::testtools::bridgetest::XMulti >
66 const & multi)
67 {
68 try {
69 checkEqual(
70 0.0,
71 css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
72 multi, css::uno::UNO_QUERY_THROW)->getatt1());
73 checkEqual(
74 0.0,
75 static_cast< test::testtools::bridgetest::XMultiBase2 * >(
76 multi.get())->getatt1());
77 checkEqual(
78 0.0,
79 css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
80 multi, css::uno::UNO_QUERY_THROW)->getatt1());
81 checkEqual(
82 0.0,
83 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
84 multi.get())->getatt1());
85 checkEqual(
86 0.0,
87 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
88 multi, css::uno::UNO_QUERY_THROW)->getatt1());
89 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
90 multi, css::uno::UNO_QUERY_THROW)->setatt1(0.1);
91 checkEqual(
92 0.1,
93 css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
94 multi, css::uno::UNO_QUERY_THROW)->getatt1());
95 checkEqual(
96 0.1,
97 static_cast< test::testtools::bridgetest::XMultiBase2 * >(
98 multi.get())->getatt1());
99 checkEqual(
100 0.1,
101 css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
102 multi, css::uno::UNO_QUERY_THROW)->getatt1());
103 checkEqual(
104 0.1,
105 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
106 multi.get())->getatt1());
107 checkEqual(
108 0.1,
109 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
110 multi, css::uno::UNO_QUERY_THROW)->getatt1());
111 checkEqual< sal_Int32 >(
112 11 * 1,
113 css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
114 multi, css::uno::UNO_QUERY_THROW)->fn11(1));
115 checkEqual< sal_Int32 >(
116 11 * 1,
117 static_cast< test::testtools::bridgetest::XMultiBase2 * >(
118 multi.get())->fn11(1));
119 checkEqual< sal_Int32 >(
120 11 * 2,
121 css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
122 multi, css::uno::UNO_QUERY_THROW)->fn11(2));
123 checkEqual< sal_Int32 >(
124 11 * 1,
125 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
126 multi.get())->fn11(1));
127 checkEqual< sal_Int32 >(
128 11 * 5,
129 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
130 multi, css::uno::UNO_QUERY_THROW)->fn11(5));
131 checkEqual(
132 rtl::OUString::createFromAscii("12" "abc"),
133 css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
134 multi, css::uno::UNO_QUERY_THROW)->fn12(
135 rtl::OUString::createFromAscii("abc")));
136 checkEqual(
137 rtl::OUString::createFromAscii("12" "abc-2"),
138 static_cast< test::testtools::bridgetest::XMultiBase2 * >(
139 multi.get())->fn12(rtl::OUString::createFromAscii("abc-2")));
140 checkEqual(
141 rtl::OUString::createFromAscii("12" "abc-2"),
142 css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
143 multi, css::uno::UNO_QUERY_THROW)->fn12(
144 rtl::OUString::createFromAscii("abc-2")));
145 checkEqual(
146 rtl::OUString::createFromAscii("12" "abc-5"),
147 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
148 multi.get())->fn12(rtl::OUString::createFromAscii("abc-5")));
149 checkEqual(
150 rtl::OUString::createFromAscii("12" "abc-5"),
151 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
152 multi, css::uno::UNO_QUERY_THROW)->fn12(
153 rtl::OUString::createFromAscii("abc-5")));
154 checkEqual< sal_Int32 >(21 * 2, multi->fn21(2));
155 checkEqual(
156 rtl::OUString::createFromAscii("22" "de"),
157 multi->fn22(rtl::OUString::createFromAscii("de")));
158 checkEqual< sal_Int32 >(
159 31 * 3,
160 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
161 multi, css::uno::UNO_QUERY_THROW)->fn31(3));
162 checkEqual< sal_Int32 >(
163 31 * 5,
164 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
165 multi.get())->fn31(5));
166 checkEqual< sal_Int32 >(
167 31 * 5,
168 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
169 multi, css::uno::UNO_QUERY_THROW)->fn31(5));
170 checkEqual(
171 0.0,
172 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
173 multi, css::uno::UNO_QUERY_THROW)->getatt3());
174 checkEqual(
175 0.0,
176 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
177 multi.get())->getatt3());
178 checkEqual(
179 0.0,
180 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
181 multi, css::uno::UNO_QUERY_THROW)->getatt3());
182 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
183 multi, css::uno::UNO_QUERY_THROW)->setatt3(0.3);
184 checkEqual(
185 0.3,
186 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
187 multi, css::uno::UNO_QUERY_THROW)->getatt3());
188 checkEqual(
189 0.3,
190 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
191 multi.get())->getatt3());
192 checkEqual(
193 0.3,
194 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
195 multi, css::uno::UNO_QUERY_THROW)->getatt3());
196 checkEqual(
197 rtl::OUString::createFromAscii("32" "f"),
198 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
199 multi, css::uno::UNO_QUERY_THROW)->fn32(
200 rtl::OUString::createFromAscii("f")));
201 checkEqual(
202 rtl::OUString::createFromAscii("32" "f-5"),
203 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
204 multi.get())->fn32(rtl::OUString::createFromAscii("f-5")));
205 checkEqual(
206 rtl::OUString::createFromAscii("32" "f-5"),
207 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
208 multi, css::uno::UNO_QUERY_THROW)->fn32(
209 rtl::OUString::createFromAscii("f-5")));
210 checkEqual< sal_Int32 >(
211 33,
212 css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
213 multi, css::uno::UNO_QUERY_THROW)->fn33());
214 checkEqual< sal_Int32 >(
215 33,
216 static_cast< test::testtools::bridgetest::XMultiBase5 * >(
217 multi.get())->fn33());
218 checkEqual< sal_Int32 >(
219 33,
220 css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
221 multi, css::uno::UNO_QUERY_THROW)->fn33());
222 checkEqual< sal_Int32 >(41 * 4, multi->fn41(4));
223 checkEqual< sal_Int32 >(61 * 6, multi->fn61(6));
224 checkEqual(
225 rtl::OUString::createFromAscii("62" ""),
226 multi->fn62(rtl::OUString::createFromAscii("")));
227 checkEqual< sal_Int32 >(71 * 7, multi->fn71(7));
228 checkEqual(
229 rtl::OUString::createFromAscii("72" "g"),
230 multi->fn72(rtl::OUString::createFromAscii("g")));
231 checkEqual< sal_Int32 >(73, multi->fn73());
232 } catch (CheckFailed const & f) {
233 return f.message;
234 }
235 return rtl::OUString();
236 }
237
238 } }
239