Skip to content

Commit

Permalink
updade code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-du-car committed Nov 14, 2023
1 parent be3b634 commit f169b5d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,13 @@ namespace RSUHealthMonitor
void RSUHealthMonitorPlugin::BroadcastRSUStatus(const Json::Value &rsuStatusJson)
{
// Broadcast the RSU status info when there are RSU responses.
if (!rsuStatusJson.empty())
if (!rsuStatusJson.empty() && _rsuWorker)
{
vector<string> rsuStatusFields;
for (auto const &field : rsuStatusJson.getMemberNames())
{
rsuStatusFields.push_back(field);
}
auto rsuStatusFields = _rsuWorker->getJsonKeys(rsuStatusJson);
auto configTbl = _rsuWorker->GetRSUStatusConfig(_rsuMibVersion);

// Only broadcast RSU status when all required fields are present.
if (_rsuWorker && _rsuWorker->validateAllRequiredFieldsPresent(configTbl, rsuStatusFields))
if (_rsuWorker->validateAllRequiredFieldsPresent(configTbl, rsuStatusFields))
{
auto sendRsuStatusMsg = _rsuWorker->convertJsonToTMXMsg(rsuStatusJson);
BroadcastMessage(sendRsuStatusMsg, RSUHealthMonitorPlugin::GetName());
Expand Down
26 changes: 26 additions & 0 deletions src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,30 @@ namespace RSUHealthMonitor
rsuStatusMsg.set_contents(json_str);
return rsuStatusMsg;
}

vector<string> RSUHealthMonitorWorker::getJsonKeys(const Json::Value &json) const
{
vector<string> keys;
if (json.isArray())
{
for (auto itr = json.begin(); itr != json.end(); itr++)
{
if (itr->isObject())
{
for (auto const &field : itr->getMemberNames())
{
keys.push_back(field);
}
}
}
}
else if (json.isObject())
{
for (auto const &field : json.getMemberNames())
{
keys.push_back(field);
}
}
return keys;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ namespace RSUHealthMonitor
*/
Json::Value populateJson(const string &field, const snmp_response_obj &response) const;

/**
* @brief List the keys from the input Json values
* @param Json Input JSON values
* @return vector of key strings
*/
vector<string> getJsonKeys(const Json::Value &json) const;

// Delete move constructor
RSUHealthMonitorWorker(RSUHealthMonitorWorker &&worker) = delete;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ namespace RSUHealthMonitor
string json_str = fasterWirter.write(rsuStatusJson);
string expectedStr = "[{\"rsuGpsOutputString\":\"$GPGGA,142440.00,3857.3065,N,07708.9734,W,2,18,0.65,86.18,M,-34.722,M,,*62\",\"rsuGpsOutputStringLatitude\":38.955108330000002,\"rsuGpsOutputStringLongitude\":-77.149556669999996},{\"rsuMode\":4}]\n";
ASSERT_EQ(expectedStr, json_str);
ASSERT_EQ(4, _rsuWorker->getJsonKeys(rsuStatusJson).size());
ASSERT_EQ(1, _rsuWorker->getJsonKeys(json).size());
}

}

0 comments on commit f169b5d

Please sign in to comment.