LCOV - code coverage report
Current view: top level - libreoffice/testtools/source/bridgetest - multi.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 55 65 84.6 %
Date: 2012-12-27 Functions: 4 7 57.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10