Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero committed Feb 2, 2024
1 parent 7b28cdd commit f5cc6c9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
34 changes: 33 additions & 1 deletion src/cmd/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ bool srvEcho(const msgs::Int32 &_req, msgs::Int32 &_rep)
return true;
}

//////////////////////////////////////////////////
/// \brief Provide a one-way service.
void srvOneway(const msgs::StringMsg &_msg)
{
g_topicCBStr = _msg.data();
}

//////////////////////////////////////////////////
/// \brief Topic callback
void topicCB(const msgs::StringMsg &_msg)
Expand Down Expand Up @@ -452,7 +459,7 @@ TEST(gzTest, TopicPublish)
}

//////////////////////////////////////////////////
/// \brief Check 'gz service -r' to request a service.
/// \brief Check 'gz service -r' to request a two-way service.
TEST(gzTest, ServiceRequest)
{
transport::Node node;
Expand All @@ -475,6 +482,31 @@ TEST(gzTest, ServiceRequest)
ASSERT_EQ(output, "data: " + value + "\n\n");
}

//////////////////////////////////////////////////
/// \brief Check 'gz service -r' to request a one-way service.
TEST(gzTest, ServiceOnewayRequest)
{
g_topicCBStr = "bad_value";
transport::Node node;

// Advertise a service.
std::string service = "/oneway";
std::string value = "good_value";
EXPECT_TRUE(node.Advertise(service, srvOneway));

msgs::StringMsg msg;
msg.set_data(value);

// Check the 'gz service -r' command.
std::string gz = std::string(GZ_PATH);
std::string output = custom_exec_str(gz +
" service -s " + service + " --reqtype gz_msgs.Int32 " +
"--req 'data: " + value + "' " + g_gzVersion);

std::this_thread::sleep_for(std::chrono::milliseconds(500));
EXPECT_EQ("good_value", g_topicCBStr);
}

//////////////////////////////////////////////////
/// \brief Check 'gz topic -e' running the publisher on a separate process.
TEST(gzTest, TopicEcho)
Expand Down
1 change: 0 additions & 1 deletion src/cmd/service_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ enum class ServiceCommand
kServiceList,
kServiceInfo,
kServiceReq,
kServiceReqOneway,
};

//////////////////////////////////////////////////
Expand Down

0 comments on commit f5cc6c9

Please sign in to comment.