BaseAssetProcessorTest.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #pragma once
  9. #include <qlogging.h>
  10. #include <QString>
  11. // Environments subclass from AZ::Test::ITestEnvironment
  12. class BaseAssetProcessorTestEnvironment : public AZ::Test::ITestEnvironment
  13. {
  14. public:
  15. virtual ~BaseAssetProcessorTestEnvironment() {}
  16. protected:
  17. // Any time Qt emits a warning, critical, or fatal, consider the test to have failed!
  18. static void UnitTestMessageHandler(QtMsgType type, const QMessageLogContext& /*context*/, const QString& msg)
  19. {
  20. switch (type)
  21. {
  22. case QtDebugMsg:
  23. break;
  24. case QtWarningMsg:
  25. EXPECT_FALSE("QtWarningMsg") << msg.toUtf8().constData();
  26. break;
  27. case QtCriticalMsg:
  28. EXPECT_FALSE("QtCriticalMsg") << msg.toUtf8().constData();
  29. break;
  30. case QtFatalMsg:
  31. EXPECT_FALSE("QtFatalMsg") << msg.toUtf8().constData();
  32. break;
  33. }
  34. }
  35. // There are two pure-virtual functions to implement, setup and teardown
  36. void SetupEnvironment() override
  37. {
  38. // Setup code
  39. qInstallMessageHandler(UnitTestMessageHandler);
  40. }
  41. void TeardownEnvironment() override
  42. {
  43. qInstallMessageHandler(nullptr);
  44. }
  45. private:
  46. // Put members that need to be maintained throughout testing lifecycle here
  47. // Don't declare them in the setup/teardown functions!
  48. };