|
| 1 | +#include "AzCore/Component/Entity.h" |
| 2 | +#include "AzCore/RTTI/ReflectContext.h" |
| 3 | +#include "AzCore/Serialization/Json/BaseJsonSerializer.h" |
| 4 | +#include "AzCore/Serialization/Json/JsonSerialization.h" |
| 5 | +#include "AzCore/Serialization/SerializeContext.h" |
| 6 | +#include "Odometry/ROS2WheelOdometry.h" |
| 7 | +#include <AzCore/IO/Streamer/Streamer.h> |
| 8 | +#include <AzCore/IO/Streamer/StreamerComponent.h> |
| 9 | +#include <AzCore/Memory/Memory.h> |
| 10 | +#include <AzCore/Memory/SystemAllocator.h> |
| 11 | +#include <AzCore/UnitTest/TestTypes.h> |
| 12 | +#include <AzTest/AzTest.h> |
| 13 | + |
| 14 | +#include <AzCore/Serialization/Json/JsonSystemComponent.h> |
| 15 | +#include <AzCore/UserSettings/UserSettingsComponent.h> |
| 16 | +#include <AzTest/GemTestEnvironment.h> |
| 17 | +#include <AzToolsFramework/UnitTest/ToolsTestApplication.h> |
| 18 | + |
| 19 | +namespace UnitTest |
| 20 | +{ |
| 21 | + class ROS2SensorsTestEnvironment : public AZ::Test::GemTestEnvironment |
| 22 | + { |
| 23 | + // AZ::Test::GemTestEnvironment overrides ... |
| 24 | + void AddGemsAndComponents() override; |
| 25 | + AZ::ComponentApplication* CreateApplicationInstance() override; |
| 26 | + void PostSystemEntityActivate() override; |
| 27 | + |
| 28 | + public: |
| 29 | + ROS2SensorsTestEnvironment() = default; |
| 30 | + ~ROS2SensorsTestEnvironment() override = default; |
| 31 | + }; |
| 32 | + |
| 33 | + void ROS2SensorsTestEnvironment::AddGemsAndComponents() |
| 34 | + { |
| 35 | + AddActiveGems(AZStd::to_array<AZStd::string_view>({ "ROS2", "ROS2Sensors"})); |
| 36 | + AddDynamicModulePaths({ "ROS2" }); |
| 37 | + // AddComponentDescriptors(AZStd::initializer_list<AZ::ComponentDescriptor*>{ ROS2::ROS2WheelOdometryComponent::CreateDescriptor(), |
| 38 | + // AZ::JsonSystemComponent::CreateDescriptor() }); |
| 39 | + // AddRequiredComponents(AZStd::to_array<AZ::TypeId const>({ AZ::JsonSystemComponent::TYPEINFO_Uuid() })); |
| 40 | + } |
| 41 | + |
| 42 | + AZ::ComponentApplication* ROS2SensorsTestEnvironment::CreateApplicationInstance() |
| 43 | + { |
| 44 | + // Using ToolsTestApplication to have AzFramework and AzToolsFramework components. |
| 45 | + return aznew UnitTest::ToolsTestApplication("ROS2SensorsTestEnvironment"); |
| 46 | + } |
| 47 | + |
| 48 | + void ROS2SensorsTestEnvironment::PostSystemEntityActivate() |
| 49 | + { |
| 50 | + AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize); |
| 51 | + } |
| 52 | + |
| 53 | + class ROS2SensorsTestFixture : public ::testing::Test |
| 54 | + { |
| 55 | + }; |
| 56 | + |
| 57 | + // Smoke test |
| 58 | + TEST_F(ROS2SensorsTestFixture, WheelOdometryComponent) |
| 59 | + { |
| 60 | + // Create a WheelOdometryComponent and check if it is created successfully |
| 61 | + // ROS2::ROS2WheelOdometryComponent wheelOdometryComponent; |
| 62 | + // EXPECT_NE(wheelOdometryComponent, nullptr); |
| 63 | + } |
| 64 | + |
| 65 | + // Store test |
| 66 | + TEST_F(ROS2SensorsTestFixture, WheelOdometryComponentStore) |
| 67 | + { |
| 68 | + // // Create a WheelOdometryComponent and check if it is created successfully |
| 69 | + // ROS2::ROS2WheelOdometryComponent wheelOdometryComponent; |
| 70 | + // // EXPECT_NE(wheelOdometryComponent, nullptr); |
| 71 | + |
| 72 | + // // Create a JSON object to store the component's configuration |
| 73 | + // rapidjson::Document document; |
| 74 | + // document.SetObject(); |
| 75 | + |
| 76 | + // AZ::Entity entity; |
| 77 | + // // auto* wheelOdometryComponent |
| 78 | + |
| 79 | + // auto jsonDocument = AZStd::make_unique<rapidjson::Document>(); |
| 80 | + |
| 81 | + // AZ::JsonDeserializerSettings settings; |
| 82 | + // auto storeResult = AZ::JsonSerialization::Load(wheelOdometryComponent, *jsonDocument, settings); |
| 83 | + |
| 84 | + // // Check if the store operation was successful |
| 85 | + // EXPECT_EQ(storeResult.GetOutcome(), AZ::JsonSerializationResult::Outcomes::Success); |
| 86 | + } |
| 87 | +} // namespace UnitTest |
| 88 | + |
| 89 | +// required to support running integration tests with Qt and PhysX |
| 90 | +AZTEST_EXPORT int AZ_UNIT_TEST_HOOK_NAME(int argc, char** argv) |
| 91 | +{ |
| 92 | + ::testing::InitGoogleMock(&argc, argv); |
| 93 | + AZ::Test::printUnusedParametersWarning(argc, argv); |
| 94 | + AZ::Test::addTestEnvironments({ new UnitTest::ROS2SensorsTestEnvironment() }); |
| 95 | + int result = RUN_ALL_TESTS(); |
| 96 | + return result; |
| 97 | +} |
| 98 | + |
| 99 | +IMPLEMENT_TEST_EXECUTABLE_MAIN(); |
0 commit comments