AWSLogSystemInterfaceTest.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Console/Console.h>
  9. #include <AzCore/Console/IConsole.h>
  10. #include <AzCore/Interface/Interface.h>
  11. #include <AzCore/std/smart_ptr/unique_ptr.h>
  12. #include <AzCore/UnitTest/TestTypes.h>
  13. #include <AWSNativeSDKInit/AWSLogSystemInterface.h>
  14. #include <aws/core/utils/logging/LogLevel.h>
  15. using namespace AWSNativeSDKInit;
  16. class AWSLogSystemInterfaceTest
  17. : public UnitTest::LeakDetectionFixture
  18. , public AZ::Debug::TraceMessageBus::Handler
  19. {
  20. public:
  21. bool OnPreAssert(const char*, int, const char*, const char*) override
  22. {
  23. return true;
  24. }
  25. bool OnPreError(const char*, const char*, int, const char*, const char*) override
  26. {
  27. m_error = true;
  28. return true;
  29. }
  30. bool OnPreWarning(const char*, const char*, int, const char*, const char*) override
  31. {
  32. m_warning = true;
  33. return true;
  34. }
  35. bool OnPrintf(const char*, const char*) override
  36. {
  37. m_printf = true;
  38. return true;
  39. }
  40. void SetUp() override
  41. {
  42. BusConnect();
  43. if (!AZ::Interface<AZ::IConsole>::Get())
  44. {
  45. m_console = AZStd::make_unique<AZ::Console>();
  46. m_console->LinkDeferredFunctors(AZ::ConsoleFunctorBase::GetDeferredHead());
  47. AZ::Interface<AZ::IConsole>::Register(m_console.get());
  48. }
  49. }
  50. void TearDown() override
  51. {
  52. if (m_console)
  53. {
  54. AZ::Interface<AZ::IConsole>::Unregister(m_console.get());
  55. m_console.reset();
  56. }
  57. BusDisconnect();
  58. }
  59. bool m_error = false;
  60. bool m_warning = false;
  61. bool m_printf = false;
  62. private:
  63. AZStd::unique_ptr<AZ::Console> m_console;
  64. };
  65. TEST_F(AWSLogSystemInterfaceTest, LogStream_LogFatalMessage_GetExpectedNotification)
  66. {
  67. AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace);
  68. Aws::OStringStream testString;
  69. logSystem.LogStream(Aws::Utils::Logging::LogLevel::Fatal, "test", testString);
  70. ASSERT_TRUE(m_error);
  71. ASSERT_FALSE(m_warning);
  72. ASSERT_FALSE(m_printf);
  73. }
  74. TEST_F(AWSLogSystemInterfaceTest, LogStream_LogErrorMessage_GetExpectedNotification)
  75. {
  76. AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace);
  77. Aws::OStringStream testString;
  78. logSystem.LogStream(Aws::Utils::Logging::LogLevel::Error, "test", testString);
  79. ASSERT_TRUE(m_error);
  80. ASSERT_FALSE(m_warning);
  81. ASSERT_FALSE(m_printf);
  82. }
  83. TEST_F(AWSLogSystemInterfaceTest, LogStream_LogWarningMessage_GetExpectedNotification)
  84. {
  85. AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace);
  86. Aws::OStringStream testString;
  87. logSystem.LogStream(Aws::Utils::Logging::LogLevel::Warn, "test", testString);
  88. ASSERT_FALSE(m_error);
  89. ASSERT_TRUE(m_warning);
  90. ASSERT_FALSE(m_printf);
  91. }
  92. TEST_F(AWSLogSystemInterfaceTest, LogStream_LogInfoMessage_GetExpectedNotification)
  93. {
  94. AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace);
  95. Aws::OStringStream testString;
  96. logSystem.LogStream(Aws::Utils::Logging::LogLevel::Info, "test", testString);
  97. ASSERT_FALSE(m_error);
  98. ASSERT_FALSE(m_warning);
  99. ASSERT_TRUE(m_printf);
  100. }
  101. TEST_F(AWSLogSystemInterfaceTest, LogStream_LogDebugMessage_GetExpectedNotification)
  102. {
  103. AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace);
  104. Aws::OStringStream testString;
  105. logSystem.LogStream(Aws::Utils::Logging::LogLevel::Debug, "test", testString);
  106. ASSERT_FALSE(m_error);
  107. ASSERT_FALSE(m_warning);
  108. ASSERT_TRUE(m_printf);
  109. }
  110. TEST_F(AWSLogSystemInterfaceTest, LogStream_LogTraceMessage_GetExpectedNotification)
  111. {
  112. AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace);
  113. Aws::OStringStream testString;
  114. logSystem.LogStream(Aws::Utils::Logging::LogLevel::Trace, "test", testString);
  115. ASSERT_FALSE(m_error);
  116. ASSERT_FALSE(m_warning);
  117. ASSERT_TRUE(m_printf);
  118. }
  119. TEST_F(AWSLogSystemInterfaceTest, LogStream_OverrideWarnAndLogInfoMessage_GetExpectedNotification)
  120. {
  121. AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace);
  122. Aws::OStringStream testString;
  123. AZ::Interface<AZ::IConsole>::Get()->PerformCommand("bg_awsLogLevel 3");
  124. logSystem.LogStream(Aws::Utils::Logging::LogLevel::Info, "test", testString);
  125. ASSERT_FALSE(m_error);
  126. ASSERT_FALSE(m_warning);
  127. ASSERT_FALSE(m_printf);
  128. }
  129. TEST_F(AWSLogSystemInterfaceTest, LogStream_OverrideWarnAndLogeErrorMessage_GetExpectedNotification)
  130. {
  131. AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace);
  132. Aws::OStringStream testString;
  133. AZ::Interface<AZ::IConsole>::Get()->PerformCommand("bg_awsLogLevel 3");
  134. logSystem.LogStream(Aws::Utils::Logging::LogLevel::Error, "test", testString);
  135. ASSERT_TRUE(m_error);
  136. ASSERT_FALSE(m_warning);
  137. ASSERT_FALSE(m_printf);
  138. }
  139. TEST_F(AWSLogSystemInterfaceTest, LogStream_OverrideOffAndLogInfoMessage_GetExpectedNotification)
  140. {
  141. AWSLogSystemInterface logSystem(Aws::Utils::Logging::LogLevel::Trace);
  142. Aws::OStringStream testString;
  143. AZ::Interface<AZ::IConsole>::Get()->PerformCommand("bg_awsLogLevel 0");
  144. logSystem.LogStream(Aws::Utils::Logging::LogLevel::Info, "test", testString);
  145. ASSERT_FALSE(m_error);
  146. ASSERT_FALSE(m_warning);
  147. ASSERT_FALSE(m_printf);
  148. }