LCOV - code coverage report
Current view: top level - unotest/source/cpp/unoexceptionprotector - unoexceptionprotector.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 16 43.8 %
Date: 2012-08-25 Functions: 7 8 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 38 13.2 %

           Branch data     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                 :            : #include <limits>
      21                 :            : #include <string>
      22                 :            : #include <iostream>
      23                 :            : 
      24                 :            : #include "boost/noncopyable.hpp"
      25                 :            : #include "com/sun/star/uno/Any.hxx"
      26                 :            : #include "com/sun/star/uno/Exception.hpp"
      27                 :            : #include "cppuhelper/exc_hlp.hxx"
      28                 :            : #include "cppunit/Message.h"
      29                 :            : #include "osl/thread.h"
      30                 :            : #include "rtl/string.hxx"
      31                 :            : #include "rtl/ustring.h"
      32                 :            : #include "rtl/ustring.hxx"
      33                 :            : #include "sal/types.h"
      34                 :            : 
      35                 :            : #include "protectorfactory.hxx"
      36                 :            : 
      37                 :            : namespace {
      38                 :            : 
      39                 :            : namespace css = com::sun::star;
      40                 :            : 
      41                 :            : // Best effort conversion:
      42                 :          0 : std::string convert(rtl::OUString const & s16) {
      43 [ #  # ][ #  # ]:          0 :     rtl::OString s8(rtl::OUStringToOString(s16, osl_getThreadTextEncoding()));
      44                 :            :     return std::string(
      45                 :            :         s8.getStr(),
      46                 :          0 :         ((static_cast< sal_uInt32 >(s8.getLength())
      47                 :          0 :           > std::numeric_limits< std::string::size_type >::max())
      48                 :            :          ? std::numeric_limits< std::string::size_type >::max()
      49 [ #  # ][ #  # ]:          0 :          : static_cast< std::string::size_type >(s8.getLength())));
      50                 :            : }
      51                 :            : 
      52                 :            : class Prot : public CppUnit::Protector, private boost::noncopyable
      53                 :            : {
      54                 :            : public:
      55                 :        183 :     Prot() {}
      56                 :            : 
      57         [ -  + ]:        366 :     virtual ~Prot() {}
      58                 :            : 
      59                 :            :     virtual bool protect(
      60                 :            :         CppUnit::Functor const & functor,
      61                 :            :         CppUnit::ProtectorContext const & context);
      62                 :            : };
      63                 :            : 
      64                 :       4563 : bool Prot::protect(
      65                 :            :     CppUnit::Functor const & functor, CppUnit::ProtectorContext const & context)
      66                 :            : {
      67                 :            :     try {
      68         [ +  - ]:       4563 :         return functor();
      69         [ #  # ]:          0 :     } catch (const css::uno::Exception &e) {
      70         [ #  # ]:          0 :         css::uno::Any a(cppu::getCaughtException());
      71                 :            :         reportError(
      72                 :            :             context,
      73                 :            :             CppUnit::Message(
      74                 :            :                 convert(
      75                 :            :                     rtl::OUString(
      76                 :            :                         RTL_CONSTASCII_USTRINGPARAM(
      77                 :            :                             "An uncaught exception of type "))
      78                 :            :                     + a.getValueTypeName()),
      79   [ #  #  #  #  :          0 :                 convert(e.Message)));
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      80                 :            :     }
      81                 :          0 :     return false;
      82                 :            : }
      83                 :            : 
      84                 :            : }
      85                 :            : 
      86                 :            : extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL
      87                 :        183 : unoexceptionprotector() {
      88         [ +  - ]:        183 :     return new Prot;
      89 [ +  - ][ +  - ]:        549 : }
      90                 :            : 
      91                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10