Mercurial > hg > orthanc
comparison UnitTestsSources/LoggingTests.cpp @ 3359:815b81142ff7 emscripten-logging
Enable custom logging functions to redirect to emscripten specific logging calls
in the ORTHANC_ENABLE_LOGGING_STDIO mode.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 07 May 2019 11:23:11 +0200 |
parents | 54cdad5a7228 |
children | 1fdbe5885783 |
comparison
equal
deleted
inserted
replaced
3355:eb18269de57f | 3359:815b81142ff7 |
---|---|
34 #include "gtest/gtest.h" | 34 #include "gtest/gtest.h" |
35 #include <boost/regex.hpp> | 35 #include <boost/regex.hpp> |
36 #include <sstream> | 36 #include <sstream> |
37 | 37 |
38 #include "../Core/Logging.h" | 38 #include "../Core/Logging.h" |
39 #include "../Core/LoggingUtils.h" | |
39 | 40 |
40 using namespace Orthanc::Logging; | 41 using namespace Orthanc::Logging; |
41 | 42 |
42 static std::stringstream testErrorStream; | 43 static std::stringstream testErrorStream; |
43 void TestError(const char* message) | 44 void TestError(const char* message) |
64 --> | 65 --> |
65 "Foo bar" | 66 "Foo bar" |
66 | 67 |
67 If the log line cannot be matched, the function returns false. | 68 If the log line cannot be matched, the function returns false. |
68 */ | 69 */ |
70 | |
71 #ifdef WIN32 | |
72 # define EOLSTRING "\r\n" | |
73 #else | |
74 # define EOLSTRING "\n" | |
75 #endif | |
76 | |
69 static bool GetLogLinePayload(std::string& payload, | 77 static bool GetLogLinePayload(std::string& payload, |
70 const std::string& logLine) | 78 const std::string& logLine) |
71 { | 79 { |
72 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} " |
73 "[a-zA-Z\\.\\-_]+:[0-9]+\\] (.*)\r\n$"; | 81 "[a-zA-Z\\.\\-_]+:[0-9]+\\] (.*)" EOLSTRING "$"; |
82 | |
74 boost::regex regexObj(regexStr); | 83 boost::regex regexObj(regexStr); |
75 | 84 |
76 //std::stringstream regexSStr; | 85 //std::stringstream regexSStr; |
77 //regexSStr << "E[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6} " | 86 //regexSStr << "E[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6} " |
78 // "[a-zA-Z\\.\\-_]+:[0-9]+\\](.*)\r\n$"; | 87 // "[a-zA-Z\\.\\-_]+:[0-9]+\\](.*)\r\n$"; |
107 | 116 |
108 TEST(FuncStreamBuf, BasicTest) | 117 TEST(FuncStreamBuf, BasicTest) |
109 { | 118 { |
110 LoggingMementoScope loggingConfiguration; | 119 LoggingMementoScope loggingConfiguration; |
111 | 120 |
112 EnableTraceLevel(TRUE); | 121 EnableTraceLevel(true); |
113 | 122 |
114 typedef void(*LoggingFunctionFunc)(const char*); | 123 typedef void(*LoggingFunctionFunc)(const char*); |
115 | 124 |
116 FuncStreamBuf<LoggingFunctionFunc> errorStreamBuf(TestError); | 125 FuncStreamBuf<LoggingFunctionFunc> errorStreamBuf(TestError); |
117 std::ostream errorStream(&errorStreamBuf); | 126 std::ostream errorStream(&errorStreamBuf); |
130 std::string logLine = testErrorStream.str(); | 139 std::string logLine = testErrorStream.str(); |
131 testErrorStream.str(""); | 140 testErrorStream.str(""); |
132 testErrorStream.clear(); | 141 testErrorStream.clear(); |
133 std::string payload; | 142 std::string payload; |
134 bool ok = GetLogLinePayload(payload, logLine); | 143 bool ok = GetLogLinePayload(payload, logLine); |
144 ASSERT_TRUE(ok); | |
135 ASSERT_STREQ(payload.c_str(), text); | 145 ASSERT_STREQ(payload.c_str(), text); |
136 } | 146 } |
137 | 147 |
138 // make sure loglines do not accumulate | 148 // make sure loglines do not accumulate |
139 { | 149 { |
142 std::string logLine = testErrorStream.str(); | 152 std::string logLine = testErrorStream.str(); |
143 testErrorStream.str(""); | 153 testErrorStream.str(""); |
144 testErrorStream.clear(); | 154 testErrorStream.clear(); |
145 std::string payload; | 155 std::string payload; |
146 bool ok = GetLogLinePayload(payload, logLine); | 156 bool ok = GetLogLinePayload(payload, logLine); |
157 ASSERT_TRUE(ok); | |
147 ASSERT_STREQ(payload.c_str(), text); | 158 ASSERT_STREQ(payload.c_str(), text); |
148 } | 159 } |
149 | 160 |
150 { | 161 { |
151 const char* text = "Trougoudou 53535345345353"; | 162 const char* text = "Trougoudou 53535345345353"; |
153 std::string logLine = testWarningStream.str(); | 164 std::string logLine = testWarningStream.str(); |
154 testWarningStream.str(""); | 165 testWarningStream.str(""); |
155 testWarningStream.clear(); | 166 testWarningStream.clear(); |
156 std::string payload; | 167 std::string payload; |
157 bool ok = GetLogLinePayload(payload, logLine); | 168 bool ok = GetLogLinePayload(payload, logLine); |
169 ASSERT_TRUE(ok); | |
158 ASSERT_STREQ(payload.c_str(), text); | 170 ASSERT_STREQ(payload.c_str(), text); |
159 } | 171 } |
160 | 172 |
161 { | 173 { |
162 const char* text = "Prout 111929"; | 174 const char* text = "Prout 111929"; |
164 std::string logLine = testInfoStream.str(); | 176 std::string logLine = testInfoStream.str(); |
165 testInfoStream.str(""); | 177 testInfoStream.str(""); |
166 testInfoStream.clear(); | 178 testInfoStream.clear(); |
167 std::string payload; | 179 std::string payload; |
168 bool ok = GetLogLinePayload(payload, logLine); | 180 bool ok = GetLogLinePayload(payload, logLine); |
181 ASSERT_TRUE(ok); | |
169 ASSERT_STREQ(payload.c_str(), text); | 182 ASSERT_STREQ(payload.c_str(), text); |
170 } | 183 } |
171 } | 184 } |
172 | 185 |
173 | 186 |