Skip to content

Commit 8357c0c

Browse files
Actuator state handle extension test
1 parent 543d2ac commit 8357c0c

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

hardware_interface/test/actuator_state_interface_test.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,82 @@ TEST_F(ActuatorStateInterfaceTest, ExcerciseApi)
125125
catch(const HardwareInterfaceException& e) {ROS_ERROR_STREAM(e.what());}
126126
}
127127

128+
namespace hardware_interface {
129+
130+
class CustomActuatorStateHandle
131+
{
132+
public:
133+
CustomActuatorStateHandle() = default;
134+
135+
CustomActuatorStateHandle(const double* custom) : custom_(custom)
136+
{
137+
if (!custom)
138+
{
139+
throw HardwareInterfaceException("Custom data pointer is null.");
140+
}
141+
}
142+
143+
virtual ~CustomActuatorStateHandle()
144+
{
145+
}
146+
147+
virtual double getCustom() const
148+
{
149+
assert(custom_);
150+
return *custom_;
151+
}
152+
153+
virtual const double* getCustomPtr() const
154+
{
155+
return custom_;
156+
}
157+
158+
virtual std::string getName() const = 0;
159+
160+
protected:
161+
const double* custom_ = nullptr;
162+
};
163+
164+
class ExtendedActuatorStateHandle : public ActuatorStateHandle,
165+
public CustomActuatorStateHandle
166+
{
167+
public:
168+
ExtendedActuatorStateHandle() = default;
169+
170+
ExtendedActuatorStateHandle(const std::string& name, const double* pos,
171+
const double* vel, const double* eff, const double* custom)
172+
: ActuatorStateHandle(name, pos, vel, eff), CustomActuatorStateHandle(custom)
173+
{
174+
}
175+
176+
std::string getName() const
177+
{
178+
return ActuatorStateHandle::getName();
179+
}
180+
};
181+
182+
}
183+
184+
TEST_F(ActuatorStateInterfaceTest, ExtensionTest)
185+
{
186+
const double POSITION = 1.0;
187+
const double VELOCITY = 2.0;
188+
const double EFFORT = 3.0;
189+
const double CUSTOM = 4.0;
190+
191+
double pos = POSITION;
192+
double vel = VELOCITY;
193+
double eff = EFFORT;
194+
double custom = CUSTOM;
195+
196+
ExtendedActuatorStateHandle act("ExtendedHandle", &pos, &vel, &eff, &custom);
197+
198+
ASSERT_EQ(act.getPosition(), POSITION);
199+
ASSERT_EQ(act.getVelocity(), VELOCITY);
200+
ASSERT_EQ(act.getEffort(), EFFORT);
201+
ASSERT_EQ(act.getCustom(), CUSTOM);
202+
}
203+
128204
int main(int argc, char** argv)
129205
{
130206
testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)