PythonBuilderProcessJobTest.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 <AzTest/AzTest.h>
  9. #include <AzCore/UnitTest/TestTypes.h>
  10. #include <AzCore/Component/ComponentApplication.h>
  11. #include <AzCore/RTTI/BehaviorContext.h>
  12. #include <EditorPythonBindings/EditorPythonBindingsSymbols.h>
  13. #include "Source/PythonAssetBuilderSystemComponent.h"
  14. #include <PythonAssetBuilder/PythonAssetBuilderBus.h>
  15. #include "PythonBuilderTestShared.h"
  16. namespace UnitTest
  17. {
  18. class PythonBuilderProcessJobTest
  19. : public LeakDetectionFixture
  20. {
  21. protected:
  22. AZStd::unique_ptr<AZ::ComponentApplication> m_app;
  23. AZ::Entity* m_systemEntity = nullptr;
  24. void SetUp() override
  25. {
  26. AZ::ComponentApplication::Descriptor appDesc;
  27. m_app = AZStd::make_unique<AZ::ComponentApplication>();
  28. AZ::ComponentApplication::StartupParameters startupParameters;
  29. startupParameters.m_loadSettingsRegistry = false;
  30. m_systemEntity = m_app->Create(appDesc, startupParameters);
  31. }
  32. void TearDown() override
  33. {
  34. m_app.reset();
  35. }
  36. };
  37. TEST_F(PythonBuilderProcessJobTest, PythonBuilder_ProcessJob_ResultSuccess)
  38. {
  39. using namespace PythonAssetBuilder;
  40. using namespace AssetBuilderSDK;
  41. const AZ::Uuid builderId = RegisterAssetBuilder(m_app.get(), m_systemEntity);
  42. MockJobHandler mockJobHandler;
  43. mockJobHandler.BusConnect(builderId);
  44. AssetBuilderSDK::ProcessJobRequest request;
  45. request.m_builderGuid = builderId;
  46. request.m_sourceFileUUID = AZ::Uuid::CreateRandom();
  47. AssetBuilderSDK::ProcessJobResponse response;
  48. response.m_resultCode = AssetBuilderSDK::ProcessJobResult_NetworkIssue;
  49. PythonBuilderNotificationBus::EventResult(
  50. response,
  51. builderId,
  52. &PythonBuilderNotificationBus::Events::OnProcessJobRequest,
  53. request);
  54. EXPECT_EQ(AssetBuilderSDK::ProcessJobResult_Success, response.m_resultCode);
  55. EXPECT_EQ(0, mockJobHandler.m_onCancelCount);
  56. }
  57. TEST_F(PythonBuilderProcessJobTest, PythonBuilder_ProcessJob_ResultFailed)
  58. {
  59. using namespace PythonAssetBuilder;
  60. using namespace AssetBuilderSDK;
  61. const AZ::Uuid builderId = RegisterAssetBuilder(m_app.get(), m_systemEntity);
  62. MockJobHandler mockJobHandler;
  63. mockJobHandler.BusConnect(builderId);
  64. AssetBuilderSDK::ProcessJobRequest request;
  65. request.m_builderGuid = builderId;
  66. request.m_sourceFileUUID = AZ::Uuid::CreateNull();
  67. AssetBuilderSDK::ProcessJobResponse response;
  68. response.m_resultCode = AssetBuilderSDK::ProcessJobResult_Success;
  69. PythonBuilderNotificationBus::EventResult(
  70. response,
  71. builderId,
  72. &PythonBuilderNotificationBus::Events::OnProcessJobRequest,
  73. request);
  74. EXPECT_EQ(AssetBuilderSDK::ProcessJobResult_Failed, response.m_resultCode);
  75. EXPECT_EQ(0, mockJobHandler.m_onCancelCount);
  76. }
  77. TEST_F(PythonBuilderProcessJobTest, PythonBuilder_ProcessJob_OnCancel)
  78. {
  79. using namespace PythonAssetBuilder;
  80. using namespace AssetBuilderSDK;
  81. const AZ::Uuid builderId = RegisterAssetBuilder(m_app.get(), m_systemEntity);
  82. MockJobHandler mockJobHandler;
  83. mockJobHandler.BusConnect(builderId);
  84. PythonBuilderNotificationBus::Event(builderId, &PythonBuilderNotificationBus::Events::OnCancel);
  85. EXPECT_EQ(1, mockJobHandler.m_onCancelCount);
  86. }
  87. }