TestFixture.h 3.6 KB

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