Belle II Software development
Fixtures.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/logging/LogSystem.h>
12#include <gtest/gtest.h>
13
14namespace Belle2::TestHelpers {
23 class LogMessageTest: public ::testing::Test {
24 protected:
26 std::vector<LogMessage> m_messages;
28 void SetUp() override;
30 void TearDown() override;
37 void expectMessage(LogConfig::ELogLevel level = LogConfig::c_Error, int count = 1, bool strict = false);
42 void expectMessageContent(LogConfig::ELogLevel level, const std::string& message);
47 void expectMessageVariables(std::map<std::string, std::string>&& variables, bool strict = false);
60 void expectErrorWithVariables(std::map<std::string, std::string>&& variables, bool strict = false);
63 {
64 m_messages.clear();
65 }
66 };
67} // namespace Belle2::TestHelpers
ELogLevel
Definition of the supported log levels.
Definition: LogConfig.h:26
@ c_Error
Error: for things that went wrong and have to be fixed.
Definition: LogConfig.h:30
Test fixture to be able to check the contents and types of emitted log messages in detail.
Definition: Fixtures.h:23
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
std::vector< LogMessage > m_messages
list of log messages
Definition: Fixtures.h:26
void clearMessages()
clear the list of save log messages
Definition: Fixtures.h:62
void expectMessageContent(LogConfig::ELogLevel level, const std::string &message)
check the content of the last log message against the given values
Definition: Fixtures.cc:82
void SetUp() override
Add a log message interceptor.
Definition: Fixtures.cc:33
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 ...
Definition: Fixtures.cc:75
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
void TearDown() override
And try to reset logging system to default.
Definition: Fixtures.cc:42
Some utilities to help with writing unit tests.
Definition: Helix.cc:34