ADTF
Loading...
Searching...
No Matches
test_logger.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <adtf_utils.h>
10#include <string>
11#include <vector>
12#include <regex>
13#include <ostream>
14#include <adtfbase/chrono.h>
15
16namespace adtf
17{
18namespace system
19{
20namespace testing
21{
22namespace lucky
23{
24
29{
30public:
34 struct tMessage
35 {
36 tTimeStamp nTimeStamp;
37 uint8_t nLogLevel;
38 std::string strText;
39 std::string strSource;
40
41 bool operator==(const tMessage& oOther) const noexcept
42 {
43 return nTimeStamp == oOther.nTimeStamp && nLogLevel == oOther.nLogLevel && strText == oOther.strText &&
44 strSource == oOther.strSource;
45 }
46 };
47
51 struct tMessages : public std::vector<tMessage>
52 {
53 public:
58 tMessages Filter(uint8_t nLogLevel);
59
64 tMessages Filter(const std::string& strContent);
65
71 tMessages Filter(const std::regex& strPattern, bool bPartialMatch = true);
72
77 tMessages FilterSource(const std::string& strContent);
78
84 tMessages FilterSource(const std::regex& strPattern, bool bPartialMatch = true);
85
90 bool ContainsMessage(const std::string& strContent);
91
97 bool ContainsMessage(const std::regex& strPattern, bool bPartialMatch = true);
98
104 tMessage FindMessage(const std::string& strContent);
105
112 tMessage FindMessage(const std::regex& strPattern, bool bPartialMatch = true);
113 };
114
120
125
131 tMessages GetCurrentMessages(bool bClear = true);
132
139
140private:
141 class cImplementation;
142 std::unique_ptr<cImplementation> m_pImplementation;
143};
144
145inline ::std::ostream& operator<<(::std::ostream& os, const cTestLogger::tMessage& oMessage)
146{
147 os << "{" << oMessage.nTimeStamp << ", " << static_cast<int>(oMessage.nLogLevel) << ", \"" << oMessage.strText
148 << "\", \"" << oMessage.strSource << "\"}";
149 return os;
150}
151
152} // namespace lucky
153
154using lucky::cTestLogger;
155
156} // namespace testing
157} // namespace system
158} // namespace adtf
tMessages GetCurrentMessages(bool bClear=true)
bool WaitForMessage(base::flash::tNanoSeconds tmTimeout=base::flash::tNanoSeconds{-1})
Namespace for all testing functionality of the ADTF System SDK provided since v3.11.
Definition test_logger.h:23
Namespace for all testing functionality of the ADTF System SDK.
Definition adtf_system.h:292
Namespace for the ADTF System SDK.
Definition adtf_service.h:14
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
A timestamp with nanosecond precision.
Definition chrono.h:23
uint8_t nLogLevel
the log level, see adtf::util::log::tLogLevel
Definition test_logger.h:37
std::string strSource
the source of the message
Definition test_logger.h:39
std::string strText
the message text
Definition test_logger.h:38
tTimeStamp nTimeStamp
the timestamp
Definition test_logger.h:36
uint8_t nLogLevel
the log level, see adtf::util::log::tLogLevel
Definition test_logger.h:37
std::string strSource
the source of the message
Definition test_logger.h:39
std::string strText
the message text
Definition test_logger.h:38
tTimeStamp nTimeStamp
the timestamp
Definition test_logger.h:36
tMessages Filter(const std::string &strContent)
tMessages FilterSource(const std::regex &strPattern, bool bPartialMatch=true)
tMessage FindMessage(const std::string &strContent)
tMessages Filter(const std::regex &strPattern, bool bPartialMatch=true)
tMessages FilterSource(const std::string &strContent)
bool ContainsMessage(const std::string &strContent)
bool ContainsMessage(const std::regex &strPattern, bool bPartialMatch=true)
tMessage FindMessage(const std::regex &strPattern, bool bPartialMatch=true)