Belle II Software  release-05-01-25
Fixtures.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/logging/LogSystem.h>
14 #include <gtest/gtest.h>
15 
16 namespace Belle2::TestHelpers {
25  class LogMessageTest: public ::testing::Test {
26  protected:
28  std::vector<LogMessage> m_messages;
30  void SetUp() override;
32  void TearDown() override;
39  void expectMessage(LogConfig::ELogLevel level = LogConfig::c_Error, int count = 1, bool strict = false);
44  void expectMessageContent(LogConfig::ELogLevel level, const std::string& message);
49  void expectMessageVariables(std::map<std::string, std::string>&& variables, bool strict = false);
62  void expectErrorWithVariables(std::map<std::string, std::string>&& variables, bool strict = false);
64  void clearMessages()
65  {
66  m_messages.clear();
67  }
68  };
69 } // namespace Belle2::TestHelpers
Belle2::TestHelpers::LogMessageTest::expectMessageVariables
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:69
Belle2::TestHelpers::LogMessageTest::SetUp
void SetUp() override
Add a log message interceptor.
Definition: Fixtures.cc:43
Belle2::TestHelpers::LogMessageTest::TearDown
void TearDown() override
And try to reset logging system to default.
Definition: Fixtures.cc:52
Belle2::LogConfig::ELogLevel
ELogLevel
Definition of the supported log levels.
Definition: LogConfig.h:36
Belle2::TestHelpers::LogMessageTest::m_messages
std::vector< LogMessage > m_messages
list of log messages
Definition: Fixtures.h:44
Belle2::TestHelpers
Some utilities to help with writing unit tests.
Definition: Helix.cc:24
Belle2::LogConfig::c_Error
@ c_Error
Error: for things that went wrong and have to be fixed.
Definition: LogConfig.h:40
Belle2::TestHelpers::LogMessageTest::expectMessage
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:57
Belle2::TestHelpers::LogMessageTest::expectErrorWithVariables
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:86
Belle2::TestHelpers::LogMessageTest::clearMessages
void clearMessages()
clear the list of save log messages
Definition: Fixtures.h:80
Belle2::TestHelpers::LogMessageTest::expectMessageContent
void expectMessageContent(LogConfig::ELogLevel level, const std::string &message)
check the content of the last log message against the given values
Definition: Fixtures.cc:93