|
17 | 17 |
|
18 | 18 | #include <gtest/gtest.h>
|
19 | 19 |
|
| 20 | +#include "gz/sim/EntityComponentManager.hh" |
20 | 21 | #include "gz/sim/Link.hh"
|
| 22 | +#include "gz/sim/components/Link.hh" |
| 23 | +#include "gz/sim/components/Name.hh" |
| 24 | +#include "gz/sim/components/ParentEntity.hh" |
| 25 | +#include "gz/sim/components/Sensor.hh" |
21 | 26 |
|
22 | 27 | /////////////////////////////////////////////////
|
23 | 28 | TEST(LinkTest, Constructor)
|
@@ -74,3 +79,63 @@ TEST(LinkTest, MoveAssignmentOperator)
|
74 | 79 | linkMoved = std::move(link);
|
75 | 80 | EXPECT_EQ(id, linkMoved.Entity());
|
76 | 81 | }
|
| 82 | + |
| 83 | +///////////////////////////////////////////////// |
| 84 | +TEST(LinkTest, Sensors) |
| 85 | +{ |
| 86 | + // linkA |
| 87 | + // - sensorAA |
| 88 | + // - sensorAB |
| 89 | + // |
| 90 | + // linkC |
| 91 | + |
| 92 | + gz::sim::EntityComponentManager ecm; |
| 93 | + |
| 94 | + // Link A |
| 95 | + auto linkAEntity = ecm.CreateEntity(); |
| 96 | + ecm.CreateComponent(linkAEntity, gz::sim::components::Link()); |
| 97 | + ecm.CreateComponent(linkAEntity, |
| 98 | + gz::sim::components::Name("linkA_name")); |
| 99 | + |
| 100 | + // Sensor AA - Child of Link A |
| 101 | + auto sensorAAEntity = ecm.CreateEntity(); |
| 102 | + ecm.CreateComponent(sensorAAEntity, gz::sim::components::Sensor()); |
| 103 | + ecm.CreateComponent(sensorAAEntity, |
| 104 | + gz::sim::components::Name("sensorAA_name")); |
| 105 | + ecm.CreateComponent(sensorAAEntity, |
| 106 | + gz::sim::components::ParentEntity(linkAEntity)); |
| 107 | + |
| 108 | + // Sensor AB - Child of Link A |
| 109 | + auto sensorABEntity = ecm.CreateEntity(); |
| 110 | + ecm.CreateComponent(sensorABEntity, gz::sim::components::Sensor()); |
| 111 | + ecm.CreateComponent(sensorABEntity, |
| 112 | + gz::sim::components::Name("sensorAB_name")); |
| 113 | + ecm.CreateComponent(sensorABEntity, |
| 114 | + gz::sim::components::ParentEntity(linkAEntity)); |
| 115 | + |
| 116 | + // Link C |
| 117 | + auto linkCEntity = ecm.CreateEntity(); |
| 118 | + ecm.CreateComponent(linkCEntity, gz::sim::components::Link()); |
| 119 | + ecm.CreateComponent(linkCEntity, |
| 120 | + gz::sim::components::Name("linkC_name")); |
| 121 | + |
| 122 | + std::size_t foundSensors = 0; |
| 123 | + |
| 124 | + gz::sim::Link linkA(linkAEntity); |
| 125 | + auto sensors = linkA.Sensors(ecm); |
| 126 | + EXPECT_EQ(2u, sensors.size()); |
| 127 | + for (const auto &sensor : sensors) |
| 128 | + { |
| 129 | + if (sensor == sensorAAEntity || sensor == sensorABEntity) |
| 130 | + foundSensors++; |
| 131 | + } |
| 132 | + EXPECT_EQ(foundSensors, sensors.size()); |
| 133 | + |
| 134 | + EXPECT_EQ(sensorAAEntity, linkA.SensorByName(ecm, "sensorAA_name")); |
| 135 | + EXPECT_EQ(sensorABEntity, linkA.SensorByName(ecm, "sensorAB_name")); |
| 136 | + EXPECT_EQ(gz::sim::kNullEntity, linkA.SensorByName(ecm, "invalid")); |
| 137 | + |
| 138 | + gz::sim::Link linkC(linkCEntity); |
| 139 | + EXPECT_EQ(0u, linkC.Sensors(ecm).size()); |
| 140 | + EXPECT_EQ(gz::sim::kNullEntity, linkC.SensorByName(ecm, "invalid")); |
| 141 | +} |
0 commit comments