Commit ec154e2d authored by Ernst Maximilian Münker's avatar Ernst Maximilian Münker
Browse files

fix tests

parent 65c52776
Pipeline #669304 passed with stage
in 46 seconds
......@@ -39,7 +39,9 @@ public:
void init(${model.getCompName()}* comp){
this->component = comp;
<#list model.getSubscribers() as sub>
${sub.getMethodName()}_wasCalled = false;
</#list>
<@m.mwinit compname="${model.getCompName()}"/>
<#list model.getSubscribers() as sub>
......@@ -53,6 +55,10 @@ void init(${model.getCompName()}* comp){
<@m.mwstart/>
}
bool hasReceivedNewData() {
return true<#list model.getSubscribers() as sub> && ${sub.getMethodName()}_wasCalled</#list>;
}
<#list model.getSubscribers() as sub>
<@m.callback sub=sub/>
</#list>
......@@ -62,6 +68,9 @@ void init(${model.getCompName()}* comp){
</#list>
void tick(){
<#list model.getSubscribers() as sub>
${sub.getMethodName()}_wasCalled = false;
</#list>
<#list model.getPublishers() as pub>
${pub.getMethodName()}();
......
......@@ -52,6 +52,7 @@ void ${sub.getMethodName()}(const ${sub.getTypeNameInTargetLanguage()}::SharedPt
</#if>
</#if>
${sub.getMethodName()}_wasCalled = true;
}
</#macro>
......
......@@ -51,6 +51,7 @@ void ${sub.getMethodName()}(const ${sub.getTypeNameInTargetLanguage()}::ConstPtr
</#if>
</#if>
${sub.getMethodName()}_wasCalled = true;
}
</#macro>
......
......@@ -11,6 +11,12 @@
class RosAdapter_tests_structs_arrayHandlingComp: public IAdapter_tests_structs_arrayHandlingComp{
tests_structs_arrayHandlingComp* component;
bool _name1Callback_wasCalled;
bool _name2Callback_wasCalled;
bool _name3Callback_wasCalled;
bool _name4Callback_wasCalled;
ros::Subscriber _name1Subscriber;
ros::Subscriber _name2Subscriber;
ros::Subscriber _name3Subscriber;
......@@ -25,6 +31,10 @@ class RosAdapter_tests_structs_arrayHandlingComp: public IAdapter_tests_structs_
void init(tests_structs_arrayHandlingComp* comp){
this->component = comp;
_name1Callback_wasCalled = false;
_name2Callback_wasCalled = false;
_name3Callback_wasCalled = false;
_name4Callback_wasCalled = false;
char* tmp = strdup("");
int i = 0;
ros::init(i, &tmp, "RosAdapter_tests_structs_arrayHandlingComp_node");
......@@ -41,6 +51,10 @@ class RosAdapter_tests_structs_arrayHandlingComp: public IAdapter_tests_structs_
ros::spin();
}
bool hasReceivedNewData() {
return true && _name1Callback_wasCalled && _name2Callback_wasCalled && _name3Callback_wasCalled && _name4Callback_wasCalled;
}
void _name1Callback(const std_msgs::Float64MultiArray::ConstPtr& msg){
int counter = 0;
......@@ -60,6 +74,7 @@ class RosAdapter_tests_structs_arrayHandlingComp: public IAdapter_tests_structs_
}
_name1Callback_wasCalled = true;
}
void _name2Callback(const std_msgs::ByteMultiArray::ConstPtr& msg){
......@@ -80,6 +95,7 @@ class RosAdapter_tests_structs_arrayHandlingComp: public IAdapter_tests_structs_
}
_name2Callback_wasCalled = true;
}
void _name3Callback(const nav_msgs::Path::ConstPtr& msg){
......@@ -100,6 +116,7 @@ class RosAdapter_tests_structs_arrayHandlingComp: public IAdapter_tests_structs_
}
_name3Callback_wasCalled = true;
}
void _name4Callback(const nav_msgs::Path::ConstPtr& msg){
......@@ -120,6 +137,7 @@ class RosAdapter_tests_structs_arrayHandlingComp: public IAdapter_tests_structs_
}
_name4Callback_wasCalled = true;
}
void publish_name5Publisher(){
......@@ -150,6 +168,11 @@ class RosAdapter_tests_structs_arrayHandlingComp: public IAdapter_tests_structs_
}
void tick(){
_name1Callback_wasCalled = false;
_name2Callback_wasCalled = false;
_name3Callback_wasCalled = false;
_name4Callback_wasCalled = false;
publish_name5Publisher();
publish_name6Publisher();
}
......
......@@ -9,6 +9,9 @@ class RosAdapter_test_basicGenericInstance_basicGeneric: public IAdapter_test_ba
const int n = 3;
test_basicGenericInstance_basicGeneric* component;
bool _name1Callback_wasCalled;
ros::Subscriber _name1Subscriber;
ros::Publisher _name1Publisher;
......@@ -19,6 +22,7 @@ class RosAdapter_test_basicGenericInstance_basicGeneric: public IAdapter_test_ba
void init(test_basicGenericInstance_basicGeneric* comp){
this->component = comp;
_name1Callback_wasCalled = false;
char* tmp = strdup("");
int i = 0;
ros::init(i, &tmp, "RosAdapter_test_basicGenericInstance_basicGeneric_node");
......@@ -31,6 +35,10 @@ class RosAdapter_test_basicGenericInstance_basicGeneric: public IAdapter_test_ba
ros::spin();
}
bool hasReceivedNewData() {
return true && _name1Callback_wasCalled;
}
void _name1Callback(const std_msgs::Float64MultiArray::ConstPtr& msg){
int counter = 0;
......@@ -50,6 +58,7 @@ class RosAdapter_test_basicGenericInstance_basicGeneric: public IAdapter_test_ba
}
_name1Callback_wasCalled = true;
}
void publish_name1Publisher(){
......@@ -67,7 +76,9 @@ class RosAdapter_test_basicGenericInstance_basicGeneric: public IAdapter_test_ba
}
void tick(){
_name1Callback_wasCalled = false;
publish_name1Publisher();
}
};
};
\ No newline at end of file
......@@ -4,8 +4,13 @@
#include "tests_msg_basicStructComp.h"
#include <ros/ros.h>
#include <struct_msgs/tests_structs_BasicStruct.h>
class RosAdapter_tests_msg_basicStructComp: public IAdapter_tests_msg_basicStructComp{
tests_msg_basicStructComp* component;
bool topic1Callback_wasCalled;
ros::Subscriber topic1Subscriber;
ros::Publisher topic2Publisher;
......@@ -16,23 +21,34 @@ class RosAdapter_tests_msg_basicStructComp: public IAdapter_tests_msg_basicStruc
void init(tests_msg_basicStructComp* comp){
this->component = comp;
topic1Callback_wasCalled = false;
char* tmp = strdup("");
int i = 0;
ros::init(i, &tmp, "RosAdapter_tests_msg_basicStructComp_node");
ros::NodeHandle node_handle = ros::NodeHandle();
topic1Subscriber = node_handle.subscribe("topic1", 5, &RosAdapter_tests_msg_basicStructComp::topic1Callback, this, ros::TransportHints().tcpNoDelay());
topic2Publisher = node_handle.advertise<struct_msgs::tests_structs_BasicStruct>("topic2",5);
ros::spin();
}
void topic1Callback(const struct_msgs::tests_structs_BasicStruct::ConstPtr& msg){
component->in1.fieldB1 = msg->fieldB1;
component->in1.fieldQ1 = msg->fieldQ1;
component->in1.fieldQ2 = msg->fieldQ2;
component->in1.fieldZ1 = msg->fieldZ1;
component->in1.fieldZ2 = msg->fieldZ2;
}
bool hasReceivedNewData() {
return true && topic1Callback_wasCalled;
}
void topic1Callback(const struct_msgs::tests_structs_BasicStruct::ConstPtr& msg){
component->in1.fieldB1 = msg->fieldB1;
component->in1.fieldQ1 = msg->fieldQ1;
component->in1.fieldQ2 = msg->fieldQ2;
component->in1.fieldZ1 = msg->fieldZ1;
component->in1.fieldZ2 = msg->fieldZ2;
topic1Callback_wasCalled = true;
}
void publishtopic2Publisher(){
struct_msgs::tests_structs_BasicStruct tmpMsg;
tmpMsg.fieldB1 = component->out1.fieldB1;
......@@ -42,10 +58,11 @@ class RosAdapter_tests_msg_basicStructComp: public IAdapter_tests_msg_basicStruc
tmpMsg.fieldZ2 = component->out1.fieldZ2;
topic2Publisher.publish(tmpMsg);
}
void tick(){
publishtopic2Publisher();
}
};
void tick(){
topic1Callback_wasCalled = false;
publishtopic2Publisher();
}
};
\ No newline at end of file
......@@ -10,6 +10,11 @@
class RosAdapter_tests_msg_basicTypesComp: public IAdapter_tests_msg_basicTypesComp{
tests_msg_basicTypesComp* component;
bool topic7Callback_wasCalled;
bool topic8Callback_wasCalled;
bool topic9Callback_wasCalled;
ros::Subscriber topic7Subscriber;
ros::Subscriber topic8Subscriber;
ros::Subscriber topic9Subscriber;
......@@ -24,6 +29,9 @@ class RosAdapter_tests_msg_basicTypesComp: public IAdapter_tests_msg_basicTypesC
void init(tests_msg_basicTypesComp* comp){
this->component = comp;
topic7Callback_wasCalled = false;
topic8Callback_wasCalled = false;
topic9Callback_wasCalled = false;
char* tmp = strdup("");
int i = 0;
ros::init(i, &tmp, "RosAdapter_tests_msg_basicTypesComp_node");
......@@ -40,20 +48,27 @@ class RosAdapter_tests_msg_basicTypesComp: public IAdapter_tests_msg_basicTypesC
ros::spin();
}
bool hasReceivedNewData() {
return true && topic7Callback_wasCalled && topic8Callback_wasCalled && topic9Callback_wasCalled;
}
void topic7Callback(const std_msgs::Float64::ConstPtr& msg){
component->inQ = msg->data;
topic7Callback_wasCalled = true;
}
void topic8Callback(const std_msgs::Int32::ConstPtr& msg){
component->inZ = msg->data;
topic8Callback_wasCalled = true;
}
void topic9Callback(const std_msgs::Bool::ConstPtr& msg){
component->inB = msg->data;
topic9Callback_wasCalled = true;
}
void publishtopic7Publisher(){
......@@ -73,6 +88,10 @@ class RosAdapter_tests_msg_basicTypesComp: public IAdapter_tests_msg_basicTypesC
}
void tick(){
topic7Callback_wasCalled = false;
topic8Callback_wasCalled = false;
topic9Callback_wasCalled = false;
publishtopic7Publisher();
publishtopic8Publisher();
publishtopic9Publisher();
......
......@@ -5,8 +5,13 @@
#include <ros/ros.h>
#include <automated_driving_msgs/StampedFloat64.h>
#include <rosgraph_msgs/Clock.h>
class RosAdapter_tests_a_compA: public IAdapter_tests_a_compA{
tests_a_compA* component;
bool _clockCallback_wasCalled;
ros::Subscriber _clockSubscriber;
ros::Publisher _echoPublisher;
......@@ -17,19 +22,28 @@ class RosAdapter_tests_a_compA: public IAdapter_tests_a_compA{
void init(tests_a_compA* comp){
this->component = comp;
_clockCallback_wasCalled = false;
char* tmp = strdup("");
int i = 0;
ros::init(i, &tmp, "RosAdapter_tests_a_compA_node");
ros::NodeHandle node_handle = ros::NodeHandle();
_clockSubscriber = node_handle.subscribe("/clock", 5, &RosAdapter_tests_a_compA::_clockCallback, this, ros::TransportHints().tcpNoDelay());
_echoPublisher = node_handle.advertise<automated_driving_msgs::StampedFloat64>("/echo",5);
ros::spin();
}
void _clockCallback(const rosgraph_msgs::Clock::ConstPtr& msg){
component->rosIn = msg->clock.toSec();
}
bool hasReceivedNewData() {
return true && _clockCallback_wasCalled;
}
void _clockCallback(const rosgraph_msgs::Clock::ConstPtr& msg){
component->rosIn = msg->clock.toSec();
_clockCallback_wasCalled = true;
}
void publish_echoPublisher(){
automated_driving_msgs::StampedFloat64 tmpMsg;
tmpMsg.data = component->rosOut;
......@@ -37,7 +51,9 @@ class RosAdapter_tests_a_compA: public IAdapter_tests_a_compA{
}
void tick(){
_clockCallback_wasCalled = false;
publish_echoPublisher();
}
};
};
\ No newline at end of file
......@@ -7,7 +7,11 @@
#include <rosgraph_msgs/Clock.h>
class RosAdapter_tests_a_compA: public IAdapter_tests_a_compA{
tests_a_compA* component;
bool _clockCallback_wasCalled;
ros::Subscriber _clockSubscriber;
ros::Publisher _echoPublisher;
......@@ -15,22 +19,31 @@ class RosAdapter_tests_a_compA: public IAdapter_tests_a_compA{
RosAdapter_tests_a_compA(){
}
void init(tests_a_compA* comp){
this->component = comp;
_clockCallback_wasCalled = false;
char* tmp = strdup("");
int i = 0;
ros::init(i, &tmp, "RosAdapter_tests_a_compA_node");
ros::NodeHandle node_handle = ros::NodeHandle();
_clockSubscriber = node_handle.subscribe("/clock", 5, &RosAdapter_tests_a_compA::_clockCallback, this, ros::TransportHints().tcpNoDelay());
_echoPublisher = node_handle.advertise<automated_driving_msgs::StampedFloat64>("/echo",5);
ros::spin();
}
void _clockCallback(const rosgraph_msgs::Clock::ConstPtr& msg){
component->rosIn = msg->clock.toSec();
}
bool hasReceivedNewData() {
return true && _clockCallback_wasCalled;
}
void _clockCallback(const rosgraph_msgs::Clock::ConstPtr& msg){
component->rosIn = msg->clock.toSec();
_clockCallback_wasCalled = true;
}
void publish_echoPublisher(){
automated_driving_msgs::StampedFloat64 tmpMsg;
tmpMsg.data = component->rosOut;
......@@ -38,7 +51,9 @@ class RosAdapter_tests_a_compA: public IAdapter_tests_a_compA{
}
void tick(){
_clockCallback_wasCalled = false;
publish_echoPublisher();
}
};
};
\ No newline at end of file
......@@ -4,8 +4,13 @@
#include "tests_a_compB.h"
#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/float64.hpp>
class RosAdapter_tests_a_compB: public IAdapter_tests_a_compB{
tests_a_compB* component;
bool _clockCallback_wasCalled;
rclcpp::Subscription<std_msgs::msg::Float64>::SharedPtr _clockSubscriber;
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr _echoPublisher;
......@@ -13,22 +18,31 @@ class RosAdapter_tests_a_compB: public IAdapter_tests_a_compB{
RosAdapter_tests_a_compB(){
}
void init(tests_a_compB* comp){
this->component = comp;
_clockCallback_wasCalled = false;
char* tmp = strdup("");
int i = 1;
rclcpp::init(i, &tmp);
auto node_handle = rclcpp::Node::make_shared("RosAdapter_tests_a_compB");
_clockSubscriber = node_handle->create_subscription<std_msgs::msg::Float64>("/clock", std::bind(&RosAdapter_tests_a_compB::_clockCallback, this, std::placeholders::_1));
_echoPublisher = node_handle->create_publisher<std_msgs::msg::Float64>("/echo");
rclcpp::spin(node_handle);
}
void _clockCallback(const std_msgs::msg::Float64::SharedPtr msg){
component->rosIn = msg->data;
}
bool hasReceivedNewData() {
return true && _clockCallback_wasCalled;
}
void _clockCallback(const std_msgs::msg::Float64::SharedPtr msg){
component->rosIn = msg->data;
_clockCallback_wasCalled = true;
}
void publish_echoPublisher(){
std_msgs::msg::Float64 tmpMsg;
tmpMsg.data = component->rosOut;
......@@ -36,7 +50,9 @@ class RosAdapter_tests_a_compB: public IAdapter_tests_a_compB{
}
void tick(){
_clockCallback_wasCalled = false;
publish_echoPublisher();
}
};
};
\ No newline at end of file
......@@ -10,6 +10,10 @@
class RosAdapter_tests_structs_matrixTypesComp: public IAdapter_tests_structs_matrixTypesComp{
tests_structs_matrixTypesComp* component;
bool _name1Callback_wasCalled;
bool _name2Callback_wasCalled;
ros::Subscriber _name1Subscriber;
ros::Subscriber _name2Subscriber;
ros::Publisher _name3Publisher;
......@@ -22,6 +26,8 @@ class RosAdapter_tests_structs_matrixTypesComp: public IAdapter_tests_structs_ma
void init(tests_structs_matrixTypesComp* comp){
this->component = comp;
_name1Callback_wasCalled = false;
_name2Callback_wasCalled = false;
char* tmp = strdup("");
int i = 0;
ros::init(i, &tmp, "RosAdapter_tests_structs_matrixTypesComp_node");
......@@ -36,6 +42,10 @@ class RosAdapter_tests_structs_matrixTypesComp: public IAdapter_tests_structs_ma
ros::spin();
}
bool hasReceivedNewData() {
return true && _name1Callback_wasCalled && _name2Callback_wasCalled;
}
void _name1Callback(const std_msgs::Float64MultiArray::ConstPtr& msg){
int counter = 0;
......@@ -55,6 +65,7 @@ class RosAdapter_tests_structs_matrixTypesComp: public IAdapter_tests_structs_ma
}
_name1Callback_wasCalled = true;
}
void _name2Callback(const std_msgs::ByteMultiArray::ConstPtr& msg){
......@@ -75,6 +86,7 @@ class RosAdapter_tests_structs_matrixTypesComp: public IAdapter_tests_structs_ma
}
_name2Callback_wasCalled = true;
}
void publish_name3Publisher(){
......@@ -105,6 +117,9 @@ class RosAdapter_tests_structs_matrixTypesComp: public IAdapter_tests_structs_ma
}
void tick(){
_name1Callback_wasCalled = false;
_name2Callback_wasCalled = false;
publish_name3Publisher();
publish_name4Publisher();
}
......
......@@ -4,8 +4,13 @@
#include "tests_msg_multiNestedStructComp.h"
#include <ros/ros.h>
#include <struct_msgs/tests_structs_MultiNestedStruct.h>
class RosAdapter_tests_msg_multiNestedStructComp: public IAdapter_tests_msg_multiNestedStructComp{
tests_msg_multiNestedStructComp* component;
bool topic5Callback_wasCalled;
ros::Subscriber topic5Subscriber;
ros::Publisher topic6Publisher;
......@@ -16,50 +21,61 @@ class RosAdapter_tests_msg_multiNestedStructComp: public IAdapter_tests_msg_mult
void init(tests_msg_multiNestedStructComp* comp){
this->component = comp;
topic5Callback_wasCalled = false;
char* tmp = strdup("");
int i = 0;
ros::init(i, &tmp, "RosAdapter_tests_msg_multiNestedStructComp_node");
ros::NodeHandle node_handle = ros::NodeHandle();
topic5Subscriber = node_handle.subscribe("topic5", 5, &RosAdapter_tests_msg_multiNestedStructComp::topic5Callback, this, ros::TransportHints().tcpNoDelay());
topic6Publisher = node_handle.advertise<struct_msgs::tests_structs_MultiNestedStruct>("topic6",5);
ros::spin();
}
void topic5Callback(const struct_msgs::tests_structs_MultiNestedStruct::ConstPtr& msg){
component->inMultiNested.fieldMultiNested1.fieldB = msg->fieldMultiNested1.fieldB;
component->inMultiNested.fieldMultiNested1.fieldNested1.fieldB1 = msg->fieldMultiNested1.fieldNested1.fieldB1;
component->inMultiNested.fieldMultiNested1.fieldNested1.fieldQ1 = msg->fieldMultiNested1.fieldNested1.fieldQ1;
component->inMultiNested.fieldMultiNested1.fieldNested1.fieldQ2 = msg->fieldMultiNested1.fieldNested1.fieldQ2;
component->inMultiNested.fieldMultiNested1.fieldNested1.fieldZ1 = msg->fieldMultiNested1.fieldNested1.fieldZ1;
component->inMultiNested.fieldMultiNested1.fieldNested1.fieldZ2 = msg->fieldMultiNested1.fieldNested1.fieldZ2;
component->inMultiNested.fieldMultiNested1.fieldNested2.fieldB1 = msg->fieldMultiNested1.fieldNested2.fieldB1;