PythonBuilderTestShared.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <AzTest/AzTest.h>
  10. #include <AzCore/UnitTest/TestTypes.h>
  11. #include <AzCore/Component/ComponentApplication.h>
  12. #include <EditorPythonBindings/EditorPythonBindingsSymbols.h>
  13. #include "Source/PythonAssetBuilderSystemComponent.h"
  14. #include <PythonAssetBuilder/PythonAssetBuilderBus.h>
  15. #include <PythonAssetBuilder/PythonBuilderNotificationBus.h>
  16. namespace UnitTest
  17. {
  18. struct MockJobHandler final
  19. : public PythonAssetBuilder::PythonBuilderNotificationBus::Handler
  20. {
  21. int m_onShutdownCount = 0;
  22. int m_onCancelCount = 0;
  23. AssetBuilderSDK::CreateJobsResponse OnCreateJobsRequest(const AssetBuilderSDK::CreateJobsRequest& request) override
  24. {
  25. if (request.m_sourceFileUUID.IsNull())
  26. {
  27. return AssetBuilderSDK::CreateJobsResponse{};
  28. }
  29. AssetBuilderSDK::CreateJobsResponse response;
  30. response.m_result = AssetBuilderSDK::CreateJobsResultCode::Success;
  31. return response;
  32. }
  33. AssetBuilderSDK::ProcessJobResponse OnProcessJobRequest(const AssetBuilderSDK::ProcessJobRequest& request) override
  34. {
  35. if (request.m_sourceFileUUID.IsNull())
  36. {
  37. return AssetBuilderSDK::ProcessJobResponse{};
  38. }
  39. AssetBuilderSDK::ProcessJobResponse response;
  40. response.m_resultCode = AssetBuilderSDK::ProcessJobResult_Success;
  41. return response;
  42. }
  43. void OnShutdown() override
  44. {
  45. ++m_onShutdownCount;
  46. }
  47. void OnCancel() override
  48. {
  49. ++m_onCancelCount;
  50. }
  51. };
  52. template <typename App, typename EntityType>
  53. AZ::Uuid RegisterAssetBuilder(App* app, EntityType* systemEntity)
  54. {
  55. using namespace PythonAssetBuilder;
  56. using namespace AssetBuilderSDK;
  57. app->RegisterComponentDescriptor(PythonAssetBuilderSystemComponent::CreateDescriptor());
  58. systemEntity->template CreateComponent<PythonAssetBuilderSystemComponent>();
  59. systemEntity->Init();
  60. systemEntity->Activate();
  61. AssetBuilderPattern buildPattern;
  62. buildPattern.m_pattern = "*.mock";
  63. buildPattern.m_type = AssetBuilderPattern::Wildcard;
  64. AssetBuilderDesc builderDesc;
  65. builderDesc.m_busId = AZ::Uuid::CreateRandom();
  66. builderDesc.m_name = "Mock Builder";
  67. builderDesc.m_patterns.push_back(buildPattern);
  68. builderDesc.m_version = 0;
  69. AZ::Outcome<bool, AZStd::string> result;
  70. PythonAssetBuilderRequestBus::BroadcastResult(result, &PythonAssetBuilderRequestBus::Events::RegisterAssetBuilder, builderDesc);
  71. EXPECT_TRUE(result.IsSuccess());
  72. return builderDesc.m_busId;
  73. }
  74. }