LCOV - code coverage report
Current view: top level - /opt/artdaq/srcs/artdaq-core/test/Utilities - ExceptionHandler_t.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 100.0 % 35 35
Test Date: 2025-09-04 00:45:34 Functions: 100.0 % 15 15

            Line data    Source code
       1              : #include "artdaq-core/Utilities/ExceptionHandler.hh"
       2              : 
       3              : #define BOOST_TEST_MODULE ExceptionHandler_t
       4              : #include "cetlib/quiet_unit_test.hpp"
       5              : 
       6              : #define TRACE_NAME "ExceptionHandler_t"
       7              : #include "TRACE/tracemf.h"
       8              : #include "canvas/Utilities/Exception.h"
       9              : #include "cetlib_except/exception.h"
      10              : 
      11              : #include <boost/exception/all.hpp>
      12              : 
      13              : BOOST_AUTO_TEST_SUITE(ExceptionHandler_test)
      14              : 
      15              : typedef boost::error_info<struct tag_my_info, std::string> my_info;
      16              : 
      17              : struct my_error : virtual boost::exception, virtual std::exception
      18              : {};
      19              : 
      20            2 : BOOST_AUTO_TEST_CASE(artException)
      21              : {
      22              :         try
      23              :         {
      24            3 :                 throw art::Exception(art::errors::Unknown, "TestException");
      25              :         }
      26            1 :         catch (art::Exception& e)
      27              :         {
      28            2 :                 artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::no, "This is a test of art::Exception");
      29            4 :                 BOOST_REQUIRE_EXCEPTION(
      30              :                     artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::yes, "This is another test of art::Exception"), art::Exception, [](art::Exception const& e) { return e.category() == e.codeToString(art::errors::Unknown); });
      31            1 :         }
      32            1 : }
      33            2 : BOOST_AUTO_TEST_CASE(cetException)
      34              : {
      35              :         try
      36              :         {
      37            3 :                 throw cet::exception("TestException");
      38              :         }
      39            1 :         catch (cet::exception&)
      40              :         {
      41            2 :                 artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::no, "This is a test of cet::exception");
      42            4 :                 BOOST_REQUIRE_EXCEPTION(
      43              :                     artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::yes, "This is another test of cet::exception"), cet::exception, [](cet::exception const& e) { return e.category() == "TestException"; });
      44            1 :         }
      45            1 : }
      46            2 : BOOST_AUTO_TEST_CASE(boostException)
      47              : {
      48              :         try
      49              :         {
      50            3 :                 throw my_error() << my_info("TestException");
      51              :         }
      52            1 :         catch (boost::exception&)
      53              :         {
      54            2 :                 artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::no, "This is a test of boost::exception");
      55            4 :                 BOOST_REQUIRE_EXCEPTION(
      56              :                     artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::yes, "This is another test of boost::exception"), boost::exception, [](boost::exception const&) { return true; });
      57            1 :         }
      58            1 : }
      59            2 : BOOST_AUTO_TEST_CASE(stdException)
      60              : {
      61              :         try
      62              :         {
      63            1 :                 throw std::exception();
      64              :         }
      65            1 :         catch (std::exception&)
      66              :         {
      67            2 :                 artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::no, "This is a test of std::exception");
      68            4 :                 BOOST_REQUIRE_EXCEPTION(
      69              :                     artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::yes, "This is another test of std::exception"), std::exception, [](std::exception const&) { return true; });
      70            1 :         }
      71            1 : }
      72            2 : BOOST_AUTO_TEST_CASE(arbitraryThrow)
      73              : {
      74              :         try
      75              :         {
      76            1 :                 throw int(5);
      77              :         }
      78            1 :         catch (...)
      79              :         {
      80            2 :                 artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::no, "This is a test of arbitrary throw handling");
      81            4 :                 BOOST_REQUIRE_EXCEPTION(
      82              :                     artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::yes, "This is another test of arbitrary throw handling"), int, [](int const& e) { return e == 5; });
      83            1 :         }
      84            1 : }
      85              : 
      86              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1