TestFixture.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <AzCore/Asset/AssetManagerComponent.h>
  10. #include <AzCore/Component/ComponentApplication.h>
  11. #include <AzCore/Component/ComponentApplicationBus.h>
  12. #include <AzCore/Component/Entity.h>
  13. #include <AzCore/Component/EntityId.h>
  14. #include <AzCore/RTTI/RTTIMacros.h>
  15. #include <AzCore/Serialization/SerializeContext.h>
  16. #include <AzCore/Slice/SliceAssetHandler.h>
  17. #include <AzCore/UserSettings/UserSettingsComponent.h>
  18. #include <AzCore/std/containers/array.h>
  19. #include <AzCore/std/string/string_view.h>
  20. #include <AzQtComponents/Utilities/QtPluginPaths.h>
  21. #include <AzTest/GemTestEnvironment.h>
  22. #include <AzToolsFramework/Entity/EditorEntityContextComponent.h>
  23. #include <AzToolsFramework/ToolsComponents/TransformComponent.h>
  24. #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
  25. #include <AzToolsFramework/UnitTest/ToolsTestApplication.h>
  26. #include <QApplication>
  27. #include <gtest/gtest.h>
  28. #include <memory>
  29. #include <string>
  30. #include <string_view>
  31. #include <vector>
  32. #include <AzCore/Utils/Utils.h>
  33. #include <AzFramework/Asset/AssetCatalog.h>
  34. #include <AzFramework/Physics/Configuration/SystemConfiguration.h>
  35. #include <AzFramework/Physics/PhysicsSystem.h>
  36. #include <AzFramework/Physics/RigidBodyBus.h>
  37. #include <AzFramework/Physics/SimulatedBodies/RigidBody.h>
  38. #include <AzFramework/Physics/SystemBus.h>
  39. namespace UnitTest
  40. {
  41. class SimulationInterfaceTestEnvironment : public AZ::Test::GemTestEnvironment
  42. {
  43. // AZ::Test::GemTestEnvironment overrides ...
  44. void AddGemsAndComponents() override;
  45. AZ::ComponentApplication* CreateApplicationInstance() override;
  46. protected:
  47. void PostSystemEntityActivate() override;
  48. public:
  49. SimulationInterfaceTestEnvironment() = default;
  50. ~SimulationInterfaceTestEnvironment() override = default;
  51. };
  52. class SimulationInterfaceTestFixture
  53. : public ::testing::Test
  54. , protected Physics::DefaultWorldBus::Handler
  55. {
  56. protected:
  57. constexpr static auto PhysXRigidBodyComponentTypeId = "{D4E52A70-BDE1-4819-BD3C-93AB3F4F3BE3}"; // From PhysX
  58. constexpr static auto PhysXStaticBodyComponentTypeId = "{A2CCCD3D-FB31-4D65-8DCD-2CD7E1D09538}"; // From PhysX
  59. constexpr static auto PhysXShapeColliderComponentTypeId = "{30CC9E77-378C-49DF-9617-6BF191901FE0}"; // From PhysX
  60. constexpr static auto PhysXSphereColliderComponentTypeId = "{108CD341-E5C3-4AE1-B712-21E81ED6C277}"; // From PhysX
  61. constexpr static auto SphereShapeComponentTypeId = "{E24CBFF0-2531-4F8D-A8AB-47AF4D54BCD2}"; // From LmbrCentral
  62. void SetUp() override;
  63. void TearDown() override;
  64. AZ::EntityId CreateEntityWithStaticBodyComponent(const AZStd::string& entityName, const AZ::Transform& transform);
  65. void DeleteEntity(const AZ::EntityId& entityId);
  66. void ClearEntities();
  67. AZStd::unordered_map<AZ::EntityId, AZStd::unique_ptr<AZ::Entity>> m_entities;
  68. void AddAsset(const AZStd::string& assetPath);
  69. //! Ask the physics system to step forward in time
  70. void StepPhysics(int numSteps = 1);
  71. //! Ask the application to tick forward in time
  72. void TickApp(int numTicks = 1);
  73. private:
  74. AzPhysics::SceneHandle GetDefaultSceneHandle() const override;
  75. AzPhysics::Scene* m_defaultScene = nullptr;
  76. AzPhysics::SceneHandle m_testSceneHandle = AzPhysics::InvalidSceneHandle;
  77. AZStd::unordered_set<AZ::Data::AssetId> m_registeredAssets;
  78. };
  79. } // namespace UnitTest