LCOV - code coverage report
Current view: top level - unotest/source/cpp/unoexceptionprotector - unoexceptionprotector.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 7 15 46.7 %
Date: 2014-11-03 Functions: 7 8 87.5 %
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             : #include <string>
      21             : #include <iostream>
      22             : 
      23             : #include "boost/noncopyable.hpp"
      24             : #include "boost/static_assert.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 "cppunittester/protectorfactory.hxx"
      36             : 
      37             : namespace {
      38             : 
      39             : // Best effort conversion:
      40           0 : std::string convert(OUString const & s16) {
      41           0 :     OString s8(OUStringToOString(s16, osl_getThreadTextEncoding()));
      42             :     BOOST_STATIC_ASSERT(sizeof (sal_Int32) <= sizeof (std::string::size_type));
      43             :         // ensure following cast is legitimate
      44             :     return std::string(
      45           0 :         s8.getStr(), static_cast< std::string::size_type >(s8.getLength()));
      46             : }
      47             : 
      48             : class Prot : public CppUnit::Protector, private boost::noncopyable
      49             : {
      50             : public:
      51         222 :     Prot() {}
      52             : 
      53         444 :     virtual ~Prot() {}
      54             : 
      55             :     virtual bool protect(
      56             :         CppUnit::Functor const & functor,
      57             :         CppUnit::ProtectorContext const & context) SAL_OVERRIDE;
      58             : };
      59             : 
      60       14190 : bool Prot::protect(
      61             :     CppUnit::Functor const & functor, CppUnit::ProtectorContext const & context)
      62             : {
      63             :     try {
      64       14190 :         return functor();
      65           0 :     } catch (const css::uno::Exception &e) {
      66           0 :         css::uno::Any a(cppu::getCaughtException());
      67             :         reportError(
      68             :             context,
      69             :             CppUnit::Message(
      70             :                 convert(
      71             :                     OUString("An uncaught exception of type ")
      72           0 :                     + a.getValueTypeName()),
      73           0 :                 convert(e.Message)));
      74             :     }
      75           0 :     return false;
      76             : }
      77             : 
      78             : }
      79             : 
      80             : extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL
      81         222 : unoexceptionprotector() {
      82         222 :     return new Prot;
      83         666 : }
      84             : 
      85             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10