/**
    By default RouteConfig to route to anyone local connection configured 
    to receive the data
 */
TEST_F(LocalTransportTest, Transmit)
{
    //////////////////////////
    // setup
    TestMessage myMsg;
    myMsg.data = 0x1234;
    Link myLink;
    MessageHandlerCollection handlers;
    handlers.Add(TEST_PROTOCOL::CRC, &TEST_PROTOCOL::CreateMessage, this, &MsgReceive);    
    LocalTransport transport(handlers);

    //////////////////////////
    // Method to test
    transport.Transmit(myLink, &myMsg);    

    //////////////////////////
    // test results

    // MsgReceived should have been called 1 time
    ASSERT_EQ(1, received.size());
    // same message
    ASSERT_EQ(myMsg.GetCode(), received[0]->GetCode());

    // duplicate copy
    ASSERT_NE(&myMsg, received[0]);

    // Pooled message, check we only have 1 ref
    ASSERT_EQ(2, received[0]->AddRef());
    ASSERT_EQ(1, received[0]->Release());
    ASSERT_EQ(0, received[0]->Release());
}
Exemple #2
0
void Echo::handle_test_message(const TestMessage& msg)
{
    std::cout << msg.DebugString() << std::endl;
    TestMessage msgout = msg;
    static int a = 0;
    static int b = 0;
    msgout.set_a(a++);
    msgout.set_b(b++);
    publish(msgout, "testgroup");
}
Exemple #3
0
void InterConnection::test() 
{
  TestMessage* t;
  for (ushort i = 0; i < rPolicy->getnRouters(); i++) {
    t = tmpool.out();
    t->init(i, PortID_t(100), 0, PortID_t(101), Message::RCV_AND_PASS);
    t->setSize(100);
    routers[i]->launchMsg(t);
    t = tmpool.out();
    t->init(i, PortID_t(100), 0, PortID_t(101), Message::RCV);
    t->setSize(100);
    routers[i]->launchMsg(t);
  }
}
void ObstacleAvoidanceController::process_messages() {
	cout << "ObstacleAvoidanceController process messages" << endl;
	MessageBuffer* sub_buf = Subscriber::getBuffer();
	TestMessage* tm = (TestMessage*) sub_buf->remove_head();
	cout << "I received a message from " << tm->publisher() << " with counter " << tm->counter() << endl;
	tm->set_counter(tm->counter() + 1);
	tm->set_topic("behavior");
	publish(tm);
}
void LocController::process_messages()
{
	MessageBuffer* sub_buf = Subscriber::getBuffer();
	TestMessage* tm = (TestMessage*)sub_buf->remove_head();
	cout << "I received a message from " << tm->publisher() << " with counter " << tm->counter() << endl;
	tm->set_counter(tm->counter() + 1);
	tm->set_topic("sensors");
	publish(tm);
}
int testfun(void *par,char* data,int data_size)
{
	CWinTest* Hand=(CWinTest*)par;
	TestMessage t;
	if(!t.ParseFromArray(data,data_size))
	{
		return -1;
	}
	uint32_t curid= t.guid();
	
	if(curid==Hand->alreadyGuid+1)
	{
		Hand->alreadyGuid=curid;
	}
	else
	{
		if(curid > Hand->alreadyGuid+1)
		{
			Hand->lostpacketCount=Hand->lostpacketCount+curid-Hand->alreadyGuid+1;
			Hand->alreadyGuid=curid;
		}
		else
		{
			if(Hand->lostpacketCount!=0)
			{
				--Hand->lostpacketCount;
				++Hand->outOrderCount;
			}
		}
	}
	
	t.set_guid(++Hand->writeGuid);
	SendPacket spkt;
	Hand->packet.makePacket(&t,1,spkt);
	Hand->Write(spkt.data,spkt.size);
	return data_size;
}
Exemple #7
0
bool TestMessageExchange::fromJson(const Variant& json) {
  if (json.isNull()) {
    printf("Not a valid JSON\n");
    return false;
  }
  if (!json.isArray()) {
    printf("Invalid format of the message exchange\n");
    return false;
  }
  for (ArrayIter it(json.toArray()); it; ++it) {
    if (!it.first().isInteger()) {
      printf("Invalid format of the message exchange\n");
      return false;
    }
    int message_key = it.first().toInt32();
    TestMessage message;
    if (!message.fromJson(it.second())) {
      printf("Invalid message #%d\n", message_key);
      return false;
    }
    m_messages.push_back(message);
  }
  return true;
}
Exemple #8
0
#include <snake/message/TestMessage.h>

#include <catch.hpp>

#include <iostream>

using namespace snake;

TEST_CASE("test_message_generator_with_test_message", "[TestMessage][Message][MessageGenerator][Proto][Protobuf]")
{
	TestMessage msg1{}, msg2{};
	REQUIRE(msg1.type() == MessageType::TEST_MESSAGE);
	
	MessageVersion version;
	REQUIRE(version.major_version == MESSAGE_MAJOR_VERSION);
	REQUIRE(version.minor_version == MESSAGE_MINOR_VERSION);
	REQUIRE(version.minimal_major_version == MESSAGE_MINIMAL_MAJOR_VERSION);
	REQUIRE(version.minimal_minor_version == MESSAGE_MINIMAL_MINOR_VERSION);
	std::string s{};
	REQUIRE(version.serialize(s));
	MessageVersion v2;
	REQUIRE(v2.deserialize(s));
	REQUIRE(version.major_version == v2.major_version);
	REQUIRE(version.minor_version == v2.minor_version);
	REQUIRE(version.minimal_major_version == v2.minimal_major_version);
	REQUIRE(version.minimal_minor_version == v2.minimal_minor_version);

	msg1.group.push_back(version);
	msg1.group.push_back(v2);
	msg1.msg = v2;
	msg1.types.push_back(MessageType::TEST_MESSAGE);
/**
* Reply example
*/
int main()
{
    // Set up the network binding
    zmq::context_t zmqContext(1);
    zmq::socket_t * pZmqSocket = new zmq::socket_t(zmqContext, ZMQ_REP);
    std::string listenAddress = "tcp://*:5555";
    pZmqSocket->bind(listenAddress.c_str());
    while (1)
    {
        if (pZmqSocket->connected())
        {
            // Create a REQUEST message pointer
            zmq::message_t * pZmqMsgIn = new zmq::message_t();

            char * buffer = nullptr;

            // Receive the REQUEST message
            {
                try
                {
                    if (pZmqSocket->recv(pZmqMsgIn))
                    {
                        std::cout << "REQUEST Message Received" << std::endl;

                        buffer = (char *)(pZmqMsgIn->data());
                        std::istringstream iss(buffer);

                        TestMessage recvData = TestMessage();
                        recvData.deserialize(iss);

                        printData(recvData);

                    }
                    else
                    {
                        std::cout << "REQUEST Message NOT Received" << std::endl;
                    }
                }
                catch (std::exception& e)
                {
                    std::cerr << "Exception caught during socket.recv(): " << e.what() << std::endl;
                }


            }

            // Create the REPLY message and copy data from the REQUEST message
            zmq::message_t * pZmqMsgOut = new zmq::message_t(sizeof(pZmqMsgIn->data()));
            memcpy((void *)pZmqMsgOut->data(), pZmqMsgIn->data(), sizeof(pZmqMsgIn->data()));

            // Send the REPLY message
            {
                try
                {
                    if (pZmqSocket->send(*pZmqMsgOut))
                    {
                        std::cout << "REPLY Message Sent" << std::endl;
                    }
                    else
                    {
                        std::cerr << "REPLY Message NOT Sent." << std::endl;
                    }
                }
                catch (std::exception& e)
                {
                    std::cerr << "Exception caught during socket.send(): " << e.what() << std::endl;
                }
            }

            delete pZmqMsgIn;
        }
    }

    delete pZmqSocket;

    return 0;
}