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