radio.cpp
Go to the documentation of this file.
00001 
00006 /*****************************************************************************
00007 ** Includes
00008 *****************************************************************************/
00009 
00010 #include <gtest/gtest.h>
00011 #include <iostream>
00012 #include <ecl/time.hpp>
00013 #include <mm_core_msgs/string.hpp>
00014 #include "../../../include/mm_radio/radio.hpp"
00015 #include "../../../include/mm_radio/publisher.hpp"
00016 #include "../../../include/mm_radio/subscriber.hpp"
00017 
00018 /*****************************************************************************
00019  ** Namespace
00020  *****************************************************************************/
00021 
00022 using namespace mm_radio;
00023 
00024 /*****************************************************************************
00025 ** Registrations
00026 *****************************************************************************/
00027 
00028 // We use 1000's by convention for test packet id's
00029 enum {
00030   TestPubSub = 9990,
00031 };
00032 
00033 MM_REGISTER_PACKET_INFO(TestPubSub, std::string, "Foo");
00034 
00035 struct Foo {
00036   void foo_cb(std::string msg) {
00037     foo_msg = msg;
00038   }
00039   std::string foo_msg;
00040 };
00041 /*****************************************************************************
00042 ** Tests
00043 *****************************************************************************/
00044 
00045 TEST(mm_radio, pubsub) {
00046   Foo old_timer_foo, old_man_foo;
00047   const std::string inproc_address = "inproc://radio";
00048   Radio::startServer("oldman", inproc_address);
00049   Radio::startClient("oldtimer", inproc_address);
00050   Subscriber<TestPubSub, std::string> oldtimer_subscriber("oldtimer", &Foo::foo_cb, old_timer_foo);
00051   Subscriber<TestPubSub, std::string> oldman_subscriber("oldman", &Foo::foo_cb, old_man_foo);
00052   Publisher oldtimer_publisher("oldtimer");
00053   Publisher oldman_publisher("oldman");
00054   ecl::MilliSleep()(200); // let the connection establish itself
00055   oldtimer_publisher.publish(TestPubSub, std::string("hey old man"));
00056   oldman_publisher.publish(TestPubSub, std::string("aye carumba"));
00057   ecl::MilliSleep()(500);
00058   EXPECT_EQ(std::string("hey old man"), old_man_foo.foo_msg);
00059   EXPECT_EQ(std::string("aye carumba"), old_timer_foo.foo_msg);
00060   Radio::shutdown();
00061 }
00062 
00063 int main(int argc, char **argv)
00064 {
00065   testing::InitGoogleTest(&argc,argv);
00066   return RUN_ALL_TESTS();
00067 }


mm_radio
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:13:24