Skip to content

Commit 32fad04

Browse files
WIP unit test
Signed-off-by: Artur Kamieniecki <[email protected]>
1 parent b532f1c commit 32fad04

File tree

4 files changed

+106
-3
lines changed

4 files changed

+106
-3
lines changed

Gems/ROS2Sensors/Code/CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ endif()
221221
# See if globally, tests are supported
222222
if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
223223
# We globally support tests, see if we support tests on this platform for ${gem_name}.Tests
224-
if(PAL_TRAIT_ROS2SENSORS_TEST_SUPPORTED)
224+
if(PAL_TRAIT_TEST_GOOGLE_TEST_SUPPORTED)
225225
# We support ${gem_name}.Tests on this platform, add dependency on the Private Object target
226226
ly_add_target(
227227
NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
@@ -249,7 +249,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
249249
# If we are a host platform we want to add tools test like editor tests here
250250
if(PAL_TRAIT_BUILD_HOST_TOOLS)
251251
# We are a host platform, see if Editor tests are supported on this platform
252-
if(PAL_TRAIT_ROS2SENSORS_EDITOR_TEST_SUPPORTED)
252+
if(PAL_TRAIT_TEST_GOOGLE_TEST_SUPPORTED)
253253
# We support ${gem_name}.Editor.Tests on this platform, add ${gem_name}.Editor.Tests target which depends on
254254
# private ${gem_name}.Editor.Private.Object target
255255
ly_add_target(
@@ -265,6 +265,9 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
265265
BUILD_DEPENDENCIES
266266
PRIVATE
267267
AZ::AzTest
268+
AZ::AzTestShared
269+
AZ::AzToolsFramework
270+
AZ::AzManipulatorTestFramework.Static
268271
Gem::${gem_name}.Editor.Private.Object
269272
)
270273

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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();

Gems/ROS2Sensors/Code/Tests/Tools/ROS2SensorsEditorTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
#include <AzTest/AzTest.h>
1010

11-
AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);
11+
// AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);

Gems/ROS2Sensors/Code/ros2sensors_editor_tests_files.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
set(FILES
1010
Tests/Tools/ROS2SensorsEditorTest.cpp
11+
Tests/Odometry/ROS2WheelOdometrySerializationTest.cpp
1112
)

0 commit comments

Comments
 (0)