test_EditorUtils.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "EditorDefs.h"
  9. #include <AzTest/AzTest.h>
  10. #include <Util/EditorUtils.h>
  11. #include <AzCore/base.h>
  12. #include <AzCore/Memory/SystemAllocator.h>
  13. #include <AzCore/Debug/TraceMessageBus.h>
  14. #include <AzCore/UnitTest/TestTypes.h>
  15. namespace EditorUtilsTest
  16. {
  17. class WarningDetector
  18. : public AZ::Debug::TraceMessageBus::Handler
  19. {
  20. public:
  21. WarningDetector()
  22. {
  23. BusConnect();
  24. }
  25. ~WarningDetector() override
  26. {
  27. BusDisconnect();
  28. }
  29. bool OnWarning(const char* /*window*/, const char* /*message*/) override
  30. {
  31. m_gotWarning = true;
  32. return true;
  33. }
  34. bool m_gotWarning = false;
  35. };
  36. class TestWarningAbsorber
  37. : public ::UnitTest::LeakDetectionFixture
  38. {
  39. };
  40. TEST_F(TestWarningAbsorber, Test)
  41. {
  42. WarningDetector detector;
  43. EditorUtils::AzWarningAbsorber absorber("ignore this");
  44. AZ_Warning("ignore this", false, "This warning should occur but be absorbed by the absorber");
  45. ASSERT_FALSE(detector.m_gotWarning);
  46. AZ_Warning("different window", false, "This warning should occur but be left alone by the absorber");
  47. ASSERT_TRUE(detector.m_gotWarning);
  48. }
  49. TEST_F(TestWarningAbsorber, NullWindow)
  50. {
  51. WarningDetector detector;
  52. EditorUtils::AzWarningAbsorber absorber("ignore this");
  53. AZ_Warning(AZ::Debug::Trace::GetDefaultSystemWindow(), false, "This warning should occur and not be absorbed by the absorber since the window name is nullptr");
  54. ASSERT_TRUE(detector.m_gotWarning);
  55. }
  56. }