pubsub.cpp
Go to the documentation of this file.
1 
6 /*****************************************************************************
7 ** Includes
8 *****************************************************************************/
9 
10 #include <gtest/gtest.h>
11 #include <iostream>
12 #include <ecl/time.hpp>
13 #include "../../include/mm_mux_demux/mux.hpp"
14 #include "../../include/mm_mux_demux/demux.hpp"
15 #include "../../include/mm_mux_demux/publisher.hpp"
16 #include "../../include/mm_mux_demux/subscriber.hpp"
17 #include <mm_core_msgs/string.hpp>
18 
19 /*****************************************************************************
20  ** Namespace
21  *****************************************************************************/
22 
23 using namespace mm_mux_demux;
24 
25 /*****************************************************************************
26 ** Registrations
27 *****************************************************************************/
28 
29 // We use 1000's by convention for test packet id's
30 enum {
31  TestPubSub = 9990,
32 };
33 
34 MM_REGISTER_PACKET_INFO(TestPubSub, std::string, "Foo");
35 
36 struct Foo {
37  void foo_cb(std::string msg) {
38  foo_msg = msg;
39  }
40  std::string foo_msg;
41 };
42 /*****************************************************************************
43 ** Tests
44 *****************************************************************************/
45 
46 TEST(MessageMuxDemux,pubsub) {
47  Foo foo;
48  mm_mux_demux::MessageMux::start("dude", "ipc:///tmp/pubsub.ipc");
49  mm_mux_demux::MessageDemux::start("dude", "ipc:///tmp/pubsub.ipc");
51  mm_mux_demux::Publisher publisher("dude");
52  ecl::MilliSleep()(200); // let the connection establish itself
53  publisher.publish(TestPubSub, std::string("dude"));
54  ecl::MilliSleep()(500);
55  EXPECT_EQ(std::string("dude"), foo.foo_msg);
57 }
58 
59 int main(int argc, char **argv)
60 {
61  testing::InitGoogleTest(&argc,argv);
62  return RUN_ALL_TESTS();
63 }
Definition: pubsub.cpp:36
void publish(const unsigned int &id, const T &msg)
int main(int argc, char **argv)
Definition: pubsub.cpp:59
static void shutdown()
Definition: demux.cpp:187
static void start(const std::string &name, const std::string &url, const mm_messages::Verbosity::Level &verbosity=mm_messages::Verbosity::QUIET, const bool bind=false)
Definition: demux.cpp:170
std::string foo_msg
Definition: pubsub.cpp:40
MM_REGISTER_PACKET_INFO(TestPubSub, std::string,"Foo")
void foo_cb(std::string msg)
Definition: pubsub.cpp:37
TEST(MessageMuxDemux, pubsub)
Definition: pubsub.cpp:46
static void start(const std::string &name, const std::string &url, const mm_messages::Verbosity::Level &verbosity=mm_messages::Verbosity::QUIET, const bool bind=true)
Pre-establish named connections.
Definition: mux.cpp:107
void foo(std::string data)
Definition: mm_pubsub.cpp:26


mm_mux_demux
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:52:14