LCOV - code coverage report
Current view: top level - unotest/source/cpp/unoexceptionprotector - unoexceptionprotector.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 15 15 100.0 %
Date: 2015-06-13 12:38:46 Functions: 8 8 100.0 %
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 "com/sun/star/uno/Any.hxx"
      25             : #include "com/sun/star/uno/Exception.hpp"
      26             : #include "cppuhelper/exc_hlp.hxx"
      27             : #include "cppunit/Message.h"
      28             : #include "osl/thread.h"
      29             : #include "rtl/string.hxx"
      30             : #include "rtl/ustring.h"
      31             : #include "rtl/ustring.hxx"
      32             : #include "sal/types.h"
      33             : 
      34             : #include "cppunittester/protectorfactory.hxx"
      35             : 
      36             : namespace {
      37             : 
      38             : // Best effort conversion:
      39           2 : std::string convert(OUString const & s16) {
      40           2 :     OString s8(OUStringToOString(s16, osl_getThreadTextEncoding()));
      41             :     static_assert(sizeof (sal_Int32) <= sizeof (std::string::size_type), "got to be at least equal");
      42             :         // ensure following cast is legitimate
      43             :     return std::string(
      44           2 :         s8.getStr(), static_cast< std::string::size_type >(s8.getLength()));
      45             : }
      46             : 
      47             : class Prot : public CppUnit::Protector, private boost::noncopyable
      48             : {
      49             : public:
      50         130 :     Prot() {}
      51             : 
      52         260 :     virtual ~Prot() {}
      53             : 
      54             :     virtual bool protect(
      55             :         CppUnit::Functor const & functor,
      56             :         CppUnit::ProtectorContext const & context) SAL_OVERRIDE;
      57             : };
      58             : 
      59        8400 : bool Prot::protect(
      60             :     CppUnit::Functor const & functor, CppUnit::ProtectorContext const & context)
      61             : {
      62             :     try {
      63        8400 :         return functor();
      64           1 :     } catch (const css::uno::Exception &e) {
      65           1 :         css::uno::Any a(cppu::getCaughtException());
      66             :         reportError(
      67             :             context,
      68             :             CppUnit::Message(
      69             :                 convert(
      70           2 :                     "An uncaught exception of type " + a.getValueTypeName()),
      71           3 :                 convert(e.Message)));
      72             :     }
      73           1 :     return false;
      74             : }
      75             : 
      76             : }
      77             : 
      78             : extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * SAL_CALL
      79         130 : unoexceptionprotector() {
      80         130 :     return new Prot;
      81         390 : }
      82             : 
      83             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11