Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::TestSupport::CheckDiagsRAII Class Reference

Install a ROOT diagnostic handler to analyse diagnostics.

It will record all diagnostics during its lifetime, and analyse them at destruction. Required and/or optional diagnostics need to be predefined with expected location and message. Unexpected or missing diagnostics will lead to gtest failures.

Example:

++
CheckDiagsRAII diagRAII{CheckDiagsRAII::EDK_Error, "TFile::TFile", "<Expected message>"};
diagRAII.optionalDiag(kInfo, "TFile::TFile", "Message that is issued only sometimes");
<test code>
constexpr Int_t kInfo
Definition TError.h:44
Install a ROOT diagnostic handler to analyse diagnostics.
void optionalDiag(int severity, std::string location, std::string message, bool matchFullMessage=true)
Register a diagnostic that can, but need not necessarily be issued.

Definition at line 65 of file TestSupport.hxx.

Classes

struct  Diag_t
 

Public Member Functions

 CheckDiagsRAII ()
 Register this instance as diagnostic handler.
 
 CheckDiagsRAII (int severity, std::string inRoutine, std::string E)
 Construct from ROOT's kWarning, kError, ... and strings specifying location and message.
 
 ~CheckDiagsRAII ()
 
void optionalDiag (int severity, std::string location, std::string message, bool matchFullMessage=true)
 Register a diagnostic that can, but need not necessarily be issued.
 
void requiredDiag (int severity, std::string location, std::string message, bool matchFullMessage=true)
 Register a new diagnostic to check for.
 

Private Member Functions

void checkDiag (int severity, const char *location, const char *msg)
 Check all received diags against list of expected ones.
 

Static Private Member Functions

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.
 

Private Attributes

std::vector< Diag_tfExpectedDiags
 
ErrorHandlerFunc_t const fOldErrorHandler
 Last active handler in case handlers are nested.
 
CheckDiagsRAII *const fOldInstance
 
std::vector< Diag_tfUnexpectedDiags
 

Static Private Attributes

static CheckDiagsRAIIsActiveInstance = nullptr
 Last active error handler function.
 

Friends

std::ostream & operator<< (std::ostream &stream, Diag_t const &diag)
 

#include <ROOT/TestSupport.hxx>

Constructor & Destructor Documentation

◆ CheckDiagsRAII() [1/2]

ROOT::TestSupport::CheckDiagsRAII::CheckDiagsRAII ( )
inline

Register this instance as diagnostic handler.

With no further action, any diagnostic will lead to a test failure.

Definition at line 69 of file TestSupport.hxx.

◆ CheckDiagsRAII() [2/2]

ROOT::TestSupport::CheckDiagsRAII::CheckDiagsRAII ( int  severity,
std::string  inRoutine,
std::string  E 
)
inline

Construct from ROOT's kWarning, kError, ... and strings specifying location and message.

Definition at line 79 of file TestSupport.hxx.

◆ ~CheckDiagsRAII()

ROOT::TestSupport::CheckDiagsRAII::~CheckDiagsRAII ( )

Definition at line 94 of file TestSupport.cxx.

Member Function Documentation

◆ callback()

static void ROOT::TestSupport::CheckDiagsRAII::callback ( int  severity,
bool  abort,
const char *  location,
const char *  msg 
)
inlinestaticprivate

Message handler that hands over all diagnostics to the currently active instance.

Definition at line 115 of file TestSupport.hxx.

◆ checkDiag()

void ROOT::TestSupport::CheckDiagsRAII::checkDiag ( int  severity,
const char *  location,
const char *  msg 
)
private

Check all received diags against list of expected ones.

Search list of expected diagnostics for given arguments, and increase the receivedCount.

If no matching predefined diagnostic is found, this will trigger an unexpected diagnostic error on exit.

Definition at line 112 of file TestSupport.cxx.

◆ optionalDiag()

void ROOT::TestSupport::CheckDiagsRAII::optionalDiag ( int  severity,
std::string  location,
std::string  message,
bool  matchFullMessage = true 
)
inline

Register a diagnostic that can, but need not necessarily be issued.

Parameters
severityOne of kInfo kWarning kError kSysError.
locationFunction name where the diagnostic should be issued.
messageDiagnostic message.
matchFullMessageIf true, the message must be exactly identical. If false, it's sufficient that message is a substring of the diagnostic message.

Definition at line 106 of file TestSupport.hxx.

◆ requiredDiag()

void ROOT::TestSupport::CheckDiagsRAII::requiredDiag ( int  severity,
std::string  location,
std::string  message,
bool  matchFullMessage = true 
)
inline

Register a new diagnostic to check for.

Parameters
severityOne of kInfo kWarning kError kSysError.
locationFunction name where the diagnostic should be issued.
messageDiagnostic message.
matchFullMessageIf true, the message must be exactly identical. If false, it's sufficient that message is a substring of the diagnostic message.

Definition at line 93 of file TestSupport.hxx.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  stream,
CheckDiagsRAII::Diag_t const &  diag 
)
friend

Definition at line 131 of file TestSupport.cxx.

Member Data Documentation

◆ fExpectedDiags

std::vector<Diag_t> ROOT::TestSupport::CheckDiagsRAII::fExpectedDiags
private

Definition at line 142 of file TestSupport.hxx.

◆ fOldErrorHandler

ErrorHandlerFunc_t const ROOT::TestSupport::CheckDiagsRAII::fOldErrorHandler
private

Last active handler in case handlers are nested.

Definition at line 146 of file TestSupport.hxx.

◆ fOldInstance

CheckDiagsRAII* const ROOT::TestSupport::CheckDiagsRAII::fOldInstance
private

Definition at line 145 of file TestSupport.hxx.

◆ fUnexpectedDiags

std::vector<Diag_t> ROOT::TestSupport::CheckDiagsRAII::fUnexpectedDiags
private

Definition at line 143 of file TestSupport.hxx.

◆ sActiveInstance

CheckDiagsRAII * ROOT::TestSupport::CheckDiagsRAII::sActiveInstance = nullptr
staticprivate

Last active error handler function.

Definition at line 148 of file TestSupport.hxx.

  • core/testsupport/inc/ROOT/TestSupport.hxx
  • core/testsupport/src/TestSupport.cxx