// First let's open the socket with the chosen ADDRESS and PORT
SRTMinorServoSocket::getInstance(ADDRESS,PORT);
try
{
// Let's try to instance another socket on a different port
SRTMinorServoSocket::getInstance(ADDRESS,PORT+1);
}
catch(ComponentErrors::SocketErrorExImpl&ex)
{
if(ex.getData("Reason")==std::string("Cannot connect the socket.").c_str())
{
FAIL()<<"Socket failed to connect. Check if the simulator or the hardware can be reached."<<std::endl;
return;
}
else
{
// Check if we got the correct exception
EXPECT_EQ(ex.getData("Reason"),std::string("Socket already open on '"+ADDRESS+":"+std::to_string(PORT)+"' . Use getInstance() (no arguments) to retrieve the object.").c_str());
}
}
}
// This test tries to retrieve an instance which has not been generated yet, failing
if(ex.getData("Reason")==std::string("Cannot connect the socket.").c_str())
{
FAIL()<<"Socket failed to connect. Check if the simulator or the hardware can be reached."<<std::endl;
return;
}
else
{
// Check if we got the correct exception
EXPECT_EQ(ex.getData("Reason"),std::string("Socket not yet initialized. Use getInstance(std::string ip_address, int port) to initialize it and retrieve the object.").c_str());
}
}
}
// This test tries to generate an instance using a pair of address and port on which the socket fails to open