00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <gtest/gtest.h>
00033 #include <ros/ros.h>
00034 #include <ros/callback_queue.h>
00035
00036 #include "test_roscpp/TestArray.h"
00037
00038 uint32_t g_pub_count = 0;
00039
00040 void callback(const test_roscpp::TestArrayConstPtr& msg)
00041 {
00042
00043 }
00044
00045 TEST(LoadsOfPublishers, waitForAll)
00046 {
00047 ros::NodeHandle nh;
00048 ros::Subscriber sub = nh.subscribe("test_roscpp/pubsub_test", 1000, callback);
00049
00050 while (sub.getNumPublishers() < g_pub_count)
00051 {
00052 ros::getGlobalCallbackQueue()->callAvailable(ros::WallDuration(0.1));
00053 }
00054
00055 ros::WallDuration(10).sleep();
00056 ros::spinOnce();
00057 ASSERT_EQ(sub.getNumPublishers(), g_pub_count);
00058 }
00059
00060 struct Helper
00061 {
00062 void callback(const test_roscpp::TestArrayConstPtr& msg)
00063 {
00064 alive[(*msg->__connection_header)["callerid"]] = true;
00065 }
00066
00067 std::map<std::string, bool> alive;
00068 };
00069
00070 TEST(LoadsOfPublishers, receiveFromAll)
00071 {
00072 ros::NodeHandle nh;
00073 Helper helper;
00074 ros::Subscriber sub = nh.subscribe("test_roscpp/pubsub_test", 1000, &Helper::callback, &helper);
00075
00076 while (helper.alive.size() < g_pub_count)
00077 {
00078 ros::getGlobalCallbackQueue()->callAvailable(ros::WallDuration(0.1));
00079 }
00080 }
00081
00082 int main(int argc, char** argv)
00083 {
00084 testing::InitGoogleTest(&argc, argv);
00085 ros::init(argc, argv, "loads_of_publishers");
00086
00087 if (argc < 2)
00088 {
00089 ROS_ERROR("Not enough arguments (usage: loads_of_publishers num_publishers)");
00090 return 1;
00091 }
00092
00093 g_pub_count = atoi(argv[1]);
00094
00095 ros::NodeHandle nh;
00096
00097 return RUN_ALL_TESTS();
00098 }