Logo ROOT  
Reference Guide
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:

{c++}
CheckDiagsRAII diagRAII{CheckDiagsRAII::EDK_Error, "TFile::TFile", "<Expected message>"};
diagRAII.optionalDiag(kInfo, "TFile::TFile", "Message that is issued only sometimes");
<test code>
#define c(i)
Definition: RSha256.hxx:101
Install a ROOT diagnostic handler to analyse diagnostics.
Definition: TestSupport.hxx:65
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: test.py:1

Definition at line 65 of file TestSupport.hxx.

Classes

struct  Diag_t
 

Public Member Functions

 CheckDiagsRAII ()
 Register this instance as diagnostic handler. More...
 
 CheckDiagsRAII (int severity, std::string inRoutine, std::string E)
 Construct from ROOT's kWarning, kError, ... and strings specifying location and message. More...
 
 ~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. More...
 
void requiredDiag (int severity, std::string location, std::string message, bool matchFullMessage=true)
 Register a new diagnostic to check for. More...
 

Private Member Functions

void checkDiag (int severity, const char *location, const char *msg)
 Check all received diags against list of expected ones. More...
 
void printDiags (std::vector< Diag_t > const &diags) const
 Print the diags in diags to the terminal. More...
 

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. More...
 

Private Attributes

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

Static Private Attributes

static CheckDiagsRAIIsActiveInstance = nullptr
 Last active error handler function. More...
 

#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 88 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 124 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 109 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.

◆ printDiags()

void ROOT::TestSupport::CheckDiagsRAII::printDiags ( std::vector< Diag_t > const &  diags) const
private

Print the diags in diags to the terminal.

Definition at line 127 of file TestSupport.cxx.

◆ 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.

Member Data Documentation

◆ fExpectedDiags

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

Definition at line 143 of file TestSupport.hxx.

◆ fOldErrorHandler

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

Last active handler in case handlers are nested.

Definition at line 147 of file TestSupport.hxx.

◆ fOldInstance

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

Definition at line 146 of file TestSupport.hxx.

◆ fUnexpectedDiags

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

Definition at line 144 of file TestSupport.hxx.

◆ sActiveInstance

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

Last active error handler function.

Definition at line 149 of file TestSupport.hxx.


The documentation for this class was generated from the following files: