123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include <gtest/gtest.h>
- #include <json.hpp>
- #include <math.h>
- #include <thread>
- #include <boost/process.hpp>
- #include <iostream>
- #if (defined (WIN32))
- #include <Windows.h>
- #endif
- #include <zmq.hpp>
- #include "zhelpers.hpp"
- using namespace boost::process;
- namespace TEST_SERVER{
- class testClient : public ::testing::Test {
- public:
- child _server;
-
- testClient() {
- // initialization code here
- }
- void SetUp() {
- std::cout << "Launching: " << SERVER_EXE << std::endl;
- _server = child(SERVER_EXE);
- // code here will execute just before the test ensues
- }
- void TearDown() {
- // code here will be called just after the test completes
- // ok to through exceptions from here if need be
- }
- };
- TEST_F(testClient, send_unchangin_request){
- zmq::context_t context(1);
- zmq::socket_t requester(context, zmq::socket_type::req);
- zmq::socket_t subscriber(context, zmq::socket_type::sub);
- requester.connect("tcp://localhost:5555");
- subscriber.connect("tcp://localhost:5556");
- std::string stopic = "CHANGED";
- subscriber.setsockopt(ZMQ_SUBSCRIBE, stopic.c_str(), stopic.length()); // Subscribe to any topic you want here
- for (int request = 0; request < 10; request++) {
- json jmsg;
- jmsg["changed"] = "gui";
- s_send(requester, std::string(jmsg.dump()));
-
- /*
- std::string string = s_recv(requester);
- std::cout << "Received reply " << request
- << " [" << string << "]" << std::endl;
- //*/
- // Read envelope with address
- while (true) {
- std::string address = s_recv(subscriber);
- // Read message contents
- std::string contents = s_recv(subscriber);
- std::cout << "[" << address << "] " << contents << std::endl;
- }
-
- }
- }
- //*/
- }
|