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)
153 TEST(TestAWSLogSystem, TestLogMethod)
160 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 1);
163 "[1] fake info log message");
167 logger->
Log(Aws::Utils::Logging::LogLevel::Debug,
"debug_tag",
"[%d] fake debug log message", 2);
170 "[2] fake debug log message");
174 logger->
Log(Aws::Utils::Logging::LogLevel::Warn,
"warn_tag",
"[%d] fake warn log message", 3);
177 "[3] fake warn log message");
181 logger->
Log(Aws::Utils::Logging::LogLevel::Error,
"error_tag",
"[%d] fake error log message", 4);
184 "[4] fake error log message");
188 logger->
Log(Aws::Utils::Logging::LogLevel::Fatal,
"fatal_tag",
"[%d] fake fatal log message", 5);
191 "[5] fake fatal log message");
196 logger->
Log(Aws::Utils::Logging::LogLevel::Debug,
"debug_tag",
"[%d] fake debug log message", 6);
199 "[6] fake debug log message");
206 logger =
new ClassUnderTest(Aws::Utils::Logging::LogLevel::Error);
209 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 1);
215 logger->
Log(Aws::Utils::Logging::LogLevel::Debug,
"debug_tag",
"[%d] fake debug log message", 2);
221 logger->
Log(Aws::Utils::Logging::LogLevel::Error,
"error_tag",
"[%d] fake error log message", 3);
224 "[3] fake error log message");
228 logger->
Log(Aws::Utils::Logging::LogLevel::Fatal,
"fatal_tag",
"[%d] fake fatal log message", 4);
231 "[4] fake fatal log message");
238 logger =
new ClassUnderTest(Aws::Utils::Logging::LogLevel::Trace);
241 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 1);
244 "[1] fake info log message");
248 logger->
Log(Aws::Utils::Logging::LogLevel::Debug,
"debug_tag",
"[%d] fake debug log message", 2);
251 "[2] fake debug log message");
255 logger->
Log(Aws::Utils::Logging::LogLevel::Error,
"error_tag",
"[%d] fake error log message", 3);
258 "[3] fake error log message");
262 logger->
Log(Aws::Utils::Logging::LogLevel::Fatal,
"fatal_tag",
"[%d] fake fatal log message", 4);
265 "[4] fake fatal log message");
269 logger->
Log(Aws::Utils::Logging::LogLevel::Trace,
"trace_tag",
"[%d] fake trace log message", 5);
272 "[5] fake trace log message");
276 TEST(TestAWSLogSystem, TestLogStreamMethod)
278 Aws::OStringStream message_stream;
285 message_stream <<
"This is a first info log message.";
286 logger->
LogStream(Aws::Utils::Logging::LogLevel::Info,
"info_tag", message_stream);
289 "This is a first info log message.");
292 message_stream <<
" This is a second info log message.";
293 logger->
LogStream(Aws::Utils::Logging::LogLevel::Info,
"info_tag", message_stream);
296 "This is a first info log message. This is a second info log message.");
300 message_stream.str(
"");
304 logger =
new ClassUnderTest(Aws::Utils::Logging::LogLevel::Error);
307 message_stream <<
"This is a first info log message.";
308 logger->
LogStream(Aws::Utils::Logging::LogLevel::Info,
"info_tag", message_stream);
314 logger->
LogStream(Aws::Utils::Logging::LogLevel::Debug,
"debug_tag", message_stream);
320 message_stream.str(
"");
324 message_stream <<
"This is a first error log message.";
325 logger->
LogStream(Aws::Utils::Logging::LogLevel::Error,
"error_tag", message_stream);
328 "This is a first error log message.");
334 TEST(TestAWSLogSystem, TestChangingLogLevels)
341 EXPECT_EQ(logger->
GetLogLevel(), Aws::Utils::Logging::LogLevel::Debug);
344 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 1);
347 "[1] fake info log message");
356 logger->
SetLogLevel(Aws::Utils::Logging::LogLevel::Error);
359 EXPECT_EQ(logger->
GetLogLevel(), Aws::Utils::Logging::LogLevel::Error);
362 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 1);
368 logger->
Log(Aws::Utils::Logging::LogLevel::Fatal,
"fatal_tag",
"[%d] fake fatal log message", 1);
371 "[1] fake fatal log message");
380 logger->
SetLogLevel(Aws::Utils::Logging::LogLevel::Info);
383 EXPECT_EQ(logger->
GetLogLevel(), Aws::Utils::Logging::LogLevel::Info);
386 logger->
Log(Aws::Utils::Logging::LogLevel::Info,
"info_tag",
"[%d] fake info log message", 3);
389 "[3] fake info log message");
395 int main(
int argc,
char ** argv)
397 testing::InitGoogleTest(&argc, argv);
398 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)