17 #include <gtest/gtest.h> 26 int log_info_count_ = 0;
27 int log_debug_count_ = 0;
28 int log_trace_count_ = 0;
29 int log_warn_count_ = 0;
30 int log_error_count_ = 0;
31 int log_fatal_count_ = 0;
45 void LogInfo(
const char * tag,
const std::string & message)
override 48 expected_log_message_string_ = message;
52 void LogTrace(
const char * tag,
const std::string & message)
override 55 expected_log_message_string_ = message;
59 void LogDebug(
const char * tag,
const std::string & message)
override 62 expected_log_message_string_ = message;
66 void LogWarn(
const char * tag,
const std::string & message)
override 69 expected_log_message_string_ = message;
73 void LogError(
const char * tag,
const std::string & message)
override 76 expected_log_message_string_ = message;
80 void LogFatal(
const char * tag,
const std::string & message)
override 83 expected_log_message_string_ = message;
132 const std::string & message)
156 TEST(TestAWSLogSystem, TestLogMethod)
163 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 1);
166 "[1] fake info log message");
170 logger->
Log(Aws::Utils::Logging::LogLevel::Debug,
"debug_tag",
"[%d] fake debug log message", 2);
173 "[2] fake debug log message");
177 logger->
Log(Aws::Utils::Logging::LogLevel::Warn,
"warn_tag",
"[%d] fake warn log message", 3);
180 "[3] fake warn log message");
184 logger->
Log(Aws::Utils::Logging::LogLevel::Error,
"error_tag",
"[%d] fake error log message", 4);
187 "[4] fake error log message");
191 logger->
Log(Aws::Utils::Logging::LogLevel::Fatal,
"fatal_tag",
"[%d] fake fatal log message", 5);
194 "[5] fake fatal log message");
199 logger->
Log(Aws::Utils::Logging::LogLevel::Debug,
"debug_tag",
"[%d] fake debug log message", 6);
202 "[6] fake debug log message");
209 logger =
new ClassUnderTest(Aws::Utils::Logging::LogLevel::Error);
212 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 1);
218 logger->
Log(Aws::Utils::Logging::LogLevel::Debug,
"debug_tag",
"[%d] fake debug log message", 2);
224 logger->
Log(Aws::Utils::Logging::LogLevel::Error,
"error_tag",
"[%d] fake error log message", 3);
227 "[3] fake error log message");
231 logger->
Log(Aws::Utils::Logging::LogLevel::Fatal,
"fatal_tag",
"[%d] fake fatal log message", 4);
234 "[4] fake fatal log message");
241 logger =
new ClassUnderTest(Aws::Utils::Logging::LogLevel::Trace);
244 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 1);
247 "[1] fake info log message");
251 logger->
Log(Aws::Utils::Logging::LogLevel::Debug,
"debug_tag",
"[%d] fake debug log message", 2);
254 "[2] fake debug log message");
258 logger->
Log(Aws::Utils::Logging::LogLevel::Error,
"error_tag",
"[%d] fake error log message", 3);
261 "[3] fake error log message");
265 logger->
Log(Aws::Utils::Logging::LogLevel::Fatal,
"fatal_tag",
"[%d] fake fatal log message", 4);
268 "[4] fake fatal log message");
272 logger->
Log(Aws::Utils::Logging::LogLevel::Trace,
"trace_tag",
"[%d] fake trace log message", 5);
275 "[5] fake trace log message");
279 TEST(TestAWSLogSystem, TestLogStreamMethod)
281 Aws::OStringStream message_stream;
288 message_stream <<
"This is a first info log message.";
289 logger->
LogStream(Aws::Utils::Logging::LogLevel::Info,
"info_tag", message_stream);
292 "This is a first info log message.");
295 message_stream <<
" This is a second info log message.";
296 logger->
LogStream(Aws::Utils::Logging::LogLevel::Info,
"info_tag", message_stream);
299 "This is a first info log message. This is a second info log message.");
303 message_stream.str(
"");
307 logger =
new ClassUnderTest(Aws::Utils::Logging::LogLevel::Error);
310 message_stream <<
"This is a first info log message.";
311 logger->
LogStream(Aws::Utils::Logging::LogLevel::Info,
"info_tag", message_stream);
317 logger->
LogStream(Aws::Utils::Logging::LogLevel::Debug,
"debug_tag", message_stream);
323 message_stream.str(
"");
327 message_stream <<
"This is a first error log message.";
328 logger->
LogStream(Aws::Utils::Logging::LogLevel::Error,
"error_tag", message_stream);
331 "This is a first error log message.");
337 TEST(TestAWSLogSystem, TestChangingLogLevels)
344 EXPECT_EQ(logger->
GetLogLevel(), Aws::Utils::Logging::LogLevel::Debug);
347 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 1);
350 "[1] fake info log message");
359 logger->
SetLogLevel(Aws::Utils::Logging::LogLevel::Error);
362 EXPECT_EQ(logger->
GetLogLevel(), Aws::Utils::Logging::LogLevel::Error);
365 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 1);
371 logger->
Log(Aws::Utils::Logging::LogLevel::Fatal,
"fatal_tag",
"[%d] fake fatal log message", 1);
374 "[1] fake fatal log message");
383 logger->
SetLogLevel(Aws::Utils::Logging::LogLevel::Info);
386 EXPECT_EQ(logger->
GetLogLevel(), Aws::Utils::Logging::LogLevel::Info);
389 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 3);
392 "[3] fake info log message");
398 int main(
int argc,
char ** argv)
400 testing::InitGoogleTest(&argc, argv);
401 return RUN_ALL_TESTS();
TEST(TestAWSLogSystem, TestLogMethod)
void LogDebug(const char *tag, const std::string &message) override
void LogTrace(const char *tag, const std::string &message) override
void LogInfo(const char *tag, const std::string &message) override
void LogWarn(const char *tag, const std::string &message) override
static int GetLogInfoCount(const ClassUnderTest *class_under_test)
void Log(Aws::Utils::Logging::LogLevel log_level, const char *tag, const char *format,...) override
static int GetLogDebugCount(const ClassUnderTest *class_under_test)
static const std::string & GetExpectedTag(const ClassUnderTest *class_under_test)
Aws::Utils::Logging::LogLevel GetLogLevel() const override
static int GetLogTraceCount(const ClassUnderTest *class_under_test)
static int GetLogErrorCount(const ClassUnderTest *class_under_test)
static int GetLogFatalCount(const ClassUnderTest *class_under_test)
std::string expected_tag_
static const std::string & GetExpectedLogMessageString(const ClassUnderTest *class_under_test)
std::string expected_log_message_string_
ClassUnderTest(Aws::Utils::Logging::LogLevel log_level)
static int GetLogWarnCount(const ClassUnderTest *class_under_test)
static void ResetLogCounts(ClassUnderTest *class_under_test)
static void SetExpectedTagString(ClassUnderTest *class_under_test, const std::string &tag)
void LogFatal(const char *tag, const std::string &message) override
void LogStream(Aws::Utils::Logging::LogLevel log_level, const char *tag, const Aws::OStringStream &message_stream) override
static void SetExpectedLogMessageString(ClassUnderTest *class_under_test, const std::string &message)
void LogError(const char *tag, const std::string &message) override
void SetLogLevel(Aws::Utils::Logging::LogLevel log_level)
int main(int argc, char **argv)