Mercurial > hg > orthanc
comparison UnitTestsSources/LoggingTests.cpp @ 4008:2d4427ca4be9
removed Core/LoggingUtils.h
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Jun 2020 08:47:43 +0200 |
parents | 9b5ace33a00d |
children | 27628b0f6ada |
comparison
equal
deleted
inserted
replaced
4007:884b55ce01f6 | 4008:2d4427ca4be9 |
---|---|
39 #include "gtest/gtest.h" | 39 #include "gtest/gtest.h" |
40 #include <boost/regex.hpp> | 40 #include <boost/regex.hpp> |
41 #include <sstream> | 41 #include <sstream> |
42 | 42 |
43 #include "../Core/Logging.h" | 43 #include "../Core/Logging.h" |
44 #include "../Core/LoggingUtils.h" | |
45 | 44 |
46 using namespace Orthanc::Logging; | 45 using namespace Orthanc::Logging; |
47 | 46 |
48 static std::stringstream testErrorStream; | 47 static std::stringstream testErrorStream; |
49 void TestError(const char* message) | 48 void TestError(const char* message) |
62 { | 61 { |
63 testInfoStream << message; | 62 testInfoStream << message; |
64 } | 63 } |
65 | 64 |
66 /** | 65 /** |
67 Extracts the log line payload | 66 Extracts the log line payload |
68 | 67 |
69 "E0423 16:55:43.001194 LoggingTests.cpp:102] Foo bar?\n" | 68 "E0423 16:55:43.001194 LoggingTests.cpp:102] Foo bar?\n" |
70 --> | 69 --> |
71 "Foo bar" | 70 "Foo bar" |
72 | 71 |
73 If the log line cannot be matched, the function returns false. | 72 If the log line cannot be matched, the function returns false. |
74 */ | 73 */ |
75 | 74 |
76 #define EOLSTRING "\n" | 75 #define EOLSTRING "\n" |
77 | 76 |
78 static bool GetLogLinePayload(std::string& payload, | 77 static bool GetLogLinePayload(std::string& payload, |
79 const std::string& logLine) | 78 const std::string& logLine) |
80 { | 79 { |
81 const char* regexStr = "[A-Z][0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6} " | 80 const char* regexStr = "[A-Z][0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6} " |
82 "[a-zA-Z\\.\\-_]+:[0-9]+\\] (.*)" EOLSTRING "$"; | 81 "[a-zA-Z\\.\\-_]+:[0-9]+\\] (.*)" EOLSTRING "$"; |
83 | 82 |
84 boost::regex regexObj(regexStr); | 83 boost::regex regexObj(regexStr); |
97 else | 96 else |
98 { | 97 { |
99 return false; | 98 return false; |
100 } | 99 } |
101 } | 100 } |
101 | |
102 | 102 |
103 namespace | 103 namespace |
104 { | 104 { |
105 class LoggingMementoScope | 105 class LoggingMementoScope |
106 { | 106 { |
112 ~LoggingMementoScope() | 112 ~LoggingMementoScope() |
113 { | 113 { |
114 Orthanc::Logging::Reset(); | 114 Orthanc::Logging::Reset(); |
115 } | 115 } |
116 }; | 116 }; |
117 } | 117 |
118 | |
119 /** | |
120 * std::streambuf subclass used in FunctionCallingStream | |
121 **/ | |
122 template<typename T> | |
123 class FuncStreamBuf : public std::stringbuf | |
124 { | |
125 public: | |
126 FuncStreamBuf(T func) : func_(func) {} | |
127 | |
128 virtual int sync() | |
129 { | |
130 std::string text = this->str(); | |
131 const char* buf = text.c_str(); | |
132 func_(buf); | |
133 this->str(""); | |
134 return 0; | |
135 } | |
136 private: | |
137 T func_; | |
138 }; | |
139 } | |
140 | |
118 | 141 |
119 TEST(FuncStreamBuf, BasicTest) | 142 TEST(FuncStreamBuf, BasicTest) |
120 { | 143 { |
121 LoggingMementoScope loggingConfiguration; | 144 LoggingMementoScope loggingConfiguration; |
122 | 145 |