pubsub.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 "../../include/mm_mux_demux/mux.hpp"
00014 #include "../../include/mm_mux_demux/demux.hpp"
00015 #include "../../include/mm_mux_demux/publisher.hpp"
00016 #include "../../include/mm_mux_demux/subscriber.hpp"
00017 #include <mm_core_msgs/string.hpp>
00018 
00019 /*****************************************************************************
00020  ** Namespace
00021  *****************************************************************************/
00022 
00023 using namespace mm_mux_demux;
00024 
00025 /*****************************************************************************
00026 ** Registrations
00027 *****************************************************************************/
00028 
00029 // We use 1000's by convention for test packet id's
00030 enum {
00031   TestPubSub = 9990,
00032 };
00033 
00034 MM_REGISTER_PACKET_INFO(TestPubSub, std::string, "Foo");
00035 
00036 struct Foo {
00037   void foo_cb(std::string msg) {
00038     foo_msg = msg;
00039   }
00040   std::string foo_msg;
00041 };
00042 /*****************************************************************************
00043 ** Tests
00044 *****************************************************************************/
00045 
00046 TEST(MessageMuxDemux,pubsub) {
00047   Foo foo;
00048   mm_mux_demux::MessageMux::start("dude", "ipc:///tmp/pubsub.ipc");
00049   mm_mux_demux::MessageDemux::start("dude", "ipc:///tmp/pubsub.ipc");
00050   mm_mux_demux::Subscriber<TestPubSub, std::string> subscriber("dude", &Foo::foo_cb, foo);
00051   mm_mux_demux::Publisher publisher("dude");
00052   ecl::MilliSleep()(200); // let the connection establish itself
00053   publisher.publish(TestPubSub, std::string("dude"));
00054   ecl::MilliSleep()(500);
00055   EXPECT_EQ(std::string("dude"), foo.foo_msg);
00056   mm_mux_demux::MessageDemux::shutdown("dude");
00057 }
00058 
00059 int main(int argc, char **argv)
00060 {
00061   testing::InitGoogleTest(&argc,argv);
00062   return RUN_ALL_TESTS();
00063 }


mm_mux_demux
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:13:22