Skip to content

Commit

Permalink
Merge branch 'feature/ci-action'
Browse files Browse the repository at this point in the history
  • Loading branch information
EirikKolas committed Oct 20, 2023
2 parents efb8673 + a148d16 commit f2711a2
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 62 deletions.
37 changes: 32 additions & 5 deletions .github/workflows/ci-action.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# From https://github.com/marketplace/actions/ros-2-ci-action
name: CI Action

on:
Expand All @@ -14,16 +15,42 @@ env:


jobs:
unit-test:
ci-action:
runs-on: ubuntu-latest

steps:
- name: Install ROS
- name: Install ROS2 and dependencies
uses: ros-tooling/[email protected]
with:
required-ros-distro: ${{ env.ROS_DISTRO }}
- name: Build and run tests

- name: Build and Run Tests
uses: ros-tooling/[email protected]
id: action_ros_ci_step
with:
package_name: vortex-m3-sonar-driver
target-ros2-distros: ${{ env.ROS_DISTRO }}
package-name: vortex-m3-sonar-driver
target-ros2-distro: ${{ env.ROS_DISTRO }}
colcon-defaults: |
{
"build": {
"mixin": ["coverage-gcc", "coverage-pytest"]
},
"test": {
"mixin": ["coverage-pytest"]
}
}
- name: Upload Code Coverage Info
uses: codecov/[email protected]
with:
# token: ${{ secrets.CODECOV_TOKEN }} # only needed for private repos
files: ros_ws/lcov/total_coverage.info,ros_ws/coveragepy/.coverage
flags: unittests
name: codecov-umbrella

- name: Upload Test Results as Artifact
uses: actions/upload-artifact@v1
with:
name: colcon-logs
path: ${{ steps.action_ros_ci_step.outputs.ros-workspace-directory-name }}/log
if: always() # upload the logs even when the build fails
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if(NOT CMAKE_CXX_STANDARD)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -fopenmp)
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Find dependencies
Expand All @@ -19,15 +19,15 @@ include_directories(include)
# Create executable
add_executable(${PROJECT_NAME}_main
src/main.cpp
src/xml/m3CommandGenerator.cpp
src/xml/m3ResponseParser.cpp
src/api/m3CommandGenerator.cpp
src/api/m3ResponseParser.cpp
)
ament_target_dependencies(${PROJECT_NAME}_main
)

# Install the headers
install(
DIRECTORY include/
DIRECTORY include
DESTINATION include
)

Expand All @@ -44,8 +44,8 @@ if(BUILD_TESTING)
test/XmlCommandGeneratorTest.cpp
test/XmlResponseParserTest.cpp

src/xml/m3CommandGenerator.cpp
src/xml/m3ResponseParser.cpp
src/api/m3CommandGenerator.cpp
src/api/m3ResponseParser.cpp
)
target_include_directories(${PROJECT_NAME}_test PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
5 changes: 5 additions & 0 deletions include/api/api.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

// Header files for the xml library
#include <api/m3CommandGenerator.hpp>
#include <api/m3ResponseParser.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#include <string>

namespace xml {
namespace m3 {
namespace api {
namespace command {

/**
Expand Down Expand Up @@ -102,4 +103,5 @@ std::string startExport();
std::string stopExport();

} // namespace command
} // namespace xml
} // namespace api
} // namespace m3
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <iostream>
#include <string>

namespace xml {
namespace m3 {
namespace api {

/**
* @brief Struct to hold the response from the sonar device
Expand All @@ -26,10 +27,13 @@ std::ostream &operator<<(std::ostream &os, ResponseInfo const &m);
/**
* @brief Parse the response from the sonar device
*
* @param response_input xml string response from the M3 sonar
* @param parsed_response parsed response
* @return int status of the response, see ResponseStatus enum
* @param response xml string response from the M3 sonar
* @return ResponseInfo parsed response
* @throw std::runtime_error if the response is invalid
* @throw std::runtime_error if the response is incomplete
* @throw rapidxml::parse_error if the response is not a valid XML
*/
ResponseInfo parseResponse(const std::string &response);

} // namespace xml
} // namespace api
} // namespace m3
5 changes: 0 additions & 5 deletions include/xml/xml.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <xml/m3CommandGenerator.hpp>
#include <api/m3CommandGenerator.hpp>

namespace xml {
namespace m3 {
namespace api {
namespace command {

std::string connect() { return "<Command>\n<Operation>Connect</Operation>\n</Command>\n"; }
Expand Down Expand Up @@ -38,4 +39,5 @@ std::string startExport() { return "<Command>\n<Operation>Start_Export</Operatio
std::string stopExport() { return "<Command>\n<Operation>Stop_Export</Operation>\n</Command>\n"; }

} // namespace command
} // namespace xml
} // namespace api
} // namespace m3
21 changes: 7 additions & 14 deletions src/xml/m3ResponseParser.cpp → src/api/m3ResponseParser.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#include <iostream>
#include <rapidxml/rapidxml.hpp>
#include <xml/m3ResponseParser.hpp>

namespace xml {

/**
* @brief Parse the response from the sonar device
*
* @param response xml string response from the M3 sonar
* @return ResponseInfo parsed response
* @throw std::runtime_error if the response is invalid
* @throw std::runtime_error if the response is incomplete
* @throw rapidxml::parse_error if the response is not a valid XML
*/
#include <api/m3ResponseParser.hpp>

namespace m3 {
namespace api{

ResponseInfo parseResponse(const std::string &response)
{
rapidxml::xml_document<> doc;
Expand Down Expand Up @@ -53,4 +45,5 @@ std::ostream &operator<<(std::ostream &os, ResponseInfo const &m)
<< "time: " << m.time << '\n';
}

} // namespace xml
} // namespace api
} // namespace m3
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <iostream>
#include <xml/xml.hpp>
#include <api/api.hpp>

int main()
{
Expand All @@ -12,7 +12,7 @@ int main()
<Time>2023-09-28 18:03:21</Time>
</Response>)";

xml::ResponseInfo result = xml::parseResponse(response);
m3::api::ResponseInfo result = m3::api::parseResponse(response);
std::cout << result << std::endl;

return 0;
Expand Down
32 changes: 17 additions & 15 deletions test/XmlCommandGeneratorTest.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
#include <gtest/gtest.h>
#include <xml/m3CommandGenerator.hpp>
#include <api/m3CommandGenerator.hpp>

TEST(XmlCommandGenerator, Connect) { EXPECT_EQ(xml::command::connect(), std::string("<Command>\n<Operation>Connect</Operation>\n</Command>\n")); }
using namespace m3::api::command;

TEST(XmlCommandGenerator, Disconnect) { EXPECT_EQ(xml::command::disconnect(), std::string("<Command>\n<Operation>Disconnect</Operation>\n</Command>\n")); }
TEST(XmlCommandGenerator, Connect) { EXPECT_EQ(connect(), std::string("<Command>\n<Operation>Connect</Operation>\n</Command>\n")); }

TEST(XmlCommandGenerator, GetStatus) { EXPECT_EQ(xml::command::getStatus(), std::string("<Command>\n<Operation>Get_Status</Operation>\n</Command>\n")); }
TEST(XmlCommandGenerator, Disconnect) { EXPECT_EQ(disconnect(), std::string("<Command>\n<Operation>Disconnect</Operation>\n</Command>\n")); }

TEST(XmlCommandGenerator, GetStatus) { EXPECT_EQ(getStatus(), std::string("<Command>\n<Operation>Get_Status</Operation>\n</Command>\n")); }

TEST(XmlCommandGenerator, SetMode)
{
EXPECT_EQ(xml::command::setMode(0), std::string("<Command>\n<Operation>Set_Mode</Operation>\n<Mode>0</Mode>\n</Command>\n"));
EXPECT_EQ(xml::command::setMode(1), std::string("<Command>\n<Operation>Set_Mode</Operation>\n<Mode>1</Mode>\n</Command>\n"));
EXPECT_EQ(xml::command::setMode(2), std::string("<Command>\n<Operation>Set_Mode</Operation>\n<Mode>2</Mode>\n</Command>\n"));
EXPECT_EQ(setMode(0), std::string("<Command>\n<Operation>Set_Mode</Operation>\n<Mode>0</Mode>\n</Command>\n"));
EXPECT_EQ(setMode(1), std::string("<Command>\n<Operation>Set_Mode</Operation>\n<Mode>1</Mode>\n</Command>\n"));
EXPECT_EQ(setMode(2), std::string("<Command>\n<Operation>Set_Mode</Operation>\n<Mode>2</Mode>\n</Command>\n"));
}

TEST(XmlCommandGenerator, SetTVG)
{
EXPECT_EQ(xml::command::setTVG(0, 0, 0, 0),
EXPECT_EQ(setTVG(0, 0, 0, 0),
std::string("<Command>\n<Operation>Set_TVG</Operation>\n<TVG_A>0</TVG_A>\n<TVG_B>0</TVG_B>\n<TVG_C>0</TVG_C>\n<TVG_L>0</TVG_L>\n</Command>\n"));
EXPECT_EQ(xml::command::setTVG(1, 2, 3, 4),
EXPECT_EQ(setTVG(1, 2, 3, 4),
std::string("<Command>\n<Operation>Set_TVG</Operation>\n<TVG_A>1</TVG_A>\n<TVG_B>2</TVG_B>\n<TVG_C>3</TVG_C>\n<TVG_L>4</TVG_L>\n</Command>\n"));
}

TEST(XmlCommandGenerator, StopPing) { EXPECT_EQ(xml::command::stopPing(), std::string("<Command>\n<Operation>Stop_Ping</Operation>\n</Command>\n")); }
TEST(XmlCommandGenerator, StopPing) { EXPECT_EQ(stopPing(), std::string("<Command>\n<Operation>Stop_Ping</Operation>\n</Command>\n")); }

TEST(XmlCommandGenerator, StartPing) { EXPECT_EQ(xml::command::startPing(), std::string("<Command>\n<Operation>Start_Ping</Operation>\n</Command>\n")); }
TEST(XmlCommandGenerator, StartPing) { EXPECT_EQ(startPing(), std::string("<Command>\n<Operation>Start_Ping</Operation>\n</Command>\n")); }

TEST(XmlCommandGenerator, StartRecord) { EXPECT_EQ(xml::command::startRecord(), std::string("<Command>\n<Operation>Start_Record</Operation>\n</Command>\n")); }
TEST(XmlCommandGenerator, StartRecord) { EXPECT_EQ(startRecord(), std::string("<Command>\n<Operation>Start_Record</Operation>\n</Command>\n")); }

TEST(XmlCommandGenerator, StopRecord) { EXPECT_EQ(xml::command::stopRecord(), std::string("<Command>\n<Operation>Stop_Record</Operation>\n</Command>\n")); }
TEST(XmlCommandGenerator, StopRecord) { EXPECT_EQ(stopRecord(), std::string("<Command>\n<Operation>Stop_Record</Operation>\n</Command>\n")); }

TEST(XmlCommandGenerator, StartExport) { EXPECT_EQ(xml::command::startExport(), std::string("<Command>\n<Operation>Start_Export</Operation>\n</Command>\n")); }
TEST(XmlCommandGenerator, StartExport) { EXPECT_EQ(startExport(), std::string("<Command>\n<Operation>Start_Export</Operation>\n</Command>\n")); }

TEST(XmlCommandGenerator, StopExport) { EXPECT_EQ(xml::command::stopExport(), std::string("<Command>\n<Operation>Stop_Export</Operation>\n</Command>\n")); }
TEST(XmlCommandGenerator, StopExport) { EXPECT_EQ(stopExport(), std::string("<Command>\n<Operation>Stop_Export</Operation>\n</Command>\n")); }
10 changes: 5 additions & 5 deletions test/XmlResponseParserTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <rapidxml/rapidxml.hpp>
#include <xml/m3ResponseParser.hpp>
#include <api/m3ResponseParser.hpp>

TEST(XmlResponseParser, ParseGetStatusResponseWithValidXml)
{
Expand All @@ -13,7 +13,7 @@ TEST(XmlResponseParser, ParseGetStatusResponseWithValidXml)
<Time>2016-09-13 15:22:21</Time>
</Response>)";

xml::ResponseInfo result = xml::parseResponse(response);
m3::api::ResponseInfo result = m3::api::parseResponse(response);

EXPECT_EQ(result.operation, "Get_Status");
EXPECT_EQ(result.status, "OK");
Expand All @@ -27,7 +27,7 @@ TEST(XmlResponseParser, ParseGetStatusResponseWithInvalidXml)
std::string response = R"(Invalid XML)";

try {
xml::ResponseInfo result = xml::parseResponse(response);
m3::api::ResponseInfo result = m3::api::parseResponse(response);
FAIL() << "Expected rapidxml::parse_error";
}
catch (const rapidxml::parse_error &e) {
Expand All @@ -47,7 +47,7 @@ TEST(XmlResponseParser, ParseGetStatusResponseWithInvalidResponse)
</NoResponse>)";

try {
xml::ResponseInfo result = xml::parseResponse(response);
m3::api::ResponseInfo result = m3::api::parseResponse(response);
FAIL() << "Expected std::runtime_error";
}
catch (const std::runtime_error &e) {
Expand All @@ -65,7 +65,7 @@ TEST(XmlResponseParser, ParseGetStatusResponseWithIncompleteResponse)
</Response>)";

try {
xml::ResponseInfo result = xml::parseResponse(response);
m3::api::ResponseInfo result = m3::api::parseResponse(response);
FAIL() << "Expected std::runtime_error";
}
catch (const std::runtime_error &e) {
Expand Down

0 comments on commit f2711a2

Please sign in to comment.