1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_testtools.hxx"
30 
31 #include "sal/config.h"
32 
33 #include "multi.hxx"
34 
35 #include "rtl/string.hxx"
36 #include "rtl/textenc.h"
37 #include "rtl/ustring.hxx"
38 
39 #include <sstream>
40 
41 namespace css = com::sun::star;
42 
43 namespace {
44 
45 struct CheckFailed {
46     explicit CheckFailed(rtl::OUString const & theMessage): message(theMessage)
47     {}
48 
49     rtl::OUString message;
50 };
51 
52 template< typename T > void checkEqual(T const & value, T const & argument) {
53     if (argument != value) {
54         std::ostringstream s;
55         s << value << " != " << argument;
56         throw CheckFailed(
57             rtl::OStringToOUString(
58                 rtl::OString(s.str().c_str()), RTL_TEXTENCODING_UTF8));
59     }
60 }
61 
62 }
63 
64 namespace testtools { namespace bridgetest {
65 
66 rtl::OUString testMulti(
67     com::sun::star::uno::Reference< test::testtools::bridgetest::XMulti >
68     const & multi)
69 {
70     try {
71         checkEqual(
72             0.0,
73             css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
74                 multi, css::uno::UNO_QUERY_THROW)->getatt1());
75         checkEqual(
76             0.0,
77             static_cast< test::testtools::bridgetest::XMultiBase2 * >(
78                 multi.get())->getatt1());
79         checkEqual(
80             0.0,
81             css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
82                 multi, css::uno::UNO_QUERY_THROW)->getatt1());
83         checkEqual(
84             0.0,
85             static_cast< test::testtools::bridgetest::XMultiBase5 * >(
86                 multi.get())->getatt1());
87         checkEqual(
88             0.0,
89             css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
90                 multi, css::uno::UNO_QUERY_THROW)->getatt1());
91         css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
92             multi, css::uno::UNO_QUERY_THROW)->setatt1(0.1);
93         checkEqual(
94             0.1,
95             css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
96                 multi, css::uno::UNO_QUERY_THROW)->getatt1());
97         checkEqual(
98             0.1,
99             static_cast< test::testtools::bridgetest::XMultiBase2 * >(
100                 multi.get())->getatt1());
101         checkEqual(
102             0.1,
103             css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
104                 multi, css::uno::UNO_QUERY_THROW)->getatt1());
105         checkEqual(
106             0.1,
107             static_cast< test::testtools::bridgetest::XMultiBase5 * >(
108                 multi.get())->getatt1());
109         checkEqual(
110             0.1,
111             css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
112                 multi, css::uno::UNO_QUERY_THROW)->getatt1());
113         checkEqual< sal_Int32 >(
114             11 * 1,
115             css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
116                 multi, css::uno::UNO_QUERY_THROW)->fn11(1));
117         checkEqual< sal_Int32 >(
118             11 * 1,
119             static_cast< test::testtools::bridgetest::XMultiBase2 * >(
120                 multi.get())->fn11(1));
121         checkEqual< sal_Int32 >(
122             11 * 2,
123             css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
124                 multi, css::uno::UNO_QUERY_THROW)->fn11(2));
125         checkEqual< sal_Int32 >(
126             11 * 1,
127             static_cast< test::testtools::bridgetest::XMultiBase5 * >(
128                 multi.get())->fn11(1));
129         checkEqual< sal_Int32 >(
130             11 * 5,
131             css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
132                 multi, css::uno::UNO_QUERY_THROW)->fn11(5));
133         checkEqual(
134             rtl::OUString::createFromAscii("12" "abc"),
135             css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >(
136                 multi, css::uno::UNO_QUERY_THROW)->fn12(
137                     rtl::OUString::createFromAscii("abc")));
138         checkEqual(
139             rtl::OUString::createFromAscii("12" "abc-2"),
140             static_cast< test::testtools::bridgetest::XMultiBase2 * >(
141                 multi.get())->fn12(rtl::OUString::createFromAscii("abc-2")));
142         checkEqual(
143             rtl::OUString::createFromAscii("12" "abc-2"),
144             css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >(
145                 multi, css::uno::UNO_QUERY_THROW)->fn12(
146                     rtl::OUString::createFromAscii("abc-2")));
147         checkEqual(
148             rtl::OUString::createFromAscii("12" "abc-5"),
149             static_cast< test::testtools::bridgetest::XMultiBase5 * >(
150                 multi.get())->fn12(rtl::OUString::createFromAscii("abc-5")));
151         checkEqual(
152             rtl::OUString::createFromAscii("12" "abc-5"),
153             css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
154                 multi, css::uno::UNO_QUERY_THROW)->fn12(
155                     rtl::OUString::createFromAscii("abc-5")));
156         checkEqual< sal_Int32 >(21 * 2, multi->fn21(2));
157         checkEqual(
158             rtl::OUString::createFromAscii("22" "de"),
159             multi->fn22(rtl::OUString::createFromAscii("de")));
160         checkEqual< sal_Int32 >(
161             31 * 3,
162             css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
163                 multi, css::uno::UNO_QUERY_THROW)->fn31(3));
164         checkEqual< sal_Int32 >(
165             31 * 5,
166             static_cast< test::testtools::bridgetest::XMultiBase5 * >(
167                 multi.get())->fn31(5));
168         checkEqual< sal_Int32 >(
169             31 * 5,
170             css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
171                 multi, css::uno::UNO_QUERY_THROW)->fn31(5));
172         checkEqual(
173             0.0,
174             css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
175                 multi, css::uno::UNO_QUERY_THROW)->getatt3());
176         checkEqual(
177             0.0,
178             static_cast< test::testtools::bridgetest::XMultiBase5 * >(
179                 multi.get())->getatt3());
180         checkEqual(
181             0.0,
182             css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
183                 multi, css::uno::UNO_QUERY_THROW)->getatt3());
184         css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
185             multi, css::uno::UNO_QUERY_THROW)->setatt3(0.3);
186         checkEqual(
187             0.3,
188             css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
189                 multi, css::uno::UNO_QUERY_THROW)->getatt3());
190         checkEqual(
191             0.3,
192             static_cast< test::testtools::bridgetest::XMultiBase5 * >(
193                 multi.get())->getatt3());
194         checkEqual(
195             0.3,
196             css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
197                 multi, css::uno::UNO_QUERY_THROW)->getatt3());
198         checkEqual(
199             rtl::OUString::createFromAscii("32" "f"),
200             css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
201                 multi, css::uno::UNO_QUERY_THROW)->fn32(
202                     rtl::OUString::createFromAscii("f")));
203         checkEqual(
204             rtl::OUString::createFromAscii("32" "f-5"),
205             static_cast< test::testtools::bridgetest::XMultiBase5 * >(
206                 multi.get())->fn32(rtl::OUString::createFromAscii("f-5")));
207         checkEqual(
208             rtl::OUString::createFromAscii("32" "f-5"),
209             css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
210                 multi, css::uno::UNO_QUERY_THROW)->fn32(
211                     rtl::OUString::createFromAscii("f-5")));
212         checkEqual< sal_Int32 >(
213             33,
214             css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >(
215                 multi, css::uno::UNO_QUERY_THROW)->fn33());
216         checkEqual< sal_Int32 >(
217             33,
218             static_cast< test::testtools::bridgetest::XMultiBase5 * >(
219                 multi.get())->fn33());
220         checkEqual< sal_Int32 >(
221             33,
222             css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >(
223                 multi, css::uno::UNO_QUERY_THROW)->fn33());
224         checkEqual< sal_Int32 >(41 * 4, multi->fn41(4));
225         checkEqual< sal_Int32 >(61 * 6, multi->fn61(6));
226         checkEqual(
227             rtl::OUString::createFromAscii("62" ""),
228             multi->fn62(rtl::OUString::createFromAscii("")));
229         checkEqual< sal_Int32 >(71 * 7, multi->fn71(7));
230         checkEqual(
231             rtl::OUString::createFromAscii("72" "g"),
232             multi->fn72(rtl::OUString::createFromAscii("g")));
233         checkEqual< sal_Int32 >(73, multi->fn73());
234     } catch (CheckFailed const & f) {
235         return f.message;
236     }
237     return rtl::OUString();
238 }
239 
240 } }
241