test_Server.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <gtest/gtest.h>
  2. #include <json.hpp>
  3. #include <math.h>
  4. #include <thread>
  5. #include <boost/process.hpp>
  6. #include <iostream>
  7. #if (defined (WIN32))
  8. #include <Windows.h>
  9. #endif
  10. #include <zmq.hpp>
  11. #include "zhelpers.hpp"
  12. using namespace boost::process;
  13. namespace TEST_SERVER{
  14. class testClient : public ::testing::Test {
  15. public:
  16. child _server;
  17. testClient() {
  18. // initialization code here
  19. }
  20. void SetUp() {
  21. std::cout << "Launching: " << SERVER_EXE << std::endl;
  22. _server = child(SERVER_EXE);
  23. // code here will execute just before the test ensues
  24. }
  25. void TearDown() {
  26. // code here will be called just after the test completes
  27. // ok to through exceptions from here if need be
  28. }
  29. };
  30. TEST_F(testClient, send_unchangin_request){
  31. zmq::context_t context(1);
  32. zmq::socket_t requester(context, zmq::socket_type::req);
  33. zmq::socket_t subscriber(context, zmq::socket_type::sub);
  34. requester.connect("tcp://localhost:5555");
  35. subscriber.connect("tcp://localhost:5556");
  36. std::string stopic = "CHANGED";
  37. subscriber.setsockopt(ZMQ_SUBSCRIBE, stopic.c_str(), stopic.length()); // Subscribe to any topic you want here
  38. for (int request = 0; request < 10; request++) {
  39. json jmsg;
  40. jmsg["changed"] = "gui";
  41. s_send(requester, std::string(jmsg.dump()));
  42. /*
  43. std::string string = s_recv(requester);
  44. std::cout << "Received reply " << request
  45. << " [" << string << "]" << std::endl;
  46. //*/
  47. // Read envelope with address
  48. while (true) {
  49. std::string address = s_recv(subscriber);
  50. // Read message contents
  51. std::string contents = s_recv(subscriber);
  52. std::cout << "[" << address << "] " << contents << std::endl;
  53. }
  54. }
  55. }
  56. //*/
  57. }