19#ifndef ROOT_UNITTESTSUPPORT_H 
   20#define ROOT_UNITTESTSUPPORT_H 
   28#include "gtest/gtest.h" 
   31namespace TestSupport {
 
   93      void requiredDiag(
int severity, std::string location, std::string message, 
bool matchFullMessage = 
true) {
 
   95            throw std::invalid_argument(
"ExpectedDiagRAII::requiredDiag(): severity is none of kInfo, kWarning, kError, kSysError");
 
   97         fExpectedDiags.push_back({severity, std::move(location), std::move(message), matchFullMessage, 
false, 0});
 
  106      void optionalDiag(
int severity, std::string location, std::string message, 
bool matchFullMessage = 
true) {
 
  108            throw std::invalid_argument(
"ExpectedDiagRAII::optionalDiag(): severity is none of kInfo, kWarning, kError, kSysError");
 
  110         fExpectedDiags.push_back({severity, std::move(location), std::move(message), matchFullMessage, 
true, 0});
 
  124      static void callback(
int severity, 
bool abort, 
const char * location, 
const char * msg) {
 
  128            throw std::logic_error(
"ExpectedDiagRAII::callback called without an active message handler.");
 
  132            std::cerr << 
"ROOT::TestSupport::CheckDiagsRAII: Forced to abort because of diagnostic with severity " 
  133               << severity << 
" in '" << location << 
"' reading '" << msg << 
"'\n";
 
  139      void checkDiag(
int severity, 
const char * location, 
const char * msg);
 
  141      void printDiags(std::vector<Diag_t> 
const & diags) 
const;
 
  154#define ROOT_EXPECT_ERROR(expression, where, expected_diag )       \ 
  156   using namespace ROOT::TestSupport;                              \ 
  157   CheckDiagsRAII EE(kError, where,                                \ 
  162#define ROOT_EXPECT_WARNING(expression, where, expected_diag)      \ 
  164   using namespace ROOT::TestSupport;                              \ 
  165   CheckDiagsRAII EE(kWarning, where,                              \ 
  170#define ROOT_EXPECT_INFO(expression, where, expected_diag)           \ 
  172   using namespace ROOT::TestSupport;                                \ 
  173   CheckDiagsRAII EE(kInfo, where,                                   \ 
  178#define ROOT_EXPECT_NODIAG(expression)                               \ 
  180   using namespace ROOT::TestSupport;                                \ 
  181   CheckDiagsRAII EE{};                                              \ 
  185#define ROOT_EXPECT_SYSERROR(expression, where, expected_diag)       \ 
  187   using namespace ROOT::TestSupport;                                \ 
  188   CheckDiagsRAII EE(kSysError, where,                               \ 
ErrorHandlerFunc_t GetErrorHandler()
Returns the current error handler function.
 
void(* ErrorHandlerFunc_t)(int level, Bool_t abort, const char *location, const char *msg)
 
ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
Set an errorhandler function. Returns the old handler.
 
Install a ROOT diagnostic handler to analyse diagnostics.
 
void printDiags(std::vector< Diag_t > const &diags) const
Print the diags in diags to the terminal.
 
static void callback(int severity, bool abort, const char *location, const char *msg)
Message handler that hands over all diagnostics to the currently active instance.
 
CheckDiagsRAII(int severity, std::string inRoutine, std::string E)
Construct from ROOT's kWarning, kError, ... and strings specifying location and message.
 
ErrorHandlerFunc_t const fOldErrorHandler
Last active handler in case handlers are nested.
 
void optionalDiag(int severity, std::string location, std::string message, bool matchFullMessage=true)
Register a diagnostic that can, but need not necessarily be issued.
 
static CheckDiagsRAII * sActiveInstance
Last active error handler function.
 
std::vector< Diag_t > fUnexpectedDiags
 
std::vector< Diag_t > fExpectedDiags
 
void checkDiag(int severity, const char *location, const char *msg)
Check all received diags against list of expected ones.
 
CheckDiagsRAII *const fOldInstance
 
void requiredDiag(int severity, std::string location, std::string message, bool matchFullMessage=true)
Register a new diagnostic to check for.
 
CheckDiagsRAII()
Register this instance as diagnostic handler.
 
Allows a user function to catch and filter/analyse ROOT and cling diagnostics, e.g.
 
FilterDiagsRAII(ErrorHandlerFunc_t fn)
 
ErrorHandlerFunc_t fPrevHandler
 
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.