tests/gtests/radio.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 <mm_core_msgs/string.hpp>
14 #include "../../../include/mm_radio/radio.hpp"
15 #include "../../../include/mm_radio/publisher.hpp"
16 #include "../../../include/mm_radio/subscriber.hpp"
17 
18 /*****************************************************************************
19  ** Namespace
20  *****************************************************************************/
21 
22 using namespace mm_radio;
23 
24 /*****************************************************************************
25 ** Registrations
26 *****************************************************************************/
27 
28 // We use 1000's by convention for test packet id's
29 enum {
30  TestPubSub = 9990,
31 };
32 
33 MM_REGISTER_PACKET_INFO(TestPubSub, std::string, "Foo");
34 
35 struct Foo {
36  void foo_cb(std::string msg) {
37  foo_msg = msg;
38  }
39  std::string foo_msg;
40 };
41 /*****************************************************************************
42 ** Tests
43 *****************************************************************************/
44 
45 TEST(mm_radio, pubsub) {
46  Foo old_timer_foo, old_man_foo;
47  const std::string inproc_address = "inproc://radio";
48  Radio::startServer("oldman", inproc_address);
49  Radio::startClient("oldtimer", inproc_address);
50  Subscriber<TestPubSub, std::string> oldtimer_subscriber("oldtimer", &Foo::foo_cb, old_timer_foo);
51  Subscriber<TestPubSub, std::string> oldman_subscriber("oldman", &Foo::foo_cb, old_man_foo);
52  Publisher oldtimer_publisher("oldtimer");
53  Publisher oldman_publisher("oldman");
54  ecl::MilliSleep()(200); // let the connection establish itself
55  oldtimer_publisher.publish(TestPubSub, std::string("hey old man"));
56  oldman_publisher.publish(TestPubSub, std::string("aye carumba"));
57  ecl::MilliSleep()(500);
58  EXPECT_EQ(std::string("hey old man"), old_man_foo.foo_msg);
59  EXPECT_EQ(std::string("aye carumba"), old_timer_foo.foo_msg);
61 }
62 
63 int main(int argc, char **argv)
64 {
65  testing::InitGoogleTest(&argc,argv);
66  return RUN_ALL_TESTS();
67 }
TEST(mm_radio, pubsub)
static void shutdown()
Definition: lib/radio.cpp:273
void publish(const unsigned int &id, const T &msg)
MM_REGISTER_PACKET_INFO(TestPubSub, std::string,"Foo")
std::string foo_msg
void foo_cb(std::string msg)
static void startClient(const std::string &name, const std::string &url, const mm_messages::Verbosity::Level &verbosity=mm_messages::Verbosity::QUIET)
Pre-establish named connections for a client.
Definition: lib/radio.cpp:234
static void startServer(const std::string &name, const std::string &url, const mm_messages::Verbosity::Level &verbosity=mm_messages::Verbosity::QUIET)
Pre-establish named connections for a server.
Definition: lib/radio.cpp:212
int main(int argc, char **argv)


mm_radio
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:52:16