Skip to content

Commit

Permalink
Address compile warnings and add unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed Jun 11, 2024
1 parent b1393ec commit f02ac5b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
16 changes: 2 additions & 14 deletions src/v2i-hub/CDASimAdapter/src/CDASimAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,12 @@ namespace CDASimAdapter{
"\nUsing Registration Port : " << std::to_string( simulation_registration_port) <<
" Time Sync Port: " << std::to_string( time_sync_port) << " and V2X Port: " << std::to_string(v2x_port) << std::endl;
if ( connection ) {
if ( sensor_json_file_path.empty()) {
connection.reset(new CDASimConnection( simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
time_sync_port, simulated_interaction_port, v2x_port, location ));
}
else {
connection.reset(new CDASimConnection( simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
connection.reset(new CDASimConnection( simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
time_sync_port, simulated_interaction_port, v2x_port, location, sensor_json_file_path ));
}
}
else {
if ( sensor_json_file_path.empty()) {
connection = std::make_unique<CDASimConnection>(simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
time_sync_port, simulated_interaction_port, v2x_port, location);
}
else {
connection = std::make_unique<CDASimConnection>(simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
connection = std::make_unique<CDASimConnection>(simulation_ip, infrastructure_id, simulation_registration_port, sim_v2x_port, local_ip,
time_sync_port, simulated_interaction_port, v2x_port, location, sensor_json_file_path);
}
}
}
catch (const TmxException &e) {
Expand Down
9 changes: 6 additions & 3 deletions src/v2i-hub/CDASimAdapter/src/include/CDASimConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ namespace CDASimAdapter {
std::shared_ptr<tmx::utils::UdpServer> time_sync_listener;
std::shared_ptr<tmx::utils::UdpServer> sensor_detected_object_listener;

FRIEND_TEST(TestCARMASimulationConnection, get_handshake_json);
FRIEND_TEST(TestCARMASimulationConnection, read_json_file);
FRIEND_TEST(TestCARMASimulationConnection, string_to_json);
FRIEND_TEST(TestCDASimConnection, get_handshake_json);
FRIEND_TEST(TestCDASimConnection, get_handshake_json_no_sensor_config);
FRIEND_TEST(TestCDASimConnection, read_json_file);
FRIEND_TEST(TestCDASimConnection, string_to_json);


};

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace tmx::utils;

namespace CDASimAdapter {

class TestCARMASimulationConnection : public ::testing::Test {
class TestCDASimConnection : public ::testing::Test {
protected:
void SetUp() override {
// Initialize CARMA Simulation connection with (0,0,0) location.
Expand All @@ -35,19 +35,19 @@ namespace CDASimAdapter {


};
TEST_F( TestCARMASimulationConnection, initialize) {
TEST_F( TestCDASimConnection, initialize) {
ASSERT_FALSE(connection->is_connected());
}

TEST_F( TestCARMASimulationConnection, forward_message) {
TEST_F( TestCDASimConnection, forward_message) {
std::shared_ptr<MockUpdClient> client = std::make_shared<MockUpdClient>();
std::string test_message = "message";
EXPECT_CALL( *client, Send(test_message) ).Times(2).WillOnce(testing::DoAll(Return(-1))).WillRepeatedly(testing::DoAll(Return(test_message.size())));
ASSERT_THROW(connection->forward_message(test_message, client), UdpClientRuntimeError);
connection->forward_message(test_message, client);
}

TEST_F( TestCARMASimulationConnection, forward_message_invalid ) {
TEST_F( TestCDASimConnection, forward_message_invalid ) {
std::shared_ptr<MockUpdClient> client = std::make_shared<MockUpdClient>();
std::string test_message = "";
// ASSERT that we never call Send message.
Expand All @@ -59,11 +59,11 @@ namespace CDASimAdapter {
connection->forward_message(test_message, client);
}

TEST_F( TestCARMASimulationConnection, consume_msg){
TEST_F( TestCDASimConnection, consume_msg){

std::shared_ptr<MockUpdServer> server = std::make_shared<MockUpdServer>();
char *msg_data = new char();
char *test_string = "Test Message";
char test_string[] = "Test Message";
EXPECT_CALL( *server, TimedReceive(_, _, _) ).Times(2).
WillOnce(testing::DoAll(Return(-1))).
WillRepeatedly( testing::DoAll( SetArrayArgument<0>(test_string, test_string + strlen(test_string) + 1),Return(10)));
Expand All @@ -78,11 +78,11 @@ namespace CDASimAdapter {

}

TEST_F( TestCARMASimulationConnection, setup_upd_connection) {
TEST_F( TestCDASimConnection, setup_upd_connection) {
ASSERT_TRUE(connection->setup_udp_connection("127.0.0.1", "127.0.0.1", 4567, 4568, 4569, 4570));
}

TEST_F( TestCARMASimulationConnection, get_handshake_json) {
TEST_F( TestCDASimConnection, get_handshake_json) {
Point location;
location.X = 1000;
location.Y = 38.955;
Expand All @@ -91,23 +91,34 @@ namespace CDASimAdapter {
in_strm.open(sensors_file_path, std::ifstream::binary);
if(in_strm.is_open())
{
ASSERT_EQ(connection->get_handshake_json("4566", "127.0.0.1", 4567, 4568, 4569, location),
EXPECT_EQ(connection->get_handshake_json("4566", "127.0.0.1", 4567, 4568, 4569, location),
"{\n \"infrastructureId\" : \"4566\",\n \"location\" : {\n \"x\" : 1000.0,\n \"y\" : 38.954999999999998,\n \"z\" : -77.149000000000001\n },\n \"rxMessageIpAddress\" : \"127.0.0.1\",\n \"rxMessagePort\" : 4569,\n \"sensors\" : [\n {\n \"location\" : {\n \"x\" : 0.0,\n \"y\" : 0.0,\n \"z\" : 0.0\n },\n \"orientation\" : {\n \"pitch\" : 0.0,\n \"roll\" : 0.0,\n \"yaw\" : 0.0\n },\n \"sensorId\" : \"SomeID\",\n \"type\" : \"SemanticLidar\"\n },\n {\n \"location\" : {\n \"x\" : 1.0,\n \"y\" : 2.0,\n \"z\" : 0.0\n },\n \"orientation\" : {\n \"pitch\" : 0.0,\n \"roll\" : 0.0,\n \"yaw\" : 23.0\n },\n \"sensorId\" : \"SomeID2\",\n \"type\" : \"SemanticLidar\"\n }\n ],\n \"simulatedInteractionPort\" : 4568,\n \"timeSyncPort\" : 4567\n}\n");
}
}

TEST_F( TestCARMASimulationConnection, carma_simulation_handshake) {
TEST_F( TestCDASimConnection, get_handshake_json_no_sensor_config) {
Point location;
location.X = 1000;
location.Y = 38.955;
location.Z = -77.149;
connection.reset(new CDASimConnection("127.0.0.1", "1212", 4567, 4678, "127.0.0.1", 1213, 1214, 1215, location));
// Test method when sensors_file_path is empty
EXPECT_EQ(connection->get_handshake_json("4566", "127.0.0.1", 4567, 4568, 4569, location),
"{\n \"infrastructureId\" : \"4566\",\n \"location\" : {\n \"x\" : 1000.0,\n \"y\" : 38.954999999999998,\n \"z\" : -77.149000000000001\n },\n \"rxMessageIpAddress\" : \"127.0.0.1\",\n \"rxMessagePort\" : 4569,\n \"simulatedInteractionPort\" : 4568,\n \"timeSyncPort\" : 4567\n}\n");
}

TEST_F( TestCDASimConnection, carma_simulation_handshake) {
Point location;
// UDP creation error
ASSERT_FALSE(connection->carma_simulation_handshake("", "45", NULL,
EXPECT_FALSE(connection->carma_simulation_handshake("", "45", 0,
"", 45, 45, 45, location));
}

TEST_F(TestCARMASimulationConnection, connect) {
ASSERT_TRUE(connection->connect());
TEST_F(TestCDASimConnection, connect) {
EXPECT_TRUE(connection->connect());
}

TEST_F(TestCARMASimulationConnection, read_json_file)
TEST_F(TestCDASimConnection, read_json_file)
{
auto sensorJsonV = connection->read_json_file("Invalid_file_path" );
ASSERT_TRUE(sensorJsonV.empty());
Expand All @@ -120,7 +131,7 @@ namespace CDASimAdapter {
}
}

TEST_F(TestCARMASimulationConnection, string_to_json)
TEST_F(TestCDASimConnection, string_to_json)
{
auto sensorJsonV = connection->string_to_json("Invalid Json");
ASSERT_TRUE(sensorJsonV.empty());
Expand Down

0 comments on commit f02ac5b

Please sign in to comment.