Belle II Software  release-08-01-10
LogMessageTest Class Reference

Test fixture to be able to check the contents and types of emitted log messages in detail. More...

#include <Fixtures.h>

Inheritance diagram for LogMessageTest:
Collaboration diagram for LogMessageTest:

Protected Member Functions

void SetUp () override
 Add a log message interceptor.
 
void TearDown () override
 And try to reset logging system to default.
 
void expectMessage (LogConfig::ELogLevel level=LogConfig::c_Error, int count=1, bool strict=false)
 check if there is a certain number of log messages of a given level More...
 
void expectMessageContent (LogConfig::ELogLevel level, const std::string &message)
 check the content of the last log message against the given values More...
 
void expectMessageVariables (std::map< std::string, std::string > &&variables, bool strict=false)
 check if the last message emitted contains the given variables and their values. More...
 
void expectErrorWithVariables (std::map< std::string, std::string > &&variables, bool strict=false)
 Expect an error with variables: This is a shorthand to check that there is exactly one error message present and that it contains the given variables. More...
 
void clearMessages ()
 clear the list of save log messages
 

Protected Attributes

std::vector< LogMessagem_messages
 list of log messages
 

Detailed Description

Test fixture to be able to check the contents and types of emitted log messages in detail.

In contrast to EXPECT_B2ERROR() and others defined here this test fixture will keep a copy of every message emitted and all messages can be expected in detail. There are a few convenient members to check for message counts and message contents.

Definition at line 23 of file Fixtures.h.

Member Function Documentation

◆ expectErrorWithVariables()

void expectErrorWithVariables ( std::map< std::string, std::string > &&  variables,
bool  strict = false 
)
protected

Expect an error with variables: This is a shorthand to check that there is exactly one error message present and that it contains the given variables.

This also clears the list of messages for convenience so after each call which is supposed to create an error this function can be called to handle the error message and afterwards the list of messages will be clean again for the next test.

This is a shorthand to just call expectMessage(), expectMessageVariables() and clearMessages()

Parameters
variablesmap of name->value mapping for all expected variables
strictif true also fail the test if there's any other variable in the message

Definition at line 75 of file Fixtures.cc.

76  {
78  expectMessageVariables(std::move(variables), strict);
79  clearMessages();
80  }
@ c_Error
Error: for things that went wrong and have to be fixed.
Definition: LogConfig.h:30
void expectMessageVariables(std::map< std::string, std::string > &&variables, bool strict=false)
check if the last message emitted contains the given variables and their values.
Definition: Fixtures.cc:59
void clearMessages()
clear the list of save log messages
Definition: Fixtures.h:62
void expectMessage(LogConfig::ELogLevel level=LogConfig::c_Error, int count=1, bool strict=false)
check if there is a certain number of log messages of a given level
Definition: Fixtures.cc:47

◆ expectMessage()

void expectMessage ( LogConfig::ELogLevel  level = LogConfig::c_Error,
int  count = 1,
bool  strict = false 
)
protected

check if there is a certain number of log messages of a given level

Parameters
levelwhich log level to check for
counthow many message should be expected
strictif true don't allow any other messages: the total number of messages must be equal to count and all need to have severity level

Definition at line 47 of file Fixtures.cc.

◆ expectMessageContent()

void expectMessageContent ( LogConfig::ELogLevel  level,
const std::string &  message 
)
protected

check the content of the last log message against the given values

Parameters
levellog level we expect for the message
messageexpected string content of the message.

Definition at line 82 of file Fixtures.cc.

◆ expectMessageVariables()

void expectMessageVariables ( std::map< std::string, std::string > &&  variables,
bool  strict = false 
)
protected

check if the last message emitted contains the given variables and their values.

Parameters
variablesmap of name->value mapping for all expected variables
strictif true also fail the test if there's any other variable in the message

Definition at line 59 of file Fixtures.cc.


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